wolray / symbol-overlay

Highlight symbols with keymap-enabled overlays
346 stars 42 forks source link

Hide unmatched lines? #30

Closed clemera closed 6 years ago

clemera commented 6 years ago

Hi, thanks for this great package! Using iedit and multiple-cursor you can toggle hiding unmatched lines which is sometimes useful to get an overview of all matches without having to navigate through the symbols. If you are interested I could try to implement it.

purcell commented 6 years ago

I think that's a bit tangential to symbol-overlay because it's very easy to implement in other ways. For example, here's what I do to address essentially the same use case: https://github.com/purcell/emacs.d/blob/master/lisp/init-ivy.el#L70-L76

clemera commented 6 years ago

Ah, yes! But this only works shows the symbol at point not all marked symbols for example. But I guess that's not to useful after all. Thanks!

purcell commented 6 years ago

But this only works shows the symbol at point not all marked symbols for example.

You could easily make a version of that function that gathered all the marked symbols and made a regexp which matched any of them using the regexp-opt function: then you could pass that regexp to swiper. :-)

clemera commented 6 years ago

The joy of Emacs :) This doesn't use regexp-opt because it was a bit easier to avoid it:

(swiper (mapconcat #'identity (mapcar #'car symbol-overlay-keywords-alist) "\\|"))
purcell commented 6 years ago

This doesn't use regexp-opt because it was a bit easier to avoid it:

Really?

(swiper (regexp-opt (mapcar #'car symbol-overlay-keywords-alist)))
clemera commented 6 years ago

(swiper (regexp-opt (mapcar #'car symbol-overlay-keywords-alist)))

This does not work for me. regex-opt expects no regex so this adds to many backslashes around the symbol regex which have to be removed so swiper can "understand".

purcell commented 6 years ago

Ah yes! I'd forgotten that the alist keys could be regexes. Just ignore me... :-)

clemera commented 5 years ago

No, I'm happy you brought it up! This made me wonder if there is an easy way to remove regex signs from a string. For symbol regexes in Elisp the following works good enough, because Elisp does not use any of the regex signs for its symbols:

(swiper (regexp-opt (mapcar (lambda (el)
                                  (replace-regexp-in-string "[\\<>_]" "" (car el)))
                                      symbol-overlay-keywords-alist)))