Improve docstring of context-menu-functions and add eww-context-menu

* lisp/mouse.el (context-menu-functions): Explain function args in docstring.

* lisp/net/eww.el (eww-context-menu): New function.
(eww-mode): Add it to context-menu-functions.

* lisp/info.el (Info-context-menu): Move history items higher.

* lisp/progmodes/prog-mode.el (prog-context-menu): Add menu items
in the middle of the menu after the region menu items.
This commit is contained in:
Juri Linkov 2021-07-21 23:34:59 +03:00
parent 1493145e30
commit ebac285d0e
6 changed files with 56 additions and 20 deletions

View file

@ -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-1] menu-bar-separator)
(define-key menu [dired-separator-2] menu-bar-separator)
(let ((easy-menu (make-sparse-keymap "Immediate")))
(easy-menu-define nil easy-menu nil
'("Immediate"
@ -2207,7 +2207,7 @@ Do so according to the former subdir alist OLD-SUBDIR-ALIST."
(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-2] menu-bar-separator))
(define-key menu [dired-separator-1] menu-bar-separator))
menu)

View file

@ -4147,14 +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)
(when (mouse-posn-property (event-start last-input-event) 'mouse-face)
(define-key menu [Info-separator-link-1] menu-bar-separator)
(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-link-2] menu-bar-separator))
(define-key-after menu [Info-separator-1] menu-bar-separator)
(define-key menu [Info-separator-2] menu-bar-separator)
(let ((easy-menu (make-sparse-keymap "Info")))
(easy-menu-define nil easy-menu nil
'("Info"
@ -4162,10 +4155,15 @@ If FORK is non-nil, it is passed to `Info-goto-node'."
:help "Go back in history to the last node you were at"]
["Forward in History" Info-history-forward :visible Info-history-forward
:help "Go forward in history"]))
(dolist (item (lookup-key easy-menu [menu-bar info]))
(dolist (item (reverse (lookup-key easy-menu [menu-bar info])))
(when (consp item)
(define-key-after menu (vector (car item)) (cdr item)))))
(define-key-after menu [Info-separator-2] menu-bar-separator)
(define-key menu (vector (car item)) (cdr item)))))
(when (mouse-posn-property (event-start last-input-event) 'mouse-face)
(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)

View file

@ -283,7 +283,9 @@ not it is actually displayed."
context-menu-region
context-menu-local
context-menu-minor)
"List of functions that produce the contents of the context menu."
"List of functions that produce the contents of the context menu.
Each function receives the menu as its argument and should return
the same menu with changes such as added new menu items."
:type 'hook
:options '(context-menu-undo
context-menu-region

View file

@ -1021,6 +1021,36 @@ the like."
["Toggle Paragraph Direction" eww-toggle-paragraph-direction]))
map))
(defun eww-context-menu (menu)
(define-key menu [eww-separator-2] menu-bar-separator)
(let ((easy-menu (make-sparse-keymap "Eww")))
(easy-menu-define nil easy-menu nil
'("Eww"
["Back to previous page" eww-back-url
:visible (not (zerop (length eww-history)))]
["Forward to next page" eww-forward-url
:visible (not (zerop eww-history-position))]
["Reload" eww-reload t]))
(dolist (item (reverse (lookup-key easy-menu [menu-bar eww])))
(when (consp item)
(define-key menu (vector (car item)) (cdr item)))))
(when (or (mouse-posn-property (event-start last-input-event) 'shr-url)
(mouse-posn-property (event-start last-input-event) 'image-url))
(define-key menu [shr-mouse-browse-url-new-window]
`(menu-item "Follow URL in new window" ,(if browse-url-new-window-flag
'shr-mouse-browse-url
'shr-mouse-browse-url-new-window)
:help "Browse the URL under the mouse cursor in a new window"))
(define-key menu [shr-mouse-browse-url]
`(menu-item "Follow URL" ,(if browse-url-new-window-flag
'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)
(defvar eww-tool-bar-map
(let ((map (make-sparse-keymap)))
(dolist (tool-bar-item
@ -1044,6 +1074,7 @@ the like."
(setq-local eww-data (list :title ""))
(setq-local browse-url-browser-function #'eww-browse-url)
(add-hook 'after-change-functions #'eww-process-text-input nil t)
(add-hook 'context-menu-functions 'eww-context-menu 5 t)
(setq-local eww-history nil)
(setq-local eww-history-position 0)
(when (boundp 'tool-bar-map)

View file

@ -126,10 +126,11 @@ 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] menu-bar-separator)
(define-key menu [goto-address-separator-2] 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")))
:help "Follow a link where you click"))
(define-key menu [goto-address-separator-1] menu-bar-separator))
menu)
(defcustom goto-address-url-face 'link

View file

@ -45,18 +45,22 @@
(defun prog-context-menu (menu)
(when (featurep 'xref)
(define-key-after menu [prog-separator-1] menu-bar-separator)
(define-key-after menu [prog-separator-1] menu-bar-separator
'separator-region-2)
(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"))
:help "Find definition of function or variable")
'prog-separator-1)
(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"))
(define-key-after menu [prog-separator-2] menu-bar-separator))
:help "Back to the position of the last search")
'xref-find-def)
(define-key-after menu [prog-separator-2] menu-bar-separator
'xref-pop))
menu)
(defvar prog-mode-map