From c3ca4fd0a05fee2139f7ef1cfe0967ba3e040263 Mon Sep 17 00:00:00 2001 From: Karthik Chikmagalur Date: Mon, 25 Dec 2023 13:58:23 -0800 Subject: [PATCH] gptel-transient: Set suffix-state explicitly for directives * gptel-transient.el (gptel-system-prompt--setup): In Transient v0.5 and up, some suffixes defined dynamically using `gptel-system-prompt--setup' are being treated as infix commands, see #140. Set the `:transient' key of these suffixes to `transient--do-return' explicitly to avoid this problem. TODO: This fix will work but it's not clear why this is needed, this needs some investigation. --- gptel-transient.el | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/gptel-transient.el b/gptel-transient.el index 748ec51..6eecd3e 100644 --- a/gptel-transient.el +++ b/gptel-transient.el @@ -171,17 +171,24 @@ which see." (cl-incf idx)) (push pos taken) pos) + ;; The explicit declaration ":transient transient--do-return" here + ;; appears to be required for Transient v0.5 and up. Without it, these + ;; are treated as suffixes when invoking `gptel-system-prompt' directly, + ;; and infixes when going through `gptel-menu'. + ;; TODO: Raise an issue with Transient. collect (list (key-description key) (capitalize name) `(lambda () (interactive) (message "Directive: %s" ,prompt) - (setq gptel--system-message ,prompt))) + (setq gptel--system-message ,prompt)) + :transient 'transient--do-return) into prompt-suffixes finally return (nconc (list (list 'gptel--suffix-system-message)) prompt-suffixes (list (list "SPC" "Pick crowdsourced prompt" - 'gptel--read-crowdsourced-prompt :transient nil)))))) + 'gptel--read-crowdsourced-prompt + :transient nil)))))) (transient-define-prefix gptel-system-prompt () "Change the system prompt to send ChatGPT.