From 8a0ba40550595ac850b21b27e002eac794462a6a Mon Sep 17 00:00:00 2001 From: 12425 <1242523@gmail.com> Date: Wed, 17 May 2017 15:48:30 +0800 Subject: [PATCH] Change regex to make g:ctrlp_by_filename work. --- autoload/pymatcher.py | 4 ++-- autoload/pymatcher.vim | 11 ++++++----- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/autoload/pymatcher.py b/autoload/pymatcher.py index 57a2e3c..f166ee0 100644 --- a/autoload/pymatcher.py +++ b/autoload/pymatcher.py @@ -12,13 +12,13 @@ def CtrlPPyMatch(): aregex = int(vim.eval('a:regex')) spath = vim.eval('a:ispath') crfile = vim.eval('a:crfile') + sep = vim.eval('s:sep') if not vim.eval('exists("g:ctrlp_match_current_file")') and ispath and crfile: items.remove(crfile) rez = vim.eval('s:rez') - regex = '' if aregex == 1: regex = astr @@ -29,7 +29,7 @@ def CtrlPPyMatch(): # If the string is longer that one character, append a mismatch # expression to each character (except the last). if len(lowAstr) > 1: - mismatch = ["[^" + c + "]*" for c in escaped[:-1]] + mismatch = ["[^" + sep + c + "]*" for c in escaped[:-1]] regex = ''.join([c for pair in zip(escaped[:-1], mismatch) for c in pair]) # Append the last character in the string to the regex diff --git a/autoload/pymatcher.vim b/autoload/pymatcher.vim index fc5f0ec..113ca1e 100644 --- a/autoload/pymatcher.vim +++ b/autoload/pymatcher.vim @@ -5,6 +5,11 @@ if !has('python') && !has('python3') endif let s:plugin_path = escape(expand(':p:h'), '\') +if has('win32') + let s:sep = '\\' +else + let s:sep = '/' +endif if has('python3') execute 'py3file ' . s:plugin_path . '/pymatcher.py' @@ -31,11 +36,7 @@ function! pymatcher#PyMatch(items, str, limit, mmode, ispath, crfile, regex) let s:matchregex = '\v\c' - if a:mmode == 'filename-only' - let s:matchregex .= '[\^\/]*' - endif - - let s:matchregex .= s:regex + let s:matchregex .= (s:regex . '[^' . s:sep . ']*$') call matchadd('CtrlPMatch', s:matchregex)