unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: joaotavora@gmail.com (João Távora)
To: Dmitry Gutov <dgutov@yandex.ru>
Cc: Mark Oteiza <mvoteiza@udel.edu>,
	Lele Gaifax <lele@metapensiero.it>,
	Stefan Monnier <monnier@iro.umontreal.ca>,
	emacs-devel@gnu.org
Subject: Re: Three Flymake backends Was Re: Two issues with the new Flymake
Date: Sun, 05 Nov 2017 21:05:50 +0000	[thread overview]
Message-ID: <87k1z4qvv5.fsf@gmail.com> (raw)
In-Reply-To: <829794de-27ca-383e-2b3a-a5bc4405581b@yandex.ru> (Dmitry Gutov's message of "Sun, 5 Nov 2017 22:14:48 +0200")

Dmitry Gutov <dgutov@yandex.ru> writes:

> On 11/5/17 3:22 PM, João Távora wrote:
>
>> I think the doors are still open for the "sooner" case :-) I don't have
>> rubucop, but defining new backends of the
>> "feed-to-stdin-then-parse-with-regexp" type is really easy (and of
>> really verbose, but we're trying to fix that)
>
> OK, I'll keep that in mind. :)

FWIW I installed it and quickly hacked up this. It's the same
boilerplate again, with the tiny exception that rubocop needs the file
to be also saved for some reason (pure stdin doesn't work for some
reason).

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

(defun rubocop-flymake (report-fn &rest _args)
  "Rubocop backend"
  (unless (executable-find "rubocop")
    (error "Cannot find a suitable checker"))

  (when (process-live-p rubocop--flymake-proc)
    (kill-process rubocop--flymake-proc))

  (let ((source (current-buffer)))
    (when buffer-file-name
      (save-restriction
        (widen)
        (setq
         rubocop--flymake-proc
         (make-process
          :name "rubocop-flymake" :noquery t :connection-type 'pipe
          :buffer (generate-new-buffer " *rubocop-flymake*")
          :command `("rubocop" "--stdin" ,buffer-file-name "--format" "emacs")
          :sentinel
          (lambda (proc _event)
            (when (eq 'exit (process-status proc))
              (unwind-protect
                  (if (with-current-buffer source (eq proc rubocop--flymake-proc))
                      (with-current-buffer (process-buffer proc)
                        (goto-char (point-min))
                        (cl-loop
                         while (search-forward-regexp
                                "^\\(?:.*.rb\\|-\\):\\([0-9]+\\):\\([0-9]+\\): \\(.*\\)$"
                                nil t)
                         for msg = (match-string 3)
                         for (beg . end) = (flymake-diag-region
                                            source
                                            (string-to-number (match-string 1))
                                            (string-to-number (match-string 2)))
                         for type = (if (string-match "^E: " msg)
                                        :error
                                      :note)
                         collect (flymake-make-diagnostic source
                                                          beg
                                                          end
                                                          type
                                                          msg)
                         into diags
                         finally (funcall report-fn diags)))
                    (flymake-log :debug "Canceling obsolete check %s"
                                 proc))
                (kill-buffer (process-buffer proc)))))))
        (process-send-region rubocop--flymake-proc (point-min) (point-max))
        (process-send-eof rubocop--flymake-proc)))))


> The defalias way should be all right with remove-hook, though.

Yes, and exposing the function that returns the lambda is also OK.

> I'm in the "don't create new macros unless it's _really_ beneficial"
> camp, though it might be in the minority here.

I'm with you on that camp. However macros that create functions or
defmethod, if done in the standard fashion, almost always escape that
razor.




  reply	other threads:[~2017-11-05 21:05 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-03  9:50 Two issues with the new Flymake Lele Gaifax
2017-11-03 12:33 ` Stefan Monnier
2017-11-03 14:07   ` Lele Gaifax
2017-11-03 16:59     ` João Távora
2017-11-03 17:15       ` Stefan Monnier
2017-11-03 20:17 ` Three Flymake backends Was " João Távora
2017-11-04 15:30   ` Stefan Monnier
2017-11-04 23:17     ` João Távora
2017-11-05 12:50   ` Dmitry Gutov
2017-11-05 12:59     ` João Távora
2017-11-05 13:04       ` Dmitry Gutov
2017-11-05 13:22         ` João Távora
2017-11-05 20:14           ` Dmitry Gutov
2017-11-05 21:05             ` João Távora [this message]
2017-11-05 23:56               ` Dmitry Gutov
2017-11-06  9:48                 ` João Távora
2017-11-06 10:35                   ` Dmitry Gutov
2017-11-06 11:08                     ` João Távora
2017-11-13  0:23                       ` Dmitry Gutov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87k1z4qvv5.fsf@gmail.com \
    --to=joaotavora@gmail.com \
    --cc=dgutov@yandex.ru \
    --cc=emacs-devel@gnu.org \
    --cc=lele@metapensiero.it \
    --cc=monnier@iro.umontreal.ca \
    --cc=mvoteiza@udel.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).