Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/xolox/vim-misc
- Loading branch information
Showing
1 changed file
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |