From: Eshel Yaron Date: Tue, 11 Jun 2024 09:36:54 +0000 (+0200) Subject: Minor improvements for Flymake diagnostics list X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=d88288b4634834e7c5461c5f6584fd856365d4c2;p=emacs.git Minor improvements for Flymake diagnostics list --- diff --git a/lisp/progmodes/flymake.el b/lisp/progmodes/flymake.el index 2ca29dd930c..9277e597d58 100644 --- a/lisp/progmodes/flymake.el +++ b/lisp/progmodes/flymake.el @@ -1859,49 +1859,44 @@ TYPE is usually keyword `:error', `:warning' or `:note'." (defvar-local flymake--diagnostics-buffer-source nil) -(defvar flymake-diagnostics-buffer-mode-map - (let ((map (make-sparse-keymap))) - (define-key map (kbd "RET") 'flymake-goto-diagnostic) - (define-key map (kbd "SPC") 'flymake-show-diagnostic) - map)) +(defvar-keymap flymake-diagnostics-buffer-mode-map + :doc "Keymap for Flyamke diagnostics list buffers." + "RET" #'flymake-diagnostics-buffer-goto-diagnostic + "SPC" #'flymake-diagnostics-buffer-show-diagnostic) + +(defun flymake-diagnostics-buffer-show-diagnostic (pos &optional action) + "Show location of diagnostic at POS. -(defun flymake-show-diagnostic (pos &optional other-window) - "Show location of diagnostic at POS." - (interactive (list (point) t)) +Optional argument ACTION is passed to `display-buffer', which see." + (interactive "d") (let* ((id (or (tabulated-list-get-id pos) - (user-error "Nothing at point"))) + (user-error "No diagnostic at this position"))) (diag (plist-get id :diagnostic)) (locus (flymake--diag-locus diag)) - (beg (flymake--diag-beg diag)) - (end (flymake--diag-end diag)) - (visit (lambda (b e) - (goto-char b) - (pulse-momentary-highlight-region (point) - (or e (line-end-position)) - 'highlight)))) + (beg (flymake--diag-beg diag))) (with-current-buffer (cond ((bufferp locus) locus) (t (find-file-noselect locus))) - (with-selected-window - (display-buffer (current-buffer) other-window) + (with-selected-window (display-buffer (current-buffer) action) (cond (;; an annotated diagnostic (most common case), or a ;; non-annotated buffer diag (number-or-marker-p beg) - (funcall visit beg end)) + (goto-char beg)) (;; a non-annotated file diag (TODO: could use `end' ;; here, too) - (pcase-let ((`(,bbeg . ,bend) + (pcase-let ((`(,bbeg . ,_) (flymake-diag-region (current-buffer) (car beg) (cdr beg)))) - (funcall visit bbeg bend))))) + (goto-char bbeg))))) (current-buffer)))) -(defun flymake-goto-diagnostic (pos) +(defun flymake-diagnostics-buffer-goto-diagnostic (pos) "Show location of diagnostic at POS. POS can be a buffer position or a button" (interactive "d") (pop-to-buffer - (flymake-show-diagnostic (if (button-type pos) (button-start pos) pos)))) + (flymake-diagnostics-buffer-show-diagnostic + (if (button-type pos) (button-start pos) pos)))) (defun flymake--tabulated-entries-1 (diags project-root) "Helper for `flymake--diagnostics-buffer-entries'. @@ -1952,8 +1947,8 @@ filename of the diagnostic relative to that directory." mouse-face highlight help-echo "mouse-2: visit this diagnostic" face nil - action flymake-goto-diagnostic - mouse-action flymake-goto-diagnostic)] + action flymake-diagnostics-buffer-goto-diagnostic + mouse-action flymake-diagnostics-buffer-goto-diagnostic)] when (and line col) collect (list (list :diagnostic diag :line line @@ -1965,8 +1960,8 @@ filename of the diagnostic relative to that directory." help-echo ,(file-relative-name file project-root) face nil mouse-face highlight - action flymake-goto-diagnostic - mouse-action flymake-goto-diagnostic )] + action flymake-diagnostics-buffer-goto-diagnostic + mouse-action flymake-diagnostics-buffer-goto-diagnostic )] data-vec) data-vec)))) @@ -2059,7 +2054,7 @@ some of this variable's contents the diagnostic listings.") (defvar-local flymake--project-diagnostic-list-project nil) -(define-derived-mode flymake-project-diagnostics-mode tabulated-list-mode +(define-derived-mode flymake-project-diagnostics-mode flymake-diagnostics-buffer-mode "Flymake diagnostics" "A mode for listing Flymake diagnostics." :interactive nil @@ -2150,5 +2145,4 @@ some of this variable's contents the diagnostic listings.") (revert-buffer))))) (provide 'flymake) - ;;; flymake.el ends here