Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support wgrep in ivy-occur buffers generated from ivy-xref #25

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

jdormit
Copy link

@jdormit jdormit commented Jun 5, 2020

This is a mostly-working implementation for the issue raised in #18.

Ivy has built-in support for
wgrep-mode in ivy-occur
buffers, assuming wgrep is already installed. However, in order for
wgrep to work the occur buffer needs to be in a specific format. This
adds a function that tells Ivy how to format the ivy-xref occur
buffer, allowing wgrep to work.

However, it is currently subtly broken - although the wgrep edits
are successfully applied, entries in the occur buffer that have been
edited can no longer be clicked on. This seems to be because after
wgrep has edited the line, the underlying (candidate . location) list
that ivy-xref-show-xrefs relies on to jump to the occurence is set to
nil. I haven't figured out how to fix this yet...

jdormit added 2 commits June 5, 2020 17:17
Ivy has built-in support for
wgrep-mode (https://github.com/mhayashi1120/Emacs-wgrep) in ivy-occur
buffers, assuming wgrep is already installed. However, in order for
wgrep to work the occur buffer needs to be in a specific format. This
adds a function that tells Ivy how to format the ivy-xref occur
buffer, allowing wgrep to work.

However, it is currently subtly broken - although the wgrep edits
are successfully applied, entries in the occur buffer that have been
edited can no longer be clicked on. This seems to be because after
wgrep has edited the line, the underlying (candidate . location) list
that ivy-xref-show-xrefs relies on to jump to the occurence is set to
nil. I haven't figured out how to fix this yet...
@jdormit
Copy link
Author

jdormit commented Jun 6, 2020

Ok, I've figured out why editing the occur buffer breaks jump-to-occurrence functionality, although I don't have a good fix for it yet.

The problem is in ivy-occur-press: https://github.com/abo-abo/swiper/blob/master/ivy.el#L5099-L5103. Ivy saves the current collection of occurrence candidates, which in our case is an alist of (occurence-text . occurence-location). When you click on a result in the occur buffer, Ivy does an alist-get with the text of the current occurence to find the correct candidate to pass to the action. This works fine as long as the text of the current occurence hasn't changed. But if you've edited the occur buffer via wgrep, the occurence text no longer matches the saved candidate alist, so when Ivy tries to look up the proper candidate it can't find it.

I'm not sure what the best way to resolve this is. I'll keep poking at it though - I feel like I'm very close.

@jdormit
Copy link
Author

jdormit commented Jun 6, 2020

Ok, I figured out how to make it work! I added text properties to the occur buffer so that we don't lose track of the candidate associated with each line even if the line itself gets edited. I think this is ready to merge now. It seems like the Travis build is broken?

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.

1 participant