-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
https://github.com/ctrlpvim/ctrlp.vim commit 43cc73b8e7d4ab45f17118573eb81fd45704b989 Signed-off-by: lilei (Cloud) <[email protected]>
- Loading branch information
lilei (Cloud)
authored and
lilei (Cloud)
committed
Sep 7, 2018
1 parent
7494e5c
commit 9159b4c
Showing
20 changed files
with
7,807 additions
and
5 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,173 @@ | ||
" ============================================================================= | ||
" File: autoload/ctrlp/autoignore.vim | ||
" Description: Auto-ignore Extension | ||
" Author: Ludovic Chabant <github.com/ludovicchabant> | ||
" ============================================================================= | ||
|
||
|
||
" Global Settings {{{ | ||
|
||
if exists('g:ctrlp_autoignore_loaded') && g:ctrlp_autoignore_loaded | ||
\ && !g:ctrlp_autoignore_debug | ||
finish | ||
endif | ||
let g:ctrlp_autoignore_loaded = 1 | ||
|
||
if !exists('g:ctrlp_autoignore_debug') | ||
let g:ctrlp_autoignore_debug = 0 | ||
endif | ||
|
||
if !exists('g:ctrlp_autoignore_trace') | ||
let g:ctrlp_autoignore_trace = 0 | ||
endif | ||
|
||
" }}} | ||
|
||
" Initialization {{{ | ||
|
||
if !exists('g:ctrlp_custom_ignore') | ||
let g:ctrlp_custom_ignore = {} | ||
endif | ||
let g:ctrlp_custom_ignore['func'] = 'ctrlp#autoignore#ignore' | ||
let g:ctrlp_custom_ignore['func-init'] = 'ctrlp#autoignore#ignore_init' | ||
let g:ctrlp_custom_ignore['func-close'] = 'ctrlp#autoignore#ignore_close' | ||
|
||
if !exists('g:ctrlp_root_markers') | ||
let g:ctrlp_root_markers = [] | ||
endif | ||
call add(g:ctrlp_root_markers, '.ctrlpignore') | ||
|
||
" }}} | ||
|
||
" Internals {{{ | ||
|
||
function! s:trace(message) abort | ||
if g:ctrlp_autoignore_trace | ||
echom "ctrlp_autoignore: " . a:message | ||
endif | ||
endfunction | ||
|
||
let s:proj_cache = {} | ||
let s:active_cwd = '' | ||
let s:active_cwd_len = 0 | ||
let s:active_patterns = [] | ||
let s:changed_wildignore = 0 | ||
let s:prev_wildignore = '' | ||
|
||
function! s:load_project_patterns(root_dir) abort | ||
let l:ign_path = a:root_dir . '/.ctrlpignore' | ||
if !filereadable(l:ign_path) | ||
call s:trace("No pattern file at: " . l:ign_path) | ||
return [] | ||
endif | ||
let l:cursyntax = 'regexp' | ||
let l:knownsyntaxes = ['regexp', 'wildignore'] | ||
let l:patterns = [] | ||
let l:lines = readfile(l:ign_path) | ||
for line in l:lines | ||
" Comment line? | ||
if match(line, '\v^\s*$') >= 0 || match(line, '\v^\s*#') >= 0 | ||
continue | ||
endif | ||
" Syntax change? | ||
let l:matches = matchlist(line, '\v^syntax:\s?(\w+)\s*$') | ||
if len(l:matches) > 0 | ||
let l:cursyntax = l:matches[1] | ||
if index(l:knownsyntaxes, l:cursyntax) < 0 | ||
echoerr "ctrlp_autoignore: Unknown syntax '".l:cursyntax."' in: ".l:ign_path | ||
endif | ||
continue | ||
endif | ||
" Patterns! | ||
let l:matches = matchlist(line, '\v^((dir|file|link)\:)?(.*)') | ||
let l:mtype = l:matches[2] | ||
let l:mpat = l:matches[3] | ||
call add(l:patterns, {'syn': l:cursyntax, 'type': l:mtype, 'pat': l:mpat}) | ||
endfor | ||
call s:trace("Loaded " . len(l:patterns) . " patterns from: " . l:ign_path) | ||
return l:patterns | ||
endfunction | ||
|
||
function! s:get_project_patterns(root_dir) abort | ||
let l:ign_path = a:root_dir . '/.ctrlpignore' | ||
let l:ign_mtime = getftime(l:ign_path) | ||
let l:patterns = get(s:proj_cache, a:root_dir) | ||
if type(l:patterns) == type({}) | ||
" Check that these patterns are still valid. | ||
if l:ign_mtime < 0 | ||
" File got deleted! :( | ||
let l:patterns['pats'] = [] | ||
return l:patterns['pats'] | ||
elseif l:ign_mtime <= l:patterns['mtime'] | ||
" File hasn't changed! :) | ||
return l:patterns['pats'] | ||
endif | ||
endif | ||
|
||
call s:trace("Loading patterns for project: " . a:root_dir) | ||
let l:loaded = s:load_project_patterns(a:root_dir) | ||
let s:proj_cache[a:root_dir] = { | ||
\'mtime': localtime(), | ||
\'pats': l:loaded} | ||
return l:loaded | ||
endfunction | ||
|
||
" The custom ignore function that CtrlP will be using in addition to | ||
" normal pattern-based matching. | ||
function! ctrlp#autoignore#ignore(item, type) abort | ||
let l:cnv_item = tr(strpart(a:item, s:active_cwd_len), "\\", "/") | ||
for pat in s:active_patterns | ||
if pat['syn'] != 'regexp' | ||
continue | ||
endif | ||
if pat['type'] == '' || pat['type'] == a:type | ||
if match(l:cnv_item, pat['pat']) >= 0 | ||
call s:trace("Ignoring ".l:cnv_item." because of ".pat['pat']) | ||
return 1 | ||
endif | ||
endif | ||
endfor | ||
return 0 | ||
endfunction | ||
|
||
function! ctrlp#autoignore#ignore_init() abort | ||
let l:root = getcwd() | ||
let s:active_cwd = l:root | ||
" len+1 is for including the next separator after the root. | ||
let s:active_cwd_len = len(l:root) + 1 | ||
let s:active_patterns = s:get_project_patterns(l:root) | ||
call s:trace("Got ".len(s:active_patterns)." patterns for ".l:root) | ||
|
||
let s:changed_wildignore = 0 | ||
let s:prev_wildignore = &wildignore | ||
for pat in s:active_patterns | ||
if pat['syn'] == 'wildignore' | ||
execute 'set wildignore+='.pat['pat'] | ||
let s:changed_wildignore = 1 | ||
endif | ||
endfor | ||
if s:changed_wildignore | ||
call s:trace("Set wildignore to ".&wildignore) | ||
endif | ||
endfunction | ||
|
||
function! ctrlp#autoignore#ignore_close() abort | ||
if s:changed_wildignore | ||
execute 'set wildignore='.s:prev_wildignore | ||
let s:prev_wildignore = '' | ||
call s:trace("Set wildignore back to ".&wildignore) | ||
endif | ||
endfunction | ||
|
||
" List patterns for a given project's root. | ||
function! ctrlp#autoignore#get_patterns(root_dir) abort | ||
let l:patterns = s:get_project_patterns(a:root_dir) | ||
for pat in l:patterns | ||
let l:prefix = pat['type'] == '' ? '(all)' : pat['type'] | ||
echom l:prefix . ':' . pat['pat'] | ||
endfor | ||
endfunction | ||
|
||
" }}} | ||
|
||
" vim:fen:fdm=marker:fmr={{{,}}}:fdl=0:fdc=1:ts=2:sw=2:sts=2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
" ============================================================================= | ||
" File: autoload/ctrlp/bookmarkdir.vim | ||
" Description: Bookmarked directories extension | ||
" Author: Kien Nguyen <github.com/kien> | ||
" ============================================================================= | ||
|
||
" Init {{{1 | ||
if exists('g:loaded_ctrlp_bookmarkdir') && g:loaded_ctrlp_bookmarkdir | ||
fini | ||
en | ||
let g:loaded_ctrlp_bookmarkdir = 1 | ||
|
||
cal add(g:ctrlp_ext_vars, { | ||
\ 'init': 'ctrlp#bookmarkdir#init()', | ||
\ 'accept': 'ctrlp#bookmarkdir#accept', | ||
\ 'lname': 'bookmarked dirs', | ||
\ 'sname': 'bkd', | ||
\ 'type': 'tabs', | ||
\ 'opmul': 1, | ||
\ 'nolim': 1, | ||
\ 'wipe': 'ctrlp#bookmarkdir#remove', | ||
\ }) | ||
|
||
let s:id = g:ctrlp_builtins + len(g:ctrlp_ext_vars) | ||
" Utilities {{{1 | ||
fu! s:getinput(str, ...) | ||
echoh Identifier | ||
cal inputsave() | ||
let input = call('input', a:0 ? [a:str] + a:000 : [a:str]) | ||
cal inputrestore() | ||
echoh None | ||
retu input | ||
endf | ||
|
||
fu! s:cachefile() | ||
if !exists('s:cadir') || !exists('s:cafile') | ||
let s:cadir = ctrlp#utils#cachedir().ctrlp#utils#lash().'bkd' | ||
let s:cafile = s:cadir.ctrlp#utils#lash().'cache.txt' | ||
en | ||
retu s:cafile | ||
endf | ||
|
||
fu! s:writecache(lines) | ||
cal ctrlp#utils#writecache(a:lines, s:cadir, s:cafile) | ||
endf | ||
|
||
fu! s:getbookmarks() | ||
retu ctrlp#utils#readfile(s:cachefile()) | ||
endf | ||
|
||
fu! s:savebookmark(name, cwd) | ||
let cwds = exists('+ssl') ? [tr(a:cwd, '\', '/'), tr(a:cwd, '/', '\')] : [a:cwd] | ||
let entries = filter(s:getbookmarks(), 'index(cwds, s:parts(v:val)[1]) < 0') | ||
cal s:writecache(insert(entries, a:name.' '.a:cwd)) | ||
endf | ||
|
||
fu! s:setentries() | ||
let time = getftime(s:cachefile()) | ||
if !( exists('s:bookmarks') && time == s:bookmarks[0] ) | ||
let s:bookmarks = [time, s:getbookmarks()] | ||
en | ||
endf | ||
|
||
fu! s:parts(str) | ||
let mlist = matchlist(a:str, '\v([^\t]+)\t(.*)$') | ||
retu mlist != [] ? mlist[1:2] : ['', ''] | ||
endf | ||
|
||
fu! s:process(entries, type) | ||
retu map(a:entries, 's:modify(v:val, a:type)') | ||
endf | ||
|
||
fu! s:modify(entry, type) | ||
let [name, dir] = s:parts(a:entry) | ||
let dir = fnamemodify(dir, a:type) | ||
retu name.' '.( dir == '' ? '.' : dir ) | ||
endf | ||
|
||
fu! s:msg(name, cwd) | ||
redr | ||
echoh Identifier | echon 'Bookmarked ' | echoh Constant | ||
echon a:name.' ' | echoh Directory | echon a:cwd | ||
echoh None | ||
endf | ||
|
||
fu! s:syntax() | ||
if !ctrlp#nosy() | ||
cal ctrlp#hicheck('CtrlPBookmark', 'Identifier') | ||
cal ctrlp#hicheck('CtrlPTabExtra', 'Comment') | ||
sy match CtrlPBookmark '^> [^\t]\+' contains=CtrlPLinePre | ||
sy match CtrlPTabExtra '\zs\t.*\ze$' | ||
en | ||
endf | ||
" Public {{{1 | ||
fu! ctrlp#bookmarkdir#init() | ||
cal s:setentries() | ||
cal s:syntax() | ||
retu s:process(copy(s:bookmarks[1]), ':.') | ||
endf | ||
|
||
fu! ctrlp#bookmarkdir#accept(mode, str) | ||
let parts = s:parts(s:modify(a:str, ':p')) | ||
cal call('s:savebookmark', parts) | ||
if a:mode =~ 't\|v\|h' | ||
cal ctrlp#exit() | ||
en | ||
cal ctrlp#setdir(parts[1], a:mode =~ 't\|h' ? 'chd!' : 'lc!') | ||
if a:mode == 'e' | ||
cal ctrlp#switchtype(0) | ||
cal ctrlp#recordhist() | ||
cal ctrlp#prtclear() | ||
en | ||
endf | ||
|
||
fu! ctrlp#bookmarkdir#add(bang, dir, ...) | ||
let ctrlp_tilde_homedir = get(g:, 'ctrlp_tilde_homedir', 0) | ||
let cwd = fnamemodify(getcwd(), ctrlp_tilde_homedir ? ':p:~' : ':p') | ||
let dir = fnamemodify(a:dir, ctrlp_tilde_homedir ? ':p:~' : ':p') | ||
if a:bang == '!' | ||
let cwd = dir != '' ? dir : cwd | ||
let name = a:0 && a:1 != '' ? a:1 : cwd | ||
el | ||
let str = 'Directory to bookmark: ' | ||
let cwd = dir != '' ? dir : s:getinput(str, cwd, 'dir') | ||
if cwd == '' | retu | en | ||
let name = a:0 && a:1 != '' ? a:1 : s:getinput('Bookmark as: ', cwd) | ||
if name == '' | retu | en | ||
en | ||
let name = tr(name, ' ', ' ') | ||
cal s:savebookmark(name, cwd) | ||
cal s:msg(name, cwd) | ||
endf | ||
|
||
fu! ctrlp#bookmarkdir#remove(entries) | ||
cal s:process(a:entries, ':p') | ||
cal s:writecache(a:entries == [] ? [] : | ||
\ filter(s:getbookmarks(), 'index(a:entries, v:val) < 0')) | ||
cal s:setentries() | ||
retu s:process(copy(s:bookmarks[1]), ':.') | ||
endf | ||
|
||
fu! ctrlp#bookmarkdir#id() | ||
retu s:id | ||
endf | ||
"}}} | ||
|
||
" vim:fen:fdm=marker:fmr={{{,}}}:fdl=0:fdc=1:ts=2:sw=2:sts=2 |
Oops, something went wrong.