Skip to content

Commit

Permalink
Merge branch 'disable-cascade' of git://github.com/juanibiapina/nerdt…
Browse files Browse the repository at this point in the history
…ree into juanibiapina-disable-cascade
  • Loading branch information
Phil Runninger committed Sep 8, 2016
2 parents 4428aba + b2bbed4 commit ac2d3b0
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 25 deletions.
23 changes: 19 additions & 4 deletions doc/NERD_tree.txt
Expand Up @@ -668,14 +668,18 @@ NERD tree. These options should be set in your vimrc.
|'NERDTreeWinSize'| Sets the window size when the NERD tree is
opened.

|'NERDTreeMinimalUI'| Disables display of the 'Bookmarks' label and
|'NERDTreeMinimalUI'| Disables display of the 'Bookmarks' label and
'Press ? for help' text.

|'NERDTreeCascadeSingleChildDir'|
Collapses on the same line directories that
have only one child directory.

|'NERDTreeCascadeOpenSingleChildDir'|
Cascade open while selected directory has only
one child that also is a directory.

|'NERDTreeAutoDeleteBuffer'| Tells the NERD tree to automatically remove
|'NERDTreeAutoDeleteBuffer'| Tells the NERD tree to automatically remove
a buffer when a file is being deleted or renamed
via a context menu command.

Expand Down Expand Up @@ -987,7 +991,18 @@ of the following lines to set this option: >
<

------------------------------------------------------------------------------
*'NERDTreeCascadeOpenSingleChildDir'*
*'NERDTreeCascadeSingleChildDir'*
Values: 0 or 1
Default: 1.

When displaying dir nodes, this option tells NERDTree to collapse dirs that
have only one child. Use one of the follow lines to set this option: >
let NERDTreeCascadeSingleChildDir=0
let NERDTreeCascadeSingleChildDir=1
<

------------------------------------------------------------------------------
*'NERDTreeCascadeOpenSingleChildDir'*
Values: 0 or 1
Default: 1.

Expand All @@ -1001,7 +1016,7 @@ useful for Java projects. Use one of the follow lines to set this option: >
<

------------------------------------------------------------------------------
*'NERDTreeAutoDeleteBuffer'*
*'NERDTreeAutoDeleteBuffer'*
Values: 0 or 1
Default: 0.

Expand Down
32 changes: 11 additions & 21 deletions lib/nerdtree/tree_dir_node.vim
Expand Up @@ -117,28 +117,14 @@ endfunction
"FUNCTION: TreeDirNode.getCascade() {{{1
"Return an array of dir nodes (starting from self) that can be cascade opened.
function! s:TreeDirNode.getCascade()
if !self.isCascadable()
return [self]
endif

let rv = [self]
let node = self

while 1
let vc = node.getVisibleChildren()
if len(vc) != 1
break
endif

let visChild = vc[0]

"TODO: optimize
if !visChild.path.isDirectory
break
endif

call add(rv, visChild)
let node = visChild
endwhile
let vc = self.getVisibleChildren()
let visChild = vc[0]

return rv
return [self] + visChild.getCascade()
endfunction

"FUNCTION: TreeDirNode.getChildCount() {{{1
Expand Down Expand Up @@ -264,6 +250,10 @@ endfunction
"FUNCTION: TreeDirNode.isCascadable() {{{1
"true if this dir has only one visible child - which is also a dir
function! s:TreeDirNode.isCascadable()
if g:NERDTreeCascadeSingleChildDir == 0
return 0
endif

let c = self.getVisibleChildren()
return len(c) == 1 && c[0].path.isDirectory
endfunction
Expand Down Expand Up @@ -466,7 +456,7 @@ function! s:TreeDirNode.refresh()

" Regular expression is too expensive. Use simply string comparison
" instead
if i[len(i)-3:2] != ".." && i[len(i)-2:2] != ".." &&
if i[len(i)-3:2] != ".." && i[len(i)-2:2] != ".." &&
\ i[len(i)-2:1] != "." && i[len(i)-1] != "."
try
"create a new path and see if it exists in this nodes children
Expand Down
1 change: 1 addition & 0 deletions plugin/NERD_tree.vim
Expand Up @@ -75,6 +75,7 @@ else
call s:initVariable("g:NERDTreeDirArrowCollapsible", "~")
endif
call s:initVariable("g:NERDTreeCascadeOpenSingleChildDir", 1)
call s:initVariable("g:NERDTreeCascadeSingleChildDir", 1)

if !exists("g:NERDTreeSortOrder")
let g:NERDTreeSortOrder = ['\/$', '*', '\.swp$', '\.bak$', '\~$']
Expand Down

0 comments on commit ac2d3b0

Please sign in to comment.