]> git.eshelyaron.com Git - emacs.git/commitdiff
Add `next-error' support for flymake diagnostics buffers
authorMatthew Tromp <matthewktromp@gmail.com>
Tue, 22 Apr 2025 19:27:58 +0000 (15:27 -0400)
committerEshel Yaron <me@eshelyaron.com>
Sat, 10 May 2025 08:47:26 +0000 (10:47 +0200)
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
(cherry picked from commit ee8b4eaca12af0ef6bf0d37780efaa558c25d45e)

lisp/progmodes/flymake.el

index 116d2964880daf179be9b31640ceac9bf34a13c8..8968df8c5fd54d4688b38c2c34c949477785aa6a 100644 (file)
@@ -1492,6 +1492,8 @@ Interactively, with a prefix arg, FORCE is t."
     map)
   "Keymap for `flymake-mode'.")
 
+(defvar-local flymake-current-diagnostic-pos nil)
+
 ;;;###autoload
 (define-minor-mode flymake-mode
   "Toggle Flymake mode on or off.
@@ -1970,13 +1972,26 @@ buffer."
     ("Origin" 8 t)
     ("Message" 0 t)])
 
+(defun flymake--diagnostics-next-error (n &optional reset)
+  "`next-error-function' for flymake diagnostics buffers.
+N is an integer representing how many errors to move.
+If RESET is non-nil, return to the beginning of the errors before
+moving."
+  (flymake-diagnostics-buffer-goto-diagnostic
+   (save-excursion
+     (goto-char (if (or reset (not flymake-current-diagnostic-pos))
+                    (point-min)
+                  flymake-current-diagnostic-pos))
+     (forward-line n)
+     (setq flymake-current-diagnostic-pos (point)))))
+
 (define-derived-mode flymake-diagnostics-buffer-mode tabulated-list-mode
   "Flymake diagnostics"
   "A mode for listing Flymake diagnostics."
   :interactive nil
-  (setq tabulated-list-format flymake--diagnostics-base-tabulated-list-format)
-  (setq tabulated-list-entries
-        'flymake--diagnostics-buffer-entries)
+  (setq tabulated-list-format flymake--diagnostics-base-tabulated-list-format
+        tabulated-list-entries 'flymake--diagnostics-buffer-entries)
+  (setq-local next-error-function #'flymake--diagnostics-next-error)
   (tabulated-list-init-header))
 
 (defun flymake--diagnostics-buffer-name (&optional buffer)
@@ -2061,8 +2076,8 @@ some of this variable's contents the diagnostic listings.")
   (setq tabulated-list-format
         (vconcat [("File" 25 t)]
                  flymake--diagnostics-base-tabulated-list-format))
-  (setq tabulated-list-entries
-        'flymake--project-diagnostics-entries)
+  (setq tabulated-list-entries 'flymake--project-diagnostics-entries)
+  (setq-local next-error-function #'flymake--diagnostics-next-error)
   (tabulated-list-init-header))
 
 (cl-defun flymake--project-diagnostics (&optional (project (project-current)))