Function: texinfo-flymake

texinfo-flymake is a byte-compiled function defined in texinfo.el.gz.

Signature

(texinfo-flymake REPORT-FN &rest _)

Documentation

Texinfo checking for Flymake.

It uses either "makeinfo" or "texi2any", in that order.

REPORT-FN is the callback function.

Source Code

;; Defined in /usr/src/emacs/lisp/textmodes/texinfo.el.gz
(defun texinfo-flymake (report-fn &rest _)
  "Texinfo checking for Flymake.

It uses either \"makeinfo\" or \"texi2any\", in that order.

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 "Canceling 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))))