branch: elpa/gptel
commit cd6d90b24d1f43b796ec09887a93d4c31fc060d5
Author: Karthik Chikmagalur <[email protected]>
Commit: Karthik Chikmagalur <[email protected]>

    gptel-transient: Improve "send in existing/new session" option
    
    gptel-transient.el (gptel-send-menu, gptel--suffix-send-existing,
    gptel--suffix-send-new, gptel--infix-model): Make menu keybindings
    more uniform and improve descriptions. Suffixes to send queries in
    existing/new sessions will now automatically send them instead of
    just yanking the text into these sessions.
---
 gptel-transient.el | 16 ++++++++++------
 gptel.el           |  3 ++-
 2 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/gptel-transient.el b/gptel-transient.el
index 1a05a12b15..a2b39d99f9 100644
--- a/gptel-transient.el
+++ b/gptel-transient.el
@@ -37,7 +37,7 @@
                     (truncate-string-to-width
                      gptel--system-message (max (- (window-width) 14) 20) nil 
nil t)))
       ("h" "Set directives for chat" gptel-system-prompt)]
-     [["Parameters"
+     [["Session Parameters"
        (gptel--infix-max-tokens)
        (gptel--infix-num-messages-to-send)
        (gptel--infix-temperature)
@@ -147,7 +147,7 @@ will get progressively longer!"
   :description "GPT Model: "
   :class 'transient-lisp-variable
   :variable 'gptel--model
-  :key "M"
+  :key "m"
   :choices '("gpt-3.5-turbo-0301" "gpt-3.5-turbo")
   :reader (lambda (prompt &rest _)
             (completing-read
@@ -166,7 +166,7 @@ will get progressively longer!"
 
 (transient-define-suffix gptel--suffix-send-existing ()
   "Send query in existing chat session."
-  :if (lambda () (use-region-p))
+  :if #'use-region-p
   :key "E"
   :description "Send in existing session"
   (interactive)
@@ -181,15 +181,19 @@ will get progressively longer!"
     (with-current-buffer buf
       (goto-char (point-max))
       (insert prompt)
-      (pop-to-buffer buf))))
+      (gptel-send))
+    (pop-to-buffer buf)))
 
 (transient-define-suffix gptel--suffix-send-new ()
   "Send query in new session."
-  :if (lambda () (use-region-p))
+  :if #'use-region-p
   :description "Send in new session"
   :key "N"
   (interactive)
-  (let ((current-prefix-arg t)) (call-interactively #'gptel)))
+  (let* ((current-prefix-arg t)
+         (buf (call-interactively #'gptel)))
+    (and (bufferp buf)
+         (with-current-buffer buf (gptel-send)))))
 
 (transient-define-suffix gptel--suffix-system-message ()
   "Set directives sent to ChatGPT."
diff --git a/gptel.el b/gptel.el
index b90bf54ff1..ca6f18fcb6 100644
--- a/gptel.el
+++ b/gptel.el
@@ -315,7 +315,8 @@ With a prefix arg, query for a (new) session name.
 
 Ask for API-KEY if `gptel-api-key' is unset.
 
-If region is active, use it as the INITIAL prompt."
+If region is active, use it as the INITIAL prompt. Returns the
+buffer created or switched to."
   (interactive (list (if current-prefix-arg
                          (read-string "Session name: " 
(generate-new-buffer-name gptel-default-session))
                        gptel-default-session)

Reply via email to