aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Tromp2025-04-22 15:27:58 -0400
committerEli Zaretskii2025-05-03 11:51:11 +0300
commitee8b4eaca12af0ef6bf0d37780efaa558c25d45e (patch)
treefc8951b1f8fdde7e2ea2e20257fe8a4cc4ff15b7
parentd164116aa52b10bdfe8242dd1089406d4e557f32 (diff)
downloademacs-ee8b4eaca12af0ef6bf0d37780efaa558c25d45e.tar.gz
emacs-ee8b4eaca12af0ef6bf0d37780efaa558c25d45e.zip
Add `next-error' support for flymake diagnostics buffers
This adds `next-error' support for flymake diagnostics buffers. Buffers created with `flymake-show-buffer-diagnostics' and `flymake-show-project-diagnostics' are now next-error enabled, and `next-error' and `previous-error' will navigate through their listed diagnostics. * lisp/progmodes/flymake.el (flymake-current-diagnostic-line) (flymake--diagnostics-next-error): Add. (flymake-show-diagnostic, flymake-show-buffer-diagnostics) (flymake-show-project-diagnostics): Set next-error-last-buffer. (flymake--tabulated-setup): Set next-error-function. (Bug#77809) Copyright-paperwork-exempt: yes
-rw-r--r--lisp/progmodes/flymake.el29
1 files changed, 28 insertions, 1 deletions
diff --git a/lisp/progmodes/flymake.el b/lisp/progmodes/flymake.el
index cfabfef78a0..2d30ec3f5bd 100644
--- a/lisp/progmodes/flymake.el
+++ b/lisp/progmodes/flymake.el
@@ -1433,6 +1433,9 @@ Interactively, with a prefix arg, FORCE is t."
1433 map) 1433 map)
1434 "Keymap for `flymake-mode'") 1434 "Keymap for `flymake-mode'")
1435 1435
1436(defvar-local flymake-current-diagnostic-line 0
1437 "The line of the most recently focused diagnostic in a diagnostics buffer.")
1438
1436;;;###autoload 1439;;;###autoload
1437(define-minor-mode flymake-mode 1440(define-minor-mode flymake-mode
1438 "Toggle Flymake mode on or off. 1441 "Toggle Flymake mode on or off.
@@ -1893,7 +1896,8 @@ TYPE is usually keyword `:error', `:warning' or `:note'."
1893(defun flymake-show-diagnostic (pos &optional other-window) 1896(defun flymake-show-diagnostic (pos &optional other-window)
1894 "From Flymake diagnostics buffer, show source of diagnostic at POS." 1897 "From Flymake diagnostics buffer, show source of diagnostic at POS."
1895 (interactive (list (point) t)) 1898 (interactive (list (point) t))
1896 (let* ((id (or (tabulated-list-get-id pos) 1899 (let* ((diagnostics-buffer (current-buffer))
1900 (id (or (tabulated-list-get-id pos)
1897 (user-error "Nothing at point"))) 1901 (user-error "Nothing at point")))
1898 (diag (plist-get id :diagnostic)) 1902 (diag (plist-get id :diagnostic))
1899 (locus (flymake--diag-locus diag)) 1903 (locus (flymake--diag-locus diag))
@@ -1903,6 +1907,7 @@ TYPE is usually keyword `:error', `:warning' or `:note'."
1903 (goto-char b) 1907 (goto-char b)
1904 (pulse-momentary-highlight-region 1908 (pulse-momentary-highlight-region
1905 b (or e (line-end-position)))))) 1909 b (or e (line-end-position))))))
1910 (setq flymake-current-diagnostic-line (line-number-at-pos pos))
1906 (with-current-buffer (cond ((bufferp locus) locus) 1911 (with-current-buffer (cond ((bufferp locus) locus)
1907 (t (find-file-noselect locus))) 1912 (t (find-file-noselect locus)))
1908 (with-selected-window 1913 (with-selected-window
@@ -1918,6 +1923,8 @@ TYPE is usually keyword `:error', `:warning' or `:note'."
1918 (car beg) 1923 (car beg)
1919 (cdr beg)))) 1924 (cdr beg))))
1920 (funcall visit bbeg bend))))) 1925 (funcall visit bbeg bend)))))
1926 ;; Emacs < 27
1927 (setq next-error-last-buffer diagnostics-buffer)
1921 (current-buffer)))) 1928 (current-buffer))))
1922 1929
1923(defun flymake-goto-diagnostic (pos) 1930(defun flymake-goto-diagnostic (pos)
@@ -2031,6 +2038,7 @@ resizing columns and ommiting redudant columns."
2031(defun flymake--tabulated-setup (use-project) 2038(defun flymake--tabulated-setup (use-project)
2032 "Helper for `flymake-diagnostics-buffer-mode'. 2039 "Helper for `flymake-diagnostics-buffer-mode'.
2033And also `flymake-project-diagnostics-mode'." 2040And also `flymake-project-diagnostics-mode'."
2041 (setq-local next-error-function #'flymake--diagnostics-next-error)
2034 (let ((saved-r-b-f revert-buffer-function) 2042 (let ((saved-r-b-f revert-buffer-function)
2035 (refresh 2043 (refresh
2036 (lambda () 2044 (lambda ()
@@ -2060,6 +2068,23 @@ And also `flymake-project-diagnostics-mode'."
2060 (funcall refresh) 2068 (funcall refresh)
2061 (apply saved-r-b-f args))))) 2069 (apply saved-r-b-f args)))))
2062 2070
2071(defun flymake--diagnostics-next-error (n &optional reset)
2072 "`next-error-function' for flymake diagnostics buffers.
2073N is an integer representing how many errors to move.
2074If RESET is non-nil, return to the beginning of the errors before
2075moving."
2076 (let ((line (if reset 1 flymake-current-diagnostic-line))
2077 (total-lines (count-lines (point-min) (point-max))))
2078 (goto-char (point-min))
2079 (unless (zerop total-lines)
2080 (let ((target-line (+ line n)))
2081 (setq target-line (max 1 target-line))
2082 (setq target-line (min target-line total-lines))
2083 (forward-line (1- target-line))))
2084 (when-let* ((win (get-buffer-window nil t)))
2085 (set-window-point win (point)))
2086 (flymake-goto-diagnostic (point))))
2087
2063(define-derived-mode flymake-diagnostics-buffer-mode tabulated-list-mode 2088(define-derived-mode flymake-diagnostics-buffer-mode tabulated-list-mode
2064 "Flymake diagnostics" 2089 "Flymake diagnostics"
2065 "A mode for listing Flymake diagnostics." 2090 "A mode for listing Flymake diagnostics."
@@ -2116,6 +2141,7 @@ This function doesn't move point"
2116 window) 2141 window)
2117 (with-current-buffer target 2142 (with-current-buffer target
2118 (setq flymake--diagnostics-buffer-source source) 2143 (setq flymake--diagnostics-buffer-source source)
2144 (setq next-error-last-buffer (current-buffer))
2119 (revert-buffer) 2145 (revert-buffer)
2120 (setq window 2146 (setq window
2121 (display-buffer (current-buffer) 2147 (display-buffer (current-buffer)
@@ -2222,6 +2248,7 @@ some of this variable's contents the diagnostic listings.")
2222 (with-current-buffer buffer 2248 (with-current-buffer buffer
2223 (flymake-project-diagnostics-mode) 2249 (flymake-project-diagnostics-mode)
2224 (setq-local flymake--project-diagnostic-list-project prj) 2250 (setq-local flymake--project-diagnostic-list-project prj)
2251 (setq next-error-last-buffer (current-buffer))
2225 (revert-buffer) 2252 (revert-buffer)
2226 (display-buffer (current-buffer) 2253 (display-buffer (current-buffer)
2227 `((display-buffer-reuse-window 2254 `((display-buffer-reuse-window