Skip to content

Commit fd8df3b

Browse files
committed
Clean up ivy--queue-exhibit
* ivy.el (ivy-dynamic-exhibit-delay-ms, ivy--exhibit-timer) (ivy--queue-last-input, ivy--exhibit): Fix docstring. (ivy--queue-exhibit): Ditto. Refactor to only compute ivy--input once (#2941).
1 parent c9cdd22 commit fd8df3b

File tree

1 file changed

+20
-19
lines changed

1 file changed

+20
-19
lines changed

ivy.el

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3409,28 +3409,29 @@ Otherwise, ~/ will move home."
34093409
:type 'boolean)
34103410

34113411
(defcustom ivy-dynamic-exhibit-delay-ms 0
3412-
"Delay in ms before dynamic collections are refreshed"
3412+
"Delay in milliseconds before dynamic collections are refreshed."
34133413
:type 'integer)
34143414

3415-
(defvar ivy--queue-last-input nil)
3416-
(defvar ivy--exhibit-timer nil)
3415+
(defvar ivy--exhibit-timer nil
3416+
"Timer for debouncing calls to `ivy--exhibit'.")
3417+
3418+
(defvar ivy--queue-last-input nil
3419+
"Value of `ivy--input' from last `post-command-hook'.")
34173420

34183421
(defun ivy--queue-exhibit ()
3419-
"Insert Ivy completions display, possibly after a timeout for
3420-
dynamic collections.
3422+
"Refresh Ivy completions display, with debouncing.
3423+
This is like `ivy--exhibit', but dynamic collections are delayed by
3424+
`ivy-dynamic-exhibit-delay-ms' to avoid issues with rapid refreshes.
34213425
Should be run via minibuffer `post-command-hook'."
3422-
(if (and (> ivy-dynamic-exhibit-delay-ms 0)
3423-
(ivy-state-dynamic-collection ivy-last)
3424-
(not (equal ivy--queue-last-input (ivy--input))))
3425-
(progn
3426-
(when ivy--exhibit-timer (cancel-timer ivy--exhibit-timer))
3427-
(setq ivy--exhibit-timer
3428-
(run-with-timer
3429-
(/ ivy-dynamic-exhibit-delay-ms 1000.0)
3430-
nil
3431-
'ivy--exhibit)))
3432-
(ivy--exhibit))
3433-
(setq ivy--queue-last-input (ivy--input)))
3426+
(if (or (<= ivy-dynamic-exhibit-delay-ms 0)
3427+
(not (ivy-state-dynamic-collection ivy-last))
3428+
(equal ivy--queue-last-input
3429+
(setq ivy--queue-last-input (ivy--input))))
3430+
(ivy--exhibit)
3431+
(when ivy--exhibit-timer (cancel-timer ivy--exhibit-timer))
3432+
(setq ivy--exhibit-timer
3433+
(run-with-timer (/ ivy-dynamic-exhibit-delay-ms 1000.0)
3434+
nil #'ivy--exhibit))))
34343435

34353436
(defalias 'ivy--file-local-name
34363437
(if (fboundp 'file-local-name)
@@ -3458,8 +3459,8 @@ The function was added in Emacs 26.1.")
34583459

34593460
(defun ivy--exhibit ()
34603461
"Insert Ivy completions display.
3461-
Should be run via minibuffer `post-command-hook'."
3462-
(when (memq 'ivy--queue-exhibit post-command-hook)
3462+
Should be run in the minibuffer."
3463+
(when (memq #'ivy--queue-exhibit post-command-hook)
34633464
(let ((inhibit-field-text-motion nil))
34643465
(constrain-to-field nil (point-max)))
34653466
(ivy-set-text (ivy--input))

0 commit comments

Comments
 (0)