Bläddra i källkod

Add `split`, `vsplit` actions for `BufExplorer()`.

This addresses several issues:

- Issue #3, "Can <leader>\be do a toggle instead?".
- Issue #94, "Add variable setting, instead of command for
  BufExplorerVerticalSplit".
- Issue #106, "Support toggle for vertical/horizontal splits".

The ability to toggle BufExplorer using various split modes has been a
popular request.  This may be done now via:

```vim
:ToggleBufExplorer split
:ToggleBufExplorer vsplit
```

It's also possible now to adjust the default split mode for
`:BufExplorer` to be a preferred split mode (say, `vsplit`) via:

```vim
let g:bufExplorerDefaultAction = 'vsplit'
```
Michael Henry 9 månader sedan
förälder
incheckning
8212aad6f3
1 ändrade filer med 8 tillägg och 12 borttagningar
  1. 8 12
      plugin/bufexplorer.vim

+ 8 - 12
plugin/bufexplorer.vim

@@ -97,6 +97,8 @@ endif
 let s:actions = [
         \ 'current',
         \ 'close',
+        \ 'split',
+        \ 'vsplit',
         \ ]
 
 " Command-line completion function for `s:actions`.
@@ -134,7 +136,6 @@ let s:name = '[BufExplorer]'
 let s:bufExplorerBuffer = 0
 let s:running = 0
 let s:sort_by = ["number", "name", "fullpath", "mru", "extension"]
-let s:splitMode = ""
 let s:didSplit = 0
 let s:types = ["fullname", "homename", "path", "relativename", "relativepath", "shortname"]
 
@@ -541,7 +542,6 @@ function! s:Cleanup()
     endif
 
     let s:running = 0
-    let s:splitMode = ""
     let s:didSplit = 0
 
     delmarks!
@@ -572,16 +572,12 @@ endfunction
 
 " BufExplorerHorizontalSplit {{{2
 function! BufExplorerHorizontalSplit()
-    let s:splitMode = "sp"
-    execute "BufExplorer"
-    let s:splitMode = ""
+    call BufExplorer('split')
 endfunction
 
 " BufExplorerVerticalSplit {{{2
 function! BufExplorerVerticalSplit()
-    let s:splitMode = "vsp"
-    execute "BufExplorer"
-    let s:splitMode = ""
+    call BufExplorer('vsplit')
 endfunction
 
 " ToggleBufExplorer {{{2
@@ -662,19 +658,19 @@ function! BufExplorer(...)
     call s:MRUGarbageCollectTabs()
 
     " We may have to split the current window.
-    if s:splitMode != ""
+    if action != 'current'
         " Save off the original settings.
         let [_splitbelow, _splitright] = [&splitbelow, &splitright]
 
         " Set the setting to ours.
         let [&splitbelow, &splitright] = [g:bufExplorerSplitBelow, g:bufExplorerSplitRight]
-        let _size = (s:splitMode == "sp") ? g:bufExplorerSplitHorzSize : g:bufExplorerSplitVertSize
+        let _size = (action == "split") ? g:bufExplorerSplitHorzSize : g:bufExplorerSplitVertSize
 
         " Split the window either horizontally or vertically.
         if _size <= 0
-            execute 'keepalt ' . s:splitMode
+            execute 'keepalt ' . action
         else
-            execute 'keepalt ' . _size . s:splitMode
+            execute 'keepalt ' . _size . action
         endif
 
         " Restore the original settings.