From: Juri Linkov Date: Tue, 27 Jul 2021 20:48:07 +0000 (+0300) Subject: Add new context-menu options for menus "File At Point" and "Version Control". X-Git-Tag: emacs-28.0.90~1470^2~4 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=2c2baa9d1231ad9e642e3a80fb1c641fdde71b33;p=emacs.git Add new context-menu options for menus "File At Point" and "Version Control". * lisp/mouse.el (context-menu-functions): Add more options. (context-menu-global, context-menu-local): Fix separators. (context-menu-minor): Rewrite to support list of submenus. (context-menu-vc, context-menu-ffap): New functions. (context-menu-undo, context-menu-region): Fix separators. * lisp/dired.el (dired-context-menu): * lisp/info.el (Info-context-menu): * lisp/net/goto-addr.el (goto-address-context-menu): * lisp/net/eww.el (eww-context-menu): * lisp/progmodes/prog-mode.el (prog-context-menu): Fix separators. --- diff --git a/lisp/dired.el b/lisp/dired.el index e16df189a76..4e82d57e216 100644 --- a/lisp/dired.el +++ b/lisp/dired.el @@ -2196,7 +2196,7 @@ Do so according to the former subdir alist OLD-SUBDIR-ALIST." (defun dired-context-menu (menu) (when (mouse-posn-property (event-start last-input-event) 'dired-filename) - (define-key menu [dired-separator-2] menu-bar-separator) + (define-key menu [dired-separator] menu-bar-separator) (let ((easy-menu (make-sparse-keymap "Immediate"))) (easy-menu-define nil easy-menu nil '("Immediate" @@ -2206,8 +2206,7 @@ Do so according to the former subdir alist OLD-SUBDIR-ALIST." :help "Edit file at mouse click in other window"])) (dolist (item (reverse (lookup-key easy-menu [menu-bar immediate]))) (when (consp item) - (define-key menu (vector (car item)) (cdr item))))) - (define-key menu [dired-separator-1] menu-bar-separator)) + (define-key menu (vector (car item)) (cdr item)))))) menu) diff --git a/lisp/info.el b/lisp/info.el index 14dc299295f..0b3a9e4bf5d 100644 --- a/lisp/info.el +++ b/lisp/info.el @@ -4147,7 +4147,7 @@ If FORK is non-nil, it is passed to `Info-goto-node'." ["Exit" quit-window :help "Stop reading Info"])) (defun Info-context-menu (menu) - (define-key menu [Info-separator-2] menu-bar-separator) + (define-key menu [Info-separator] menu-bar-separator) (let ((easy-menu (make-sparse-keymap "Info"))) (easy-menu-define nil easy-menu nil '("Info" @@ -4163,7 +4163,6 @@ If FORK is non-nil, it is passed to `Info-goto-node'." (define-key menu [Info-mouse-follow-nearest-node] '(menu-item "Follow Link" Info-mouse-follow-nearest-node :help "Follow a link where you click"))) - (define-key menu [Info-separator-1] menu-bar-separator) menu) diff --git a/lisp/mouse.el b/lisp/mouse.el index 37721e60823..60c4f4b85c5 100644 --- a/lisp/mouse.el +++ b/lisp/mouse.el @@ -291,7 +291,9 @@ the same menu with changes such as added new menu items." context-menu-region context-menu-global context-menu-local - context-menu-minor) + context-menu-minor + context-menu-vc + context-menu-ffap) :version "28.1") (defcustom context-menu-filter-function nil @@ -313,44 +315,50 @@ the same menu with changes such as added new menu items." (defun context-menu-global (menu) "Global submenus." (run-hooks 'activate-menubar-hook 'menu-bar-update-hook) - (define-key-after menu [separator-global-1] menu-bar-separator) + (define-key-after menu [separator-global] menu-bar-separator) (dolist (item (lookup-key global-map [menu-bar])) (when (consp item) (define-key-after menu (vector (car item)) (if (consp (cdr item)) (copy-sequence (cdr item)) (cdr item))))) - (define-key-after menu [separator-global-2] menu-bar-separator) menu) (defun context-menu-local (menu) "Major mode submenus." (run-hooks 'activate-menubar-hook 'menu-bar-update-hook) - (define-key-after menu [separator-local-1] menu-bar-separator) + (define-key-after menu [separator-local] menu-bar-separator) (dolist (item (local-key-binding [menu-bar])) (when (consp item) (define-key-after menu (vector (car item)) (if (consp (cdr item)) (copy-sequence (cdr item)) (cdr item))))) - (define-key-after menu [separator-local-2] menu-bar-separator) menu) (defun context-menu-minor (menu) "Minor mode submenus." (run-hooks 'activate-menubar-hook 'menu-bar-update-hook) - (define-key-after menu [separator-minor-1] menu-bar-separator) - (dolist (item (minor-mode-key-binding [menu-bar])) - (when (and (consp item) (symbol-value (car item))) - (define-key-after menu (vector (cadr item)) - (if (consp (cddr item)) - (copy-sequence (cddr item)) - (cddr item))))) - (define-key-after menu [separator-minor-2] menu-bar-separator) + (define-key-after menu [separator-minor] menu-bar-separator) + (dolist (mode (minor-mode-key-binding [menu-bar])) + (when (and (consp mode) (symbol-value (car mode))) + (dolist (item (cdr mode)) + (when (consp item) + (define-key-after menu (vector (car item)) + (if (consp (cdr item)) + (copy-sequence (cdr item)) + (cdr item))))))) + menu) + +(defun context-menu-vc (menu) + "Version Control menu." + (define-key-after menu [separator-vc] menu-bar-separator) + (define-key-after menu [vc-menu] vc-menu-entry) menu) (defun context-menu-undo (menu) - (define-key-after menu [separator-undo-1] menu-bar-separator) + (when (cddr menu) + (define-key-after menu [separator-undo] menu-bar-separator)) (define-key-after menu [undo] '(menu-item "Undo" undo :visible (and (not buffer-read-only) @@ -364,11 +372,11 @@ the same menu with changes such as added new menu items." :visible (and (not buffer-read-only) (undo--last-change-was-undo-p buffer-undo-list)) :help "Redo last undone edits")) - (define-key-after menu [separator-undo-2] menu-bar-separator) menu) (defun context-menu-region (menu) - (define-key-after menu [separator-region-1] menu-bar-separator) + (when (cddr menu) + (define-key-after menu [separator-region] menu-bar-separator)) (define-key-after menu [cut] '(menu-item "Cut" kill-region :visible (and mark-active (not buffer-read-only)) @@ -413,7 +421,16 @@ the same menu with changes such as added new menu items." (define-key-after menu [mark-whole-buffer] '(menu-item "Select All" mark-whole-buffer :help "Mark the whole buffer for a subsequent cut/copy")) - (define-key-after menu [separator-region-2] menu-bar-separator) + menu) + +(defun context-menu-ffap (menu) + (save-excursion + (mouse-set-point last-input-event) + (when (ffap-guess-file-name-at-point) + (define-key menu [ffap-separator] menu-bar-separator) + (define-key menu [ffap-at-mouse] + '(menu-item "Find File or URL" ffap-at-mouse + :help "Find file or URL guessed from text around mouse click")))) menu) (defvar context-menu-entry diff --git a/lisp/net/eww.el b/lisp/net/eww.el index b8761029864..5c46ccfe001 100644 --- a/lisp/net/eww.el +++ b/lisp/net/eww.el @@ -1022,7 +1022,7 @@ the like." map)) (defun eww-context-menu (menu) - (define-key menu [eww-separator-2] menu-bar-separator) + (define-key menu [eww-separator] menu-bar-separator) (let ((easy-menu (make-sparse-keymap "Eww"))) (easy-menu-define nil easy-menu nil '("Eww" @@ -1047,7 +1047,6 @@ the like." 'shr-mouse-browse-url-new-window 'shr-mouse-browse-url) :help "Browse the URL under the mouse cursor"))) - (define-key menu [eww-separator-1] menu-bar-separator) menu) diff --git a/lisp/net/goto-addr.el b/lisp/net/goto-addr.el index c270cf53cbf..2c43d0f7532 100644 --- a/lisp/net/goto-addr.el +++ b/lisp/net/goto-addr.el @@ -126,11 +126,10 @@ will have no effect.") (defun goto-address-context-menu (menu) (when (mouse-posn-property (event-start last-input-event) 'goto-address) - (define-key menu [goto-address-separator-2] menu-bar-separator) + (define-key menu [goto-address-separator] menu-bar-separator) (define-key menu [goto-address-at-mouse] '(menu-item "Follow Link" goto-address-at-mouse - :help "Follow a link where you click")) - (define-key menu [goto-address-separator-1] menu-bar-separator)) + :help "Follow a link where you click"))) menu) (defcustom goto-address-url-face 'link diff --git a/lisp/progmodes/prog-mode.el b/lisp/progmodes/prog-mode.el index a10291a9c7d..a8b608b018a 100644 --- a/lisp/progmodes/prog-mode.el +++ b/lisp/progmodes/prog-mode.el @@ -45,22 +45,20 @@ (defun prog-context-menu (menu) (when (featurep 'xref) - (define-key-after menu [prog-separator-1] menu-bar-separator - 'separator-region-2) + (define-key-after menu [prog-separator] menu-bar-separator + 'mark-whole-buffer) (define-key-after menu [xref-find-def] '(menu-item "Find Definition" xref-find-definitions-at-mouse :visible (save-excursion (mouse-set-point last-input-event) (xref-backend-identifier-at-point (xref-find-backend))) :help "Find definition of function or variable") - 'prog-separator-1) + 'prog-separator) (define-key-after menu [xref-pop] '(menu-item "Back Definition" xref-pop-marker-stack :visible (not (xref-marker-stack-empty-p)) :help "Back to the position of the last search") - 'xref-find-def) - (define-key-after menu [prog-separator-2] menu-bar-separator - 'xref-pop)) + 'xref-find-def)) menu) (defvar prog-mode-map