From: Eshel Yaron via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: 67650@debbugs.gnu.org
Subject: bug#67650: [PATCH] ; Hide completion preview when switching windows
Date: Tue, 05 Dec 2023 21:26:27 +0100 [thread overview]
Message-ID: <m1sf4gwg3w.fsf@dazzs-mbp.home> (raw)
[-- Attachment #1: Type: text/plain, Size: 376 bytes --]
Tags: patch
This patch ensures that we dismiss the completion preview when users
switch to another window. Previously, the completion preview would
remain in a window after switching to another window showing another
buffer, since the `post-command-hook` that Completion Preview mode sets
up locally doesn't run after a command switches to another buffer.
Thanks,
Eshel
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Hide-completion-preview-when-switching-windows.patch --]
[-- Type: text/patch, Size: 2078 bytes --]
From 1edb324d5c47fab96eb8131393b1fd38f7dee7ce Mon Sep 17 00:00:00 2001
From: Eshel Yaron <me@eshelyaron.com>
Date: Tue, 5 Dec 2023 21:04:43 +0100
Subject: [PATCH] ; Hide completion preview when switching windows
* lisp/completion-preview.el
(completion-preview--window-selection-change): New function.
(completion-preview-mode): Add it to
'window-selection-change-functions'.
---
lisp/completion-preview.el | 16 +++++++++++++++-
1 file changed, 15 insertions(+), 1 deletion(-)
diff --git a/lisp/completion-preview.el b/lisp/completion-preview.el
index 1d5f1253702..b4f35d436b3 100644
--- a/lisp/completion-preview.el
+++ b/lisp/completion-preview.el
@@ -377,6 +377,15 @@ completion-preview--active-p
completion-preview-next-candidate))
(put cmd 'completion-predicate #'completion-preview--active-p))
+(defun completion-preview--window-selection-change (window)
+ "Hide completion preview in WINDOW after switching to another window.
+Completion Preview mode adds this function to
+`window-selection-change-functions', which see."
+ (unless (or (eq window (selected-window))
+ (eq window (minibuffer-selected-window)))
+ (with-current-buffer (window-buffer window)
+ (completion-preview-active-mode -1))))
+
;;;###autoload
(define-minor-mode completion-preview-mode
"Show in-buffer completion suggestions in a preview as you type.
@@ -391,8 +400,13 @@ completion-preview-mode
cycles backward."
:lighter " CP"
(if completion-preview-mode
- (add-hook 'post-command-hook #'completion-preview--post-command nil t)
+ (progn
+ (add-hook 'post-command-hook #'completion-preview--post-command nil t)
+ (add-hook 'window-selection-change-functions
+ #'completion-preview--window-selection-change nil t))
(remove-hook 'post-command-hook #'completion-preview--post-command t)
+ (remove-hook 'window-selection-change-functions
+ #'completion-preview--window-selection-change t)
(completion-preview-active-mode -1)))
(provide 'completion-preview)
--
2.42.0
next reply other threads:[~2023-12-05 20:26 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-05 20:26 Eshel Yaron via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
2023-12-06 12:04 ` bug#67650: [PATCH] ; Hide completion preview when switching windows Eli Zaretskii
2023-12-06 13:33 ` Eshel Yaron via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-12-06 16:43 ` Eli Zaretskii
2023-12-06 18:29 ` Eshel Yaron via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-12-06 19:02 ` Eli Zaretskii
2023-12-06 21:16 ` Eshel Yaron via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-12-09 9:08 ` Eli Zaretskii
2023-12-06 20:02 ` Dmitry Gutov
2023-12-06 20:54 ` Eshel Yaron via Bug reports for GNU Emacs, the Swiss army knife of text editors
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=m1sf4gwg3w.fsf@dazzs-mbp.home \
--to=bug-gnu-emacs@gnu.org \
--cc=67650@debbugs.gnu.org \
--cc=me@eshelyaron.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.