From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Lele Gaifax Newsgroups: gmane.emacs.devel Subject: Re: Flymake refactored Date: Thu, 05 Oct 2017 13:28:46 +0200 Organization: Nautilus Entertainments Message-ID: <87r2uh3kb5.fsf@metapensiero.it> References: <87h8vmj3tr.fsf@lolita> <1507138648.1972.0@smtp.gmail.com> <874lre2von.fsf@gmail.com> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: blaine.gmane.org 1507202947 23983 195.159.176.226 (5 Oct 2017 11:29:07 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Thu, 5 Oct 2017 11:29:07 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.60 (gnu/linux) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Oct 05 13:29:03 2017 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e04Kt-0005hK-CF for ged-emacs-devel@m.gmane.org; Thu, 05 Oct 2017 13:29:03 +0200 Original-Received: from localhost ([::1]:39160 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e04L0-0001YL-LW for ged-emacs-devel@m.gmane.org; Thu, 05 Oct 2017 07:29:10 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:40154) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e04Kt-0001Y1-K7 for emacs-devel@gnu.org; Thu, 05 Oct 2017 07:29:04 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e04Kq-0003ka-VV for emacs-devel@gnu.org; Thu, 05 Oct 2017 07:29:03 -0400 Original-Received: from [195.159.176.226] (port=54410 helo=blaine.gmane.org) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1e04Kq-0003j4-NW for emacs-devel@gnu.org; Thu, 05 Oct 2017 07:29:00 -0400 Original-Received: from list by blaine.gmane.org with local (Exim 4.84_2) (envelope-from ) id 1e04Kc-0004A4-Rq for emacs-devel@gnu.org; Thu, 05 Oct 2017 13:28:46 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 94 Original-X-Complaints-To: usenet@blaine.gmane.org Cancel-Lock: sha1:DaqQ4BFa1VuueoJO18V7XXPr8Po= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 195.159.176.226 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:219117 Archived-At: joaotavora@gmail.com (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. Thank you João for the example, I'm attaching below my Python pyflakes variant, that seems working pretty well. I have a couple of questions: a) I had to use lexical-binding, otherwise the funcall form in the inner lambda raises an error about report-fn being undefined; did I miss something, or is that the right thing to do? b) I had to omit the "local" flag when hooking esk/python-flymake to flymake-diagnostic-functions as you did in the example: shouldn't the latter be a defvar-local variable? Thanks in advance, ciao, lele. ;; excerpt from my .emacs.d/esk/python.el -- -*- lexical-binding:t -*- ;; ;; TODO: Maybe defcustom the following two? (defvar esk/python-flymake-command '("python3.6" "-m" "pyflakes")) (defvar esk/python-flymake-warning-regexp "\\(^redefinition\\|.*unused.*\\|used$\\)") (defvar-local esk/python--flymake-proc nil) ;; Explicitly use Python 3.6, to handle f-strings (defvar esk/python-flymake-command '("python3.6" "-m" "pyflakes")) ;; Accomodate for older pyflakes, which did not report the column number (defvar esk/python-flymake-diag-regexp "^\\(?:.*\\.p[yj]\\|\\):\\([0-9]+\\):\\(?:\\([0-9]+\\):\\)? \\(.*\\)$") ;; Recognize warning messages (defvar esk/python-flymake-warn-msg-regexp "\\(^redefinition\\|.*unused.*\\|used$\\)") (defvar-local esk/python--flymake-proc nil) (defun esk/python-flymake (report-fn &rest _args) (unless (executable-find (car esk/python-flymake-command)) (error "Cannot find a suitable checker")) (unless (derived-mode-p 'python-mode) (error "Can only work on `python-mode' buffers")) (when (process-live-p esk/python--flymake-proc) (kill-process esk/python--flymake-proc)) (let ((source (current-buffer))) (save-restriction (widen) (setq esk/python--flymake-proc (make-process :name "python-flymake" :noquery t :connection-type 'pipe :buffer (generate-new-buffer " *python-flymake*") :command esk/python-flymake-command :sentinel (lambda (proc _event) (unwind-protect (with-current-buffer (process-buffer proc) (goto-char (point-min)) (cl-loop while (search-forward-regexp esk/python-flymake-diag-regexp nil t) for msg = (match-string 3) for (beg . end) = (flymake-diag-region source (string-to-number (match-string 1)) (and (match-string 2) (string-to-number (match-string 2)))) for type = (if (string-match esk/python-flymake-warn-msg-regexp msg) :warning :error) collect (flymake-make-diagnostic source beg end type msg) into diags finally (funcall report-fn diags))) (kill-buffer (process-buffer proc)))))) (process-send-region esk/python--flymake-proc (point-min) (point-max)) (process-send-eof esk/python--flymake-proc)))) (add-hook 'flymake-diagnostic-functions #'esk/python-flymake) (add-hook 'python-mode-hook #'flymake-mode-on) -- nickname: Lele Gaifax | Quando vivrò di quello che ho pensato ieri real: Emanuele Gaifas | comincerò ad aver paura di chi mi copia. lele@metapensiero.it | -- Fortunato Depero, 1929.