Skip to content

Commit

Permalink
make default async delays configurable
Browse files Browse the repository at this point in the history
fix #109
  • Loading branch information
minad committed Jan 1, 2021
1 parent a656682 commit 2fd52e0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,10 @@ that the main package `consult.el` only depends on Emacs core components.
| Variable | Default | Description |
|-------------------------------|------------------|---------------------------------------------------------|
| consult-after-jump-hook | '(recenter) | Functions to call after jumping to a location |
| consult-async-min-input | 3 | Minimum numbers of letters needed for async process |
| consult-async-default-split | "#" | Separator character used for splitting #async#filter |
| consult-async-input-delay | 0.5 | Input delay for asynchronous commands |
| consult-async-min-input | 3 | Minimum numbers of letters needed for async process |
| consult-async-refresh-delay | 0.2 | Refresh delay for asynchronous commands |
| consult-goto-line-numbers | t | Show line numbers for `consult-goto-line` |
| consult-imenu-narrow || Mode-specific narrowing keys for `consult-imenu` |
| consult-imenu-toplevel || Mode-specific toplevel names used by `consult-imenu` |
Expand Down
18 changes: 14 additions & 4 deletions consult.el
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,14 @@ If this key is unset, defaults to 'consult-narrow-key SPC'."
"Function which returns project root, used by `consult-buffer' and `consult-grep'."
:type 'function)

(defcustom consult-async-refresh-delay 0.2
"Refreshing delay of the completion ui for asynchronous commands."
:type 'float)

(defcustom consult-async-input-delay 0.5
"Input delay of the completion ui for asynchronous commands."
:type 'float)

(defcustom consult-async-min-input 3
"Minimum number of letters needed, before asynchronous process is called.
This applies for example to `consult-grep'."
Expand Down Expand Up @@ -1009,8 +1017,10 @@ CMD is the command argument list."
(_ (funcall async action))))))

(defun consult--async-throttle (async &optional delay)
"Create async function from ASYNC which limits the input rate by DELAY."
(let ((delay (or delay 0.5)) (input "") (timer))
"Create async function from ASYNC which limits the input rate by DELAY.
The delay defaults to `consult-async-input-delay'."
(let ((delay (or delay consult-async-input-delay)) (input "") (timer))
(lambda (action)
(pcase action
('setup
Expand Down Expand Up @@ -1038,8 +1048,8 @@ The refresh happens immediately when candidates are pushed."
(defun consult--async-refresh-timer (async &optional delay)
"Create async function from ASYNC, which refreshes the display.
The refresh happens after a DELAY, defaulting to 0.2."
(let ((timer) (refresh t) (delay (or delay 0.2)))
The refresh happens after a DELAY, defaulting to `consult-async-refresh-delay'."
(let ((timer) (refresh t) (delay (or delay consult-async-refresh-delay)))
(lambda (action)
(pcase action
((or (pred listp) (pred stringp) 'refresh 'flush)
Expand Down

0 comments on commit 2fd52e0

Please sign in to comment.