aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/replace.el
diff options
context:
space:
mode:
authorPhilip Kaludercic2021-09-15 10:13:53 +0300
committerJuri Linkov2021-09-15 10:13:53 +0300
commit3eb80b78473b425cdbc251e48aec7cfd9afea2cc (patch)
treefa96b67ec06c3c4986f4695b6481dc79c6473c85 /lisp/replace.el
parent67ab890cde6c4c87ddf2913f4d476ea2e2f6b19e (diff)
downloademacs-3eb80b78473b425cdbc251e48aec7cfd9afea2cc.tar.gz
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/replace.el')
-rw-r--r--lisp/replace.el27
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'."
2367 ;; And the second element is the list of context after-lines. 2367 ;; And the second element is the list of context after-lines.
2368 (if (> nlines 0) after-lines)))) 2368 (if (> nlines 0) after-lines))))
2369 2369
2370(defun occur-word-at-mouse (event)
2371 "Display an occur buffer for the word at EVENT."
2372 (interactive "e")
2373 (let ((word (thing-at-mouse event 'word t)))
2374 (occur (concat "\\<" (regexp-quote word) "\\>"))))
2375
2376(defun occur-symbol-at-mouse (event)
2377 "Display an occur buffer for the symbol at EVENT."
2378 (interactive "e")
2379 (let ((symbol (thing-at-mouse event 'symbol t)))
2380 (occur (concat "\\_<" (regexp-quote symbol) "\\_>"))))
2381
2382(defun occur-context-menu (menu click)
2383 "Populate MENU with occur commands for CLICK.
2384To be added to `context-menu-functions'."
2385 (let ((word (thing-at-mouse click 'word))
2386 (sym (thing-at-mouse click 'symbol)))
2387 (when (or word sym)
2388 (define-key-after menu [occur-separator] menu-bar-separator)
2389 (when word
2390 (define-key-after menu [occur-word-at-mouse]
2391 '(menu-item "Occur Word" occur-word-at-mouse)))
2392 (when sym
2393 (define-key-after menu [occur-symbol-at-mouse]
2394 '(menu-item "Occur Symbol" occur-symbol-at-mouse)))))
2395 menu)
2396
2370 2397
2371;; It would be nice to use \\[...], but there is no reasonable way 2398;; It would be nice to use \\[...], but there is no reasonable way
2372;; to make that display both SPC and Y. 2399;; to make that display both SPC and Y.