Permalink
Browse files

Release 0.21.4

  • Loading branch information...
1 parent fb59e17 commit 32019ec96e5b07ce2b42f132f8dd81522b306bad @xolox committed May 21, 2013
View
Oops, something went wrong.
@@ -0,0 +1,86 @@
+" This Vim script was modified by a Python script that I use to manage the
+" inclusion of miscellaneous functions in the plug-ins that I publish to Vim
+" Online and GitHub. Please don't edit this file, instead make your changes on
+" the 'dev' branch of the git repository (thanks!). This file was generated on
+" May 21, 2013 at 03:00.
+
+" Handling of special buffers
+"
+" Author: Peter Odding <peter@peterodding.com>
+" 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#notes#misc#buffer#is_empty() " {{{1
+ " 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#notes#misc#buffer#prepare(...) " {{{1
+ " 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}
+ 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#notes#misc#path#equals(options['path'], bufname(bufnr))
+ execute winnr . 'wincmd w'
+ let found = 1
+ break
+ else
+ let winnr += 1
+ endif
+ endfor
+ if !(found || xolox#notes#misc#buffer#is_empty())
+ vsplit
+ endif
+ silent execute 'edit' fnameescape(options['path'])
+ lcd " clear working directory
+ setlocal buftype=nofile bufhidden=hide noswapfile
+ let &l:statusline = '[' . options['name'] . ']'
+ call xolox#notes#misc#buffer#unlock()
+ silent %delete
+endfunction
+
+function! xolox#notes#misc#buffer#lock() " {{{1
+ " Lock a special buffer so that its contents can no longer be edited.
+ setlocal readonly nomodifiable nomodified
+endfunction
+
+function! xolox#notes#misc#buffer#unlock() " {{{1
+ " Unlock a special buffer so that its content can be updated.
+ setlocal noreadonly modifiable
+endfunction
@@ -0,0 +1,28 @@
+" This Vim script was modified by a Python script that I use to manage the
+" inclusion of miscellaneous functions in the plug-ins that I publish to Vim
+" Online and GitHub. Please don't edit this file, instead make your changes on
+" the 'dev' branch of the git repository (thanks!). This file was generated on
+" May 21, 2013 at 03:00.
+
+" Tab completion for user defined commands.
+"
+" Author: Peter Odding <peter@peterodding.com>
+" Last Change: May 19, 2013
+" URL: http://peterodding.com/code/vim/misc/
+
+function! xolox#notes#misc#complete#keywords(arglead, cmdline, cursorpos)
+ " This function can be used to perform keyword completion for user defined
+ " Vim commands based on the contents of the current buffer. Here's an
+ " example of how you would use it:
+ "
+ " :command -nargs=* -complete=customlist,xolox#notes#misc#complete#keywords MyCmd call s:MyCmd(<f-args>)
+ let words = {}
+ for line in getline(1, '$')
+ for word in split(line, '\W\+')
+ let words[word] = 1
+ endfor
+ endfor
+ return sort(keys(filter(words, 'v:key =~# a:arglead')))
+endfunction
+
+" vim: ts=2 sw=2 et
@@ -0,0 +1,62 @@
+" This Vim script was modified by a Python script that I use to manage the
+" inclusion of miscellaneous functions in the plug-ins that I publish to Vim
+" Online and GitHub. Please don't edit this file, instead make your changes on
+" the 'dev' branch of the git repository (thanks!). This file was generated on
+" May 21, 2013 at 03:00.
+
+" String escaping functions.
+"
+" Author: Peter Odding <peter@peterodding.com>
+" Last Change: May 19, 2013
+" URL: http://peterodding.com/code/vim/misc/
+
+function! xolox#notes#misc#escape#pattern(string) " {{{1
+ " Takes a single string argument and converts it into a [:substitute]
+ " [subcmd] / [substitute()] [subfun] pattern string that matches the given
+ " string literally.
+ "
+ " [subfun]: http://vimdoc.sourceforge.net/htmldoc/eval.html#substitute()
+ " [subcmd]: http://vimdoc.sourceforge.net/htmldoc/change.html#:substitute
+ if type(a:string) == type('')
+ let string = escape(a:string, '^$.*\~[]')
+ return substitute(string, '\n', '\\n', 'g')
+ endif
+ return ''
+endfunction
+
+function! xolox#notes#misc#escape#substitute(string) " {{{1
+ " Takes a single string argument and converts it into a [:substitute]
+ " [subcmd] / [substitute()] [subfun] replacement string that inserts the
+ " given string literally.
+ if type(a:string) == type('')
+ let string = escape(a:string, '\&~%')
+ return substitute(string, '\n', '\\r', 'g')
+ endif
+ return ''
+endfunction
+
+function! xolox#notes#misc#escape#shell(string) " {{{1
+ " Takes a single string argument and converts it into a quoted command line
+ " argument.
+ "
+ " I was going to add a long rant here about Vim's ['shellslash' option]
+ " [shellslash], but really, it won't make any difference. Let's just suffice
+ " to say that I have yet to encounter a single person out there who uses
+ " this option for its intended purpose (running a UNIX style shell on
+ " Microsoft Windows).
+ "
+ " [shellslash]: http://vimdoc.sourceforge.net/htmldoc/options.html#'shellslash'
+ if xolox#notes#misc#os#is_win()
+ try
+ let ssl_save = &shellslash
+ set noshellslash
+ return shellescape(a:string)
+ finally
+ let &shellslash = ssl_save
+ endtry
+ else
+ return shellescape(a:string)
+ endif
+endfunction
+
+" vim: ts=2 sw=2 et
@@ -0,0 +1,63 @@
+" This Vim script was modified by a Python script that I use to manage the
+" inclusion of miscellaneous functions in the plug-ins that I publish to Vim
+" Online and GitHub. Please don't edit this file, instead make your changes on
+" the 'dev' branch of the git repository (thanks!). This file was generated on
+" May 21, 2013 at 03:00.
+
+" List handling functions.
+"
+" Author: Peter Odding <peter@peterodding.com>
+" Last Change: May 19, 2013
+" URL: http://peterodding.com/code/vim/misc/
+
+function! xolox#notes#misc#list#unique(list) " {{{1
+ " Remove duplicate values from the given list in-place (preserves order).
+ call reverse(a:list)
+ call filter(a:list, 'count(a:list, v:val) == 1')
+ return reverse(a:list)
+endfunction
+
+function! xolox#notes#misc#list#binsert(list, value, ...) " {{{1
+ " Performs in-place binary insertion, which depending on your use case can
+ " be more efficient than calling Vim's [sort()] [sort] function after each
+ " insertion (in cases where a single, final sort is not an option). Expects
+ " three arguments:
+ "
+ " 1. A list
+ " 2. A value to insert
+ " 3. 1 (true) when case should be ignored, 0 (false) otherwise
+ "
+ " [sort]: http://vimdoc.sourceforge.net/htmldoc/eval.html#sort()
+ let idx = s:binsert_r(a:list, 0, len(a:list), a:value, exists('a:1') && a:1)
+ return insert(a:list, a:value, idx)
+endfunction
+
+function! s:binsert_r(list, low, high, value, ignorecase)
+ let mid = a:low + (a:high - a:low) / 2
+ if a:low == a:high
+ return a:low
+ elseif a:ignorecase ? a:value >? a:list[mid] : a:value > a:list[mid]
+ return s:binsert_r(a:list, mid + 1, a:high, a:value, a:ignorecase)
+ elseif a:ignorecase ? a:value <? a:list[mid] : a:value < a:list[mid]
+ return s:binsert_r(a:list, a:low, mid, a:value, a:ignorecase)
+ else
+ return mid
+ endif
+endfunction
+
+if 0
+ " Tests for xolox#notes#misc#list#binsert().
+ let s:list = ['a', 'B', 'e']
+ function! s:test(value, expected)
+ call xolox#notes#misc#list#binsert(s:list, a:value, 1)
+ if s:list != a:expected
+ call xolox#notes#misc#msg#warn("list.vim: Test failed! Expected %s, got %s",
+ \ string(a:expected), string(s:list))
+ endif
+ endfunction
+ call s:test('c', ['a', 'B', 'c', 'e'])
+ call s:test('D', ['a', 'B', 'c', 'D', 'e'])
+ call s:test('f', ['a', 'B', 'c', 'D', 'e', 'f'])
+endif
+
+" vim: ts=2 sw=2 et
@@ -0,0 +1,97 @@
+" This Vim script was modified by a Python script that I use to manage the
+" inclusion of miscellaneous functions in the plug-ins that I publish to Vim
+" Online and GitHub. Please don't edit this file, instead make your changes on
+" the 'dev' branch of the git repository (thanks!). This file was generated on
+" May 21, 2013 at 03:00.
+
+" Functions to interact with the user.
+"
+" Author: Peter Odding <peter@peterodding.com>
+" Last Change: May 20, 2013
+" URL: http://peterodding.com/code/vim/misc/
+
+if !exists('g:xolox_message_buffer')
+ " For when I lose my :messages history :-\
+ let g:xolox_message_buffer = 100
+endif
+
+if !exists('g:xolox_messages')
+ let g:xolox_messages = []
+endif
+
+function! xolox#notes#misc#msg#info(...) " {{{1
+ " Show a formatted informational message to the user. This function has the
+ " same argument handling as Vim's [printf()] [printf] function.
+ "
+ " [printf]: http://vimdoc.sourceforge.net/htmldoc/eval.html#printf()
+ call s:show_message('title', a:000)
+endfunction
+
+function! xolox#notes#misc#msg#warn(...) " {{{1
+ " Show a formatted warning message to the user. This function has the same
+ " argument handling as Vim's [printf()] [printf] function.
+ call s:show_message('warningmsg', a:000)
+endfunction
+
+function! xolox#notes#misc#msg#debug(...) " {{{1
+ " Show a formatted debugging message to the user, if the user has enabled
+ " increased verbosity by setting Vim's ['verbose'] [verbose] option to one
+ " (1) or higher. This function has the same argument handling as Vim's
+ " [printf()] [printf] function.
+ if &vbs >= 1
+ call s:show_message('question', a:000)
+ endif
+endfunction
+
+function! s:show_message(hlgroup, args) " {{{1
+ " The implementation of info() and warn().
+ let nargs = len(a:args)
+ if nargs == 1
+ let message = a:args[0]
+ elseif nargs >= 2
+ let message = call('printf', a:args)
+ endif
+ if exists('message')
+ try
+ " Temporarily disable Vim's |hit-enter| prompt and mode display.
+ if !exists('s:more_save')
+ let s:more_save = &more
+ let s:ruler_save = &ruler
+ let s:smd_save = &showmode
+ endif
+ set nomore noshowmode
+ if winnr('$') == 1 | set noruler | endif
+ augroup PluginXoloxHideMode
+ autocmd! CursorHold,CursorHoldI * call s:clear_message()
+ augroup END
+ execute 'echohl' a:hlgroup
+ " Redraw to avoid |hit-enter| prompt.
+ redraw
+ for line in split(message, "\n")
+ echomsg line
+ endfor
+ if g:xolox_message_buffer > 0
+ call add(g:xolox_messages, message)
+ if len(g:xolox_messages) > g:xolox_message_buffer
+ call remove(g:xolox_messages, 0)
+ endif
+ endif
+ finally
+ " Always clear message highlighting, even when interrupted by Ctrl-C.
+ echohl none
+ endtry
+ endif
+endfunction
+
+function! s:clear_message() " {{{1
+ " Callback to clear message after some time has passed.
+ echo ''
+ let &more = s:more_save
+ let &showmode = s:smd_save
+ let &ruler = s:ruler_save
+ unlet s:more_save s:ruler_save s:smd_save
+ autocmd! PluginXoloxHideMode
+ augroup! PluginXoloxHideMode
+endfunction
+
+" vim: ts=2 sw=2 et
Oops, something went wrong.

0 comments on commit 32019ec

Please sign in to comment.