]> git.eshelyaron.com Git - emacs.git/commitdiff
Select the right buffer for event in context-menu functions (bug#9923)
authorJuri Linkov <juri@linkov.net>
Mon, 6 Dec 2021 17:24:09 +0000 (19:24 +0200)
committerJuri Linkov <juri@linkov.net>
Mon, 6 Dec 2021 17:24:09 +0000 (19:24 +0200)
* lisp/mouse.el (context-menu-region):
* lisp/progmodes/prog-mode.el (prog-context-menu):
Switch to the buffer displayed by the window of the event
before using syntax-ppss, char-after.

lisp/mouse.el
lisp/progmodes/prog-mode.el

index 5c645a4b8957788d0f2c6bf8ce8f28bdfc655208..8474a82111849bda5f5d4a613a71e4732b2d1449 100644 (file)
@@ -479,14 +479,15 @@ Some context functions add menu items below the separator."
       `(menu-item "All"
                   ,(lambda (e) (interactive "e") (mark-thing-at-mouse e 'buffer))
                   :help "Mark the whole buffer for a subsequent cut/copy"))
-    (when (let* ((pos (posn-point (event-end click)))
-                 (char (when pos (char-after pos))))
-            (or (and char (eq (char-syntax char) ?\"))
-                (nth 3 (save-excursion (syntax-ppss pos)))))
-      (define-key-after submenu [mark-string]
-        `(menu-item "String"
-                    ,(lambda (e) (interactive "e") (mark-thing-at-mouse e 'string))
-                    :help "Mark the string at click for a subsequent cut/copy")))
+    (with-current-buffer (window-buffer (posn-window (event-end click)))
+      (when (let* ((pos (posn-point (event-end click)))
+                   (char (when pos (char-after pos))))
+              (or (and char (eq (char-syntax char) ?\"))
+                  (nth 3 (save-excursion (syntax-ppss pos)))))
+        (define-key-after submenu [mark-string]
+          `(menu-item "String"
+                      ,(lambda (e) (interactive "e") (mark-thing-at-mouse e 'string))
+                      :help "Mark the string at click for a subsequent cut/copy"))))
     (define-key-after submenu [mark-line]
       `(menu-item "Line"
                   ,(lambda (e) (interactive "e") (mark-thing-at-mouse e 'line))
index 4997c2746f2b0431dddeb168c099fadfd609af7f..e43f2ff90b548c108b21ed5d08dfc20db3f33d1f 100644 (file)
@@ -87,7 +87,9 @@
     'mark-whole-buffer)
 
   ;; Include text-mode select menu only in strings and comments.
-  (when (nth 8 (save-excursion (syntax-ppss (posn-point (event-end click)))))
+  (when (nth 8 (save-excursion
+                 (with-current-buffer (window-buffer (posn-window (event-end click)))
+                   (syntax-ppss (posn-point (event-end click))))))
     (text-mode-context-menu menu click))
 
   menu)