From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: joaotavora@gmail.com (=?UTF-8?Q?Jo=C3=A3o_?= =?UTF-8?Q?T=C3=A1vora?=) Newsgroups: gmane.emacs.bugs Subject: bug#28821: [PATCH] Implement Python backend for Flymake Date: Fri, 13 Oct 2017 21:56:25 +0100 Message-ID: <87bmlan4w6.fsf@gmail.com> References: <87y3of2zbj.fsf@metapensiero.it> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1507928245 27630 195.159.176.226 (13 Oct 2017 20:57:25 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Fri, 13 Oct 2017 20:57:25 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.90 (gnu/linux) Cc: 28821@debbugs.gnu.org To: Lele Gaifax Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Fri Oct 13 22:57:19 2017 Return-path: Envelope-to: geb-bug-gnu-emacs@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 1e3710-0004tq-VX for geb-bug-gnu-emacs@m.gmane.org; Fri, 13 Oct 2017 22:57:07 +0200 Original-Received: from localhost ([::1]:51865 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e3718-0001AO-7K for geb-bug-gnu-emacs@m.gmane.org; Fri, 13 Oct 2017 16:57:14 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:52556) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e3712-0001AI-HR for bug-gnu-emacs@gnu.org; Fri, 13 Oct 2017 16:57:09 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e370y-0008Ev-Kk for bug-gnu-emacs@gnu.org; Fri, 13 Oct 2017 16:57:08 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:58029) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1e370y-0008Em-GN for bug-gnu-emacs@gnu.org; Fri, 13 Oct 2017 16:57:04 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1e370w-0004aL-5X for bug-gnu-emacs@gnu.org; Fri, 13 Oct 2017 16:57:04 -0400 X-Loop: help-debbugs@gnu.org Resent-From: joaotavora@gmail.com (=?UTF-8?Q?Jo=C3=A3o_?= =?UTF-8?Q?T=C3=A1vora?=) Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 13 Oct 2017 20:57:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 28821 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-Cc: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.150792820417597 (code B ref -1); Fri, 13 Oct 2017 20:57:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 13 Oct 2017 20:56:44 +0000 Original-Received: from localhost ([127.0.0.1]:38477 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e370e-0004Zk-JV for submit@debbugs.gnu.org; Fri, 13 Oct 2017 16:56:44 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:33249) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e370c-0004ZX-Ps for submit@debbugs.gnu.org; Fri, 13 Oct 2017 16:56:43 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e370W-00087U-LW for submit@debbugs.gnu.org; Fri, 13 Oct 2017 16:56:37 -0400 Original-Received: from lists.gnu.org ([2001:4830:134:3::11]:36868) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e370W-00087N-IP for submit@debbugs.gnu.org; Fri, 13 Oct 2017 16:56:36 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:52444) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e370V-00018Q-89 for bug-gnu-emacs@gnu.org; Fri, 13 Oct 2017 16:56:36 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e370R-00085k-B7 for bug-gnu-emacs@gnu.org; Fri, 13 Oct 2017 16:56:35 -0400 Original-Received: from mail-wr0-x22c.google.com ([2a00:1450:400c:c0c::22c]:54736) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1e370R-00085L-3X for bug-gnu-emacs@gnu.org; Fri, 13 Oct 2017 16:56:31 -0400 Original-Received: by mail-wr0-x22c.google.com with SMTP id o44so1854472wrf.11 for ; Fri, 13 Oct 2017 13:56:30 -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=KRsnWzUOedf1lUEgarXL6aacR+NKygQfdgohJTv8nh0=; b=m+n5aDnSK1ipxuu/QxcnTf71jNHUFD/AP5zYPUGRuDfUkIGYD7baNqD6xAIDXh22zz +kHOU+v+tcg46vjd+A/Iguw5XLFvLMWdCTc741pMzNXphLufONbGoKU4eORa3remfGy1 ywtzLd1z5uI047u7JH76N9rlKNG7DfYVjbHsu6SZlUL2PazfoZthmhEkRihOL++ZC3YL 3gNKfC+eB/xxvRqskoObg26i3/w+JhGRppeMJ+pF/B1cWsQBMYAZq1rFxMtdOrk4L9ao LgDOdEclK78xIL5ip8XoEVHpX8ey/UPng3yP6Jiaanhqz+lr/+iBRgqX99Uo8x8dzy1n AgNg== 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=KRsnWzUOedf1lUEgarXL6aacR+NKygQfdgohJTv8nh0=; b=EaBnobQodfSYBxj3qci/dBE6bUkd3s+/oLXhvCHCZAFhZJaTrgdEoL49ryEoaE5jIz 5GO70klH+aBNgjFFp/OINK8944ZRHl4mQhDbqsUAf9CbZImSBb31vN0FJdETxe7WNUXY gwYD0RLmPal2yvNU7ndL+iypYBiVfzSNyE3AWL2OaSkrm6xFuKi/CQ2Ys0qqmAkgX9KC e7eKpFZ3GibfZGzsFR1WuJ6bCTxpEF2Hc2HnABkWTQXnMK9Io2vQidAm86PVV5yx+ICe jYUXpkyF+spru0vCzZvAClo/r5Bs7302pp7DI0YcVjzD8zxp6PP8fJM44PV1PMZyN9Mv hK3Q== X-Gm-Message-State: AMCzsaWaqQ4PQ1jR+3ZkFfYMexi8gQaWymCOLxQZGf2OVU+bZ9yHLQY+ uYtV3o4pRBTMBw188Iv1ogyxezBZ X-Google-Smtp-Source: AOwi7QD2flRSQTM4FxJIfKhGYCCRh0YGn1TUBEZGvsaa16LRwY2jI1o2fIWJsu1lj52JFkF2VuBxPg== X-Received: by 10.223.142.45 with SMTP id n42mr2230230wrb.278.1507928189546; Fri, 13 Oct 2017 13:56:29 -0700 (PDT) Original-Received: from lolita.yourcompany.com (188.139.62.94.rev.vodafone.pt. [94.62.139.188]) by smtp.gmail.com with ESMTPSA id 38sm1487419wrl.76.2017.10.13.13.56.28 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 13 Oct 2017 13:56:28 -0700 (PDT) In-Reply-To: <87y3of2zbj.fsf@metapensiero.it> (Lele Gaifax's message of "Fri, 13 Oct 2017 11:04:48 +0200") X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:138363 Archived-At: 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. > +(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 :-)