2012-08-17 03:41:25 +00:00
|
|
|
" @Author: Tom Link (micathom AT gmail com?subject=[vim])
|
|
|
|
" @Created: 2007-04-10.
|
2013-11-16 19:45:48 +00:00
|
|
|
" @Last Change: 2013-09-25.
|
2014-04-18 12:58:02 +00:00
|
|
|
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
|
2014-07-02 11:18:18 +00:00
|
|
|
" @Revision: 751
|
2014-04-18 12:58:02 +00:00
|
|
|
" @Website: http://www.vim.org/account/profile.php?user_id=4037
|
2012-08-17 03:41:25 +00:00
|
|
|
" GetLatestVimScripts: 1863 1 tlib.vim
|
2014-04-18 12:58:02 +00:00
|
|
|
" tlib.vim -- Some utility functions
|
2012-08-17 03:41:25 +00:00
|
|
|
|
|
|
|
if &cp || exists("loaded_tlib")
|
|
|
|
finish
|
|
|
|
endif
|
|
|
|
if v:version < 700 "{{{2
|
|
|
|
echoerr "tlib requires Vim >= 7"
|
|
|
|
finish
|
|
|
|
endif
|
2014-07-02 11:18:18 +00:00
|
|
|
let loaded_tlib = 110
|
2012-08-17 03:41:25 +00:00
|
|
|
|
|
|
|
let s:save_cpo = &cpo
|
|
|
|
set cpo&vim
|
|
|
|
|
|
|
|
|
|
|
|
" Init~ {{{1
|
|
|
|
" call tlib#autocmdgroup#Init()
|
|
|
|
|
|
|
|
|
|
|
|
" Commands~ {{{1
|
|
|
|
|
2013-04-13 17:45:21 +00:00
|
|
|
" :display: :TRequire NAME [VERSION [FILE]]
|
2012-08-17 03:41:25 +00:00
|
|
|
" Make a certain vim file is loaded.
|
|
|
|
"
|
|
|
|
" Conventions: If FILE isn't defined, plugin/NAME.vim is loaded. The
|
|
|
|
" file must provide a variable loaded_{NAME} that represents the version
|
|
|
|
" number.
|
|
|
|
command! -nargs=+ TRequire let s:require = [<f-args>]
|
|
|
|
\ | if !exists('loaded_'. get(s:require, 0))
|
|
|
|
\ | exec 'runtime '. get(s:require, 2, 'plugin/'. get(s:require, 0) .'.vim')
|
|
|
|
\ | if !exists('loaded_'. get(s:require, 0)) || loaded_{get(s:require, 0)} < get(s:require, 1, loaded_{get(s:require, 0)})
|
|
|
|
\ | echoerr 'Require '. get(s:require, 0) .' >= '. get(s:require, 1, 'any version will do')
|
|
|
|
\ | finish
|
|
|
|
\ | endif
|
|
|
|
\ | endif | unlet s:require
|
|
|
|
|
|
|
|
|
|
|
|
" :display: :TLet VAR = VALUE
|
|
|
|
" Set a variable only if it doesn't already exist.
|
|
|
|
" EXAMPLES: >
|
|
|
|
" TLet foo = 1
|
|
|
|
" TLet foo = 2
|
|
|
|
" echo foo
|
|
|
|
" => 1
|
|
|
|
command! -nargs=+ TLet if !exists(matchstr(<q-args>, '^[^=[:space:]]\+')) | exec 'let '. <q-args> | endif
|
|
|
|
|
|
|
|
|
|
|
|
" Open a scratch buffer (a buffer without a file).
|
|
|
|
" TScratch ... use split window
|
|
|
|
" TScratch! ... use the whole frame
|
|
|
|
" This command takes an (inner) dictionary as optional argument.
|
|
|
|
" EXAMPLES: >
|
|
|
|
" TScratch 'scratch': '__FOO__'
|
|
|
|
" => Open a scratch buffer named __FOO__
|
|
|
|
command! -bar -nargs=* -bang TScratch call tlib#scratch#UseScratch({'scratch_split': '<bang>' != '!', <args>})
|
|
|
|
|
|
|
|
|
|
|
|
" :display: :TVarArg VAR1, [VAR2, DEFAULT2] ...
|
|
|
|
" A convenience wrapper for |tlib#arg#Let|.
|
|
|
|
" EXAMPLES: >
|
|
|
|
" function! Foo(...)
|
|
|
|
" TVarArg ['a', 1], 'b'
|
|
|
|
" echo 'a='. a
|
|
|
|
" echo 'b='. b
|
|
|
|
" endf
|
|
|
|
command! -nargs=+ TVarArg exec tlib#arg#Let([<args>])
|
|
|
|
|
|
|
|
|
|
|
|
" :display: :TKeyArg DICT, VAR1, [VAR2, DEFAULT2] ...
|
|
|
|
" A convenience wrapper for |tlib#arg#Let|.
|
|
|
|
" EXAMPLES: >
|
|
|
|
" function! Foo(keyargs)
|
|
|
|
" TKeyArg a:keyargs, ['a', 1], 'b'
|
|
|
|
" echo 'a='. a
|
|
|
|
" echo 'b='. b
|
|
|
|
" endf
|
|
|
|
command! -nargs=+ TKeyArg exec tlib#arg#Key([<args>])
|
|
|
|
|
|
|
|
|
2013-04-13 17:45:21 +00:00
|
|
|
" :display: :TBrowseOutput COMMAND
|
2012-08-17 03:41:25 +00:00
|
|
|
" Ever wondered how to efficiently browse the output of a command
|
|
|
|
" without redirecting it to a file? This command takes a command as
|
|
|
|
" argument and presents the output via |tlib#input#List()| so that you
|
|
|
|
" can easily search for a keyword (e.g. the name of a variable or
|
|
|
|
" function) and the like.
|
|
|
|
"
|
|
|
|
" If you press enter, the selected line will be copied to the command
|
|
|
|
" line. Press ESC to cancel browsing.
|
|
|
|
"
|
|
|
|
" EXAMPLES: >
|
|
|
|
" TBrowseOutput 20verb TeaseTheCulprit
|
|
|
|
command! -nargs=1 -complete=command TBrowseOutput call tlib#cmd#BrowseOutput(<q-args>)
|
|
|
|
|
2013-04-13 17:45:21 +00:00
|
|
|
" :display: :TBrowseScriptnames
|
2012-08-17 03:41:25 +00:00
|
|
|
" List all sourced script names (the output of ':scriptnames').
|
|
|
|
"
|
|
|
|
" When you press enter, the selected script will be opened in the current
|
|
|
|
" window. Press ESC to cancel.
|
|
|
|
"
|
|
|
|
" EXAMPLES: >
|
|
|
|
" TBrowseScriptnames
|
|
|
|
command! -nargs=0 -complete=command TBrowseScriptnames call
|
|
|
|
\ tlib#cmd#BrowseOutputWithCallback("tlib#cmd#ParseScriptname", "scriptnames")
|
|
|
|
|
2013-04-13 17:45:21 +00:00
|
|
|
" :display: :TTimeCommand CMD
|
2012-08-17 03:41:25 +00:00
|
|
|
" Time the execution time of CMD.
|
|
|
|
command! -nargs=1 -complete=command TTimeCommand call tlib#cmd#Time(<q-args>)
|
|
|
|
|
|
|
|
|
|
|
|
let &cpo = s:save_cpo
|
|
|
|
unlet s:save_cpo
|