emacs-devel
[Top][All Lists]
Advanced

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

Re: Flymake refactored


From: Mark Oteiza
Subject: Re: Flymake refactored
Date: Wed, 04 Oct 2017 23:52:50 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.60 (gnu/linux)

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

> For example, here's a decent Ruby checker under 40 lines that does the
> same as MELPA's flymake-ruby.el (which is based on flymake-easy), but
> using the new API and without creating any temporary files.

Modeled after your example and bits from flycheck[0] and syntastic[1], I
have attached humble beginnings to a clang checker (errors only).

Something is probably very broken, as using it to check Emacs C at this
point triggers the following:

  funcall-interactively: binding stack not balanced (serious byte compiler bug)

I also seem to have problems using the column number (match-string 2)
and so it is left unused.

[0]: http://www.flycheck.org/en/latest/
[1]: https://github.com/vim-syntastic/syntastic

(defvar clang-program "clang")

(defvar-local clang--flymake-proc nil)

(defun clang-flymake (report-fn &rest _args)
  (unless (executable-find clang-program)
    (error "Cannot find a suitable clang"))
  (when (process-live-p clang--flymake-proc)
    (kill-process clang--flymake-proc))
  (let ((source (current-buffer)))
    (save-restriction
      (widen)
      (setq clang--flymake-proc
            (make-process
             :name "clang-flymake"
             :buffer (generate-new-buffer "*clang-flymake*")
             :command `(,clang-program
                        "-fsyntax-only" "-Weverything"
                        "-fno-color-diagnostics"
                        "-fno-caret-diagnostics"
                        "-fno-diagnostics-show-option"
                        "-x" "c" "-")
             :noquery t :connection-type 'pipe
             :sentinel
             (lambda (p _ev)
               (unwind-protect
                   (with-current-buffer (process-buffer p)
                     (goto-char (point-min))
                     (cl-loop
                      while (search-forward-regexp
                             (rx bol (or "<stdin>" (eval (or (buffer-file-name) 
"")))
                                 ":" (group-n 1 (+ digit)) ":" (group-n 2 (+ 
digit))
                                 ": " (or "fatal error" "error")
                                 ": " (group-n 3 (? (* anything))) eol)
                             nil t)
                      for msg = (match-string 3)
                      for (beg . end) = (flymake-diag-region
                                         (string-to-number (match-string 1)))
                      for type = :error
                      collect (flymake-make-diagnostic source beg end type msg)
                      into diags
                      finally (funcall report-fn diags)))
                 ;; (message "%S"
                 ;;          (with-current-buffer (process-buffer p)
                 ;;            (buffer-string)))
                 (kill-buffer (process-buffer p)))
               )))
      (process-send-region clang--flymake-proc (point-min) (point-max))
      (process-send-eof clang--flymake-proc))))

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

(add-hook 'c-mode-hook 'clang-flymake-register)





reply via email to

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