From df44b2d956d1a658c51c558857cdc6d0b2e30572 Mon Sep 17 00:00:00 2001 From: Philip Kaludercic Date: Fri, 31 Dec 2021 12:37:50 +0100 Subject: [PATCH] Implement context-menu-mode support for man pages * man.el (Man-at-mouse): Add new command (Man-context-menu): Add new function --- lisp/man.el | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/lisp/man.el b/lisp/man.el index adf244a11ad..d94cbf20153 100644 --- a/lisp/man.el +++ b/lisp/man.el @@ -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) + ;; Init the man package variables, if not already done. (Man-init-defvars) -- 2.39.2