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

Ensure that isearch can see through overlays added by magit-section #3999

Closed
wants to merge 1 commit into from

Conversation

cpitclaudel
Copy link
Contributor

@cpitclaudel cpitclaudel commented Nov 16, 2019

Thanks a lot for all your hard work on magit.

I'd like to be able to use isearch in magit-status buffers. This feature would be useful when splitting a large change into multiple commits, to ensure that I haven't forgotten to commit part of a change.

For example, in the course of working on a feature, I might rename an identifier throughout my project. When I'm done with the rename and the change, I'll use selective staging to create a commit including only the rename. To make sure I include all lines affected by the rename, I currently press TAB on all files in the "Unstaged changes" section, and then use isearch to look for the renamed symbol. If I don't reveal the diffs for all files, isearch can't search through them, it seems.

Based on https://www.gnu.org/software/emacs/manual/html_node/elisp/Invisible-Text.html and looking at how org-mode handles this case (org-mode reveals hidden text when it contains an isearch match), I think the right implementation would be to set a non-nil isearch-open-invisible property on the overlays used to hide diffs in magit-status.

I have done this in this PR.

@cpitclaudel
Copy link
Contributor Author

One thing I haven't figured out, however, is how to make the reveal persistent. After I complete a search that revealed a section, that section is immediately hidden again.

@tarsius
Copy link
Member

tarsius commented Nov 17, 2019

Problems:

  1. Expanded section collapses again after finishing search, as you mentioned.
  2. Some sections that haven't been expanded since last being recreated have not been "painted" yet. Diffs for example are not painted until expanded for performance reasons.
  3. The bodies of some sections are not even inserted until they are expanded. Again for performance reasons.

There's nothing we can do about (3). To address (1) and (2) isearch would have to be taught to call magit-section-show when appropriate. Maybe isearch has a hook for that, but I doubt it. So you would probably have to find the place where isearch considers isearch-open-invisible and then advice/redefine the respective function to do so.

I am not gonna do that myself any time soon and if I do, then I would do so for swiper instead because that's what I use.

@tarsius tarsius added the enhancement New feature or request label Nov 17, 2019
@tarsius
Copy link
Member

tarsius commented Nov 17, 2019

Would you like me to merge this as-is?

@cpitclaudel cpitclaudel force-pushed the cpitclaudel_isearch branch 2 times, most recently from 313f6fe to ef85630 Compare November 17, 2019 18:28
@cpitclaudel
Copy link
Contributor Author

Probably not; 2 should be fixed. I don't want to merge a partly broken feature in.

To address (1) and (2) isearch would have to be taught to call magit-section-show when appropriate. Maybe isearch has a hook for that, but I doubt it.

It's easy to do that, actually:

(defun magit-section-open-invisible (overlay hide)
  "Show or HIDE the section corresponding to OVERLAY."
  (when-let ((section (overlay-get overlay 'magit-section)))
    (if hide (magit-section-hide section) (magit-section-show section))))

… 
(overlay-put o 'magit-section section)
(overlay-put o 'isearch-open-invisible-temporary #'magit-section-open-invisible)

But the issue is that magit-show deletes the overlay instead of just toggling it, which confuses isearch when it tries to re-hide it.

@tarsius tarsius removed the enhancement New feature or request label Nov 18, 2019
@tarsius tarsius force-pushed the master branch 3 times, most recently from d2401a8 to d58d520 Compare September 9, 2020 18:00
@tarsius tarsius closed this in 1a5cc32 Oct 22, 2020
@tarsius
Copy link
Member

tarsius commented Oct 22, 2020

I've just pushed my implementation.

For Isearch this should work already. Swiper users have to wait until abo-abo/swiper#2689 is merged.

@cpitclaudel cpitclaudel deleted the cpitclaudel_isearch branch October 22, 2020 22:26
@cpitclaudel
Copy link
Contributor Author

👏 👍 🙇

@basil-conto
Copy link
Contributor

Swiper users have to wait until abo-abo/swiper#2689 is merged.

Done; I think three weeks was long enough.

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

Successfully merging this pull request may close these issues.

None yet

3 participants