aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoão Távora2017-09-27 12:42:20 +0100
committerJoão Távora2017-10-03 14:18:54 +0100
commit73601787b45d08cdd5026ea36ff680bd49076950 (patch)
treecc6161f0f10f6ec97e8b43d582b1c73395617935
parent5ec7d738655db209ef7375e340d3d2b0ae5fc3da (diff)
downloademacs-73601787b45d08cdd5026ea36ff680bd49076950.tar.gz
emacs-73601787b45d08cdd5026ea36ff680bd49076950.zip
Tweak Flymake commands flymake-goto-[next/prev]-error
Add filters, useful for backends like the upcoming flymake-elisp-checkdoc backend, for example, which litters everything with low-priority notes. Also re-implement wraparound for flymake-goto-next-error. Manual mentions this, so it's probably a good idea to keep it. Added a new customization variable flymake-wrap-around to control it. * lisp/progmodes/flymake.el (flymake-goto-prev-error) (flymake-goto-next-error): Accept FILTER argument. (flymake-wrap-around): New variable. (flymake-goto-next-error): Wrap around according to flymake-wrap-around. * test/lisp/progmodes/flymake-tests.el (different-diagnostic-types, dummy-backends): Pass FILTER to flymake-goto-prev-error. (different-diagnostic-types) (dummy-backends): Use flymake-wrap-around.
-rw-r--r--lisp/progmodes/flymake.el74
-rw-r--r--test/lisp/progmodes/flymake-tests.el6
2 files changed, 62 insertions, 18 deletions
diff --git a/lisp/progmodes/flymake.el b/lisp/progmodes/flymake.el
index 242c83cf86e..f136e14ec19 100644
--- a/lisp/progmodes/flymake.el
+++ b/lisp/progmodes/flymake.el
@@ -112,6 +112,10 @@ See `flymake-error-bitmap' and `flymake-warning-bitmap'."
112 "it is superseded by `warning-minimum-log-level.'" 112 "it is superseded by `warning-minimum-log-level.'"
113 "26.1") 113 "26.1")
114 114
115(defcustom flymake-wrap-around t
116 "If non-nil, moving to errors wraps around buffer boundaries."
117 :group 'flymake :type 'boolean)
118
115(defvar-local flymake-timer nil 119(defvar-local flymake-timer nil
116 "Timer for starting syntax check.") 120 "Timer for starting syntax check.")
117 121
@@ -687,20 +691,44 @@ non-nil."
687 (flymake-mode) 691 (flymake-mode)
688 (flymake-log :warning "Turned on in `flymake-find-file-hook'"))) 692 (flymake-log :warning "Turned on in `flymake-find-file-hook'")))
689 693
690(defun flymake-goto-next-error (&optional n interactive) 694(defun flymake-goto-next-error (&optional n filter interactive)
691 "Go to next, or Nth next, flymake error in buffer." 695 "Go to Nth next flymake error in buffer matching FILTER.
692 (interactive (list 1 t)) 696FILTER is a list of diagnostic types found in
697`flymake-diagnostic-types-alist', or nil, if no filter is to be
698applied.
699
700Interactively, always goes to the next error. Also
701interactively, FILTER is determined by the prefix arg. With no
702prefix arg, don't use a filter, otherwise only consider
703diagnostics of type `:error' and `:warning'."
704 (interactive (list 1
705 (if current-prefix-arg
706 '(:error :warning))
707 t))
693 (let* ((n (or n 1)) 708 (let* ((n (or n 1))
694 (ovs (flymake--overlays :filter 'flymake--diagnostic 709 (ovs (flymake--overlays :filter
710 (lambda (ov)
711 (let ((diag (overlay-get
712 ov
713 'flymake--diagnostic)))
714 (and diag
715 (or (not filter)
716 (memq (flymake--diag-type diag)
717 filter)))))
695 :compare (if (cl-plusp n) #'< #'>) 718 :compare (if (cl-plusp n) #'< #'>)
696 :key #'overlay-start)) 719 :key #'overlay-start))
697 (chain (cl-member-if (lambda (ov) 720 (tail (cl-member-if (lambda (ov)
698 (if (cl-plusp n) 721 (if (cl-plusp n)
699 (> (overlay-start ov) 722 (> (overlay-start ov)
700 (point)) 723 (point))
701 (< (overlay-start ov) 724 (< (overlay-start ov)
702 (point)))) 725 (point))))
703 ovs)) 726 ovs))
727 (chain (if flymake-wrap-around
728 (if tail
729 (progn (setcdr (last tail) ovs) tail)
730 (and ovs (setcdr (last ovs) ovs)))
731 tail))
704 (target (nth (1- n) chain))) 732 (target (nth (1- n) chain)))
705 (cond (target 733 (cond (target
706 (goto-char (overlay-start target)) 734 (goto-char (overlay-start target))
@@ -709,12 +737,26 @@ non-nil."
709 (funcall (overlay-get target 'help-echo) 737 (funcall (overlay-get target 'help-echo)
710 nil nil (point))))) 738 nil nil (point)))))
711 (interactive 739 (interactive
712 (user-error "No more flymake errors"))))) 740 (user-error "No more flymake errors%s"
741 (if filter
742 (format " of types %s" filter)
743 ""))))))
744
745(defun flymake-goto-prev-error (&optional n filter interactive)
746 "Go to Nth previous flymake error in buffer matching FILTER.
747FILTER is a list of diagnostic types found in
748`flymake-diagnostic-types-alist', or nil, if no filter is to be
749applied.
750
751Interactively, always goes to the previous error. Also
752interactively, FILTER is determined by the prefix arg. With no
753prefix arg, don't use a filter, otherwise only consider
754diagnostics of type `:error' and `:warning'."
755 (interactive (list 1 (if current-prefix-arg
756 '(:error :warning))
757 t))
758 (flymake-goto-next-error (- (or n 1)) filter interactive))
713 759
714(defun flymake-goto-prev-error (&optional n interactive)
715 "Go to previous, or Nth previous, flymake error in buffer."
716 (interactive (list 1 t))
717 (flymake-goto-next-error (- (or n 1)) interactive))
718 760
719(provide 'flymake) 761(provide 'flymake)
720 762
diff --git a/test/lisp/progmodes/flymake-tests.el b/test/lisp/progmodes/flymake-tests.el
index 921c2f648a4..fa77a9a8ae6 100644
--- a/test/lisp/progmodes/flymake-tests.el
+++ b/test/lisp/progmodes/flymake-tests.el
@@ -129,7 +129,8 @@ SEVERITY-PREDICATE is used to setup
129 (should (eq 'flymake-warning (face-at-point))) 129 (should (eq 'flymake-warning (face-at-point)))
130 (flymake-goto-next-error) 130 (flymake-goto-next-error)
131 (should (eq 'flymake-error (face-at-point))) 131 (should (eq 'flymake-error (face-at-point)))
132 (should-error (flymake-goto-next-error nil t)) )) 132 (let ((flymake-wrap-around nil))
133 (should-error (flymake-goto-next-error nil nil t))) ))
133 134
134(defmacro flymake-tests--assert-set (set 135(defmacro flymake-tests--assert-set (set
135 should 136 should
@@ -244,7 +245,8 @@ SEVERITY-PREDICATE is used to setup
244 (should (eq 'flymake-warning (face-at-point))) ; dolor 245 (should (eq 'flymake-warning (face-at-point))) ; dolor
245 (flymake-goto-next-error) 246 (flymake-goto-next-error)
246 (should (eq 'flymake-error (face-at-point))) ; prognata 247 (should (eq 'flymake-error (face-at-point))) ; prognata
247 (should-error (flymake-goto-next-error nil t)))))) 248 (let ((flymake-wrap-around nil))
249 (should-error (flymake-goto-next-error nil nil t)))))))
248 250
249(provide 'flymake-tests) 251(provide 'flymake-tests)
250 252