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: Fri, 06 Oct 2017 09:09:46 +0200 Organization: Nautilus Entertainments Message-ID: <87k208n45h.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> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: blaine.gmane.org 1507273890 5817 195.159.176.226 (6 Oct 2017 07:11:30 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Fri, 6 Oct 2017 07:11:30 +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 Fri Oct 06 09:11:26 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 1e0Mn5-0000Y0-17 for ged-emacs-devel@m.gmane.org; Fri, 06 Oct 2017 09:11:23 +0200 Original-Received: from localhost ([::1]:43314 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e0MnA-0001Jr-ST for ged-emacs-devel@m.gmane.org; Fri, 06 Oct 2017 03:11:28 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:45355) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e0Mls-0000oL-RQ for emacs-devel@gnu.org; Fri, 06 Oct 2017 03:10:09 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e0Mlo-0003Uy-E4 for emacs-devel@gnu.org; Fri, 06 Oct 2017 03:10:08 -0400 Original-Received: from [195.159.176.226] (port=49542 helo=blaine.gmane.org) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1e0Mlo-0003UZ-5k for emacs-devel@gnu.org; Fri, 06 Oct 2017 03:10:04 -0400 Original-Received: from list by blaine.gmane.org with local (Exim 4.84_2) (envelope-from ) id 1e0Mld-0007d2-UR for emacs-devel@gnu.org; Fri, 06 Oct 2017 09:09:53 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 124 Original-X-Complaints-To: usenet@blaine.gmane.org Cancel-Lock: sha1:69njjhDEadq/dMoMZoZ6q7n5YdE= 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:219164 Archived-At: --=-=-= Content-Type: text/plain Stefan Monnier writes: > I think the Python backend would naturally belong in python.el I'm attaching what I'm currently testing out: how should I proceed to contribute it? Thanks a lot, ciao, lele. --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=python.el.diff diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index 9aa5134ca0..d29139fbde 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el @@ -5137,6 +5137,89 @@ 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 + "^\\(?:.*\\.py\\|\\):\\(?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-warn-msg-regexp + "\\(^redefinition\\|.*unused.*\\|used$\\)" + "The regexp used to discriminate warnings from errors." + :group 'python-flymake + :type 'regexp) + +(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 = (if (string-match + python-flymake-warn-msg-regexp msg) + :warning :error) + collect (flymake-make-diagnostic + source beg end type msg) + into diags + finally (funcall report-fn diags)))) + (kill-buffer (process-buffer proc)))))) + (process-send-region 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. --=-=-=--