nixprime / cpsm

A CtrlP matcher, specialized for paths.
Apache License 2.0
202 stars 19 forks source link

How to get highlighting back like in original ctrlp? #2

Closed svenstaro closed 9 years ago

svenstaro commented 9 years ago

So the original ctrlp will give me a neat partial highlight during matching. I wonder whether I can somehow get that back? It's useful to see exactly where I'm matching and also it looks neat.

nixprime commented 9 years ago

In principle we can determine the set of matched characters in all of the top results, emit Vim regexes that match them precisely with \zs and \ze, and then matchadd() those regexes to highlight them (like CtrlP does). The tricky part is actually determining the matched bytes; before matching, match items are split into path components and then (optionally) decoded from UTF-8 to Unicode code points as they're used, and these are what are matched on, so we'd have to translate code point and path component position back to byte position to build the regex.

mattn commented 9 years ago

I'm currently working matcher-color on ctrlp.vim

https://github.com/ctrlpvim/ctrlp.vim/tree/matcher-color

could you add new option to add color attribute for g:ctrlp_matcher_func?

let g:ctrlp_match_func = {'match': 'cpsm#CtrlPMatch', 'color': 1}

This highlight text from \zs to \ze.

mattn commented 9 years ago

This color may be changed to highlight. I'm not sure.

nixprime commented 9 years ago

mattn, if I understand what you mean, I don't think the color/highlight attribute you have is enough for the kind of highlighting I'd like, because it only allows a single contiguous match to be highlighted per line; cpsm regularly matches in multiple groups.