mirror of
https://github.com/khoaliber/khoj.git
synced 2026-03-06 05:39:12 +00:00
Convert main khoj.el entrypoint into transient menu for richer configuration
This commit is contained in:
@@ -6,7 +6,7 @@
|
|||||||
;; Description: Natural, Incremental Search for your Second Brain
|
;; Description: Natural, Incremental Search for your Second Brain
|
||||||
;; Keywords: search, org-mode, outlines, markdown, beancount, ledger, image
|
;; Keywords: search, org-mode, outlines, markdown, beancount, ledger, image
|
||||||
;; Version: 0.2.2
|
;; Version: 0.2.2
|
||||||
;; Package-Requires: ((emacs "27.1"))
|
;; Package-Requires: ((emacs "27.1") (transient "0.3.0"))
|
||||||
;; URL: https://github.com/debanjum/khoj/tree/master/src/interface/emacs
|
;; URL: https://github.com/debanjum/khoj/tree/master/src/interface/emacs
|
||||||
|
|
||||||
;; This file is NOT part of GNU Emacs.
|
;; This file is NOT part of GNU Emacs.
|
||||||
@@ -48,6 +48,7 @@
|
|||||||
|
|
||||||
(require 'url)
|
(require 'url)
|
||||||
(require 'json)
|
(require 'json)
|
||||||
|
(require 'transient)
|
||||||
|
|
||||||
(defcustom khoj-server-url "http://localhost:8000"
|
(defcustom khoj-server-url "http://localhost:8000"
|
||||||
"Location of Khoj API server."
|
"Location of Khoj API server."
|
||||||
@@ -332,14 +333,10 @@ Render results in BUFFER-NAME."
|
|||||||
(remove-hook 'post-command-hook #'khoj--incremental-search)
|
(remove-hook 'post-command-hook #'khoj--incremental-search)
|
||||||
(remove-hook 'minibuffer-exit-hook #'khoj--teardown-incremental-search))
|
(remove-hook 'minibuffer-exit-hook #'khoj--teardown-incremental-search))
|
||||||
|
|
||||||
|
(defun khoj-incremental ()
|
||||||
;;;###autoload
|
|
||||||
(defun khoj ()
|
|
||||||
"Natural, Incremental Search for your personal notes, transactions and music."
|
"Natural, Incremental Search for your personal notes, transactions and music."
|
||||||
(interactive)
|
(interactive)
|
||||||
(let* ((khoj-buffer-name (get-buffer-create khoj--buffer-name)))
|
(let* ((khoj-buffer-name (get-buffer-create khoj--buffer-name)))
|
||||||
;; set khoj search type to last used or based on current buffer
|
|
||||||
(setq khoj--search-type (or khoj--search-type (khoj--buffer-name-to-search-type (buffer-name))))
|
|
||||||
;; switch to khoj results buffer
|
;; switch to khoj results buffer
|
||||||
(switch-to-buffer khoj-buffer-name)
|
(switch-to-buffer khoj-buffer-name)
|
||||||
;; open and setup minibuffer for incremental search
|
;; open and setup minibuffer for incremental search
|
||||||
@@ -356,6 +353,32 @@ Render results in BUFFER-NAME."
|
|||||||
(add-hook 'minibuffer-exit-hook #'khoj--teardown-incremental-search)) ; teardown khoj incremental search on minibuffer exit
|
(add-hook 'minibuffer-exit-hook #'khoj--teardown-incremental-search)) ; teardown khoj incremental search on minibuffer exit
|
||||||
(read-string khoj--query-prompt))))
|
(read-string khoj--query-prompt))))
|
||||||
|
|
||||||
|
(transient-define-argument khoj--content-type-switch ()
|
||||||
|
:class 'transient-switches
|
||||||
|
:argument-format "--content-type=%s"
|
||||||
|
:argument-regexp ".+"
|
||||||
|
;; set content type to last used or based on current buffer or to default
|
||||||
|
:init-value (lambda (obj) (oset obj value (format "--content-type=%s" (or khoj--search-type (khoj--buffer-name-to-search-type (buffer-name))))))
|
||||||
|
:choices '("org" "markdown" "ledger" "music" "image"))
|
||||||
|
|
||||||
|
(transient-define-suffix khoj--search (&optional args)
|
||||||
|
(interactive (list (transient-args transient-current-command)))
|
||||||
|
(progn
|
||||||
|
;; set search type to last used or based on current buffer or to default
|
||||||
|
(setq khoj--search-type (or (transient-arg-value "--content-type=" args) (khoj--buffer-name-to-search-type (buffer-name))))
|
||||||
|
;; set results count to last used or to default
|
||||||
|
(setq khoj-results-count (or (transient-arg-value "--results-count=" args) khoj-results-count))
|
||||||
|
;; trigger incremental search
|
||||||
|
(call-interactively #'khoj-incremental)))
|
||||||
|
|
||||||
|
|
||||||
|
;;;###autoload
|
||||||
|
(transient-define-prefix khoj ()
|
||||||
|
[["Set"
|
||||||
|
("t" "Content Type" khoj--content-type-switch)
|
||||||
|
("n" "Results Count" "--results-count=" :init-value (lambda (obj) (oset obj value (format "%s" khoj-results-count))))]]
|
||||||
|
[["Act" ("s" "Search" khoj--search)]])
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun khoj-simple (query)
|
(defun khoj-simple (query)
|
||||||
"Natural Search for QUERY on your personal notes, transactions, music and images."
|
"Natural Search for QUERY on your personal notes, transactions, music and images."
|
||||||
|
|||||||
Reference in New Issue
Block a user