Fix more bad interactions with evil visual#1235
Fix more bad interactions with evil visual#1235real-or-random wants to merge 3 commits intokarthink:masterfrom
Conversation
| ;; Ensure redisplay after applying presets | ||
| :refresh-suffixes t |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
There are actually many calls to
transient-setupor equivalent in specific infixes ofgptel-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.
|
Hm, after taking a step, I'm not convinced anymore that the second and the third commit actually do fix anything. They avoid cases in which we get the region wrong, i.e., the user has created a visual selection, but evil hasn't had a chance to set the region to this selection). All those cases appear when displaying the transient. However, this is not just about wrong info displayed to the user (as in #909) but they actually affect functionality: if the code displaying the transient believes that there's no region, then all the choices related to a region won't even appear (e.g., "r Rewrite" or "-r Add region to context"). The problem now is that the display code gets the region wrong only when called from the post-command-hook or from a timer (1), but not when called directly by the user (2). So the second and the third commit here potentially avoid issues for case 2 but not for case 1. For case 1, we'll anyway need a bit of evil-specific code to solve these issues entirely, even if we get rid of the timers. What does this mean?
|
See #1236. |
* gptel-rewrite.el (gptel--suffix-rewrite): The goal of moving point backward one char is to move the user's cursor, not for us to make edits, so use the window point instead of the buffer point; note that we're inside a (with-current buffer ...). The right window to use is not the selected one, which is a minibuffer or transient window, but the one that was selected previously, i.e., before the minibuffer or transient was opened. This gets us rid of a hack (run-at-time 0 ...) hack. This is a follow up to 7095771 inspired by a discussion on emacs-devel, see: https://lists.gnu.org/archive/html/emacs-devel/2026-02/msg00033.html
* gptel-rewrite.el (gptel--rewrite-read-message): Get rid of the remaining (run-at-time 0 ...) hacks in gptel-rewrite, which fixes more bad interactions with evil-mode. For example, this commit ensures that the region is setup correctly when invoking transient from the "rewrite minibuffer" by pressing M-RET. Without this commit, the "r Rewrite" action may not be available in the resulting transient popup because (use-region-p) is wrongly nil.
Before this commit, functions that apply prefixes when a transient window is open call transient-setup via (run-at-time 0 ...) as some kind of hack to force a redisplay of the entire transient window. This commit replaces this by transient's native :refresh-suffices functionality, which is already used in gptel-tools. This fixes another case where the region is not correctly taken into account when using evil-mode (similar to 7095771). In theory, this commit should make a bit faster after applying presets and a bit slower after pressing keys that don't apply presets. In practice, I'm not able to notice any difference in latency.
38b2a59 to
55de653
Compare
|
|
Sorry, I tried to explain what everything does, but I see that there's a lot of text in this PR, and it's not super clear since also my understanding of things has evolved over time. Let me try to explain again, and more clearly.
They are independent. In terms of fixed user-facing evil-mode issues, #1236 entirely subsumes this one because it addresses the problem at a different layer. My suggestion is to go ahead and merge #1236 if you're fine with the changes there. This should resolve all user-facing issues with evil-mode, so getting #1236 in should be the main priority in this "evil project". Assuming #1236 gets in, all this PR here does is clean up the code by getting rid of the remaining
Each commit in this PR removes one Why does it need
The current code calls However, if we remove the timer and simply call What we want to do here is to refresh the parent. But there does not seem to be an official way of doing this. The only options I could come up with:
Here's my suggestion on how to move forward:
|
Follow up to #1205.
The first commit is a tweak to #1205. The other commits fix additional cases.
I hope this should fix any real functionality problems with evil-mode's visual selection. The remaining issues will then be issues when displaying the transient menu (#909). But let's first fix functionality.