]> git.eshelyaron.com Git - emacs.git/commitdiff
Minor improvements for Flymake diagnostics list
authorEshel Yaron <me@eshelyaron.com>
Tue, 11 Jun 2024 09:36:54 +0000 (11:36 +0200)
committerEshel Yaron <me@eshelyaron.com>
Tue, 11 Jun 2024 09:36:54 +0000 (11:36 +0200)
lisp/progmodes/flymake.el

index 2ca29dd930ca313adbe1a6797c53cfacadc0197f..9277e597d5846db284cab79c60967b5f1e15213a 100644 (file)
@@ -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