diff options
author | Philip Kaludercic <philipk@posteo.net> | 2021-09-15 10:13:53 +0300 |
---|---|---|
committer | Juri Linkov <juri@linkov.net> | 2021-09-15 10:13:53 +0300 |
commit | 3eb80b78473b425cdbc251e48aec7cfd9afea2cc (patch) | |
tree | fa96b67ec06c3c4986f4695b6481dc79c6473c85 /lisp | |
parent | 67ab890cde6c4c87ddf2913f4d476ea2e2f6b19e (diff) | |
download | emacs-3eb80b78473b425cdbc251e48aec7cfd9afea2cc.tar.gz emacs-3eb80b78473b425cdbc251e48aec7cfd9afea2cc.tar.bz2 emacs-3eb80b78473b425cdbc251e48aec7cfd9afea2cc.zip |
Add occur-related context-menu operations (bug#50552)
* replace.el (occur-word-at-mouse): Add new command.
(occur-symbol-at-mouse): Add new command.
(occur-context-menu): Add new function.
Diffstat (limited to 'lisp')
-rw-r--r-- | lisp/replace.el | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/lisp/replace.el b/lisp/replace.el index 69bdfe1331d..63b3e213ce8 100644 --- a/lisp/replace.el +++ b/lisp/replace.el @@ -2367,6 +2367,33 @@ See also `multi-occur'." ;; And the second element is the list of context after-lines. (if (> nlines 0) after-lines)))) +(defun occur-word-at-mouse (event) + "Display an occur buffer for the word at EVENT." + (interactive "e") + (let ((word (thing-at-mouse event 'word t))) + (occur (concat "\\<" (regexp-quote word) "\\>")))) + +(defun occur-symbol-at-mouse (event) + "Display an occur buffer for the symbol at EVENT." + (interactive "e") + (let ((symbol (thing-at-mouse event 'symbol t))) + (occur (concat "\\_<" (regexp-quote symbol) "\\_>")))) + +(defun occur-context-menu (menu click) + "Populate MENU with occur commands for CLICK. +To be added to `context-menu-functions'." + (let ((word (thing-at-mouse click 'word)) + (sym (thing-at-mouse click 'symbol))) + (when (or word sym) + (define-key-after menu [occur-separator] menu-bar-separator) + (when word + (define-key-after menu [occur-word-at-mouse] + '(menu-item "Occur Word" occur-word-at-mouse))) + (when sym + (define-key-after menu [occur-symbol-at-mouse] + '(menu-item "Occur Symbol" occur-symbol-at-mouse))))) + menu) + ;; It would be nice to use \\[...], but there is no reasonable way ;; to make that display both SPC and Y. |