mirror of
https://github.com/preservim/nerdtree.git
synced 2025-11-09 03:43:50 -05:00
Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
090791407e | ||
|
|
cea02c6d98 | ||
|
|
00ab690758 | ||
|
|
d4b4d69469 | ||
|
|
283559bd97 | ||
|
|
38442b06d4 | ||
|
|
ae0d744357 | ||
|
|
094074d8c6 | ||
|
|
9b192b4be4 |
@@ -901,7 +901,19 @@ fridge for later ;)
|
|||||||
==============================================================================
|
==============================================================================
|
||||||
7. Changelog *NERDTreeChangelog*
|
7. Changelog *NERDTreeChangelog*
|
||||||
|
|
||||||
2.xx.xx
|
2.14.2
|
||||||
|
- when opening a file (with 'o' or double click) dont split the window
|
||||||
|
unless we absolutely have to. This should make the script work better
|
||||||
|
with other explorer plugins. Thanks to Ryan Penn, Simon Peter Nicholls
|
||||||
|
and Michael
|
||||||
|
- fix a bug where directories starting with a '+' char could not be opened.
|
||||||
|
Thanks to Tomasz Chomiuk.
|
||||||
|
- fix a bug where closing vim with :qa with a tree open in another tab
|
||||||
|
would break, thanks to Denis Pokataev.
|
||||||
|
- compatibility bugfix for older versions of vim, thanks to knekk for
|
||||||
|
helping me track it down and to Sean Chou.
|
||||||
|
|
||||||
|
2.14.1
|
||||||
- dont clobber &cpo. Thanks to godlygeek for the bug report.
|
- dont clobber &cpo. Thanks to godlygeek for the bug report.
|
||||||
|
|
||||||
2.14.0
|
2.14.0
|
||||||
@@ -1227,6 +1239,21 @@ handling named pipes.
|
|||||||
|
|
||||||
Chur to godlygeek for reporting a bug where &cpo was getting clobbered.
|
Chur to godlygeek for reporting a bug where &cpo was getting clobbered.
|
||||||
|
|
||||||
|
Cheers to knekk for helping me track down a bug when overwriting dictionary
|
||||||
|
keys that only occurred in some versions of vim.
|
||||||
|
|
||||||
|
Thanks also to Sean Chou for the bug report about the above bug.
|
||||||
|
|
||||||
|
Thanks to Ryan Penn, Simon Peter Nicholls and Michael for pointing out an issue
|
||||||
|
where the script was splitting constantly when using the 'o' mapping while
|
||||||
|
other explorers were open.
|
||||||
|
|
||||||
|
Thanks to Tomasz Chomiuk for the bug report about the script failing when dir
|
||||||
|
names began with a +.
|
||||||
|
|
||||||
|
Thanks to Denis Pokataev for the bug report about the script failing when
|
||||||
|
closing vim with :qa with a tree open in another tab.
|
||||||
|
|
||||||
==============================================================================
|
==============================================================================
|
||||||
9. License *NERDTreeLicense*
|
9. License *NERDTreeLicense*
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
" File: NERD_tree.vim
|
" File: NERD_tree.vim
|
||||||
" Description: vim global plugin that provides a nice tree explorer
|
" Description: vim global plugin that provides a nice tree explorer
|
||||||
" Maintainer: Martin Grenfell <martin_grenfell at msn dot com>
|
" Maintainer: Martin Grenfell <martin_grenfell at msn dot com>
|
||||||
" Last Change: 20 July, 2008
|
" Last Change: 29 October, 2008
|
||||||
" License: This program is free software. It comes without any warranty,
|
" License: This program is free software. It comes without any warranty,
|
||||||
" to the extent permitted by applicable law. You can redistribute
|
" to the extent permitted by applicable law. You can redistribute
|
||||||
" it and/or modify it under the terms of the Do What The Fuck You
|
" it and/or modify it under the terms of the Do What The Fuck You
|
||||||
@@ -10,7 +10,7 @@
|
|||||||
" See http://sam.zoy.org/wtfpl/COPYING for more details.
|
" See http://sam.zoy.org/wtfpl/COPYING for more details.
|
||||||
"
|
"
|
||||||
" ============================================================================
|
" ============================================================================
|
||||||
let s:NERD_tree_version = '2.14.0'
|
let s:NERD_tree_version = '2.14.2'
|
||||||
|
|
||||||
" SECTION: Script init stuff {{{1
|
" SECTION: Script init stuff {{{1
|
||||||
"============================================================
|
"============================================================
|
||||||
@@ -132,8 +132,7 @@ let s:escape_chars = " \\`\|\"#%&,?()\*^<>"
|
|||||||
let s:NERDTreeWinName = '_NERD_tree_'
|
let s:NERDTreeWinName = '_NERD_tree_'
|
||||||
|
|
||||||
let s:tree_wid = 2
|
let s:tree_wid = 2
|
||||||
let s:tree_markup_reg = '[ \-+~`|]'
|
let s:tree_markup_reg = '^[ `|]*[\-+~]'
|
||||||
let s:tree_markup_reg_neg = '[^ \-+~`|]'
|
|
||||||
let s:tree_up_dir_line = '.. (up a dir)'
|
let s:tree_up_dir_line = '.. (up a dir)'
|
||||||
|
|
||||||
let s:os_slash = '/'
|
let s:os_slash = '/'
|
||||||
@@ -141,7 +140,6 @@ if s:running_windows
|
|||||||
let s:os_slash = '\'
|
let s:os_slash = '\'
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
|
||||||
" SECTION: Commands {{{1
|
" SECTION: Commands {{{1
|
||||||
"============================================================
|
"============================================================
|
||||||
"init the command that users start the nerd tree with
|
"init the command that users start the nerd tree with
|
||||||
@@ -713,6 +711,7 @@ endfunction
|
|||||||
"
|
"
|
||||||
"Args:
|
"Args:
|
||||||
"path: a path object
|
"path: a path object
|
||||||
|
unlet s:TreeDirNode.findNode
|
||||||
function! s:TreeDirNode.findNode(path)
|
function! s:TreeDirNode.findNode(path)
|
||||||
if a:path.equals(self.path)
|
if a:path.equals(self.path)
|
||||||
return self
|
return self
|
||||||
@@ -731,7 +730,6 @@ function! s:TreeDirNode.findNode(path)
|
|||||||
endif
|
endif
|
||||||
return {}
|
return {}
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
"FUNCTION: TreeDirNode.getChildCount() {{{3
|
"FUNCTION: TreeDirNode.getChildCount() {{{3
|
||||||
"Returns the number of children this node has
|
"Returns the number of children this node has
|
||||||
function! s:TreeDirNode.getChildCount()
|
function! s:TreeDirNode.getChildCount()
|
||||||
@@ -887,6 +885,7 @@ endfunction
|
|||||||
"
|
"
|
||||||
"Args:
|
"Args:
|
||||||
"path: a path object representing the full filesystem path to the file/dir that the node represents
|
"path: a path object representing the full filesystem path to the file/dir that the node represents
|
||||||
|
unlet s:TreeDirNode.New
|
||||||
function! s:TreeDirNode.New(path)
|
function! s:TreeDirNode.New(path)
|
||||||
if a:path.isDirectory != 1
|
if a:path.isDirectory != 1
|
||||||
throw "NERDTree.TreeDirNode.InvalidArguments exception. A TreeDirNode object must be instantiated with a directory Path object."
|
throw "NERDTree.TreeDirNode.InvalidArguments exception. A TreeDirNode object must be instantiated with a directory Path object."
|
||||||
@@ -948,6 +947,7 @@ function! s:TreeDirNode._openRecursively2(forceOpen)
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
"FUNCTION: TreeDirNode.refresh() {{{3
|
"FUNCTION: TreeDirNode.refresh() {{{3
|
||||||
|
unlet s:TreeDirNode.refresh
|
||||||
function! s:TreeDirNode.refresh()
|
function! s:TreeDirNode.refresh()
|
||||||
call self.path.refresh()
|
call self.path.refresh()
|
||||||
|
|
||||||
@@ -2061,7 +2061,7 @@ function! s:findNodeLineNumber(treenode)
|
|||||||
|
|
||||||
let curLine = getline(lnum)
|
let curLine = getline(lnum)
|
||||||
|
|
||||||
let indent = match(curLine,s:tree_markup_reg_neg) / s:tree_wid
|
let indent = s:indentLevelFor(curLine)
|
||||||
if indent == curPathComponent
|
if indent == curPathComponent
|
||||||
let curLine = s:stripMarkupFromLine(curLine, 1)
|
let curLine = s:stripMarkupFromLine(curLine, 1)
|
||||||
|
|
||||||
@@ -2092,6 +2092,21 @@ function! s:findRootNodeLineNumber()
|
|||||||
return rootLine
|
return rootLine
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
"FUNCTION: s:firstNormalWindow(){{{2
|
||||||
|
"find the window number of the first normal window
|
||||||
|
function! s:firstNormalWindow()
|
||||||
|
let i = 1
|
||||||
|
while i <= winnr("$")
|
||||||
|
let bnum = winbufnr(i)
|
||||||
|
if bnum != -1 && getbufvar(bnum, '&buftype') == ''
|
||||||
|
\ && !getwinvar(i, '&previewwindow')
|
||||||
|
return i
|
||||||
|
endif
|
||||||
|
|
||||||
|
let i += 1
|
||||||
|
endwhile
|
||||||
|
return -1
|
||||||
|
endfunction
|
||||||
"FUNCTION: s:getPath(ln) {{{2
|
"FUNCTION: s:getPath(ln) {{{2
|
||||||
"Gets the full path to the node that is rendered on the given line number
|
"Gets the full path to the node that is rendered on the given line number
|
||||||
"
|
"
|
||||||
@@ -2119,9 +2134,7 @@ function! s:getPath(ln)
|
|||||||
return t:NERDTreeRoot.path.getParent()
|
return t:NERDTreeRoot.path.getParent()
|
||||||
endif
|
endif
|
||||||
|
|
||||||
"get the indent level for the file (i.e. how deep in the tree it is)
|
let indent = s:indentLevelFor(line)
|
||||||
let indent = match(line, s:tree_markup_reg_neg) / s:tree_wid
|
|
||||||
|
|
||||||
|
|
||||||
"remove the tree parts and the leading space
|
"remove the tree parts and the leading space
|
||||||
let curFile = s:stripMarkupFromLine(line, 0)
|
let curFile = s:stripMarkupFromLine(line, 0)
|
||||||
@@ -2146,7 +2159,7 @@ function! s:getPath(ln)
|
|||||||
break
|
break
|
||||||
endif
|
endif
|
||||||
if curLineStripped =~ '/$'
|
if curLineStripped =~ '/$'
|
||||||
let lpindent = match(curLine,s:tree_markup_reg_neg) / s:tree_wid
|
let lpindent = s:indentLevelFor(curLine)
|
||||||
if lpindent < indent
|
if lpindent < indent
|
||||||
let indent = indent - 1
|
let indent = indent - 1
|
||||||
|
|
||||||
@@ -2209,12 +2222,14 @@ function! s:getTreeWinNum()
|
|||||||
return -1
|
return -1
|
||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
"FUNCTION: s:indentLevelFor(line) {{{2
|
||||||
|
function! s:indentLevelFor(line)
|
||||||
|
return match(a:line, '[^ \-+~`|]') / s:tree_wid
|
||||||
|
endfunction
|
||||||
"FUNCTION: s:isTreeOpen() {{{2
|
"FUNCTION: s:isTreeOpen() {{{2
|
||||||
function! s:isTreeOpen()
|
function! s:isTreeOpen()
|
||||||
return s:getTreeWinNum() != -1
|
return s:getTreeWinNum() != -1
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
" FUNCTION: s:jumpToChild(direction) {{{2
|
" FUNCTION: s:jumpToChild(direction) {{{2
|
||||||
" Args:
|
" Args:
|
||||||
" direction: 0 if going to first child, 1 if going to last
|
" direction: 0 if going to first child, 1 if going to last
|
||||||
@@ -2284,11 +2299,16 @@ function! s:openFileNode(treenode)
|
|||||||
if winnr != -1
|
if winnr != -1
|
||||||
exec winnr . "wincmd w"
|
exec winnr . "wincmd w"
|
||||||
|
|
||||||
elseif s:shouldSplitToOpen(winnr("#"))
|
else
|
||||||
|
if s:windowIsUsable(winnr("#")) && s:firstNormalWindow() == -1
|
||||||
call s:openFileNodeSplit(a:treenode)
|
call s:openFileNodeSplit(a:treenode)
|
||||||
else
|
else
|
||||||
try
|
try
|
||||||
|
if s:windowIsUsable(winnr("#"))
|
||||||
|
exec s:firstNormalWindow() . "wincmd w"
|
||||||
|
else
|
||||||
wincmd p
|
wincmd p
|
||||||
|
endif
|
||||||
exec ("edit " . a:treenode.path.strForEditCmd())
|
exec ("edit " . a:treenode.path.strForEditCmd())
|
||||||
catch /^Vim\%((\a\+)\)\=:E37/
|
catch /^Vim\%((\a\+)\)\=:E37/
|
||||||
call s:putCursorInTreeWin()
|
call s:putCursorInTreeWin()
|
||||||
@@ -2297,6 +2317,7 @@ function! s:openFileNode(treenode)
|
|||||||
echo v:exception
|
echo v:exception
|
||||||
endtry
|
endtry
|
||||||
endif
|
endif
|
||||||
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
"FUNCTION: s:openFileNodeSplit(treenode) {{{2
|
"FUNCTION: s:openFileNodeSplit(treenode) {{{2
|
||||||
@@ -2582,11 +2603,14 @@ endfunction
|
|||||||
"scroll position
|
"scroll position
|
||||||
function! s:saveScreenState()
|
function! s:saveScreenState()
|
||||||
let win = winnr()
|
let win = winnr()
|
||||||
|
try
|
||||||
call s:putCursorInTreeWin()
|
call s:putCursorInTreeWin()
|
||||||
let t:NERDTreeOldPos = getpos(".")
|
let t:NERDTreeOldPos = getpos(".")
|
||||||
let t:NERDTreeOldTopLine = line("w0")
|
let t:NERDTreeOldTopLine = line("w0")
|
||||||
let t:NERDTreeOldWindowSize = s:shouldSplitVertically() ? winwidth("") : winheight("")
|
let t:NERDTreeOldWindowSize = s:shouldSplitVertically() ? winwidth("") : winheight("")
|
||||||
exec win . "wincmd w"
|
exec win . "wincmd w"
|
||||||
|
catch /NERDTree.view.InvalidOperation/
|
||||||
|
endtry
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
"FUNCTION: s:setupSyntaxHighlighting() {{{2
|
"FUNCTION: s:setupSyntaxHighlighting() {{{2
|
||||||
@@ -2680,37 +2704,6 @@ function! s:setupSyntaxHighlighting()
|
|||||||
hi def link NERDTreeCurrentNode Search
|
hi def link NERDTreeCurrentNode Search
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
"FUNCTION: s:shouldSplitToOpen() {{{2
|
|
||||||
"Returns 1 if opening a file from the tree in the given window requires it to
|
|
||||||
"be split
|
|
||||||
"
|
|
||||||
"Args:
|
|
||||||
"winnumber: the number of the window in question
|
|
||||||
function! s:shouldSplitToOpen(winnumber)
|
|
||||||
"gotta split if theres only one window (i.e. the NERD tree)
|
|
||||||
if winnr("$") == 1
|
|
||||||
return 1
|
|
||||||
endif
|
|
||||||
|
|
||||||
let oldwinnr = winnr()
|
|
||||||
exec a:winnumber . "wincmd p"
|
|
||||||
let specialWindow = getbufvar("%", '&buftype') != '' || getwinvar('%', '&previewwindow')
|
|
||||||
let modified = &modified
|
|
||||||
exec oldwinnr . "wincmd p"
|
|
||||||
|
|
||||||
"if its a special window e.g. quickfix or another explorer plugin then we
|
|
||||||
"have to split
|
|
||||||
if specialWindow
|
|
||||||
return 1
|
|
||||||
endif
|
|
||||||
|
|
||||||
if &hidden
|
|
||||||
return 0
|
|
||||||
endif
|
|
||||||
|
|
||||||
return modified && s:bufInWindows(winbufnr(a:winnumber)) < 2
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
" Function: s:shouldSplitVertically() {{{2
|
" Function: s:shouldSplitVertically() {{{2
|
||||||
" Returns 1 if g:NERDTreeWinPos is 'left' or 'right'
|
" Returns 1 if g:NERDTreeWinPos is 'left' or 'right'
|
||||||
function! s:shouldSplitVertically()
|
function! s:shouldSplitVertically()
|
||||||
@@ -2726,7 +2719,7 @@ endfunction
|
|||||||
function! s:stripMarkupFromLine(line, removeLeadingSpaces)
|
function! s:stripMarkupFromLine(line, removeLeadingSpaces)
|
||||||
let line = a:line
|
let line = a:line
|
||||||
"remove the tree parts and the leading space
|
"remove the tree parts and the leading space
|
||||||
let line = substitute (line,"^" . s:tree_markup_reg . "*","","")
|
let line = substitute (line, s:tree_markup_reg,"","")
|
||||||
|
|
||||||
"strip off any read only flag
|
"strip off any read only flag
|
||||||
let line = substitute (line, ' \[RO\]', "","")
|
let line = substitute (line, ' \[RO\]', "","")
|
||||||
@@ -2774,6 +2767,37 @@ function! s:toggle(dir)
|
|||||||
call s:initNerdTree(a:dir)
|
call s:initNerdTree(a:dir)
|
||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
"FUNCTION: s:windowIsUsable() {{{2
|
||||||
|
"Returns 1 if opening a file from the tree in the given window requires it to
|
||||||
|
"be split
|
||||||
|
"
|
||||||
|
"Args:
|
||||||
|
"winnumber: the number of the window in question
|
||||||
|
function! s:windowIsUsable(winnumber)
|
||||||
|
"gotta split if theres only one window (i.e. the NERD tree)
|
||||||
|
if winnr("$") == 1
|
||||||
|
return 1
|
||||||
|
endif
|
||||||
|
|
||||||
|
let oldwinnr = winnr()
|
||||||
|
exec a:winnumber . "wincmd p"
|
||||||
|
let specialWindow = getbufvar("%", '&buftype') != '' || getwinvar('%', '&previewwindow')
|
||||||
|
let modified = &modified
|
||||||
|
exec oldwinnr . "wincmd p"
|
||||||
|
|
||||||
|
"if its a special window e.g. quickfix or another explorer plugin then we
|
||||||
|
"have to split
|
||||||
|
if specialWindow
|
||||||
|
return 1
|
||||||
|
endif
|
||||||
|
|
||||||
|
if &hidden
|
||||||
|
return 0
|
||||||
|
endif
|
||||||
|
|
||||||
|
return modified && s:bufInWindows(winbufnr(a:winnumber)) < 2
|
||||||
|
endfunction
|
||||||
|
|
||||||
"SECTION: Interface bindings {{{1
|
"SECTION: Interface bindings {{{1
|
||||||
"============================================================
|
"============================================================
|
||||||
"FUNCTION: s:activateNode(forceKeepWindowOpen) {{{2
|
"FUNCTION: s:activateNode(forceKeepWindowOpen) {{{2
|
||||||
@@ -2905,8 +2929,7 @@ function! s:checkForActivate()
|
|||||||
"if they clicked a dir, check if they clicked on the + or ~ sign
|
"if they clicked a dir, check if they clicked on the + or ~ sign
|
||||||
"beside it
|
"beside it
|
||||||
if currentNode.path.isDirectory
|
if currentNode.path.isDirectory
|
||||||
let reg = '^' . s:tree_markup_reg .'*[~+]$'
|
if startToCur =~ s:tree_markup_reg . '$' && char =~ '[+~]'
|
||||||
if startToCur =~ reg
|
|
||||||
call s:activateNode(0)
|
call s:activateNode(0)
|
||||||
return
|
return
|
||||||
endif
|
endif
|
||||||
|
|||||||
Reference in New Issue
Block a user