Permalink
Browse files

Cleaned up old miscellaneous scripts

  • Loading branch information...
1 parent fecbb5e commit cc0c218fa0bab44b3efa32a15f9fffbfc8b29aa2 @xolox committed Aug 19, 2013
@@ -1,80 +0,0 @@
-" 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#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#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#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(options['path'])
- lcd " clear working directory
- setlocal buftype=nofile bufhidden=hide noswapfile
- let &l:statusline = '[' . options['name'] . ']'
- call xolox#misc#buffer#unlock()
- silent %delete
-endfunction
-
-function! xolox#misc#buffer#lock() " {{{1
- " Lock a special buffer so that its contents can no longer be edited.
- setlocal readonly nomodifiable nomodified
-endfunction
-
-function! xolox#misc#buffer#unlock() " {{{1
- " Unlock a special buffer so that its content can be updated.
- setlocal noreadonly modifiable
-endfunction
@@ -1,37 +0,0 @@
-" Compatibility checking.
-"
-" Author: Peter Odding <peter@peterodding.com>
-" Last Change: May 20, 2013
-" URL: http://peterodding.com/code/vim/misc/
-"
-" This Vim script defines a version number for the miscellaneous scripts. Each
-" of my plug-ins compares their expected version of the miscellaneous scripts
-" against the version number defined inside the miscellaneous scripts.
-"
-" The version number is incremented whenever a change in the miscellaneous
-" scripts breaks backwards compatibility. This enables my Vim plug-ins to fail
-" early when they detect an incompatible version, instead of breaking at the
-" worst possible moments :-).
-let g:xolox#misc#compat#version = 9
-
-" Remember the directory where the miscellaneous scripts are loaded from
-" so the user knows which plug-in to update if incompatibilities arise.
-let s:misc_directory = fnamemodify(expand('<sfile>'), ':~:h')
-
-function! xolox#misc#compat#check(plugin_name, plugin_version, required_version)
- " Expects three arguments:
- "
- " 1. The name of the Vim plug-in that is using the miscellaneous scripts
- " 2. The version of the Vim plug-in that is using the miscellaneous scripts
- " 3. The version of the miscellaneous scripts expected by the plug-in
- "
- " When the loaded version of the miscellaneous scripts is different from the
- " version expected by the plug-in, this function will raise an error message
- " that explains what went wrong.
- if a:required_version != g:xolox#misc#compat#version
- let msg = "The %s %s plug-in expects version %i of the miscellaneous scripts, however version %i was loaded from the directory %s! Please upgrade your plug-ins to the latest releases to resolve this problem."
- throw printf(msg, a:plugin_name, a:plugin_version, a:required_version, g:xolox#misc#compat#version, s:misc_directory)
- endif
-endfunction
-
-" vim: ts=2 sw=2 et
@@ -1,22 +0,0 @@
-" 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#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#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
@@ -1,56 +0,0 @@
-" String escaping functions.
-"
-" Author: Peter Odding <peter@peterodding.com>
-" Last Change: May 19, 2013
-" URL: http://peterodding.com/code/vim/misc/
-
-function! xolox#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#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#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#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
@@ -1,57 +0,0 @@
-" List handling functions.
-"
-" Author: Peter Odding <peter@peterodding.com>
-" Last Change: May 19, 2013
-" URL: http://peterodding.com/code/vim/misc/
-
-function! xolox#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#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#misc#list#binsert().
- let s:list = ['a', 'B', 'e']
- function! s:test(value, expected)
- call xolox#misc#list#binsert(s:list, a:value, 1)
- if s:list != a:expected
- call xolox#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
@@ -1,91 +0,0 @@
-" 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#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#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#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 cc0c218

Please sign in to comment.