Function: lua-flymake

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

Signature

(lua-flymake REPORT-FN &rest ARGS)

Documentation

Flymake backend using the luacheck program.

Takes a Flymake callback REPORT-FN as argument, as expected of a member of flymake-diagnostic-functions.

Source Code

;; Defined in /usr/src/emacs/lisp/progmodes/lua-mode.el.gz
(defun lua-flymake (report-fn &rest _args)
  "Flymake backend using the luacheck program.
Takes a Flymake callback REPORT-FN as argument, as expected of a
member of `flymake-diagnostic-functions'."
  (when (process-live-p lua--flymake-process)
    (kill-process lua--flymake-process))
  (let ((source (current-buffer)))
    (save-restriction
      (widen)
      (setq lua--flymake-process
            (make-process
             :name "luacheck" :noquery t :connection-type 'pipe
             :buffer (generate-new-buffer " *flymake-luacheck*")
             :command `(,lua-luacheck-program
                        "--codes" "--ranges" "--formatter" "plain" "-")
             :sentinel
             (lambda (proc _event)
               (when (eq 'exit (process-status proc))
                 (unwind-protect
                     (if (with-current-buffer source
                           (eq proc lua--flymake-process))
                         (with-current-buffer (process-buffer proc)
                           (goto-char (point-min))
                           (cl-loop
                            while (search-forward-regexp
                                   "^\\([^:]*\\):\\([0-9]+\\):\\([0-9]+\\)-\\([0-9]+\\): \\(.*\\)$"
                                   nil t)
                            for line = (string-to-number (match-string 2))
                            for col1 = (string-to-number (match-string 3))
                            for col2 = (1+ (string-to-number (match-string 4)))
                            for msg = (match-string 5)
                            for type = (if (string-match-p "\\`(E" msg) :error :warning)
                            collect (flymake-make-diagnostic source
                                                             (cons line col1)
                                                             (cons line col2)
                                                             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 lua--flymake-process (point-min) (point-max))
      (process-send-eof lua--flymake-process))))