Add 'xref-mouse-mode' minor mode

* doc/emacs/maintaining.texi (Looking Up Identifiers): Document
it.
* etc/NEWS (bindings): Mention it.
* etc/themes/newcomers-presets-theme.el (newcomers-presets): Add
it.
* lisp/progmodes/xref.el (xref-mouse-mode-map, xref-mouse-mode)
(global-xref-mouse-mode): Implement it.
This commit is contained in:
Philip Kaludercic 2026-03-11 19:39:30 +01:00
parent dad9864340
commit d019b5ec71
No known key found for this signature in database
4 changed files with 40 additions and 3 deletions

View file

@ -2675,10 +2675,11 @@ new frame for it. The former is @w{@kbd{C-x 4 .}}
(@code{xref-find-definitions-other-window}), and the latter is
@w{@kbd{C-x 5 .}} (@code{xref-find-definitions-other-frame}).
@findex xref-mouse-mode
The command @code{xref-find-definitions-at-mouse} works like
@code{xref-find-definitions}, but it looks for the identifier name at
or around the place of a mouse event. This command is intended to be
bound to a mouse event, such as @kbd{C-M-mouse-1}, for example.
@code{xref-find-definitions}, but it looks for the identifier name at or
around the place of a mouse event. The @code{xref-mouse-mode} minor
mode binds the command to @kbd{C-mouse-1}.
@kindex C-M-.
@findex xref-find-apropos

View file

@ -3164,6 +3164,13 @@ destination window is chosen using 'display-buffer-alist'. Example:
display-buffer-use-some-window)
(some-window . mru))))
+++
*** New minor mode 'xref-mouse-mode'.
This minor mode binds 'xref-find-definitions-at-mouse' to
'C-<down-mouse-1>', allowing you to "control click" to jump to a
definition, following the convention from other editors. The global
minor mode 'global-xref-mouse-mode' will enable this in all buffers.
** Revert
+++

View file

@ -105,6 +105,7 @@ This minor mode will enable and disable the theme on startup."
'(mouse-drag-and-drop-region t)
'(mouse-drag-and-drop-region-cross-program t)
'(mouse-drag-mode-line-buffer t)
'(global-xref-mouse-mode t)
;;;; Persistence-related options
'(savehist-mode t)

View file

@ -1731,6 +1731,34 @@ This command is intended to be bound to a mouse event."
(xref-find-references identifier))
(user-error "No identifier here"))))
(defvar-keymap xref-mouse-mode-map
;; Using "Control-Click" has been popularized TextMate and it's
;; descendants (Sublime, Atom, VSCode) and even other traditions such
;; as Eclipse or the IntelliJ editor suite.
;;
;; TODO: Add some kind of hovering indication that a identifier under
;; the mouse cursor has a definition we could jump to.
"C-<down-mouse-1>" #'xref-find-definitions-at-mouse
"C-<mouse-1>" #'xref-find-definitions-at-mouse
"C-<drag-mouse-1>" #'xref-find-definitions-at-mouse)
;;;###autoload
(define-minor-mode xref-mouse-mode
"Minor mode to bind Xref commands invoked using the mouse.
See `global-xref-mouse-mode' if you want to enable this minor mode in
all buffers."
:version "31.1")
;;;###autoload
(define-globalized-minor-mode global-xref-mouse-mode
xref-mouse-mode xref-mouse-mode
:version "31.1")
;; ;;;##autoload
;; (add-to-list
;; 'emulation-mode-map-alists ;since we are "emulating" other conventions
;; `((xref-mouse-mode . ,xref-mouse-mode-map)))
(declare-function apropos-parse-pattern "apropos" (pattern &optional do-all))
;;;###autoload