[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Flymake refactored

From: Mark Oteiza
Subject: Re: Flymake refactored
Date: Thu, 05 Oct 2017 17:22:02 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.60 (gnu/linux)

address@hidden (João Távora) writes:

> Mark Oteiza <address@hidden> writes:
>> I also seem to have problems using the column number (match-string 2)
>> and so it is left unused.
> The problem is that you are calling flymake-diag-region in the wrong
> buffer. It has to be the source buffer, so in your case you need a
> (with-current-buffer source ...) around it.
> But that inconvenience has been fixed in the very latest code emacs-26
> branch. In that version, you just pass 'source' (the c/c++ buffer) to
> flymake-diag-region.

Ah, thank you.

> I've built a backend very similar to yours but base on gcc (clang is
> 500MB and no time for that right now). Have a look, below my sig.

Nice.  Adding to the pile, a LaTeX checker with chktex below.

> I've also noticed, there's a lot of repetition building up in these
> examples. Later it's probably useful to invent an abstraction that hides
> it away.

At first sight it looks like the much of the sentinel contents could be
abstracted away in something like compilation mode's error regexp alists

;;; flymake-chktex.el --- Flymake backend for chktex(1) -*- lexical-binding: t 

;;; Code:

(defgroup flymake-chktex ()
  "Flymake backend for chktex"
  :link '(url-link "http://www.nongnu.org/chktex/";)
  :group 'flymake)

(defcustom flymake-chktex-program "chktex"
  :type 'string
  :group 'flymake-chktex)

(defvar-local flymake-chktex--process nil)

(defun flymake-chktex-command (program)
  `(,program "--quiet" "--verbosity=0" "--inputfiles"))

(defun flymake-chktex (report-fn &rest _args)
  (unless (executable-find flymake-chktex-program)
    (error "Cannot find a suitable chktex"))
  (when (process-live-p flymake-chktex--process)
    (kill-process flymake-chktex--process))
  (let ((source (current-buffer)))
      (setq flymake-chktex--process
             :name "flymake-chktex"
             :buffer (generate-new-buffer "*flymake-chktex*")
             :command (flymake-chktex-command flymake-chktex-program)
             :noquery t :connection-type 'pipe
             (lambda (process _event)
                   (when (eq process flymake-chktex--process)
                     (with-current-buffer (process-buffer process)
                       (goto-char (point-min))
                        while (search-forward-regexp
                               nil t)
                        for msg = (match-string 4)
                        for (beg . end) = (flymake-diag-region source
(string-to-number (match-string 1))
(string-to-number (match-string 2)))
                        collect (flymake-make-diagnostic source beg end 
:warning msg)
                        into diags
                        finally (funcall report-fn diags))))
                 (kill-buffer (process-buffer process))))))
      (process-send-region flymake-chktex--process (point-min) (point-max))
      (process-send-eof flymake-chktex--process))))

(defun flymake-chktex-register ()
  (add-hook 'flymake-diagnostic-functions 'flymake-chktex nil t))

(add-hook 'plain-tex-mode-hook 'flymake-chktex-register)
(add-hook 'latex-mode-hook 'flymake-chktex-register)
(add-hook 'bibtex-mode-hook 'flymake-chktex-register)

(provide 'flymake-chktex)

;;; flymake-chktex.el ends here

reply via email to

[Prev in Thread] Current Thread [Next in Thread]