unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#70816: 29.2; Flymake fails in latex-mode when the buffer is narrowed
@ 2024-05-07  7:56 Vangelis Evangelou
  2024-05-07 15:19 ` Arash Esbati
  0 siblings, 1 reply; 6+ messages in thread
From: Vangelis Evangelou @ 2024-05-07  7:56 UTC (permalink / raw)
  To: 70816

[-- Attachment #1: Type: text/plain, Size: 472 bytes --]

With the buffer having the contents shown below,
1. Enable flymake-mode.
2. Narrow from the top of the buffer down to the indicated comment.
3. Execute flymake-start.
You should get an error "error in process sentinel: Wrong type argument:
integer-or-marker-p, nil". I suspect perl-flymake has similar issues so you
might want to check that out as well.

Buffer contents:

\documentclass{article}
\begin{document}
0
a
b
c
% <----- End narrow
d
e
f
g
h
i
j{
\end{document}

[-- Attachment #2: Type: text/html, Size: 657 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#70816: 29.2; Flymake fails in latex-mode when the buffer is narrowed
  2024-05-07  7:56 bug#70816: 29.2; Flymake fails in latex-mode when the buffer is narrowed Vangelis Evangelou
@ 2024-05-07 15:19 ` Arash Esbati
  2024-05-18  8:41   ` Eli Zaretskii
  2024-05-18 14:51   ` Spencer Baugh
  0 siblings, 2 replies; 6+ messages in thread
From: Arash Esbati @ 2024-05-07 15:19 UTC (permalink / raw)
  To: Vangelis Evangelou; +Cc: 70816

Vangelis Evangelou <evangelou@gmail.com> writes:

> With the buffer having the contents shown below,
> 1. Enable flymake-mode.
> 2. Narrow from the top of the buffer down to the indicated comment.
> 3. Execute flymake-start.

The reproducer for me was to save a file like this (note the first blank
lines):

--8<---------------cut here---------------start------------->8---



\documentclass{article}
\begin{document}
0
a
b
cf
% <----- End narrow
d
e
f
g
h
i
j{
\end{document}
--8<---------------cut here---------------end--------------->8---

Then:

  • emacs -Q
  • M-x toggle-debug-on-error RET
  • Visit the file, M-x flymake-mode RET
  • Mark '\document... End narrow' and hit 'C-x n n'
  • Put point after c and hit f

This is what the debugger says (linebreaks added manually):

--8<---------------cut here---------------start------------->8---
Debugger entered--Lisp error: (wrong-type-argument integer-or-marker-p nil)
  make-overlay(nil nil)
  flymake--highlight-line(#s(flymake--diag :locus #<buffer
  flymake-test.tex> :beg nil :end nil :type :warning :text "No match
found for `{'." :backend tex-chktex :data nil :overlay-properties nil
:overlay nil :orig-beg nil :orig-end nil))
  flymake--publish-diagnostics((#s(flymake--diag :locus #<buffer
flymake-test.tex> :beg nil :end nil :type :warning :text "No match
found for `{'." :backend tex-chktex :data nil :overlay-properties nil
:overlay nil :orig-beg nil :orig-end nil) #s(flymake--diag :locus
#<buffer flymake-test.tex> :beg 54 :end 73 :type :warning :text
"Number of `{' doesn't match the number of `}'!" :backend tex-chktex
:data nil :overlay-properties nil :overlay nil :orig-beg 54 :orig-end
73)) :backend tex-chktex :state #s(flymake--state :running
backend-token1 :reported-p nil :disabled nil :diags (#s(flymake--diag
:locus #<buffer flymake-test.tex> :beg nil :end nil :type :warning
:text "No match found for `{'." :backend tex-chktex :data nil
:overlay-properties nil :overlay nil :orig-beg nil :orig-end nil))
:foreign-diags #<hash-table eql 0/0 0x43d74c56 ...>) :region nil)
  flymake--handle-report(tex-chktex backend-token1 (#s(flymake--diag
:locus #<buffer flymake-test.tex> :beg nil :end nil :type :warning
:text "No match found for `{'." :backend tex-chktex :data nil
:overlay-properties nil :overlay nil :orig-beg nil :orig-end nil)
#s(flymake--diag :locus #<buffer flymake-test.tex> :beg 54 :end 73
:type :warning :text "Number of `{' doesn't match the number of `}'!"
:backend tex-chktex :data nil :overlay-properties nil :overlay nil
:orig-beg 54 :orig-end 73)))
  apply(flymake--handle-report tex-chktex backend-token1
(#s(flymake--diag :locus #<buffer flymake-test.tex> :beg nil :end nil
:type :warning :text "No match found for `{'." :backend tex-chktex
:data nil :overlay-properties nil :overlay nil :orig-beg nil :orig-end
nil) #s(flymake--diag :locus #<buffer flymake-test.tex> :beg 54 :end
73 :type :warning :text "Number of `{' doesn't match the number of
`}'!" :backend tex-chktex :data nil :overlay-properties nil :overlay
nil :orig-beg 54 :orig-end 73)))
  #f(compiled-function (&rest args) #<bytecode
-0x16dfa1c308597683>)((#s(flymake--diag :locus #<buffer
flymake-test.tex> :beg nil :end nil :type :warning :text "No match
found for `{'." :backend tex-chktex :data nil :overlay-properties nil
:overlay nil :orig-beg nil :orig-end nil) #s(flymake--diag :locus
#<buffer flymake-test.tex> :beg 54 :end 73 :type :warning :text
"Number of `{' doesn't match the number of `}'!" :backend tex-chktex
:data nil :overlay-properties nil :overlay nil :orig-beg 54 :orig-end
73)))
  #f(compiled-function (process event) #<bytecode
-0x13a3e83da652160>)(#<process tex-chktex> "finished\n")
--8<---------------cut here---------------end--------------->8---

Best, Arash





^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#70816: 29.2; Flymake fails in latex-mode when the buffer is narrowed
  2024-05-07 15:19 ` Arash Esbati
@ 2024-05-18  8:41   ` Eli Zaretskii
  2024-05-18 14:51   ` Spencer Baugh
  1 sibling, 0 replies; 6+ messages in thread
From: Eli Zaretskii @ 2024-05-18  8:41 UTC (permalink / raw)
  To: Arash Esbati, Spencer Baugh; +Cc: evangelou, 70816

> Cc: 70816@debbugs.gnu.org
> From: Arash Esbati <arash@gnu.org>
> Date: Tue, 07 May 2024 17:19:03 +0200
> 
> Vangelis Evangelou <evangelou@gmail.com> writes:
> 
> > With the buffer having the contents shown below,
> > 1. Enable flymake-mode.
> > 2. Narrow from the top of the buffer down to the indicated comment.
> > 3. Execute flymake-start.
> 
> The reproducer for me was to save a file like this (note the first blank
> lines):
> 
> --8<---------------cut here---------------start------------->8---
> 
> 
> 
> \documentclass{article}
> \begin{document}
> 0
> a
> b
> cf
> % <----- End narrow
> d
> e
> f
> g
> h
> i
> j{
> \end{document}
> --8<---------------cut here---------------end--------------->8---
> 
> Then:
> 
>   • emacs -Q
>   • M-x toggle-debug-on-error RET
>   • Visit the file, M-x flymake-mode RET
>   • Mark '\document... End narrow' and hit 'C-x n n'
>   • Put point after c and hit f

Spencer, can you please look into this?

> 
> This is what the debugger says (linebreaks added manually):
> 
> --8<---------------cut here---------------start------------->8---
> Debugger entered--Lisp error: (wrong-type-argument integer-or-marker-p nil)
>   make-overlay(nil nil)
>   flymake--highlight-line(#s(flymake--diag :locus #<buffer
>   flymake-test.tex> :beg nil :end nil :type :warning :text "No match
> found for `{'." :backend tex-chktex :data nil :overlay-properties nil
> :overlay nil :orig-beg nil :orig-end nil))
>   flymake--publish-diagnostics((#s(flymake--diag :locus #<buffer
> flymake-test.tex> :beg nil :end nil :type :warning :text "No match
> found for `{'." :backend tex-chktex :data nil :overlay-properties nil
> :overlay nil :orig-beg nil :orig-end nil) #s(flymake--diag :locus
> #<buffer flymake-test.tex> :beg 54 :end 73 :type :warning :text
> "Number of `{' doesn't match the number of `}'!" :backend tex-chktex
> :data nil :overlay-properties nil :overlay nil :orig-beg 54 :orig-end
> 73)) :backend tex-chktex :state #s(flymake--state :running
> backend-token1 :reported-p nil :disabled nil :diags (#s(flymake--diag
> :locus #<buffer flymake-test.tex> :beg nil :end nil :type :warning
> :text "No match found for `{'." :backend tex-chktex :data nil
> :overlay-properties nil :overlay nil :orig-beg nil :orig-end nil))
> :foreign-diags #<hash-table eql 0/0 0x43d74c56 ...>) :region nil)
>   flymake--handle-report(tex-chktex backend-token1 (#s(flymake--diag
> :locus #<buffer flymake-test.tex> :beg nil :end nil :type :warning
> :text "No match found for `{'." :backend tex-chktex :data nil
> :overlay-properties nil :overlay nil :orig-beg nil :orig-end nil)
> #s(flymake--diag :locus #<buffer flymake-test.tex> :beg 54 :end 73
> :type :warning :text "Number of `{' doesn't match the number of `}'!"
> :backend tex-chktex :data nil :overlay-properties nil :overlay nil
> :orig-beg 54 :orig-end 73)))
>   apply(flymake--handle-report tex-chktex backend-token1
> (#s(flymake--diag :locus #<buffer flymake-test.tex> :beg nil :end nil
> :type :warning :text "No match found for `{'." :backend tex-chktex
> :data nil :overlay-properties nil :overlay nil :orig-beg nil :orig-end
> nil) #s(flymake--diag :locus #<buffer flymake-test.tex> :beg 54 :end
> 73 :type :warning :text "Number of `{' doesn't match the number of
> `}'!" :backend tex-chktex :data nil :overlay-properties nil :overlay
> nil :orig-beg 54 :orig-end 73)))
>   #f(compiled-function (&rest args) #<bytecode
> -0x16dfa1c308597683>)((#s(flymake--diag :locus #<buffer
> flymake-test.tex> :beg nil :end nil :type :warning :text "No match
> found for `{'." :backend tex-chktex :data nil :overlay-properties nil
> :overlay nil :orig-beg nil :orig-end nil) #s(flymake--diag :locus
> #<buffer flymake-test.tex> :beg 54 :end 73 :type :warning :text
> "Number of `{' doesn't match the number of `}'!" :backend tex-chktex
> :data nil :overlay-properties nil :overlay nil :orig-beg 54 :orig-end
> 73)))
>   #f(compiled-function (process event) #<bytecode
> -0x13a3e83da652160>)(#<process tex-chktex> "finished\n")
> --8<---------------cut here---------------end--------------->8---
> 
> Best, Arash
> 
> 
> 
> 





^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#70816: 29.2; Flymake fails in latex-mode when the buffer is narrowed
  2024-05-07 15:19 ` Arash Esbati
  2024-05-18  8:41   ` Eli Zaretskii
@ 2024-05-18 14:51   ` Spencer Baugh
  2024-05-18 14:58     ` Spencer Baugh
  1 sibling, 1 reply; 6+ messages in thread
From: Spencer Baugh @ 2024-05-18 14:51 UTC (permalink / raw)
  To: Arash Esbati; +Cc: Vangelis Evangelou, 70816


Can you test with the following patch, please?

diff --git a/lisp/progmodes/flymake.el b/lisp/progmodes/flymake.el
index ef190ff0cb5..146aae06253 100644
--- a/lisp/progmodes/flymake.el
+++ b/lisp/progmodes/flymake.el
@@ -430,6 +430,8 @@ flymake-diag-region
         (let ((line (min (max line 1)
                          (line-number-at-pos (point-max) 'absolute))))
           (save-excursion
+            (save-restriction
+              (widen)
             (save-match-data
               (goto-char (point-min))
               (forward-line (1- line))
@@ -463,7 +465,7 @@ flymake-diag-region
                               (fallback-eol beg))))
                   (let* ((beg (fallback-bol))
                          (end (fallback-eol beg)))
-                    (cons beg end))))))))
+                    (cons beg end)))))))))
     (error (flymake-log :warning "Invalid region line=%s col=%s" line col)
            nil)))
 





^ permalink raw reply related	[flat|nested] 6+ messages in thread

* bug#70816: 29.2; Flymake fails in latex-mode when the buffer is narrowed
  2024-05-18 14:51   ` Spencer Baugh
@ 2024-05-18 14:58     ` Spencer Baugh
  2024-05-18 17:11       ` Vangelis Evangelou
  0 siblings, 1 reply; 6+ messages in thread
From: Spencer Baugh @ 2024-05-18 14:58 UTC (permalink / raw)
  To: Arash Esbati; +Cc: Vangelis Evangelou, 70816

Spencer Baugh <sbaugh@janestreet.com> writes:
> Can you test with the following patch, please?

Context:

It looks like the latex-mode flymake diagnostic function, tex-chktex,
widens before sending the buffer contents to the external linter
process.  So the line numbers of errors are reported relative to the
widened buffer, not the narrowed buffer.  A number of different checkers
in Emacs seem to do the same thing.

The bug is that these checkers call flymake-diag-region to translate the
line numbers into buffer positions.  But flymake-diag-region does not
widen the buffer when doing this translation, so it fails.

I expect you have some flymake logs of the form "Invalid region line=%s
col=%s". when triggering this bug.

Probably the right fix in flymake is to make flymake-diag-region widen,
as in the patch I posted, but that's a bit of a behavior change...  will
think about it, but it's probably fine.





^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#70816: 29.2; Flymake fails in latex-mode when the buffer is narrowed
  2024-05-18 14:58     ` Spencer Baugh
@ 2024-05-18 17:11       ` Vangelis Evangelou
  0 siblings, 0 replies; 6+ messages in thread
From: Vangelis Evangelou @ 2024-05-18 17:11 UTC (permalink / raw)
  To: Spencer Baugh; +Cc: Arash Esbati, 70816

[-- Attachment #1: Type: text/plain, Size: 1406 bytes --]

Hi Spencer.

Yes, that does resolve the issue. However, as you hinted, it causes issues
with other diagnostic functions. In my tests, `ess-r-flymake' from the
emacs speaks statistics (ess) package produces incorrect error positions. I
wonder if `flymake-diag-region' should have an optional argument to not
widen the buffer before calculating the positions.

Best,
Vangelis

On Sat, 18 May 2024 at 15:58, Spencer Baugh <sbaugh@janestreet.com> wrote:

> Spencer Baugh <sbaugh@janestreet.com> writes:
> > Can you test with the following patch, please?
>
> Context:
>
> It looks like the latex-mode flymake diagnostic function, tex-chktex,
> widens before sending the buffer contents to the external linter
> process.  So the line numbers of errors are reported relative to the
> widened buffer, not the narrowed buffer.  A number of different checkers
> in Emacs seem to do the same thing.
>
> The bug is that these checkers call flymake-diag-region to translate the
> line numbers into buffer positions.  But flymake-diag-region does not
> widen the buffer when doing this translation, so it fails.
>
> I expect you have some flymake logs of the form "Invalid region line=%s
> col=%s". when triggering this bug.
>
> Probably the right fix in flymake is to make flymake-diag-region widen,
> as in the patch I posted, but that's a bit of a behavior change...  will
> think about it, but it's probably fine.
>

[-- Attachment #2: Type: text/html, Size: 1928 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2024-05-18 17:11 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-05-07  7:56 bug#70816: 29.2; Flymake fails in latex-mode when the buffer is narrowed Vangelis Evangelou
2024-05-07 15:19 ` Arash Esbati
2024-05-18  8:41   ` Eli Zaretskii
2024-05-18 14:51   ` Spencer Baugh
2024-05-18 14:58     ` Spencer Baugh
2024-05-18 17:11       ` Vangelis Evangelou

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).