From 3cc77e0ba1d2c6e016196e1586eaf36c0951cfa1 Mon Sep 17 00:00:00 2001 From: Matthew Tromp Date: Tue, 22 Apr 2025 15:27:58 -0400 Subject: [PATCH] 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 (cherry picked from commit ee8b4eaca12af0ef6bf0d37780efaa558c25d45e) --- lisp/progmodes/flymake.el | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/lisp/progmodes/flymake.el b/lisp/progmodes/flymake.el index 116d2964880..8968df8c5fd 100644 --- a/lisp/progmodes/flymake.el +++ b/lisp/progmodes/flymake.el @@ -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))) -- 2.39.5