Apply trick to insert font-locked strings in a font-locked buffer
This commit is contained in:
parent
3a9964e905
commit
714db74bb0
1 changed files with 18 additions and 1 deletions
19
kagi.el
19
kagi.el
|
@ -257,6 +257,21 @@ https://help.kagi.com/kagi/api/fastgpt.html for more information."
|
||||||
nil)
|
nil)
|
||||||
(buffer-string)))
|
(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 ()
|
(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))
|
||||||
|
@ -402,7 +417,9 @@ object (created with `make-shell-maker-config')."
|
||||||
:execute-command
|
:execute-command
|
||||||
(lambda (command _history callback error-callback)
|
(lambda (command _history callback error-callback)
|
||||||
(condition-case err
|
(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
|
(json-parse-error (funcall error-callback
|
||||||
(format "Could not parse the server response %s" (cdr err))))
|
(format "Could not parse the server response %s" (cdr err))))
|
||||||
(error (funcall error-callback (format "An error occurred during the request %s" (cdr err)))))))
|
(error (funcall error-callback (format "An error occurred during the request %s" (cdr err)))))))
|
||||||
|
|
Loading…
Reference in a new issue