Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lazy Directory Refresh #1362

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions doc/NERDTree.txt
Original file line number Diff line number Diff line change
Expand Up @@ -774,6 +774,8 @@ the NERDTree. These settings should be set in your vimrc, using `:let`.
|NERDTreeCustomOpenArgs| A dictionary with values that control how a node
is opened with the |NERDTree-<CR>| key.

|NERDTreeLazyDirRefresh| Enables lazy directory refreshing (experimental)

------------------------------------------------------------------------------
3.2. Customisation details *NERDTreeSettingsDetails*

Expand Down Expand Up @@ -1311,6 +1313,18 @@ To open files and directories (creating a new NERDTree) in a new tab, >
<
To open a file always in the current tab, and expand directories in place, >
{'file': {'reuse':'currenttab', 'where':'p', 'keepopen':1, 'stay':1}}
<
------------------------------------------------------------------------------
*NERDTreeLazyDirRefresh*
Values: 0 or 1
Default: 0

'experimental'

If set to 1, the NERDTree will use lazy refresh on close directories whenever
a refresh action is performed. Actual refresh happens when it is required.
It happens on directory open and findNode functions.

<
==============================================================================
4. The NERDTree API *NERDTreeAPI*
Expand Down
28 changes: 24 additions & 4 deletions lib/nerdtree/tree_dir_node.vim
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ endfunction
" path: a path object
unlet s:TreeDirNode.findNode
function! s:TreeDirNode.findNode(path)
call self.refresh(2)
if a:path.equals(self.path)
return self
endif
Expand Down Expand Up @@ -461,6 +462,8 @@ function! s:TreeDirNode.New(path, nerdtree)
let newTreeNode.isOpen = 0
let newTreeNode.children = []

let newTreeNode.lazyRefresh = 0

let newTreeNode.parent = {}
let newTreeNode._nerdtree = a:nerdtree

Expand All @@ -472,6 +475,7 @@ endfunction
" are provided. Return 0 if options were processed. Otherwise, return the
" number of new cached nodes.
function! s:TreeDirNode.open(...)
call self.refresh(2)
let l:options = a:0 ? a:1 : {}

" If special options were specified, process them and return.
Expand Down Expand Up @@ -557,12 +561,24 @@ function! s:TreeDirNode.openRecursively()
endfor
endfunction

" FUNCTION: TreeDirNode.refresh() {{{1
function! s:TreeDirNode.refresh()
" FUNCTION: TreeDirNode.refresh([options]) {{{1
" refreshes the node and its children
"
" Args:
" An optional integer selecting refresh mode
"
" 0 == normal (default)
" 1 == force
" 2 == lazyRefresh (refreshes node only if lazyRefresh flag is set)
"
function! s:TreeDirNode.refresh(...)
let l:mode = a:0 ? a:1 : 0
call self.path.refresh(self.getNerdtree())

"if this node was ever opened, refresh its children
if self.isOpen || !empty(self.children)
"if refresh is forced, refresh its children
"if this node is open, refresh its children
"if this node is flaged for lazyRefresh and lazyRefresh requested, refresh its children
if l:mode == 1 || self.isOpen || (!empty(self.children) && !g:NERDTreeLazyDirRefresh) || (l:mode == 2 && self.lazyRefresh)
let files = self._glob('*', 1) + self._glob('.*', 0)
let newChildNodes = []
let invalidFilesFound = 0
Expand Down Expand Up @@ -595,6 +611,10 @@ function! s:TreeDirNode.refresh()
if invalidFilesFound
call nerdtree#echoWarning(invalidFilesFound . ' Invalid file(s): ' . join(invalidFiles, ', '))
endif
let self.lazyRefresh = 0
" if this node is not empty and NERDTreeLazyDirRefresh is enable flag the node for lazyRefresh
elseif g:NERDTreeLazyDirRefresh && !empty(self.children)
let self.lazyRefresh = 1
endif
endfunction

Expand Down
1 change: 1 addition & 0 deletions plugin/NERD_tree.vim
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ let g:NERDTreeShowFiles = get(g:, 'NERDTreeShowFiles', 1
let g:NERDTreeShowHidden = get(g:, 'NERDTreeShowHidden', 0)
let g:NERDTreeShowLineNumbers = get(g:, 'NERDTreeShowLineNumbers', 0)
let g:NERDTreeSortDirs = get(g:, 'NERDTreeSortDirs', 1)
let g:NERDTreeLazyDirRefresh = get(g:, 'NERDTreeLazyDirRefresh', 0)

if !nerdtree#runningWindows() && !nerdtree#runningCygwin()
let g:NERDTreeDirArrowExpandable = get(g:, 'NERDTreeDirArrowExpandable', '▸')
Expand Down