1
0
Fork 0

Let kagi-fastgpt-prompt return a font-locked string by markdown-mode

This commit is contained in:
Bram Schoenmakers 2024-07-22 19:58:39 +02:00
parent 54bd8466a5
commit 36b4e3782d
Signed by: bram
GPG key ID: 0CCD19DFDC63258F

16
kagi.el
View file

@ -244,6 +244,19 @@ https://help.kagi.com/kagi/api/fastgpt.html for more information."
references) references)
"\n\n")) "\n\n"))
(defun kagi--apply-markdown-font-lock (s)
"Apply Markdown formatting with markdown-mode on string S."
;; Inspired by this answer at Emacs StackExchange:
;; https://emacs.stackexchange.com/a/5408
(with-temp-buffer
(insert s)
(delay-mode-hooks (markdown-mode))
(font-lock-default-function #'markdown-mode)
(font-lock-default-fontify-region (point-min)
(point-max)
nil)
(buffer-string)))
(defun kagi--curl-flags () (defun kagi--curl-flags ()
"Collect flags for a `curl' command to call the Kagi API." "Collect flags for a `curl' command to call the Kagi API."
(let ((token (cond ((functionp kagi-api-token) (funcall kagi-api-token)) (let ((token (cond ((functionp kagi-api-token) (funcall kagi-api-token))
@ -491,7 +504,8 @@ string (suitable for invocations from Emacs Lisp)."
(message result)) (message result))
((and interactive-p (> result-lines 1)) ((and interactive-p (> result-lines 1))
(kagi--fastgpt-display-result result)) (kagi--fastgpt-display-result result))
((not interactive-p) result)))) ((not interactive-p)
(kagi--apply-markdown-font-lock result)))))
(define-kagi-fastgpt-prompt kagi-fastgpt-prompt-definition (define-kagi-fastgpt-prompt kagi-fastgpt-prompt-definition
"Define the following word: %s" "Define the following word: %s"