]> git.eshelyaron.com Git - emacs.git/commitdiff
Implement context-menu-mode support for hi-lock
authorPhilip Kaludercic <philipk@posteo.net>
Fri, 31 Dec 2021 11:45:52 +0000 (12:45 +0100)
committerLars Ingebrigtsen <larsi@gnus.org>
Fri, 14 Jan 2022 08:46:59 +0000 (09:46 +0100)
* hi-lock.el (hi-lock-symbol-at-mouse): Add new command
(hi-lock-context-menu): Add new function

lisp/hi-lock.el

index fbd698e234a7a9e672080b09095c088c801cdcfc..d7d98c78f86b9deed2728078ab7b6f3101e7c345 100644 (file)
@@ -854,6 +854,25 @@ SPACES-REGEXP is a regexp to substitute spaces in font-lock search."
   ;; continue standard unloading
   nil)
 
+;;; Mouse support
+(defun hi-lock-symbol-at-mouse (event)
+  "Highlight symbol at mouse click EVENT."
+  (interactive "e")
+  (save-excursion
+    (mouse-set-point event)
+    (highlight-symbol-at-point)))
+
+(defun hi-lock-context-menu (menu click)
+  "Populate MENU with a menu item to highlight symbol at CLICK."
+  (save-excursion
+    (mouse-set-point click)
+    (when (symbol-at-point)
+      (define-key-after menu [highlight-search-separator] menu-bar-separator)
+      (define-key-after menu [highlight-search-mouse]
+        '(menu-item "Highlight Symbol" highlight-symbol-at-mouse
+                    :help "Highlight symbol at point"))))
+  menu)
+
 (provide 'hi-lock)
 
 ;;; hi-lock.el ends here