aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJuri Linkov2021-07-21 23:34:59 +0300
committerJuri Linkov2021-07-21 23:34:59 +0300
commitebac285d0ee567ed86e14b871cf0bac2de8655db (patch)
tree7544b94da3c0b02f1ac1b0e1bd357b09423f54d3
parent1493145e3048e057d8ac9e8c9c56d1f99a97eb53 (diff)
downloademacs-ebac285d0ee567ed86e14b871cf0bac2de8655db.tar.gz
emacs-ebac285d0ee567ed86e14b871cf0bac2de8655db.zip
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.
-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."
2196 2196
2197(defun dired-context-menu (menu) 2197(defun dired-context-menu (menu)
2198 (when (mouse-posn-property (event-start last-input-event) 'dired-filename) 2198 (when (mouse-posn-property (event-start last-input-event) 'dired-filename)
2199 (define-key menu [dired-separator-1] menu-bar-separator) 2199 (define-key menu [dired-separator-2] menu-bar-separator)
2200 (let ((easy-menu (make-sparse-keymap "Immediate"))) 2200 (let ((easy-menu (make-sparse-keymap "Immediate")))
2201 (easy-menu-define nil easy-menu nil 2201 (easy-menu-define nil easy-menu nil
2202 '("Immediate" 2202 '("Immediate"
@@ -2207,7 +2207,7 @@ Do so according to the former subdir alist OLD-SUBDIR-ALIST."
2207 (dolist (item (reverse (lookup-key easy-menu [menu-bar immediate]))) 2207 (dolist (item (reverse (lookup-key easy-menu [menu-bar immediate])))
2208 (when (consp item) 2208 (when (consp item)
2209 (define-key menu (vector (car item)) (cdr item))))) 2209 (define-key menu (vector (car item)) (cdr item)))))
2210 (define-key menu [dired-separator-2] menu-bar-separator)) 2210 (define-key menu [dired-separator-1] menu-bar-separator))
2211 menu) 2211 menu)
2212 2212
2213 2213
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'."
4147 ["Exit" quit-window :help "Stop reading Info"])) 4147 ["Exit" quit-window :help "Stop reading Info"]))
4148 4148
4149(defun Info-context-menu (menu) 4149(defun Info-context-menu (menu)
4150 (when (mouse-posn-property (event-start last-input-event) 'mouse-face) 4150 (define-key menu [Info-separator-2] menu-bar-separator)
4151 (define-key menu [Info-separator-link-1] menu-bar-separator)
4152 (define-key menu [Info-mouse-follow-nearest-node]
4153 '(menu-item "Follow Link" Info-mouse-follow-nearest-node
4154 :help "Follow a link where you click"))
4155 (define-key menu [Info-separator-link-2] menu-bar-separator))
4156
4157 (define-key-after menu [Info-separator-1] menu-bar-separator)
4158 (let ((easy-menu (make-sparse-keymap "Info"))) 4151 (let ((easy-menu (make-sparse-keymap "Info")))
4159 (easy-menu-define nil easy-menu nil 4152 (easy-menu-define nil easy-menu nil
4160 '("Info" 4153 '("Info"
@@ -4162,10 +4155,15 @@ If FORK is non-nil, it is passed to `Info-goto-node'."
4162 :help "Go back in history to the last node you were at"] 4155 :help "Go back in history to the last node you were at"]
4163 ["Forward in History" Info-history-forward :visible Info-history-forward 4156 ["Forward in History" Info-history-forward :visible Info-history-forward
4164 :help "Go forward in history"])) 4157 :help "Go forward in history"]))
4165 (dolist (item (lookup-key easy-menu [menu-bar info])) 4158 (dolist (item (reverse (lookup-key easy-menu [menu-bar info])))
4166 (when (consp item) 4159 (when (consp item)
4167 (define-key-after menu (vector (car item)) (cdr item))))) 4160 (define-key menu (vector (car item)) (cdr item)))))
4168 (define-key-after menu [Info-separator-2] menu-bar-separator) 4161
4162 (when (mouse-posn-property (event-start last-input-event) 'mouse-face)
4163 (define-key menu [Info-mouse-follow-nearest-node]
4164 '(menu-item "Follow Link" Info-mouse-follow-nearest-node
4165 :help "Follow a link where you click")))
4166 (define-key menu [Info-separator-1] menu-bar-separator)
4169 4167
4170 menu) 4168 menu)
4171 4169
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."
283 context-menu-region 283 context-menu-region
284 context-menu-local 284 context-menu-local
285 context-menu-minor) 285 context-menu-minor)
286 "List of functions that produce the contents of the context menu." 286 "List of functions that produce the contents of the context menu.
287Each function receives the menu as its argument and should return
288the same menu with changes such as added new menu items."
287 :type 'hook 289 :type 'hook
288 :options '(context-menu-undo 290 :options '(context-menu-undo
289 context-menu-region 291 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."
1021 ["Toggle Paragraph Direction" eww-toggle-paragraph-direction])) 1021 ["Toggle Paragraph Direction" eww-toggle-paragraph-direction]))
1022 map)) 1022 map))
1023 1023
1024(defun eww-context-menu (menu)
1025 (define-key menu [eww-separator-2] menu-bar-separator)
1026 (let ((easy-menu (make-sparse-keymap "Eww")))
1027 (easy-menu-define nil easy-menu nil
1028 '("Eww"
1029 ["Back to previous page" eww-back-url
1030 :visible (not (zerop (length eww-history)))]
1031 ["Forward to next page" eww-forward-url
1032 :visible (not (zerop eww-history-position))]
1033 ["Reload" eww-reload t]))
1034 (dolist (item (reverse (lookup-key easy-menu [menu-bar eww])))
1035 (when (consp item)
1036 (define-key menu (vector (car item)) (cdr item)))))
1037
1038 (when (or (mouse-posn-property (event-start last-input-event) 'shr-url)
1039 (mouse-posn-property (event-start last-input-event) 'image-url))
1040 (define-key menu [shr-mouse-browse-url-new-window]
1041 `(menu-item "Follow URL in new window" ,(if browse-url-new-window-flag
1042 'shr-mouse-browse-url
1043 'shr-mouse-browse-url-new-window)
1044 :help "Browse the URL under the mouse cursor in a new window"))
1045 (define-key menu [shr-mouse-browse-url]
1046 `(menu-item "Follow URL" ,(if browse-url-new-window-flag
1047 'shr-mouse-browse-url-new-window
1048 'shr-mouse-browse-url)
1049 :help "Browse the URL under the mouse cursor")))
1050 (define-key menu [eww-separator-1] menu-bar-separator)
1051
1052 menu)
1053
1024(defvar eww-tool-bar-map 1054(defvar eww-tool-bar-map
1025 (let ((map (make-sparse-keymap))) 1055 (let ((map (make-sparse-keymap)))
1026 (dolist (tool-bar-item 1056 (dolist (tool-bar-item
@@ -1044,6 +1074,7 @@ the like."
1044 (setq-local eww-data (list :title "")) 1074 (setq-local eww-data (list :title ""))
1045 (setq-local browse-url-browser-function #'eww-browse-url) 1075 (setq-local browse-url-browser-function #'eww-browse-url)
1046 (add-hook 'after-change-functions #'eww-process-text-input nil t) 1076 (add-hook 'after-change-functions #'eww-process-text-input nil t)
1077 (add-hook 'context-menu-functions 'eww-context-menu 5 t)
1047 (setq-local eww-history nil) 1078 (setq-local eww-history nil)
1048 (setq-local eww-history-position 0) 1079 (setq-local eww-history-position 0)
1049 (when (boundp 'tool-bar-map) 1080 (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.")
126 126
127(defun goto-address-context-menu (menu) 127(defun goto-address-context-menu (menu)
128 (when (mouse-posn-property (event-start last-input-event) 'goto-address) 128 (when (mouse-posn-property (event-start last-input-event) 'goto-address)
129 (define-key menu [goto-address-separator] menu-bar-separator) 129 (define-key menu [goto-address-separator-2] menu-bar-separator)
130 (define-key menu [goto-address-at-mouse] 130 (define-key menu [goto-address-at-mouse]
131 '(menu-item "Follow Link" goto-address-at-mouse 131 '(menu-item "Follow Link" goto-address-at-mouse
132 :help "Follow a link where you click"))) 132 :help "Follow a link where you click"))
133 (define-key menu [goto-address-separator-1] menu-bar-separator))
133 menu) 134 menu)
134 135
135(defcustom goto-address-url-face 'link 136(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 @@
45 45
46(defun prog-context-menu (menu) 46(defun prog-context-menu (menu)
47 (when (featurep 'xref) 47 (when (featurep 'xref)
48 (define-key-after menu [prog-separator-1] menu-bar-separator) 48 (define-key-after menu [prog-separator-1] menu-bar-separator
49 'separator-region-2)
49 (define-key-after menu [xref-find-def] 50 (define-key-after menu [xref-find-def]
50 '(menu-item "Find Definition" xref-find-definitions-at-mouse 51 '(menu-item "Find Definition" xref-find-definitions-at-mouse
51 :visible (save-excursion 52 :visible (save-excursion
52 (mouse-set-point last-input-event) 53 (mouse-set-point last-input-event)
53 (xref-backend-identifier-at-point (xref-find-backend))) 54 (xref-backend-identifier-at-point (xref-find-backend)))
54 :help "Find definition of function or variable")) 55 :help "Find definition of function or variable")
56 'prog-separator-1)
55 (define-key-after menu [xref-pop] 57 (define-key-after menu [xref-pop]
56 '(menu-item "Back Definition" xref-pop-marker-stack 58 '(menu-item "Back Definition" xref-pop-marker-stack
57 :visible (not (xref-marker-stack-empty-p)) 59 :visible (not (xref-marker-stack-empty-p))
58 :help "Back to the position of the last search")) 60 :help "Back to the position of the last search")
59 (define-key-after menu [prog-separator-2] menu-bar-separator)) 61 'xref-find-def)
62 (define-key-after menu [prog-separator-2] menu-bar-separator
63 'xref-pop))
60 menu) 64 menu)
61 65
62(defvar prog-mode-map 66(defvar prog-mode-map