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: Sat, 07 Oct 2017 16:40:11 +0200 Organization: Nautilus Entertainments Message-ID: <87376vxbqs.fsf@metapensiero.it> References: <87h8vmj3tr.fsf@lolita> <1507138648.1972.0@smtp.gmail.com> <874lre2von.fsf@gmail.com> <87mv566yjx.fsf@udel.edu> <87shex276r.fsf@gmail.com> <87efqh2sud.fsf@udel.edu> <877ew919hd.fsf@gmail.com> <87poa0z4ur.fsf@gmail.com> <83o9pjt6m8.fsf@gnu.org> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: blaine.gmane.org 1507387233 3465 195.159.176.226 (7 Oct 2017 14:40:33 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sat, 7 Oct 2017 14:40:33 +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 Sat Oct 07 16:40:28 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 1e0qHB-0008Jx-Ud for ged-emacs-devel@m.gmane.org; Sat, 07 Oct 2017 16:40:26 +0200 Original-Received: from localhost ([::1]:49965 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e0qHJ-0002sb-Cv for ged-emacs-devel@m.gmane.org; Sat, 07 Oct 2017 10:40:33 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:43045) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e0qHC-0002sU-46 for emacs-devel@gnu.org; Sat, 07 Oct 2017 10:40:27 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e0qH8-0007Jg-5k for emacs-devel@gnu.org; Sat, 07 Oct 2017 10:40:26 -0400 Original-Received: from [195.159.176.226] (port=39450 helo=blaine.gmane.org) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1e0qH7-0007Hf-O1 for emacs-devel@gnu.org; Sat, 07 Oct 2017 10:40:22 -0400 Original-Received: from list by blaine.gmane.org with local (Exim 4.84_2) (envelope-from ) id 1e0qGy-0006ox-2V for emacs-devel@gnu.org; Sat, 07 Oct 2017 16:40:12 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 177 Original-X-Complaints-To: usenet@blaine.gmane.org Cancel-Lock: sha1:4lGP/IzBn5znwqNurFTcQNJTVn8= 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:219221 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Eli Zaretskii writes: >> From: Stefan Monnier >> Date: Sat, 07 Oct 2017 09:28:04 -0400 >> >> > Yes, that is the natural way. But should it go into the emacs-26 branch? >> >> I'll let Eli&John decide. > > If it's just a Flymake back-end, and doesn't affect anything else > unless activated, I see no reason not to have it on the release > branch, assuming that its support in the version of Flymake on the > release branch is reasonably good. Great, I'll do my best to get there: current version of python-flymake, ameliorated with Noam's suggestions, works pretty well, and I'm right now trying it with customized settings so that it uses an alternative checker (flake8). However, I have a problem when using the new implementation in my real development context, that wasn't present before (before João work I was using python-flymake-pyflakes from ELPA). I use the `desktop' functionality, to keep a persistent state of open files, and in one project the `emacs.desktop' file has 367 entries, of which 284 are python-mode buffers: now when I open that project the python-flymake backend gets disabled with the following errors, for each python-mode buffer: Warning [flymake xxx.py]: Disabling backend python-flymake because (file-error Creating pipe Troppi file aperti) Warning [flymake xxx.py]: Disabling backend flymake-proc-legacy-flymake because (error Can find a suitable init function) where "Troppi file aperti" means "Too many open files". The mode-line of all those buffers tells that Flymake is in "Wait" status. I wonder if the problem is in the backend or rather in the new Flymake mechanism. Also, I will try to understand whether there could be a way to tell Flymake to run the checker only after the buffer has been modified, in other words to *not* run it on newly open files. Any hint on how to investigate the issue? I'm attaching below the current backend I'm trying out. Thanks&bye, lele. --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=python.diff diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index 9aa5134ca0..7328170a9b 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el @@ -5137,6 +5137,106 @@ python-util-valid-regexp-p (ignore-errors (string-match regexp "") t)) +;;; Flymake integration + +(defgroup python-flymake nil + "Integration between Python and Flymake." + :group 'python + :link '(custom-group-link :tag "Flymake" flymake) + :version "26.1") + +(defcustom python-flymake-command '("pyflakes") + "The external tool that will be used to perform the syntax check." + :group 'python-flymake + :type '(repeat string)) + +;; The default regexp accomodates for older pyflakes, which did not +;; report the column number +(defcustom python-flymake-command-output-regexp + "^\\(?:\\):\\(?1:[0-9]+\\):\\(?:\\(?2:[0-9]+\\):\\)? \\(?3:.*\\)$" + "The regexp used to parse the output of the specified tool. +It must contain two or three groups: group 1 is the line number, group 2 the +optional column number and the third is the actual message." + :group 'python-flymake + :type 'regexp) + +(defcustom python-flymake-msg-alist + '(("\\(^redefinition\\|.*unused.*\\|used$\\)" . :warning)) + "Alist used to associate messages to their types. +Each element should be a cons-cell (REGEXP . TYPE), where TYPE must be +one defined in the variable `flymake-diagnostic-types-alist'." + :group 'python-flymake + :type `(alist :key-type (regexp) + :value-type (symbol))) + ;; :value-type (choice + ;; (mapcar (lambda (type) + ;; (list 'const + ;; ':tag + ;; (capitalize + ;; (substring + ;; (symbol-name (car type)) + ;; 1 nil)) + ;; (car type))) + ;; flymake-diagnostic-types-alist)))) + ;; :value-type (choice (const :tag "Error" :error) + ;; (const :tag "Warning" :warning) + ;; (const :tag "Note" :note)))) + +(defvar-local python--flymake-proc nil) + +(defun python-flymake (report-fn &rest _args) + (unless (executable-find (car 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 python--flymake-proc) + (kill-process python--flymake-proc)) + + (let ((source (current-buffer))) + (save-restriction + (widen) + (setq python--flymake-proc + (make-process + :name "python-flymake" + :noquery t + :connection-type 'pipe + :buffer (generate-new-buffer " *python-flymake*") + :command python-flymake-command + :sentinel + (lambda (proc _event) + (unwind-protect + (when (eq proc python--flymake-proc) + (with-current-buffer (process-buffer proc) + (goto-char (point-min)) + (cl-loop + while (search-forward-regexp + python-flymake-command-output-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 = (or (assoc-default msg + python-flymake-msg-alist + #'string-match) + :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 python--flymake-proc (point-min) (point-max)) + (process-send-eof python--flymake-proc)))) + +(defun python-flymake-activate () + "Activate the Flymake syntax check on all python-mode buffers." + (add-hook 'flymake-diagnostic-functions #'python-flymake nil t)) + + (defun python-electric-pair-string-delimiter () (when (and electric-pair-mode (memq last-command-event '(?\" ?\')) --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit -- 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. --=-=-=--