Improve rendering search results of plugin content types in khoj.el

Render only the entry from plugin search response instead of raw json
This commit is contained in:
Debanjum Singh Solanky 2023-02-24 16:16:13 -06:00
parent f3f24387ec
commit c2814fce58

View file

@ -244,6 +244,18 @@ Use `which-key` if available, else display simple message in echo area"
;; remove trailing (, ) or SPC from extracted entries string
(replace-regexp-in-string "[\(\) ]$" ""))))
(defun khoj--extract-entries (json-response query)
"Convert JSON-RESPONSE, QUERY from API to text entries."
(thread-last json-response
;; extract and render entries from API response
(mapcar (lambda (args) (format "%s\n\n" (cdr (assoc 'entry args)))))
;; Set query as heading in rendered results buffer
(format "# Query: %s\n\n%s\n" query)
;; remove leading (, ) or SPC from extracted entries string
(replace-regexp-in-string "^[\(\) ]" "")
;; remove trailing (, ) or SPC from extracted entries string
(replace-regexp-in-string "[\(\) ]$" "")))
(defun khoj--buffer-name-to-content-type (buffer-name)
"Infer content type based on BUFFER-NAME."
(let ((enabled-content-types (khoj--get-enabled-content-types))
@ -296,7 +308,7 @@ Use `which-key` if available, else display simple message in echo area"
((equal content-type "markdown") (khoj--extract-entries-as-markdown json-response query))
((equal content-type "ledger") (khoj--extract-entries-as-ledger json-response query))
((equal content-type "image") (khoj--extract-entries-as-images json-response query))
(t (format "%s" json-response))))
(t (khoj--extract-entries json-response query))))
(cond ((equal content-type "org") (progn (org-mode)
(visual-line-mode)))
((equal content-type "markdown") (progn (markdown-mode)