From 64cb6204ccfeaa0ea73c946e0082b4da138f4a72 Mon Sep 17 00:00:00 2001 From: Martin Grenfell Date: Wed, 9 Jan 2013 09:48:16 +0000 Subject: [PATCH] move a couple of functions into NERDTreeCreator The "next buffer name" functions are only used in NERDTreeCreator so put them there. --- autoload/nerdtree.vim | 24 ------------------------ plugin/NERD_tree.vim | 4 ++-- plugin/nerdtree/creator.vim | 28 ++++++++++++++++++++++++++-- 3 files changed, 28 insertions(+), 28 deletions(-) diff --git a/autoload/nerdtree.vim b/autoload/nerdtree.vim index e6054e0..b8f69dc 100644 --- a/autoload/nerdtree.vim +++ b/autoload/nerdtree.vim @@ -33,11 +33,6 @@ function! nerdtree#bufInWindows(bnum) return cnt endfunction -" FUNCTION: nerdtree#bufNamePrefix() {{{2 -function! nerdtree#bufNamePrefix() - return 'NERD_tree_' -endfunction - "FUNCTION: nerdtree#checkForBrowse(dir) {{{2 "inits a secondary nerd tree in the current buffer if appropriate function! nerdtree#checkForBrowse(dir) @@ -232,25 +227,6 @@ function! nerdtree#invokeKeyMap(key) call g:NERDTreeKeyMap.Invoke(a:key) endfunction -" FUNCTION: nerdtree#nextBufferName() {{{2 -" returns the buffer name for the next nerd tree -function! nerdtree#nextBufferName() - let name = nerdtree#bufNamePrefix() . nerdtree#nextBufferNumber() - return name -endfunction - -" FUNCTION: nerdtree#nextBufferNumber() {{{2 -" the number to add to the nerd tree buffer name to make the buf name unique -function! nerdtree#nextBufferNumber() - if !exists("s:nextBufNum") - let s:nextBufNum = 1 - else - let s:nextBufNum += 1 - endif - - return s:nextBufNum -endfunction - " FUNCTION: nerdtree#postSourceActions() {{{2 function! nerdtree#postSourceActions() call g:NERDTreeBookmark.CacheBookmarks(0) diff --git a/plugin/NERD_tree.vim b/plugin/NERD_tree.vim index 8b853d4..6c19a3f 100644 --- a/plugin/NERD_tree.vim +++ b/plugin/NERD_tree.vim @@ -161,10 +161,10 @@ command! -n=0 -bar NERDTreeCWD call NERDTreeCWD() "============================================================ augroup NERDTree "Save the cursor position whenever we close the nerd tree - exec "autocmd BufWinLeave ". nerdtree#bufNamePrefix() ."* call nerdtree#saveScreenState()" + exec "autocmd BufWinLeave ". g:NERDTreeCreator.BufNamePrefix() ."* call nerdtree#saveScreenState()" "disallow insert mode in the NERDTree - exec "autocmd BufEnter ". nerdtree#bufNamePrefix() ."* stopinsert" + exec "autocmd BufEnter ". g:NERDTreeCreator.BufNamePrefix() ."* stopinsert" augroup END if g:NERDTreeHijackNetrw diff --git a/plugin/nerdtree/creator.vim b/plugin/nerdtree/creator.vim index 5adc960..ee5f740 100644 --- a/plugin/nerdtree/creator.vim +++ b/plugin/nerdtree/creator.vim @@ -27,6 +27,11 @@ function! s:Creator._broadcastInitEvent() silent doautocmd User NERDTreeInit endfunction +" FUNCTION: s:Creator.BufNamePrefix() {{{2 +function! s:Creator.BufNamePrefix() + return 'NERD_tree_' +endfunction + "FUNCTION: s:Creator.CreatePrimary(a:name) {{{1 function! s:Creator.CreatePrimary(name) let creator = s:Creator.New() @@ -91,7 +96,7 @@ function! s:Creator.createSecondary(dir) "we need a unique name for each secondary tree buffer to ensure they are "all independent - exec "silent edit " . nerdtree#nextBufferName() + exec "silent edit " . self._nextBufferName() let b:NERDTreePreviousBuf = bufnr(previousBuf) @@ -174,7 +179,7 @@ function! s:Creator._createTreeWin() let splitSize = g:NERDTreeWinSize if !exists('t:NERDTreeBufName') - let t:NERDTreeBufName = nerdtree#nextBufferName() + let t:NERDTreeBufName = self._nextBufferName() silent! exec splitLocation . 'vertical ' . splitSize . ' new' silent! exec "edit " . t:NERDTreeBufName else @@ -192,6 +197,25 @@ function! s:Creator.New() return newCreator endfunction +" FUNCTION: s:Creator._nextBufferName() {{{2 +" returns the buffer name for the next nerd tree +function! s:Creator._nextBufferName() + let name = s:Creator.BufNamePrefix() . self._nextBufferNumber() + return name +endfunction + +" FUNCTION: s:Creator._nextBufferNumber() {{{2 +" the number to add to the nerd tree buffer name to make the buf name unique +function! s:Creator._nextBufferNumber() + if !exists("s:Creator._NextBufNum") + let s:Creator._NextBufNum = 1 + else + let s:Creator._NextBufNum += 1 + endif + + return s:Creator._NextBufNum +endfunction + "FUNCTION: s:Creator._pathForString(str) {{{1 "find a bookmark or adirectory for the given string function! s:Creator._pathForString(str)