Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions gptel-rewrite.el
Original file line number Diff line number Diff line change
Expand Up @@ -284,16 +284,17 @@ input history list."
(start-rewrite-maybe
(lambda () (interactive)
(when (minibufferp) (funcall set-rewrite-message))
(if transient--prefix ;Called from transient? Don't start rewrite
(run-at-time 0 nil #'transient-setup 'gptel-rewrite)
(with-current-buffer cb
(with-current-buffer cb
(if transient--prefix ;Called from transient? Don't start rewrite
(transient-setup 'gptel-rewrite)
(gptel--suffix-rewrite gptel--rewrite-message)))
(when (minibufferp) (exit-minibuffer))))
(start-transient
(lambda () (interactive)
(run-at-time 0 nil #'transient-setup 'gptel-rewrite)
(when (minibufferp) (funcall set-rewrite-message))
(with-current-buffer cb
(transient-setup 'gptel-rewrite))
(when (minibufferp)
(funcall set-rewrite-message)
(exit-minibuffer))))
(edit-in-buffer
(lambda () (interactive)
Expand Down Expand Up @@ -744,9 +745,14 @@ generated from functions."
:transforms gptel-prompt-transform-functions
:fsm (gptel-make-fsm :handlers gptel--rewrite-handlers)
:callback #'gptel--rewrite-callback)
;; Move back so that the cursor is on the overlay when done.
(unless (get-char-property (point) 'gptel-rewrite)
(when (= (point) (region-end)) (run-at-time 0 nil #'backward-char 1)))
;; Move point of original window back so that it's on the overlay when done.
(let* ((window (or (minibuffer-selected-window)
transient--original-window)))
(when (window-live-p window)
(with-selected-window window
(unless (get-char-property (point) 'gptel-rewrite)
(when (= (point) (region-end))
(backward-char 1))))))
(setq deactivate-mark t))))

;; Allow this to be called non-interactively for dry runs
Expand Down
9 changes: 4 additions & 5 deletions gptel-transient.el
Original file line number Diff line number Diff line change
Expand Up @@ -542,8 +542,7 @@ which see."
name (lambda (sym val)
(gptel--set-with-scope sym val gptel--set-buffer-locally)))
(message "Applied gptel preset %s"
(propertize (symbol-name name) 'face 'transient-value))
(when transient--stack (run-at-time 0 nil #'transient-setup)))
(propertize (symbol-name name) 'face 'transient-value)))


;; * Transient classes and methods for gptel
Expand Down Expand Up @@ -778,6 +777,8 @@ Also format the value of OBJ in the transient menu."
(transient-define-prefix gptel-menu ()
"Change parameters of prompt to send to the LLM."
:incompatible '(("m" "y" "i") ("e" "g" "b" "k"))
;; Ensure redisplay after applying presets
:refresh-suffixes t
Comment on lines +780 to +781
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This forces rebuilding the entire transient after every key press.

If you don't like the overhead introduced by this, then an alternative is to call (transient--stack-pop) (transient--env-apply #'transient--refresh-transient)) (still, instead of the (run-at-time ...). This will also refresh the main transient prefix. But it relies on transient internals. Please let me know if you prefer this solution.

Copy link
Copy Markdown
Owner

@karthink karthink Feb 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm aware of :refresh-suffixes and chose to avoid it in gptel-menu because of performance issues. I use it in some other transient menus, like gptel-tools, that have to be fully dynamic to function.

Why do you need to enforce a menu-wide change here?

There are actually many calls to transient-setup or equivalent in specific infixes of gptel-menu, not just the ones on line 548 and 1053 you've removed.

Copy link
Copy Markdown
Contributor Author

@real-or-random real-or-random Feb 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are actually many calls to transient-setup or equivalent in specific infixes of gptel-menu, not just the ones on line 548 and 1053 you've removed.

Indeed. It took me a while to figure out what is special about the calls on lines 548 and 1053 (and why they need a timer): on these lines, the active transient is not gptel-menu but gptel--preset. So when you call transient-setup there without a timer, you refresh gptel--preset but not the parent gptel-menu.

I don't think transient offers an official way to refresh the parent. I tried calling (transient-setup 'gptel-menu) but that didn't work.

If you're concerned about performance, then there are two options:

  • As I said above, (transient--stack-pop) (transient--env-apply #'transient--refresh-transient) does the job at the cost of relying on a transient internal.
  • Or, let's just drop the third commit (and perhaps also the second)
    and keep the timers here. As I wrote below, removing these is not essential.

;; :value (list (concat "b" (buffer-name)))
[:description gptel-system-prompt--format
[""
Expand Down Expand Up @@ -1046,9 +1047,7 @@ together. See `gptel-make-preset' for details."
(lambda (sym val) (gptel--set-with-scope
sym val gptel--set-buffer-locally)))
(message "Applied gptel preset %s"
(propertize ,name 'face 'transient-value))
(when transient--stack
(run-at-time 0 nil #'transient-setup))))
(propertize ,name 'face 'transient-value))))
into generated
finally return
(nconc (list '(gptel--infix-variable-scope
Expand Down