branch: externals/ivy
commit acb20ad74f00cb3aa339ff6c4d30ecfef342018b
Merge: d63d52f140 fd8df3b733
Author: Basil L. Contovounesios <[email protected]>
Commit: Basil L. Contovounesios <[email protected]>
Merge branch 'master' into externals/ivy
---
ivy.el | 36 ++++++++++++++++++++----------------
1 file changed, 20 insertions(+), 16 deletions(-)
diff --git a/ivy.el b/ivy.el
index 063c9eee59..cddd64aef8 100644
--- a/ivy.el
+++ b/ivy.el
@@ -3409,25 +3409,29 @@ Otherwise, ~/ will move home."
:type 'boolean)
(defcustom ivy-dynamic-exhibit-delay-ms 0
- "Delay in ms before dynamic collections are refreshed"
+ "Delay in milliseconds before dynamic collections are refreshed."
:type 'integer)
-(defvar ivy--exhibit-timer nil)
+(defvar ivy--exhibit-timer nil
+ "Timer for debouncing calls to `ivy--exhibit'.")
+
+(defvar ivy--queue-last-input nil
+ "Value of `ivy--input' from last `post-command-hook'.")
(defun ivy--queue-exhibit ()
- "Insert Ivy completions display, possibly after a timeout for
-dynamic collections.
+ "Refresh Ivy completions display, with debouncing.
+This is like `ivy--exhibit', but dynamic collections are delayed by
+`ivy-dynamic-exhibit-delay-ms' to avoid issues with rapid refreshes.
Should be run via minibuffer `post-command-hook'."
- (if (and (> ivy-dynamic-exhibit-delay-ms 0)
- (ivy-state-dynamic-collection ivy-last))
- (progn
- (when ivy--exhibit-timer (cancel-timer ivy--exhibit-timer))
- (setq ivy--exhibit-timer
- (run-with-timer
- (/ ivy-dynamic-exhibit-delay-ms 1000.0)
- nil
- 'ivy--exhibit)))
- (ivy--exhibit)))
+ (if (or (<= ivy-dynamic-exhibit-delay-ms 0)
+ (not (ivy-state-dynamic-collection ivy-last))
+ (equal ivy--queue-last-input
+ (setq ivy--queue-last-input (ivy--input))))
+ (ivy--exhibit)
+ (when ivy--exhibit-timer (cancel-timer ivy--exhibit-timer))
+ (setq ivy--exhibit-timer
+ (run-with-timer (/ ivy-dynamic-exhibit-delay-ms 1000.0)
+ nil #'ivy--exhibit))))
(defalias 'ivy--file-local-name
(if (fboundp 'file-local-name)
@@ -3455,8 +3459,8 @@ The function was added in Emacs 26.1.")
(defun ivy--exhibit ()
"Insert Ivy completions display.
-Should be run via minibuffer `post-command-hook'."
- (when (memq 'ivy--queue-exhibit post-command-hook)
+Should be run in the minibuffer."
+ (when (memq #'ivy--queue-exhibit post-command-hook)
(let ((inhibit-field-text-motion nil))
(constrain-to-field nil (point-max)))
(ivy-set-text (ivy--input))