diff options
Diffstat (limited to 'autoload/xolox/misc/buffer.vim')
-rw-r--r-- | autoload/xolox/misc/buffer.vim | 39 |
1 files changed, 34 insertions, 5 deletions
diff --git a/autoload/xolox/misc/buffer.vim b/autoload/xolox/misc/buffer.vim index 3597cc2..01dca6e 100644 --- a/autoload/xolox/misc/buffer.vim +++ b/autoload/xolox/misc/buffer.vim @@ -1,15 +1,44 @@ -" Vim auto-load script +" Handling of special buffers +" " Author: Peter Odding <peter@peterodding.com> -" Last Change: April 18, 2013 +" Last Change: May 19, 2013 " URL: http://peterodding.com/code/vim/misc/ +" +" The functions defined here make it easier to deal with special Vim buffers +" that contain text generated by a Vim plug-in. For example my [vim-notes +" plug-in] [vim-notes] generates several such buffers: +" +" - [:RecentNotes] [RecentNotes] lists recently modified notes +" - [:ShowTaggedNotes] [ShowTaggedNotes] lists notes grouped by tags +" - etc. +" +" Because the text in these buffers is generated, Vim shouldn't bother with +" swap files and it should never prompt the user whether to save changes to +" the generated text. +" +" [vim-notes]: http://peterodding.com/code/vim/notes/ +" [RecentNotes]: http://peterodding.com/code/vim/notes/#recentnotes_command +" [ShowTaggedNotes]: http://peterodding.com/code/vim/notes/#showtaggednotes_command function! xolox#misc#buffer#is_empty() " {{{1 - " Check if the current buffer is an empty, unchanged buffer which can be reused. + " Checks if the current buffer is an empty, unchanged buffer which can be + " reused. Returns 1 if an empty buffer is found, 0 otherwise. return !&modified && expand('%') == '' && line('$') <= 1 && getline(1) == '' endfunction function! xolox#misc#buffer#prepare(...) " {{{1 - " Open a special buffer (with generated contents, not directly edited by the user). + " Open a special buffer, i.e. a buffer that will hold generated contents, + " not directly edited by the user. The buffer can be customized by passing a + " dictionary with the following key/value pairs as the first argument: + " + " - **name** (required): The base name of the buffer (i.e. the base name of + " the file loaded in the buffer, even though it isn't really a file and + " nothing is really 'loaded' :-) + " - **path** (required): The pathname of the buffer. May be relevant if + " [:lcd] [lcd] or ['autochdir'] [acd] is being used. + " + " [lcd]: http://vimdoc.sourceforge.net/htmldoc/editing.html#:lcd + " [acd]: http://vimdoc.sourceforge.net/htmldoc/options.html#'autochdir' if a:0 == 1 && type(a:1) == type('') " Backwards compatibility with old interface. let options = {'name': a:1, 'path': a:1} @@ -41,7 +70,7 @@ function! xolox#misc#buffer#prepare(...) " {{{1 endfunction function! xolox#misc#buffer#lock() " {{{1 - " Lock a special buffer so it can no longer be edited. + " Lock a special buffer so that its contents can no longer be edited. setlocal readonly nomodifiable nomodified endfunction |