summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBasil L. Contovounesios <basil@contovou.net>2025-04-15 12:36:59 +0200
committerBasil L. Contovounesios <basil@contovou.net>2025-11-23 11:36:19 +0100
commit2c64b2994e1dd778a625f58be711b5cc0ac31435 (patch)
tree52fb3f69af878eee2841e08e9ef99c7a0c19102f
parent425c85672454b44fb84250d607636f8879ffade2 (diff)
Fix minibuffer hooks
The function ivy--cleanup runs after exiting (and outside of) the minibuffer. Instead of removing Ivy minibuffer-local hooks from their default values in ivy--cleanup, do so locally in the appropriate minibuffer-exit-hook. * ivy.el (ivy--cleanup): Remove temporary ESS workaround which is no longer needed (#1660, emacs-ess/ESS#609). Stop removing Ivy minibuffer-local hooks from default post-command-hook and window-size-change-functions. (ivy--minibuffer-exit): New function that removes these hooks minibuffer-locally instead. (ivy--minibuffer-setup): Add it to current minibuffer-exit-hook. (ivy--completing-p): New function, extracted... (ivy--exhibit): ...from here. (ivy--window-size-changed): Use it instead of ivy-mode for determining whether Ivy is completing something, since it's possible to use Ivy-based completion with ivy-mode off.
-rw-r--r--ivy.el21
1 files changed, 14 insertions, 7 deletions
diff --git a/ivy.el b/ivy.el
index b790306..63d90a5 100644
--- a/ivy.el
+++ b/ivy.el
@@ -2291,10 +2291,6 @@ customizations apply to the current completion session."
hist (propertize item 'ivy-index ivy--index))))))))
(defun ivy--cleanup ()
- ;; Fixes a bug in ESS, #1660
- (put 'post-command-hook 'permanent-local nil)
- (remove-hook 'post-command-hook #'ivy--queue-exhibit)
- (remove-hook 'window-size-change-functions #'ivy--window-size-changed)
(let ((cleanup (ivy--display-function-prop :cleanup))
(unwind (ivy-state-unwind ivy-last)))
(when (functionp cleanup)
@@ -3115,7 +3111,7 @@ tries to ensure that it does not change depending on the number of candidates."
:type 'boolean)
(defun ivy--minibuffer-setup ()
- "Setup ivy completion in the minibuffer."
+ "Set up Ivy completion in `minibuffer-setup-hook'."
;; Guard for --without-x builds where `mwheel' is not preloaded.
(when (boundp 'mwheel-scroll-up-function)
(setq-local mwheel-scroll-up-function 'ivy-next-line))
@@ -3136,12 +3132,19 @@ tries to ensure that it does not change depending on the number of candidates."
(ivy-add-newline-after-prompt 2))))
(when height
(set-window-text-height nil height)))
+ (add-hook 'minibuffer-exit-hook #'ivy--minibuffer-exit nil t)
(add-hook 'post-command-hook #'ivy--queue-exhibit nil t)
(add-hook 'window-size-change-functions #'ivy--window-size-changed nil t)
(let ((hook (ivy-alist-setting ivy-hooks-alist)))
(when (functionp hook)
(funcall hook))))
+(defun ivy--minibuffer-exit ()
+ "Clean up Ivy completion in `minibuffer-exit-hook'."
+ (remove-hook 'minibuffer-exit-hook #'ivy--minibuffer-exit t)
+ (remove-hook 'post-command-hook #'ivy--queue-exhibit t)
+ (remove-hook 'window-size-change-functions #'ivy--window-size-changed t))
+
(defun ivy--input ()
"Return the current minibuffer input."
;; assume one-line minibuffer input
@@ -3478,10 +3481,14 @@ The function was added in Emacs 26.1.")
(ivy--format
(setq ivy--all-candidates cands))))
+(defun ivy--completing-p ()
+ "Return non-nil if Ivy is completing in the current buffer."
+ (memq #'ivy--queue-exhibit post-command-hook))
+
(defun ivy--exhibit ()
"Insert Ivy completions display.
Should be run in the minibuffer."
- (when (memq #'ivy--queue-exhibit post-command-hook)
+ (when (ivy--completing-p)
(let ((inhibit-field-text-motion nil))
(constrain-to-field nil (point-max)))
(ivy-set-text (ivy--input))
@@ -3628,7 +3635,7 @@ height < `ivy-height', auto-shrink the minibuffer."
(defun ivy--window-size-changed (&rest _)
"Resize ivy window to fit with current frame's size."
- (when ivy-mode
+ (when (ivy--completing-p)
(ivy--resize-minibuffer-to-fit)))
(defun ivy--add-face (str face)