]> git.eshelyaron.com Git - emacs.git/commitdiff
; Hide completion preview when switching windows
authorEshel Yaron <me@eshelyaron.com>
Tue, 5 Dec 2023 20:04:43 +0000 (21:04 +0100)
committerEshel Yaron <me@eshelyaron.com>
Thu, 7 Dec 2023 18:25:36 +0000 (19:25 +0100)
* lisp/completion-preview.el
(completion-preview--window-selection-change): New function.
(completion-preview-active-mode): Add it to
'window-selection-change-functions'.  (Bug#67650)

lisp/completion-preview.el

index 1d5f1253702abd9ebc48deccc0ab4d696a572f4d..2ed2e5dd0011bc419cd5cfc920c9fb34e309b0d3 100644 (file)
@@ -189,10 +189,24 @@ Completion Preview mode avoids updating the preview after these commands.")
   "Return property PROP of the completion preview overlay."
   (overlay-get completion-preview--overlay prop))
 
+(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))))
+
 (define-minor-mode completion-preview-active-mode
   "Mode for when the completion preview is shown."
   :interactive nil
-  (unless completion-preview-active-mode (completion-preview-hide)))
+  (if completion-preview-active-mode
+      (add-hook 'window-selection-change-functions
+                #'completion-preview--window-selection-change nil t)
+    (remove-hook 'window-selection-change-functions
+                 #'completion-preview--window-selection-change t)
+    (completion-preview-hide)))
 
 (defun completion-preview--try-table (table beg end props)
   "Check TABLE for a completion matching the text between BEG and END.