abo-abo / swiper

Ivy - a generic completion frontend for Emacs, Swiper - isearch with an overview, and more. Oh, man!
https://oremacs.com/swiper/
2.31k stars 338 forks source link

ivy-restrict-to-matches inverse match #2794

Open chaoyi opened 3 years ago

chaoyi commented 3 years ago

Does swiper has functionality to restrict candidates by filtering out matches? Currently I am using swiper-thing-at-point and ivy-restrict-to-matches once or multiple times to search symbols interactively. That maybe could be an alternative to fzf's extended mode.

basil-conto commented 3 years ago

Does swiper has functionality to restrict candidates by filtering out matches?

Yes, by default anything following a ! negates the match, e.g. foo ! bar matches lines that include foo but not bar.

See (info "(ivy) Completion Styles") and its subnodes.

chaoyi commented 3 years ago

Wait, why not foo bar! syntax?

basil-conto commented 3 years ago

Wait, why not foo bar! syntax?

Because the author didn't design it that way, of course. ;) Why would you expect foo bar! to work?

If you want that syntax, I think you'd need to add a custom matcher to ivy-re-builders-alist. One downside of it would be that you presumably have to append ! to every pattern you want to negate, whereas with infix foo ! bar baz you can specify multiple patterns to negate.

chaoyi commented 3 years ago

I wanted to have two keybindings

(map! :map ivy-minibuffer-map
      "C-r" #'ivy-restrict-to-matches
      "C-w" #'ivy-restrict-to-matches-negative)

In this way, I can visualize negative matches while typing.

chaoyi commented 3 years ago

Maybe one keybinding, but if repeated negate to positive

chaoyi commented 3 years ago

I want to add a function called ivy-restrict-to-matches-negate. It acts the same as ivy-restrict-to-matches but for non-matches. It is useful for searching variables.

basil-conto commented 3 years ago

Sorry, I misunderstood; reopening.