karthink / gptel

A simple LLM client for Emacs
GNU General Public License v3.0
1.06k stars 116 forks source link

[Feature request] Persist transient flags #94

Closed garrett-hopper closed 7 months ago

garrett-hopper commented 11 months ago

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 call gptel-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)

tshu-w commented 11 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:

Screenshot 2023-07-30 at 13 27 41
(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

tshu-w commented 11 months ago

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))))
karthink commented 11 months ago

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:

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.

karthink commented 7 months ago

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.

karthink commented 3 months ago

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))))