mirror of
https://github.com/khoaliber/khoj.git
synced 2026-03-06 05:39:12 +00:00
Wait for user to stop typing to trigger search from khoj.el in Emacs
- Improves user experience by aligning idle time with search latency to avoid display jitter (to render results) while user is typing - Makes the idle time configurable Closes #480
This commit is contained in:
@@ -87,6 +87,12 @@
|
||||
:group 'khoj
|
||||
:type 'integer)
|
||||
|
||||
(defcustom khoj-search-on-idle-time 0.3
|
||||
"Idle time (in seconds) to wait before triggering search."
|
||||
:group 'khoj
|
||||
:type 'number)
|
||||
|
||||
|
||||
(defcustom khoj-default-content-type "org"
|
||||
"The default content type to perform search on."
|
||||
:group 'khoj
|
||||
@@ -115,6 +121,9 @@
|
||||
(defvar khoj--content-type "org"
|
||||
"The type of content to perform search on.")
|
||||
|
||||
(defvar khoj--search-on-idle-timer nil
|
||||
"Idle timer to trigger incremental search.")
|
||||
|
||||
(declare-function org-element-property "org-mode" (PROPERTY ELEMENT))
|
||||
(declare-function org-element-type "org-mode" (ELEMENT))
|
||||
(declare-function markdown-mode "markdown-mode" ())
|
||||
@@ -920,6 +929,9 @@ RECEIVE-DATE is the message receive date."
|
||||
(message "khoj.el: Teardown Incremental Search")
|
||||
;; unset khoj minibuffer window
|
||||
(setq khoj--minibuffer-window nil)
|
||||
(when (and khoj--search-on-idle-timer
|
||||
(timerp khoj--search-on-idle-timer))
|
||||
(cancel-timer khoj--search-on-idle-timer))
|
||||
;; delete open connections to khoj server
|
||||
(khoj--delete-open-network-connections-to-server)
|
||||
;; remove hooks for khoj incremental query and self
|
||||
@@ -942,8 +954,10 @@ RECEIVE-DATE is the message receive date."
|
||||
;; set current (mini-)buffer entered as khoj minibuffer
|
||||
;; used to query khoj API only when user in khoj minibuffer
|
||||
(setq khoj--minibuffer-window (current-buffer))
|
||||
(add-hook 'post-command-hook #'khoj--incremental-search) ; do khoj incremental search after every user action
|
||||
(add-hook 'minibuffer-exit-hook #'khoj--teardown-incremental-search)) ; teardown khoj incremental search on minibuffer exit
|
||||
; do khoj incremental search after idle time
|
||||
(setq khoj--search-on-idle-timer (run-with-idle-timer khoj-search-on-idle-time t #'khoj--incremental-search))
|
||||
; teardown khoj incremental search on minibuffer exit
|
||||
(add-hook 'minibuffer-exit-hook #'khoj--teardown-incremental-search))
|
||||
(read-string khoj--query-prompt))))
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user