From cad330f31eb7f7b127a970296f323524d31e7fee Mon Sep 17 00:00:00 2001 From: Philip Kaludercic Date: Sat, 11 Sep 2021 22:41:32 +0200 Subject: [PATCH] Add occur menu for context-mode-menu * lisp/mouse.el (context-menu-functions): Register context-menu-occur (context-menu-occur): Add backend function * lisp/replace.el (occur-word-at-mouse): Add command (occur-symbol-at-mouse): Add command --- lisp/mouse.el | 17 +++++++++++++++++ lisp/replace.el | 14 ++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/lisp/mouse.el b/lisp/mouse.el index 7d3ed9a0e4..3590e27e3e 100644 --- a/lisp/mouse.el +++ b/lisp/mouse.el @@ -296,6 +296,7 @@ context-menu-functions (function-item context-menu-buffers) (function-item context-menu-vc) (function-item context-menu-ffap) + (function-item context-menu-occur) (function :tag "Custom function"))) :version "28.1") @@ -465,6 +466,22 @@ context-menu-ffap :help "Find file or URL guessed from text around mouse click")))) menu) +(defun context-menu-occur (menu) + "Occur at point menu." + (save-excursion + (mouse-set-point last-input-event) + (let ((word (thing-at-point 'word)) + (sym (thing-at-point '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) + (defvar context-menu-entry `(menu-item ,(purecopy "Context Menu") ignore :filter (lambda (_) (context-menu-map)))) diff --git a/lisp/replace.el b/lisp/replace.el index 69bdfe1331..f234a933bd 100644 --- a/lisp/replace.el +++ b/lisp/replace.el @@ -2367,6 +2367,20 @@ occur-context-lines ;; 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") + (save-excursion + (mouse-set-point event) + (occur (regexp-quote (thing-at-point 'word))))) + +(defun occur-symbol-at-mouse (event) + "Display an occur buffer for the symbol at EVENT." + (interactive "e") + (save-excursion + (mouse-set-point event) + (occur (regexp-quote (thing-at-point 'symbol))))) + ;; It would be nice to use \\[...], but there is no reasonable way ;; to make that display both SPC and Y. -- 2.30.2