branch: elpa/gptel commit 10e77396bc78e05c922b04a344818bc8ab72d665 Author: Karthik Chikmagalur <karthikchikmaga...@gmail.com> Commit: Karthik Chikmagalur <karthikchikmaga...@gmail.com>
gptel-transient: Don't serialize backend to transient history * gptel-transient.el (gptel-provider-variable, transient-format-value, transient-infix-set, gptel--infix-provider): Saving the backend struct as the value of `gptel--infix-provider' can serialize it to the Transient history file. This serialized value is not always readable, causing Transient to sometimes throw errors when reading the history file. Since the history file is shared between all Transients, this can cause magit (etc) to not function (#693). `gptel--infix-provider' sets both the model and the backend, but the backend was the value of the infix. Invert this to make the model the value. The model is a symbol and thus reliably serializable. The Transient history file should be much shorter as a result, as well. --- gptel-transient.el | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/gptel-transient.el b/gptel-transient.el index d162246225..e40fcbc5d5 100644 --- a/gptel-transient.el +++ b/gptel-transient.el @@ -497,28 +497,28 @@ This is used only for setting this variable via `gptel-menu'.") (oset obj value value))) (defclass gptel-provider-variable (transient-lisp-variable) - ((model :initarg :model) - (model-value :initarg :model-value) + ((backend :initarg :backend) + (backend-value :initarg :backend-value) (always-read :initform t) (set-value :initarg :set-value :initform #'set)) "Class used for gptel-backends.") (cl-defmethod transient-format-value ((obj gptel-provider-variable)) (propertize (concat - (gptel-backend-name (oref obj value)) ":" - (gptel--model-name - (buffer-local-value (oref obj model) transient--original-buffer))) + (gptel-backend-name + (buffer-local-value (oref obj backend) transient--original-buffer)) ":" + (gptel--model-name (oref obj value))) 'face 'transient-value)) (cl-defmethod transient-infix-set ((obj gptel-provider-variable) value) (pcase-let ((`(,backend-value ,model-value) value)) (funcall (oref obj set-value) (oref obj variable) - (oset obj value backend-value) + (oset obj value model-value) gptel--set-buffer-locally) (funcall (oref obj set-value) - (oref obj model) - (oset obj model-value model-value) + (oref obj backend) + (oset obj backend-value backend-value) gptel--set-buffer-locally)) (transient-setup)) @@ -913,9 +913,9 @@ responses." :description "Model" :class 'gptel-provider-variable :prompt "Model: " - :variable 'gptel-backend + :variable 'gptel-model :set-value #'gptel--set-with-scope - :model 'gptel-model + :backend 'gptel-backend :key "-m" :reader (lambda (prompt &rest _) (cl-loop