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

lisp/man.el

index adf244a11ad17629e0b9a5eb715fe802b519c25e..d94cbf201532d179ded0c60cc2985a09df0b3bfd 100644 (file)
@@ -1976,6 +1976,29 @@ Uses `Man-name-local-regexp'."
     (bookmark-default-handler
      `("" (buffer . ,buf) . ,(bookmark-get-bookmark-record bookmark)))))
 
+;;; Mouse support
+(defun Man-at-mouse (e)
+  "Open man manual at point."
+  (interactive "e")
+  (save-excursion
+    (mouse-set-point e)
+    (man (Man-default-man-entry))))
+
+(defun Man-context-menu (menu click)
+  "Populate MENU with commands that open a man page at point."
+  (save-excursion
+    (mouse-set-point click)
+    (when (save-excursion
+            (skip-syntax-backward "^ ")
+            (and (looking-at
+                  "[[:space:]]*\\([[:alnum:]_-]+([[:alnum:]]+)\\)")
+                  (match-string 1)))
+      (define-key-after menu [man-separator] menu-bar-separator)
+      (define-key-after menu [man-at-mouse]
+    '(menu-item "Open man page" man-at-mouse
+            :help "Open man page around mouse click"))))
+  menu)
+
 \f
 ;; Init the man package variables, if not already done.
 (Man-init-defvars)