Fix %s expansion in prompts defined with define-kagi-fastgpt-prompt
The expansion is done with replace-regexp-in-string, which does a combination of string-match and replace-match. When a function is passed to replace-regexp-in-string instead of a text, it will call kagi--get-text-for-prompt which uses the minibuffer / completing read, possibly messing up the (match-data) along the way that replace-regexp-in-string relies on. Therefore, save the matching data before calling the supplied text function, so it will be restored and replace-regexp-in-string won't notice it.
This commit is contained in:
parent
153ec9a838
commit
002393ad7a
3 changed files with 7 additions and 1 deletions
|
@ -268,6 +268,10 @@ The full changelog can be found in README.org.
|
|||
|
||||
- Show a welcome message when starting the FastGPT shell (=kagi-fastgpt-shell=). This can be customized with =kagi-fastgpt-welcome-function=, a variable with a function that returns a welcome string.
|
||||
|
||||
*** Fixes
|
||||
|
||||
- Prompts defined with =define-kagi-fastgpt-prompt= wouldn't always work when expanding =%s= placeholders (possibly resulting in =Lisp error: (args-out-of-range 0 7)=).
|
||||
|
||||
*** Misc
|
||||
|
||||
- Minor refactoring in the code calling the FastGPT API.
|
||||
|
|
4
kagi.el
4
kagi.el
|
@ -465,7 +465,9 @@ user input."
|
|||
(lambda (match)
|
||||
(pcase match
|
||||
("%%" "%")
|
||||
("%s" (or user-text (setq user-text (funcall text-function))))
|
||||
("%s" (or user-text
|
||||
(setq user-text (save-match-data
|
||||
(funcall text-function)))))
|
||||
(_ match)))
|
||||
prompt t t)))
|
||||
|
||||
|
|
BIN
kagi.info
BIN
kagi.info
Binary file not shown.
Loading…
Reference in a new issue