Mercurial > dotfiles
changeset 263:230cd2fc2e29
Moved CtrlP auto-ignore extension to a stand-alone plugin.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Sat, 24 Jan 2015 13:28:21 -0800 |
parents | 6c1ae937ad66 |
children | 85ba8a78b216 |
files | .hgsub .hgsubstate vim/autoload/ctrlp/autoignore.vim vim/autoload/ctrlp/projectjump.vim |
diffstat | 4 files changed, 4 insertions(+), 198 deletions(-) [+] |
line wrap: on
line diff
--- a/.hgsub Thu Jan 22 08:38:57 2015 -0800 +++ b/.hgsub Sat Jan 24 13:28:21 2015 -0800 @@ -27,6 +27,7 @@ vim/bundle/interestingwords = [git]https://github.com/vasconcelloslf/vim-interestingwords.git vim/bundle/jinja = [git]https://github.com/mitsuhiko/vim-jinja.git +vim/bundle/ctrlp-autoignore = https://bitbucket.org/ludovicchabant/vim-ctrlp-autoignore vim/bundle/gutentags = https://bitbucket.org/ludovicchabant/vim-gutentags vim/bundle/lawrencium = https://bitbucket.org/ludovicchabant/vim-lawrencium vim/bundle/piecrust = https://bitbucket.org/ludovicchabant/vim-piecrust
--- a/.hgsubstate Thu Jan 22 08:38:57 2015 -0800 +++ b/.hgsubstate Sat Jan 24 13:28:21 2015 -0800 @@ -9,14 +9,15 @@ 81c6dd7ce3169e5ad9ba92422ba6e1ce5b074e36 vim/bundle/colorschemes 9c685131a5facfa0d643feca3a61b41c007d8170 vim/bundle/commentary 5d2aa8522dfd73a699b77128a310535d9d462061 vim/bundle/ctrlp +0b311aa53a49be0c74aa784274a70441dd40b2e7 vim/bundle/ctrlp-autoignore 9ceebf91fc137644cf0693561a386ef4071dbf87 vim/bundle/easymotion 2c8461db084d205903a792a23163faa546f143c9 vim/bundle/fugitive eb9fc8676b8959c3c2c95bf6b6e8f0f44317c5c0 vim/bundle/gundo -c9dfccf3c2f762f5f1f2b86320f2fd0258998ed0 vim/bundle/gutentags +8b3c611a4d3b0f9ea62091925cc9b8137ddd5054 vim/bundle/gutentags 204e32721154766e03e99ff857bc798aa5b741dc vim/bundle/haml 6e0ac033107bd12c1390cbdf49398393930f3fb6 vim/bundle/interestingwords 8a8f0ed97c1751d304cf5b7241f2fe27b0e61f81 vim/bundle/jinja -53a2c9403ba8e8d7f5229eead2e6933ab04c70d1 vim/bundle/lawrencium +7da11e02977391513169d166f5ebbe9c1d030627 vim/bundle/lawrencium 940a8defa0576385dee1ad177bab0b34738540aa vim/bundle/less b69e54f4bf0a0ee26f6582ee8764b25529610c88 vim/bundle/linediff 409c37b205afa2f9d590e23de8171482d66770e2 vim/bundle/markdown
--- a/vim/autoload/ctrlp/autoignore.vim Thu Jan 22 08:38:57 2015 -0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,108 +0,0 @@ -" ============================================================================= -" File: autoload/ctrlp/autoignore.vim -" Description: Auto-ignore Extension -" Author: Ludovic Chabant <github.com/ludovicchabant> -" ============================================================================= - - -" Global Settings {{{ - -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 - -if exists('g:ctrlp_autoignore_loaded') && g:ctrlp_autoignore_loaded - \ && !g:ctrlp_autoignore_debug - finish -endif -let g:ctrlp_autoignore_loaded = 1 - -" }}} - -" 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' - -" }}} - -" 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_patterns = [] - -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:patterns = [] - let l:lines = readfile(l:ign_path) - for line in l:lines - if match(line, '\v^\s*$') >= 0 || match(line, '\v^\s*#') >= 0 - continue - endif - 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, {'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:patterns = get(s:proj_cache, a:root_dir) - if type(l:patterns) == type([]) - return l:patterns - 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] = 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 - for pat in s:active_patterns - if pat['type'] == '' || pat['type'] == a:type - if match(a:item, pat['pat']) >= 0 - return 1 - endif - endif - endfor - return 0 -endfunction - -function! ctrlp#autoignore#ignore_init() abort - let l:root = getcwd() - let s:active_patterns = s:get_project_patterns(l:root) -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 - -" }}} -
--- a/vim/autoload/ctrlp/projectjump.vim Thu Jan 22 08:38:57 2015 -0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,88 +0,0 @@ -" ============================================================================= -" File: autoload/ctrlp/projectjump.vim -" Description: Project Jumper Extension -" Author: Ludovic Chabant <github.com/ludovicchabant> -" ============================================================================= - - -" Global Settings {{{ - -if !exists('g:ctrlp_projectjump_debug') - let g:ctrlp_projectjump_debug = 0 -endif - -if !exists('g:ctrlp_projectjump_trace') - let g:ctrlp_projectjump_trace = 0 -endif - -if exists('g:ctrlp_projectjump_loaded') && g:ctrlp_projectjump_loaded - \ && !g:ctrlp_projectjump_debug - finish -endif -let g:ctrlp_projectjump_loaded = 1 - -if !exists('g:ctrlp_projectjump_roots') - let g:ctrlp_projectjump_roots = [] -endif - -" }}} - -" Init {{{ - -if !exists('g:ctrlp_ext_vars') - let g:ctrlp_ext_vars = [] -endif -call add(g:ctrlp_ext_vars, { - \ 'init': 'ctrlp#projectjump#init()', - \ 'exit': 'ctrlp#projectjump#exit()', - \ 'accept': 'ctrlp#projectjump#accept', - \ 'lname': 'projectjump', - \ 'sname': 'prjmp', - \ 'type': 'project' - \ }) -let s:ext_id = g:ctrlp_builtins + len(g:ctrlp_ext_vars) - -command! CtrlPProjectJump call ctrlp#init(s:ext_id) - -" }}} - -" Callbacks {{{ - -function! ctrlp#projectjump#init() abort - let l:project_roots = [] - for prj in g:ctrlp_projectjump_roots - let l:prj_type = get(prj, 'type', 'project') - if l:prj_type == 'project' - call add(l:project_roots, prj['path']) - elseif l:prj_type == 'parent' - let l:subdirs = glob(prj['path'], 0, 1) - for sd in l:subdirs - call add(l:project_roots, sd) - endfor - else - echoerr "CtrlPProjectJump: Unsupported project root type: ".l:prj_type - endif - endfor - return l:project_roots -endfunction - -function! ctrlp#projectjump#accept(mode, str) abort - call ctrlp#exit() - call ctrlp#init(0, {'dir': a:str}) -endfunction - -function! ctrlp#projectjump#exit() abort -endfunction - -" }}} - -" Internals {{{ - -function! s:trace(message) abort - if g:ctrlp_projectjump_trace - echom "ctrlp_projectjump: " . a:message - endif -endfunction - -" }}} -