Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Asynchronous, non-blocking matching #542

Open
wants to merge 41 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
1c2fe90
call a process function from the matcher instead of returning the lines
Feb 28, 2014
0b96bef
the process function needs to be called from other scripts
urandom Feb 28, 2014
63d4f24
python code for filtering in a thread
urandom Mar 2, 2014
9ae4b5a
define the script folder path
urandom Mar 2, 2014
d57e516
add some missing python imports
urandom Mar 2, 2014
7f21c56
use the python matcher
urandom Mar 2, 2014
5cf1993
rename the python class
urandom Mar 2, 2014
4b2611e
add debug logging
urandom Mar 2, 2014
0cf4b0f
refactor the matcher
urandom Mar 2, 2014
fe565d0
do not reset the pymatcher variable
urandom Mar 2, 2014
9077887
correctly set the pattern
urandom Mar 2, 2014
97dc4f1
change the refresh feedkeys
urandom Mar 2, 2014
e494a29
force the update to go through
urandom Mar 3, 2014
2d79500
start showing the items
urandom Mar 3, 2014
6d0dcd6
fix case matching
urandom Mar 4, 2014
1362cc2
set the metadata on process
urandom Mar 4, 2014
2c609b1
create a cursorhold refresh function
urandom Mar 4, 2014
45fabcb
always show the matches in order
urandom Mar 4, 2014
7d2f288
do not process linues if the buffer doesn't exist
urandom Mar 5, 2014
d778be6
clear the sequence if there is no pattern
urandom Mar 5, 2014
fe16d70
make the python interface be the same as the matcher plugin
urandom Mar 5, 2014
64fc444
allow matcher plugins to force the update
urandom Mar 5, 2014
aff18e8
sort the matched items in python for more accuracy
urandom Mar 6, 2014
38a83ff
python module for translating vim regex syntax to python
urandom Mar 7, 2014
c16f1b9
turn on regex support
Mar 7, 2014
66f468c
fix processing of \\
Mar 7, 2014
334fa37
use bindeval to get the corrent type
Mar 7, 2014
1a709b9
correctly force a new cursorhold without changing the cursor
Mar 7, 2014
5028ff4
fix the flag initialization
Mar 7, 2014
b4a1e15
use the correct string when creating a pattern
urandom Mar 7, 2014
ebf2ab7
do not sort if the pymatcher is used
urandom Mar 8, 2014
2f349f9
give priority to mru files
urandom Mar 8, 2014
a98723a
turn off debugging
urandom Mar 8, 2014
43a6278
fix the tag filter
urandom Mar 8, 2014
a77c733
only process the last entry in the done queue
urandom Mar 8, 2014
2ab408f
check for differences in the mode and path
urandom Mar 8, 2014
93aba0f
add more vim atoms
urandom Mar 8, 2014
400494d
use a noop func to force the cursorhold event
urandom Mar 8, 2014
af5bb89
always sort first by filename, for more accurate results
urandom Mar 9, 2014
7471f29
filter by recent files in the project first
urandom Mar 18, 2014
09b3bca
show the mru files for the current project in the initial list first
urandom Mar 18, 2014
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 61 additions & 13 deletions autoload/ctrlp.vim
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,19 @@ let [s:lcmap, s:prtmaps] = ['nn <buffer> <silent>', {
\ 'MarkToOpen()': ['<c-z>'],
\ 'OpenMulti()': ['<c-o>'],
\ 'PrtExit()': ['<esc>', '<c-c>', '<c-g>'],
\ 'PrtNoop()': ['<c-/>'],
\ }]

let s:scriptpath = expand('<sfile>:p:h')
let s:pymatcher = 0
if has('autocmd') && has('python')
py import sys
exe 'python sys.path.insert( 0, "' . escape(s:scriptpath, '\') . '/../python" )'
py from ctrlp.matcher import CtrlPMatcher
py ctrlp = CtrlPMatcher()
let s:pymatcher = 1
en

if !has('gui_running')
cal add(s:prtmaps['PrtBS()'], remove(s:prtmaps['PrtCurLeft()'], 0))
en
Expand Down Expand Up @@ -468,8 +479,8 @@ fu! s:MatchIt(items, pat, limit, exc)
en | cat | brea | endt
if a:limit > 0 && len(lines) >= a:limit | brea | en
endfo
let s:mdata = [s:dyncwd, s:itemtype, s:regexp, s:sublist(a:items, id, -1)]
retu lines

cal ctrlp#process(lines, a:pat, 0, s:sublist(a:items, id, -1))
endf

fu! s:MatchedItems(items, pat, limit)
Expand All @@ -486,13 +497,17 @@ fu! s:MatchedItems(items, pat, limit)
\ 'crfile': exc,
\ 'regex': s:regexp,
\ }] : [items, a:pat, a:limit, s:mmode(), s:ispath, exc, s:regexp]
let lines = call(s:matcher['match'], argms, s:matcher)
call(s:matcher['match'], argms, s:matcher)
elsei s:pymatcher && s:lazy > 1
py <<EOPYTHON
ctrlp.filter(vim.bindeval('items'), vim.bindeval('a:pat'),
vim.bindeval('a:limit'), vim.bindeval('s:mmode()'),
vim.bindeval('s:ispath'), vim.bindeval('exc'),
vim.bindeval('s:regexp'))
EOPYTHON
el
let lines = s:MatchIt(items, a:pat, a:limit, exc)
cal s:MatchIt(items, a:pat, a:limit, exc)
en
let s:matches = len(lines)
unl! s:did_exp
retu lines
endf

fu! s:SplitPattern(str)
Expand Down Expand Up @@ -576,12 +591,21 @@ fu! s:Update(str)
" Get the new string sans tail
let str = s:sanstail(a:str)
" Stop if the string's unchanged
if str == oldstr && !empty(str) && !exists('s:force') | retu | en
if str == oldstr && !empty(str) && !exists('s:force')
\ && (!has_key(s:matcher, 'force_update') || s:matcher['force_update'] == 1)
\ && (!s:pymatcher || s:lazy < 2)
retu
en
let s:martcs = &scs && str =~ '\u' ? '\C' : ''
let pat = s:matcher == {} ? s:SplitPattern(str) : str
let lines = s:nolim == 1 && empty(str) ? copy(g:ctrlp_lines)
\ : s:MatchedItems(g:ctrlp_lines, pat, s:mw_res)
cal s:Render(lines, pat)
let pat = str
if s:matcher == {} && (!s:pymatcher || s:lazy < 2)
let pat = s:SplitPattern(str)
en

if s:nolim == 1 && empty(str)
cal s:Render(copy(g:ctrlp_lines), pat)
else
cal s:MatchedItems(g:ctrlp_lines, pat, s:mw_res)
endf

fu! s:ForceUpdate()
Expand Down Expand Up @@ -835,6 +859,9 @@ fu! s:PrtExit()
en
endf

fu! s:PrtNoop()
endf

fu! s:PrtHistory(...)
if !s:focus || !s:maxhst | retu | en
let [str, hst, s:matches] = [join(s:prompt, ''), s:hstry, 1]
Expand Down Expand Up @@ -1906,7 +1933,8 @@ fu! s:modevar()
endf

fu! s:nosort()
retu s:matcher != {} || s:nolim == 1 || ( s:itemtype == 2 && s:mrudef )
retu s:matcher != {} || (s:pymatcher && s:lazy > 1)
\ || s:nolim == 1 || ( s:itemtype == 2 && s:mrudef )
\ || ( s:itemtype =~ '\v^(1|2)$' && s:prompt == ['', '', ''] ) || !s:dosort
endf

Expand Down Expand Up @@ -2262,6 +2290,26 @@ fu! ctrlp#init(type, ...)
cal s:BuildPrompt(1)
if s:keyloop | cal s:KeyLoop() | en
endf

fu! ctrlp#process(lines, pat, split, subitems)
if !exists('s:init') | retu | en

let s:matches = len(a:lines)
unl! s:did_exp

let pat = a:pat

if a:split | let pat = s:SplitPattern(pat) | en

let s:mdata = [s:dyncwd, s:itemtype, s:regexp, a:subitems]

cal s:Render(a:lines, pat)
endf

fu! ctrlp#forcecursorhold()
cal feedkeys("\<c-/>")
endf

" - Autocmds {{{1
if has('autocmd')
aug CtrlPAug
Expand Down
Empty file added python/ctrlp/__init__.py
Empty file.
Loading