From 465635456c581a7bc667fc1333ce463e19262a35 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jo=C3=A3o=20T=C3=A1vora?= Date: Fri, 4 May 2018 00:25:03 +0100 Subject: [PATCH] Fix mode-line mouse-clicks from outside selected window * eglot.el (eglot--mode-line-call): New helper. (eglot--mode-line-format): Use it. --- lisp/progmodes/eglot.el | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/lisp/progmodes/eglot.el b/lisp/progmodes/eglot.el index 693535ac8b1..bdd339d9715 100644 --- a/lisp/progmodes/eglot.el +++ b/lisp/progmodes/eglot.el @@ -695,6 +695,13 @@ that case, also signal textDocument/didOpen." (put 'eglot--mode-line-format 'risky-local-variable t) +(defun eglot--mode-line-call (what) + "Make an interactive lambda for calling WHAT from mode-line." + (lambda (event) + (interactive "e") + (with-selected-window (posn-window (event-start event)) + (call-interactively what)))) + (defun eglot--mode-line-format () "Compose the mode-line format spec." (pcase-let* ((proc (eglot--current-process)) @@ -715,7 +722,7 @@ that case, also signal textDocument/didOpen." face eglot-mode-line keymap ,(let ((map (make-sparse-keymap))) (define-key map [mode-line down-mouse-1] - eglot-menu) + (eglot--mode-line-call 'eglot-menu)) map) mouse-face mode-line-highlight help-echo "mouse-1: pop-up EGLOT menu" @@ -726,9 +733,12 @@ that case, also signal textDocument/didOpen." ,name face eglot-mode-line keymap ,(let ((map (make-sparse-keymap))) - (define-key map [mode-line mouse-1] 'eglot-events-buffer) - (define-key map [mode-line mouse-2] 'eglot-shutdown) - (define-key map [mode-line mouse-3] 'eglot-reconnect) + (define-key map [mode-line mouse-1] + (eglot--mode-line-call 'eglot-events-buffer)) + (define-key map [mode-line mouse-2] + (eglot--mode-line-call 'eglot-shutdown)) + (define-key map [mode-line mouse-3] + (eglot--mode-line-call 'eglot-reconnect)) map) mouse-face mode-line-highlight help-echo ,(concat "mouse-1: go to events buffer\n" @@ -744,9 +754,9 @@ that case, also signal textDocument/didOpen." face compilation-mode-line-fail keymap ,(let ((map (make-sparse-keymap))) (define-key map [mode-line mouse-1] - 'eglot-events-buffer) + (eglot--mode-line-call 'eglot-events-buffer)) (define-key map [mode-line mouse-3] - 'eglot-clear-status) + (eglot--mode-line-call 'eglot-clear-status)) map)))) ,@(when (and doing (not done-p)) `("/" @@ -757,7 +767,7 @@ that case, also signal textDocument/didOpen." face compilation-mode-line-run keymap ,(let ((map (make-sparse-keymap))) (define-key map [mode-line mouse-1] - 'eglot-events-buffer) + (eglot--mode-line-call 'eglot-events-buffer)) map)))) ,@(when (cl-plusp pending) `("/" @@ -775,9 +785,9 @@ that case, also signal textDocument/didOpen." 'eglot-mode-line)) keymap ,(let ((map (make-sparse-keymap))) (define-key map [mode-line mouse-1] - 'eglot-events-buffer) + (eglot--mode-line-call 'eglot-events-buffer)) (define-key map [mode-line mouse-3] - 'eglot-forget-pending-continuations) + (eglot--mode-line-call 'eglot-forget-pending-continuations)) map))))))))) (add-to-list 'mode-line-misc-info -- 2.39.2