summaryrefslogtreecommitdiff
path: root/lisp
diff options
context:
space:
mode:
authorJuri Linkov <juri@linkov.net>2021-07-21 23:34:59 +0300
committerJuri Linkov <juri@linkov.net>2021-07-21 23:34:59 +0300
commitebac285d0ee567ed86e14b871cf0bac2de8655db (patch)
tree7544b94da3c0b02f1ac1b0e1bd357b09423f54d3 /lisp
parent1493145e3048e057d8ac9e8c9c56d1f99a97eb53 (diff)
downloademacs-ebac285d0ee567ed86e14b871cf0bac2de8655db.tar.gz
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.
Diffstat (limited to 'lisp')
-rw-r--r--lisp/dired.el4
-rw-r--r--lisp/info.el20
-rw-r--r--lisp/mouse.el4
-rw-r--r--lisp/net/eww.el31
-rw-r--r--lisp/net/goto-addr.el5
-rw-r--r--lisp/progmodes/prog-mode.el12
6 files changed, 56 insertions, 20 deletions
diff --git a/lisp/dired.el b/lisp/dired.el
index 5e44f524f6b..e16df189a76 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-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)
diff --git a/lisp/info.el b/lisp/info.el
index a8848a94758..14dc299295f 100644
--- a/lisp/info.el
+++ b/lisp/info.el
@@ -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)
diff --git a/lisp/mouse.el b/lisp/mouse.el
index 7a564f989c2..37721e60823 100644
--- a/lisp/mouse.el
+++ b/lisp/mouse.el
@@ -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
diff --git a/lisp/net/eww.el b/lisp/net/eww.el
index eec3ec7ba8b..b8761029864 100644
--- a/lisp/net/eww.el
+++ b/lisp/net/eww.el
@@ -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)
diff --git a/lisp/net/goto-addr.el b/lisp/net/goto-addr.el
index 2c43d0f7532..c270cf53cbf 100644
--- a/lisp/net/goto-addr.el
+++ b/lisp/net/goto-addr.el
@@ -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
diff --git a/lisp/progmodes/prog-mode.el b/lisp/progmodes/prog-mode.el
index ad1b13f4bda..a10291a9c7d 100644
--- a/lisp/progmodes/prog-mode.el
+++ b/lisp/progmodes/prog-mode.el
@@ -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