feat: add NERDTreeExplore command. (#1389)

* create a explorer command that opens a window tree at specified
directory

* update CHANGELOG.md

* Update CHANGELOG.md

* revert CHANGELOG.md

* CreateExplorerTree matches :Explore command

* prevent empty split when calling NERDTreeExplorer with invalid arg from modified buffer

* NERDTreeExplore/CreateExploreTree checks for hidden and
autowriteall settings
This commit is contained in:
msibal6 2023-12-22 16:17:43 -08:00 committed by GitHub
parent a954661824
commit fefea5d382
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 0 deletions

View File

@ -642,6 +642,7 @@ endfunction
function! nerdtree#ui_glue#setupCommands() abort
command! -n=? -complete=dir -bar NERDTree :call g:NERDTreeCreator.CreateTabTree('<args>')
command! -n=? -complete=dir -bar NERDTreeToggle :call g:NERDTreeCreator.ToggleTabTree('<args>')
command! -n=? -complete=dir -bar NERDTreeExplore :call g:NERDTreeCreator.CreateExploreTree('<args>')
command! -n=0 -bar NERDTreeClose :call g:NERDTree.Close()
command! -n=1 -complete=customlist,nerdtree#completeBookmarks -bar NERDTreeFromBookmark call g:NERDTreeCreator.CreateTabTree('<args>')
command! -n=0 -bar NERDTreeMirror call g:NERDTreeCreator.CreateMirror()

View File

@ -38,6 +38,29 @@ function! s:Creator.BufNamePrefix()
return 'NERD_tree_'
endfunction
" FUNCTION: s:Creator.CreateExploreTree(dir) {{{1
function! s:Creator.CreateExploreTree(dir)
try
let path = g:NERDTreePath.New(a:dir)
catch /^NERDTree.InvalidArgumentsError/
call nerdtree#echo('Invalid directory name:' . a:dir)
return
endtry
let creator = s:Creator.New()
if getbufinfo('%')[0].changed && !&hidden && !&autowriteall
let l:splitLocation = g:NERDTreeWinPos ==# 'left' || g:NERDTreeWinPos ==# 'top' ? 'topleft ' : 'botright '
let l:splitDirection = g:NERDTreeWinPos ==# 'left' || g:NERDTreeWinPos ==# 'right' ? 'vertical' : ''
silent! execute l:splitLocation . l:splitDirection . ' new'
else
silent! execute 'enew'
endif
call creator.createWindowTree(a:dir)
"we want windowTree buffer to disappear after moving to any other buffer
setlocal bufhidden=wipe
endfunction
" FUNCTION: s:Creator.CreateTabTree(a:name) {{{1
function! s:Creator.CreateTabTree(name)
let creator = s:Creator.New()