mirror of
https://github.com/preservim/nerdtree.git
synced 2024-11-23 14:56:19 +08:00
Merge branch 'refactor_autoload'
This commit is contained in:
commit
09e1dbec10
|
@ -95,175 +95,9 @@ function! nerdtree#runningWindows()
|
|||
return has("win16") || has("win32") || has("win64")
|
||||
endfunction
|
||||
|
||||
"FUNCTION: nerdtree#treeMarkupReg(dir) {{{2
|
||||
function! nerdtree#treeMarkupReg()
|
||||
if g:NERDTreeDirArrows
|
||||
return '^\([▾▸] \| \+[▾▸] \| \+\)'
|
||||
endif
|
||||
|
||||
return '^[ `|]*[\-+~]'
|
||||
endfunction
|
||||
|
||||
"FUNCTION: nerdtree#treeUpDirLine(dir) {{{2
|
||||
function! nerdtree#treeUpDirLine()
|
||||
return '.. (up a dir)'
|
||||
endfunction
|
||||
|
||||
"FUNCTION: nerdtree#treeWid(dir) {{{2
|
||||
function! nerdtree#treeWid()
|
||||
return 2
|
||||
endfunction
|
||||
|
||||
" SECTION: View Functions {{{1
|
||||
"============================================================
|
||||
|
||||
"FUNCTION: nerdtree#closeTree() {{{2
|
||||
"Closes the primary NERD tree window for this tab
|
||||
function! nerdtree#closeTree()
|
||||
if !nerdtree#isTreeOpen()
|
||||
throw "NERDTree.NoTreeFoundError: no NERDTree is open"
|
||||
endif
|
||||
|
||||
if winnr("$") != 1
|
||||
if winnr() == nerdtree#getTreeWinNum()
|
||||
call nerdtree#exec("wincmd p")
|
||||
let bufnr = bufnr("")
|
||||
call nerdtree#exec("wincmd p")
|
||||
else
|
||||
let bufnr = bufnr("")
|
||||
endif
|
||||
|
||||
call nerdtree#exec(nerdtree#getTreeWinNum() . " wincmd w")
|
||||
close
|
||||
call nerdtree#exec(bufwinnr(bufnr) . " wincmd w")
|
||||
else
|
||||
close
|
||||
endif
|
||||
endfunction
|
||||
|
||||
"FUNCTION: nerdtree#closeTreeIfOpen() {{{2
|
||||
"Closes the NERD tree window if it is open
|
||||
function! nerdtree#closeTreeIfOpen()
|
||||
if nerdtree#isTreeOpen()
|
||||
call nerdtree#closeTree()
|
||||
endif
|
||||
endfunction
|
||||
|
||||
"FUNCTION: nerdtree#closeTreeIfQuitOnOpen() {{{2
|
||||
"Closes the NERD tree window if the close on open option is set
|
||||
function! nerdtree#closeTreeIfQuitOnOpen()
|
||||
if g:NERDTreeQuitOnOpen && nerdtree#isTreeOpen()
|
||||
call nerdtree#closeTree()
|
||||
endif
|
||||
endfunction
|
||||
|
||||
"FUNCTION: nerdtree#dumpHelp {{{2
|
||||
"prints out the quick help
|
||||
function! nerdtree#dumpHelp()
|
||||
let old_h = @h
|
||||
if b:treeShowHelp ==# 1
|
||||
let @h= "\" NERD tree (" . nerdtree#version() . ") quickhelp~\n"
|
||||
let @h=@h."\" ============================\n"
|
||||
let @h=@h."\" File node mappings~\n"
|
||||
let @h=@h."\" ". (g:NERDTreeMouseMode ==# 3 ? "single" : "double") ."-click,\n"
|
||||
let @h=@h."\" <CR>,\n"
|
||||
if b:NERDTreeType ==# "primary"
|
||||
let @h=@h."\" ". g:NERDTreeMapActivateNode .": open in prev window\n"
|
||||
else
|
||||
let @h=@h."\" ". g:NERDTreeMapActivateNode .": open in current window\n"
|
||||
endif
|
||||
if b:NERDTreeType ==# "primary"
|
||||
let @h=@h."\" ". g:NERDTreeMapPreview .": preview\n"
|
||||
endif
|
||||
let @h=@h."\" ". g:NERDTreeMapOpenInTab.": open in new tab\n"
|
||||
let @h=@h."\" ". g:NERDTreeMapOpenInTabSilent .": open in new tab silently\n"
|
||||
let @h=@h."\" middle-click,\n"
|
||||
let @h=@h."\" ". g:NERDTreeMapOpenSplit .": open split\n"
|
||||
let @h=@h."\" ". g:NERDTreeMapPreviewSplit .": preview split\n"
|
||||
let @h=@h."\" ". g:NERDTreeMapOpenVSplit .": open vsplit\n"
|
||||
let @h=@h."\" ". g:NERDTreeMapPreviewVSplit .": preview vsplit\n"
|
||||
|
||||
let @h=@h."\"\n\" ----------------------------\n"
|
||||
let @h=@h."\" Directory node mappings~\n"
|
||||
let @h=@h."\" ". (g:NERDTreeMouseMode ==# 1 ? "double" : "single") ."-click,\n"
|
||||
let @h=@h."\" ". g:NERDTreeMapActivateNode .": open & close node\n"
|
||||
let @h=@h."\" ". g:NERDTreeMapOpenRecursively .": recursively open node\n"
|
||||
let @h=@h."\" ". g:NERDTreeMapCloseDir .": close parent of node\n"
|
||||
let @h=@h."\" ". g:NERDTreeMapCloseChildren .": close all child nodes of\n"
|
||||
let @h=@h."\" current node recursively\n"
|
||||
let @h=@h."\" middle-click,\n"
|
||||
let @h=@h."\" ". g:NERDTreeMapOpenExpl.": explore selected dir\n"
|
||||
|
||||
let @h=@h."\"\n\" ----------------------------\n"
|
||||
let @h=@h."\" Bookmark table mappings~\n"
|
||||
let @h=@h."\" double-click,\n"
|
||||
let @h=@h."\" ". g:NERDTreeMapActivateNode .": open bookmark\n"
|
||||
let @h=@h."\" ". g:NERDTreeMapOpenInTab.": open in new tab\n"
|
||||
let @h=@h."\" ". g:NERDTreeMapOpenInTabSilent .": open in new tab silently\n"
|
||||
let @h=@h."\" ". g:NERDTreeMapDeleteBookmark .": delete bookmark\n"
|
||||
|
||||
let @h=@h."\"\n\" ----------------------------\n"
|
||||
let @h=@h."\" Tree navigation mappings~\n"
|
||||
let @h=@h."\" ". g:NERDTreeMapJumpRoot .": go to root\n"
|
||||
let @h=@h."\" ". g:NERDTreeMapJumpParent .": go to parent\n"
|
||||
let @h=@h."\" ". g:NERDTreeMapJumpFirstChild .": go to first child\n"
|
||||
let @h=@h."\" ". g:NERDTreeMapJumpLastChild .": go to last child\n"
|
||||
let @h=@h."\" ". g:NERDTreeMapJumpNextSibling .": go to next sibling\n"
|
||||
let @h=@h."\" ". g:NERDTreeMapJumpPrevSibling .": go to prev sibling\n"
|
||||
|
||||
let @h=@h."\"\n\" ----------------------------\n"
|
||||
let @h=@h."\" Filesystem mappings~\n"
|
||||
let @h=@h."\" ". g:NERDTreeMapChangeRoot .": change tree root to the\n"
|
||||
let @h=@h."\" selected dir\n"
|
||||
let @h=@h."\" ". g:NERDTreeMapUpdir .": move tree root up a dir\n"
|
||||
let @h=@h."\" ". g:NERDTreeMapUpdirKeepOpen .": move tree root up a dir\n"
|
||||
let @h=@h."\" but leave old root open\n"
|
||||
let @h=@h."\" ". g:NERDTreeMapRefresh .": refresh cursor dir\n"
|
||||
let @h=@h."\" ". g:NERDTreeMapRefreshRoot .": refresh current root\n"
|
||||
let @h=@h."\" ". g:NERDTreeMapMenu .": Show menu\n"
|
||||
let @h=@h."\" ". g:NERDTreeMapChdir .":change the CWD to the\n"
|
||||
let @h=@h."\" selected dir\n"
|
||||
let @h=@h."\" ". g:NERDTreeMapCWD .":change tree root to CWD\n"
|
||||
|
||||
let @h=@h."\"\n\" ----------------------------\n"
|
||||
let @h=@h."\" Tree filtering mappings~\n"
|
||||
let @h=@h."\" ". g:NERDTreeMapToggleHidden .": hidden files (" . (b:NERDTreeShowHidden ? "on" : "off") . ")\n"
|
||||
let @h=@h."\" ". g:NERDTreeMapToggleFilters .": file filters (" . (b:NERDTreeIgnoreEnabled ? "on" : "off") . ")\n"
|
||||
let @h=@h."\" ". g:NERDTreeMapToggleFiles .": files (" . (b:NERDTreeShowFiles ? "on" : "off") . ")\n"
|
||||
let @h=@h."\" ". g:NERDTreeMapToggleBookmarks .": bookmarks (" . (b:NERDTreeShowBookmarks ? "on" : "off") . ")\n"
|
||||
|
||||
"add quickhelp entries for each custom key map
|
||||
let @h=@h."\"\n\" ----------------------------\n"
|
||||
let @h=@h."\" Custom mappings~\n"
|
||||
for i in g:NERDTreeKeyMap.All()
|
||||
if !empty(i.quickhelpText)
|
||||
let @h=@h."\" ". i.key .": ". i.quickhelpText ."\n"
|
||||
endif
|
||||
endfor
|
||||
|
||||
let @h=@h."\"\n\" ----------------------------\n"
|
||||
let @h=@h."\" Other mappings~\n"
|
||||
let @h=@h."\" ". g:NERDTreeMapQuit .": Close the NERDTree window\n"
|
||||
let @h=@h."\" ". g:NERDTreeMapToggleZoom .": Zoom (maximize-minimize)\n"
|
||||
let @h=@h."\" the NERDTree window\n"
|
||||
let @h=@h."\" ". g:NERDTreeMapHelp .": toggle help\n"
|
||||
let @h=@h."\"\n\" ----------------------------\n"
|
||||
let @h=@h."\" Bookmark commands~\n"
|
||||
let @h=@h."\" :Bookmark [<name>]\n"
|
||||
let @h=@h."\" :BookmarkToRoot <name>\n"
|
||||
let @h=@h."\" :RevealBookmark <name>\n"
|
||||
let @h=@h."\" :OpenBookmark <name>\n"
|
||||
let @h=@h."\" :ClearBookmarks [<names>]\n"
|
||||
let @h=@h."\" :ClearAllBookmarks\n"
|
||||
silent! put h
|
||||
elseif g:NERDTreeMinimalUI == 0
|
||||
let @h="\" Press ". g:NERDTreeMapHelp ." for help\n"
|
||||
silent! put h
|
||||
endif
|
||||
|
||||
let @h = old_h
|
||||
endfunction
|
||||
|
||||
"FUNCTION: nerdtree#echo {{{2
|
||||
"A wrapper for :echo. Appends 'NERDTree:' on the front of all messages
|
||||
"
|
||||
|
@ -294,114 +128,9 @@ function! nerdtree#echoWarning(msg)
|
|||
echohl normal
|
||||
endfunction
|
||||
|
||||
"FUNCTION: nerdtree#getTreeWinNum() {{{2
|
||||
"gets the nerd tree window number for this tab
|
||||
function! nerdtree#getTreeWinNum()
|
||||
if exists("t:NERDTreeBufName")
|
||||
return bufwinnr(t:NERDTreeBufName)
|
||||
else
|
||||
return -1
|
||||
endif
|
||||
endfunction
|
||||
|
||||
"FUNCTION: nerdtree#isTreeOpen() {{{2
|
||||
function! nerdtree#isTreeOpen()
|
||||
return nerdtree#getTreeWinNum() != -1
|
||||
endfunction
|
||||
|
||||
"FUNCTION: nerdtree#putCursorOnBookmarkTable(){{{2
|
||||
"Places the cursor at the top of the bookmarks table
|
||||
function! nerdtree#putCursorOnBookmarkTable()
|
||||
if !b:NERDTreeShowBookmarks
|
||||
throw "NERDTree.IllegalOperationError: cant find bookmark table, bookmarks arent active"
|
||||
endif
|
||||
|
||||
if g:NERDTreeMinimalUI
|
||||
return cursor(1, 2)
|
||||
endif
|
||||
|
||||
let rootNodeLine = b:NERDTree.ui.getRootLineNum()
|
||||
|
||||
let line = 1
|
||||
while getline(line) !~# '^>-\+Bookmarks-\+$'
|
||||
let line = line + 1
|
||||
if line >= rootNodeLine
|
||||
throw "NERDTree.BookmarkTableNotFoundError: didnt find the bookmarks table"
|
||||
endif
|
||||
endwhile
|
||||
call cursor(line, 2)
|
||||
endfunction
|
||||
|
||||
"FUNCTION: nerdtree#putCursorInTreeWin(){{{2
|
||||
"Places the cursor in the nerd tree window
|
||||
function! nerdtree#putCursorInTreeWin()
|
||||
if !nerdtree#isTreeOpen()
|
||||
throw "NERDTree.InvalidOperationError: cant put cursor in NERD tree window, no window exists"
|
||||
endif
|
||||
|
||||
call nerdtree#exec(nerdtree#getTreeWinNum() . "wincmd w")
|
||||
endfunction
|
||||
|
||||
"FUNCTION: nerdtree#renderBookmarks {{{2
|
||||
function! nerdtree#renderBookmarks()
|
||||
|
||||
if g:NERDTreeMinimalUI == 0
|
||||
call setline(line(".")+1, ">----------Bookmarks----------")
|
||||
call cursor(line(".")+1, col("."))
|
||||
endif
|
||||
|
||||
for i in g:NERDTreeBookmark.Bookmarks()
|
||||
call setline(line(".")+1, i.str())
|
||||
call cursor(line(".")+1, col("."))
|
||||
endfor
|
||||
|
||||
call setline(line(".")+1, '')
|
||||
call cursor(line(".")+1, col("."))
|
||||
endfunction
|
||||
|
||||
"FUNCTION: nerdtree#renderView {{{2
|
||||
function! nerdtree#renderView()
|
||||
call b:NERDTree.render()
|
||||
endfunction
|
||||
"
|
||||
"FUNCTION: nerdtree#stripMarkupFromLine(line, removeLeadingSpaces){{{2
|
||||
"returns the given line with all the tree parts stripped off
|
||||
"
|
||||
"Args:
|
||||
"line: the subject line
|
||||
"removeLeadingSpaces: 1 if leading spaces are to be removed (leading spaces =
|
||||
"any spaces before the actual text of the node)
|
||||
function! nerdtree#stripMarkupFromLine(line, removeLeadingSpaces)
|
||||
let line = a:line
|
||||
"remove the tree parts and the leading space
|
||||
let line = substitute (line, nerdtree#treeMarkupReg(),"","")
|
||||
|
||||
"strip off any read only flag
|
||||
let line = substitute (line, ' \[RO\]', "","")
|
||||
|
||||
"strip off any bookmark flags
|
||||
let line = substitute (line, ' {[^}]*}', "","")
|
||||
|
||||
"strip off any executable flags
|
||||
let line = substitute (line, '*\ze\($\| \)', "","")
|
||||
|
||||
"strip off any generic flags
|
||||
let line = substitute (line, '\[[^]]*\]', "","")
|
||||
|
||||
let wasdir = 0
|
||||
if line =~# '/$'
|
||||
let wasdir = 1
|
||||
endif
|
||||
let line = substitute (line,' -> .*',"","") " remove link to
|
||||
if wasdir ==# 1
|
||||
let line = substitute (line, '/\?$', '/', "")
|
||||
endif
|
||||
|
||||
if a:removeLeadingSpaces
|
||||
let line = substitute (line, '^ *', '', '')
|
||||
endif
|
||||
|
||||
return line
|
||||
endfunction
|
||||
|
||||
" vim: set sw=4 sts=4 et fdm=marker:
|
||||
|
|
|
@ -85,7 +85,7 @@ endfunction
|
|||
"FUNCTION: s:activateAll() {{{1
|
||||
"handle the user activating the updir line
|
||||
function! s:activateAll()
|
||||
if getline(".") ==# nerdtree#treeUpDirLine()
|
||||
if getline(".") ==# g:NERDTreeUI.UpDirLine()
|
||||
return nerdtree#ui_glue#upDir(0)
|
||||
endif
|
||||
endfunction
|
||||
|
@ -212,7 +212,7 @@ function! s:closeTreeWindow()
|
|||
exec "buffer " . b:NERDTreePreviousBuf
|
||||
else
|
||||
if winnr("$") > 1
|
||||
call nerdtree#closeTree()
|
||||
call g:NERDTree.Close()
|
||||
else
|
||||
call nerdtree#echo("Cannot close last window")
|
||||
endif
|
||||
|
@ -275,20 +275,20 @@ function! s:findAndRevealPath()
|
|||
endif
|
||||
else
|
||||
if !p.isUnder(g:NERDTreeFileNode.GetRootForTab().path)
|
||||
if !nerdtree#isTreeOpen()
|
||||
if !g:NERDTree.IsOpen()
|
||||
call g:NERDTreeCreator.TogglePrimary('')
|
||||
else
|
||||
call nerdtree#putCursorInTreeWin()
|
||||
call g:NERDTree.CursorToTreeWin()
|
||||
endif
|
||||
let b:NERDTreeShowHidden = g:NERDTreeShowHidden
|
||||
call s:chRoot(g:NERDTreeDirNode.New(p.getParent()))
|
||||
else
|
||||
if !nerdtree#isTreeOpen()
|
||||
if !g:NERDTree.IsOpen()
|
||||
call g:NERDTreeCreator.TogglePrimary("")
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
call nerdtree#putCursorInTreeWin()
|
||||
call g:NERDTree.CursorToTreeWin()
|
||||
call b:NERDTreeRoot.reveal(p)
|
||||
|
||||
if p.isUnixHiddenFile()
|
||||
|
@ -312,7 +312,7 @@ function! s:handleLeftClick()
|
|||
endfor
|
||||
|
||||
if currentNode.path.isDirectory
|
||||
if startToCur =~# nerdtree#treeMarkupReg() && startToCur =~# '[+~▾▸] \?$'
|
||||
if startToCur =~# g:NERDTreeUI.MarkupReg() && startToCur =~# '[+~▾▸] \?$'
|
||||
call currentNode.activate()
|
||||
return
|
||||
endif
|
||||
|
@ -320,7 +320,7 @@ function! s:handleLeftClick()
|
|||
|
||||
if (g:NERDTreeMouseMode ==# 2 && currentNode.path.isDirectory) || g:NERDTreeMouseMode ==# 3
|
||||
let char = strpart(startToCur, strlen(startToCur)-1, 1)
|
||||
if char !~# nerdtree#treeMarkupReg()
|
||||
if char !~# g:NERDTreeUI.MarkupReg()
|
||||
if currentNode.path.isDirectory
|
||||
call currentNode.activate()
|
||||
else
|
||||
|
@ -547,7 +547,7 @@ endfunction
|
|||
function! nerdtree#ui_glue#setupCommands()
|
||||
command! -n=? -complete=dir -bar NERDTree :call g:NERDTreeCreator.CreatePrimary('<args>')
|
||||
command! -n=? -complete=dir -bar NERDTreeToggle :call g:NERDTreeCreator.TogglePrimary('<args>')
|
||||
command! -n=0 -bar NERDTreeClose :call nerdtree#closeTreeIfOpen()
|
||||
command! -n=0 -bar NERDTreeClose :call g:NERDTree.Close()
|
||||
command! -n=1 -complete=customlist,nerdtree#completeBookmarks -bar NERDTreeFromBookmark call g:NERDTreeCreator.CreatePrimary('<args>')
|
||||
command! -n=0 -bar NERDTreeMirror call g:NERDTreeCreator.CreateMirror()
|
||||
command! -n=0 -bar NERDTreeFind call s:findAndRevealPath()
|
||||
|
|
|
@ -253,7 +253,7 @@ endfunction
|
|||
" FUNCTION: Bookmark.str() {{{1
|
||||
" Get the string that should be rendered in the view for this bookmark
|
||||
function! s:Bookmark.str()
|
||||
let pathStrMaxLen = winwidth(nerdtree#getTreeWinNum()) - 4 - len(self.name)
|
||||
let pathStrMaxLen = winwidth(g:NERDTree.GetWinNum()) - 4 - len(self.name)
|
||||
if &nu
|
||||
let pathStrMaxLen = pathStrMaxLen - &numberwidth
|
||||
endif
|
||||
|
|
|
@ -55,8 +55,8 @@ function! s:Creator.createPrimary(name)
|
|||
endif
|
||||
|
||||
if g:NERDTree.ExistsForTab()
|
||||
if nerdtree#isTreeOpen()
|
||||
call nerdtree#closeTree()
|
||||
if g:NERDTree.IsOpen()
|
||||
call g:NERDTree.Close()
|
||||
endif
|
||||
unlet t:NERDTreeBufName
|
||||
endif
|
||||
|
@ -168,8 +168,8 @@ function! s:Creator.createMirror()
|
|||
return
|
||||
endif
|
||||
|
||||
if g:NERDTree.ExistsForTab() && nerdtree#isTreeOpen()
|
||||
call nerdtree#closeTree()
|
||||
if g:NERDTree.ExistsForTab() && g:NERDTree.IsOpen()
|
||||
call g:NERDTree.Close()
|
||||
endif
|
||||
|
||||
let t:NERDTreeBufName = bufferName
|
||||
|
@ -333,14 +333,14 @@ endfunction
|
|||
"initialized.
|
||||
function! s:Creator.togglePrimary(dir)
|
||||
if g:NERDTree.ExistsForTab()
|
||||
if !nerdtree#isTreeOpen()
|
||||
if !g:NERDTree.IsOpen()
|
||||
call self._createTreeWin()
|
||||
if !&hidden
|
||||
call b:NERDTree.render()
|
||||
endif
|
||||
call b:NERDTree.ui.restoreScreenState()
|
||||
else
|
||||
call nerdtree#closeTree()
|
||||
call g:NERDTree.Close()
|
||||
endif
|
||||
else
|
||||
call self.createPrimary(a:dir)
|
||||
|
|
|
@ -3,6 +3,68 @@
|
|||
let s:NERDTree = {}
|
||||
let g:NERDTree = s:NERDTree
|
||||
|
||||
"FUNCTION: s:NERDTree.Close() {{{1
|
||||
"Closes the primary NERD tree window for this tab
|
||||
function! s:NERDTree.Close()
|
||||
if !s:NERDTree.IsOpen()
|
||||
return
|
||||
endif
|
||||
|
||||
if winnr("$") != 1
|
||||
if winnr() == s:NERDTree.GetWinNum()
|
||||
call nerdtree#exec("wincmd p")
|
||||
let bufnr = bufnr("")
|
||||
call nerdtree#exec("wincmd p")
|
||||
else
|
||||
let bufnr = bufnr("")
|
||||
endif
|
||||
|
||||
call nerdtree#exec(s:NERDTree.GetWinNum() . " wincmd w")
|
||||
close
|
||||
call nerdtree#exec(bufwinnr(bufnr) . " wincmd w")
|
||||
else
|
||||
close
|
||||
endif
|
||||
endfunction
|
||||
|
||||
"FUNCTION: s:NERDTree.CloseIfQuitOnOpen() {{{1
|
||||
"Closes the NERD tree window if the close on open option is set
|
||||
function! s:NERDTree.CloseIfQuitOnOpen()
|
||||
if g:NERDTreeQuitOnOpen && s:NERDTree.IsOpen()
|
||||
call s:NERDTree.Close()
|
||||
endif
|
||||
endfunction
|
||||
|
||||
"FUNCTION: s:NERDTree.CursorToBookmarkTable(){{{1
|
||||
"Places the cursor at the top of the bookmarks table
|
||||
function! s:NERDTree.CursorToBookmarkTable()
|
||||
if !b:NERDTreeShowBookmarks
|
||||
throw "NERDTree.IllegalOperationError: cant find bookmark table, bookmarks arent active"
|
||||
endif
|
||||
|
||||
if g:NERDTreeMinimalUI
|
||||
return cursor(1, 2)
|
||||
endif
|
||||
|
||||
let rootNodeLine = b:NERDTree.ui.getRootLineNum()
|
||||
|
||||
let line = 1
|
||||
while getline(line) !~# '^>-\+Bookmarks-\+$'
|
||||
let line = line + 1
|
||||
if line >= rootNodeLine
|
||||
throw "NERDTree.BookmarkTableNotFoundError: didnt find the bookmarks table"
|
||||
endif
|
||||
endwhile
|
||||
call cursor(line, 2)
|
||||
endfunction
|
||||
|
||||
"FUNCTION: s:NERDTree.CursorToTreeWin(){{{1
|
||||
"Places the cursor in the nerd tree window
|
||||
function! s:NERDTree.CursorToTreeWin()
|
||||
call g:NERDTree.MustBeOpen()
|
||||
call nerdtree#exec(g:NERDTree.GetWinNum() . "wincmd w")
|
||||
endfunction
|
||||
|
||||
" Function: s:NERDTree.ExistsForBuffer() {{{1
|
||||
" Returns 1 if a nerd tree root exists in the current buffer
|
||||
function! s:NERDTree.ExistsForBuf()
|
||||
|
@ -23,6 +85,29 @@ function! s:NERDTree.ForCurrentBuf()
|
|||
endif
|
||||
endfunction
|
||||
|
||||
"FUNCTION: s:NERDTree.GetWinNum() {{{1
|
||||
"gets the nerd tree window number for this tab
|
||||
function! s:NERDTree.GetWinNum()
|
||||
if exists("t:NERDTreeBufName")
|
||||
return bufwinnr(t:NERDTreeBufName)
|
||||
else
|
||||
return -1
|
||||
endif
|
||||
endfunction
|
||||
|
||||
"FUNCTION: s:NERDTree.IsOpen() {{{1
|
||||
function! s:NERDTree.IsOpen()
|
||||
return s:NERDTree.GetWinNum() != -1
|
||||
endfunction
|
||||
|
||||
"FUNCTION: s:NERDTree.MustBeOpen() {{{1
|
||||
function! s:NERDTree.MustBeOpen()
|
||||
if !s:NERDTree.IsOpen()
|
||||
throw "NERDTree.TreeNotOpen"
|
||||
endif
|
||||
endfunction
|
||||
|
||||
"FUNCTION: s:NERDTree.New() {{{1
|
||||
function! s:NERDTree.New(path)
|
||||
let newObj = copy(self)
|
||||
let newObj.ui = g:NERDTreeUI.New(newObj)
|
||||
|
@ -36,4 +121,3 @@ endfunction
|
|||
function! s:NERDTree.render()
|
||||
call self.ui.render()
|
||||
endfunction
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@ function! s:Opener._checkToCloseTree(newtab)
|
|||
endif
|
||||
|
||||
if (a:newtab && self._where == 't') || !a:newtab
|
||||
call nerdtree#closeTreeIfQuitOnOpen()
|
||||
call g:NERDTree.CloseIfQuitOnOpen()
|
||||
endif
|
||||
endfunction
|
||||
|
||||
|
@ -189,7 +189,7 @@ function! s:Opener._newSplit()
|
|||
try
|
||||
exec(splitMode." sp ")
|
||||
catch /^Vim\%((\a\+)\)\=:E37/
|
||||
call nerdtree#putCursorInTreeWin()
|
||||
call g:NERDTree.CursorToTreeWin()
|
||||
throw "NERDTree.FileAlreadyOpenAndModifiedError: ". self._path.str() ." is already open and modified."
|
||||
catch /^Vim\%((\a\+)\)\=:/
|
||||
"do nothing
|
||||
|
@ -219,7 +219,7 @@ function! s:Opener._newVSplit()
|
|||
vnew
|
||||
|
||||
"resize the nerd tree back to the original size
|
||||
call nerdtree#putCursorInTreeWin()
|
||||
call g:NERDTree.CursorToTreeWin()
|
||||
exec("silent vertical resize ". winwidth)
|
||||
call nerdtree#exec('wincmd p')
|
||||
endfunction
|
||||
|
@ -288,7 +288,7 @@ function! s:Opener._previousWindow()
|
|||
call nerdtree#exec('wincmd p')
|
||||
endif
|
||||
catch /^Vim\%((\a\+)\)\=:E37/
|
||||
call nerdtree#putCursorInTreeWin()
|
||||
call g:NERDTree.CursorToTreeWin()
|
||||
throw "NERDTree.FileAlreadyOpenAndModifiedError: ". self._path.str() ." is already open and modified."
|
||||
catch /^Vim\%((\a\+)\)\=:/
|
||||
echo v:exception
|
||||
|
|
|
@ -3,11 +3,6 @@
|
|||
let s:UI = {}
|
||||
let g:NERDTreeUI = s:UI
|
||||
|
||||
|
||||
function! s:UI.lolcats()
|
||||
echomsg "lolcats"
|
||||
endfunction
|
||||
|
||||
"FUNCTION: s:UI.centerView() {{{2
|
||||
"centers the nerd tree window around the cursor (provided the nerd tree
|
||||
"options permit)
|
||||
|
@ -15,13 +10,121 @@ function! s:UI.centerView()
|
|||
if g:NERDTreeAutoCenter
|
||||
let current_line = winline()
|
||||
let lines_to_top = current_line
|
||||
let lines_to_bottom = winheight(nerdtree#getTreeWinNum()) - current_line
|
||||
let lines_to_bottom = winheight(g:NERDTree.GetWinNum()) - current_line
|
||||
if lines_to_top < g:NERDTreeAutoCenterThreshold || lines_to_bottom < g:NERDTreeAutoCenterThreshold
|
||||
normal! zz
|
||||
endif
|
||||
endif
|
||||
endfunction
|
||||
|
||||
"FUNCTION: s:UI._dumpHelp {{{1
|
||||
"prints out the quick help
|
||||
function! s:UI._dumpHelp()
|
||||
let old_h = @h
|
||||
if b:treeShowHelp ==# 1
|
||||
let @h= "\" NERD tree (" . nerdtree#version() . ") quickhelp~\n"
|
||||
let @h=@h."\" ============================\n"
|
||||
let @h=@h."\" File node mappings~\n"
|
||||
let @h=@h."\" ". (g:NERDTreeMouseMode ==# 3 ? "single" : "double") ."-click,\n"
|
||||
let @h=@h."\" <CR>,\n"
|
||||
if b:NERDTreeType ==# "primary"
|
||||
let @h=@h."\" ". g:NERDTreeMapActivateNode .": open in prev window\n"
|
||||
else
|
||||
let @h=@h."\" ". g:NERDTreeMapActivateNode .": open in current window\n"
|
||||
endif
|
||||
if b:NERDTreeType ==# "primary"
|
||||
let @h=@h."\" ". g:NERDTreeMapPreview .": preview\n"
|
||||
endif
|
||||
let @h=@h."\" ". g:NERDTreeMapOpenInTab.": open in new tab\n"
|
||||
let @h=@h."\" ". g:NERDTreeMapOpenInTabSilent .": open in new tab silently\n"
|
||||
let @h=@h."\" middle-click,\n"
|
||||
let @h=@h."\" ". g:NERDTreeMapOpenSplit .": open split\n"
|
||||
let @h=@h."\" ". g:NERDTreeMapPreviewSplit .": preview split\n"
|
||||
let @h=@h."\" ". g:NERDTreeMapOpenVSplit .": open vsplit\n"
|
||||
let @h=@h."\" ". g:NERDTreeMapPreviewVSplit .": preview vsplit\n"
|
||||
|
||||
let @h=@h."\"\n\" ----------------------------\n"
|
||||
let @h=@h."\" Directory node mappings~\n"
|
||||
let @h=@h."\" ". (g:NERDTreeMouseMode ==# 1 ? "double" : "single") ."-click,\n"
|
||||
let @h=@h."\" ". g:NERDTreeMapActivateNode .": open & close node\n"
|
||||
let @h=@h."\" ". g:NERDTreeMapOpenRecursively .": recursively open node\n"
|
||||
let @h=@h."\" ". g:NERDTreeMapCloseDir .": close parent of node\n"
|
||||
let @h=@h."\" ". g:NERDTreeMapCloseChildren .": close all child nodes of\n"
|
||||
let @h=@h."\" current node recursively\n"
|
||||
let @h=@h."\" middle-click,\n"
|
||||
let @h=@h."\" ". g:NERDTreeMapOpenExpl.": explore selected dir\n"
|
||||
|
||||
let @h=@h."\"\n\" ----------------------------\n"
|
||||
let @h=@h."\" Bookmark table mappings~\n"
|
||||
let @h=@h."\" double-click,\n"
|
||||
let @h=@h."\" ". g:NERDTreeMapActivateNode .": open bookmark\n"
|
||||
let @h=@h."\" ". g:NERDTreeMapOpenInTab.": open in new tab\n"
|
||||
let @h=@h."\" ". g:NERDTreeMapOpenInTabSilent .": open in new tab silently\n"
|
||||
let @h=@h."\" ". g:NERDTreeMapDeleteBookmark .": delete bookmark\n"
|
||||
|
||||
let @h=@h."\"\n\" ----------------------------\n"
|
||||
let @h=@h."\" Tree navigation mappings~\n"
|
||||
let @h=@h."\" ". g:NERDTreeMapJumpRoot .": go to root\n"
|
||||
let @h=@h."\" ". g:NERDTreeMapJumpParent .": go to parent\n"
|
||||
let @h=@h."\" ". g:NERDTreeMapJumpFirstChild .": go to first child\n"
|
||||
let @h=@h."\" ". g:NERDTreeMapJumpLastChild .": go to last child\n"
|
||||
let @h=@h."\" ". g:NERDTreeMapJumpNextSibling .": go to next sibling\n"
|
||||
let @h=@h."\" ". g:NERDTreeMapJumpPrevSibling .": go to prev sibling\n"
|
||||
|
||||
let @h=@h."\"\n\" ----------------------------\n"
|
||||
let @h=@h."\" Filesystem mappings~\n"
|
||||
let @h=@h."\" ". g:NERDTreeMapChangeRoot .": change tree root to the\n"
|
||||
let @h=@h."\" selected dir\n"
|
||||
let @h=@h."\" ". g:NERDTreeMapUpdir .": move tree root up a dir\n"
|
||||
let @h=@h."\" ". g:NERDTreeMapUpdirKeepOpen .": move tree root up a dir\n"
|
||||
let @h=@h."\" but leave old root open\n"
|
||||
let @h=@h."\" ". g:NERDTreeMapRefresh .": refresh cursor dir\n"
|
||||
let @h=@h."\" ". g:NERDTreeMapRefreshRoot .": refresh current root\n"
|
||||
let @h=@h."\" ". g:NERDTreeMapMenu .": Show menu\n"
|
||||
let @h=@h."\" ". g:NERDTreeMapChdir .":change the CWD to the\n"
|
||||
let @h=@h."\" selected dir\n"
|
||||
let @h=@h."\" ". g:NERDTreeMapCWD .":change tree root to CWD\n"
|
||||
|
||||
let @h=@h."\"\n\" ----------------------------\n"
|
||||
let @h=@h."\" Tree filtering mappings~\n"
|
||||
let @h=@h."\" ". g:NERDTreeMapToggleHidden .": hidden files (" . (b:NERDTreeShowHidden ? "on" : "off") . ")\n"
|
||||
let @h=@h."\" ". g:NERDTreeMapToggleFilters .": file filters (" . (b:NERDTreeIgnoreEnabled ? "on" : "off") . ")\n"
|
||||
let @h=@h."\" ". g:NERDTreeMapToggleFiles .": files (" . (b:NERDTreeShowFiles ? "on" : "off") . ")\n"
|
||||
let @h=@h."\" ". g:NERDTreeMapToggleBookmarks .": bookmarks (" . (b:NERDTreeShowBookmarks ? "on" : "off") . ")\n"
|
||||
|
||||
"add quickhelp entries for each custom key map
|
||||
let @h=@h."\"\n\" ----------------------------\n"
|
||||
let @h=@h."\" Custom mappings~\n"
|
||||
for i in g:NERDTreeKeyMap.All()
|
||||
if !empty(i.quickhelpText)
|
||||
let @h=@h."\" ". i.key .": ". i.quickhelpText ."\n"
|
||||
endif
|
||||
endfor
|
||||
|
||||
let @h=@h."\"\n\" ----------------------------\n"
|
||||
let @h=@h."\" Other mappings~\n"
|
||||
let @h=@h."\" ". g:NERDTreeMapQuit .": Close the NERDTree window\n"
|
||||
let @h=@h."\" ". g:NERDTreeMapToggleZoom .": Zoom (maximize-minimize)\n"
|
||||
let @h=@h."\" the NERDTree window\n"
|
||||
let @h=@h."\" ". g:NERDTreeMapHelp .": toggle help\n"
|
||||
let @h=@h."\"\n\" ----------------------------\n"
|
||||
let @h=@h."\" Bookmark commands~\n"
|
||||
let @h=@h."\" :Bookmark [<name>]\n"
|
||||
let @h=@h."\" :BookmarkToRoot <name>\n"
|
||||
let @h=@h."\" :RevealBookmark <name>\n"
|
||||
let @h=@h."\" :OpenBookmark <name>\n"
|
||||
let @h=@h."\" :ClearBookmarks [<names>]\n"
|
||||
let @h=@h."\" :ClearAllBookmarks\n"
|
||||
silent! put h
|
||||
elseif g:NERDTreeMinimalUI == 0
|
||||
let @h="\" Press ". g:NERDTreeMapHelp ." for help\n"
|
||||
silent! put h
|
||||
endif
|
||||
|
||||
let @h = old_h
|
||||
endfunction
|
||||
|
||||
|
||||
"FUNCTION: s:UI.new(nerdtree) {{{1
|
||||
function! s:UI.New(nerdtree)
|
||||
let newObj = copy(self)
|
||||
|
@ -56,14 +159,14 @@ function! s:UI.getPath(ln)
|
|||
endif
|
||||
endif
|
||||
|
||||
if line ==# nerdtree#treeUpDirLine()
|
||||
if line ==# s:UI.UpDirLine()
|
||||
return b:NERDTreeRoot.path.getParent()
|
||||
endif
|
||||
|
||||
let indent = self._indentLevelFor(line)
|
||||
|
||||
"remove the tree parts and the leading space
|
||||
let curFile = nerdtree#stripMarkupFromLine(line, 0)
|
||||
let curFile = self._stripMarkup(line, 0)
|
||||
|
||||
let wasdir = 0
|
||||
if curFile =~# '/$'
|
||||
|
@ -76,7 +179,7 @@ function! s:UI.getPath(ln)
|
|||
while lnum > 0
|
||||
let lnum = lnum - 1
|
||||
let curLine = getline(lnum)
|
||||
let curLineStripped = nerdtree#stripMarkupFromLine(curLine, 1)
|
||||
let curLineStripped = self._stripMarkup(curLine, 1)
|
||||
|
||||
"have we reached the top of the tree?
|
||||
if lnum == rootLine
|
||||
|
@ -127,7 +230,7 @@ function! s:UI.getLineNum(file_node)
|
|||
|
||||
let indent = self._indentLevelFor(curLine)
|
||||
if indent ==# curPathComponent
|
||||
let curLine = nerdtree#stripMarkupFromLine(curLine, 1)
|
||||
let curLine = self._stripMarkup(curLine, 1)
|
||||
|
||||
let curPath = join(pathcomponents, '/') . '/' . curLine
|
||||
if stridx(fullpath, curPath, 0) ==# 0
|
||||
|
@ -146,7 +249,6 @@ function! s:UI.getLineNum(file_node)
|
|||
return -1
|
||||
endfunction
|
||||
|
||||
|
||||
"FUNCTION: s:UI.getRootLineNum(){{{1
|
||||
"gets the line number of the root node
|
||||
function! s:UI.getRootLineNum()
|
||||
|
@ -157,9 +259,9 @@ function! s:UI.getRootLineNum()
|
|||
return rootLine
|
||||
endfunction
|
||||
|
||||
"FUNCTION: s:UI._indentLevelFor(line) {{{2
|
||||
"FUNCTION: s:UI._indentLevelFor(line) {{{1
|
||||
function! s:UI._indentLevelFor(line)
|
||||
let level = match(a:line, '[^ \-+~▸▾`|]') / nerdtree#treeWid()
|
||||
let level = match(a:line, '[^ \-+~▸▾`|]') / s:UI.IndentWid()
|
||||
" check if line includes arrows
|
||||
if match(a:line, '[▸▾]') > -1
|
||||
" decrement level as arrow uses 3 ascii chars
|
||||
|
@ -168,8 +270,38 @@ function! s:UI._indentLevelFor(line)
|
|||
return level
|
||||
endfunction
|
||||
|
||||
"FUNCTION: s:UI.IndentWid() {{{1
|
||||
function! s:UI.IndentWid()
|
||||
return 2
|
||||
endfunction
|
||||
|
||||
"FUNCTION: s:UI.restoreScreenState() {{{2
|
||||
"FUNCTION: s:UI.MarkupReg() {{{1
|
||||
function! s:UI.MarkupReg()
|
||||
if g:NERDTreeDirArrows
|
||||
return '^\([▾▸] \| \+[▾▸] \| \+\)'
|
||||
endif
|
||||
|
||||
return '^[ `|]*[\-+~]'
|
||||
endfunction
|
||||
|
||||
"FUNCTION: s:UI._renderBookmarks {{{1
|
||||
function! s:UI._renderBookmarks()
|
||||
|
||||
if g:NERDTreeMinimalUI == 0
|
||||
call setline(line(".")+1, ">----------Bookmarks----------")
|
||||
call cursor(line(".")+1, col("."))
|
||||
endif
|
||||
|
||||
for i in g:NERDTreeBookmark.Bookmarks()
|
||||
call setline(line(".")+1, i.str())
|
||||
call cursor(line(".")+1, col("."))
|
||||
endfor
|
||||
|
||||
call setline(line(".")+1, '')
|
||||
call cursor(line(".")+1, col("."))
|
||||
endfunction
|
||||
|
||||
"FUNCTION: s:UI.restoreScreenState() {{{1
|
||||
"
|
||||
"Sets the screen state back to what it was when nerdtree#saveScreenState was last
|
||||
"called.
|
||||
|
@ -189,13 +321,13 @@ function! s:UI.restoreScreenState()
|
|||
let &scrolloff=old_scrolloff
|
||||
endfunction
|
||||
|
||||
"FUNCTION: s:UI.saveScreenState() {{{2
|
||||
"FUNCTION: s:UI.saveScreenState() {{{1
|
||||
"Saves the current cursor position in the current buffer and the window
|
||||
"scroll position
|
||||
function! s:UI.saveScreenState()
|
||||
let win = winnr()
|
||||
try
|
||||
call nerdtree#putCursorInTreeWin()
|
||||
call g:NERDTree.CursorToTreeWin()
|
||||
let self._screenState = {}
|
||||
let self._screenState['oldPos'] = getpos(".")
|
||||
let self._screenState['oldTopLine'] = line("w0")
|
||||
|
@ -205,7 +337,47 @@ function! s:UI.saveScreenState()
|
|||
endtry
|
||||
endfunction
|
||||
|
||||
"FUNCTION: s:UI.render() {{{2
|
||||
"FUNCTION: s:UI._stripMarkup(line, removeLeadingSpaces){{{1
|
||||
"returns the given line with all the tree parts stripped off
|
||||
"
|
||||
"Args:
|
||||
"line: the subject line
|
||||
"removeLeadingSpaces: 1 if leading spaces are to be removed (leading spaces =
|
||||
"any spaces before the actual text of the node)
|
||||
function! s:UI._stripMarkup(line, removeLeadingSpaces)
|
||||
let line = a:line
|
||||
"remove the tree parts and the leading space
|
||||
let line = substitute (line, g:NERDTreeUI.MarkupReg(),"","")
|
||||
|
||||
"strip off any read only flag
|
||||
let line = substitute (line, ' \[RO\]', "","")
|
||||
|
||||
"strip off any bookmark flags
|
||||
let line = substitute (line, ' {[^}]*}', "","")
|
||||
|
||||
"strip off any executable flags
|
||||
let line = substitute (line, '*\ze\($\| \)', "","")
|
||||
|
||||
"strip off any generic flags
|
||||
let line = substitute (line, '\[[^]]*\]', "","")
|
||||
|
||||
let wasdir = 0
|
||||
if line =~# '/$'
|
||||
let wasdir = 1
|
||||
endif
|
||||
let line = substitute (line,' -> .*',"","") " remove link to
|
||||
if wasdir ==# 1
|
||||
let line = substitute (line, '/\?$', '/', "")
|
||||
endif
|
||||
|
||||
if a:removeLeadingSpaces
|
||||
let line = substitute (line, '^ *', '', '')
|
||||
endif
|
||||
|
||||
return line
|
||||
endfunction
|
||||
|
||||
"FUNCTION: s:UI.render() {{{1
|
||||
function! s:UI.render()
|
||||
setlocal modifiable
|
||||
|
||||
|
@ -218,7 +390,7 @@ function! s:UI.render()
|
|||
"delete all lines in the buffer (being careful not to clobber a register)
|
||||
silent 1,$delete _
|
||||
|
||||
call nerdtree#dumpHelp()
|
||||
call self._dumpHelp()
|
||||
|
||||
"delete the blank line before the help and add one after it
|
||||
if g:NERDTreeMinimalUI == 0
|
||||
|
@ -227,12 +399,12 @@ function! s:UI.render()
|
|||
endif
|
||||
|
||||
if b:NERDTreeShowBookmarks
|
||||
call nerdtree#renderBookmarks()
|
||||
call self._renderBookmarks()
|
||||
endif
|
||||
|
||||
"add the 'up a dir' line
|
||||
if !g:NERDTreeMinimalUI
|
||||
call setline(line(".")+1, nerdtree#treeUpDirLine())
|
||||
call setline(line(".")+1, s:UI.UpDirLine())
|
||||
call cursor(line(".")+1, col("."))
|
||||
endif
|
||||
|
||||
|
@ -295,7 +467,7 @@ function! s:UI.toggleShowBookmarks()
|
|||
let b:NERDTreeShowBookmarks = !b:NERDTreeShowBookmarks
|
||||
if b:NERDTreeShowBookmarks
|
||||
call b:NERDTree.render()
|
||||
call nerdtree#putCursorOnBookmarkTable()
|
||||
call g:NERDTree.CursorToBookmarkTable()
|
||||
else
|
||||
call b:NERDTree.ui.renderViewSavingPosition()
|
||||
endif
|
||||
|
@ -330,3 +502,8 @@ function! s:UI.toggleZoom()
|
|||
let b:NERDTreeZoomed = 1
|
||||
endif
|
||||
endfunction
|
||||
|
||||
"FUNCTION: s:UI.UpDirLine() {{{1
|
||||
function! s:UI.UpDirLine()
|
||||
return '.. (up a dir)'
|
||||
endfunction
|
||||
|
|
|
@ -185,8 +185,8 @@ function! NERDTreeRender()
|
|||
endfunction
|
||||
|
||||
function! NERDTreeFocus()
|
||||
if nerdtree#isTreeOpen()
|
||||
call nerdtree#putCursorInTreeWin()
|
||||
if g:NERDTree.IsOpen()
|
||||
call g:NERDTree.CursorToTreeWin()
|
||||
else
|
||||
call g:NERDTreeCreator.TogglePrimary("")
|
||||
endif
|
||||
|
|
Loading…
Reference in New Issue
Block a user