From debbugs-submit-bounces@debbugs.gnu.org Fri Oct 13 05:54:35 2017 Received: (at submit) by debbugs.gnu.org; 13 Oct 2017 09:54:36 +0000 Received: from localhost ([127.0.0.1]:36899 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e2wfr-0000YW-Gz for submit@debbugs.gnu.org; Fri, 13 Oct 2017 05:54:35 -0400 Received: from eggs.gnu.org ([208.118.235.92]:58677) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e2wfp-0000YK-Lg for submit@debbugs.gnu.org; Fri, 13 Oct 2017 05:54:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e2wfi-0005GH-Pg for submit@debbugs.gnu.org; Fri, 13 Oct 2017 05:54:28 -0400 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=0.8 required=5.0 tests=BAYES_50 autolearn=disabled version=3.3.2 Received: from lists.gnu.org ([2001:4830:134:3::11]:49254) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e2wfi-0005GD-Ll for submit@debbugs.gnu.org; Fri, 13 Oct 2017 05:54:26 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49643) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e2wfg-00033Z-LW for bug-gnu-emacs@gnu.org; Fri, 13 Oct 2017 05:54:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e2wfd-0005CY-IQ for bug-gnu-emacs@gnu.org; Fri, 13 Oct 2017 05:54:24 -0400 Received: from mail.arstecnica.it ([144.76.81.238]:40550) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e2wfd-0005B0-7c for bug-gnu-emacs@gnu.org; Fri, 13 Oct 2017 05:54:21 -0400 Received: from nautilus (assp.arstecnica.it [192.168.1.102]) by mail.arstecnica.it (Postfix) with ESMTPSA id 8C63A83EC71 for ; Fri, 13 Oct 2017 09:54:14 +0000 (UTC) Received: from nautilus ([31.44.165.109] helo=nautilus) by assp.arstecnica.it with SMTPS(AES256-GCM-SHA384) (2.3.3); 13 Oct 2017 09:54:13 +0000 From: Lele Gaifax To: bug-gnu-emacs@gnu.org Subject: [PATCH] Implement Python backend for Flymake Date: Fri, 13 Oct 2017 11:54:13 +0200 Message-ID: <87lgkf2x16.fsf@metapensiero.it> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Assp-Version: 2.3.3(14029) on assp.arstecnica.it X-Assp-ID: assp.arstecnica.it m1-88454-03815 X-Assp-Session: A71666BC (mail 1) X-Assp-Envelope-From: lele@metapensiero.it X-Assp-Intended-For: bug-gnu-emacs@gnu.org X-Assp-Client-TLS: yes X-Assp-Server-TLS: yes X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 2001:4830:134:3::11 X-Spam-Score: -4.1 (----) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -4.1 (----) --=-=-= Content-Type: text/plain Hi, here below you can find an implementation of a Python backend for the new Flymake facility. I'm quite satisfied by it: I tested both the default settings (targeting `pyflakes') and the `flake8' customization suggested in the docstrings. As always, I'm willing to apply whatever tweak/fix you may find reasonable. Thanks a lot, ciao, lele. --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-Fix-typo.patch >From 16828afebe3e732e3cbf856b093dfff65d3319ff Mon Sep 17 00:00:00 2001 From: Lele Gaifax Date: Fri, 13 Oct 2017 10:43:13 +0200 Subject: [PATCH 1/2] Fix typo --- lisp/progmodes/flymake.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lisp/progmodes/flymake.el b/lisp/progmodes/flymake.el index 8c9c4b211a..8fa763a4b8 100644 --- a/lisp/progmodes/flymake.el +++ b/lisp/progmodes/flymake.el @@ -124,7 +124,7 @@ flymake-gui-warnings-enabled "it no longer has any effect." "26.1") (defcustom flymake-start-on-flymake-mode t - "Start syntax check when `flymake-mode'is enabled. + "Start syntax check when `flymake-mode' is enabled. Specifically, start it when the buffer is actually displayed." :type 'boolean) -- 2.15.0.rc0 --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0002-Add-a-Flymake-backend-for-Python.patch >From 84a4dd4ef7a6ae9e49cb7442070744b5d6e3ec95 Mon Sep 17 00:00:00 2001 From: Lele Gaifax Date: Fri, 13 Oct 2017 10:44:02 +0200 Subject: [PATCH 2/2] Add a Flymake backend for Python * lisp/progmodes/python.el: Implement new Flymake backend with related customizable settings. (python-flymake-command, python-flymake-command-output-regexp, python-flymake-msg-alist): New defcustom. (python-flymake): New function. (python-flymake-activate): New function. --- lisp/progmodes/python.el | 101 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index f79d9a47d3..866e02ffbd 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el @@ -5141,6 +5141,107 @@ 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. +This is a non empty list of strings, the checker tool possibly followed by +required arguments: to use `flake8' you would set this to (\"flake8\" \"-\")." + :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'. +For example, when using `flake8' a possible configuration could be: + + ((\"\\(^redefinition\\|.*unused.*\\|used$\\)\" . :warning) + (\"^E999\" . :error) + (\"^[EW][0-9]+\" . :note)) + +By default messages are considered errors." + :group 'python-flymake + :type `(alist :key-type (regexp) + :value-type (symbol))) + +(defvar-local python--flymake-proc nil) + +(defun python-flymake (report-fn &rest _args) + "Flymake backend for Python. +This backend uses `python-flymake-command' (which see) to launch a process +that is passed the current buffer's content via stdin. +REPORT-FN is Flymake's callback function." + (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) + (when (eq 'exit (process-status proc)) + (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 '(?\" ?\')) -- 2.15.0.rc0 --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable --=20 nickname: Lele Gaifax | Quando vivr=C3=B2 di quello che ho pensato ieri real: Emanuele Gaifas | comincer=C3=B2 ad aver paura di chi mi copia. lele@metapensiero.it | -- Fortunato Depero, 1929. --=-=-=-- From debbugs-submit-bounces@debbugs.gnu.org Fri Oct 13 17:03:58 2017 Received: (at 28808) by debbugs.gnu.org; 13 Oct 2017 21:03:58 +0000 Received: from localhost ([127.0.0.1]:38491 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e377d-0004n4-VT for submit@debbugs.gnu.org; Fri, 13 Oct 2017 17:03:58 -0400 Received: from mail-wr0-f171.google.com ([209.85.128.171]:56762) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e377c-0004mr-JG for 28808@debbugs.gnu.org; Fri, 13 Oct 2017 17:03:57 -0400 Received: by mail-wr0-f171.google.com with SMTP id r79so1865578wrb.13 for <28808@debbugs.gnu.org>; Fri, 13 Oct 2017 14:03:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version:content-transfer-encoding; bh=MIgGExUsuZNeTxMTRr+lsdYufKzAaFcxkgB3QY454Ro=; b=GtlpcGBrsbIfIsWJDj5rKhryQBmDJTDIpJS5pcfjGRqmAem1rpkufjTkAsC5zW6w5s Yp6FI3W0pNi1QQjKlYumGZR9q1HX9fgctHJs6cgxnVkvCzGuAGtjh5US/gcG1zRIdEI3 fOiKJckuO4X3T4Y18CdPaisy+O5KrB5IzkPDgF4lQ1JC+ntXtLcnkxHKQKjf2AwOcLGr zove8mTykF0ek9BWpDObZX42Cy/iQvqVRz0vFVRtEoATLmIE3TaiyjJUVIpUYcYKG7Fw IMGxULzhmUbyZcWlo5OXtWZos4cTj1IyeX4lPwamwy0bORFTq8GQidTzV4NQHjf/BLN9 CPhw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version:content-transfer-encoding; bh=MIgGExUsuZNeTxMTRr+lsdYufKzAaFcxkgB3QY454Ro=; b=FsOGSvIBU9L+AJDjWYXviWUTuC3r40ElPJZlP4YyQX694LLueW2kef/c+av8E9EZMR nkwcoJbHi0cLb8qI299piGk6Dj+btdQ9YsueKdrr2b2a39WZe9RhyIPZNT5hTCjHZOfo DCQ2Y9pqDUXvqonzE+ncIX01K1/0ar3JwVMz2CGrJ4FDQdb+Gy+9joaiFW02pBvvbe+E ULaoIV8jwpi7RQucy7xk2Upccc3AzqcudZ0t3wWIMM8WBYe1H6xt2g8PmgEaZrEDJOsw bxY4zybHrlE6ldV/GorhpiEWAxhFdvjuYIdq8bz8gdWT5t3IVCmM81qIvQcofwpzau81 r4og== X-Gm-Message-State: AMCzsaXqU7Iz3cyf5BPclxoppyHnZgnvPvgJR8hzTJhwfJJ2xgLW6sBg TV7hgSr9evviFfRFwa/V5kRnx/hFdHk= X-Google-Smtp-Source: AOwi7QDlTynoKa4qb/+OcaU/e1VZCgY86nQGoAYWHZ4P6B1xdWdUfq1rgfdjHCZ6XESKp0HApazDXQ== X-Received: by 10.223.178.26 with SMTP id u26mr2530547wra.239.1507928630783; Fri, 13 Oct 2017 14:03:50 -0700 (PDT) Received: from lolita.yourcompany.com (188.139.62.94.rev.vodafone.pt. [94.62.139.188]) by smtp.gmail.com with ESMTPSA id b11sm3130300wrd.91.2017.10.13.14.03.49 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 13 Oct 2017 14:03:50 -0700 (PDT) From: joaotavora@gmail.com (=?utf-8?B?Sm/Do28gVMOhdm9yYQ==?=) To: Lele Gaifax Subject: Re: [PATCH] Implement Python backend for Flymake References: <87bmlan4w6.fsf@gmail.com> Date: Fri, 13 Oct 2017 22:03:47 +0100 In-Reply-To: (GNU bug Tracking System's message of "Fri, 13 Oct 2017 20:57:04 +0000") Message-ID: <87zi8ulpzg.fsf_-_@gmail.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.90 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -2.8 (--) X-Debbugs-Envelope-To: 28808 Cc: 28808@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.8 (--) [ Sorry Lele if you're getting this twice, I mistankenly created another bug #28821, let's continue here ] Hi Lele, Here are some comments: Lele Gaifax writes: > +(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. > +This is a non empty list of strings, the checker tool possibly followed = by > +required arguments: to use `flake8' you would set this to (\"flake8\" \"= -\")." > I wonder if you shouldn't mention here that the command produced should, once invoked, check (a file? a chunk?) of python source code passed to it via its standard input. > + :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." A common trick here that old flymake (and also compile.el) use is to define the variable's value as list (REGEXP LINE COLUMN TYPE MESSAGE). REGEXP is mandatory. LINE, COLUMN, TYPE and MESSAGE are non-negative integer numbers designating regexp groups, or nil. In the latter case it means the regexp cannot capture that entity. So in your case it would become (defcustom python-flymake-command-output-regexp (list "^\\(?:\\):\\(?1:[0-9]+\\):\\(?:\\(?2:[0-9]+\\):\\)? \\(?3:.*\\)= $" 1 2 nil 3) "docstring" :group 'python-flymake :type '(list string (choice integer symbol) (choice integer symbol) (choice integer symbol) (choice integer symbol))) Perhaps TYPE does not make much sense currently. But it would match slightly better with compilation-error-regexp-alist in the future (which you should see). > + (unless (derived-mode-p 'python-mode) > + (error "Can only work on `python-mode' buffers")) Stefan and I arrived at the conclusion that this is cruft and isn't needed.=20 > +(defun python-flymake-activate () Rename this to python--flymake-setup, because "activation" is actually enabling flymake-mode. Also, I think you should add an autoload cookie to python--flymake-setup and then call that function from the end of python-mode. The > + "Activate the Flymake syntax check on all python-mode buffers." > + (add-hook 'flymake-diagnostic-functions #'python-flymake nil t)) I'd use 'python-flymake instead of #'python-flymake in add-hook, but I can't offer a sound reason why :-) Jo=C3=A3o From debbugs-submit-bounces@debbugs.gnu.org Sat Oct 14 04:16:04 2017 Received: (at 28808) by debbugs.gnu.org; 14 Oct 2017 08:16:04 +0000 Received: from localhost ([127.0.0.1]:38755 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e3Hc2-0002Kw-35 for submit@debbugs.gnu.org; Sat, 14 Oct 2017 04:16:02 -0400 Received: from mail.arstecnica.it ([144.76.81.238]:37435) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e3Hc0-0002KY-6j for 28808@debbugs.gnu.org; Sat, 14 Oct 2017 04:16:01 -0400 Received: from nautilus (assp.arstecnica.it [192.168.1.102]) by mail.arstecnica.it (Postfix) with ESMTPSA id 51BF283ED58; Sat, 14 Oct 2017 08:15:52 +0000 (UTC) Received: from nautilus ([31.44.165.109] helo=nautilus) by assp.arstecnica.it with SMTPS(AES256-GCM-SHA384) (2.3.3); 14 Oct 2017 08:15:51 +0000 From: Lele Gaifax To: =?utf-8?B?Sm/Do28gVMOhdm9yYQ==?= Subject: Re: [PATCH] Implement Python backend for Flymake In-Reply-To: <87zi8ulpzg.fsf_-_@gmail.com> References: <87bmlan4w6.fsf@gmail.com> <87zi8ulpzg.fsf_-_@gmail.com> Date: Sat, 14 Oct 2017 10:15:51 +0200 Message-ID: <877evyywjs.fsf@metapensiero.it> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Assp-Version: 2.3.3(14029) on assp.arstecnica.it X-Assp-ID: assp.arstecnica.it m1-68952-05458 X-Assp-Session: B19D25A8 (mail 1) X-Assp-Envelope-From: lele@metapensiero.it X-Assp-Intended-For: 28808@debbugs.gnu.org X-Assp-Intended-For: joaotavora@gmail.com X-Assp-Client-TLS: yes X-Assp-Server-TLS: yes X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 28808 Cc: 28808@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.0 (/) Thank you Jo=C3=A3o! joaotavora@gmail.com (Jo=C3=A3o T=C3=A1vora) writes: >> +(defcustom python-flymake-command '("pyflakes") >> + "The external tool that will be used to perform the syntax check. >> +This is a non empty list of strings, the checker tool possibly followed= by >> +required arguments: to use `flake8' you would set this to (\"flake8\" \= "-\")." >> > I wonder if you shouldn't mention here that the command produced should, > once invoked, check (a file? a chunk?) of python source code passed to > it via its standard input. Ok, done. >> +(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." > > A common trick here that old flymake (and also compile.el) use is to > define the variable's value as list (REGEXP LINE COLUMN TYPE > MESSAGE). I will try to better understand this, as I failed to see the benefit of add= ing that indirection... maybe the compile.el functionality is older than the ability to use explicit group numbers in the regexp? >> + (unless (derived-mode-p 'python-mode) >> + (error "Can only work on `python-mode' buffers")) > > Stefan and I arrived at the conclusion that this is cruft and isn't > needed.=20 Ok, removed. >> +(defun python-flymake-activate () > > Rename this to python--flymake-setup, because "activation" is actually > enabling flymake-mode. Ok, done. > Also, I think you should add an autoload cookie > to python--flymake-setup and then call that function from the end of > python-mode. The I'm curious here: why the need of autoload cookie, if the (only?) caller si= te lives in the very same source file? And if that's not only caller, why mark= ing it private with the double dash? More importantly: if we unconditionally activate the Flymake feature, inste= ad of being an user's choice, then the python--flymake-setup function may go away, and the add-hook moved inside the python-mode function, it already contains lot of those... >> + "Activate the Flymake syntax check on all python-mode buffers." >> + (add-hook 'flymake-diagnostic-functions #'python-flymake nil t)) > > I'd use 'python-flymake instead of #'python-flymake in add-hook, but I > can't offer a sound reason why :-) Well, my habit is different here, and it's also the convention used by the rest of python.el, so I will leave that as is. See http://endlessparentheses.com/get-in-the-habit-of-using-sharp-quote.html for what I considered a "sound reason" :) ciao, lele. --=20 nickname: Lele Gaifax | Quando vivr=C3=B2 di quello che ho pensato ieri real: Emanuele Gaifas | comincer=C3=B2 ad aver paura di chi mi copia. lele@metapensiero.it | -- Fortunato Depero, 1929. From debbugs-submit-bounces@debbugs.gnu.org Sat Oct 14 05:14:42 2017 Received: (at 28808) by debbugs.gnu.org; 14 Oct 2017 09:14:42 +0000 Received: from localhost ([127.0.0.1]:38822 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e3IWn-0003mE-Qz for submit@debbugs.gnu.org; Sat, 14 Oct 2017 05:14:42 -0400 Received: from mail-wm0-f54.google.com ([74.125.82.54]:52759) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e3IWm-0003m1-78 for 28808@debbugs.gnu.org; Sat, 14 Oct 2017 05:14:40 -0400 Received: by mail-wm0-f54.google.com with SMTP id k4so25576302wmc.1 for <28808@debbugs.gnu.org>; Sat, 14 Oct 2017 02:14:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=idX8iv0XCO86IhYCXkiXY7Qlpr1wmIxEaZmWnEVpo60=; b=s8Ro9asuDLCuHGhq0v4hztNatt5pWtoCoj1ChbsFFWHn+UhfCRp8QntGQ601IvrSfR tYJqgfzduqnee8CKpdeWhrd+/1mvSLldJwufbf9WHfQ9kfMy4dgsBKQV0GYHZTpk3U6Z Q2P3TYzygVqQtpxe3Oi8XtAEw8fe1wAI+UziRFt0LB8lXe3dSX3VTBsMDNDM6AWwFkD2 wddBNIgi3hqWI161WftupOhnnfCzDjMVOKZt6Y+iN8w5PT49Nj2jcni3lPViyrA8yy2+ KAzRYJ4hpjBXlHTWVWBwS8CRmtleJeejhgr8ccz7RM9RV/Qnoby3WyCuHsFcfM9YYwyF DTRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version; bh=idX8iv0XCO86IhYCXkiXY7Qlpr1wmIxEaZmWnEVpo60=; b=r/YGqOKw8uFzrs7nhnVpqLFpYpr+x4c1y8LqQgUna2DbKM3bh440PzTgNLRzm66ILE +ZfqAkIMxbzY/FxCdDHAbLh/2K8rrVfwK/GKAuEjNef2lLnS9eLDOJmS894laVBgI4nR miJgJwtB4IQeTAvIvyZbq0iQ+Bx0b/Z0E1tkzqAlG7Qbwpt933RaPD8vCgrc7jIxf2A5 FKl8DqjnKxiPcZgNca5ZogmVtBjaVvy3cGWiibnP0Csf80r4TjF/Qdy2ZYzJBBuilDZT qId6Re1zTR1aPoUiR6XdP5dA0sHrNKN7eAMX4osnIsOzxYULCtji15B2BcFRMXFl8Cdm 2c+w== X-Gm-Message-State: AMCzsaVrX5IYnWXDtTG+XdFfZm8UoHOZ70lJ7XoEfB9LfKPvP1jbXhiO 9Tv6Tb46Mc1TDNPsS3sYjMqJdRRYn1g= X-Google-Smtp-Source: ABhQp+Q7c2flsjIC5jpslZykMfoj7gjYQcCf+ioqS2D/AGqw8+hgskSLaic1NEdyUtqOCz2fv4OX/A== X-Received: by 10.28.109.23 with SMTP id i23mr3158567wmc.32.1507972474171; Sat, 14 Oct 2017 02:14:34 -0700 (PDT) Received: from lolita.yourcompany.com (188.139.62.94.rev.vodafone.pt. [94.62.139.188]) by smtp.gmail.com with ESMTPSA id 67sm3777490wmw.22.2017.10.14.02.14.32 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 14 Oct 2017 02:14:33 -0700 (PDT) From: joaotavora@gmail.com (=?utf-8?B?Sm/Do28gVMOhdm9yYQ==?=) To: Lele Gaifax Subject: Re: bug#28808: [PATCH] Implement Python backend for Flymake References: <87bmlan4w6.fsf@gmail.com> <87zi8ulpzg.fsf_-_@gmail.com> <877evyywjs.fsf@metapensiero.it> Date: Sat, 14 Oct 2017 10:14:31 +0100 In-Reply-To: <877evyywjs.fsf@metapensiero.it> (Lele Gaifax's message of "Sat, 14 Oct 2017 10:15:51 +0200") Message-ID: <87fuamks5k.fsf@gmail.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.90 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: 0.5 (/) X-Debbugs-Envelope-To: 28808 Cc: 28808@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.5 (/) Hi Lele, Lele Gaifax writes: >> A common trick here that old flymake (and also compile.el) use is to >> define the variable's value as list (REGEXP LINE COLUMN TYPE >> MESSAGE). > > I will try to better understand this, as I failed to see the benefit of adding > that indirection... maybe the compile.el functionality is older than the > ability to use explicit group numbers in the regexp? The benefit is that if I switch to a checker that doesn't provide COLUMN, for example, I won't be locked out with your expression. Likewise if I do switch to a checker that emits errors where I can clearly identify a TYPE. > I'm curious here: why the need of autoload cookie, if the (only?) caller site > lives in the very same source file? And if that's not only caller, why marking > it private with the double dash? Sorry for the noise. There is no need for the autoload cookie. I thought you were changing a different file than flymake. Don't use the cookie, use the double dash. > > More importantly: if we unconditionally activate the Flymake feature, instead > of being an user's choice, then the python--flymake-setup function may go > away, and the add-hook moved inside the python-mode function, it already > contains lot of those... That makes sense. But we don't (yet) "unconditionally activate" Flymake, we simply set up the buffer so that a later activation of Flymake will be met with agreeable conditions. > See http://endlessparentheses.com/get-in-the-habit-of-using-sharp-quote.html > for what I considered a "sound reason" :) Obviously, I use sharp quote myself, just not in add-hook, as that is the style I am familiar with. But if that is the style of python.el, that's a good reason. It's not in the rest of emacs. But I can explain what it bothered me: As you know, in the specific Flymake-case, backends are functions. You might be tempted to put a closure, like a (lambda (report-fn) ...) in flymake-diagnostic-functions. If you do that everything will work, except for the interactive messages that mention names of backends, where intead of the name of the symbol you see something very ugly like #f(compiled-function (report-fn) #) So, for now, as a good practice, I thought it better to use just ' so as not to encourage others to put closures there. Eventually, once function-put starts working for non-symbol functions and I can set a name property there, closures will probably not only be accepted but encouraged. From debbugs-submit-bounces@debbugs.gnu.org Tue Oct 17 17:58:25 2017 Received: (at 28808) by debbugs.gnu.org; 17 Oct 2017 21:58:25 +0000 Received: from localhost ([127.0.0.1]:46708 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e4ZsW-0003aZ-Mn for submit@debbugs.gnu.org; Tue, 17 Oct 2017 17:58:24 -0400 Received: from mail.arstecnica.it ([144.76.81.238]:50552) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e4ZsU-0003aL-ET for 28808@debbugs.gnu.org; Tue, 17 Oct 2017 17:58:23 -0400 Received: from nautilus (assp.arstecnica.it [192.168.1.102]) by mail.arstecnica.it (Postfix) with ESMTPSA id 7B12283EBB4; Tue, 17 Oct 2017 21:58:09 +0000 (UTC) Received: from nautilus ([31.44.165.109] helo=nautilus) by assp.arstecnica.it with SMTPS(AES256-GCM-SHA384) (2.3.3); 17 Oct 2017 21:58:08 +0000 From: Lele Gaifax To: =?utf-8?B?Sm/Do28gVMOhdm9yYQ==?= Subject: Re: bug#28808: [PATCH] Implement Python backend for Flymake In-Reply-To: <87fuamks5k.fsf@gmail.com> References: <87bmlan4w6.fsf@gmail.com> <87zi8ulpzg.fsf_-_@gmail.com> <877evyywjs.fsf@metapensiero.it> <87fuamks5k.fsf@gmail.com> Date: Tue, 17 Oct 2017 23:58:08 +0200 Message-ID: <878tg9sahb.fsf@metapensiero.it> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Assp-Version: 2.3.3(14029) on assp.arstecnica.it X-Assp-ID: assp.arstecnica.it m1-77489-06611 X-Assp-Session: B1028674 (mail 1) X-Assp-Envelope-From: lele@metapensiero.it X-Assp-Intended-For: 28808@debbugs.gnu.org X-Assp-Intended-For: joaotavora@gmail.com X-Assp-Client-TLS: yes X-Assp-Server-TLS: yes X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 28808 Cc: 28808@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.0 (/) --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Hi Jo=C3=A3o, I think I fulfilled all your suggestions/requests, and thus I'm re-attaching the current version of the backend. Please let me know if there's something more I can do, I will happily keep hacking! ciao, lele. --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-Add-a-Flymake-backend-for-Python.patch >From 4e61fa030704a5e7bfcd537c503cef1da4409b6b Mon Sep 17 00:00:00 2001 From: Lele Gaifax Date: Fri, 13 Oct 2017 10:44:02 +0200 Subject: [PATCH] Add a Flymake backend for Python * lisp/progmodes/python.el: Implement new Flymake backend with related customizable settings. (python-flymake-command, python-flymake-command-output-regexp, python-flymake-msg-alist): New defcustom. (python-flymake): New function. (python-flymake-activate): New function. --- lisp/progmodes/python.el | 135 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 135 insertions(+) diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index 895117b9ee..831fd7e7f2 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el @@ -5142,6 +5142,141 @@ 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. +This is a non empty list of strings, the checker tool possibly followed by +required arguments. Once launched it will receive the Python source to be +checked as its standard input. +To use `flake8' you would set this to (\"flake8\" \"-\")." + :group 'python-flymake + :type '(repeat string)) + +;; The default regexp accomodates for older pyflakes, which did not +;; report the column number, and at the same time it's compatible with +;; flake8 output, although it may be redefined to explicitly match the +;; TYPE +(defcustom python-flymake-command-output-regexp + (list + "^\\(?:?\\):\\(?1:[0-9]+\\):\\(?:\\(?2:[0-9]+\\):\\)? \\(?3:.*\\)$" + 1 2 nil 3) + "Specify how to parse the output of the specified tool. +The value has the form (REGEXP LINE COLUMN TYPE MESSAGE): if +REGEXP matches, the LINE'th subexpression gives the line number, +the COLUMN'th subexpression gives the column number on that line, +the TYPE'th subexpression gives the type of the message and +MESSAGE'th is the message text itself. + +If COLUMN or TYPE are nil or that index didn't match, that +information is not present on the matched line and a default will +be used." + :group 'python-flymake + :type '(list regexp + (integer :tag "Line's index") + (choice + (const :tag "No column" nil) + (integer :tag "Column's index")) + (choice + (const :tag "No type" nil) + (integer :tag "Type's index")) + (integer :tag "Message's index"))) + +(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'. +For example, when using `flake8' a possible configuration could be: + + ((\"\\(^redefinition\\|.*unused.*\\|used$\\)\" . :warning) + (\"^E999\" . :error) + (\"^[EW][0-9]+\" . :note)) + +By default messages are considered errors." + :group 'python-flymake + :type `(alist :key-type (regexp) + :value-type (symbol))) + +(defvar-local python--flymake-proc nil) + +(defun python--flymake-parse-output (source proc report-fn) + "Collect diagnostics parsing checker tool's output line by line." + (let ((rx (nth 0 python-flymake-command-output-regexp)) + (lineidx (nth 1 python-flymake-command-output-regexp)) + (colidx (nth 2 python-flymake-command-output-regexp)) + (typeidx (nth 3 python-flymake-command-output-regexp)) + (msgidx (nth 4 python-flymake-command-output-regexp))) + (with-current-buffer (process-buffer proc) + (goto-char (point-min)) + (cl-loop + while (search-forward-regexp rx nil t) + for msg = (match-string msgidx) + for (beg . end) = (flymake-diag-region + source + (string-to-number + (match-string lineidx)) + (and colidx + (match-string colidx) + (string-to-number + (match-string colidx)))) + for type = (or (and typeidx + (match-string typeidx) + (assoc-default + (match-string typeidx) + python-flymake-msg-alist + #'string-match)) + (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))))) + +(defun python-flymake (report-fn &rest _args) + "Flymake backend for Python. +This backend uses `python-flymake-command' (which see) to launch a process +that is passed the current buffer's content via stdin. +REPORT-FN is Flymake's callback function." + (unless (executable-find (car python-flymake-command)) + (error "Cannot find a suitable checker")) + + (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) + (when (eq 'exit (process-status proc)) + (unwind-protect + (when (eq proc python--flymake-proc) + (python--flymake-parse-output source proc report-fn)) + (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 '(?\" ?\')) -- 2.15.0.rc1 --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable --=20 nickname: Lele Gaifax | Quando vivr=C3=B2 di quello che ho pensato ieri real: Emanuele Gaifas | comincer=C3=B2 ad aver paura di chi mi copia. lele@metapensiero.it | -- Fortunato Depero, 1929. --=-=-=-- From debbugs-submit-bounces@debbugs.gnu.org Tue Oct 17 18:41:38 2017 Received: (at 28808) by debbugs.gnu.org; 17 Oct 2017 22:41:38 +0000 Received: from localhost ([127.0.0.1]:46730 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e4aYM-0004dN-5o for submit@debbugs.gnu.org; Tue, 17 Oct 2017 18:41:38 -0400 Received: from mail.arstecnica.it ([144.76.81.238]:53385) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e4aYK-0004d9-9P for 28808@debbugs.gnu.org; Tue, 17 Oct 2017 18:41:36 -0400 Received: from nautilus (assp.arstecnica.it [192.168.1.102]) by mail.arstecnica.it (Postfix) with ESMTPSA id BA5F583EFD7 for <28808@debbugs.gnu.org>; Tue, 17 Oct 2017 22:41:28 +0000 (UTC) Received: from nautilus ([31.44.165.109] helo=nautilus) by assp.arstecnica.it with SMTPS(AES256-GCM-SHA384) (2.3.3); 17 Oct 2017 22:41:28 +0000 From: Lele Gaifax To: 28808@debbugs.gnu.org Subject: Activation of the new backend Date: Wed, 18 Oct 2017 00:41:28 +0200 Message-ID: <87zi8pqtwn.fsf@metapensiero.it> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Assp-Version: 2.3.3(14029) on assp.arstecnica.it X-Assp-ID: assp.arstecnica.it m1-80088-10292 X-Assp-Session: B12FC920 (mail 1) X-Assp-Envelope-From: lele@metapensiero.it X-Assp-Intended-For: 28808@debbugs.gnu.org X-Assp-Client-TLS: yes X-Assp-Server-TLS: yes X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 28808 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.0 (/) Re-reading the patch I just sent, I see that one thing is still not the way Jo=C3=A3o suggested (and I'm quite surprised, since I'm pretty sure I *did*= that: by any chance the "git stash/fetch/merge upstream/stash pop" dance fooled me...): he asked to rename `python-flymake-activate' to `python--flymake-se= tup' and automatically call the latter from `python-mode'. I will rectify that asap. ciao, lele. --=20 nickname: Lele Gaifax | Quando vivr=C3=B2 di quello che ho pensato ieri real: Emanuele Gaifas | comincer=C3=B2 ad aver paura di chi mi copia. lele@metapensiero.it | -- Fortunato Depero, 1929. From debbugs-submit-bounces@debbugs.gnu.org Wed Oct 18 02:05:33 2017 Received: (at 28808) by debbugs.gnu.org; 18 Oct 2017 06:05:33 +0000 Received: from localhost ([127.0.0.1]:47172 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e4hTw-0002by-NG for submit@debbugs.gnu.org; Wed, 18 Oct 2017 02:05:33 -0400 Received: from mail.arstecnica.it ([144.76.81.238]:53804) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e4hTt-0002bi-7G for 28808@debbugs.gnu.org; Wed, 18 Oct 2017 02:05:31 -0400 Received: from nautilus (assp.arstecnica.it [192.168.1.102]) by mail.arstecnica.it (Postfix) with ESMTPSA id 28A9783EC29 for <28808@debbugs.gnu.org>; Wed, 18 Oct 2017 06:05:17 +0000 (UTC) Received: from nautilus ([31.44.165.109] helo=nautilus) by assp.arstecnica.it with SMTPS(AES256-GCM-SHA384) (2.3.3); 18 Oct 2017 06:05:17 +0000 From: Lele Gaifax To: 28808@debbugs.gnu.org Subject: Re: Activation of the new backend In-Reply-To: <87zi8pqtwn.fsf@metapensiero.it> References: <87zi8pqtwn.fsf@metapensiero.it> Date: Wed, 18 Oct 2017 08:05:17 +0200 Message-ID: <877evtdm8y.fsf@metapensiero.it> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Assp-Version: 2.3.3(14029) on assp.arstecnica.it X-Assp-ID: assp.arstecnica.it m1-06717-05833 X-Assp-Session: 111E88C0 (mail 1) X-Assp-Envelope-From: lele@metapensiero.it X-Assp-Intended-For: 28808@debbugs.gnu.org X-Assp-Client-TLS: yes X-Assp-Server-TLS: yes X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 28808 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.0 (/) --=-=-= Content-Type: text/plain Ok, here is the patch again, sorry for the hiccup. I rectified also the commit message, to reflect latest changes. --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-Add-a-Flymake-backend-for-Python.patch >From a2a6decfeb79a5b25a7193ec964f709232f1c784 Mon Sep 17 00:00:00 2001 From: Lele Gaifax Date: Fri, 13 Oct 2017 10:44:02 +0200 Subject: [PATCH] Add a Flymake backend for Python * lisp/progmodes/python.el: Implement new Flymake backend with related customizable settings. (python-flymake-command, python-flymake-command-output-regexp, python-flymake-msg-alist): New defcustom. (python--flymake-parse-output): New function, able to parse python-flymake-command output accordingly to python-flymake-command-output-regexp. (python--flymake): New function implementing the backend interface using python--flymake-parse-output for the real work. (python-mode): Add python--flymake to flymake-diagnostic-functions. --- lisp/progmodes/python.el | 135 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 134 insertions(+), 1 deletion(-) diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index 895117b9ee..ed9065e5d6 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el @@ -5142,6 +5142,137 @@ 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. +This is a non empty list of strings, the checker tool possibly followed by +required arguments. Once launched it will receive the Python source to be +checked as its standard input. +To use `flake8' you would set this to (\"flake8\" \"-\")." + :group 'python-flymake + :type '(repeat string)) + +;; The default regexp accomodates for older pyflakes, which did not +;; report the column number, and at the same time it's compatible with +;; flake8 output, although it may be redefined to explicitly match the +;; TYPE +(defcustom python-flymake-command-output-regexp + (list + "^\\(?:?\\):\\(?1:[0-9]+\\):\\(?:\\(?2:[0-9]+\\):\\)? \\(?3:.*\\)$" + 1 2 nil 3) + "Specify how to parse the output of the specified tool. +The value has the form (REGEXP LINE COLUMN TYPE MESSAGE): if +REGEXP matches, the LINE'th subexpression gives the line number, +the COLUMN'th subexpression gives the column number on that line, +the TYPE'th subexpression gives the type of the message and +MESSAGE'th is the message text itself. + +If COLUMN or TYPE are nil or that index didn't match, that +information is not present on the matched line and a default will +be used." + :group 'python-flymake + :type '(list regexp + (integer :tag "Line's index") + (choice + (const :tag "No column" nil) + (integer :tag "Column's index")) + (choice + (const :tag "No type" nil) + (integer :tag "Type's index")) + (integer :tag "Message's index"))) + +(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'. +For example, when using `flake8' a possible configuration could be: + + ((\"\\(^redefinition\\|.*unused.*\\|used$\\)\" . :warning) + (\"^E999\" . :error) + (\"^[EW][0-9]+\" . :note)) + +By default messages are considered errors." + :group 'python-flymake + :type `(alist :key-type (regexp) + :value-type (symbol))) + +(defvar-local python--flymake-proc nil) + +(defun python--flymake-parse-output (source proc report-fn) + "Collect diagnostics parsing checker tool's output line by line." + (let ((rx (nth 0 python-flymake-command-output-regexp)) + (lineidx (nth 1 python-flymake-command-output-regexp)) + (colidx (nth 2 python-flymake-command-output-regexp)) + (typeidx (nth 3 python-flymake-command-output-regexp)) + (msgidx (nth 4 python-flymake-command-output-regexp))) + (with-current-buffer (process-buffer proc) + (goto-char (point-min)) + (cl-loop + while (search-forward-regexp rx nil t) + for msg = (match-string msgidx) + for (beg . end) = (flymake-diag-region + source + (string-to-number + (match-string lineidx)) + (and colidx + (match-string colidx) + (string-to-number + (match-string colidx)))) + for type = (or (and typeidx + (match-string typeidx) + (assoc-default + (match-string typeidx) + python-flymake-msg-alist + #'string-match)) + (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))))) + +(defun python--flymake (report-fn &rest _args) + "Flymake backend for Python. +This backend uses `python-flymake-command' (which see) to launch a process +that is passed the current buffer's content via stdin. +REPORT-FN is Flymake's callback function." + (unless (executable-find (car python-flymake-command)) + (error "Cannot find a suitable checker")) + + (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) + (when (eq 'exit (process-status proc)) + (unwind-protect + (when (eq proc python--flymake-proc) + (python--flymake-parse-output source proc report-fn)) + (kill-buffer (process-buffer proc))))))) + (process-send-region python--flymake-proc (point-min) (point-max)) + (process-send-eof python--flymake-proc)))) + + (defun python-electric-pair-string-delimiter () (when (and electric-pair-mode (memq last-command-event '(?\" ?\')) @@ -5255,7 +5386,9 @@ python-mode (make-local-variable 'python-shell-internal-buffer) (when python-indent-guess-indent-offset - (python-indent-guess-indent-offset))) + (python-indent-guess-indent-offset)) + + (add-hook 'flymake-diagnostic-functions #'python--flymake nil t)) (provide 'python) -- 2.15.0.rc1 --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable --=20 nickname: Lele Gaifax | Quando vivr=C3=B2 di quello che ho pensato ieri real: Emanuele Gaifas | comincer=C3=B2 ad aver paura di chi mi copia. lele@metapensiero.it | -- Fortunato Depero, 1929. --=-=-=-- From debbugs-submit-bounces@debbugs.gnu.org Sat Oct 21 03:15:53 2017 Received: (at 28808) by debbugs.gnu.org; 21 Oct 2017 07:15:53 +0000 Received: from localhost ([127.0.0.1]:52998 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e5o0f-0003pq-Av for submit@debbugs.gnu.org; Sat, 21 Oct 2017 03:15:53 -0400 Received: from mail.arstecnica.it ([144.76.81.238]:49019) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e5o0c-0003pV-Fv for 28808@debbugs.gnu.org; Sat, 21 Oct 2017 03:15:51 -0400 Received: from nautilus (assp.arstecnica.it [192.168.1.102]) by mail.arstecnica.it (Postfix) with ESMTPSA id E150D83EF1C for <28808@debbugs.gnu.org>; Sat, 21 Oct 2017 07:15:38 +0000 (UTC) Received: from nautilus ([31.44.165.109] helo=nautilus) by assp.arstecnica.it with SMTPS(AES256-GCM-SHA384) (2.3.3); 21 Oct 2017 07:15:38 +0000 From: Lele Gaifax To: 28808@debbugs.gnu.org Subject: Consider the right python--flymake-proc In-Reply-To: <878tg9sahb.fsf@metapensiero.it> References: <87bmlan4w6.fsf@gmail.com> <87zi8ulpzg.fsf_-_@gmail.com> <877evyywjs.fsf@metapensiero.it> <87fuamks5k.fsf@gmail.com> <878tg9sahb.fsf@metapensiero.it> Date: Sat, 21 Oct 2017 09:15:38 +0200 Message-ID: <87inf9dl9h.fsf@metapensiero.it> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Assp-Version: 2.3.3(14029) on assp.arstecnica.it X-Assp-ID: assp.arstecnica.it m1-70138-10303 X-Assp-Session: B1ECE80C (mail 1) X-Assp-Envelope-From: lele@metapensiero.it X-Assp-Intended-For: 28808@debbugs.gnu.org X-Assp-Client-TLS: yes X-Assp-Server-TLS: yes X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 28808 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.0 (/) --=-=-= Content-Type: text/plain Hi, I applied the fix about accessing the local python--flymake-proc in the right buffer, in the inner lambda in python--flymake. ciao, lele. --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-Add-a-Flymake-backend-for-Python.patch >From 739643bcf8cfcdbb09d43dd84ba12b0ab5d98d89 Mon Sep 17 00:00:00 2001 From: Lele Gaifax Date: Fri, 13 Oct 2017 10:44:02 +0200 Subject: [PATCH] Add a Flymake backend for Python * lisp/progmodes/python.el: Implement new Flymake backend with related customizable settings. (python-flymake-command, python-flymake-command-output-regexp, python-flymake-msg-alist): New defcustom. (python--flymake-parse-output): New function, able to parse python-flymake-command output accordingly to python-flymake-command-output-regexp. (python--flymake): New function implementing the backend interface using python--flymake-parse-output for the real work. (python-mode): Add python--flymake to flymake-diagnostic-functions. --- lisp/progmodes/python.el | 136 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 135 insertions(+), 1 deletion(-) diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index 895117b9ee..49c1ad907d 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el @@ -5142,6 +5142,138 @@ 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. +This is a non empty list of strings, the checker tool possibly followed by +required arguments. Once launched it will receive the Python source to be +checked as its standard input. +To use `flake8' you would set this to (\"flake8\" \"-\")." + :group 'python-flymake + :type '(repeat string)) + +;; The default regexp accomodates for older pyflakes, which did not +;; report the column number, and at the same time it's compatible with +;; flake8 output, although it may be redefined to explicitly match the +;; TYPE +(defcustom python-flymake-command-output-regexp + (list + "^\\(?:?\\):\\(?1:[0-9]+\\):\\(?:\\(?2:[0-9]+\\):\\)? \\(?3:.*\\)$" + 1 2 nil 3) + "Specify how to parse the output of the specified tool. +The value has the form (REGEXP LINE COLUMN TYPE MESSAGE): if +REGEXP matches, the LINE'th subexpression gives the line number, +the COLUMN'th subexpression gives the column number on that line, +the TYPE'th subexpression gives the type of the message and +MESSAGE'th is the message text itself. + +If COLUMN or TYPE are nil or that index didn't match, that +information is not present on the matched line and a default will +be used." + :group 'python-flymake + :type '(list regexp + (integer :tag "Line's index") + (choice + (const :tag "No column" nil) + (integer :tag "Column's index")) + (choice + (const :tag "No type" nil) + (integer :tag "Type's index")) + (integer :tag "Message's index"))) + +(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'. +For example, when using `flake8' a possible configuration could be: + + ((\"\\(^redefinition\\|.*unused.*\\|used$\\)\" . :warning) + (\"^E999\" . :error) + (\"^[EW][0-9]+\" . :note)) + +By default messages are considered errors." + :group 'python-flymake + :type `(alist :key-type (regexp) + :value-type (symbol))) + +(defvar-local python--flymake-proc nil) + +(defun python--flymake-parse-output (source proc report-fn) + "Collect diagnostics parsing checker tool's output line by line." + (let ((rx (nth 0 python-flymake-command-output-regexp)) + (lineidx (nth 1 python-flymake-command-output-regexp)) + (colidx (nth 2 python-flymake-command-output-regexp)) + (typeidx (nth 3 python-flymake-command-output-regexp)) + (msgidx (nth 4 python-flymake-command-output-regexp))) + (with-current-buffer (process-buffer proc) + (goto-char (point-min)) + (cl-loop + while (search-forward-regexp rx nil t) + for msg = (match-string msgidx) + for (beg . end) = (flymake-diag-region + source + (string-to-number + (match-string lineidx)) + (and colidx + (match-string colidx) + (string-to-number + (match-string colidx)))) + for type = (or (and typeidx + (match-string typeidx) + (assoc-default + (match-string typeidx) + python-flymake-msg-alist + #'string-match)) + (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))))) + +(defun python--flymake (report-fn &rest _args) + "Flymake backend for Python. +This backend uses `python-flymake-command' (which see) to launch a process +that is passed the current buffer's content via stdin. +REPORT-FN is Flymake's callback function." + (unless (executable-find (car python-flymake-command)) + (error "Cannot find a suitable checker")) + + (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) + (when (eq 'exit (process-status proc)) + (unwind-protect + (when (with-current-buffer source + (eq proc python--flymake-proc)) + (python--flymake-parse-output source proc report-fn)) + (kill-buffer (process-buffer proc))))))) + (process-send-region python--flymake-proc (point-min) (point-max)) + (process-send-eof python--flymake-proc)))) + + (defun python-electric-pair-string-delimiter () (when (and electric-pair-mode (memq last-command-event '(?\" ?\')) @@ -5255,7 +5387,9 @@ python-mode (make-local-variable 'python-shell-internal-buffer) (when python-indent-guess-indent-offset - (python-indent-guess-indent-offset))) + (python-indent-guess-indent-offset)) + + (add-hook 'flymake-diagnostic-functions #'python--flymake nil t)) (provide 'python) -- 2.15.0.rc1 --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable --=20 nickname: Lele Gaifax | Quando vivr=C3=B2 di quello che ho pensato ieri real: Emanuele Gaifas | comincer=C3=B2 ad aver paura di chi mi copia. lele@metapensiero.it | -- Fortunato Depero, 1929. --=-=-=-- From debbugs-submit-bounces@debbugs.gnu.org Sat Oct 21 09:05:56 2017 Received: (at 28808) by debbugs.gnu.org; 21 Oct 2017 13:05:56 +0000 Received: from localhost ([127.0.0.1]:53153 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e5tTQ-0006KV-4I for submit@debbugs.gnu.org; Sat, 21 Oct 2017 09:05:56 -0400 Received: from mail-qt0-f173.google.com ([209.85.216.173]:51373) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e5tTL-0006KE-ST for 28808@debbugs.gnu.org; Sat, 21 Oct 2017 09:05:52 -0400 Received: by mail-qt0-f173.google.com with SMTP id h4so21437163qtk.8 for <28808@debbugs.gnu.org>; Sat, 21 Oct 2017 06:05:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=EBwmH84mGGpxy/OTv0ZSOaJ2RQ/E+qwNUsoFuwVu8tw=; b=oDOiCF8uykwvFMyVzNtjgET6uSiZ4/kF6FVM75V/I0K+1vzZQ1sKelUJwl3kiZg048 GJcQK5DBABeXSk0APExSNwgoDdG092wBe3dAlpISU6qKFiMxnIWGw9ct2n3Z0AF8HiEw wEpUFQqYJFD8b9zXwEd+mtKYJBxfQoTSkiiVW9nJFJtI2jBHqWaNcfFukakzm1S91ObI b/qNy343ob/vkYFOiFJglTAhcqWl1/DEf9DOpaqJc6tlajGirhKf90QwjyGKwnUMYMzu gvmD1HmovHXwiEwqEnFsOpJWHc7qdBRvCaaLwNF02SDF7oJEPNiFVDFP5wQEWW+ct7gt u6Og== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=EBwmH84mGGpxy/OTv0ZSOaJ2RQ/E+qwNUsoFuwVu8tw=; b=g/bZiDsouuQXkq/h2n8tpUx8usMI7dIg9DgKrqH0tJEgIvpJgJtPX8fhFtJMMmWNpO nXr85S6wMXi/FJ0EPSj6KRsEbl54TzviHgqml2xKEFV5nOuqhdQI2/3i7ipSaVom/kAG ttYwbXfNEE5rSHCangc1nqvmeIYGc996ti6urZ2ycK2SiIzQnadIM6pFDTwrIqCv8Mey 5Rz4T8CVNBul2+oLIA7tfT9YI41lqh3xL0jW3T9ZbebpHH3fZYY656Rw2DA4jwICgeIW ytyKAOYX5LtiCbGVGQBBRevQR3TdkB0so40PtzsB/Zdgn/QxL2+Ov2o6AlEltwFQ3aIl NPAw== X-Gm-Message-State: AMCzsaXn0B43IK+QECTViJL9t1QxqG2+bIK1Yq84iIg4hUHYH3laAMj4 d8CpXCdViMrVdzgSXNQN6CyJ8+sxe7s9Nhz6UgxxJw== X-Google-Smtp-Source: ABhQp+RBbtnQf16phH6NMc8x0sbBksj4c/9hIUpaiwDPM6hPKUKuXjyeW7R8nd714K/vpRoq8MUO/5Yv7WsmBQ7OMk4= X-Received: by 10.237.37.76 with SMTP id w12mr11941562qtc.201.1508591146167; Sat, 21 Oct 2017 06:05:46 -0700 (PDT) MIME-Version: 1.0 Received: by 10.12.145.228 with HTTP; Sat, 21 Oct 2017 06:05:25 -0700 (PDT) In-Reply-To: <87inf9dl9h.fsf@metapensiero.it> References: <87bmlan4w6.fsf@gmail.com> <87zi8ulpzg.fsf_-_@gmail.com> <877evyywjs.fsf@metapensiero.it> <87fuamks5k.fsf@gmail.com> <878tg9sahb.fsf@metapensiero.it> <87inf9dl9h.fsf@metapensiero.it> From: =?UTF-8?B?Sm/Do28gVMOhdm9yYQ==?= Date: Sat, 21 Oct 2017 14:05:25 +0100 Message-ID: Subject: Re: bug#28808: Consider the right python--flymake-proc To: Lele Gaifax Content-Type: multipart/alternative; boundary="001a113f433060f55c055c0e3ffa" X-Spam-Score: 0.5 (/) X-Debbugs-Envelope-To: 28808 Cc: 28808@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.5 (/) --001a113f433060f55c055c0e3ffa Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Good one. I'll have a look at all the backends, including yours of course, during the next week. Jo=C3=A3o On Sat, Oct 21, 2017 at 8:15 AM, Lele Gaifax wrote: > Hi, > > I applied the fix about accessing the local python--flymake-proc in the > right > buffer, in the inner lambda in python--flymake. > > ciao, lele. > > > > -- > nickname: Lele Gaifax | Quando vivr=C3=B2 di quello che ho pensato ieri > real: Emanuele Gaifas | comincer=C3=B2 ad aver paura di chi mi copia. > lele@metapensiero.it | -- Fortunato Depero, 1929. > > --=20 Jo=C3=A3o T=C3=A1vora --001a113f433060f55c055c0e3ffa Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Good one.=C2=A0

I'll have a look at= all the backends, including yours of course, during the next week.

Jo=C3=A3o

On Sat, Oct 21, 2017 at 8:15 AM, Lele Gaifax <lel= e@metapensiero.it> wrote:
H= i,

I applied the fix about accessing the local python--flymake-proc in the rig= ht
buffer, in the inner lambda in python--flymake.

ciao, lele.



--
nickname: Lele Gaifax | Quando vivr=C3=B2 di quello che ho pensato ieri
real: Emanuele Gaifas | comincer=C3=B2 ad aver paura di chi mi copia.
lele@metapensiero.it=C2=A0 |=C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0-- Fortunato Dep= ero, 1929.




--
Jo=C3=A3o T=C3=A1= vora
--001a113f433060f55c055c0e3ffa-- From debbugs-submit-bounces@debbugs.gnu.org Fri Nov 03 08:24:31 2017 Received: (at 28808) by debbugs.gnu.org; 3 Nov 2017 12:24:31 +0000 Received: from localhost ([127.0.0.1]:48858 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eAb1T-0007ph-FK for submit@debbugs.gnu.org; Fri, 03 Nov 2017 08:24:31 -0400 Received: from mail-wm0-f48.google.com ([74.125.82.48]:53424) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eAb1Q-0007pT-RM for 28808@debbugs.gnu.org; Fri, 03 Nov 2017 08:24:29 -0400 Received: by mail-wm0-f48.google.com with SMTP id r196so1187704wmf.2 for <28808@debbugs.gnu.org>; Fri, 03 Nov 2017 05:24:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=YAOMeLYR0kcGdR+LNxjeWF2b4c5x6kFtGQ+jX/glnzw=; b=LsoXq8a3e0a5R/ZYMOH33p7WdCL7pNft5OqTDxLA7h4JpYHRq/BvGBd+GKllHYJomi hv38zLbpk5CDBNloX8wHn4DicuNz0F9KD6b/vDynw19RSmpoA/mH/brBun5PnqM9i4P7 sdCif3BpcInyuVNE49y+xYrq8v7MWFw/VS0KmZgtkJ1/tqie5JFff/Cn8N+cgh6qAdAP VRiVh6JyEOcNyrY21LYUkYmKKrdKgXh4MDtRF9D5XZPQiRX0GICGlno48Xqu5d6YUnAW Zb9rV0O6PY0bwK1QtrPVF83VPap0Jbmtlpawv5MCbWcvaAT+6fWSg8jkkj/OmynxT7cM gR5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version; bh=YAOMeLYR0kcGdR+LNxjeWF2b4c5x6kFtGQ+jX/glnzw=; b=Im/5m/68IM6MyEb5xXugAStOq09FnXiDqiM0V6gC5C4Iaf2lpgrdVbhv4Y5ZYJ1iRo xzav+V8RmB8Uev+/rz3uagWr/ybvaUr5+a53++okVDvsFeIO5zZWtvTbdqh0yeefn9Hl sj8C3z9bPDWE/we8a8QCSfaCIi2blWUggfu/+o2y3wK7AGX0EUX1nCfqG6038YqHmpZH RNSwX2Qcp74KMAnTl7m4v7MoO2qLOygsudFfyfvCDrwUEEfTPBjOkULpCr316gxV3M4h p6O2G6+pGluwoFOgrAFI0SBRdnIjjs34QlXe4LpHN2Q24Lb589EWxSCgewFwuxSiZmdd pqTw== X-Gm-Message-State: AMCzsaU7G/StPuxDu69Sv723QxN6//39Wc18vgeZ2zQxnHKGIOIV0fZq piuE67hrIPj2JdcOrtfKRAfTDRiF X-Google-Smtp-Source: ABhQp+SKt6fL/chKwZNQzzuTcKKCXtQPivk9YpAvywebPzRGDCD0Xd09eVVIF2Ze3q305kiEUDTfCA== X-Received: by 10.80.169.193 with SMTP id n59mr8734910edc.282.1509711862837; Fri, 03 Nov 2017 05:24:22 -0700 (PDT) Received: from lolita.yourcompany.com (188.139.62.94.rev.vodafone.pt. [94.62.139.188]) by smtp.gmail.com with ESMTPSA id u14sm4931386edd.47.2017.11.03.05.24.21 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 03 Nov 2017 05:24:21 -0700 (PDT) From: joaotavora@gmail.com (=?utf-8?B?Sm/Do28gVMOhdm9yYQ==?=) To: Lele Gaifax Subject: Re: bug#28808: Consider the right python--flymake-proc References: <87bmlan4w6.fsf@gmail.com> <87zi8ulpzg.fsf_-_@gmail.com> <877evyywjs.fsf@metapensiero.it> <87fuamks5k.fsf@gmail.com> <878tg9sahb.fsf@metapensiero.it> <87inf9dl9h.fsf@metapensiero.it> Date: Fri, 03 Nov 2017 12:24:19 +0000 In-Reply-To: (=?utf-8?Q?=22Jo=C3=A3o_T=C3=A1vora=22's?= message of "Sat, 21 Oct 2017 14:05:25 +0100") Message-ID: <87wp37turw.fsf@gmail.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.90 (gnu/linux) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 28808 Cc: 28808@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.0 (/) --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Jo=C3=A3o T=C3=A1vora writes: > Good one.=20 > > I'll have a look at all the backends, including yours of course, during t= he next week. > > Jo=C3=A3o > Sorry for the delay. I am ready to commit your patch to emacs-26 with very minor changes: 1. The defcustom python-flymake-command-output-regexp is renamed to python-flymake-command-output-pattern. 2. The docstring of that variable is slightly changed. 3. The function python--flymake is renamed python-flymake, since it is public to python.el (there was some misunderstanding caused by me earlier). 4. The commit message is very slightly changed so that the description sentence starts on a line by its own. Please verify, Jo=C3=A3o --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-Add-a-Flymake-backend-for-Python.patch >From fd800a9e16493872ff3c8244a2e30e2d9e61fca4 Mon Sep 17 00:00:00 2001 From: Lele Gaifax Date: Fri, 3 Nov 2017 12:20:36 +0000 Subject: [PATCH] Add a Flymake backend for Python Implement new Flymake backend with related customizable settings. * lisp/progmodes/python.el (python-flymake-command) (python-flymake-command-output-pattern) (python-flymake-msg-alist): New defcustom. (python--flymake-parse-output): New function, able to parse python-flymake-command output accordingly to python-flymake-command-output-pattern. (python-flymake): New function implementing the backend interface using python--flymake-parse-output for the real work. (python-mode): Add python-flymake to flymake-diagnostic-functions. --- lisp/progmodes/python.el | 136 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 135 insertions(+), 1 deletion(-) diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index 895117b9ee..b7902fb978 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el @@ -5142,6 +5142,138 @@ 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. +This is a non empty list of strings, the checker tool possibly followed by +required arguments. Once launched it will receive the Python source to be +checked as its standard input. +To use `flake8' you would set this to (\"flake8\" \"-\")." + :group 'python-flymake + :type '(repeat string)) + +;; The default regexp accomodates for older pyflakes, which did not +;; report the column number, and at the same time it's compatible with +;; flake8 output, although it may be redefined to explicitly match the +;; TYPE +(defcustom python-flymake-command-output-pattern + (list + "^\\(?:?\\):\\(?1:[0-9]+\\):\\(?:\\(?2:[0-9]+\\):\\)? \\(?3:.*\\)$" + 1 2 nil 3) + "Specify how to parse the output of `python-flymake-command'. +The value has the form (REGEXP LINE COLUMN TYPE MESSAGE): if +REGEXP matches, the LINE'th subexpression gives the line number, +the COLUMN'th subexpression gives the column number on that line, +the TYPE'th subexpression gives the type of the message and the +MESSAGE'th gives the message text itself. + +If COLUMN or TYPE are nil or that index didn't match, that +information is not present on the matched line and a default will +be used." + :group 'python-flymake + :type '(list regexp + (integer :tag "Line's index") + (choice + (const :tag "No column" nil) + (integer :tag "Column's index")) + (choice + (const :tag "No type" nil) + (integer :tag "Type's index")) + (integer :tag "Message's index"))) + +(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'. +For example, when using `flake8' a possible configuration could be: + + ((\"\\(^redefinition\\|.*unused.*\\|used$\\)\" . :warning) + (\"^E999\" . :error) + (\"^[EW][0-9]+\" . :note)) + +By default messages are considered errors." + :group 'python-flymake + :type `(alist :key-type (regexp) + :value-type (symbol))) + +(defvar-local python--flymake-proc nil) + +(defun python--flymake-parse-output (source proc report-fn) + "Collect diagnostics parsing checker tool's output line by line." + (let ((rx (nth 0 python-flymake-command-output-pattern)) + (lineidx (nth 1 python-flymake-command-output-pattern)) + (colidx (nth 2 python-flymake-command-output-pattern)) + (typeidx (nth 3 python-flymake-command-output-pattern)) + (msgidx (nth 4 python-flymake-command-output-pattern))) + (with-current-buffer (process-buffer proc) + (goto-char (point-min)) + (cl-loop + while (search-forward-regexp rx nil t) + for msg = (match-string msgidx) + for (beg . end) = (flymake-diag-region + source + (string-to-number + (match-string lineidx)) + (and colidx + (match-string colidx) + (string-to-number + (match-string colidx)))) + for type = (or (and typeidx + (match-string typeidx) + (assoc-default + (match-string typeidx) + python-flymake-msg-alist + #'string-match)) + (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))))) + +(defun python-flymake (report-fn &rest _args) + "Flymake backend for Python. +This backend uses `python-flymake-command' (which see) to launch a process +that is passed the current buffer's content via stdin. +REPORT-FN is Flymake's callback function." + (unless (executable-find (car python-flymake-command)) + (error "Cannot find a suitable checker")) + + (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) + (when (eq 'exit (process-status proc)) + (unwind-protect + (when (with-current-buffer source + (eq proc python--flymake-proc)) + (python--flymake-parse-output source proc report-fn)) + (kill-buffer (process-buffer proc))))))) + (process-send-region python--flymake-proc (point-min) (point-max)) + (process-send-eof python--flymake-proc)))) + + (defun python-electric-pair-string-delimiter () (when (and electric-pair-mode (memq last-command-event '(?\" ?\')) @@ -5255,7 +5387,9 @@ python-mode (make-local-variable 'python-shell-internal-buffer) (when python-indent-guess-indent-offset - (python-indent-guess-indent-offset))) + (python-indent-guess-indent-offset)) + + (add-hook 'flymake-diagnostic-functions #'python-flymake nil t)) (provide 'python) -- 2.14.2 --=-=-=-- From debbugs-submit-bounces@debbugs.gnu.org Fri Nov 03 15:16:52 2017 Received: (at 28808) by debbugs.gnu.org; 3 Nov 2017 19:16:52 +0000 Received: from localhost ([127.0.0.1]:49847 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eAhSW-00017P-8b for submit@debbugs.gnu.org; Fri, 03 Nov 2017 15:16:52 -0400 Received: from mail.arstecnica.it ([144.76.81.238]:36239) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eAhSU-00017C-4p for 28808@debbugs.gnu.org; Fri, 03 Nov 2017 15:16:50 -0400 Received: from nautilus (assp.arstecnica.it [192.168.1.102]) by mail.arstecnica.it (Postfix) with ESMTPSA id 2007483ED7F; Fri, 3 Nov 2017 19:16:42 +0000 (UTC) Received: from nautilus ([31.44.165.109] helo=nautilus) by assp.arstecnica.it with SMTPS(AES256-GCM-SHA384) (2.3.3); 3 Nov 2017 19:16:42 +0000 From: Lele Gaifax To: =?utf-8?B?Sm/Do28gVMOhdm9yYQ==?= Subject: Re: bug#28808: Consider the right python--flymake-proc In-Reply-To: <87wp37turw.fsf@gmail.com> References: <87bmlan4w6.fsf@gmail.com> <87zi8ulpzg.fsf_-_@gmail.com> <877evyywjs.fsf@metapensiero.it> <87fuamks5k.fsf@gmail.com> <878tg9sahb.fsf@metapensiero.it> <87inf9dl9h.fsf@metapensiero.it> <87wp37turw.fsf@gmail.com> Date: Fri, 03 Nov 2017 20:16:42 +0100 Message-ID: <87bmkj9nqd.fsf@metapensiero.it> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Assp-Version: 2.3.3(14029) on assp.arstecnica.it X-Assp-ID: assp.arstecnica.it m1-36602-03748 X-Assp-Session: E7E9CEC (mail 1) X-Assp-Envelope-From: lele@metapensiero.it X-Assp-Intended-For: 28808@debbugs.gnu.org X-Assp-Intended-For: joaotavora@gmail.com X-Assp-Client-TLS: yes X-Assp-Server-TLS: yes X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 28808 Cc: 28808@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.0 (/) joaotavora@gmail.com (Jo=C3=A3o T=C3=A1vora) writes: > Please verify, Thank you Jo=C3=A3o, everything seems good to me. Ciao, lele. --=20 nickname: Lele Gaifax | Quando vivr=C3=B2 di quello che ho pensato ieri real: Emanuele Gaifas | comincer=C3=B2 ad aver paura di chi mi copia. lele@metapensiero.it | -- Fortunato Depero, 1929. From debbugs-submit-bounces@debbugs.gnu.org Sun Nov 05 16:53:13 2017 Received: (at control) by debbugs.gnu.org; 5 Nov 2017 21:53:13 +0000 Received: from localhost ([127.0.0.1]:52747 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eBSqu-0003hZ-Vi for submit@debbugs.gnu.org; Sun, 05 Nov 2017 16:53:13 -0500 Received: from mail-wm0-f52.google.com ([74.125.82.52]:43028) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eBSqs-0003hL-OA for control@debbugs.gnu.org; Sun, 05 Nov 2017 16:53:11 -0500 Received: by mail-wm0-f52.google.com with SMTP id r68so7275696wmr.0 for ; Sun, 05 Nov 2017 13:53:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:message-id:to:from:subject:mime-version :content-transfer-encoding; bh=pzQwdeITWLQs0WRsvneTx2AKczvLBpgZuDe34vFC+dE=; b=CNqHfm1jduIm6F615qmtN+fklpvHNPgF7+4bXvn4KSCrmMpK5MmaidAkMV1+YKTBpu WgY2Ow8ya7YrRQvenxifJ9xW3zoLloYk+K79OPeOWVxIvKXhqDT+NK3FwiRi+pNal0Rr k8AGrNRg+Y6ixUCSxTHyTwcq8wWPBmQph/CNaRl89rsN110kz2cB/NiSHNWqkg/PXW9r V2ZLtJ/EVUMVgpmSHVHH0affTM1DZWkiLHyu+NgcDBvAx1H11y/fBKwpIRiN1cKCQtpM nZNcilIndKa1rmn3dA284TBgK+qPMvjkVXWYEMgiy+XsQ62+MY97yzm22XpWjgisaSvv 76Vw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:to:from:subject:mime-version :content-transfer-encoding; bh=pzQwdeITWLQs0WRsvneTx2AKczvLBpgZuDe34vFC+dE=; b=YvnCettWsu25qAc7DhWPay06r5n+mrZxGOv7XTmgZL1BAAsWvCeQzYUrYWtaRgc/+t h2YYE1fkiC4/DO8Y5s0dbnruxH5SEC2VPGJugIPm80+MOJDzuy6Qkf+EwCRxzd1kLpmZ vPpVqf5esHFoM7zP+6Hn+jqQlzNWlXAYVIWlYz+/WcsCbjbp8xiAhj9lTbFXUukXM/hZ k2okoUf1ie2r85q8oAtRACTKyh4J+FidTfkG2Ov1nKEWmY64ibB7SQJzeFlC6/C1sW6K yBOvptGo98MRJSlphcX3nwcf7dIXCh8YfjcrlFkx94kbNhiN6OxO1OJpZHzzN1iOPW5r DfMg== X-Gm-Message-State: AJaThX4FmYwWX9C8Y1AeilMjmubF3NRzWb5pNLtBgv1IC9mz2lKQy1On AFYs/y6eGQCQwcO3nnHaWQl5dhgB X-Google-Smtp-Source: ABhQp+S0MO3oq2fHdVnxeM0N+s4fZnB5kbEmjTGTLb1gOBaBbCIckcQEfPfK61LHTGwG/4jrtTrHKw== X-Received: by 10.28.181.2 with SMTP id e2mr3299907wmf.81.1509918784832; Sun, 05 Nov 2017 13:53:04 -0800 (PST) Received: from lolita.yourcompany.com (188.139.62.94.rev.vodafone.pt. [94.62.139.188]) by smtp.gmail.com with ESMTPSA id 1sm4962101wmu.8.2017.11.05.13.53.04 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 05 Nov 2017 13:53:04 -0800 (PST) Date: Sun, 05 Nov 2017 21:53:03 +0000 Message-Id: <87h8u8qtog.fsf@gmail.com> To: control@debbugs.gnu.org From: joaotavora@gmail.com (=?utf-8?B?Sm/Do28gVMOhdm9yYQ==?=) Subject: control message for bug #28808 MIME-version: 1.0 Content-type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: control X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.0 (/) tags 28808 fixed close 28808 26.1 From unknown Sat Jun 21 05:14:45 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Mon, 04 Dec 2017 12:24:05 +0000 User-Agent: Fakemail v42.6.9 # This is a fake control message. # # The action: # bug archived. thanks # This fakemail brought to you by your local debbugs # administrator