Kaynağa Gözat

Add actions to `:ToggleBufExplorer` and `ToggleBufExplorer()`.

Michael Henry 9 ay önce
ebeveyn
işleme
ff38122e4f
1 değiştirilmiş dosya ile 24 ekleme ve 5 silme
  1. 24 5
      plugin/bufexplorer.vim

+ 24 - 5
plugin/bufexplorer.vim

@@ -107,7 +107,8 @@ endfunction
 " Create commands {{{2
 " Create commands {{{2
 command! -nargs=? -complete=custom,<SID>ActionArgs
 command! -nargs=? -complete=custom,<SID>ActionArgs
         \ BufExplorer :call BufExplorer(<f-args>)
         \ BufExplorer :call BufExplorer(<f-args>)
-command! ToggleBufExplorer :call ToggleBufExplorer()
+command! -nargs=? -complete=custom,<SID>ActionArgs
+        \ ToggleBufExplorer :call ToggleBufExplorer(<f-args>)
 command! BufExplorerHorizontalSplit :call BufExplorerHorizontalSplit()
 command! BufExplorerHorizontalSplit :call BufExplorerHorizontalSplit()
 command! BufExplorerVerticalSplit :call BufExplorerVerticalSplit()
 command! BufExplorerVerticalSplit :call BufExplorerVerticalSplit()
 
 
@@ -584,12 +585,30 @@ function! BufExplorerVerticalSplit()
 endfunction
 endfunction
 
 
 " ToggleBufExplorer {{{2
 " ToggleBufExplorer {{{2
-function! ToggleBufExplorer()
-    if exists("s:running") && s:running == 1 && bufname(winbufnr(0)) == s:name
-        call s:Close()
+" Args: `([action])`
+" Optional `action` argument must be taken from `s:actions`.  If not present,
+" `action` defaults to `g:bufExplorerDefaultAction`.
+function! ToggleBufExplorer(...)
+    if a:0 >= 1
+        let action = a:1
     else
     else
-        call BufExplorer()
+        let action = g:bufExplorerDefaultAction
+    endif
+    if a:0 >= 2
+        echoerr 'Too many arguments'
+        return
+    endif
+
+    if index(s:actions, action) < 0
+        echoerr 'Invalid action ' . action
+        return
     endif
     endif
+
+    if s:running && bufnr('%') == s:bufExplorerBuffer
+        let action = 'close'
+    endif
+
+    call BufExplorer(action)
 endfunction
 endfunction
 
 
 " BufExplorer {{{2
 " BufExplorer {{{2