unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#52342: [PATCH] Add Texinfo support for Flymake
@ 2021-12-07  2:48 Okamsn via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2021-12-07 14:10 ` Stefan Kangas
  0 siblings, 1 reply; 17+ messages in thread
From: Okamsn via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2021-12-07  2:48 UTC (permalink / raw)
  To: 52342

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

Hello,

This patch adds basic Texinfo support for Flymake, following the
annotated example in the Flymake manual.  All it does is feed the
contents of the buffer to the program `makeinfo`, which either reports
errors or outputs the resulting file to the specified /dev/null.

The regexp for identifying errors and warnings is the same as used by
the package Flycheck (see here:
https://github.com/flycheck/flycheck/blob/784f184cdd9f9cb4e3dbb997c09d93e954142842/flycheck.el#L12175).
It seems to identify an optional column number, but I didn't see that in
the programs output or listed in the Man page.  The patch does not make
use of any match for that information.

The Man page says that the program will by default report 100 errors
before stopping.

While the package Flymake is required during compilation, the byte
compiler still wanted the function `flymake--log-1` declared.  This is
the function run by the macro `flymake-log`.

Thank you.

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: v2-0001-Add-basic-Texinfo-support-for-Flymake.patch --]
[-- Type: text/x-patch; name=v2-0001-Add-basic-Texinfo-support-for-Flymake.patch, Size: 4951 bytes --]

From 2209e84f98d75eb3db5589bfe6c64ded266c67e2 Mon Sep 17 00:00:00 2001
From: Earl Hyatt <okamsn@protonmail.com>
Date: Mon, 6 Dec 2021 21:04:27 -0500
Subject: [PATCH v2] Add basic Texinfo support for Flymake.

* lisp/textmodes/texinfo.el (texinfo-flymake, texinfo--flymake-proc)
(texinfo-mode):
Add the functions texinfo-flymake and process variable
texinfo--flymake-proc.  Modify texinfo-mode to automatically add this
function to the hook flymake-diagnostic-functions.
---
 lisp/textmodes/texinfo.el | 78 ++++++++++++++++++++++++++++++++++++++-
 1 file changed, 77 insertions(+), 1 deletion(-)

diff --git a/lisp/textmodes/texinfo.el b/lisp/textmodes/texinfo.el
index 71db33bae3..292d819dc2 100644
--- a/lisp/textmodes/texinfo.el
+++ b/lisp/textmodes/texinfo.el
@@ -32,6 +32,16 @@
 
 ;;; Code:
 
+(eval-when-compile (require 'cl-lib)
+                   (require 'flymake)
+                   (require 'rx))
+(declare-function flymake-diag-region "flymake"
+                  (buffer line &optional col))
+(declare-function flymake-make-diagnostic "flymake"
+                  ( locus beg end type text
+                    &optional data overlay-properties))
+(declare-function flymake--log-1 (level sublog msg &rest args))
+
 (eval-when-compile (require 'tex-mode))
 (declare-function tex-buffer "tex-mode" ())
 (declare-function tex-region "tex-mode" (beg end))
@@ -336,6 +346,69 @@ texinfo-current-defun-name
     (if (re-search-backward "^@node[ \t]+\\([^,\n]+\\)" nil t)
 	(match-string-no-properties 1))))
 
+;;; Flymake support
+(defvar-local texinfo--flymake-proc nil)
+(defun texinfo-flymake (report-fn &rest _)
+  "Texinfo checking for Flymake.
+
+REPORT-FN is the callback function."
+  (let ((executable (or (executable-find "makeinfo")
+                        (executable-find "texi2any")))
+        (source (current-buffer)))
+
+    (unless executable
+      (error "Flymake for Texinfo requires `makeinfo' or `texi2any'"))
+
+    (when (process-live-p texinfo--flymake-proc)
+      (kill-process texinfo--flymake-proc))
+
+    (save-restriction
+      (widen)
+      (setq texinfo--flymake-proc
+            (make-process
+             :name "texinfo-flymake"
+             :noquery t
+             :connection-type 'pipe
+             :buffer (generate-new-buffer " *texinfo-flymake*")
+             :command `(,executable "-o" ,null-device "-")
+             :sentinel
+             (lambda (proc _event)
+               (when (memq (process-status proc) '(exit signal))
+                 (unwind-protect
+                     (if (eq (buffer-local-value 'texinfo--flymake-proc
+                                                 source)
+                             proc)
+                         (with-current-buffer (process-buffer proc)
+                           (goto-char (point-min))
+                           (cl-loop
+                            while (search-forward-regexp
+                                   (rx line-start
+                                       "-:"
+                                       (group-n 1 (0+ digit)) ; Line
+                                       (optional ":" (group-n 2 (0+ digit))) ; col
+                                       ": "
+                                       (optional (group-n 3 "warning: ")) ; warn
+                                       (group-n 4 (0+ nonl)) ; Message
+                                       line-end)
+                                   nil t)
+                            for msg = (match-string 4)
+                            for (beg . end) = (flymake-diag-region
+                                               source
+                                               (string-to-number (match-string 1)))
+                            for type = (if (match-string 3)
+                                           :warning
+                                         :error)
+                            collect (flymake-make-diagnostic
+                                     source beg end type msg)
+                            into diags
+                            finally (funcall report-fn diags)))
+                       (flymake-log :warning "Cancelling obsolete check %s"
+                                    proc))
+                   (kill-buffer (process-buffer proc)))))))
+      (process-send-region texinfo--flymake-proc (point-min) (point-max))
+      (process-send-eof texinfo--flymake-proc))))
+
+
 ;;; Texinfo mode
 
 ;;;###autoload
@@ -455,7 +528,10 @@ texinfo-mode
 	      (let ((prevent-filling "^@\\(def\\|multitable\\)"))
 		(if (null auto-fill-inhibit-regexp)
 		    prevent-filling
-		  (concat auto-fill-inhibit-regexp "\\|" prevent-filling)))))
+		  (concat auto-fill-inhibit-regexp "\\|" prevent-filling))))
+
+  ;; Set up Flymake support.
+  (add-hook 'flymake-diagnostic-functions #'texinfo-flymake nil t))
 
 (defvar texinfo-fillable-commands '("@noindent")
   "A list of commands that can be filled.")
-- 
2.25.1


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

* bug#52342: [PATCH] Add Texinfo support for Flymake
  2021-12-07  2:48 bug#52342: [PATCH] Add Texinfo support for Flymake Okamsn via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2021-12-07 14:10 ` Stefan Kangas
  2021-12-07 14:23   ` João Távora
  0 siblings, 1 reply; 17+ messages in thread
From: Stefan Kangas @ 2021-12-07 14:10 UTC (permalink / raw)
  To: Okamsn; +Cc: 52342, João Távora

Okamsn <okamsn@protonmail.com> writes:

> This patch adds basic Texinfo support for Flymake, following the
> annotated example in the Flymake manual.  All it does is feed the
> contents of the buffer to the program `makeinfo`, which either reports
> errors or outputs the resulting file to the specified /dev/null.

João, what do you think of this patch?





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

* bug#52342: [PATCH] Add Texinfo support for Flymake
  2021-12-07 14:10 ` Stefan Kangas
@ 2021-12-07 14:23   ` João Távora
  2021-12-07 23:39     ` Okamsn via Bug reports for GNU Emacs, the Swiss army knife of text editors
  0 siblings, 1 reply; 17+ messages in thread
From: João Távora @ 2021-12-07 14:23 UTC (permalink / raw)
  To: Stefan Kangas; +Cc: Okamsn, 52342

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

Looks 99% fine to me, it's the way Flymake is suppose to be extended
with new backends.  So that part's super.

Not sure about the eval-when-compile for require.  It was my
expression that require is always "when compile".

I've unfortunately been a little away from Emacs lately.

João

On Tue, Dec 7, 2021 at 2:10 PM Stefan Kangas <stefan@marxist.se> wrote:

> Okamsn <okamsn@protonmail.com> writes:
>
> > This patch adds basic Texinfo support for Flymake, following the
> > annotated example in the Flymake manual.  All it does is feed the
> > contents of the buffer to the program `makeinfo`, which either reports
> > errors or outputs the resulting file to the specified /dev/null.
>
> João, what do you think of this patch?
>


-- 
João Távora

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

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

* bug#52342: [PATCH] Add Texinfo support for Flymake
  2021-12-07 14:23   ` João Távora
@ 2021-12-07 23:39     ` Okamsn via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2021-12-07 23:43       ` João Távora
  0 siblings, 1 reply; 17+ messages in thread
From: Okamsn via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2021-12-07 23:39 UTC (permalink / raw)
  To: João Távora, Stefan Kangas; +Cc: 52342

On 12/7/21 09:23, João Távora wrote:
> Not sure about the eval-when-compile for require.  It was my
> expression that require is always "when compile".
>
> I've unfortunately been a little away from Emacs lately.
>
> João

My understanding is that `eval-when-compile` is used to make sure that
macro definitions are available during compilation and that the
libraries are not loaded when `texinfo.el` is loaded.  The macros in the
patch are `rx`, `cl-loop`, and `flymake-log`.

There is also the following comment on line 82 of the current version
(https://git.savannah.gnu.org/cgit/emacs.git/tree/lisp/textmodes/texinfo.el#n82):

 > Don't you dare insert any `require' calls at top level in this file
 > --rms.

which I tried to observe.







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

* bug#52342: [PATCH] Add Texinfo support for Flymake
  2021-12-07 23:39     ` Okamsn via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2021-12-07 23:43       ` João Távora
  2021-12-07 23:46         ` João Távora
  2021-12-08  0:50         ` Stefan Kangas
  0 siblings, 2 replies; 17+ messages in thread
From: João Távora @ 2021-12-07 23:43 UTC (permalink / raw)
  To: Okamsn, Stefan Monnier; +Cc: Stefan Kangas, 52342

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

On Tue, Dec 7, 2021 at 11:39 PM Okamsn <okamsn@protonmail.com> wrote:

> On 12/7/21 09:23, João Távora wrote:
> > Not sure about the eval-when-compile for require.  It was my
> > expression that require is always "when compile".
> >
> > I've unfortunately been a little away from Emacs lately.
> >
> > João
>
> My understanding is that `eval-when-compile` is used to make sure that
> macro definitions are available during compilation and that the
> libraries are not loaded when `texinfo.el` is loaded.  The macros in the
> patch are `rx`, `cl-loop`, and `flymake-log`.
>

require is always `eval-and-compile` (sorry if I misled you earlier).
It's OK to use `eval-when-compile` when needing `cl-loop` from `cl-lib`
if _all_ you need form `cl-lib` is indeed macros.

But for flymake, you need the actual runtime things too, right? So
I think plain require is better and simpler


> There is also the following comment on line 82 of the current version
> (
> https://git.savannah.gnu.org/cgit/emacs.git/tree/lisp/textmodes/texinfo.el#n82
> ):
>
>  > Don't you dare insert any `require' calls at top level in this file
>  > --rms.
>
> which I tried to observe.


No comment :-)

Anyway, let's hear what byte-compiler guru Stefan Monnier has to say
about this?

João

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

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

* bug#52342: [PATCH] Add Texinfo support for Flymake
  2021-12-07 23:43       ` João Távora
@ 2021-12-07 23:46         ` João Távora
  2021-12-08  1:00           ` Okamsn via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2021-12-19 16:17           ` Okamsn via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2021-12-08  0:50         ` Stefan Kangas
  1 sibling, 2 replies; 17+ messages in thread
From: João Távora @ 2021-12-07 23:46 UTC (permalink / raw)
  To: Okamsn, Stefan Monnier; +Cc: Stefan Kangas, 52342

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

On Tue, Dec 7, 2021 at 11:43 PM João Távora <joaotavora@gmail.com> wrote:

>
> On Tue, Dec 7, 2021 at 11:39 PM Okamsn <okamsn@protonmail.com> wrote:
>
>> On 12/7/21 09:23, João Távora wrote:
>> > Not sure about the eval-when-compile for require.  It was my
>> > expression that require is always "when compile".
>> >
>> > I've unfortunately been a little away from Emacs lately.
>> >
>> > João
>>
>> My understanding is that `eval-when-compile` is used to make sure that
>> macro definitions are available during compilation and that the
>> libraries are not loaded when `texinfo.el` is loaded.  The macros in the
>> patch are `rx`, `cl-loop`, and `flymake-log`.
>>
>
> require is always `eval-and-compile` (sorry if I misled you earlier).
> It's OK to use `eval-when-compile` when needing `cl-loop` from `cl-lib`
> if _all_ you need form `cl-lib` is indeed macros.
>
> But for flymake, you need the actual runtime things too, right? So
> I think plain require is better and simpler
>

Hmmm, on second thought, it you're planning on relying on
autoloads for ultimate loading lazyness.... Hmm, maybe
you're right...

João

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

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

* bug#52342: [PATCH] Add Texinfo support for Flymake
  2021-12-07 23:43       ` João Távora
  2021-12-07 23:46         ` João Távora
@ 2021-12-08  0:50         ` Stefan Kangas
  2021-12-10  1:40           ` Okamsn via Bug reports for GNU Emacs, the Swiss army knife of text editors
  1 sibling, 1 reply; 17+ messages in thread
From: Stefan Kangas @ 2021-12-08  0:50 UTC (permalink / raw)
  To: João Távora, Okamsn, Stefan Monnier; +Cc: 52342

João Távora <joaotavora@gmail.com> writes:

>>  > Don't you dare insert any `require' calls at top level in this file
>>  > --rms.
>>
>> which I tried to observe.
>
> No comment :-)

That file is really jumping through a lot of hoops to avoid require, for
some reason.  It seems like yet another thing that was probably relevant
30 years ago, but not so much today.  Personally, I'd just simplify it.





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

* bug#52342: [PATCH] Add Texinfo support for Flymake
  2021-12-07 23:46         ` João Távora
@ 2021-12-08  1:00           ` Okamsn via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2021-12-08  1:03             ` Okamsn via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2021-12-19 16:17           ` Okamsn via Bug reports for GNU Emacs, the Swiss army knife of text editors
  1 sibling, 1 reply; 17+ messages in thread
From: Okamsn via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2021-12-08  1:00 UTC (permalink / raw)
  To: João Távora, Stefan Monnier; +Cc: Stefan Kangas, 52342

On 12/7/21 18:46, João Távora wrote:
>     require is always `eval-and-compile` (sorry if I misled you earlier).
>     It's OK to use `eval-when-compile` when needing `cl-loop` from `cl-lib`
>     if _all_ you need form `cl-lib` is indeed macros.
>
>     But for flymake, you need the actual runtime things too, right? So
>     I think plain require is better and simpler
>
>
> Hmmm, on second thought, it you're planning on relying on
> autoloads for ultimate loading lazyness.... Hmm, maybe
> you're right...
>
> João

My thinking was that the Flymake features would be loaded when
`flymake-mode` was enabled and that the added function `texinfo-flymake`
won't run until Flymake is loaded and processes
`flymake-diagnostic-functions`. Does that sound right?






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

* bug#52342: [PATCH] Add Texinfo support for Flymake
  2021-12-08  1:00           ` Okamsn via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2021-12-08  1:03             ` Okamsn via Bug reports for GNU Emacs, the Swiss army knife of text editors
  0 siblings, 0 replies; 17+ messages in thread
From: Okamsn via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2021-12-08  1:03 UTC (permalink / raw)
  To: João Távora, Stefan Monnier; +Cc: Stefan Kangas, 52342

On 12/7/21 20:00, Okamsn wrote:
> On 12/7/21 18:46, João Távora wrote:
>>      require is always `eval-and-compile` (sorry if I misled you earlier).
>>      It's OK to use `eval-when-compile` when needing `cl-loop` from `cl-lib`
>>      if _all_ you need form `cl-lib` is indeed macros.
>>
>>      But for flymake, you need the actual runtime things too, right? So
>>      I think plain require is better and simpler
>>
>>
>> Hmmm, on second thought, it you're planning on relying on
>> autoloads for ultimate loading lazyness.... Hmm, maybe
>> you're right...
>>
>> João
>
> My thinking was that the Flymake features would be loaded when
> `flymake-mode` was enabled and that the added function `texinfo-flymake`
> won't run until Flymake is loaded and processes
> `flymake-diagnostic-functions`. Does that sound right?

This is what happened when I tested it with `emacs -q`, I should add.







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

* bug#52342: [PATCH] Add Texinfo support for Flymake
  2021-12-08  0:50         ` Stefan Kangas
@ 2021-12-10  1:40           ` Okamsn via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2021-12-10  2:07             ` Stefan Kangas
  0 siblings, 1 reply; 17+ messages in thread
From: Okamsn via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2021-12-10  1:40 UTC (permalink / raw)
  To: Stefan Kangas, João Távora, Stefan Monnier; +Cc: 52342

On 12/7/21 19:50, Stefan Kangas wrote:
> João Távora <joaotavora@gmail.com> writes:
>
>>>   > Don't you dare insert any `require' calls at top level in this file
>>>   > --rms.
>>>
>>> which I tried to observe.
>>
>> No comment :-)
>
> That file is really jumping through a lot of hoops to avoid require, for
> some reason.  It seems like yet another thing that was probably relevant
> 30 years ago, but not so much today.  Personally, I'd just simplify it.
>

Hello,

Would the file `texinfo.el` loading Flymake affect the use of a more
recent version of Flymake installed as a package? I have run into issues
when using Org as a downloaded package, where a library causes the
built-in version to load, which breaks using the newer features.

The file `python.el` doesn't seem to do any loading/declaring of Flymake
features.

Thank you.







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

* bug#52342: [PATCH] Add Texinfo support for Flymake
  2021-12-10  1:40           ` Okamsn via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2021-12-10  2:07             ` Stefan Kangas
  0 siblings, 0 replies; 17+ messages in thread
From: Stefan Kangas @ 2021-12-10  2:07 UTC (permalink / raw)
  To: Okamsn, João Távora, Stefan Monnier; +Cc: 52342

Okamsn <okamsn@protonmail.com> writes:

> Would the file `texinfo.el` loading Flymake affect the use of a more
> recent version of Flymake installed as a package? I have run into issues
> when using Org as a downloaded package, where a library causes the
> built-in version to load, which breaks using the newer features.

AFAIK, this should just work: if a newer version of a package is
installed it should be used instead of the built-in one.  If there are
any problems with that, it might be indicative of a bug somewhere.

> The file `python.el` doesn't seem to do any loading/declaring of Flymake
> features.

Probably it relies on autoloads in flymake itself.  Maybe we could do
the same here, but it depends on whether or not it would make sense to
autoload the things you need.  João is probably the best person to
answer that.





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

* bug#52342: [PATCH] Add Texinfo support for Flymake
  2021-12-07 23:46         ` João Távora
  2021-12-08  1:00           ` Okamsn via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2021-12-19 16:17           ` Okamsn via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2022-01-04 20:21             ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2022-04-16 21:59             ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
  1 sibling, 2 replies; 17+ messages in thread
From: Okamsn via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2021-12-19 16:17 UTC (permalink / raw)
  To: João Távora, Stefan Monnier; +Cc: Stefan Kangas, 52342

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

On 12/7/21 18:46, João Távora wrote:
> On Tue, Dec 7, 2021 at 11:43 PM João Távora <joaotavora@gmail.com
> <mailto:joaotavora@gmail.com>> wrote:
>
>
>     On Tue, Dec 7, 2021 at 11:39 PM Okamsn <okamsn@protonmail.com
>     <mailto:okamsn@protonmail.com>> wrote:
>
>         On 12/7/21 09:23, João Távora wrote:
>          > Not sure about the eval-when-compile for require.  It was my
>          > expression that require is always "when compile".
>          >
>          > I've unfortunately been a little away from Emacs lately.
>          >
>          > João
>
>         My understanding is that `eval-when-compile` is used to make
>         sure that
>         macro definitions are available during compilation and that the
>         libraries are not loaded when `texinfo.el` is loaded.  The
>         macros in the
>         patch are `rx`, `cl-loop`, and `flymake-log`.
>
>
>     require is always `eval-and-compile` (sorry if I misled you earlier).
>     It's OK to use `eval-when-compile` when needing `cl-loop` from `cl-lib`
>     if _all_ you need form `cl-lib` is indeed macros.
>
>     But for flymake, you need the actual runtime things too, right? So
>     I think plain require is better and simpler
>
>
> Hmmm, on second thought, it you're planning on relying on
> autoloads for ultimate loading lazyness.... Hmm, maybe
> you're right...
>
> João

Hello Stefan Monnier,

Do you have any thoughts about the lazy loading of Flymake features used
in the patch discussed in this thread (re-attached for convenience)?

Thank you.

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: v2-0001-Add-basic-Texinfo-support-for-Flymake.patch --]
[-- Type: text/x-patch; name=v2-0001-Add-basic-Texinfo-support-for-Flymake.patch, Size: 4951 bytes --]

From 2209e84f98d75eb3db5589bfe6c64ded266c67e2 Mon Sep 17 00:00:00 2001
From: Earl Hyatt <okamsn@protonmail.com>
Date: Mon, 6 Dec 2021 21:04:27 -0500
Subject: [PATCH v2] Add basic Texinfo support for Flymake.

* lisp/textmodes/texinfo.el (texinfo-flymake, texinfo--flymake-proc)
(texinfo-mode):
Add the functions texinfo-flymake and process variable
texinfo--flymake-proc.  Modify texinfo-mode to automatically add this
function to the hook flymake-diagnostic-functions.
---
 lisp/textmodes/texinfo.el | 78 ++++++++++++++++++++++++++++++++++++++-
 1 file changed, 77 insertions(+), 1 deletion(-)

diff --git a/lisp/textmodes/texinfo.el b/lisp/textmodes/texinfo.el
index 71db33bae3..292d819dc2 100644
--- a/lisp/textmodes/texinfo.el
+++ b/lisp/textmodes/texinfo.el
@@ -32,6 +32,16 @@
 
 ;;; Code:
 
+(eval-when-compile (require 'cl-lib)
+                   (require 'flymake)
+                   (require 'rx))
+(declare-function flymake-diag-region "flymake"
+                  (buffer line &optional col))
+(declare-function flymake-make-diagnostic "flymake"
+                  ( locus beg end type text
+                    &optional data overlay-properties))
+(declare-function flymake--log-1 (level sublog msg &rest args))
+
 (eval-when-compile (require 'tex-mode))
 (declare-function tex-buffer "tex-mode" ())
 (declare-function tex-region "tex-mode" (beg end))
@@ -336,6 +346,69 @@ texinfo-current-defun-name
     (if (re-search-backward "^@node[ \t]+\\([^,\n]+\\)" nil t)
 	(match-string-no-properties 1))))
 
+;;; Flymake support
+(defvar-local texinfo--flymake-proc nil)
+(defun texinfo-flymake (report-fn &rest _)
+  "Texinfo checking for Flymake.
+
+REPORT-FN is the callback function."
+  (let ((executable (or (executable-find "makeinfo")
+                        (executable-find "texi2any")))
+        (source (current-buffer)))
+
+    (unless executable
+      (error "Flymake for Texinfo requires `makeinfo' or `texi2any'"))
+
+    (when (process-live-p texinfo--flymake-proc)
+      (kill-process texinfo--flymake-proc))
+
+    (save-restriction
+      (widen)
+      (setq texinfo--flymake-proc
+            (make-process
+             :name "texinfo-flymake"
+             :noquery t
+             :connection-type 'pipe
+             :buffer (generate-new-buffer " *texinfo-flymake*")
+             :command `(,executable "-o" ,null-device "-")
+             :sentinel
+             (lambda (proc _event)
+               (when (memq (process-status proc) '(exit signal))
+                 (unwind-protect
+                     (if (eq (buffer-local-value 'texinfo--flymake-proc
+                                                 source)
+                             proc)
+                         (with-current-buffer (process-buffer proc)
+                           (goto-char (point-min))
+                           (cl-loop
+                            while (search-forward-regexp
+                                   (rx line-start
+                                       "-:"
+                                       (group-n 1 (0+ digit)) ; Line
+                                       (optional ":" (group-n 2 (0+ digit))) ; col
+                                       ": "
+                                       (optional (group-n 3 "warning: ")) ; warn
+                                       (group-n 4 (0+ nonl)) ; Message
+                                       line-end)
+                                   nil t)
+                            for msg = (match-string 4)
+                            for (beg . end) = (flymake-diag-region
+                                               source
+                                               (string-to-number (match-string 1)))
+                            for type = (if (match-string 3)
+                                           :warning
+                                         :error)
+                            collect (flymake-make-diagnostic
+                                     source beg end type msg)
+                            into diags
+                            finally (funcall report-fn diags)))
+                       (flymake-log :warning "Cancelling obsolete check %s"
+                                    proc))
+                   (kill-buffer (process-buffer proc)))))))
+      (process-send-region texinfo--flymake-proc (point-min) (point-max))
+      (process-send-eof texinfo--flymake-proc))))
+
+
 ;;; Texinfo mode
 
 ;;;###autoload
@@ -455,7 +528,10 @@ texinfo-mode
 	      (let ((prevent-filling "^@\\(def\\|multitable\\)"))
 		(if (null auto-fill-inhibit-regexp)
 		    prevent-filling
-		  (concat auto-fill-inhibit-regexp "\\|" prevent-filling)))))
+		  (concat auto-fill-inhibit-regexp "\\|" prevent-filling))))
+
+  ;; Set up Flymake support.
+  (add-hook 'flymake-diagnostic-functions #'texinfo-flymake nil t))
 
 (defvar texinfo-fillable-commands '("@noindent")
   "A list of commands that can be filled.")
-- 
2.25.1


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

* bug#52342: [PATCH] Add Texinfo support for Flymake
  2021-12-19 16:17           ` Okamsn via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2022-01-04 20:21             ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2022-01-04 21:00               ` João Távora
  2022-04-16 21:59             ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
  1 sibling, 1 reply; 17+ messages in thread
From: Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2022-01-04 20:21 UTC (permalink / raw)
  To: Okamsn; +Cc: Stefan Kangas, João Távora, 52342

Sorry for this late answer, you got stuck in a slow lane :-(

> Do you have any thoughts about the lazy loading of Flymake features used
> in the patch discussed in this thread (re-attached for convenience)?

Looks fine to me.
[ The amount of work needed for `flymake-log` is a bit disheartening, tho.
  Not sure making it a macro is worth the trouble.  ]


        Stefan






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

* bug#52342: [PATCH] Add Texinfo support for Flymake
  2022-01-04 20:21             ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2022-01-04 21:00               ` João Távora
  2022-04-15  1:12                 ` Okamsn via Bug reports for GNU Emacs, the Swiss army knife of text editors
  0 siblings, 1 reply; 17+ messages in thread
From: João Távora @ 2022-01-04 21:00 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: Okamsn, Stefan Kangas, 52342

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

On Tue, Jan 4, 2022 at 8:21 PM Stefan Monnier <monnier@iro.umontreal.ca>
wrote:

> Sorry for this late answer, you got stuck in a slow lane :-(
>
> > Do you have any thoughts about the lazy loading of Flymake features used
> > in the patch discussed in this thread (re-attached for convenience)?
>
> Looks fine to me.
> [ The amount of work needed for `flymake-log` is a bit disheartening, tho.
>   Not sure making it a macro is worth the trouble.  ]


Yup, I wrote somewhere else that I think that part is a bit
over-enginneered.
The idea was/is to have it add the locus of the log call to the log entry.
But I don't remember ever having used that functionality.

So go ahead and make it an (autoloaded) function if you think it's best.

João

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

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

* bug#52342: [PATCH] Add Texinfo support for Flymake
  2022-01-04 21:00               ` João Távora
@ 2022-04-15  1:12                 ` Okamsn via Bug reports for GNU Emacs, the Swiss army knife of text editors
  0 siblings, 0 replies; 17+ messages in thread
From: Okamsn via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2022-04-15  1:12 UTC (permalink / raw)
  To: João Távora, Stefan Monnier; +Cc: Stefan Kangas, 52342

On 1/4/22 16:00, João Távora wrote:
> On Tue, Jan 4, 2022 at 8:21 PM Stefan Monnier <monnier@iro.umontreal.ca
> <mailto:monnier@iro.umontreal.ca>> wrote:
>
>     Sorry for this late answer, you got stuck in a slow lane :-(
>
>      > Do you have any thoughts about the lazy loading of Flymake
>     features used
>      > in the patch discussed in this thread (re-attached for convenience)?
>
>     Looks fine to me.
>     [ The amount of work needed for `flymake-log` is a bit
>     disheartening, tho.
>        Not sure making it a macro is worth the trouble.  ]
>
>
> Yup, I wrote somewhere else that I think that part is a bit
> over-enginneered.
> The idea was/is to have it add the locus of the log call to the log entry.
> But I don't remember ever having used that functionality.
>
> So go ahead and make it an (autoloaded) function if you think it's best.
>
> João

Hello,

Are you still willing to add this Flymake checker for Texinfo?

Thank you.






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

* bug#52342: [PATCH] Add Texinfo support for Flymake
  2021-12-19 16:17           ` Okamsn via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2022-01-04 20:21             ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2022-04-16 21:59             ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2022-09-08 14:25               ` Lars Ingebrigtsen
  1 sibling, 1 reply; 17+ messages in thread
From: Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2022-04-16 21:59 UTC (permalink / raw)
  To: Okamsn; +Cc: Stefan Kangas, João Távora, 52342

Hi Okamsn, (?)

Okamsn [2021-12-19 16:17:56] wrote:
> Do you have any thoughts about the lazy loading of Flymake features used
> in the patch discussed in this thread (re-attached for convenience)?

Okamsn [2022-04-15 01:12:21] wrote:
> Are you still willing to add this Flymake checker for Texinfo?

Sorry for dropping the ball: Yes!
I just pushed your patch to Emacs's `master` branch.
Thank you for your contribution,


        Stefan






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

* bug#52342: [PATCH] Add Texinfo support for Flymake
  2022-04-16 21:59             ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2022-09-08 14:25               ` Lars Ingebrigtsen
  0 siblings, 0 replies; 17+ messages in thread
From: Lars Ingebrigtsen @ 2022-09-08 14:25 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: Okamsn, Stefan Kangas, João Távora, 52342

Stefan Monnier <monnier@iro.umontreal.ca> writes:

> I just pushed your patch to Emacs's `master` branch.

(The bug report was left open, so I'm closing it now.)





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

end of thread, other threads:[~2022-09-08 14:25 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-07  2:48 bug#52342: [PATCH] Add Texinfo support for Flymake Okamsn via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-12-07 14:10 ` Stefan Kangas
2021-12-07 14:23   ` João Távora
2021-12-07 23:39     ` Okamsn via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-12-07 23:43       ` João Távora
2021-12-07 23:46         ` João Távora
2021-12-08  1:00           ` Okamsn via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-12-08  1:03             ` Okamsn via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-12-19 16:17           ` Okamsn via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-01-04 20:21             ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-01-04 21:00               ` João Távora
2022-04-15  1:12                 ` Okamsn via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-04-16 21:59             ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-09-08 14:25               ` Lars Ingebrigtsen
2021-12-08  0:50         ` Stefan Kangas
2021-12-10  1:40           ` Okamsn via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-12-10  2:07             ` Stefan Kangas

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).