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

Question: Persist search highlights #2064

Closed
pinpox opened this issue May 15, 2019 · 5 comments
Closed

Question: Persist search highlights #2064

pinpox opened this issue May 15, 2019 · 5 comments

Comments

@pinpox
Copy link

@pinpox pinpox commented May 15, 2019

I'll ask here, since I've looked around and coudn't find the solution:

Is it possible to keep all search matches highligted when searching in a buffer with swiper?
I'm using swiper with evil-mode. I also set in my config:

    (setq lazy-highlight-cleanup nil)

The above line works fine for the default isearch but not for swiper. I'd like to replace the default vim-style search (/) in evil-mode with swiper. This means mostly:

  • Persist the search highlights until manually cleared (e.g. with :noh)
  • make the n and N keys work after seaching (next and previous match)

Is this possible?
Thanks for any help!

@abo-abo
Copy link
Owner

@abo-abo abo-abo commented May 16, 2019

Should be easy with a bit of custom code:

(setq lazy-highlight-cleanup nil)

(defun swiper--cleanup ()
  "Clean up the overlays."
  (interactive)
  (when (or lazy-highlight-cleanup
            (called-interactively-p 'any))
    (while swiper--overlays
      (delete-overlay (pop swiper--overlays)))
    (save-excursion
      (goto-char (point-min))
      (isearch-clean-overlays))))

@pinpox
Copy link
Author

@pinpox pinpox commented May 16, 2019

Hi @abo-abo, thanks for the response!
This seems to work partly. The text ist marked in two ways it seems (yellow and blue here), but also some kind of blue selection appear across some lines. It's really hard do discribe, so I made a small video of how it looks.

This is what I do in the clip:

  • I ran first my normal setup with swiper.
  • Search with swiper
  • press 'n' a few times (should go to next match)
  • Run the code you posted above
  • Search again
  • press 'n' a few times (should go to next match)

You can see there is a difference, but something is wrong. I hope you can see what is happening, it's a bit blurry...

EDIT: My emacs config is over here: https://github.com/binaryplease/dotemacs

peek

@abo-abo abo-abo closed this in 773ac65 May 17, 2019
@abo-abo
Copy link
Owner

@abo-abo abo-abo commented May 17, 2019

Thanks, please test.

No custom code is necessary, just set (setq lazy-highlight-cleanup nil). You can use M-x lazy-highlight-cleanup to clean up the overlays manually.

@pinpox
Copy link
Author

@pinpox pinpox commented May 17, 2019

Ok will test it out. I've currently installed ivy via melpa, I guess I need the github-version to test it?

@abo-abo
Copy link
Owner

@abo-abo abo-abo commented May 17, 2019

The github version makes it to MELPA after a few hours. But it's easier to just test the Git clone.

astoff added a commit to astoff/swiper that referenced this issue Jan 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants