mirror of
https://github.com/preservim/nerdtree.git
synced 2024-11-25 17:57:24 +08:00
move ui functions out into their own autoload
All of the autoload shit needs to be cleaned up... break it out first
This commit is contained in:
parent
d162c08fd7
commit
86488b1aa0
|
@ -57,80 +57,6 @@ function! nerdtree#compareNodes(n1, n2)
|
|||
return a:n1.path.compareTo(a:n2.path)
|
||||
endfunction
|
||||
|
||||
" FUNCTION: nerdtree#createDefaultBindings() {{{2
|
||||
function! nerdtree#createDefaultBindings()
|
||||
let s = '<SNR>' . s:SID() . '_'
|
||||
|
||||
call NERDTreeAddKeyMap({ 'key': '<MiddleRelease>', 'scope': "all", 'callback': s."handleMiddleMouse" })
|
||||
call NERDTreeAddKeyMap({ 'key': '<LeftRelease>', 'scope': "all", 'callback': s."handleLeftClick" })
|
||||
call NERDTreeAddKeyMap({ 'key': '<2-LeftMouse>', 'scope': "DirNode", 'callback': s."activateDirNode" })
|
||||
call NERDTreeAddKeyMap({ 'key': '<2-LeftMouse>', 'scope': "FileNode", 'callback': s."activateFileNode" })
|
||||
call NERDTreeAddKeyMap({ 'key': '<2-LeftMouse>', 'scope': "Bookmark", 'callback': s."activateBookmark" })
|
||||
call NERDTreeAddKeyMap({ 'key': '<2-LeftMouse>', 'scope': "all", 'callback': s."activateAll" })
|
||||
|
||||
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapActivateNode, 'scope': "DirNode", 'callback': s."activateDirNode" })
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapActivateNode, 'scope': "FileNode", 'callback': s."activateFileNode" })
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapActivateNode, 'scope': "Bookmark", 'callback': s."activateBookmark" })
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapActivateNode, 'scope': "all", 'callback': s."activateAll" })
|
||||
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapOpenSplit, 'scope': "Node", 'callback': s."openHSplit" })
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapOpenVSplit, 'scope': "Node", 'callback': s."openVSplit" })
|
||||
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapOpenSplit, 'scope': "Bookmark", 'callback': s."openHSplit" })
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapOpenVSplit, 'scope': "Bookmark", 'callback': s."openVSplit" })
|
||||
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapPreview, 'scope': "Node", 'callback': s."previewNodeCurrent" })
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapPreviewVSplit, 'scope': "Node", 'callback': s."previewNodeVSplit" })
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapPreviewSplit, 'scope': "Node", 'callback': s."previewNodeHSplit" })
|
||||
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapPreview, 'scope': "Bookmark", 'callback': s."previewNodeCurrent" })
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapPreviewVSplit, 'scope': "Bookmark", 'callback': s."previewNodeVSplit" })
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapPreviewSplit, 'scope': "Bookmark", 'callback': s."previewNodeHSplit" })
|
||||
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapOpenRecursively, 'scope': "DirNode", 'callback': s."openNodeRecursively" })
|
||||
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapUpdir, 'scope': "all", 'callback': s."upDirCurrentRootClosed" })
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapUpdirKeepOpen, 'scope': "all", 'callback': s."upDirCurrentRootOpen" })
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapChangeRoot, 'scope': "Node", 'callback': s."chRoot" })
|
||||
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapChdir, 'scope': "Node", 'callback': s."chCwd" })
|
||||
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapQuit, 'scope': "all", 'callback': s."closeTreeWindow" })
|
||||
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapCWD, 'scope': "all", 'callback': "nerdtree#chRootCwd" })
|
||||
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapRefreshRoot, 'scope': "all", 'callback': s."refreshRoot" })
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapRefresh, 'scope': "Node", 'callback': s."refreshCurrent" })
|
||||
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapHelp, 'scope': "all", 'callback': s."displayHelp" })
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapToggleZoom, 'scope': "all", 'callback': s."toggleZoom" })
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapToggleHidden, 'scope': "all", 'callback': s."toggleShowHidden" })
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapToggleFilters, 'scope': "all", 'callback': s."toggleIgnoreFilter" })
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapToggleFiles, 'scope': "all", 'callback': s."toggleShowFiles" })
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapToggleBookmarks, 'scope': "all", 'callback': s."toggleShowBookmarks" })
|
||||
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapCloseDir, 'scope': "Node", 'callback': s."closeCurrentDir" })
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapCloseChildren, 'scope': "DirNode", 'callback': s."closeChildren" })
|
||||
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapMenu, 'scope': "Node", 'callback': s."showMenu" })
|
||||
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapJumpParent, 'scope': "Node", 'callback': s."jumpToParent" })
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapJumpFirstChild, 'scope': "Node", 'callback': s."jumpToFirstChild" })
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapJumpLastChild, 'scope': "Node", 'callback': s."jumpToLastChild" })
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapJumpRoot, 'scope': "all", 'callback': s."jumpToRoot" })
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapJumpNextSibling, 'scope': "Node", 'callback': s."jumpToNextSibling" })
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapJumpPrevSibling, 'scope': "Node", 'callback': s."jumpToPrevSibling" })
|
||||
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapOpenInTab, 'scope': "Node", 'callback': s."openInNewTab" })
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapOpenInTabSilent, 'scope': "Node", 'callback': s."openInNewTabSilent" })
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapOpenInTab, 'scope': "Bookmark", 'callback': s."openInNewTab" })
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapOpenInTabSilent, 'scope': "Bookmark", 'callback': s."openInNewTabSilent" })
|
||||
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapOpenExpl, 'scope': "DirNode", 'callback': s."openExplorer" })
|
||||
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapDeleteBookmark, 'scope': "Bookmark", 'callback': s."deleteBookmark" })
|
||||
endfunction
|
||||
|
||||
" FUNCTION: nerdtree#deprecated(func, [msg]) {{{2
|
||||
" Issue a deprecation warning for a:func. If a second arg is given, use this
|
||||
|
@ -243,7 +169,7 @@ endfunction
|
|||
" FUNCTION: nerdtree#postSourceActions() {{{2
|
||||
function! nerdtree#postSourceActions()
|
||||
call g:NERDTreeBookmark.CacheBookmarks(0)
|
||||
call nerdtree#createDefaultBindings()
|
||||
call nerdtree#ui_glue#createDefaultBindings()
|
||||
|
||||
"load all nerdtree plugins
|
||||
runtime! nerdtree_plugin/**/*.vim
|
||||
|
@ -254,14 +180,6 @@ function! nerdtree#runningWindows()
|
|||
return has("win16") || has("win32") || has("win64")
|
||||
endfunction
|
||||
|
||||
" Function: s:SID() {{{2
|
||||
function s:SID()
|
||||
if !exists("s:sid")
|
||||
let s:sid = matchstr(expand('<sfile>'), '<SNR>\zs\d\+\ze_SID$')
|
||||
endif
|
||||
return s:sid
|
||||
endfun
|
||||
|
||||
" FUNCTION: nerdtree#tabpagevar(tabnr, var) {{{2
|
||||
function! nerdtree#tabpagevar(tabnr, var)
|
||||
let currentTab = tabpagenr()
|
||||
|
@ -957,432 +875,4 @@ function! nerdtree#stripMarkupFromLine(line, removeLeadingSpaces)
|
|||
return line
|
||||
endfunction
|
||||
|
||||
"SECTION: Interface bindings {{{1
|
||||
"============================================================
|
||||
|
||||
"FUNCTION: s:activateAll() {{{2
|
||||
"handle the user activating the updir line
|
||||
function! s:activateAll()
|
||||
if getline(".") ==# nerdtree#treeUpDirLine()
|
||||
return nerdtree#upDir(0)
|
||||
endif
|
||||
endfunction
|
||||
"FUNCTION: s:activateDirNode() {{{2
|
||||
"handle the user activating a tree node
|
||||
function! s:activateDirNode(node)
|
||||
call a:node.activate({'reuse': 1})
|
||||
endfunction
|
||||
|
||||
"FUNCTION: s:activateFileNode() {{{2
|
||||
"handle the user activating a tree node
|
||||
function! s:activateFileNode(node)
|
||||
call a:node.activate({'reuse': 1, 'where': 'p'})
|
||||
endfunction
|
||||
|
||||
"FUNCTION: s:activateBookmark() {{{2
|
||||
"handle the user activating a bookmark
|
||||
function! s:activateBookmark(bm)
|
||||
call a:bm.activate(!a:bm.path.isDirectory ? {'where': 'p'} : {})
|
||||
endfunction
|
||||
|
||||
" FUNCTION: nerdtree#bookmarkNode(name) {{{2
|
||||
" Associate the current node with the given name
|
||||
function! nerdtree#bookmarkNode(...)
|
||||
let currentNode = g:NERDTreeFileNode.GetSelected()
|
||||
if currentNode != {}
|
||||
let name = a:1
|
||||
if empty(name)
|
||||
let name = currentNode.path.getLastPathComponent(0)
|
||||
endif
|
||||
try
|
||||
call currentNode.bookmark(name)
|
||||
call nerdtree#renderView()
|
||||
catch /^NERDTree.IllegalBookmarkNameError/
|
||||
call nerdtree#echo("bookmark names must not contain spaces")
|
||||
endtry
|
||||
else
|
||||
call nerdtree#echo("select a node first")
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" FUNCTION: s:chCwd(node) {{{2
|
||||
function! s:chCwd(node)
|
||||
try
|
||||
call a:node.path.changeToDir()
|
||||
catch /^NERDTree.PathChangeError/
|
||||
call nerdtree#echoWarning("could not change cwd")
|
||||
endtry
|
||||
endfunction
|
||||
|
||||
" FUNCTION: s:chRoot(node) {{{2
|
||||
" changes the current root to the selected one
|
||||
function! s:chRoot(node)
|
||||
call a:node.makeRoot()
|
||||
call nerdtree#renderView()
|
||||
call b:NERDTreeRoot.putCursorHere(0, 0)
|
||||
endfunction
|
||||
|
||||
" FUNCTION: s:chRootCwd() {{{2
|
||||
" changes the current root to CWD
|
||||
function! nerdtree#chRootCwd()
|
||||
try
|
||||
let cwd = g:NERDTreePath.New(getcwd())
|
||||
catch /^NERDTree.InvalidArgumentsError/
|
||||
call nerdtree#echo("current directory does not exist.")
|
||||
return
|
||||
endtry
|
||||
if cwd.str() == g:NERDTreeFileNode.GetRootForTab().path.str()
|
||||
return
|
||||
endif
|
||||
call nerdtree#chRoot(g:NERDTreeDirNode.New(cwd))
|
||||
endfunction
|
||||
|
||||
" FUNCTION: nerdtree#clearBookmarks(bookmarks) {{{2
|
||||
function! nerdtree#clearBookmarks(bookmarks)
|
||||
if a:bookmarks ==# ''
|
||||
let currentNode = g:NERDTreeFileNode.GetSelected()
|
||||
if currentNode != {}
|
||||
call currentNode.clearBookmarks()
|
||||
endif
|
||||
else
|
||||
for name in split(a:bookmarks, ' ')
|
||||
let bookmark = g:NERDTreeBookmark.BookmarkFor(name)
|
||||
call bookmark.delete()
|
||||
endfor
|
||||
endif
|
||||
call nerdtree#renderView()
|
||||
endfunction
|
||||
|
||||
" FUNCTION: s:closeChildren(node) {{{2
|
||||
" closes all childnodes of the current node
|
||||
function! s:closeChildren(node)
|
||||
call a:node.closeChildren()
|
||||
call nerdtree#renderView()
|
||||
call a:node.putCursorHere(0, 0)
|
||||
endfunction
|
||||
|
||||
" FUNCTION: s:closeCurrentDir(node) {{{2
|
||||
" closes the parent dir of the current node
|
||||
function! s:closeCurrentDir(node)
|
||||
let parent = a:node.parent
|
||||
if parent ==# {} || parent.isRoot()
|
||||
call nerdtree#echo("cannot close tree root")
|
||||
else
|
||||
while g:NERDTreeCascadeOpenSingleChildDir && !parent.parent.isRoot()
|
||||
if parent.parent.getVisibleChildCount() == 1
|
||||
call parent.close()
|
||||
let parent = parent.parent
|
||||
else
|
||||
break
|
||||
endif
|
||||
endwhile
|
||||
call parent.close()
|
||||
call nerdtree#renderView()
|
||||
call parent.putCursorHere(0, 0)
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" FUNCTION: s:closeTreeWindow() {{{2
|
||||
" close the tree window
|
||||
function! s:closeTreeWindow()
|
||||
if b:NERDTreeType ==# "secondary" && b:NERDTreePreviousBuf != -1
|
||||
exec "buffer " . b:NERDTreePreviousBuf
|
||||
else
|
||||
if winnr("$") > 1
|
||||
call nerdtree#closeTree()
|
||||
else
|
||||
call nerdtree#echo("Cannot close last window")
|
||||
endif
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" FUNCTION: s:deleteBookmark(bm) {{{2
|
||||
" if the cursor is on a bookmark, prompt to delete
|
||||
function! s:deleteBookmark(bm)
|
||||
echo "Are you sure you wish to delete the bookmark:\n\"" . a:bm.name . "\" (yN):"
|
||||
|
||||
if nr2char(getchar()) ==# 'y'
|
||||
try
|
||||
call a:bm.delete()
|
||||
call nerdtree#renderView()
|
||||
redraw
|
||||
catch /^NERDTree/
|
||||
call nerdtree#echoWarning("Could not remove bookmark")
|
||||
endtry
|
||||
else
|
||||
call nerdtree#echo("delete aborted" )
|
||||
endif
|
||||
|
||||
endfunction
|
||||
|
||||
" FUNCTION: s:displayHelp() {{{2
|
||||
" toggles the help display
|
||||
function! s:displayHelp()
|
||||
let b:treeShowHelp = b:treeShowHelp ? 0 : 1
|
||||
call nerdtree#renderView()
|
||||
call nerdtree#centerView()
|
||||
endfunction
|
||||
|
||||
"FUNCTION: s:handleLeftClick() {{{2
|
||||
"Checks if the click should open the current node
|
||||
function! s:handleLeftClick()
|
||||
let currentNode = g:NERDTreeFileNode.GetSelected()
|
||||
if currentNode != {}
|
||||
|
||||
"the dir arrows are multibyte chars, and vim's string functions only
|
||||
"deal with single bytes - so split the line up with the hack below and
|
||||
"take the line substring manually
|
||||
let line = split(getline(line(".")), '\zs')
|
||||
let startToCur = ""
|
||||
for i in range(0,len(line)-1)
|
||||
let startToCur .= line[i]
|
||||
endfor
|
||||
|
||||
if currentNode.path.isDirectory
|
||||
if startToCur =~# nerdtree#treeMarkupReg() && startToCur =~# '[+~▾▸] \?$'
|
||||
call currentNode.activate()
|
||||
return
|
||||
endif
|
||||
endif
|
||||
|
||||
if (g:NERDTreeMouseMode ==# 2 && currentNode.path.isDirectory) || g:NERDTreeMouseMode ==# 3
|
||||
let char = strpart(startToCur, strlen(startToCur)-1, 1)
|
||||
if char !~# nerdtree#treeMarkupReg()
|
||||
if currentNode.path.isDirectory
|
||||
call currentNode.activate()
|
||||
else
|
||||
call currentNode.activate({'reuse': 1, 'where': 'p'})
|
||||
endif
|
||||
return
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" FUNCTION: s:handleMiddleMouse() {{{2
|
||||
function! s:handleMiddleMouse()
|
||||
let curNode = g:NERDTreeFileNode.GetSelected()
|
||||
if curNode ==# {}
|
||||
call nerdtree#echo("Put the cursor on a node first" )
|
||||
return
|
||||
endif
|
||||
|
||||
if curNode.path.isDirectory
|
||||
call nerdtree#openExplorer(curNode)
|
||||
else
|
||||
call curNode.open({'where': 'h'})
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" FUNCTION: s:jumpToFirstChild() {{{2
|
||||
" wrapper for the jump to child method
|
||||
function! s:jumpToFirstChild(node)
|
||||
call nerdtree#jumpToChild(a:node, 0)
|
||||
endfunction
|
||||
|
||||
" FUNCTION: s:jumpToLastChild() {{{2
|
||||
" wrapper for the jump to child method
|
||||
function! s:jumpToLastChild(node)
|
||||
call nerdtree#jumpToChild(a:node, 1)
|
||||
endfunction
|
||||
|
||||
" FUNCTION: s:jumpToParent(node) {{{2
|
||||
" moves the cursor to the parent of the current node
|
||||
function! s:jumpToParent(node)
|
||||
if !empty(a:node.parent)
|
||||
call a:node.parent.putCursorHere(1, 0)
|
||||
call nerdtree#centerView()
|
||||
else
|
||||
call nerdtree#echo("cannot jump to parent")
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" FUNCTION: s:jumpToRoot() {{{2
|
||||
" moves the cursor to the root node
|
||||
function! s:jumpToRoot()
|
||||
call b:NERDTreeRoot.putCursorHere(1, 0)
|
||||
call nerdtree#centerView()
|
||||
endfunction
|
||||
|
||||
" FUNCTION: s:jumpToNextSibling(node) {{{2
|
||||
function! s:jumpToNextSibling(node)
|
||||
call nerdtree#jumpToSibling(a:node, 1)
|
||||
endfunction
|
||||
|
||||
" FUNCTION: s:jumpToPrevSibling(node) {{{2
|
||||
function! s:jumpToPrevSibling(node)
|
||||
call nerdtree#jumpToSibling(a:node, 0)
|
||||
endfunction
|
||||
|
||||
" FUNCTION: nerdtree#openBookmark(name) {{{2
|
||||
" put the cursor on the given bookmark and, if its a file, open it
|
||||
function! nerdtree#openBookmark(name)
|
||||
try
|
||||
let targetNode = g:NERDTreeBookmark.GetNodeForName(a:name, 0)
|
||||
call targetNode.putCursorHere(0, 1)
|
||||
redraw!
|
||||
catch /^NERDTree.BookmarkedNodeNotFoundError/
|
||||
call nerdtree#echo("note - target node is not cached")
|
||||
let bookmark = g:NERDTreeBookmark.BookmarkFor(a:name)
|
||||
let targetNode = g:NERDTreeFileNode.New(bookmark.path)
|
||||
endtry
|
||||
if targetNode.path.isDirectory
|
||||
call targetNode.openExplorer()
|
||||
else
|
||||
call targetNode.open({'where': 'p'})
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" FUNCTION: s:openHSplit(target) {{{2
|
||||
function! s:openHSplit(target)
|
||||
call a:target.activate({'where': 'h'})
|
||||
endfunction
|
||||
|
||||
" FUNCTION: s:openVSplit(target) {{{2
|
||||
function! s:openVSplit(target)
|
||||
call a:target.activate({'where': 'v'})
|
||||
endfunction
|
||||
|
||||
" FUNCTION: s:openExplorer(node) {{{2
|
||||
function! s:openExplorer(node)
|
||||
call a:node.openExplorer()
|
||||
endfunction
|
||||
|
||||
" FUNCTION: s:openInNewTab(target) {{{2
|
||||
function! s:openInNewTab(target)
|
||||
call a:target.activate({'where': 't'})
|
||||
endfunction
|
||||
|
||||
" FUNCTION: s:openInNewTabSilent(target) {{{2
|
||||
function! s:openInNewTabSilent(target)
|
||||
call a:target.activate({'where': 't', 'stay': 1})
|
||||
endfunction
|
||||
|
||||
" FUNCTION: s:openNodeRecursively(node) {{{2
|
||||
function! s:openNodeRecursively(node)
|
||||
call nerdtree#echo("Recursively opening node. Please wait...")
|
||||
call a:node.openRecursively()
|
||||
call nerdtree#renderView()
|
||||
redraw
|
||||
call nerdtree#echo("Recursively opening node. Please wait... DONE")
|
||||
endfunction
|
||||
|
||||
"FUNCTION: s:previewNodeCurrent(node) {{{2
|
||||
function! s:previewNodeCurrent(node)
|
||||
call a:node.open({'stay': 1, 'where': 'p', 'keepopen': 1})
|
||||
endfunction
|
||||
|
||||
"FUNCTION: s:previewNodeHSplit(node) {{{2
|
||||
function! s:previewNodeHSplit(node)
|
||||
call a:node.open({'stay': 1, 'where': 'h', 'keepopen': 1})
|
||||
endfunction
|
||||
|
||||
"FUNCTION: s:previewNodeVSplit(node) {{{2
|
||||
function! s:previewNodeVSplit(node)
|
||||
call a:node.open({'stay': 1, 'where': 'v', 'keepopen': 1})
|
||||
endfunction
|
||||
|
||||
" FUNCTION: nerdtree#revealBookmark(name) {{{2
|
||||
" put the cursor on the node associate with the given name
|
||||
function! nerdtree#revealBookmark(name)
|
||||
try
|
||||
let targetNode = g:NERDTreeBookmark.GetNodeForName(a:name, 0)
|
||||
call targetNode.putCursorHere(0, 1)
|
||||
catch /^NERDTree.BookmarkNotFoundError/
|
||||
call nerdtree#echo("Bookmark isnt cached under the current root")
|
||||
endtry
|
||||
endfunction
|
||||
|
||||
" FUNCTION: s:refreshRoot() {{{2
|
||||
" Reloads the current root. All nodes below this will be lost and the root dir
|
||||
" will be reloaded.
|
||||
function! s:refreshRoot()
|
||||
call nerdtree#echo("Refreshing the root node. This could take a while...")
|
||||
call b:NERDTreeRoot.refresh()
|
||||
call nerdtree#renderView()
|
||||
redraw
|
||||
call nerdtree#echo("Refreshing the root node. This could take a while... DONE")
|
||||
endfunction
|
||||
|
||||
" FUNCTION: s:refreshCurrent(node) {{{2
|
||||
" refreshes the root for the current node
|
||||
function! s:refreshCurrent(node)
|
||||
let node = a:node
|
||||
if !node.path.isDirectory
|
||||
let node = node.parent
|
||||
endif
|
||||
|
||||
call nerdtree#echo("Refreshing node. This could take a while...")
|
||||
call node.refresh()
|
||||
call nerdtree#renderView()
|
||||
redraw
|
||||
call nerdtree#echo("Refreshing node. This could take a while... DONE")
|
||||
endfunction
|
||||
|
||||
" FUNCTION: s:showMenu(node) {{{2
|
||||
function! s:showMenu(node)
|
||||
let mc = g:NERDTreeMenuController.New(g:NERDTreeMenuItem.AllEnabled())
|
||||
call mc.showMenu()
|
||||
endfunction
|
||||
|
||||
" FUNCTION: s:toggleIgnoreFilter() {{{2
|
||||
" toggles the use of the NERDTreeIgnore option
|
||||
function! s:toggleIgnoreFilter()
|
||||
let b:NERDTreeIgnoreEnabled = !b:NERDTreeIgnoreEnabled
|
||||
call nerdtree#renderViewSavingPosition()
|
||||
call nerdtree#centerView()
|
||||
endfunction
|
||||
|
||||
" FUNCTION: s:toggleShowBookmarks() {{{2
|
||||
" toggles the display of bookmarks
|
||||
function! s:toggleShowBookmarks()
|
||||
let b:NERDTreeShowBookmarks = !b:NERDTreeShowBookmarks
|
||||
if b:NERDTreeShowBookmarks
|
||||
call nerdtree#renderView()
|
||||
call nerdtree#putCursorOnBookmarkTable()
|
||||
else
|
||||
call nerdtree#renderViewSavingPosition()
|
||||
endif
|
||||
call nerdtree#centerView()
|
||||
endfunction
|
||||
|
||||
" FUNCTION: s:toggleShowFiles() {{{2
|
||||
" toggles the display of hidden files
|
||||
function! s:toggleShowFiles()
|
||||
let b:NERDTreeShowFiles = !b:NERDTreeShowFiles
|
||||
call nerdtree#renderViewSavingPosition()
|
||||
call nerdtree#centerView()
|
||||
endfunction
|
||||
|
||||
" FUNCTION: s:toggleShowHidden() {{{2
|
||||
" toggles the display of hidden files
|
||||
function! s:toggleShowHidden()
|
||||
let b:NERDTreeShowHidden = !b:NERDTreeShowHidden
|
||||
call nerdtree#renderViewSavingPosition()
|
||||
call nerdtree#centerView()
|
||||
endfunction
|
||||
|
||||
" FUNCTION: s:toggleZoom() {{{2
|
||||
" zoom (maximize/minimize) the NERDTree window
|
||||
function! s:toggleZoom()
|
||||
if exists("b:NERDTreeZoomed") && b:NERDTreeZoomed
|
||||
let size = exists("b:NERDTreeOldWindowSize") ? b:NERDTreeOldWindowSize : g:NERDTreeWinSize
|
||||
exec "silent vertical resize ". size
|
||||
let b:NERDTreeZoomed = 0
|
||||
else
|
||||
exec "vertical resize"
|
||||
let b:NERDTreeZoomed = 1
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" FUNCTION: s:upDirCurrentRootOpen() {{{2
|
||||
function! s:upDirCurrentRootOpen()
|
||||
call nerdtree#upDir(1)
|
||||
endfunction
|
||||
|
||||
" FUNCTION: s:upDirCurrentRootClosed() {{{2
|
||||
function! s:upDirCurrentRootClosed()
|
||||
call nerdtree#upDir(0)
|
||||
endfunction
|
||||
|
||||
" vim: set sw=4 sts=4 et fdm=marker:
|
||||
|
|
518
autoload/nerdtree/ui_glue.vim
Normal file
518
autoload/nerdtree/ui_glue.vim
Normal file
|
@ -0,0 +1,518 @@
|
|||
if exists("g:loaded_nerdtree_ui_glue_autoload")
|
||||
finish
|
||||
endif
|
||||
let g:loaded_nerdtree_ui_glue_autoload = 1
|
||||
|
||||
" FUNCTION: nerdtree#ui_glue#createDefaultBindings() {{{1
|
||||
function! nerdtree#ui_glue#createDefaultBindings()
|
||||
let s = '<SNR>' . s:SID() . '_'
|
||||
|
||||
call NERDTreeAddKeyMap({ 'key': '<MiddleRelease>', 'scope': "all", 'callback': s."handleMiddleMouse" })
|
||||
call NERDTreeAddKeyMap({ 'key': '<LeftRelease>', 'scope': "all", 'callback': s."handleLeftClick" })
|
||||
call NERDTreeAddKeyMap({ 'key': '<2-LeftMouse>', 'scope': "DirNode", 'callback': s."activateDirNode" })
|
||||
call NERDTreeAddKeyMap({ 'key': '<2-LeftMouse>', 'scope': "FileNode", 'callback': s."activateFileNode" })
|
||||
call NERDTreeAddKeyMap({ 'key': '<2-LeftMouse>', 'scope': "Bookmark", 'callback': s."activateBookmark" })
|
||||
call NERDTreeAddKeyMap({ 'key': '<2-LeftMouse>', 'scope': "all", 'callback': s."activateAll" })
|
||||
|
||||
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapActivateNode, 'scope': "DirNode", 'callback': s."activateDirNode" })
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapActivateNode, 'scope': "FileNode", 'callback': s."activateFileNode" })
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapActivateNode, 'scope': "Bookmark", 'callback': s."activateBookmark" })
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapActivateNode, 'scope': "all", 'callback': s."activateAll" })
|
||||
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapOpenSplit, 'scope': "Node", 'callback': s."openHSplit" })
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapOpenVSplit, 'scope': "Node", 'callback': s."openVSplit" })
|
||||
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapOpenSplit, 'scope': "Bookmark", 'callback': s."openHSplit" })
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapOpenVSplit, 'scope': "Bookmark", 'callback': s."openVSplit" })
|
||||
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapPreview, 'scope': "Node", 'callback': s."previewNodeCurrent" })
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapPreviewVSplit, 'scope': "Node", 'callback': s."previewNodeVSplit" })
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapPreviewSplit, 'scope': "Node", 'callback': s."previewNodeHSplit" })
|
||||
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapPreview, 'scope': "Bookmark", 'callback': s."previewNodeCurrent" })
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapPreviewVSplit, 'scope': "Bookmark", 'callback': s."previewNodeVSplit" })
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapPreviewSplit, 'scope': "Bookmark", 'callback': s."previewNodeHSplit" })
|
||||
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapOpenRecursively, 'scope': "DirNode", 'callback': s."openNodeRecursively" })
|
||||
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapUpdir, 'scope': "all", 'callback': s."upDirCurrentRootClosed" })
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapUpdirKeepOpen, 'scope': "all", 'callback': s."upDirCurrentRootOpen" })
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapChangeRoot, 'scope': "Node", 'callback': s."chRoot" })
|
||||
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapChdir, 'scope': "Node", 'callback': s."chCwd" })
|
||||
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapQuit, 'scope': "all", 'callback': s."closeTreeWindow" })
|
||||
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapCWD, 'scope': "all", 'callback': "nerdtree#ui_glue#chRootCwd" })
|
||||
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapRefreshRoot, 'scope': "all", 'callback': s."refreshRoot" })
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapRefresh, 'scope': "Node", 'callback': s."refreshCurrent" })
|
||||
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapHelp, 'scope': "all", 'callback': s."displayHelp" })
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapToggleZoom, 'scope': "all", 'callback': s."toggleZoom" })
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapToggleHidden, 'scope': "all", 'callback': s."toggleShowHidden" })
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapToggleFilters, 'scope': "all", 'callback': s."toggleIgnoreFilter" })
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapToggleFiles, 'scope': "all", 'callback': s."toggleShowFiles" })
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapToggleBookmarks, 'scope': "all", 'callback': s."toggleShowBookmarks" })
|
||||
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapCloseDir, 'scope': "Node", 'callback': s."closeCurrentDir" })
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapCloseChildren, 'scope': "DirNode", 'callback': s."closeChildren" })
|
||||
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapMenu, 'scope': "Node", 'callback': s."showMenu" })
|
||||
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapJumpParent, 'scope': "Node", 'callback': s."jumpToParent" })
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapJumpFirstChild, 'scope': "Node", 'callback': s."jumpToFirstChild" })
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapJumpLastChild, 'scope': "Node", 'callback': s."jumpToLastChild" })
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapJumpRoot, 'scope': "all", 'callback': s."jumpToRoot" })
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapJumpNextSibling, 'scope': "Node", 'callback': s."jumpToNextSibling" })
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapJumpPrevSibling, 'scope': "Node", 'callback': s."jumpToPrevSibling" })
|
||||
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapOpenInTab, 'scope': "Node", 'callback': s."openInNewTab" })
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapOpenInTabSilent, 'scope': "Node", 'callback': s."openInNewTabSilent" })
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapOpenInTab, 'scope': "Bookmark", 'callback': s."openInNewTab" })
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapOpenInTabSilent, 'scope': "Bookmark", 'callback': s."openInNewTabSilent" })
|
||||
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapOpenExpl, 'scope': "DirNode", 'callback': s."openExplorer" })
|
||||
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapDeleteBookmark, 'scope': "Bookmark", 'callback': s."deleteBookmark" })
|
||||
endfunction
|
||||
|
||||
|
||||
"SECTION: Interface bindings {{{1
|
||||
"============================================================
|
||||
|
||||
"FUNCTION: s:activateAll() {{{1
|
||||
"handle the user activating the updir line
|
||||
function! s:activateAll()
|
||||
if getline(".") ==# nerdtree#treeUpDirLine()
|
||||
return nerdtree#upDir(0)
|
||||
endif
|
||||
endfunction
|
||||
"FUNCTION: s:activateDirNode() {{{1
|
||||
"handle the user activating a tree node
|
||||
function! s:activateDirNode(node)
|
||||
call a:node.activate({'reuse': 1})
|
||||
endfunction
|
||||
|
||||
"FUNCTION: s:activateFileNode() {{{1
|
||||
"handle the user activating a tree node
|
||||
function! s:activateFileNode(node)
|
||||
call a:node.activate({'reuse': 1, 'where': 'p'})
|
||||
endfunction
|
||||
|
||||
"FUNCTION: s:activateBookmark() {{{1
|
||||
"handle the user activating a bookmark
|
||||
function! s:activateBookmark(bm)
|
||||
call a:bm.activate(!a:bm.path.isDirectory ? {'where': 'p'} : {})
|
||||
endfunction
|
||||
|
||||
" FUNCTION: nerdtree#ui_glue#bookmarkNode(name) {{{1
|
||||
" Associate the current node with the given name
|
||||
function! nerdtree#ui_glue#bookmarkNode(...)
|
||||
let currentNode = g:NERDTreeFileNode.GetSelected()
|
||||
if currentNode != {}
|
||||
let name = a:1
|
||||
if empty(name)
|
||||
let name = currentNode.path.getLastPathComponent(0)
|
||||
endif
|
||||
try
|
||||
call currentNode.bookmark(name)
|
||||
call nerdtree#renderView()
|
||||
catch /^NERDTree.IllegalBookmarkNameError/
|
||||
call nerdtree#echo("bookmark names must not contain spaces")
|
||||
endtry
|
||||
else
|
||||
call nerdtree#echo("select a node first")
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" FUNCTION: s:chCwd(node) {{{1
|
||||
function! s:chCwd(node)
|
||||
try
|
||||
call a:node.path.changeToDir()
|
||||
catch /^NERDTree.PathChangeError/
|
||||
call nerdtree#echoWarning("could not change cwd")
|
||||
endtry
|
||||
endfunction
|
||||
|
||||
" FUNCTION: s:chRoot(node) {{{1
|
||||
" changes the current root to the selected one
|
||||
function! s:chRoot(node)
|
||||
call a:node.makeRoot()
|
||||
call nerdtree#renderView()
|
||||
call b:NERDTreeRoot.putCursorHere(0, 0)
|
||||
endfunction
|
||||
|
||||
" FUNCTION: s:nerdtree#ui_glue#chRootCwd() {{{1
|
||||
" changes the current root to CWD
|
||||
function! nerdtree#ui_glue#chRootCwd()
|
||||
try
|
||||
let cwd = g:NERDTreePath.New(getcwd())
|
||||
catch /^NERDTree.InvalidArgumentsError/
|
||||
call nerdtree#echo("current directory does not exist.")
|
||||
return
|
||||
endtry
|
||||
if cwd.str() == g:NERDTreeFileNode.GetRootForTab().path.str()
|
||||
return
|
||||
endif
|
||||
call nerdtree#chRoot(g:NERDTreeDirNode.New(cwd))
|
||||
endfunction
|
||||
|
||||
" FUNCTION: nnerdtree#ui_glue#clearBookmarks(bookmarks) {{{1
|
||||
function! nerdtree#ui_glue#clearBookmarks(bookmarks)
|
||||
if a:bookmarks ==# ''
|
||||
let currentNode = g:NERDTreeFileNode.GetSelected()
|
||||
if currentNode != {}
|
||||
call currentNode.clearBookmarks()
|
||||
endif
|
||||
else
|
||||
for name in split(a:bookmarks, ' ')
|
||||
let bookmark = g:NERDTreeBookmark.BookmarkFor(name)
|
||||
call bookmark.delete()
|
||||
endfor
|
||||
endif
|
||||
call nerdtree#renderView()
|
||||
endfunction
|
||||
|
||||
" FUNCTION: s:closeChildren(node) {{{1
|
||||
" closes all childnodes of the current node
|
||||
function! s:closeChildren(node)
|
||||
call a:node.closeChildren()
|
||||
call nerdtree#renderView()
|
||||
call a:node.putCursorHere(0, 0)
|
||||
endfunction
|
||||
|
||||
" FUNCTION: s:closeCurrentDir(node) {{{1
|
||||
" closes the parent dir of the current node
|
||||
function! s:closeCurrentDir(node)
|
||||
let parent = a:node.parent
|
||||
if parent ==# {} || parent.isRoot()
|
||||
call nerdtree#echo("cannot close tree root")
|
||||
else
|
||||
while g:NERDTreeCascadeOpenSingleChildDir && !parent.parent.isRoot()
|
||||
if parent.parent.getVisibleChildCount() == 1
|
||||
call parent.close()
|
||||
let parent = parent.parent
|
||||
else
|
||||
break
|
||||
endif
|
||||
endwhile
|
||||
call parent.close()
|
||||
call nerdtree#renderView()
|
||||
call parent.putCursorHere(0, 0)
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" FUNCTION: s:closeTreeWindow() {{{1
|
||||
" close the tree window
|
||||
function! s:closeTreeWindow()
|
||||
if b:NERDTreeType ==# "secondary" && b:NERDTreePreviousBuf != -1
|
||||
exec "buffer " . b:NERDTreePreviousBuf
|
||||
else
|
||||
if winnr("$") > 1
|
||||
call nerdtree#closeTree()
|
||||
else
|
||||
call nerdtree#echo("Cannot close last window")
|
||||
endif
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" FUNCTION: s:deleteBookmark(bm) {{{1
|
||||
" if the cursor is on a bookmark, prompt to delete
|
||||
function! s:deleteBookmark(bm)
|
||||
echo "Are you sure you wish to delete the bookmark:\n\"" . a:bm.name . "\" (yN):"
|
||||
|
||||
if nr2char(getchar()) ==# 'y'
|
||||
try
|
||||
call a:bm.delete()
|
||||
call nerdtree#renderView()
|
||||
redraw
|
||||
catch /^NERDTree/
|
||||
call nerdtree#echoWarning("Could not remove bookmark")
|
||||
endtry
|
||||
else
|
||||
call nerdtree#echo("delete aborted" )
|
||||
endif
|
||||
|
||||
endfunction
|
||||
|
||||
" FUNCTION: s:displayHelp() {{{1
|
||||
" toggles the help display
|
||||
function! s:displayHelp()
|
||||
let b:treeShowHelp = b:treeShowHelp ? 0 : 1
|
||||
call nerdtree#renderView()
|
||||
call nerdtree#centerView()
|
||||
endfunction
|
||||
|
||||
"FUNCTION: s:handleLeftClick() {{{1
|
||||
"Checks if the click should open the current node
|
||||
function! s:handleLeftClick()
|
||||
let currentNode = g:NERDTreeFileNode.GetSelected()
|
||||
if currentNode != {}
|
||||
|
||||
"the dir arrows are multibyte chars, and vim's string functions only
|
||||
"deal with single bytes - so split the line up with the hack below and
|
||||
"take the line substring manually
|
||||
let line = split(getline(line(".")), '\zs')
|
||||
let startToCur = ""
|
||||
for i in range(0,len(line)-1)
|
||||
let startToCur .= line[i]
|
||||
endfor
|
||||
|
||||
if currentNode.path.isDirectory
|
||||
if startToCur =~# nerdtree#treeMarkupReg() && startToCur =~# '[+~▾▸] \?$'
|
||||
call currentNode.activate()
|
||||
return
|
||||
endif
|
||||
endif
|
||||
|
||||
if (g:NERDTreeMouseMode ==# 2 && currentNode.path.isDirectory) || g:NERDTreeMouseMode ==# 3
|
||||
let char = strpart(startToCur, strlen(startToCur)-1, 1)
|
||||
if char !~# nerdtree#treeMarkupReg()
|
||||
if currentNode.path.isDirectory
|
||||
call currentNode.activate()
|
||||
else
|
||||
call currentNode.activate({'reuse': 1, 'where': 'p'})
|
||||
endif
|
||||
return
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" FUNCTION: s:handleMiddleMouse() {{{1
|
||||
function! s:handleMiddleMouse()
|
||||
let curNode = g:NERDTreeFileNode.GetSelected()
|
||||
if curNode ==# {}
|
||||
call nerdtree#echo("Put the cursor on a node first" )
|
||||
return
|
||||
endif
|
||||
|
||||
if curNode.path.isDirectory
|
||||
call nerdtree#openExplorer(curNode)
|
||||
else
|
||||
call curNode.open({'where': 'h'})
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" FUNCTION: s:jumpToFirstChild() {{{1
|
||||
" wrapper for the jump to child method
|
||||
function! s:jumpToFirstChild(node)
|
||||
call nerdtree#jumpToChild(a:node, 0)
|
||||
endfunction
|
||||
|
||||
" FUNCTION: s:jumpToLastChild() {{{1
|
||||
" wrapper for the jump to child method
|
||||
function! s:jumpToLastChild(node)
|
||||
call nerdtree#jumpToChild(a:node, 1)
|
||||
endfunction
|
||||
|
||||
" FUNCTION: s:jumpToParent(node) {{{1
|
||||
" moves the cursor to the parent of the current node
|
||||
function! s:jumpToParent(node)
|
||||
if !empty(a:node.parent)
|
||||
call a:node.parent.putCursorHere(1, 0)
|
||||
call nerdtree#centerView()
|
||||
else
|
||||
call nerdtree#echo("cannot jump to parent")
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" FUNCTION: s:jumpToRoot() {{{1
|
||||
" moves the cursor to the root node
|
||||
function! s:jumpToRoot()
|
||||
call b:NERDTreeRoot.putCursorHere(1, 0)
|
||||
call nerdtree#centerView()
|
||||
endfunction
|
||||
|
||||
" FUNCTION: s:jumpToNextSibling(node) {{{1
|
||||
function! s:jumpToNextSibling(node)
|
||||
call nerdtree#jumpToSibling(a:node, 1)
|
||||
endfunction
|
||||
|
||||
" FUNCTION: s:jumpToPrevSibling(node) {{{1
|
||||
function! s:jumpToPrevSibling(node)
|
||||
call nerdtree#jumpToSibling(a:node, 0)
|
||||
endfunction
|
||||
|
||||
" FUNCTION: nerdtree#ui_glue#openBookmark(name) {{{1
|
||||
" put the cursor on the given bookmark and, if its a file, open it
|
||||
function! nerdtree#ui_glue#openBookmark(name)
|
||||
try
|
||||
let targetNode = g:NERDTreeBookmark.GetNodeForName(a:name, 0)
|
||||
call targetNode.putCursorHere(0, 1)
|
||||
redraw!
|
||||
catch /^NERDTree.BookmarkedNodeNotFoundError/
|
||||
call nerdtree#echo("note - target node is not cached")
|
||||
let bookmark = g:NERDTreeBookmark.BookmarkFor(a:name)
|
||||
let targetNode = g:NERDTreeFileNode.New(bookmark.path)
|
||||
endtry
|
||||
if targetNode.path.isDirectory
|
||||
call targetNode.openExplorer()
|
||||
else
|
||||
call targetNode.open({'where': 'p'})
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" FUNCTION: s:openHSplit(target) {{{1
|
||||
function! s:openHSplit(target)
|
||||
call a:target.activate({'where': 'h'})
|
||||
endfunction
|
||||
|
||||
" FUNCTION: s:openVSplit(target) {{{1
|
||||
function! s:openVSplit(target)
|
||||
call a:target.activate({'where': 'v'})
|
||||
endfunction
|
||||
|
||||
" FUNCTION: s:openExplorer(node) {{{1
|
||||
function! s:openExplorer(node)
|
||||
call a:node.openExplorer()
|
||||
endfunction
|
||||
|
||||
" FUNCTION: s:openInNewTab(target) {{{1
|
||||
function! s:openInNewTab(target)
|
||||
call a:target.activate({'where': 't'})
|
||||
endfunction
|
||||
|
||||
" FUNCTION: s:openInNewTabSilent(target) {{{1
|
||||
function! s:openInNewTabSilent(target)
|
||||
call a:target.activate({'where': 't', 'stay': 1})
|
||||
endfunction
|
||||
|
||||
" FUNCTION: s:openNodeRecursively(node) {{{1
|
||||
function! s:openNodeRecursively(node)
|
||||
call nerdtree#echo("Recursively opening node. Please wait...")
|
||||
call a:node.openRecursively()
|
||||
call nerdtree#renderView()
|
||||
redraw
|
||||
call nerdtree#echo("Recursively opening node. Please wait... DONE")
|
||||
endfunction
|
||||
|
||||
"FUNCTION: s:previewNodeCurrent(node) {{{1
|
||||
function! s:previewNodeCurrent(node)
|
||||
call a:node.open({'stay': 1, 'where': 'p', 'keepopen': 1})
|
||||
endfunction
|
||||
|
||||
"FUNCTION: s:previewNodeHSplit(node) {{{1
|
||||
function! s:previewNodeHSplit(node)
|
||||
call a:node.open({'stay': 1, 'where': 'h', 'keepopen': 1})
|
||||
endfunction
|
||||
|
||||
"FUNCTION: s:previewNodeVSplit(node) {{{1
|
||||
function! s:previewNodeVSplit(node)
|
||||
call a:node.open({'stay': 1, 'where': 'v', 'keepopen': 1})
|
||||
endfunction
|
||||
|
||||
" FUNCTION: nerdtree#ui_glue#revealBookmark(name) {{{1
|
||||
" put the cursor on the node associate with the given name
|
||||
function! nerdtree#ui_glue#revealBookmark(name)
|
||||
try
|
||||
let targetNode = g:NERDTreeBookmark.GetNodeForName(a:name, 0)
|
||||
call targetNode.putCursorHere(0, 1)
|
||||
catch /^NERDTree.BookmarkNotFoundError/
|
||||
call nerdtree#echo("Bookmark isnt cached under the current root")
|
||||
endtry
|
||||
endfunction
|
||||
|
||||
" FUNCTION: s:refreshRoot() {{{1
|
||||
" Reloads the current root. All nodes below this will be lost and the root dir
|
||||
" will be reloaded.
|
||||
function! s:refreshRoot()
|
||||
call nerdtree#echo("Refreshing the root node. This could take a while...")
|
||||
call b:NERDTreeRoot.refresh()
|
||||
call nerdtree#renderView()
|
||||
redraw
|
||||
call nerdtree#echo("Refreshing the root node. This could take a while... DONE")
|
||||
endfunction
|
||||
|
||||
" FUNCTION: s:refreshCurrent(node) {{{1
|
||||
" refreshes the root for the current node
|
||||
function! s:refreshCurrent(node)
|
||||
let node = a:node
|
||||
if !node.path.isDirectory
|
||||
let node = node.parent
|
||||
endif
|
||||
|
||||
call nerdtree#echo("Refreshing node. This could take a while...")
|
||||
call node.refresh()
|
||||
call nerdtree#renderView()
|
||||
redraw
|
||||
call nerdtree#echo("Refreshing node. This could take a while... DONE")
|
||||
endfunction
|
||||
|
||||
" Function: s:SID() {{{1
|
||||
function s:SID()
|
||||
if !exists("s:sid")
|
||||
let s:sid = matchstr(expand('<sfile>'), '<SNR>\zs\d\+\ze_SID$')
|
||||
endif
|
||||
return s:sid
|
||||
endfun
|
||||
|
||||
" FUNCTION: s:showMenu(node) {{{1
|
||||
function! s:showMenu(node)
|
||||
let mc = g:NERDTreeMenuController.New(g:NERDTreeMenuItem.AllEnabled())
|
||||
call mc.showMenu()
|
||||
endfunction
|
||||
|
||||
" FUNCTION: s:toggleIgnoreFilter() {{{1
|
||||
" toggles the use of the NERDTreeIgnore option
|
||||
function! s:toggleIgnoreFilter()
|
||||
let b:NERDTreeIgnoreEnabled = !b:NERDTreeIgnoreEnabled
|
||||
call nerdtree#renderViewSavingPosition()
|
||||
call nerdtree#centerView()
|
||||
endfunction
|
||||
|
||||
" FUNCTION: s:toggleShowBookmarks() {{{1
|
||||
" toggles the display of bookmarks
|
||||
function! s:toggleShowBookmarks()
|
||||
let b:NERDTreeShowBookmarks = !b:NERDTreeShowBookmarks
|
||||
if b:NERDTreeShowBookmarks
|
||||
call nerdtree#renderView()
|
||||
call nerdtree#putCursorOnBookmarkTable()
|
||||
else
|
||||
call nerdtree#renderViewSavingPosition()
|
||||
endif
|
||||
call nerdtree#centerView()
|
||||
endfunction
|
||||
|
||||
" FUNCTION: s:toggleShowFiles() {{{1
|
||||
" toggles the display of hidden files
|
||||
function! s:toggleShowFiles()
|
||||
let b:NERDTreeShowFiles = !b:NERDTreeShowFiles
|
||||
call nerdtree#renderViewSavingPosition()
|
||||
call nerdtree#centerView()
|
||||
endfunction
|
||||
|
||||
" FUNCTION: s:toggleShowHidden() {{{1
|
||||
" toggles the display of hidden files
|
||||
function! s:toggleShowHidden()
|
||||
let b:NERDTreeShowHidden = !b:NERDTreeShowHidden
|
||||
call nerdtree#renderViewSavingPosition()
|
||||
call nerdtree#centerView()
|
||||
endfunction
|
||||
|
||||
" FUNCTION: s:toggleZoom() {{{1
|
||||
" zoom (maximize/minimize) the NERDTree window
|
||||
function! s:toggleZoom()
|
||||
if exists("b:NERDTreeZoomed") && b:NERDTreeZoomed
|
||||
let size = exists("b:NERDTreeOldWindowSize") ? b:NERDTreeOldWindowSize : g:NERDTreeWinSize
|
||||
exec "silent vertical resize ". size
|
||||
let b:NERDTreeZoomed = 0
|
||||
else
|
||||
exec "vertical resize"
|
||||
let b:NERDTreeZoomed = 1
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" FUNCTION: s:upDirCurrentRootOpen() {{{1
|
||||
function! s:upDirCurrentRootOpen()
|
||||
call nerdtree#upDir(1)
|
||||
endfunction
|
||||
|
||||
" FUNCTION: s:upDirCurrentRootClosed() {{{1
|
||||
function! s:upDirCurrentRootClosed()
|
||||
call nerdtree#upDir(0)
|
||||
endfunction
|
||||
|
||||
" vim: set sw=4 sts=4 et fdm=marker:
|
|
@ -12,10 +12,10 @@ function! s:Creator._bindMappings()
|
|||
|
||||
call g:NERDTreeKeyMap.BindAll()
|
||||
|
||||
command! -buffer -nargs=? Bookmark :call nerdtree#bookmarkNode('<args>')
|
||||
command! -buffer -complete=customlist,nerdtree#completeBookmarks -nargs=1 RevealBookmark :call nerdtree#revealBookmark('<args>')
|
||||
command! -buffer -complete=customlist,nerdtree#completeBookmarks -nargs=1 OpenBookmark :call nerdtree#openBookmark('<args>')
|
||||
command! -buffer -complete=customlist,nerdtree#completeBookmarks -nargs=* ClearBookmarks call nerdtree#clearBookmarks('<args>')
|
||||
command! -buffer -nargs=? Bookmark :call nerdtree#ui_glue#bookmarkNode('<args>')
|
||||
command! -buffer -complete=customlist,nerdtree#completeBookmarks -nargs=1 RevealBookmark :call nerdtree#ui_glue#revealBookmark('<args>')
|
||||
command! -buffer -complete=customlist,nerdtree#completeBookmarks -nargs=1 OpenBookmark :call nerdtree#ui_glue#openBookmark('<args>')
|
||||
command! -buffer -complete=customlist,nerdtree#completeBookmarks -nargs=* ClearBookmarks call nerdtree#ui_glue#clearBookmarks('<args>')
|
||||
command! -buffer -complete=customlist,nerdtree#completeBookmarks -nargs=+ BookmarkToRoot call g:NERDTreeBookmark.ToRoot('<args>')
|
||||
command! -buffer -nargs=0 ClearAllBookmarks call g:NERDTreeBookmark.ClearAll() <bar> call nerdtree#renderView()
|
||||
command! -buffer -nargs=0 ReadBookmarks call g:NERDTreeBookmark.CacheBookmarks(0) <bar> call nerdtree#renderView()
|
||||
|
|
Loading…
Reference in New Issue
Block a user