mirror of
https://github.com/khoj-ai/khoj.git
synced 2024-11-30 19:03:01 +01:00
Initialize the Khoj Transient menu on first run instead of load
This prevents Khoj from polling the Khoj server until explicitly invoked via `khoj' entrypoint function. Previously it'd make a request to the khoj server every time Emacs or khoj.el was loaded Closes #243
This commit is contained in:
parent
b669aa2395
commit
f64fa06e22
1 changed files with 49 additions and 43 deletions
|
@ -1092,7 +1092,10 @@ Paragraph only starts at first text after blank line."
|
||||||
;; Khoj Menu
|
;; Khoj Menu
|
||||||
;; ---------
|
;; ---------
|
||||||
|
|
||||||
(transient-define-argument khoj--content-type-switch ()
|
(defun khoj--setup-and-show-menu ()
|
||||||
|
"Create Transient menu for khoj and show it."
|
||||||
|
;; Create the Khoj Transient menu
|
||||||
|
(transient-define-argument khoj--content-type-switch ()
|
||||||
:class 'transient-switches
|
:class 'transient-switches
|
||||||
:argument-format "--content-type=%s"
|
:argument-format "--content-type=%s"
|
||||||
:argument-regexp ".+"
|
:argument-regexp ".+"
|
||||||
|
@ -1101,7 +1104,7 @@ Paragraph only starts at first text after blank line."
|
||||||
;; dynamically set choices to content types enabled on khoj backend
|
;; dynamically set choices to content types enabled on khoj backend
|
||||||
:choices (or (ignore-errors (mapcar #'symbol-name (khoj--get-enabled-content-types))) '("all" "org" "markdown" "pdf" "image")))
|
:choices (or (ignore-errors (mapcar #'symbol-name (khoj--get-enabled-content-types))) '("all" "org" "markdown" "pdf" "image")))
|
||||||
|
|
||||||
(transient-define-suffix khoj--search-command (&optional args)
|
(transient-define-suffix khoj--search-command (&optional args)
|
||||||
(interactive (list (transient-args transient-current-command)))
|
(interactive (list (transient-args transient-current-command)))
|
||||||
(progn
|
(progn
|
||||||
;; set content type to: specified > last used > based on current buffer > default type
|
;; set content type to: specified > last used > based on current buffer > default type
|
||||||
|
@ -1111,7 +1114,7 @@ Paragraph only starts at first text after blank line."
|
||||||
;; trigger incremental search
|
;; trigger incremental search
|
||||||
(call-interactively #'khoj-incremental)))
|
(call-interactively #'khoj-incremental)))
|
||||||
|
|
||||||
(transient-define-suffix khoj--find-similar-command (&optional args)
|
(transient-define-suffix khoj--find-similar-command (&optional args)
|
||||||
"Find items similar to current item at point."
|
"Find items similar to current item at point."
|
||||||
(interactive (list (transient-args transient-current-command)))
|
(interactive (list (transient-args transient-current-command)))
|
||||||
(progn
|
(progn
|
||||||
|
@ -1121,7 +1124,7 @@ Paragraph only starts at first text after blank line."
|
||||||
(setq khoj-results-count (or (transient-arg-value "--results-count=" args) khoj-results-count))
|
(setq khoj-results-count (or (transient-arg-value "--results-count=" args) khoj-results-count))
|
||||||
(khoj--find-similar khoj--content-type)))
|
(khoj--find-similar khoj--content-type)))
|
||||||
|
|
||||||
(transient-define-suffix khoj--update-command (&optional args)
|
(transient-define-suffix khoj--update-command (&optional args)
|
||||||
"Call khoj API to update index of specified content type."
|
"Call khoj API to update index of specified content type."
|
||||||
(interactive (list (transient-args transient-current-command)))
|
(interactive (list (transient-args transient-current-command)))
|
||||||
(let* ((force-update (if (member "--force-update" args) "true" "false"))
|
(let* ((force-update (if (member "--force-update" args) "true" "false"))
|
||||||
|
@ -1134,12 +1137,12 @@ Paragraph only starts at first text after blank line."
|
||||||
(setq khoj--content-type content-type)
|
(setq khoj--content-type content-type)
|
||||||
(url-retrieve update-url (lambda (_) (message "khoj.el: %s index %supdated!" content-type (if (member "--force-update" args) "force " "")))))))
|
(url-retrieve update-url (lambda (_) (message "khoj.el: %s index %supdated!" content-type (if (member "--force-update" args) "force " "")))))))
|
||||||
|
|
||||||
(transient-define-suffix khoj--chat-command (&optional _)
|
(transient-define-suffix khoj--chat-command (&optional _)
|
||||||
"Command to Chat with Khoj."
|
"Command to Chat with Khoj."
|
||||||
(interactive (list (transient-args transient-current-command)))
|
(interactive (list (transient-args transient-current-command)))
|
||||||
(khoj--chat))
|
(khoj--chat))
|
||||||
|
|
||||||
(transient-define-prefix khoj--menu ()
|
(transient-define-prefix khoj--menu ()
|
||||||
"Create Khoj Menu to Configure and Execute Commands."
|
"Create Khoj Menu to Configure and Execute Commands."
|
||||||
[["Configure Search"
|
[["Configure Search"
|
||||||
("n" "Results Count" "--results-count=" :init-value (lambda (obj) (oset obj value (format "%s" khoj-results-count))))
|
("n" "Results Count" "--results-count=" :init-value (lambda (obj) (oset obj value (format "%s" khoj-results-count))))
|
||||||
|
@ -1153,6 +1156,9 @@ Paragraph only starts at first text after blank line."
|
||||||
("u" "Update" khoj--update-command)
|
("u" "Update" khoj--update-command)
|
||||||
("q" "Quit" transient-quit-one)]])
|
("q" "Quit" transient-quit-one)]])
|
||||||
|
|
||||||
|
;; Show the Khoj Transient menu
|
||||||
|
(khoj--menu))
|
||||||
|
|
||||||
|
|
||||||
;; ----------
|
;; ----------
|
||||||
;; Entrypoint
|
;; Entrypoint
|
||||||
|
@ -1164,7 +1170,7 @@ Paragraph only starts at first text after blank line."
|
||||||
(interactive)
|
(interactive)
|
||||||
(when khoj-auto-setup
|
(when khoj-auto-setup
|
||||||
(khoj-setup t))
|
(khoj-setup t))
|
||||||
(khoj--menu))
|
(khoj--setup-and-show-menu))
|
||||||
|
|
||||||
(provide 'khoj)
|
(provide 'khoj)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue