Skip to content

Commit c3b63d2

Browse files
committed
add some class methods to wrap the NERDTreeCreator public methods
This is needed because some versions of vim dont let you chain method calls together. So do the work in NERDTreeCreator instead of forcing all callers to break the New().createXXX() calls out onto 2 lines with an intermediate variable. Fixes preservim#226.
1 parent 7cbaee2 commit c3b63d2

File tree

5 files changed

+38
-14
lines changed

5 files changed

+38
-14
lines changed

autoload/nerdtree.vim

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ endfunction
4242
"inits a secondary nerd tree in the current buffer if appropriate
4343
function! nerdtree#checkForBrowse(dir)
4444
if a:dir != '' && isdirectory(a:dir)
45-
call g:NERDTreeCreator.New().createSecondary(a:dir)
45+
call g:NERDTreeCreator.CreateSecondary(a:dir)
4646
endif
4747
endfunction
4848

@@ -193,22 +193,22 @@ function! nerdtree#findAndRevealPath()
193193
endtry
194194

195195
if p.isUnder(cwd)
196-
call g:NERDTreeCreator.New().createPrimary(cwd.str())
196+
call g:NERDTreeCreator.CreatePrimary(cwd.str())
197197
else
198-
call g:NERDTreeCreator.New().createPrimary(p.getParent().str())
198+
call g:NERDTreeCreator.CreatePrimary(p.getParent().str())
199199
endif
200200
else
201201
if !p.isUnder(g:NERDTreeFileNode.GetRootForTab().path)
202202
if !nerdtree#isTreeOpen()
203-
call g:NERDTreeCreator.New().togglePrimary('')
203+
call g:NERDTreeCreator.TogglePrimary('')
204204
else
205205
call nerdtree#putCursorInTreeWin()
206206
endif
207207
let b:NERDTreeShowHidden = g:NERDTreeShowHidden
208208
call nerdtree#chRoot(g:NERDTreeDirNode.New(p.getParent()))
209209
else
210210
if !nerdtree#isTreeOpen()
211-
call g:NERDTreeCreator.New().togglePrimary("")
211+
call g:NERDTreeCreator.TogglePrimary("")
212212
endif
213213
endif
214214
endif

plugin/NERD_tree.vim

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -149,11 +149,11 @@ runtime plugin/nerdtree/creator.vim
149149
" SECTION: Commands {{{1
150150
"============================================================
151151
"init the command that users start the nerd tree with
152-
command! -n=? -complete=dir -bar NERDTree :call g:NERDTreeCreator.New().createPrimary('<args>')
153-
command! -n=? -complete=dir -bar NERDTreeToggle :call g:NERDTreeCreator.New().togglePrimary('<args>')
152+
command! -n=? -complete=dir -bar NERDTree :call g:NERDTreeCreator.CreatePrimary('<args>')
153+
command! -n=? -complete=dir -bar NERDTreeToggle :call g:NERDTreeCreator.TogglePrimary('<args>')
154154
command! -n=0 -bar NERDTreeClose :call nerdtree#closeTreeIfOpen()
155-
command! -n=1 -complete=customlist,nerdtree#completeBookmarks -bar NERDTreeFromBookmark call g:NERDTreeCreator.New().createPrimary('<args>')
156-
command! -n=0 -bar NERDTreeMirror call g:NERDTreeCreator.New().createMirror()
155+
command! -n=1 -complete=customlist,nerdtree#completeBookmarks -bar NERDTreeFromBookmark call g:NERDTreeCreator.CreatePrimary('<args>')
156+
command! -n=0 -bar NERDTreeMirror call g:NERDTreeCreator.CreateMirror()
157157
command! -n=0 -bar NERDTreeFind call nerdtree#findAndRevealPath()
158158
command! -n=0 -bar NERDTreeFocus call NERDTreeFocus()
159159
command! -n=0 -bar NERDTreeCWD call NERDTreeCWD()
@@ -201,7 +201,7 @@ function! NERDTreeFocus()
201201
if nerdtree#isTreeOpen()
202202
call nerdtree#putCursorInTreeWin()
203203
else
204-
call g:NERDTreeCreator.New().togglePrimary("")
204+
call g:NERDTreeCreator.TogglePrimary("")
205205
endif
206206
endfunction
207207

plugin/nerdtree/creator.vim

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ function! s:Creator._broadcastInitEvent()
2727
silent doautocmd User NERDTreeInit
2828
endfunction
2929

30+
"FUNCTION: s:Creator.CreatePrimary(a:name) {{{1
31+
function! s:Creator.CreatePrimary(name)
32+
let creator = s:Creator.New()
33+
call creator.createPrimary(a:name)
34+
endfunction
35+
3036
"FUNCTION: s:Creator.createPrimary(a:name) {{{1
3137
"name: the name of a bookmark or a directory
3238
function! s:Creator.createPrimary(name)
@@ -63,6 +69,12 @@ function! s:Creator.createPrimary(name)
6369
call self._broadcastInitEvent()
6470
endfunction
6571

72+
"FUNCTION: s:Creator.CreateSecondary(dir) {{{1
73+
function! s:Creator.CreateSecondary(dir)
74+
let creator = s:Creator.New()
75+
call creator.createSecondary(a:dir)
76+
endfunction
77+
6678
"FUNCTION: s:Creator.createSecondary(dir) {{{1
6779
function! s:Creator.createSecondary(dir)
6880
try
@@ -94,6 +106,12 @@ function! s:Creator.createSecondary(dir)
94106
call self._broadcastInitEvent()
95107
endfunction
96108

109+
" FUNCTION: s:Creator.CreateMirror() {{{1
110+
function! s:Creator.CreateMirror()
111+
let creator = s:Creator.New()
112+
call creator.createMirror()
113+
endfunction
114+
97115
" FUNCTION: s:Creator.createMirror() {{{1
98116
function! s:Creator.createMirror()
99117
"get the names off all the nerd tree buffers
@@ -248,6 +266,12 @@ function! s:Creator._setupStatusline()
248266
endif
249267
endfunction
250268

269+
"FUNCTION: s:Creator.TogglePrimary(dir) {{{1
270+
function! s:Creator.TogglePrimary(dir)
271+
let creator = s:Creator.New()
272+
call creator.togglePrimary(a:dir)
273+
endfunction
274+
251275
"FUNCTION: s:Creator.togglePrimary(dir) {{{1
252276
"Toggles the NERD tree. I.e the NERD tree is open, it is closed, if it is
253277
"closed it is restored or initialized (if it doesnt exist)

plugin/nerdtree/opener.vim

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,17 +185,17 @@ endfunction
185185
function! s:Opener._openDirectory(node)
186186
if self._treetype ==# "secondary"
187187
call self._gotoTargetWin()
188-
call g:NERDTreeCreator.New().createSecondary(a:node.path.str())
188+
call g:NERDTreeCreator.CreateSecondary(a:node.path.str())
189189
else
190190
call self._gotoTargetWin()
191191
if empty(self._where)
192192
call a:node.makeRoot()
193193
call nerdtree#renderView()
194194
call a:node.putCursorHere(0, 0)
195195
elseif self._where == 't'
196-
call g:NERDTreeCreator.New().createPrimary(a:node.path.str())
196+
call g:NERDTreeCreator.CreatePrimary(a:node.path.str())
197197
else
198-
call g:NERDTreeCreator.New().createSecondary(a:node.path.str())
198+
call g:NERDTreeCreator.CreateSecondary(a:node.path.str())
199199
endif
200200
endif
201201

plugin/nerdtree/tree_dir_node.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ endfunction
351351
"FUNCTION: TreeDirNode._openInNewTab() {{{1
352352
function! s:TreeDirNode._openInNewTab()
353353
tabnew
354-
call g:NERDTreeCreator.New().createPrimary(self.path.str())
354+
call g:NERDTreeCreator.CreatePrimary(self.path.str())
355355
endfunction
356356

357357
"FUNCTION: TreeDirNode.openRecursively() {{{1

0 commit comments

Comments
 (0)