Suppress events for intermediate window/tab/buffer changes (#1026)

* Add an optional parameter to neredtree#exec to suppress all events.

The value doesn't matter, but 1 is a good choice. Its presence is an
indicator that tells NERDTree to tell Vim to ignore all events. I'm not
yet sure if there needs to be an else section to that if block. It may
be OK to allow all events to fire in the right situations.

* Supress events in all intermediate nerdtree#exec calls.

Finding all the right function calls is the key here.

* Make ignoreAll a required parameter to nerdtree#exec().

* Put required ignoreAll argument (==0) in where it's now needed.

* Ignore events when creating a new vertical split.

* Ignore events when closing NERDTree. This may need to be reverted.

* Remove debugging statment and commented-out code.

* Wrap remaining buffer/window-switching commands in nerdtree#exec().

* Update version number.

* Add a space between arguments in nerdtree#exec() calls.
This commit is contained in:
Phil Runninger 2019-08-08 22:00:35 -04:00 committed by GitHub
parent 63c59208c1
commit ae1c0004ec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 47 additions and 46 deletions

View File

@ -1,6 +1,7 @@
# Change Log # Change Log
#### 5.2... #### 5.2...
- **.9**: Suppress events for intermediate window/tab/buffer changes [#1026](https://github.com/scrooloose/nerdtree/pull/1026)
- **.8**: Revert [#1019](https://github.com/scrooloose/nerdtree/pull/1019) to fix nvim artifacts and flickering. (PhilRunninger) [#1021](https://github.com/scrooloose/nerdtree/pull/1021) - **.8**: Revert [#1019](https://github.com/scrooloose/nerdtree/pull/1019) to fix nvim artifacts and flickering. (PhilRunninger) [#1021](https://github.com/scrooloose/nerdtree/pull/1021)
- **.7**: Use :mode only in neovim. MacVim still needs to use :redraw! [#1019](https://github.com/scrooloose/nerdtree/pull/1019) - **.7**: Use :mode only in neovim. MacVim still needs to use :redraw! [#1019](https://github.com/scrooloose/nerdtree/pull/1019)
- **.6**: In CHANGELOG.md and PR template, make reference to PR a true HTML link. [#1017](https://github.com/scrooloose/nerdtree/pull/1017) - **.6**: In CHANGELOG.md and PR template, make reference to PR a true HTML link. [#1017](https://github.com/scrooloose/nerdtree/pull/1017)

View File

@ -154,13 +154,13 @@ function! nerdtree#deprecated(func, ...)
endif endif
endfunction endfunction
" FUNCTION: nerdtree#exec(cmd) {{{2 " FUNCTION: nerdtree#exec(cmd, ignoreAll) {{{2
" Same as :exec cmd but with eventignore set for the duration " Same as :exec cmd but, if ignoreAll is TRUE, set eventignore=all for the duration
" to disable the autocommands used by NERDTree (BufEnter, function! nerdtree#exec(cmd, ignoreAll)
" BufLeave and VimEnter)
function! nerdtree#exec(cmd)
let old_ei = &ei let old_ei = &ei
set ei=BufEnter,BufLeave,VimEnter if a:ignoreAll
set ei=all
endif
exec a:cmd exec a:cmd
let &ei = old_ei let &ei = old_ei
endfunction endfunction

View File

@ -574,11 +574,11 @@ function! s:refreshRoot()
call nerdtree#echo("Refreshing the root node. This could take a while...") call nerdtree#echo("Refreshing the root node. This could take a while...")
let l:curWin = winnr() let l:curWin = winnr()
call nerdtree#exec(g:NERDTree.GetWinNum() . "wincmd w") call nerdtree#exec(g:NERDTree.GetWinNum() . "wincmd w", 1)
call b:NERDTree.root.refresh() call b:NERDTree.root.refresh()
call b:NERDTree.render() call b:NERDTree.render()
redraw redraw
call nerdtree#exec(l:curWin . "wincmd w") call nerdtree#exec(l:curWin . "wincmd w", 1)
call nerdtree#echo("") call nerdtree#echo("")
endfunction endfunction

View File

@ -159,8 +159,8 @@ endfunction
" FUNCTION: s:Edit() {{{1 " FUNCTION: s:Edit() {{{1
" opens the NERDTreeBookmarks file for manual editing " opens the NERDTreeBookmarks file for manual editing
function! s:Bookmark.Edit() function! s:Bookmark.Edit()
execute "wincmd w" call nerdtree#exec("wincmd w", 1)
execute "edit ".g:NERDTreeBookmarksFile call nerdtree#exec("edit ".g:NERDTreeBookmarksFile, 1)
endfunction endfunction
" FUNCTION: Bookmark.getNode(nerdtree, searchFromAbsoluteRoot) {{{1 " FUNCTION: Bookmark.getNode(nerdtree, searchFromAbsoluteRoot) {{{1

View File

@ -44,19 +44,19 @@ function! s:NERDTree.Close()
let l:useWinId = exists('*win_getid') && exists('*win_gotoid') let l:useWinId = exists('*win_getid') && exists('*win_gotoid')
if winnr() == s:NERDTree.GetWinNum() if winnr() == s:NERDTree.GetWinNum()
call nerdtree#exec("wincmd p") call nerdtree#exec("wincmd p", 1)
let l:activeBufOrWin = l:useWinId ? win_getid() : bufnr("") let l:activeBufOrWin = l:useWinId ? win_getid() : bufnr("")
call nerdtree#exec("wincmd p") call nerdtree#exec("wincmd p", 1)
else else
let l:activeBufOrWin = l:useWinId ? win_getid() : bufnr("") let l:activeBufOrWin = l:useWinId ? win_getid() : bufnr("")
endif endif
call nerdtree#exec(s:NERDTree.GetWinNum() . " wincmd w") call nerdtree#exec(s:NERDTree.GetWinNum() . " wincmd w", 1)
close call nerdtree#exec("close", 1)
if l:useWinId if l:useWinId
call nerdtree#exec("call win_gotoid(" . l:activeBufOrWin . ")") call nerdtree#exec("call win_gotoid(" . l:activeBufOrWin . ")", 0)
else else
call nerdtree#exec(bufwinnr(l:activeBufOrWin) . " wincmd w") call nerdtree#exec(bufwinnr(l:activeBufOrWin) . " wincmd w", 0)
endif endif
else else
close close
@ -98,7 +98,7 @@ endfunction
"Places the cursor in the nerd tree window "Places the cursor in the nerd tree window
function! s:NERDTree.CursorToTreeWin() function! s:NERDTree.CursorToTreeWin()
call g:NERDTree.MustBeOpen() call g:NERDTree.MustBeOpen()
call nerdtree#exec(g:NERDTree.GetWinNum() . "wincmd w") call nerdtree#exec(g:NERDTree.GetWinNum() . "wincmd w", 1)
endfunction endfunction
" Function: s:NERDTree.ExistsForBuffer() {{{1 " Function: s:NERDTree.ExistsForBuffer() {{{1

View File

@ -107,10 +107,10 @@ function! s:Opener._isWindowUsable(winnumber)
endif endif
let oldwinnr = winnr() let oldwinnr = winnr()
call nerdtree#exec(a:winnumber . "wincmd p") call nerdtree#exec(a:winnumber . "wincmd p", 1)
let specialWindow = getbufvar("%", '&buftype') != '' || getwinvar('%', '&previewwindow') let specialWindow = getbufvar("%", '&buftype') != '' || getwinvar('%', '&previewwindow')
let modified = &modified let modified = &modified
call nerdtree#exec(oldwinnr . "wincmd p") call nerdtree#exec(oldwinnr . "wincmd p", 1)
"if its a special window e.g. quickfix or another explorer plugin then we "if its a special window e.g. quickfix or another explorer plugin then we
"have to split "have to split
@ -172,7 +172,7 @@ function! s:Opener._newSplit()
let below=0 let below=0
" Attempt to go to adjacent window " Attempt to go to adjacent window
call nerdtree#exec(back) call nerdtree#exec(back, 1)
let onlyOneWin = (winnr("$") ==# 1) let onlyOneWin = (winnr("$") ==# 1)
@ -201,9 +201,9 @@ function! s:Opener._newSplit()
"resize the tree window if no other window was open before "resize the tree window if no other window was open before
if onlyOneWin if onlyOneWin
let size = exists("b:NERDTreeOldWindowSize") ? b:NERDTreeOldWindowSize : g:NERDTreeWinSize let size = exists("b:NERDTreeOldWindowSize") ? b:NERDTreeOldWindowSize : g:NERDTreeWinSize
call nerdtree#exec(there) call nerdtree#exec(there, 1)
exec("silent ". splitMode ." resize ". size) exec("silent ". splitMode ." resize ". size)
call nerdtree#exec('wincmd p') call nerdtree#exec('wincmd p', 0)
endif endif
" Restore splitmode settings " Restore splitmode settings
@ -219,8 +219,8 @@ function! s:Opener._newVSplit()
let l:winwidth = g:NERDTreeWinSize let l:winwidth = g:NERDTreeWinSize
endif endif
call nerdtree#exec('wincmd p') call nerdtree#exec('wincmd p', 1)
vnew call nerdtree#exec('vnew', 1)
let l:currentWindowNumber = winnr() let l:currentWindowNumber = winnr()
@ -228,7 +228,7 @@ function! s:Opener._newVSplit()
call g:NERDTree.CursorToTreeWin() call g:NERDTree.CursorToTreeWin()
execute 'silent vertical resize ' . l:winwidth execute 'silent vertical resize ' . l:winwidth
call nerdtree#exec(l:currentWindowNumber . 'wincmd w') call nerdtree#exec(l:currentWindowNumber . 'wincmd w', 0)
endfunction endfunction
" FUNCTION: Opener.open(target) {{{1 " FUNCTION: Opener.open(target) {{{1
@ -290,9 +290,9 @@ function! s:Opener._previousWindow()
else else
try try
if !self._isWindowUsable(winnr("#")) if !self._isWindowUsable(winnr("#"))
call nerdtree#exec(self._firstUsableWindow() . "wincmd w") call nerdtree#exec(self._firstUsableWindow() . "wincmd w", 1)
else else
call nerdtree#exec('wincmd p') call nerdtree#exec('wincmd p', 1)
endif endif
catch /^Vim\%((\a\+)\)\=:E37/ catch /^Vim\%((\a\+)\)\=:E37/
call g:NERDTree.CursorToTreeWin() call g:NERDTree.CursorToTreeWin()
@ -305,8 +305,8 @@ endfunction
" FUNCTION: Opener._restoreCursorPos() {{{1 " FUNCTION: Opener._restoreCursorPos() {{{1
function! s:Opener._restoreCursorPos() function! s:Opener._restoreCursorPos()
call nerdtree#exec(self._tabnr . 'tabnext') call nerdtree#exec(self._tabnr . 'tabnext', 1)
call nerdtree#exec(bufwinnr(self._bufnr) . 'wincmd w') call nerdtree#exec(bufwinnr(self._bufnr) . 'wincmd w', 1)
endfunction endfunction
" FUNCTION: Opener._reuseWindow() {{{1 " FUNCTION: Opener._reuseWindow() {{{1
@ -321,7 +321,7 @@ function! s:Opener._reuseWindow()
"check the current tab for the window "check the current tab for the window
let winnr = bufwinnr('^' . self._path.str() . '$') let winnr = bufwinnr('^' . self._path.str() . '$')
if winnr != -1 if winnr != -1
call nerdtree#exec(winnr . "wincmd w") call nerdtree#exec(winnr . "wincmd w", 0)
call self._checkToCloseTree(0) call self._checkToCloseTree(0)
return 1 return 1
endif endif
@ -334,9 +334,9 @@ function! s:Opener._reuseWindow()
let tabnr = self._path.tabnr() let tabnr = self._path.tabnr()
if tabnr if tabnr
call self._checkToCloseTree(1) call self._checkToCloseTree(1)
call nerdtree#exec(tabnr . 'tabnext') call nerdtree#exec(tabnr . 'tabnext', 1)
let winnr = bufwinnr('^' . self._path.str() . '$') let winnr = bufwinnr('^' . self._path.str() . '$')
call nerdtree#exec(winnr . "wincmd w") call nerdtree#exec(winnr . "wincmd w", 0)
return 1 return 1
endif endif

View File

@ -340,7 +340,7 @@ function! s:UI.restoreScreenState()
if !has_key(self, '_screenState') if !has_key(self, '_screenState')
return return
endif endif
exec("silent vertical resize " . self._screenState['oldWindowSize']) call nerdtree#exec("silent vertical resize " . self._screenState['oldWindowSize'], 1)
let old_scrolloff=&scrolloff let old_scrolloff=&scrolloff
let &scrolloff=0 let &scrolloff=0
@ -360,7 +360,7 @@ function! s:UI.saveScreenState()
let self._screenState['oldPos'] = getpos(".") let self._screenState['oldPos'] = getpos(".")
let self._screenState['oldTopLine'] = line("w0") let self._screenState['oldTopLine'] = line("w0")
let self._screenState['oldWindowSize']= winwidth("") let self._screenState['oldWindowSize']= winwidth("")
call nerdtree#exec(win . "wincmd w") call nerdtree#exec(win . "wincmd w", 1)
endfunction endfunction
" FUNCTION: s:UI.setShowHidden(val) {{{1 " FUNCTION: s:UI.setShowHidden(val) {{{1
@ -506,10 +506,10 @@ endfunction
function! s:UI.toggleZoom() function! s:UI.toggleZoom()
if exists("b:NERDTreeZoomed") && b:NERDTreeZoomed if exists("b:NERDTreeZoomed") && b:NERDTreeZoomed
let size = exists("b:NERDTreeOldWindowSize") ? b:NERDTreeOldWindowSize : g:NERDTreeWinSize let size = exists("b:NERDTreeOldWindowSize") ? b:NERDTreeOldWindowSize : g:NERDTreeWinSize
exec "silent vertical resize ". size call nerdtree#exec("silent vertical resize ". size, 1)
let b:NERDTreeZoomed = 0 let b:NERDTreeZoomed = 0
else else
exec "vertical resize ". get(g:, 'NERDTreeWinSizeMax', '') call nerdtree#exec("vertical resize ". get(g:, 'NERDTreeWinSizeMax', ''), 1)
let b:NERDTreeZoomed = 1 let b:NERDTreeZoomed = 1
endif endif
endfunction endfunction

View File

@ -114,14 +114,14 @@ function! s:promptToDelBuffer(bufnum, msg)
let l:listedBufferCount = 0 let l:listedBufferCount = 0
endif endif
if l:listedBufferCount > 1 if l:listedBufferCount > 1
exec "tabdo windo if winbufnr(0) == " . a:bufnum . " | exec ':bnext! ' | endif" call nerdtree#exec("tabdo windo if winbufnr(0) == " . a:bufnum . " | exec ':bnext! ' | endif", 1)
else else
exec "tabdo windo if winbufnr(0) == " . a:bufnum . " | exec ':enew! ' | endif" call nerdtree#exec("tabdo windo if winbufnr(0) == " . a:bufnum . " | exec ':enew! ' | endif", 1)
endif endif
exec "tabnext " . s:originalTabNumber call nerdtree#exec("tabnext " . s:originalTabNumber, 1)
exec s:originalWindowNumber . "wincmd w" call nerdtree#exec(s:originalWindowNumber . "wincmd w", 1)
" 3. We don't need a previous buffer anymore " 3. We don't need a previous buffer anymore
exec "bwipeout! " . a:bufnum call nerdtree#exec("bwipeout! " . a:bufnum, 0)
endif endif
endfunction endfunction
@ -141,17 +141,17 @@ function! s:renameBuffer(bufNum, newNodeName, isDirectory)
let editStr = g:NERDTreePath.New(a:newNodeName).str({'format': 'Edit'}) let editStr = g:NERDTreePath.New(a:newNodeName).str({'format': 'Edit'})
endif endif
" 1. ensure that a new buffer is loaded " 1. ensure that a new buffer is loaded
exec "badd " . quotedFileName call nerdtree#exec("badd " . quotedFileName, 1)
" 2. ensure that all windows which display the just deleted filename " 2. ensure that all windows which display the just deleted filename
" display a buffer for a new filename. " display a buffer for a new filename.
let s:originalTabNumber = tabpagenr() let s:originalTabNumber = tabpagenr()
let s:originalWindowNumber = winnr() let s:originalWindowNumber = winnr()
exec "tabdo windo if winbufnr(0) == " . a:bufNum . " | exec ':e! " . editStr . "' | endif" call nerdtree#exec("tabdo windo if winbufnr(0) == " . a:bufNum . " | exec ':e! " . editStr . "' | endif", 1)
exec "tabnext " . s:originalTabNumber call nerdtree#exec("tabnext " . s:originalTabNumber, 1)
exec s:originalWindowNumber . "wincmd w" call nerdtree#exec(s:originalWindowNumber . "wincmd w", 1)
" 3. We don't need a previous buffer anymore " 3. We don't need a previous buffer anymore
try try
exec "confirm bwipeout " . a:bufNum call nerdtree#exec("confirm bwipeout " . a:bufNum, 0)
catch catch
" This happens when answering Cancel if confirmation is needed. Do nothing. " This happens when answering Cancel if confirmation is needed. Do nothing.
endtry endtry