From 153ec9a8386a094dd5dc24e5f146459b54e8c1e2 Mon Sep 17 00:00:00 2001 From: bram Date: Mon, 22 Jul 2024 17:28:16 +0000 Subject: [PATCH 1/2] Fix minor typo in docstring --- kagi.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kagi.el b/kagi.el index 7b67180..0e98f4a 100644 --- a/kagi.el +++ b/kagi.el @@ -259,7 +259,7 @@ FastGPT with the following prompt: (propertize (format "[%d]" i) 'font-lock-face 'kagi-bold)) (defun kagi--format-references (references) - "Format the REFRENCES as a string. + "Format the REFERENCES as a string. The REFERENCES is a part of the JSON response, see https://help.kagi.com/kagi/api/fastgpt.html for more information." From 002393ad7a7e4ab1bfde39d890e4b7aa106fa2c0 Mon Sep 17 00:00:00 2001 From: Bram Schoenmakers Date: Tue, 23 Jul 2024 21:20:41 +0200 Subject: [PATCH 2/2] 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. --- README.org | 4 ++++ kagi.el | 4 +++- kagi.info | Bin 17382 -> 17747 bytes 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/README.org b/README.org index 07c8915..d6f69db 100644 --- a/README.org +++ b/README.org @@ -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. diff --git a/kagi.el b/kagi.el index 0e98f4a..e39d96f 100644 --- a/kagi.el +++ b/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))) diff --git a/kagi.info b/kagi.info index 7f9725f13b4e29f54ad1038ee828d25239675933..08e0d2a8445a9da1dcabd712a9cd26cd6aa28f4c 100644 GIT binary patch delta 658 zcmYLHzi-n(6qb{eB9{@VtrXgaP(zGJWXHcFRZv?3Awg6j7#K}_Nvs;5xpSIyawLTK zv4C_7u))NHkTNi{umJ-MjL?Cd|A4#1NpCp4_ucotci+4F`$YQjT>AL5v~n#PBg!6? zuAG5c2z5?K7tdFmP}yXtS=GgW6nZ6!{zr8 g{`3X&HtHdQk}jeg*4+i{<0K2Z8OI#WWFLIzKfMRd-v9sr delta 405 zcmX|-Jxjwt7{^IkL_)_v@hwCu(t^WXa+kLbqNx=TO9#I|s7DQIT9f!P2sbJYfKsfoU$Xb6U&dDoBCDUMCs9HZV2l61Yh z%`tVc0-7?daD&qEWq49`jhhtZZ}rWfAL=XJ4LxD$(U4OE!_E9ro&DI zW2@lb9SA}GXF*h;g^S$Pm<4+wRGP|?@HQ!uMUGy_4dGlu^6Yka$`Y{z+okZ?QmcsK SqTL`$gPv$?5!-;7HRlIb;d}Z3