Closed garrett-hopper closed 7 months ago
Update: a new version without save
(defun gptel-transient-send-last ()
"Call `gptel--suffix-send' with last history."
(interactive)
(let* ((obj (plist-get (symbol-plist 'gptel-menu) 'transient--prefix))
(hst (alist-get (transient--history-key obj)
transient-history))
(args (nth 0 hst)))
(gptel--suffix-send args)))
(gptel-transient-send-last)
Here is a user-side solution, you can run C-x C-s
to save infixes after modification. And call gptel-transient-send
to reuse saved flags:
(defun gptel-transient-send (args)
"Call `gptel--suffix-send' with saved ARGS."
(interactive (list (transient-args 'gptel-menu)))
(gptel--suffix-send args))
(call-interactively 'gptel-transient-send)
If you like, you can advice gptel--suffix-send
to called (transient-save)
at each call.
Ref: https://github.com/positron-solutions/transient-showcase/tree/master
I end up using gptel-transient-send
to replace gptel-send
(defun gptel-transient-send (&optional arg)
"Call `gptel--suffix-send' with latest history."
(interactive "P")
(if (and arg (require 'gptel-transient nil t))
(call-interactively #'gptel-menu)
(let* ((obj (plist-get (symbol-plist 'gptel-menu) 'transient--prefix))
(hst (alist-get (transient--history-key obj)
transient-history))
(args (nth 0 hst)))
(gptel--suffix-send args))))
Here is a user-side solution, you can run
C-x C-s
to save infixes after modification. And callgptel-transient-send
to reuse saved flags:
Wow, thanks for pointing this out! Making Transient flags persistent is a problem best handled by Transient itself. Trying to do it in gptel would be very messy.
I am considering the issue resolved and @tshu-w's method as the solution here. It might be worth adding this to the wiki at some point. @garrett-hopper if you have any specific concerns feel free to re-open.
I've added a section to the wiki with a simple solution, reproduced here:
You can replace your usage of
gptel-send
with the following command if you want these options to be applied without having to bring up the menu:
(put 'gptel--suffix-send 'interactive-only nil)
(defun gptel-send-with-options (&optional arg)
"Send query. With prefix ARG open gptel's menu instead."
(interactive "P")
(if arg
(call-interactively 'gptel-menu)
(gptel--suffix-send (transient-args 'gptel-menu))))
I would like to be able to call
C-u <gptel-send>
to bring up the transient map, update some flags in it, and then from then on only need to callgptel-send
to reuse those flags. (E.g. sending output to minibuffer, reading input from minibuffer (pre-populated with selection), sending to new or existing session)