branch: elpa/gptel
commit 55e51e5e8684df3cda8e83d824afb2658487d26a
Author: Steven Allen <[email protected]>
Commit: Karthik Chikmagalur <[email protected]>
gptel: Fix oneshot setting restoration
* gptel-transient.el (gptel--set-with-scope): When a gptel option
is set in a "oneshot" manner more than once, ensure that the
original value of the option is restored correctly.
For example, When one preset inherits from another and they both
set the same variable, this variable is set multiple times, first
as part of applying the parent preset, then the preset itself. We
want to restore the pre-existing value instead of the parent
preset's value.
---
gptel-transient.el | 23 ++++++++++++-----------
1 file changed, 12 insertions(+), 11 deletions(-)
diff --git a/gptel-transient.el b/gptel-transient.el
index a4f69af612..10209f90f2 100644
--- a/gptel-transient.el
+++ b/gptel-transient.el
@@ -59,17 +59,18 @@ If SCOPE is 1, reset it after the next gptel request.
(oneshot)
Otherwise, clear any buffer-local value and set its default
global value."
(pcase scope
- (1 (put sym 'gptel-history (symbol-value sym))
- (set sym value)
- (letrec ((restore-value
- (lambda ()
- (remove-hook 'gptel-post-request-hook restore-value)
- (run-at-time ; Required to work around let bindings
- 0 nil (lambda (s) ; otherwise this change is
overwritten!
- (set s (get s 'gptel-history))
- (put s 'gptel-history nil))
- sym))))
- (add-hook 'gptel-post-request-hook restore-value)))
+ (1 (unless (get sym 'gptel-history)
+ (put sym 'gptel-history (symbol-value sym))
+ (letrec ((restore-value
+ (lambda ()
+ (remove-hook 'gptel-post-request-hook restore-value)
+ (run-at-time ; Required to work around let
bindings
+ 0 nil (lambda (s) ; otherwise this change is
overwritten!
+ (set s (get s 'gptel-history))
+ (put s 'gptel-history nil))
+ sym))))
+ (add-hook 'gptel-post-request-hook restore-value)))
+ (set sym value))
('t (set (make-local-variable sym) value))
(_ (kill-local-variable sym)
(set sym value))))