Skip to content

gptel-transient: Fix display issues with evil visual selections#1236

Open
real-or-random wants to merge 2 commits intokarthink:masterfrom
real-or-random:202602-evil-visual-env
Open

gptel-transient: Fix display issues with evil visual selections#1236
real-or-random wants to merge 2 commits intokarthink:masterfrom
real-or-random:202602-evil-visual-env

Conversation

@real-or-random
Copy link
Copy Markdown
Contributor

Fixes #909 and a few other issues, e.g., missing "Rewrite r" choices in the transient menu when there's an evil visual selection.

I played around with multiple approaches, but I think this is by far the cleanest fix. First, it kills the problem entirely, i.e., we won't need to change every (use-region-p), (region-beginning), etc. responsible for displaying a transient, which would be very annoying to maintain. Second, this approach is not very hacky because it uses a mechanism offered by transient for setting up an "environment" in which the display code runs.

We'll need transient 0.7.8. I think it's fine to bump it -- the release dates differ just by a few months -- but we can also make the code conditional in the version if you prefer that approach.

I couldn't notice any difference in performance, and performance should anyway be totally fine:

  • The first thing evil-visual-expand-region does is to check if there's a visual selection, i.e., if there's anything to do at all. If not, it returns immediately. (Note that these evil functions are performance-critical in evil-mode itself because they run in the pre/post-command-hook.)
  • The code is skipped if the region is already expanded.
  • The code is skipped entirely if evil-mode is not loaded.

@karthink
Copy link
Copy Markdown
Owner

This looks great, thanks for the PR! I'll merge it soon.

* gptel.el: Bump minimum transient version from 0.7.4 (2024-08-05) to
0.7.8 (2024-11-02).  This will be required for :environment as used in
then next commit.
* README.org: Same.
* NEWS: Mention this change.
* gptel-transient.el (gptel--transient-fix-evil-visual): Add this
transient environment function whose purpose is to ensure that the
region matches the visual selection in evil-mode before calling
transient display code (karthink#909).  This relies on a feature present in
transient>=0.7.8, see:
magit/transient@05c011b
* gptel-transient.el (gptel-menu): Use gptel--transient-fix-evil-visual
as :environment.
* gptel-rewrite.el (gptel-rewrite): Use gptel--transient-fix-evil-visual
as :environment.
@real-or-random
Copy link
Copy Markdown
Contributor Author

Force-pushed to fix a typo in the docstring and to rebase on master

@real-or-random
Copy link
Copy Markdown
Contributor Author

@karthink Friendly ping.

This looks great, thanks for the PR! I'll merge it soon.

As I said in my last comment in #1235, this PR here is independent of #1235 and should be merged in any case. And then we can see what to do with #1235.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

When using evil mode, "Send selection" goes away in transient menu on any menu choices

2 participants