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

Respect NERDTreeCustomOpenArgs when opening bookmark #1200

Merged
merged 7 commits into from
Jan 18, 2021
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- **.PATCH**: Pull Request Title (PR Author) [PR Number](Link to PR)
-->
#### 6.9
- **.12**: Respect NERDTreeCustomOpenArgs when opening bookmark (przepompownia) [#1200](https://github.com/preservim/nerdtree/pull/1200)
- **.11**: Revamp the README. (buncis, PhilRunninger) [#1192](https://github.com/preservim/nerdtree/pull/1192), [#1193](https://github.com/preservim/nerdtree/pull/1193)
- **.10**: Open a mirrored NERDTree with correct width (PhilRunninger) [#1177](https://github.com/preservim/nerdtree/pull/1177)
- **.9**: Updated Readme, removed typo (H3RSKO) [#1167](https://github.com/preservim/nerdtree/pull/1167)
Expand Down
39 changes: 35 additions & 4 deletions autoload/nerdtree/ui_glue.vim
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,38 @@ endfunction
"FUNCTION: s:initCustomOpenArgs() {{{1
" Make sure NERDTreeCustomOpenArgs has needed keys
function! s:initCustomOpenArgs() abort
let g:NERDTreeCustomOpenArgs = get(g:, 'NERDTreeCustomOpenArgs', {})
return extend(g:NERDTreeCustomOpenArgs, {'file':{'reuse': 'all', 'where': 'p'}, 'dir':{}}, 'keep')
let l:defaultOpenArgs = {'file': {'reuse': 'all', 'where': 'p'}, 'dir': {}}
let l:customOpenArgs = get(g:, 'NERDTreeCustomOpenArgs', {})

if v:false is# s:validateType(l:customOpenArgs, v:t_dict)
return l:defaultOpenArgs
endif

for l:typeKey in keys(l:defaultOpenArgs)
if v:false is# s:validateType(get(l:customOpenArgs, l:typeKey, {}), v:t_dict)
let l:customOpenArgs[l:typeKey] = l:defaultOpenArgs[l:typeKey]
continue
endif

for l:optionName in keys(l:defaultOpenArgs[l:typeKey])
if s:validateType(get(l:customOpenArgs[l:typeKey], l:optionName, v:null), v:t_string)
continue
endif
let l:customOpenArgs[l:typeKey][l:optionName] = l:defaultOpenArgs[l:typeKey][l:optionName]
endfor
endfor

let g:NERDTreeCustomOpenArgs = l:customOpenArgs

return extend(l:customOpenArgs, l:defaultOpenArgs, 'keep')
endfunction

function! s:validateType(variable, type) abort
if type(a:variable) is# a:type
return v:true
endif

return v:false
endfunction

"FUNCTION: s:activateAll() {{{1
Expand Down Expand Up @@ -500,9 +530,10 @@ function! nerdtree#ui_glue#openBookmark(name) abort
endtry
if l:bookmark.path.isDirectory
call l:bookmark.open(b:NERDTree)
else
call l:bookmark.open(b:NERDTree, {'where': 'p'})
return
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left quick returning to avoid unnecessary nesting level.

endif

call l:bookmark.open(b:NERDTree, s:initCustomOpenArgs().file)
endfunction

" FUNCTION: s:openHSplit(target) {{{1
Expand Down