From 9eb14b99fde37af16903e160e886bb54b49769dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Per-Jonny=20K=C3=A4ck?= Date: Sun, 30 Oct 2016 21:09:34 +0100 Subject: [PATCH 1/2] Pass 'nosort' parameter to external match function Plugins can disable sorting by setting 'sort' option to 0. Ctrlp can disable sorting internally, e.g. for the mru list. Pass this information to external match function. --- autoload/ctrlp.vim | 13 +++++++++---- doc/ctrlp.txt | 3 +++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/autoload/ctrlp.vim b/autoload/ctrlp.vim index 4905c230..0dea82b4 100644 --- a/autoload/ctrlp.vim +++ b/autoload/ctrlp.vim @@ -579,7 +579,8 @@ fu! s:MatchedItems(items, pat, limit) \ 'ispath': s:ispath, \ 'crfile': exc, \ 'regex': s:regexp, - \ }] : [items, a:pat, a:limit, s:mmode(), s:ispath, exc, s:regexp] + \ 'nosort': s:matchernosort(), + \ }] : [items, a:pat, a:limit, s:mmode(), s:ispath, exc, s:regexp, s:matchernosort()] let lines = call(s:matcher['match'], argms, s:matcher) el let lines = s:MatchIt(items, a:pat, a:limit, exc) @@ -640,7 +641,7 @@ fu! s:Render(lines, pat) en let s:matched = copy(lines) " Sorting - if !s:nosort() + if !s:rendernosort() let s:compat = s:martcs.pat cal sort(lines, 's:mixedsort') unl s:compat @@ -2170,12 +2171,16 @@ fu! s:modevar() let s:spi = !s:itemtype || s:getextvar('specinput') > 0 endf -fu! s:nosort() +fu! s:matchernosort() let ct = s:curtype() - retu s:matcher != {} || s:nolim == 1 || ( ct == 'mru' && s:mrudef ) + retu ( ct == 'mru' && s:mrudef ) \ || ( ct =~ '^\(buf\|mru\)$' && s:prompt == ['', '', ''] ) || !s:dosort endf +fu! s:rendernosort() + retu s:matcher != {} || s:nolim == 1 || s:matchernosort() +endf + fu! s:byfname() retu s:curtype() != 'buf' && s:ispath && s:byfname endf diff --git a/doc/ctrlp.txt b/doc/ctrlp.txt index 416fd000..724f3ab0 100644 --- a/doc/ctrlp.txt +++ b/doc/ctrlp.txt @@ -818,6 +818,9 @@ Structure of the function: > " | results when a:ispath == 1. " | " +- a:regex : In regex mode: 1 or 0. + " | + " +- a:nosort : No sort: 1 or 0. Sorting may be disabled for some plugins. + " | Match function should keep item order when a:nosort == 1. return list_of_matched_items endfunction From adfc2fcba2cf599dca3c0f9a1ec3ef142a1dd34b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Per-Jonny=20K=C3=A4ck?= Date: Sun, 26 Jan 2020 21:04:09 +0100 Subject: [PATCH 2/2] Don't pass nosort when calling matcher with a list The extra argument breaks backwards compatibility with other matchers. Only pass nosort when matcher function is called with a dictionary. --- autoload/ctrlp.vim | 2 +- doc/ctrlp.txt | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/autoload/ctrlp.vim b/autoload/ctrlp.vim index 934f70b6..1d593d72 100644 --- a/autoload/ctrlp.vim +++ b/autoload/ctrlp.vim @@ -580,7 +580,7 @@ fu! s:MatchedItems(items, pat, limit) \ 'crfile': exc, \ 'regex': s:regexp, \ 'nosort': s:matchernosort(), - \ }] : [items, a:pat, a:limit, s:mmode(), s:ispath, exc, s:regexp, s:matchernosort()] + \ }] : [items, a:pat, a:limit, s:mmode(), s:ispath, exc, s:regexp] let lines = call(s:matcher['match'], argms, s:matcher) el let lines = s:MatchIt(items, a:pat, a:limit, exc) diff --git a/doc/ctrlp.txt b/doc/ctrlp.txt index bc8abb80..b6312df5 100644 --- a/doc/ctrlp.txt +++ b/doc/ctrlp.txt @@ -822,6 +822,9 @@ Structure of the function: > " | " +- a:nosort : No sort: 1 or 0. Sorting may be disabled for some plugins. " | Match function should keep item order when a:nosort == 1. + " | Only available when function is called with a dictionary, + " | see note below. + return list_of_matched_items endfunction