[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] [UPDATE2] Fix mouse click on flymake
From: |
Ergus |
Subject: |
Re: [PATCH] [UPDATE2] Fix mouse click on flymake |
Date: |
Fri, 24 Jan 2025 17:10:57 +0100 |
Please find attached the patch with the fix + the new feature.
It includes:
1. A new defcustom equivalent to xref-after-jump-hook.
2. An optional argument to flymake-show-buffer-diagnostics.
3. Modification to flymake-menu to use a new function that also highlights
the candidate when possible.
4. A simplification of my previous patch to use the flymake api to find
diagnostics.
They look like too many, but are actually just a few lines, so I put
them together.
Best,
Ergus
On Fri, Jan 24, 2025 at 02:09:09PM +0100, Ergus wrote:
Hi Eli:
Thanks for replying.
Please, find attached the new patch.
At some point I would like to add an extra feature to highlight the
exact error message in the tabulated list somehow (or at least to go
directly to the error line in the tabulated list, or using
pulse-momentary-highlight-one-line)
But that's a different feature and tabulated-list does not seem to bring
this feature directly (at last go to the tabular line based in some key)
so, for now I prefer not to hack flymake to do it artificially.
Best,
Ergus
On Fri, Jan 24, 2025 at 09:51:03AM +0200, Eli Zaretskii wrote:
Date: Fri, 24 Jan 2025 00:25:07 +0100
From: Ergus <spacibba@aol.com>
Cc: emacs-devel@gnu.org, juri@linkov.net, sbaugh@janestreet.com
I have a patch that actually works with margins (extremely simple now
BTW).
However, I am trying to get the same with fringes, but I don't find any
documentation on how to add a 'keymap property to a fringe. Is it even
possible?
Not via 'keymap' property, not AFAIK. But if all you want is to call
a command when the user clicks on the fringe at a certain vertical
position, then it's possible by other means. For example, "M-x gdb"
supports setting breakpoints by clicking C-mouse-1 on the fringe: the
breakpoint is set on the code line that is at the same vertical
position as the click. See gdb-mouse-toggle-breakpoint-fringe in
gdb-mi.el. Thus, instead of having a 'keymap' property on the fringe
at some location, your command should examine the click coordinates
and do nothing if they don't match the place where you want the click
to do its thing.
diff --git a/lisp/progmodes/flymake.el b/lisp/progmodes/flymake.el
index 9dda53713f5..44cbc18b8b0 100644
--- a/lisp/progmodes/flymake.el
+++ b/lisp/progmodes/flymake.el
@@ -748,34 +748,41 @@ flymake--severity
(flymake--lookup-type-property type 'severity
(warning-numeric-level :error)))
-(defun flymake--indicator-overlay-spec (indicator)
+(defun flymake--indicator-overlay-spec (type)
"Return INDICATOR as propertized string to use in error indicators."
- (let* ((value (if (symbolp indicator)
+ (let* ((indicator (flymake--lookup-type-property
+ type
+ (cond ((eq flymake-indicator-type 'fringes)
+ 'flymake-bitmap)
+ ((eq flymake-indicator-type 'margins)
+ 'flymake-margin-string))
+ (alist-get 'bitmap (alist-get type ; backward compat
+
flymake-diagnostic-types-alist))))
+ (value (if (symbolp indicator)
(symbol-value indicator)
indicator))
- (indicator-car (if (listp value)
- (car value)
- value))
- (indicator-cdr (if (listp value)
- (cdr value))))
+ (valuelist (if (listp value)
+ value
+ (list value)))
+ (indicator-car (car valuelist)))
+
(cond
((and (symbolp indicator-car)
flymake-fringe-indicator-position)
(propertize "!" 'display
- (cons flymake-fringe-indicator-position
- (if (listp value)
- value
- (list value)))))
+ (cons flymake-fringe-indicator-position valuelist)))
((and (stringp indicator-car)
flymake-margin-indicator-position)
(propertize "!"
'display
`((margin ,flymake-margin-indicator-position)
- ,(propertize
- indicator-car
- 'face
- `(:inherit (,indicator-cdr
- default)))))))))
+ ,(propertize indicator-car
+ 'face `(:inherit (,(cdr valuelist) default))
+ 'mouse-face 'highlight
+ 'help-echo "Open Flymake diagnostics"
+ 'keymap `,(define-keymap
+ (format "<%s> <mouse-1>"
flymake-margin-indicator-position)
+
#'flymake-mouse-show-buffer-diagnostics))))))))
(defun flymake--resize-margins (&optional orig-width)
"Resize current window margins according to
`flymake-margin-indicator-position'.
@@ -941,16 +948,7 @@ flymake--highlight-line
(overlay-put ov prop (flymake--lookup-type-property
type prop value)))))
(default-maybe 'face 'flymake-error)
- (default-maybe 'before-string
- (flymake--indicator-overlay-spec
- (flymake--lookup-type-property
- type
- (cond ((eq flymake-indicator-type 'fringes)
- 'flymake-bitmap)
- ((eq flymake-indicator-type 'margins)
- 'flymake-margin-string))
- (alist-get 'bitmap (alist-get type ; backward compat
- flymake-diagnostic-types-alist)))))
+ (default-maybe 'before-string (flymake--indicator-overlay-spec type))
;; (default-maybe 'after-string
;; (flymake--diag-text diagnostic))
(default-maybe 'help-echo
@@ -1369,12 +1367,31 @@ flymake-start
nil)))
(flymake--import-foreign-diagnostics))))))
-(defvar flymake-mode-map
- (let ((map (make-sparse-keymap)))
- (define-key map `[,flymake-fringe-indicator-position mouse-1]
- #'flymake-show-buffer-diagnostics)
- map)
- "Keymap for `flymake-mode'.")
+(defun flymake-mouse-show-buffer-diagnostics (event)
+ "Show diagnostics buffer on mouse click in the margin or fringe.
+This uses two different approaches to work.
+For margin it is set as a char property of the margin character directly.
+While in the fringe it is set as part of the `flymake-mode-map'."
+ (interactive "e")
+ (mouse-minibuffer-check event)
+ (let* ((posn (event-end event))
+ (pos (posn-point posn)))
+ (when (numberp pos)
+ (with-selected-window (posn-window posn)
+ (with-current-buffer (window-buffer)
+ (goto-char pos)
+ (when (catch 'found
+ (dolist (overlay (overlays-in pos (1+ pos)))
+ (when (overlay-get overlay 'flymake-overlay)
+ (throw 'found t))))
+ (flymake-show-buffer-diagnostics)))))))
+
+;; Set the fringe mouse-1 action directly and perform the filtering
+;; latter iterating over the overlays.
+(defvar-keymap flymake-mode-map
+ :doc "Keymap for `flymake-mode'."
+ (format "<%s> <mouse-1>" flymake-fringe-indicator-position)
+ #'flymake-mouse-show-buffer-diagnostics)
;;;###autoload
(define-minor-mode flymake-mode
flymake-indicator-margin-click_v2.patch
Description: Text document
- Re: [PATCH] Fix mouse click on flymake, (continued)
- Re: [PATCH] Fix mouse click on flymake, Ergus, 2025/01/19
- Message not available
- Re: [PATCH] Fix mouse click on flymake, Ergus, 2025/01/20
- Re: [PATCH] Fix mouse click on flymake, Juri Linkov, 2025/01/20
- Re: [PATCH] Fix mouse click on flymake, Ergus, 2025/01/20
- Re: [PATCH] Fix mouse click on flymake, Eli Zaretskii, 2025/01/21
- Re: [PATCH] Fix mouse click on flymake, Ergus, 2025/01/21
- Re: [PATCH] Fix mouse click on flymake, Eli Zaretskii, 2025/01/23
- Re: [PATCH] Fix mouse click on flymake, Ergus, 2025/01/23
- Re: [PATCH] Fix mouse click on flymake, Eli Zaretskii, 2025/01/24
- Re: [PATCH] [UPDATE] Fix mouse click on flymake, Ergus, 2025/01/24
- Re: [PATCH] [UPDATE2] Fix mouse click on flymake,
Ergus <=
- Re: [PATCH] [UPDATE2] Fix mouse click on flymake, Juri Linkov, 2025/01/25
- Re: [PATCH] [UPDATE3] Fix mouse click on flymake, Ergus, 2025/01/25
- Re: [PATCH] Fix mouse click on flymake, Ergus, 2025/01/19