unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Lele Gaifax <lele@metapensiero.it>
To: emacs-devel@gnu.org
Subject: Re: Flymake refactored
Date: Fri, 06 Oct 2017 09:09:46 +0200	[thread overview]
Message-ID: <87k208n45h.fsf@metapensiero.it> (raw)
In-Reply-To: jwvd1612bmn.fsf-monnier+emacs@gnu.org

[-- Attachment #1: Type: text/plain, Size: 230 bytes --]

Stefan Monnier <monnier@iro.umontreal.ca> 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.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: python.el.diff --]
[-- Type: text/x-diff, Size: 3811 bytes --]

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))
 
 \f
+;;; 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\\|<stdin>\\):\\(?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))
+
+\f
 (defun python-electric-pair-string-delimiter ()
   (when (and electric-pair-mode
              (memq last-command-event '(?\" ?\'))

[-- Attachment #3: Type: text/plain, Size: 206 bytes --]


-- 
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.

  reply	other threads:[~2017-10-06  7:09 UTC|newest]

Thread overview: 79+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-28 14:27 Flymake refactored João Távora
2017-09-28 19:52 ` Stefan Monnier
2017-09-29  0:22   ` João Távora
2017-09-29  3:11     ` Stefan Monnier
2017-10-01 16:52       ` João Távora
2017-10-01 20:50         ` Stefan Monnier
2017-10-02  1:01           ` João Távora
2017-10-02  3:12             ` Stefan Monnier
2017-10-03  0:33               ` João Távora
2017-10-03  1:09                 ` Stefan Monnier
2017-09-29 12:51   ` Dmitry Gutov
2017-09-29 14:55     ` Ted Zlatanov
2017-09-29 15:03       ` Dmitry Gutov
2017-09-29 16:26         ` Ted Zlatanov
2017-09-29 17:35           ` Dmitry Gutov
2017-09-29 17:56             ` Ted Zlatanov
2017-09-30 15:07               ` Dmitry Gutov
2017-09-30  7:55 ` Marcin Borkowski
2017-09-30 23:43   ` João Távora
2017-10-01  8:53     ` Marcin Borkowski
2017-10-01 11:54       ` Mark Oteiza
2017-10-04 17:37 ` Simen Heggestøyl
2017-10-05  2:08   ` João Távora
2017-10-05  3:52     ` Mark Oteiza
2017-10-05 10:57       ` João Távora
2017-10-05 13:11         ` Stefan Monnier
2017-10-05 14:45           ` João Távora
2017-10-05 23:01             ` João Távora
2017-10-05 21:22         ` Mark Oteiza
2017-10-05 23:05           ` João Távora
2017-10-06  3:35             ` Stefan Monnier
2017-10-06  7:09               ` Lele Gaifax [this message]
2017-10-06  8:14                 ` Eli Zaretskii
2017-10-06  8:19                   ` Lele Gaifax
2017-10-06  9:48                     ` Eli Zaretskii
2017-10-06  9:54                       ` Lele Gaifax
2017-10-06 13:04                 ` Mark Oteiza
2017-10-06 14:47                   ` Lele Gaifax
2017-10-06 15:21                     ` Mark Oteiza
2017-10-06 15:26                       ` Mark Oteiza
2017-10-06 15:28                       ` Lele Gaifax
2017-10-06 16:28                         ` João Távora
2017-10-06 19:24                           ` Lele Gaifax
2017-10-06 15:13               ` João Távora
2017-10-07 13:28                 ` Stefan Monnier
2017-10-07 13:44                   ` Eli Zaretskii
2017-10-07 14:40                     ` Lele Gaifax
2017-10-07 14:52                       ` Eli Zaretskii
2017-10-08  2:06                       ` Stefan Monnier
2017-10-08  9:32                         ` João Távora
2017-10-08 11:24                           ` Lele Gaifax
2017-10-08 14:17                           ` Stefan Monnier
2017-10-08 23:33                             ` João Távora
2017-10-09  3:01                               ` Stefan Monnier
2017-10-09 10:19                                 ` João Távora
2017-10-09 15:50                                   ` [SUSPECTED SPAM] " Stefan Monnier
2017-10-09 16:33                                   ` [PATCH] " Lele Gaifax
2017-10-07  6:31               ` Marcin Borkowski
2017-10-07 13:37                 ` Stefan Monnier
2017-10-07 16:48                   ` Marcin Borkowski
2017-10-06 12:54           ` John Wiegley
2017-10-06 15:17             ` Mark Oteiza
2017-10-06 16:04               ` João Távora
2017-10-06 21:22                 ` Mark Oteiza
2017-10-06 22:03                   ` João Távora
2017-10-07 13:31               ` Stefan Monnier
2017-10-07 16:02                 ` João Távora
2017-10-07 16:07               ` João Távora
2017-10-07 18:18                 ` Mark Oteiza
2017-10-08  9:06                   ` João Távora
2017-10-08 12:51                     ` Mark Oteiza
2017-10-08 23:21                       ` João Távora
2017-10-10 14:27                         ` Mark Oteiza
2017-10-10 15:20                           ` João Távora
2017-10-10 16:10                             ` Mark Oteiza
2017-10-05 11:28     ` Lele Gaifax
2017-10-05 15:12       ` Lele Gaifax
2017-10-10 10:40 ` Lele Gaifax
2017-10-10 12:27   ` João Távora

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87k208n45h.fsf@metapensiero.it \
    --to=lele@metapensiero.it \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).