Keep chat messages at 1 empty line visible distance in khoj.el

- Clean redundant concat, format string
- Improve variable name to emojified sender
This commit is contained in:
Debanjum Singh Solanky 2023-03-24 21:24:42 +07:00
parent 27217a330d
commit b08745b541

View file

@ -417,14 +417,16 @@ RECEIVE-DATE is the message receive date."
(let ((first-message-line (car (split-string message "\n" t)))
(rest-message-lines (string-join (cdr (split-string message "\n" t)) "\n"))
(heading-level (if (equal sender "you") "**" "***"))
(emojified-by (if (equal sender "you") "🤔 *You*" "🦅 *Khoj*"))
(emojified-sender (if (equal sender "you") "🤔 *You*" "🦅 *Khoj*"))
(suffix-newlines (if (equal sender "khoj") "\n\n" ""))
(received (or receive-date (format-time-string "%F %T"))))
(format "%s %s: %s\n :PROPERTIES:\n :RECEIVED: [%s]\n :END:\n%s\n"
(format "%s %s: %s\n :PROPERTIES:\n :RECEIVED: [%s]\n :END:\n%s\n%s"
heading-level
emojified-by
emojified-sender
first-message-line
received
rest-message-lines)))
rest-message-lines
suffix-newlines)))
(defun khoj--generate-reference (reference)
"Create `org-mode' footnotes with REFERENCE."
@ -447,13 +449,15 @@ RECEIVE-DATE is the message receive date."
(footnote-links (mapcar #'car footnotes))
(footnote-defs (mapcar #'cdr footnotes)))
(thread-first
;; extract khoj message from API response and make it bold
(format "%s" message)
;; append reference links to khoj message
(concat (string-join footnote-links ""))
;; append reference sub-section to khoj message
(concat (if footnote-defs "\n**** References\n:PROPERTIES:\n:VISIBILITY: folded\n:END:" ""))
(concat (string-join footnote-defs " "))
;; concatenate khoj message and references from API
(concat
;; extract khoj message from API response and make it bold
message
;; append reference links to khoj message
(string-join footnote-links "")
;; append reference sub-section to khoj message and fold it
(if footnote-defs "\n**** References\n:PROPERTIES:\n:VISIBILITY: folded\n:END:" "")
(string-join footnote-defs " "))
;; Render chat message using data obtained from API
(khoj--render-chat-message sender receive-date))))