From c2814fce58b7c8ecfbae325d03617885d92fca6c Mon Sep 17 00:00:00 2001 From: Debanjum Singh Solanky Date: Fri, 24 Feb 2023 16:16:13 -0600 Subject: [PATCH] Improve rendering search results of plugin content types in khoj.el Render only the entry from plugin search response instead of raw json --- src/interface/emacs/khoj.el | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/interface/emacs/khoj.el b/src/interface/emacs/khoj.el index f6fba071..1b8c8905 100644 --- a/src/interface/emacs/khoj.el +++ b/src/interface/emacs/khoj.el @@ -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)