From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Eduard Wiebe Newsgroups: gmane.emacs.bugs Subject: bug#14217: 24.3.50; patch: flymake.el -- warning predicate Date: Tue, 16 Apr 2013 23:36:29 +0200 Message-ID: <87y5ci5faa.fsf@pusto.de> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: ger.gmane.org 1366141071 20886 80.91.229.3 (16 Apr 2013 19:37:51 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 16 Apr 2013 19:37:51 +0000 (UTC) To: 14217@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Tue Apr 16 21:37:55 2013 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1USBhS-0004Z7-Hu for geb-bug-gnu-emacs@m.gmane.org; Tue, 16 Apr 2013 21:37:54 +0200 Original-Received: from localhost ([::1]:39333 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1USBhS-0001FK-6r for geb-bug-gnu-emacs@m.gmane.org; Tue, 16 Apr 2013 15:37:54 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:48615) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1USBhL-0001FA-GV for bug-gnu-emacs@gnu.org; Tue, 16 Apr 2013 15:37:50 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1USBhH-0003Q8-Sc for bug-gnu-emacs@gnu.org; Tue, 16 Apr 2013 15:37:47 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:51066) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1USBhH-0003Px-Os for bug-gnu-emacs@gnu.org; Tue, 16 Apr 2013 15:37:43 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.72) (envelope-from ) id 1USBlR-0004RF-OV for bug-gnu-emacs@gnu.org; Tue, 16 Apr 2013 15:42:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Eduard Wiebe Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 16 Apr 2013 19:42:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 14217 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.136614126516956 (code B ref -1); Tue, 16 Apr 2013 19:42:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 16 Apr 2013 19:41:05 +0000 Original-Received: from localhost ([127.0.0.1]:55175 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1USBkW-0004PQ-7Q for submit@debbugs.gnu.org; Tue, 16 Apr 2013 15:41:04 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:36983) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1USBkT-0004P9-Vu for submit@debbugs.gnu.org; Tue, 16 Apr 2013 15:41:03 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1USBgE-0003CT-SM for submit@debbugs.gnu.org; Tue, 16 Apr 2013 15:36:43 -0400 Original-Received: from lists.gnu.org ([208.118.235.17]:47633) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1USBgE-0003CP-Q8 for submit@debbugs.gnu.org; Tue, 16 Apr 2013 15:36:38 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:48291) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1USBg6-0000On-DO for bug-gnu-emacs@gnu.org; Tue, 16 Apr 2013 15:36:38 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1USBg0-0002uI-Cw for bug-gnu-emacs@gnu.org; Tue, 16 Apr 2013 15:36:30 -0400 Original-Received: from wp093.webpack.hosteurope.de ([80.237.132.100]:45434) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1USBfz-0002to-VR for bug-gnu-emacs@gnu.org; Tue, 16 Apr 2013 15:36:24 -0400 Original-Received: from f049237196.adsl.alicedsl.de ([78.49.237.196] helo=nirvana); authenticated by wp093.webpack.hosteurope.de running ExIM with esmtpsa (TLS1.0:RSA_AES_256_CBC_SHA1:32) id 1USBfw-0007kM-N0; Tue, 16 Apr 2013 21:36:21 +0200 Original-Received: from ew by nirvana with local (Exim 4.72) (envelope-from ) id 1USDYE-0000gr-Am for bug-gnu-emacs@gnu.org; Tue, 16 Apr 2013 23:36:30 +0200 X-bounce-key: webpack.hosteurope.de;ew@pusto.de;1366140983;6d925acb; X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x 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.13 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 140.186.70.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-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:73462 Archived-At: --=-=-= Content-Type: text/plain Hello, here is a patch, which extends current flymake mechanism for classifing error text as warning. --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=flymake.warn.pred.patch diff --git a/doc/misc/ChangeLog b/doc/misc/ChangeLog index f99b821..ea347ea 100644 --- a/doc/misc/ChangeLog +++ b/doc/misc/ChangeLog @@ -1,3 +1,8 @@ +2013-04-16 Eduard Wiebe + + * flymake.texi (Parsing the output, Customizable variables): Add + reference to `flymake-warning-predicate'. + 2013-04-15 Michael Albinus * tramp.texi (Frequently Asked Questions): New item for diff --git a/doc/misc/flymake.texi b/doc/misc/flymake.texi index 5dedda1..7196eed 100644 --- a/doc/misc/flymake.texi +++ b/doc/misc/flymake.texi @@ -311,6 +311,9 @@ Used when looking for a master file. @xref{Locating a master file}. Patterns for error/warning messages in the form @code{(regexp file-idx line-idx col-idx err-text-idx)}. @xref{Parsing the output}. +@item flymake-warning-predicate +Predicate to classify error text as warning. @xref{Parsing the output}. + @item flymake-compilation-prevents-syntax-check A flag indicating whether compilation and syntax check of the same file cannot be run simultaneously. @@ -706,7 +709,10 @@ list of items of the form @code{(regexp file-idx line-idx err-text-idx)}, used to determine whether a particular line is an error message and extract file name, line number and error text, respectively. Error type (error/warning) is also guessed by matching -error text with the '@code{^[wW]arning}' pattern. Anything that was not +error text with the @code{flymake-warning-predicate} predicate. The +predicate is either a regular expression, default @code{"[wW]arning"}, +or a function. When the predicate is a function, it takes error text +as argument and returns a non-nil for a warning. Anything that was not classified as a warning is considered an error. Type is then used to sort error menu items, which shows error messages first. diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 81868e8..f8cb826 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,12 @@ +2013-04-15 Eduard Wiebe + + Extend flymakes warning predicate. + + * progmodes/flymake.el (flymake-warning-predicate): New. + (flymake-parse-line): Use it. + (flymake-warning-re): Make obsolete alias to + `flymake-warning-predicate'. + 2013-04-15 Stefan Monnier * minibuffer.el (minibuffer-complete): Don't just scroll diff --git a/lisp/progmodes/flymake.el b/lisp/progmodes/flymake.el index 0f92df9..905ad49 100644 --- a/lisp/progmodes/flymake.el +++ b/lisp/progmodes/flymake.el @@ -1002,8 +1002,13 @@ from compile.el") ;; :type '(repeat (string number number number)) ;;) -(defvar flymake-warning-re "^[wW]arning" - "Regexp matching against err-text to detect a warning.") +(define-obsolete-variable-alias 'flymake-warning-re 'flymake-warning-predicate "24.4") +(defcustom flymake-warning-predicate "^[wW]arning" + "Predicate matching against error text to detect a warning." + :group 'flymake + :version "24.4" + :type '(choice (regexp :tag "Regexp predicate") + (function :tag "Function predicate"))) (defun flymake-parse-line (line) "Parse LINE to see if it is an error or warning. @@ -1024,10 +1029,13 @@ Return its components if so, nil otherwise." (setq err-text (if (> (length (car patterns)) 4) (match-string (nth 4 (car patterns)) line) (flymake-patch-err-text (substring line (match-end 0))))) - (or err-text (setq err-text "")) - (if (and err-text (string-match flymake-warning-re err-text)) - (setq err-type "w") - ) + (if (null err-text) + (setq err-text "") + (when (cond ((stringp flymake-warning-predicate) + (string-match flymake-warning-predicate err-text)) + ((functionp flymake-warning-predicate) + (funcall flymake-warning-predicate err-text))) + (setq err-type "w"))) (flymake-log 3 "parse line: file-idx=%s line-idx=%s file=%s line=%s text=%s" file-idx line-idx raw-file-name line-no err-text) (setq matched t))) diff --git a/test/ChangeLog b/test/ChangeLog index bf68984..21e2f16 100644 --- a/test/ChangeLog +++ b/test/ChangeLog @@ -1,3 +1,12 @@ +2013-04-15 Eduard Wiebe + + Test suite for flymake. + + * automated/flymake-tests.el: + * automated/flymake/warnpred/Makefile + * automated/flymake/warnpred/test.c + * automated/flymake/warnpred/test.pl: New files. + 2013-04-09 Masatake YAMATO * automated/add-log-tests.el: New file. (Bug#14112) --=-=-= Content-Type: text/plain The corresponding test driver: --=-=-= Content-Type: application/emacs-lisp Content-Disposition: attachment; filename=flymake-tests.el Content-Transfer-Encoding: quoted-printable ;;; flymake-tests.el --- Test suite for flymake ;; Copyright (C) 2011-2013 Free Software Foundation, Inc. ;; Author: Eduard Wiebe ;; This file is part of GNU Emacs. ;; GNU Emacs is free software: you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation, either version 3 of the License, or ;; (at your option) any later version. ;; GNU Emacs is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with GNU Emacs. If not, see . ;;; Commentary: ;;; Code: (require 'ert) (require 'flymake) (defgroup flymake-tests nil "Test suite for flymake.") ;; Warning predicate (defun flymake-tests--current-face (file predicate) (let ((buffer (find-file-noselect file))) (unwind-protect (with-current-buffer (find-file-noselect file) (setq-local flymake-warning-predicate predicate) (goto-char (point-min)) (flymake-mode 1) (sleep-for (+ 0.5 flymake-no-changes-timeout)) ; XXX: is this rel= iable enough? (flymake-goto-next-error) (face-at-point)) (and buffer (kill-buffer buffer))))) (ert-deftest warnining-predicate-rx-gcc () "Test GCC warning via regexp predicate." :expected-result (if (executable-find "gcc") :passed :failed) (should (eq 'flymake-warnline (flymake-tests--current-face "flymake/warnpred/test.c" "^[Ww]arning")))) (ert-deftest warning-predicate-function-gcc () "Test GCC warning via function predicate." :expected-result (if (and (executable-find "gcc") (executable-find "make"= )) :passed :failed) (should (eq 'flymake-warnline (flymake-tests--current-face "flymake/warnpred/test.c" (lambda (msg) (string-match "^[Ww]arning" msg)))))) (ert-deftest warning-predicate-rx-perl () "Test perl warning via regular expression predicate." :expected-result (if (executable-find "perl") :passed :failed) (should (eq 'flymake-warnline (flymake-tests--current-face "flymake/warnpred/test.pl" "^Scalar value")))) (ert-deftest warning-predicate-function-perl () "Test perl warning via function predicate." :expected-result (if (executable-find "perl") :passed :failed) (should (eq 'flymake-warnline (flymake-tests--current-face "flymake/warnpred/test.pl" (lambda (msg) (string-match "^Scalar value" msg)))))) (provide 'flymake-tests) ;;; flymake.el ends here --=-=-= Content-Type: text/plain Following files are test helper and should be placed under test/automated/flymake/warnpred directory. --=-=-= Content-Type: application/octet-stream Content-Disposition: attachment; filename=Makefile Content-Transfer-Encoding: base64 IyBNYWtlZmlsZSBmb3IgZmx5bWFrZSB0ZXN0cwoKQ0NfT1BUUyA9IC1XYWxsCgpjaGVjay1zeW50 YXg6CgkkKENDKSAkKENDX09QVFMpICR7Q0hLX1NPVVJDRVN9CgojIGVvZgo= --=-=-= Content-Type: text/x-csrc Content-Disposition: attachment; filename=test.c int main() { char c = 1000; return c; } --=-=-= Content-Type: text/x-perl Content-Disposition: attachment; filename=test.pl @arr = [1,2,3,4]; @arr[1] = -1; --=-=-=--