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)