Add BookmarkDir extension
Literally the only thing I was still using NERDTree for, so figured I'd bring it to CtrlP.
This commit is contained in:
parent
e94a5e78e7
commit
d6e5c56b04
@ -1642,6 +1642,10 @@ fu! ctrlp#hicheck(grp, defgrp)
|
||||
exe 'hi link' a:grp a:defgrp
|
||||
en
|
||||
endf
|
||||
|
||||
fu! ctrlp#call(func, ...)
|
||||
cal call(a:func, a:000)
|
||||
endf
|
||||
"}}}1
|
||||
" * Initialization {{{1
|
||||
fu! ctrlp#setlines(...)
|
||||
|
138
autoload/ctrlp/bookmarkdir.vim
Normal file
138
autoload/ctrlp/bookmarkdir.vim
Normal file
@ -0,0 +1,138 @@
|
||||
" =============================================================================
|
||||
" 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().'bookmark'
|
||||
let s:cafile = s:cadir.ctrlp#utils#lash().'dir.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 entries = filter(s:getbookmarks(), 's:parts(v:val)[1] != a:cwd')
|
||||
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)
|
||||
retu matchlist(a:str, '\v([^\t]+)\t(.*)$')[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)
|
||||
if a:mode =~ 't\|v\|h'
|
||||
cal ctrlp#exit()
|
||||
en
|
||||
let parts = s:parts(s:modify(a:str, ':p'))
|
||||
cal call('s:savebookmark', parts)
|
||||
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(dir)
|
||||
let str = 'Directory to bookmark: '
|
||||
let cwd = a:dir != '' ? a:dir : s:getinput(str, getcwd(), 'dir')
|
||||
if cwd == '' | retu | en
|
||||
let cwd = fnamemodify(cwd, ':p')
|
||||
let name = s:getinput('Bookmark as: ', cwd)
|
||||
if name == '' | retu | 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
|
@ -64,12 +64,14 @@ Overview:~
|
||||
|ctrlp_default_input| Seed the prompt with an initial string.
|
||||
|ctrlp_use_migemo| Use Migemo patterns for Japanese filenames.
|
||||
|ctrlp_prompt_mappings| Change the mappings in the prompt.
|
||||
|
||||
MRU mode:
|
||||
|ctrlp_mruf_max| Max MRU entries to remember.
|
||||
|ctrlp_mruf_exclude| Files that shouldn’t be remembered.
|
||||
|ctrlp_mruf_include| Files to be remembered.
|
||||
|ctrlp_mruf_relative| Show only MRU files in the working directory.
|
||||
|ctrlp_mruf_case_sensitive| MRU files are case sensitive or not.
|
||||
|
||||
Advanced options:
|
||||
|ctrlp_status_func| Change CtrlP’s two statuslines.
|
||||
|ctrlp_buffer_func| Call custom functions in the CtrlP buffer.
|
||||
@ -763,7 +765,7 @@ EXTENSIONS *ctrlp-extensions*
|
||||
Extensions are optional. To enable an extension, add its name to the variable
|
||||
g:ctrlp_extensions: >
|
||||
let g:ctrlp_extensions = ['tag', 'buffertag', 'quickfix', 'dir', 'rtscript',
|
||||
\ 'undo', 'line', 'changes', 'mixed']
|
||||
\ 'undo', 'line', 'changes', 'mixed', 'bookmarkdir']
|
||||
<
|
||||
The order of the items will be the order they appear on the statusline and when
|
||||
using <c-f>, <c-b>.
|
||||
@ -783,7 +785,7 @@ Available extensions:~
|
||||
*:CtrlPBufTagAll*
|
||||
* Buffer Tag mode:~
|
||||
- Name: 'buffertag'
|
||||
- Commands: ':CtrlPBufTag [buffer-name]',
|
||||
- Commands: ':CtrlPBufTag [buffer]',
|
||||
':CtrlPBufTagAll'.
|
||||
- Search for a tag within the current buffer or all listed buffers and jump
|
||||
to the definition. Requires |exuberant_ctags| or compatible programs.
|
||||
@ -828,7 +830,7 @@ Available extensions:~
|
||||
*:CtrlPChangeAll*
|
||||
* Change list mode:~
|
||||
- Name: 'changes'
|
||||
- Commands: ':CtrlPChange [buffer-name]',
|
||||
- Commands: ':CtrlPChange [buffer]',
|
||||
':CtrlPChangeAll'.
|
||||
- Search for and jump to a recent change in the current buffer or in all
|
||||
listed buffers.
|
||||
@ -839,6 +841,22 @@ Available extensions:~
|
||||
- Command: ':CtrlPMixed'
|
||||
- Search in files, buffers and MRU files at the same time.
|
||||
|
||||
*:CtrlPBookmarkDir*
|
||||
*:CtrlPBookmarkDirAdd*
|
||||
* BookmarkDir mode:~
|
||||
- Name: 'bookmarkdir'
|
||||
- Commands: ':CtrlPBookmarkDir',
|
||||
':CtrlPBookmarkDirAdd [directory]'.
|
||||
- Search for a bookmarked directory and change the working directory to it.
|
||||
- Mappings:
|
||||
+ <cr> change the local working directory for CtrlP, keep it open and
|
||||
switch to find file mode.
|
||||
+ <c-x> change the global working directory (exit).
|
||||
+ <c-v> change the local working directory for the current window (exit).
|
||||
+ <F7>
|
||||
- Wipe bookmark list.
|
||||
- Or delete entries marked by <c-z>.
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
Buffer Tag mode options:~
|
||||
|
||||
@ -889,6 +907,7 @@ Highlighting:~
|
||||
CtrlPUndoNr : the undo number inside [] in undo mode (String)
|
||||
CtrlPUndoSv : the point where the file was saved (Comment)
|
||||
CtrlPUndoPo : the current position in the undo tree (|hl-Title|)
|
||||
CtrlPBookmark : the name of the bookmark (Identifier)
|
||||
|
||||
Statuslines:~
|
||||
* Highlight groups:
|
||||
@ -971,6 +990,10 @@ Special thanks:~
|
||||
===============================================================================
|
||||
CHANGELOG *ctrlp-changelog*
|
||||
|
||||
+ New feature: Bookmarked directories extension.
|
||||
+ New commands: |:CtrlPBookmarkDir|
|
||||
|:CtrlPBookmarkDirAdd|
|
||||
|
||||
Before 2012/04/15~
|
||||
|
||||
+ New option: |g:ctrlp_buffer_func|, callback functions for CtrlP buffer.
|
||||
|
@ -42,17 +42,20 @@ en
|
||||
|
||||
cal ctrlp#mrufiles#init()
|
||||
|
||||
com! CtrlPTag cal ctrlp#init(ctrlp#tag#id())
|
||||
com! CtrlPQuickfix cal ctrlp#init(ctrlp#quickfix#id())
|
||||
com! CtrlPTag cal ctrlp#init(ctrlp#tag#id())
|
||||
com! CtrlPQuickfix cal ctrlp#init(ctrlp#quickfix#id())
|
||||
com! -n=? -com=dir CtrlPDir
|
||||
\ cal ctrlp#init(ctrlp#dir#id(), <q-args>)
|
||||
com! -n=? -com=buffer CtrlPBufTag
|
||||
\ cal ctrlp#init(ctrlp#buffertag#cmd(0, <q-args>))
|
||||
com! CtrlPBufTagAll cal ctrlp#init(ctrlp#buffertag#cmd(1))
|
||||
com! CtrlPRTS cal ctrlp#init(ctrlp#rtscript#id())
|
||||
com! CtrlPUndo cal ctrlp#init(ctrlp#undo#id())
|
||||
com! CtrlPLine cal ctrlp#init(ctrlp#line#id())
|
||||
com! CtrlPBufTagAll cal ctrlp#init(ctrlp#buffertag#cmd(1))
|
||||
com! CtrlPRTS cal ctrlp#init(ctrlp#rtscript#id())
|
||||
com! CtrlPUndo cal ctrlp#init(ctrlp#undo#id())
|
||||
com! CtrlPLine cal ctrlp#init(ctrlp#line#id())
|
||||
com! -n=? -com=buffer CtrlPChange
|
||||
\ cal ctrlp#init(ctrlp#changes#cmd(0, <q-args>))
|
||||
com! CtrlPChangeAll cal ctrlp#init(ctrlp#changes#cmd(1))
|
||||
com! CtrlPMixed cal ctrlp#init(ctrlp#mixed#id())
|
||||
com! CtrlPChangeAll cal ctrlp#init(ctrlp#changes#cmd(1))
|
||||
com! CtrlPMixed cal ctrlp#init(ctrlp#mixed#id())
|
||||
com! CtrlPBookmarkDir cal ctrlp#init(ctrlp#bookmarkdir#id())
|
||||
com! -n=? -com=dir CtrlPBookmarkDirAdd
|
||||
\ cal ctrlp#call('ctrlp#bookmarkdir#add', <q-args>)
|
||||
|
Loading…
Reference in New Issue
Block a user