diff --git a/lisp/mouse.el b/lisp/mouse.el index 30fe5e99ff..851da77ce0 100644 --- a/lisp/mouse.el +++ b/lisp/mouse.el @@ -488,14 +488,15 @@ context-menu-region `(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) + (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)) diff --git a/lisp/progmodes/prog-mode.el b/lisp/progmodes/prog-mode.el index 30b6edf0d9..bf1f619858 100644 --- a/lisp/progmodes/prog-mode.el +++ b/lisp/progmodes/prog-mode.el @@ -93,7 +93,9 @@ prog-context-menu '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) + (syntax-ppss (posn-point (event-end click)))))) (text-mode-context-menu menu click)) menu)