nixprime / cpsm

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

Filter buffers by number #34

Closed vimeitor closed 7 years ago

vimeitor commented 7 years ago

Hello!

The default ctrlp matcher allows you to filter the currently opened buffers by the number it assigns. It would be very nice if yours also allowed me to do that.

I like your matcher the best out all I have tried. Thank you for making it =)

nixprime commented 7 years ago

Hello,

Thank you for the kind words! I'm not sure I understand the issue; cpsm should work with the CtrlPBuffer command, although match quality is likely to be suboptimal right now. Can you please clarify?

vimeitor commented 7 years ago

Hi!

Sorry for not explaining properly. cpsm does indeed filter the buffers well; however, at the leftside of the buffer name ctrlp attaches a number which in the default filter you can use to filter it. If I use that number in your filter, it doesn't find any matches. This is what I'm referring to:

image

Writing '3', for example, won't show me any results. I apologize if I'm not explaining properly.

nixprime commented 7 years ago

I spent some time looking into this today, and unfortunately I don't think it's possible for cpsm to handle CtrlPBuffer correctly. The reason is that CtrlP doesn't make its buffer numbers available to third-party matchers; it's special-cased in CtrlP's built-in matcher for CtrlPBuffer: https://github.com/ctrlpvim/ctrlp.vim/blob/master/autoload/ctrlp.vim#L569 => https://github.com/ctrlpvim/ctrlp.vim/blob/master/autoload/ctrlp.vim#L550 => https://github.com/ctrlpvim/ctrlp.vim/blob/master/autoload/ctrlp.vim#L2384.

I'd suggest disabling cpsm before invoking CtrlPBuffer. For example:

" CtrlP: do not overwrite mapping for C-p set below
let g:ctrlp_map = ''

" Ctrl-p invokes CtrlP using cpsm
" Ctrl-o invokes CtrlPMRU without cpsm empty query matching
" Ctrl-i invokes CtrlPBuffer without cpsm
nnoremap <silent> <C-p> :let g:ctrlp_match_func = {'match': 'cpsm#CtrlPMatch'}<CR>:let g:cpsm_match_empty_query = 1<CR>:CtrlP<CR>
nnoremap <silent> <C-o> :let g:ctrlp_match_func = {'match': 'cpsm#CtrlPMatch'}<CR>:let g:cpsm_match_empty_query = 0<CR>:CtrlPMRU<CR>
nnoremap <silent> <C-i> :unlet g:ctrlp_match_func<CR>:CtrlPBuffer<CR>

Apologies for the inconvenience.

vimeitor commented 7 years ago

No apologizes at all, please. Thank you so much for the alternative solution and for taking your time looking at this! I kind of had the feeling that ctrlp did not expose the numbers, so having a solution is great. I'm very grateful, really =)