diff --git a/NEWS b/NEWS
index 73fb37f8..17edc413 100644
--- a/NEWS
+++ b/NEWS
@@ -3,6 +3,9 @@
* 0.9.9.4
** Breaking changes
+- gptel now requires Transient 0.7.8 or higher. Transient is a built-in package
+ and Emacs does not update it by default. Ensure that
+ =package-install-upgrade-built-in= is non-nil, or update Transient manually.
- The models =gpt-5-codex=, =o3=, =o3-mini=, =o4-mini=,
=claude-3.5-sonnet=, =claude-3.7-sonnet=, =claude-3.7-sonnet-thought=,
diff --git a/README.org b/README.org
index 8d069ab1..5491b216 100644
--- a/README.org
+++ b/README.org
@@ -135,7 +135,7 @@ gptel uses Curl if available, but falls back to the built-in url-retrieve to wor
** Installation
-Note: gptel requires Transient 0.7.4 or higher. Transient is a built-in package and Emacs does not update it by default. Ensure that =package-install-upgrade-built-in= is true, or update Transient manually.
+Note: gptel requires Transient 0.7.8 or higher. Transient is a built-in package and Emacs does not update it by default. Ensure that =package-install-upgrade-built-in= is true, or update Transient manually.
- *Release version*: =M-x package-install= ⏎ =gptel= in Emacs.
- *Development snapshot*: Add MELPA or NonGNU-devel ELPA to your list of package sources, then install with =M-x package-install= ⏎ =gptel=.
@@ -151,7 +151,7 @@ Note: gptel requires Transient 0.7.4 or higher. Transient is a built-in package
#+html:
*** Manual
#+html:
-Note: gptel requires Transient 0.7.4 or higher. Transient is a built-in package and Emacs does not update it by default. Ensure that =package-install-upgrade-built-in= is true, or update Transient manually.
+Note: gptel requires Transient 0.7.8 or higher. Transient is a built-in package and Emacs does not update it by default. Ensure that =package-install-upgrade-built-in= is true, or update Transient manually.
Clone or download this repository and run =M-x package-install-file⏎= on the repository directory.
#+html:
diff --git a/gptel-rewrite.el b/gptel-rewrite.el
index 97ca3da8..6cbbb84e 100644
--- a/gptel-rewrite.el
+++ b/gptel-rewrite.el
@@ -595,6 +595,7 @@ By default, gptel uses the directive associated with the `rewrite'
;;;###autoload (autoload 'gptel-rewrite "gptel-rewrite" nil t)
(transient-define-prefix gptel-rewrite ()
"Rewrite or refactor text region using an LLM."
+ :environment #'gptel--transient-fix-evil-visual
[:description
(lambda ()
(gptel--describe-directive
diff --git a/gptel-transient.el b/gptel-transient.el
index e6c00364..caaea25b 100644
--- a/gptel-transient.el
+++ b/gptel-transient.el
@@ -545,6 +545,29 @@ which see."
(propertize (symbol-name name) 'face 'transient-value))
(when transient--stack (run-at-time 0 nil #'transient-setup)))
+(defun gptel--transient-fix-evil-visual (fn)
+ "Let evil-mode set up the region correctly before displaying a transient.
+
+This is supposed to be used in the `:entry' slot of `transient-define-prefix'.
+
+The transient display code may be called from an entry in `post-command-hook',
+which may happen to run late, i.e., after evil-mode's entry in that hook has
+already teared down the temporary expanding of the region to a possibly existing
+visual selection. This environment will ensure that the region is always
+expanded before calling the transient display code in FN.
+
+If evil-mode is not in use, this function is a no-op and calls FN directly."
+ (if (and (boundp 'evil-visual-region-expanded)
+ (not evil-visual-region-expanded)
+ (fboundp 'evil-visual-expand-region)
+ (fboundp 'evil-visual-contract-region))
+ (progn
+ (evil-visual-expand-region)
+ (funcall fn)
+ (when evil-visual-region-expanded
+ (evil-visual-contract-region)))
+ (funcall fn)))
+
;; * Transient classes and methods for gptel
@@ -778,6 +801,7 @@ 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"))
+ :environment #'gptel--transient-fix-evil-visual
;; :value (list (concat "b" (buffer-name)))
[:description gptel-system-prompt--format
[""
diff --git a/gptel.el b/gptel.el
index 821d9ae0..e6d148b5 100644
--- a/gptel.el
+++ b/gptel.el
@@ -4,7 +4,7 @@
;; Author: Karthik Chikmagalur
;; Version: 0.9.9.4
-;; Package-Requires: ((emacs "27.1") (transient "0.7.4") (compat "30.1.0.0"))
+;; Package-Requires: ((emacs "27.1") (transient "0.7.8") (compat "30.1.0.0"))
;; Keywords: convenience, tools
;; URL: https://github.com/karthink/gptel