[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] scratch/flymake-refactor 192cb7f 17/18: flymake-ui.el high
From: |
João Távora |
Subject: |
[Emacs-diffs] scratch/flymake-refactor 192cb7f 17/18: flymake-ui.el highlights GCC notes detected by flymake-proc.el |
Date: |
Thu, 21 Sep 2017 20:35:26 -0400 (EDT) |
branch: scratch/flymake-refactor
commit 192cb7f7dc42d0ee0d8690672db3aabe15c05245
Author: João Távora <address@hidden>
Commit: João Távora <address@hidden>
flymake-ui.el highlights GCC notes detected by flymake-proc.el
* lisp/progmodes/flymake-proc.el
(flymake-proc--diagnostics-for-pattern): Rewrite (using cl-loop) to
honour more sophisticated flymake-proc-diagnostic-type-pred.
(flymake-warning-re): Is now an obsolete alias for
flymake-proc-diagnostic-type-pred.
(flymake-proc-diagnostic-type-pred): Rename and augment from
flymake-proc-warning-predicate. (flymake-proc-warning-predicate):
Delete.
* lisp/progmodes/flymake-ui.el (flymake-note): New face.
(flymake-diagnostic-types-alist): Simplify.
(flymake-note): New overlay category.
(flymake-type-alist): Rename from flymake--type-alist.
(flymake--diag-errorp): Rewrite.
(flymake--highlight-line): Use flymake-type-alist.
* test/lisp/progmodes/flymake-tests.el
(different-diagnostic-types): Rename from errors-and-warnings.
Check notes.
(flymake-tests--call-with-fixture): Use
flymake-proc-diagnostic-type-pred.
---
lisp/progmodes/flymake-proc.el | 120 +++++++++++++++++++----------------
lisp/progmodes/flymake-ui.el | 53 ++++++++++------
test/lisp/progmodes/flymake-tests.el | 8 +--
3 files changed, 103 insertions(+), 78 deletions(-)
diff --git a/lisp/progmodes/flymake-proc.el b/lisp/progmodes/flymake-proc.el
index 022f025..fb40467 100644
--- a/lisp/progmodes/flymake-proc.el
+++ b/lisp/progmodes/flymake-proc.el
@@ -396,47 +396,50 @@ Create parent directories as needed."
(flymake-log 3 "saved buffer %s in file %s" (buffer-name) file-name))
(defun flymake-proc--diagnostics-for-pattern (proc pattern)
- (condition-case-unless-debug err
- (pcase-let ((`(,regexp ,file-idx ,line-idx ,col-idx ,message-idx)
- pattern)
- (retval))
- (while (search-forward-regexp regexp nil t)
- (let* ((fname (and file-idx (match-string file-idx)))
- (message (and message-idx (match-string message-idx)))
- (line-string (and line-idx (match-string line-idx)))
- (line-number (and line-string
- (string-to-number line-string)))
- (col-string (and col-idx (match-string col-idx)))
- (col-number (and col-string
- (string-to-number col-string))))
- (with-current-buffer (process-buffer proc)
- (push
- (flymake-make-diagnostic
- :file fname
- :line line-number
- :col col-number
- :type (if (and
- message
- (cond ((stringp flymake-proc-warning-predicate)
- (string-match flymake-proc-warning-predicate
- message))
- ((functionp flymake-proc-warning-predicate)
- (funcall flymake-proc-warning-predicate
- message))))
- "w"
- "e")
- :text message
- :full-file (and fname
- (funcall
- (flymake-proc--get-real-file-name-function
- fname)
- fname)))
- retval))))
- retval)
- (error
- (flymake-log 1 "Error parsing process output for pattern %s: %s"
- pattern err)
- nil)))
+ (cl-flet ((guess-type
+ (pred message)
+ (cond ((null message)
+ :error)
+ ((stringp pred)
+ (if (string-match pred message)
+ :warning
+ :error))
+ ((functionp pred)
+ (let ((probe (funcall pred message)))
+ (cond ((flymake-type-alist probe)
+ probe)
+ (probe
+ :warning)
+ (t
+ :error)))))))
+ (condition-case-unless-debug err
+ (cl-loop
+ with (regexp file-idx line-idx col-idx message-idx) = pattern
+ while (search-forward-regexp regexp nil t)
+ for fname = (and file-idx (match-string file-idx))
+ for message = (and message-idx (match-string message-idx))
+ for line-string = (and line-idx (match-string line-idx))
+ for line-number = (and line-string
+ (string-to-number line-string))
+ for col-string = (and col-idx (match-string col-idx))
+ for col-number = (and col-string
+ (string-to-number col-string))
+ collect (with-current-buffer (process-buffer proc)
+ (flymake-make-diagnostic
+ :file fname
+ :line line-number
+ :col col-number
+ :type (guess-type flymake-proc-diagnostic-type-pred
message)
+ :text message
+ :full-file (and fname
+ (funcall
+ (flymake-proc--get-real-file-name-function
+ fname)
+ fname)))))
+ (error
+ (flymake-log 1 "Error parsing process output for pattern %s: %s"
+ pattern err)
+ nil))))
(defun flymake-proc--process-filter (proc string)
"Parse STRING and collect diagnostics info."
@@ -569,12 +572,29 @@ Convert it to flymake internal format."
Use `flymake-proc-reformat-err-line-patterns-from-compile-el' to add patterns
from compile.el")
-(define-obsolete-variable-alias 'flymake-warning-re
'flymake-proc-warning-predicate "24.4")
-(defvar flymake-proc-warning-predicate "^[wW]arning"
- "Predicate matching against error text to detect a warning.
-Takes a single argument, the error's text and should return non-nil
-if it's a warning.
-Instead of a function, it can also be a regular expression.")
+(define-obsolete-variable-alias 'flymake-warning-re
'flymake-proc-diagnostic-type-pred "26.1")
+(defvar flymake-proc-diagnostic-type-pred
+ 'flymake-proc-default-guess
+ "Predicate matching against diagnostic text to detect its type.
+Takes a single argument, the diagnostic's text and should return
+a value suitable for indexing
+`flymake-dianostic-types-alist' (which see). If the returned
+value is nil, a type of `error' is assumed. For some backward
+compatibility, if a non-nil value is returned that that doesn't
+index that alist, a type of `:warning' is assumed.
+
+Instead of a function, it can also be a string, a regular
+expression. A match indicates `:warning' type, otherwise
+`:error'")
+
+(defun flymake-proc-default-guess (text)
+ "Guess if TEXT means a warning, a note or an error."
+ (cond ((string-match "^[wW]arning" text)
+ :warning)
+ ((string-match "^[nN]ote" text)
+ :note)
+ (t
+ :error)))
(defun flymake-proc-get-project-include-dirs-imp (basedir)
"Include dirs for the project current file belongs to."
@@ -1174,12 +1194,6 @@ Convert it to flymake internal format.")
(REGEXP FILE-IDX LINE-IDX COL-IDX ERR-TEXT-IDX).
Use `flymake-reformat-err-line-patterns-from-compile-el' to add patterns
from compile.el")
- (define-obsolete-variable-alias 'flymake-warning-predicate
- 'flymake-proc-warning-predicate "26.1"
- "Predicate matching against error text to detect a warning.
-Takes a single argument, the error's text and should return non-nil
-if it's a warning.
-Instead of a function, it can also be a regular expression.")
(define-obsolete-function-alias 'flymake-parse-line
'flymake-proc-parse-line "26.1"
"Parse LINE to see if it is an error or warning.
diff --git a/lisp/progmodes/flymake-ui.el b/lisp/progmodes/flymake-ui.el
index 4422fb0..4cdad95 100644
--- a/lisp/progmodes/flymake-ui.el
+++ b/lisp/progmodes/flymake-ui.el
@@ -194,6 +194,15 @@ verify FILTER, sort them by COMPARE (using KEY)."
:version "24.4"
:group 'flymake)
+(defface flymake-note
+ '((((supports :underline (:style wave)))
+ :underline (:style wave :color "yellow green"))
+ (t
+ :inherit warning))
+ "Face used for marking note regions."
+ :version "26.1"
+ :group 'flymake)
+
(define-obsolete-face-alias 'flymake-warnline 'flymake-warning "26.1")
(define-obsolete-face-alias 'flymake-errline 'flymake-error "26.1")
@@ -231,13 +240,14 @@ Or nil if the region is invalid."
nil)))
(defvar flymake-diagnostic-types-alist
- `((("e" :error error)
+ `((:error
. ((category . flymake-error)))
- (("w" :warning warning)
- . ((category . flymake-warning))))
- "Alist (KEY PROPS) of properties of flymake error types.
-KEY can be anything passed as `:type' to `flymake-diag-make', or
-a list of such objects that all share PROPS.
+ (:warning
+ . ((category . flymake-warning)))
+ (:note
+ . ((category . flymake-note))))
+ "Alist ((KEY . PROPS)*) of properties of flymake error types.
+KEY can be anything passed as `:type' to `flymake-diag-make'.
PROPS is an alist of properties that are applied, in order, to
the overlays representing diagnostics. Every property pertaining
@@ -259,25 +269,26 @@ with flymake-specific meaning can also be used.
(put 'flymake-warning 'face 'flymake-warning)
(put 'flymake-warning 'bitmap flymake-warning-bitmap)
-(put 'flymake-warning 'warning (warning-numeric-level :warning))
+(put 'flymake-warning 'severity (warning-numeric-level :warning))
+
+(put 'flymake-note 'face 'flymake-note)
+(put 'flymake-note 'bitmap flymake-warning-bitmap)
+(put 'flymake-note 'severity (warning-numeric-level :debug))
-(defun flymake--type-alist (diagnostic-type)
+(defun flymake-type-alist (diagnostic-type)
+ "Look up DIAGNOSTIC-TYPE in `flymake-diagnostic-types-alist'."
(assoc-default diagnostic-type
- flymake-diagnostic-types-alist
- (lambda (entry key)
- (or (equal key entry)
- (member key entry)))))
+ flymake-diagnostic-types-alist))
(defun flymake--diag-errorp (diag)
"Tell if DIAG is a flymake error or something else"
- (let ((sev (flymake--severity diag)))
- (= sev (warning-numeric-level :error))))
-
-(defun flymake--severity (diagnostic)
- (or (assoc-default
- 'severity
- (flymake--type-alist (flymake--diag-type diagnostic)))
- ))
+ ;; FIXME repeats some logic in ‘flymake--highlight-line’
+ (if-let* ((alist (flymake-type-alist (flymake--diag-type diag)))
+ (sev (or (assoc-default 'severity alist)
+ (get (assoc-default 'category alist)
+ 'severity))))
+ (>= sev (warning-numeric-level :error))
+ t))
(defun flymake--fringe-overlay-spec (bitmap)
(and flymake-fringe-indicator-position
@@ -295,7 +306,7 @@ with flymake-specific meaning can also be used.
;; First copy over to ov every property in the relevant alist.
;;
(cl-loop for (k . v) in
- (flymake--type-alist (flymake--diag-type diagnostic))
+ (flymake-type-alist (flymake--diag-type diagnostic))
do (overlay-put ov k v))
;; Now ensure some defaults are set
;;
diff --git a/test/lisp/progmodes/flymake-tests.el
b/test/lisp/progmodes/flymake-tests.el
index 7057288..76ec31b 100644
--- a/test/lisp/progmodes/flymake-tests.el
+++ b/test/lisp/progmodes/flymake-tests.el
@@ -41,7 +41,7 @@
nil sev-pred-supplied-p))
"Call FN after flymake setup in FILE, using `flymake-proc`.
SEVERITY-PREDICATE is used to setup
-`flymake-proc-warning-predicate'."
+`flymake-proc-diagnostic-type-pred'"
(let* ((file (expand-file-name file flymake-tests-data-directory))
(visiting (find-buffer-visiting file))
(buffer (or visiting (find-file-noselect file)))
@@ -51,7 +51,7 @@ SEVERITY-PREDICATE is used to setup
(with-current-buffer buffer
(save-excursion
(when sev-pred-supplied-p
- (setq-local flymake-proc-warning-predicate severity-predicate))
+ (setq-local flymake-proc-diagnostic-type-pred
severity-predicate))
(goto-char (point-min))
(flymake-mode 1)
;; Weirdness here... http://debbugs.gnu.org/17647#25
@@ -115,13 +115,13 @@ SEVERITY-PREDICATE is used to setup
(should (eq 'flymake-warning
(face-at-point)))))
-(ert-deftest errors-and-warnings ()
+(ert-deftest different-diagnostic-types ()
"Test GCC warning via function predicate."
(skip-unless (and (executable-find "gcc") (executable-find "make")))
(flymake-tests--with-flymake
("errors-and-warnings.c")
(flymake-goto-next-error)
- (should (eq 'flymake-error (face-at-point)))
+ (should (eq 'flymake-note (face-at-point)))
(flymake-goto-next-error)
(should (eq 'flymake-warning (face-at-point)))
(flymake-goto-next-error)
- [Emacs-diffs] scratch/flymake-refactor 7140018 18/18: Protect flymake-ui against commands like fill-paragraph, (continued)
- [Emacs-diffs] scratch/flymake-refactor 7140018 18/18: Protect flymake-ui against commands like fill-paragraph, João Távora, 2017/09/21
- [Emacs-diffs] scratch/flymake-refactor 593d4303 16/18: Add a new flymake test for multiple errors and warnings, João Távora, 2017/09/21
- [Emacs-diffs] scratch/flymake-refactor 46e0721 01/18: Fix test failure introduced by previous commit, João Távora, 2017/09/21
- [Emacs-diffs] scratch/flymake-refactor 46b4391 09/18: flymake-proc.el parses column numbers from gcc/javac errors, João Távora, 2017/09/21
- [Emacs-diffs] scratch/flymake-refactor 205c444 03/18: Use non-obsolete variable names in flymake-tests.el, João Távora, 2017/09/21
- [Emacs-diffs] scratch/flymake-refactor f3b8a72 13/18: Refactor flymake-tests.el in preparation for more tests, João Távora, 2017/09/21
- [Emacs-diffs] scratch/flymake-refactor bac7512 05/18: New flymake-diagnostic-types-alist and more cleanup, João Távora, 2017/09/21
- [Emacs-diffs] scratch/flymake-refactor d3168cf 02/18: Make lisp/progmodes/flymake-ui.el some 150 lines lighter, João Távora, 2017/09/21
- [Emacs-diffs] scratch/flymake-refactor 61ba20b 14/18: Echo flymake error messages when navigating errors interactively, João Távora, 2017/09/21
- [Emacs-diffs] scratch/flymake-refactor b2c4135 08/18: Clarify logic around flymake-diagnostic-types-alist, João Távora, 2017/09/21
- [Emacs-diffs] scratch/flymake-refactor 192cb7f 17/18: flymake-ui.el highlights GCC notes detected by flymake-proc.el,
João Távora <=
- [Emacs-diffs] scratch/flymake-refactor 4292342 06/18: Further simplify progmodes/flymake-ui.el, João Távora, 2017/09/21
- [Emacs-diffs] scratch/flymake-refactor 14db516 15/18: flymake-ui.el checks file names before considering diagnostics, João Távora, 2017/09/21
- [Emacs-diffs] scratch/flymake-refactor c5cc7e9 10/18: Make debugging flymake-proc.el easier, João Távora, 2017/09/21
- [Emacs-diffs] scratch/flymake-refactor 12aa247 12/18: Protect against timer triggers when no flymake-mode, João Távora, 2017/09/21