aboutsummaryrefslogtreecommitdiffstats
path: root/buffer.vim
diff options
context:
space:
mode:
authorPeter Odding <peter@peterodding.com>2013-04-18 02:11:40 +0200
committerPeter Odding <peter@peterodding.com>2013-04-18 02:11:40 +0200
commitca030c928d37d8400cbd576d13423411f3498c67 (patch)
treef302fe13347e7b1c8c62539be09ab815e2204027 /buffer.vim
parentb88ab45dae322f6780d8e0be0fdee2c7a68984ab (diff)
downloadvim-easytags-ca030c928d37d8400cbd576d13423411f3498c67.tar.gz
Improve xolox#misc#buffer#prepare()
Diffstat (limited to 'buffer.vim')
-rw-r--r--buffer.vim42
1 files changed, 28 insertions, 14 deletions
diff --git a/buffer.vim b/buffer.vim
index e4472e6..3597cc2 100644
--- a/buffer.vim
+++ b/buffer.vim
@@ -1,37 +1,51 @@
" Vim auto-load script
" Author: Peter Odding <peter@peterodding.com>
-" Last Change: September 4, 2011
+" Last Change: April 18, 2013
" URL: http://peterodding.com/code/vim/misc/
-function! xolox#misc#buffer#is_empty()
+function! xolox#misc#buffer#is_empty() " {{{1
" Check if the current buffer is an empty, unchanged buffer which can be reused.
return !&modified && expand('%') == '' && line('$') <= 1 && getline(1) == ''
endfunction
-function! xolox#misc#buffer#prepare(bufname)
- let bufname = '[' . a:bufname . ']'
- let buffers = tabpagebuflist()
- call map(buffers, 'fnamemodify(bufname(v:val), ":t:r")')
- let idx = index(buffers, bufname)
- if idx >= 0
- execute (idx + 1) . 'wincmd w'
- elseif !(xolox#misc#buffer#is_empty() || expand('%:t') == bufname)
+function! xolox#misc#buffer#prepare(...) " {{{1
+ " Open a special buffer (with generated contents, not directly edited by the user).
+ if a:0 == 1 && type(a:1) == type('')
+ " Backwards compatibility with old interface.
+ let options = {'name': a:1, 'path': a:1}
+ elseif type(a:1) == type({})
+ let options = a:1
+ else
+ throw "Invalid arguments"
+ endif
+ let winnr = 1
+ let found = 0
+ for bufnr in tabpagebuflist()
+ if xolox#misc#path#equals(options['path'], bufname(bufnr))
+ execute winnr . 'wincmd w'
+ let found = 1
+ break
+ else
+ let winnr += 1
+ endif
+ endfor
+ if !(found || xolox#misc#buffer#is_empty())
vsplit
endif
- silent execute 'edit' fnameescape(bufname)
+ silent execute 'edit' fnameescape(options['path'])
lcd " clear working directory
setlocal buftype=nofile bufhidden=hide noswapfile
- let &l:statusline = bufname
+ let &l:statusline = '[' . options['name'] . ']'
call xolox#misc#buffer#unlock()
silent %delete
endfunction
-function! xolox#misc#buffer#lock()
+function! xolox#misc#buffer#lock() " {{{1
" Lock a special buffer so it can no longer be edited.
setlocal readonly nomodifiable nomodified
endfunction
-function! xolox#misc#buffer#unlock()
+function! xolox#misc#buffer#unlock() " {{{1
" Unlock a special buffer so that its content can be updated.
setlocal noreadonly modifiable
endfunction