mirror of
https://github.com/khoaliber/khoj.git
synced 2026-03-09 05:39:12 +00:00
Clean-up khoj.el based on linting helpers and manual review
This commit is contained in:
@@ -109,6 +109,8 @@
|
|||||||
(defvar khoj--content-type "org"
|
(defvar khoj--content-type "org"
|
||||||
"The type of content to perform search on.")
|
"The type of content to perform search on.")
|
||||||
|
|
||||||
|
(declare-function org-element-property "org-mode" (PROPERTY ELEMENT))
|
||||||
|
(declare-function org-element-type "org-mode" (ELEMENT))
|
||||||
(declare-function beancount-mode "beancount" ())
|
(declare-function beancount-mode "beancount" ())
|
||||||
(declare-function markdown-mode "markdown-mode" ())
|
(declare-function markdown-mode "markdown-mode" ())
|
||||||
(declare-function org-music-mode "org-music" ())
|
(declare-function org-music-mode "org-music" ())
|
||||||
@@ -345,6 +347,7 @@ Render results in BUFFER-NAME using QUERY, CONTENT-TYPE."
|
|||||||
(khoj--query-chat-api-and-render-messages query khoj--chat-buffer-name))))
|
(khoj--query-chat-api-and-render-messages query khoj--chat-buffer-name))))
|
||||||
|
|
||||||
(defun khoj--load-chat-history (buffer-name)
|
(defun khoj--load-chat-history (buffer-name)
|
||||||
|
"Load Khoj Chat conversation history into BUFFER-NAME."
|
||||||
(let ((json-response (cdr (assoc 'response (khoj--query-chat-api "")))))
|
(let ((json-response (cdr (assoc 'response (khoj--query-chat-api "")))))
|
||||||
(with-current-buffer (get-buffer-create buffer-name)
|
(with-current-buffer (get-buffer-create buffer-name)
|
||||||
(erase-buffer)
|
(erase-buffer)
|
||||||
@@ -366,7 +369,7 @@ Render results in BUFFER-NAME using QUERY, CONTENT-TYPE."
|
|||||||
(read-only-mode t)))))
|
(read-only-mode t)))))
|
||||||
|
|
||||||
(defun khoj--add-hover-text-to-footnote-refs (start-pos)
|
(defun khoj--add-hover-text-to-footnote-refs (start-pos)
|
||||||
"Show footnote definition on mouse hover over all footnote references from START-POS."
|
"Show footnote defs on mouse hover on footnote refs from START-POS."
|
||||||
(org-with-wide-buffer
|
(org-with-wide-buffer
|
||||||
(goto-char start-pos)
|
(goto-char start-pos)
|
||||||
(while (re-search-forward org-footnote-re nil t)
|
(while (re-search-forward org-footnote-re nil t)
|
||||||
@@ -382,8 +385,11 @@ Render results in BUFFER-NAME using QUERY, CONTENT-TYPE."
|
|||||||
'(footnote-reference))
|
'(footnote-reference))
|
||||||
(-->
|
(-->
|
||||||
footnote-def
|
footnote-def
|
||||||
|
;; truncate footnote definition if required
|
||||||
(substring it 0 footnote-width)
|
(substring it 0 footnote-width)
|
||||||
|
;; append continuation suffix if truncated
|
||||||
(concat it (if footnote-width "..." ""))
|
(concat it (if footnote-width "..." ""))
|
||||||
|
;; show definition on hover on footnote reference
|
||||||
(overlay-put overlay 'help-echo it)))))))
|
(overlay-put overlay 'help-echo it)))))))
|
||||||
|
|
||||||
(defun khoj--query-chat-api-and-render-messages (query buffer-name)
|
(defun khoj--query-chat-api-and-render-messages (query buffer-name)
|
||||||
@@ -399,9 +405,10 @@ Render results in BUFFER-NAME using QUERY, CONTENT-TYPE."
|
|||||||
(khoj--render-chat-message query "you" query-time)
|
(khoj--render-chat-message query "you" query-time)
|
||||||
(khoj--render-chat-response json-response))
|
(khoj--render-chat-response json-response))
|
||||||
(khoj--add-hover-text-to-footnote-refs new-content-start-pos))
|
(khoj--add-hover-text-to-footnote-refs new-content-start-pos))
|
||||||
(progn (org-mode)
|
(progn
|
||||||
(visual-line-mode))
|
(org-set-startup-visibility)
|
||||||
(read-only-mode t)))
|
(visual-line-mode)
|
||||||
|
(re-search-backward "^\*+ 🦅" nil t))))
|
||||||
|
|
||||||
(defun khoj--query-chat-api (query)
|
(defun khoj--query-chat-api (query)
|
||||||
"Send QUERY to Khoj Chat API."
|
"Send QUERY to Khoj Chat API."
|
||||||
@@ -454,12 +461,12 @@ RECEIVE-DATE is the message receive date."
|
|||||||
(thread-first
|
(thread-first
|
||||||
;; concatenate khoj message and references from API
|
;; concatenate khoj message and references from API
|
||||||
(concat
|
(concat
|
||||||
;; extract khoj message from API response and make it bold
|
|
||||||
message
|
message
|
||||||
;; append reference links to khoj message
|
;; append reference links to khoj message
|
||||||
(string-join footnote-links "")
|
(string-join footnote-links "")
|
||||||
;; append reference sub-section to khoj message and fold it
|
;; append reference sub-section to khoj message and fold it
|
||||||
(if footnote-defs "\n**** References\n:PROPERTIES:\n:VISIBILITY: folded\n:END:" "")
|
(if footnote-defs "\n**** References\n:PROPERTIES:\n:VISIBILITY: folded\n:END:" "")
|
||||||
|
;; append reference definitions to references subsection
|
||||||
(string-join footnote-defs " "))
|
(string-join footnote-defs " "))
|
||||||
;; Render chat message using data obtained from API
|
;; Render chat message using data obtained from API
|
||||||
(khoj--render-chat-message sender receive-date))))
|
(khoj--render-chat-message sender receive-date))))
|
||||||
|
|||||||
Reference in New Issue
Block a user