branch: elpa/gptel commit 6486fc36b53c52463dc5706c5bf5338412af5c70 Author: Karthik Chikmagalur <karthikchikmaga...@gmail.com> Commit: Karthik Chikmagalur <karthikchikmaga...@gmail.com>
gptel: Bind symbols to their current values in gptel-with-preset * gptel.el (gptel-with-preset): When applying a preset in `gptel-with-preset', let-bind preset symbols to their current values instead of nil. This fixes the use of forms like (:append "tool_name"), where we want the specified tools to be appended to the current value of `gptel-tools'. (#1005) --- gptel.el | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/gptel.el b/gptel.el index ff3cda305a9..b4d7022d6a4 100644 --- a/gptel.el +++ b/gptel.el @@ -3791,6 +3791,8 @@ PRESET is the name of a preset, or a spec (plist) of the form (car preset) key)))))) (cl-delete-duplicates syms))) +;; This is identical to `cl-progv', only we let-bind symbols SYM from the preset +;; to their current values instead of evaluating the values explicitly. (#1005) (defmacro gptel-with-preset (name &rest body) "Run BODY with gptel preset NAME applied. @@ -3800,9 +3802,14 @@ from a gptel preset applied. NAME is the name of a preset, or a spec (plist) of the form (:KEY1 VAL1 :KEY2 VAL2 ...). It must be quoted." (declare (indent 1)) - `(cl-progv (gptel--preset-syms ,name) nil - (gptel--apply-preset ,name) - ,@body)) + (let ((syms (make-symbol "syms")) + (binds (make-symbol "binds")) + (bodyfun (make-symbol "body"))) + `(let* ((,syms (gptel--preset-syms ,name)) + (,bodyfun (lambda () (gptel--apply-preset ,name) ,@body)) + (,binds nil)) + (while ,syms (push (list (car ,syms) (pop ,syms)) ,binds)) + (eval (list 'let (nreverse ,binds) (list 'funcall (list 'quote ,bodyfun))))))) ;;;; Presets in-buffer UI (defun gptel--transform-apply-preset (_fsm)