aboutsummaryrefslogtreecommitdiffstats
path: root/autoload
diff options
context:
space:
mode:
authorPeter Odding <peter@peterodding.com>2011-09-04 15:58:36 +0200
committerPeter Odding <peter@peterodding.com>2011-09-04 15:58:36 +0200
commit87811624857d0737943052032c2515de61903bed (patch)
tree57f7ad9a0674b2bc3b5de478234f0dd791e67fa1 /autoload
parentf526e2b8bce040ac91a6b3e1bf7dc297f9f2ca23 (diff)
parent2cfd5153a2cd25f5513a9c6aa72196691dd74d19 (diff)
downloadvim-easytags-87811624857d0737943052032c2515de61903bed.tar.gz
Merge branch 'master' of https://github.com/xolox/vim-misc
Diffstat (limited to 'autoload')
-rw-r--r--autoload/xolox/misc/buffer.vim37
1 files changed, 37 insertions, 0 deletions
diff --git a/autoload/xolox/misc/buffer.vim b/autoload/xolox/misc/buffer.vim
new file mode 100644
index 0000000..e4472e6
--- /dev/null
+++ b/autoload/xolox/misc/buffer.vim
@@ -0,0 +1,37 @@
+" Vim auto-load script
+" Author: Peter Odding <peter@peterodding.com>
+" Last Change: September 4, 2011
+" URL: http://peterodding.com/code/vim/misc/
+
+function! xolox#misc#buffer#is_empty()
+ " 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)
+ vsplit
+ endif
+ silent execute 'edit' fnameescape(bufname)
+ lcd " clear working directory
+ setlocal buftype=nofile bufhidden=hide noswapfile
+ let &l:statusline = bufname
+ call xolox#misc#buffer#unlock()
+ silent %delete
+endfunction
+
+function! xolox#misc#buffer#lock()
+ " Lock a special buffer so it can no longer be edited.
+ setlocal readonly nomodifiable nomodified
+endfunction
+
+function! xolox#misc#buffer#unlock()
+ " Unlock a special buffer so that its content can be updated.
+ setlocal noreadonly modifiable
+endfunction