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
#### 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)
- **.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)

View File

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

View File

@ -574,11 +574,11 @@ function! s:refreshRoot()
call nerdtree#echo("Refreshing the root node. This could take a while...")
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.render()
redraw
call nerdtree#exec(l:curWin . "wincmd w")
call nerdtree#exec(l:curWin . "wincmd w", 1)
call nerdtree#echo("")
endfunction

View File

@ -159,8 +159,8 @@ endfunction
" FUNCTION: s:Edit() {{{1
" opens the NERDTreeBookmarks file for manual editing
function! s:Bookmark.Edit()
execute "wincmd w"
execute "edit ".g:NERDTreeBookmarksFile
call nerdtree#exec("wincmd w", 1)
call nerdtree#exec("edit ".g:NERDTreeBookmarksFile, 1)
endfunction
" 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')
if winnr() == s:NERDTree.GetWinNum()
call nerdtree#exec("wincmd p")
call nerdtree#exec("wincmd p", 1)
let l:activeBufOrWin = l:useWinId ? win_getid() : bufnr("")
call nerdtree#exec("wincmd p")
call nerdtree#exec("wincmd p", 1)
else
let l:activeBufOrWin = l:useWinId ? win_getid() : bufnr("")
endif
call nerdtree#exec(s:NERDTree.GetWinNum() . " wincmd w")
close
call nerdtree#exec(s:NERDTree.GetWinNum() . " wincmd w", 1)
call nerdtree#exec("close", 1)
if l:useWinId
call nerdtree#exec("call win_gotoid(" . l:activeBufOrWin . ")")
call nerdtree#exec("call win_gotoid(" . l:activeBufOrWin . ")", 0)
else
call nerdtree#exec(bufwinnr(l:activeBufOrWin) . " wincmd w")
call nerdtree#exec(bufwinnr(l:activeBufOrWin) . " wincmd w", 0)
endif
else
close
@ -98,7 +98,7 @@ endfunction
"Places the cursor in the nerd tree window
function! s:NERDTree.CursorToTreeWin()
call g:NERDTree.MustBeOpen()
call nerdtree#exec(g:NERDTree.GetWinNum() . "wincmd w")
call nerdtree#exec(g:NERDTree.GetWinNum() . "wincmd w", 1)
endfunction
" Function: s:NERDTree.ExistsForBuffer() {{{1

View File

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

View File

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

View File

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