emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] scratch/flymake-refactor 4fea8a9 30/52: Allow filtering in


From: João Távora
Subject: [Emacs-diffs] scratch/flymake-refactor 4fea8a9 30/52: Allow filtering in flymake-goto-[next/prev]-error
Date: Sun, 1 Oct 2017 12:40:48 -0400 (EDT)

branch: scratch/flymake-refactor
commit 4fea8a94f82ff659dfedf62d39c782ac28719618
Author: João Távora <address@hidden>
Commit: João Távora <address@hidden>

    Allow filtering in flymake-goto-[next/prev]-error
    
    It's useful for backends like the upcoming flymake-elisp-checkdoc
    backend, for example, which litters everything with low-priority notes.
    
    * lisp/progmodes/flymake-ui.el (flymake-goto-prev-error)
    (flymake-goto-next-error): Accept FILTER argument.
    
    * test/lisp/progmodes/flymake-tests.el
    (different-diagnostic-types, dummy-backends): Pass FILTER to
    flymake-goto-prev-error.
---
 lisp/progmodes/flymake-ui.el         | 51 +++++++++++++++++++++++++++++-------
 test/lisp/progmodes/flymake-tests.el |  4 +--
 2 files changed, 44 insertions(+), 11 deletions(-)

diff --git a/lisp/progmodes/flymake-ui.el b/lisp/progmodes/flymake-ui.el
index cd5ffe3..bd46fcf 100644
--- a/lisp/progmodes/flymake-ui.el
+++ b/lisp/progmodes/flymake-ui.el
@@ -642,11 +642,30 @@ sources."
     (flymake-mode)
     (flymake-log 3 "automatically turned ON")))
 
-(defun flymake-goto-next-error (&optional n interactive)
-  "Go to next, or Nth next, flymake error in buffer."
-  (interactive (list 1 t))
+(defun flymake-goto-next-error (&optional n filter interactive)
+  "Go to Nth next flymake error in buffer matching FILTER.
+FILTER is a list of diagnostic types found in
+`flymake-diagnostic-types-alist', or nil, if no filter is to be
+applied.
+
+Interactively, always goes to the next error.  Also
+interactively, FILTER is determined by the prefix arg.  With no
+prefix arg, don't use a filter, otherwise only consider
+diagnostics of type `:error' and `:warning'."
+  (interactive (list 1
+                     (if current-prefix-arg
+                         '(:error :warning))
+                     t))
   (let* ((n (or n 1))
-         (ovs (flymake--overlays :filter 'flymake--diagnostic
+         (ovs (flymake--overlays :filter
+                                 (lambda (ov)
+                                   (let ((diag (overlay-get
+                                                ov
+                                                'flymake--diagnostic)))
+                                     (and diag
+                                          (or (not filter)
+                                              (memq (flymake--diag-type diag)
+                                                    filter)))))
                                  :compare (if (cl-plusp n) #'< #'>)
                                  :key #'overlay-start))
          (chain (cl-member-if (lambda (ov)
@@ -664,12 +683,26 @@ sources."
               (funcall (overlay-get target 'help-echo)
                        nil nil (point)))))
           (interactive
-           (user-error "No more flymake errors")))))
+           (user-error "No more flymake errors%s"
+                       (if filter
+                           (format " of types %s" filter)
+                         ""))))))
+
+(defun flymake-goto-prev-error (&optional n filter interactive)
+  "Go to Nth previous flymake error in buffer matching FILTER.
+FILTER is a list of diagnostic types found in
+`flymake-diagnostic-types-alist', or nil, if no filter is to be
+applied.
+
+Interactively, always goes to the previous error.  Also
+interactively, FILTER is determined by the prefix arg.  With no
+prefix arg, don't use a filter, otherwise only consider
+diagnostics of type `:error' and `:warning'."
+  (interactive (list 1 (if current-prefix-arg
+                           '(:error :warning))
+                     t))
+  (flymake-goto-next-error (- (or n 1)) filter interactive))
 
-(defun flymake-goto-prev-error (&optional n interactive)
-  "Go to previous, or Nth previous, flymake error in buffer."
-  (interactive (list 1 t))
-  (flymake-goto-next-error (- (or n 1)) interactive))
 
 (provide 'flymake-ui)
 ;;; flymake-ui.el ends here
diff --git a/test/lisp/progmodes/flymake-tests.el 
b/test/lisp/progmodes/flymake-tests.el
index 521d045..494d1c9 100644
--- a/test/lisp/progmodes/flymake-tests.el
+++ b/test/lisp/progmodes/flymake-tests.el
@@ -128,7 +128,7 @@ SEVERITY-PREDICATE is used to setup
     (should (eq 'flymake-warning (face-at-point)))
     (flymake-goto-next-error)
     (should (eq 'flymake-error (face-at-point)))
-    (should-error (flymake-goto-next-error nil t)) ))
+    (should-error (flymake-goto-next-error nil nil t)) ))
 
 (defmacro flymake-tests--assert-set (set
                                      should
@@ -243,7 +243,7 @@ SEVERITY-PREDICATE is used to setup
         (should (eq 'flymake-warning (face-at-point))) ; dolor
         (flymake-goto-next-error)
         (should (eq 'flymake-error (face-at-point))) ; prognata
-        (should-error (flymake-goto-next-error nil t))))))
+        (should-error (flymake-goto-next-error nil nil t))))))
 
 (provide 'flymake-tests)
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]