]> git.eshelyaron.com Git - emacs.git/commitdiff
* lisp/mouse.el (context-menu-map): Add 'click' arg to called funs (bug#50256)
authorJuri Linkov <juri@linkov.net>
Sun, 12 Sep 2021 17:11:52 +0000 (20:11 +0300)
committerJuri Linkov <juri@linkov.net>
Sun, 12 Sep 2021 17:11:52 +0000 (20:11 +0300)
(context-menu-toolbar, context-menu-global, context-menu-local)
(context-menu-minor, context-menu-buffers, context-menu-vc)
(context-menu-undo, context-menu-region, context-menu-ffap): Add 'click' arg.

* lisp/dired.el (dired-context-menu):
* lisp/help-mode.el (help-mode-context-menu):
* lisp/info.el (Info-context-menu):
* lisp/net/eww.el (eww-context-menu):
* lisp/net/goto-addr.el (goto-address-context-menu):
* lisp/progmodes/prog-mode.el (prog-context-menu):  Add 'click' arg.

lisp/dired.el
lisp/help-mode.el
lisp/info.el
lisp/mouse.el
lisp/net/eww.el
lisp/net/goto-addr.el
lisp/progmodes/prog-mode.el

index 958677cd0c78c899af40ca733facdba55a023800..1ed83cb95a763688570682e3990d0f651757568f 100644 (file)
@@ -2193,8 +2193,8 @@ Do so according to the former subdir alist OLD-SUBDIR-ALIST."
     ["Delete Image Tag..." image-dired-delete-tag
      :help "Delete image tag from current or marked files"]))
 
-(defun dired-context-menu (menu)
-  (when (mouse-posn-property (event-start last-input-event) 'dired-filename)
+(defun dired-context-menu (menu click)
+  (when (mouse-posn-property (event-start click) 'dired-filename)
     (define-key menu [dired-separator] menu-bar-separator)
     (let ((easy-menu (make-sparse-keymap "Immediate")))
       (easy-menu-define nil easy-menu nil
index d224bdcbcf8f9ba5fc94b5beabda09f48db70fe4..d341b4c9e4a8b73ec43ee285e308bf0a79bf1f9c 100644 (file)
@@ -70,7 +70,7 @@
     ["Customize" help-customize
      :help "Customize variable or face"]))
 
-(defun help-mode-context-menu (menu)
+(defun help-mode-context-menu (menu click)
   (define-key menu [help-mode-separator] menu-bar-separator)
   (let ((easy-menu (make-sparse-keymap "Help-Mode")))
     (easy-menu-define nil easy-menu nil
@@ -85,7 +85,7 @@
       (when (consp item)
         (define-key menu (vector (car item)) (cdr item)))))
 
-  (when (mouse-posn-property (event-start last-input-event) 'mouse-face)
+  (when (mouse-posn-property (event-start click) 'mouse-face)
     (define-key menu [help-mode-push-button]
       '(menu-item "Follow Link" (lambda (event)
                                   (interactive "e")
index c09c75ad4849f70a872b1ab47cdb9e8b057c20a0..b861fff744c3878ea92baacb816fefbc94d19b04 100644 (file)
@@ -4151,7 +4151,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)
+(defun Info-context-menu (menu click)
   (define-key menu [Info-separator] menu-bar-separator)
   (let ((easy-menu (make-sparse-keymap "Info")))
     (easy-menu-define nil easy-menu nil
@@ -4164,7 +4164,7 @@ If FORK is non-nil, it is passed to `Info-goto-node'."
       (when (consp item)
         (define-key menu (vector (car item)) (cdr item)))))
 
-  (when (mouse-posn-property (event-start last-input-event) 'mouse-face)
+  (when (mouse-posn-property (event-start click) '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")))
index f7ade5f89a5ce30f3c18d727b7ae8c46231f9836..bd11ec50d57fab0ed9a878bb6d5606edd9ac8669 100644 (file)
@@ -284,8 +284,8 @@ not it is actually displayed."
                                     context-menu-local
                                     context-menu-minor)
   "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."
+Each function receives the menu and the mouse click event as its arguments
+and should return the same menu with changes such as added new menu items."
   :type '(repeat
           (choice (function-item context-menu-undo)
                   (function-item context-menu-region)
@@ -304,17 +304,18 @@ the same menu with changes such as added new menu items."
   :type '(choice (const nil) function)
   :version "28.1")
 
-(defun context-menu-map ()
+(defun context-menu-map (&optional click)
   "Return composite menu map."
-  (let ((menu (make-sparse-keymap (propertize "Context Menu" 'hide t))))
-    (let ((fun (mouse-posn-property (event-start last-input-event)
-                                    'context-menu-function)))
-      (if (functionp fun)
-          (setq menu (funcall fun menu))
-        (run-hook-wrapped 'context-menu-functions
-                          (lambda (fun)
-                            (setq menu (funcall fun menu))
-                            nil))))
+  (let* ((menu (make-sparse-keymap (propertize "Context Menu" 'hide t)))
+         (click (or click last-input-event))
+         (fun (mouse-posn-property (event-start click)
+                                   'context-menu-function)))
+    (if (functionp fun)
+        (setq menu (funcall fun menu click))
+      (run-hook-wrapped 'context-menu-functions
+                        (lambda (fun)
+                          (setq menu (funcall fun menu click))
+                          nil)))
 
     ;; Remove duplicate separators
     (let ((l menu))
@@ -325,10 +326,10 @@ the same menu with changes such as added new menu items."
         (setq l (cdr l))))
 
     (when (functionp context-menu-filter-function)
-      (setq menu (funcall context-menu-filter-function menu)))
+      (setq menu (funcall context-menu-filter-function menu click)))
     menu))
 
-(defun context-menu-toolbar (menu)
+(defun context-menu-toolbar (menu _click)
   "Tool bar menu items."
   (run-hooks 'activate-menubar-hook 'menu-bar-update-hook)
   (define-key-after menu [separator-toolbar] menu-bar-separator)
@@ -339,7 +340,7 @@ the same menu with changes such as added new menu items."
               (lookup-key global-map [tool-bar]))
   menu)
 
-(defun context-menu-global (menu)
+(defun context-menu-global (menu _click)
   "Global submenus."
   (run-hooks 'activate-menubar-hook 'menu-bar-update-hook)
   (define-key-after menu [separator-global] menu-bar-separator)
@@ -350,7 +351,7 @@ the same menu with changes such as added new menu items."
               (lookup-key global-map [menu-bar]))
   menu)
 
-(defun context-menu-local (menu)
+(defun context-menu-local (menu _click)
   "Major mode submenus."
   (run-hooks 'activate-menubar-hook 'menu-bar-update-hook)
   (define-key-after menu [separator-local] menu-bar-separator)
@@ -363,7 +364,7 @@ the same menu with changes such as added new menu items."
                   keymap)))
   menu)
 
-(defun context-menu-minor (menu)
+(defun context-menu-minor (menu _click)
   "Minor modes submenus."
   (run-hooks 'activate-menubar-hook 'menu-bar-update-hook)
   (define-key-after menu [separator-minor] menu-bar-separator)
@@ -376,7 +377,7 @@ the same menu with changes such as added new menu items."
                   (cdr mode))))
   menu)
 
-(defun context-menu-buffers (menu)
+(defun context-menu-buffers (menu _click)
   "Submenus with buffers."
   (run-hooks 'activate-menubar-hook 'menu-bar-update-hook)
   (define-key-after menu [separator-buffers] menu-bar-separator)
@@ -387,13 +388,13 @@ the same menu with changes such as added new menu items."
               (mouse-buffer-menu-keymap))
   menu)
 
-(defun context-menu-vc (menu)
+(defun context-menu-vc (menu _click)
   "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)
+(defun context-menu-undo (menu _click)
   "Undo menu."
   (define-key-after menu [separator-undo] menu-bar-separator)
   (when (and (not buffer-read-only)
@@ -411,7 +412,7 @@ the same menu with changes such as added new menu items."
                   :help "Redo last undone edits")))
   menu)
 
-(defun context-menu-region (menu)
+(defun context-menu-region (menu _click)
   "Region commands menu."
   (define-key-after menu [separator-region] menu-bar-separator)
   (when (and mark-active (not buffer-read-only))
@@ -456,10 +457,10 @@ the same menu with changes such as added new menu items."
                 :help "Mark the whole buffer for a subsequent cut/copy"))
   menu)
 
-(defun context-menu-ffap (menu)
+(defun context-menu-ffap (menu click)
   "File at point menu."
   (save-excursion
-    (mouse-set-point last-input-event)
+    (mouse-set-point click)
     (when (ffap-guess-file-name-at-point)
       (define-key menu [ffap-separator] menu-bar-separator)
       (define-key menu [ffap-at-mouse]
index 90301e92acf0e2246c455e45b39bde014d52dfaa..62f19925f62c5145db739c875c40071bc2636aa3 100644 (file)
@@ -1021,7 +1021,7 @@ the like."
         ["Toggle Paragraph Direction" eww-toggle-paragraph-direction]))
     map))
 
-(defun eww-context-menu (menu)
+(defun eww-context-menu (menu click)
   (define-key menu [eww-separator] menu-bar-separator)
   (let ((easy-menu (make-sparse-keymap "Eww")))
     (easy-menu-define nil easy-menu nil
@@ -1035,8 +1035,8 @@ the like."
       (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))
+  (when (or (mouse-posn-property (event-start click) 'shr-url)
+            (mouse-posn-property (event-start click) '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
index 2c43d0f75323d8618dc16e1c65fb51ca2bbb597a..97230f42fe844a7867aea7e115aa5c70235fcdd9 100644 (file)
@@ -124,8 +124,8 @@ will have no effect.")
     m)
   "Keymap to hold goto-addr's mouse key defs under highlighted URLs.")
 
-(defun goto-address-context-menu (menu)
-  (when (mouse-posn-property (event-start last-input-event) 'goto-address)
+(defun goto-address-context-menu (menu click)
+  (when (mouse-posn-property (event-start click) 'goto-address)
     (define-key menu [goto-address-separator] menu-bar-separator)
     (define-key menu [goto-address-at-mouse]
       '(menu-item "Follow Link" goto-address-at-mouse
index be9b72e47eb8fdc25d26364f33f78af06a91016a..bd2c653638869d20a038b6aa3e45a9c66b97ae2e 100644 (file)
                                 display-line-numbers-mode
                                 prettify-symbols-mode))
 
-(defun prog-context-menu (menu)
+(defun prog-context-menu (menu click)
   (require 'xref)
   (define-key-after menu [prog-separator] menu-bar-separator
     'mark-whole-buffer)
   (when (save-excursion
-          (mouse-set-point last-input-event)
+          (mouse-set-point click)
           (xref-backend-identifier-at-point
            (xref-find-backend)))
     (define-key-after menu [xref-find-def]
@@ -56,7 +56,7 @@
                   :help "Find definition of identifier")
       'prog-separator))
   (when (save-excursion
-          (mouse-set-point last-input-event)
+          (mouse-set-point click)
           (xref-backend-identifier-at-point
            (xref-find-backend)))
     (define-key-after menu [xref-find-ref]