unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#67650: [PATCH] ; Hide completion preview when switching windows
@ 2023-12-05 20:26 Eshel Yaron via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2023-12-06 12:04 ` Eli Zaretskii
  2023-12-06 20:02 ` Dmitry Gutov
  0 siblings, 2 replies; 10+ messages in thread
From: Eshel Yaron via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2023-12-05 20:26 UTC (permalink / raw)
  To: 67650

[-- 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


^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2023-12-09  9:08 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-12-05 20:26 bug#67650: [PATCH] ; Hide completion preview when switching windows Eshel Yaron via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-12-06 12:04 ` 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

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).