diff --git a/kagi.el b/kagi.el index b773884..f84f77b 100644 --- a/kagi.el +++ b/kagi.el @@ -257,6 +257,21 @@ https://help.kagi.com/kagi/api/fastgpt.html for more information." nil) (buffer-string))) +(defun kagi--fontify-using-faces (s) + "Set the fontified property in the string S. + +This is needed to insert a font-locked string (generated by +`kagi--apply-markdown-font-lock') in a font-lock enabled buffer." + ;; Inspired by this answer at Emacs StackExchange: + ;; https://emacs.stackexchange.com/a/5408 + (let ((pos 0) + (next)) + (while (setq next (next-single-property-change pos 'face s)) + (put-text-property pos next 'font-lock-face (get-text-property pos 'face s) s) + (setq pos next)) + (add-text-properties 0 (length s) '(fontified t) s) + s)) + (defun kagi--curl-flags () "Collect flags for a `curl' command to call the Kagi API." (let ((token (cond ((functionp kagi-api-token) (funcall kagi-api-token)) @@ -402,7 +417,9 @@ object (created with `make-shell-maker-config')." :execute-command (lambda (command _history callback error-callback) (condition-case err - (funcall callback (kagi-fastgpt-prompt command) nil) + (funcall callback + (kagi--fontify-using-faces (kagi-fastgpt-prompt command)) + nil) (json-parse-error (funcall error-callback (format "Could not parse the server response %s" (cdr err)))) (error (funcall error-callback (format "An error occurred during the request %s" (cdr err)))))))