mirror of
https://github.com/amix/vimrc
synced 2025-02-28 14:12:51 +08:00
mac ok
This commit is contained in:
parent
a8f0b6f678
commit
960d858e9e
@ -1,72 +0,0 @@
|
||||
This is a mirror of http://www.vim.org/scripts/script.php?script_id=1863
|
||||
|
||||
This library provides some utility functions. There isn't much need to
|
||||
install it unless another plugin requires you to do so.
|
||||
|
||||
The most useful functions provided by this library probably are:
|
||||
|
||||
tlib#input#List(), tlib#input#ListW()
|
||||
- Display a list
|
||||
- Dynamically filter items matching a pattern (somethat like google)
|
||||
- E.g. you filter for "foo -bar": show all entries containing foo but not bar.
|
||||
- Select items from a list
|
||||
- Do stuff
|
||||
- Developers can define keys that trigger some action with the
|
||||
selected items
|
||||
- Demo: http://vimsomnia.blogspot.com/2010/11/selecting-items-from-list-with-tlibs.html
|
||||
|
||||
tlib#input#EditList
|
||||
+ Edit a list (copy, cut, paste, delete, edit ...)
|
||||
|
||||
:TLet VAR = VALUE
|
||||
Set a variable only if it doesn't already exist.
|
||||
|
||||
:TScratch
|
||||
Open a scratch buffer (a buffer without a file).
|
||||
|
||||
:TVarArg VAR1, [VAR2, DEFAULT2] ...
|
||||
Handle "rest" (variable) arguments in functions.
|
||||
EXAMPLES:
|
||||
function! Foo(...)
|
||||
TVarArg ['a', 1], 'b'
|
||||
echo 'a='. a
|
||||
echo 'b='. b
|
||||
endf
|
||||
|
||||
TBrowseOutput COMMAND
|
||||
Every wondered how to effciently 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
|
||||
TBrowseOutput let
|
||||
TBrowseOutput map
|
||||
|
||||
|
||||
Related (small) plugins that utilize tlib and thus provide some degree of uniform user experience:
|
||||
tbibtools (vimscript #1915): bibtex-related utilities (sort, reformat, list contents ...)
|
||||
tmarks (vimscript #2594): Browse, place, & delete marks
|
||||
tmboxbrowser (vimscript #1906): A mbox browser -- Read your e-mails with vim
|
||||
tmru (vimscript #1864): Most Recently Used Files
|
||||
trag (vimscript #2033): A slightly language-aware alternative to grep
|
||||
tregisters (vimscript #2017): List, edit, and run/execute registers/clipboards
|
||||
tselectbuffer (vimscript #1866): A quick buffer selector/switcher
|
||||
tselectfiles (vimscript #1865): A quick file selector/browser/explorer (sort of)
|
||||
ttagecho (vimscript #2055): Show current tag information
|
||||
ttagcomplete (vimscript #2069): Context-sensitive tags-based completion and code skeletons
|
||||
ttags (vimscript #2018): Tag list browser (List, filter, preview, jump to tags)
|
||||
ttoc (vimscript #2014): A regexp-based table of contents of the current buffer
|
||||
vikitasks (vimscript #2894): Search viki files for tasks and display them in a list
|
||||
|
||||
|
||||
For full details, please see:
|
||||
http://github.com/tomtom/tlib_vim/blob/master/doc/tlib.txt
|
||||
|
||||
Also available via git
|
||||
http://github.com/tomtom/tlib_vim
|
@ -1,8 +0,0 @@
|
||||
" @Author: Tom Link (micathom AT gmail com?subject=[vim])
|
||||
" @Website: http://www.vim.org/account/profile.php?user_id=4037
|
||||
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
|
||||
" @Revision: 13
|
||||
|
||||
" :nodefault:
|
||||
TLet g:tlib#debug = 0
|
||||
|
@ -1,151 +0,0 @@
|
||||
" Filter_cnf.vim
|
||||
" @Author: Tom Link (mailto:micathom AT gmail com?subject=[vim])
|
||||
" @Website: http://www.vim.org/account/profile.php?user_id=4037
|
||||
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
|
||||
" @Created: 2008-11-25.
|
||||
" @Last Change: 2014-11-18.
|
||||
" @Revision: 0.0.114
|
||||
|
||||
let s:prototype = tlib#Object#New({'_class': ['Filter_cnf'], 'name': 'cnf'}) "{{{2
|
||||
let s:prototype.highlight = g:tlib#input#higroup
|
||||
|
||||
" The search pattern for |tlib#input#List()| is in conjunctive normal
|
||||
" form: (P1 OR P2 ...) AND (P3 OR P4 ...) ...
|
||||
" The pattern is a '/\V' very no-'/magic' regexp pattern.
|
||||
"
|
||||
" Pressing <space> joins two patterns with AND.
|
||||
" Pressing | joins two patterns with OR.
|
||||
" I.e. In order to get "lala AND (foo OR bar)", you type
|
||||
" "lala foo|bar".
|
||||
"
|
||||
" This is also the base class for other filters.
|
||||
function! tlib#Filter_cnf#New(...) "{{{3
|
||||
let object = s:prototype.New(a:0 >= 1 ? a:1 : {})
|
||||
return object
|
||||
endf
|
||||
|
||||
|
||||
" :nodoc:
|
||||
function! s:prototype.Init(world) dict "{{{3
|
||||
endf
|
||||
|
||||
|
||||
" :nodoc:
|
||||
function! s:prototype.Help(world) dict "{{{3
|
||||
call a:world.PushHelp(
|
||||
\ printf('"%s", "%s", "%sWORD"', g:tlib#input#and, g:tlib#input#or, g:tlib#input#not),
|
||||
\ 'AND, OR, NOT')
|
||||
endf
|
||||
|
||||
|
||||
" :nodoc:
|
||||
function! s:prototype.AssessName(world, name) dict "{{{3
|
||||
let xa = 0
|
||||
let prefix = self.FilterRxPrefix()
|
||||
for flt in a:world.filter_pos
|
||||
" let flt = prefix . a:world.GetRx(fltl)
|
||||
" if flt =~# '\u' && a:name =~# flt
|
||||
" let xa += 5
|
||||
" endif
|
||||
|
||||
if a:name =~ '\^'. flt
|
||||
let xa += 4
|
||||
elseif a:name =~ '\<'. flt
|
||||
let xa += 3
|
||||
" elseif a:name =~ '[[:punct:][:space:][:digit:]]'. flt
|
||||
" let xa += 2
|
||||
elseif a:name =~ '\A'. flt .'\|'. flt .'\A'
|
||||
let xa += 1
|
||||
endif
|
||||
endfor
|
||||
" TLogVAR a:name, xa
|
||||
return xa
|
||||
endf
|
||||
|
||||
|
||||
" :nodoc:
|
||||
function! s:prototype.Match(world, text) dict "{{{3
|
||||
" TLogVAR a:text
|
||||
" let sc = &smartcase
|
||||
" let ic = &ignorecase
|
||||
" if &ignorecase
|
||||
" set smartcase
|
||||
" endif
|
||||
" try
|
||||
if !empty(a:world.filter_neg)
|
||||
for rx in a:world.filter_neg
|
||||
" TLogVAR rx
|
||||
if a:text =~ rx
|
||||
return 0
|
||||
endif
|
||||
endfor
|
||||
endif
|
||||
if !empty(a:world.filter_pos)
|
||||
for rx in a:world.filter_pos
|
||||
" TLogVAR rx
|
||||
if a:text !~ rx
|
||||
return 0
|
||||
endif
|
||||
endfor
|
||||
endif
|
||||
" finally
|
||||
" let &smartcase = sc
|
||||
" let &ignorecase = ic
|
||||
" endtry
|
||||
return 1
|
||||
endf
|
||||
|
||||
|
||||
" :nodoc:
|
||||
function! s:prototype.DisplayFilter(filter) dict "{{{3
|
||||
let filter1 = deepcopy(a:filter)
|
||||
call map(filter1, '"(". join(reverse(self.Pretty(v:val)), " OR ") .")"')
|
||||
return join(reverse(filter1), ' AND ')
|
||||
endf
|
||||
|
||||
|
||||
function! s:prototype.Pretty(filter) dict "{{{3
|
||||
" call map(a:filter, 'substitute(v:val, ''\\\.\\{-}'', ''=>'', ''g'')')
|
||||
call map(a:filter, 'self.CleanFilter(v:val)')
|
||||
return a:filter
|
||||
endf
|
||||
|
||||
|
||||
" :nodoc:
|
||||
function! s:prototype.SetFrontFilter(world, pattern) dict "{{{3
|
||||
let a:world.filter[0] = reverse(split(a:pattern, '\s*|\s*')) + a:world.filter[0][1 : -1]
|
||||
endf
|
||||
|
||||
|
||||
" :nodoc:
|
||||
function! s:prototype.PushFrontFilter(world, char) dict "{{{3
|
||||
let a:world.filter[0][0] .= nr2char(a:char)
|
||||
endf
|
||||
|
||||
|
||||
" :nodoc:
|
||||
function! s:prototype.ReduceFrontFilter(world) dict "{{{3
|
||||
let filter = a:world.filter[0][0]
|
||||
" TLogVAR filter
|
||||
let str = matchstr(filter, '\(\\\(\.\\{-}\|[.?*+$^]\)\|\)$')
|
||||
if empty(str)
|
||||
let filter = filter[0 : -2]
|
||||
else
|
||||
let filter = strpart(filter, 0, len(filter) - len(str))
|
||||
endif
|
||||
" TLogVAR str, filter
|
||||
let a:world.filter[0][0] = filter
|
||||
endf
|
||||
|
||||
|
||||
" :nodoc:
|
||||
function! s:prototype.FilterRxPrefix() dict "{{{3
|
||||
return '\V'
|
||||
endf
|
||||
|
||||
|
||||
" :nodoc:
|
||||
function! s:prototype.CleanFilter(filter) dict "{{{3
|
||||
return a:filter
|
||||
endf
|
||||
|
@ -1,53 +0,0 @@
|
||||
" Filter_cnfd.vim
|
||||
" @Author: Tom Link (mailto:micathom AT gmail com?subject=[vim])
|
||||
" @Website: http://www.vim.org/account/profile.php?user_id=4037
|
||||
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
|
||||
" @Created: 2008-11-25.
|
||||
" @Last Change: 2014-01-23.
|
||||
" @Revision: 0.0.57
|
||||
|
||||
let s:prototype = tlib#Filter_cnf#New({'_class': ['Filter_cnfd'], 'name': 'cnfd'}) "{{{2
|
||||
let s:prototype.highlight = g:tlib#input#higroup
|
||||
|
||||
|
||||
" The same as |tlib#Filter_cnf#New()| but a dot is expanded to '\.\{-}'.
|
||||
" As a consequence, patterns cannot match dots.
|
||||
" The pattern is a '/\V' very no-'/magic' regexp pattern.
|
||||
function! tlib#Filter_cnfd#New(...) "{{{3
|
||||
let object = s:prototype.New(a:0 >= 1 ? a:1 : {})
|
||||
return object
|
||||
endf
|
||||
|
||||
|
||||
" :nodoc:
|
||||
function! s:prototype.Init(world) dict "{{{3
|
||||
endf
|
||||
|
||||
|
||||
let s:Help = s:prototype.Help
|
||||
|
||||
" :nodoc:
|
||||
function! s:prototype.Help(world) dict "{{{3
|
||||
call call(s:Help, [a:world], self)
|
||||
call a:world.PushHelp('.', 'Any characters')
|
||||
endf
|
||||
|
||||
|
||||
" :nodoc:
|
||||
function! s:prototype.SetFrontFilter(world, pattern) dict "{{{3
|
||||
let pattern = substitute(a:pattern, '\.', '\\.\\{-}', 'g')
|
||||
let a:world.filter[0] = reverse(split(pattern, '\s*|\s*')) + a:world.filter[0][1 : -1]
|
||||
endf
|
||||
|
||||
|
||||
" :nodoc:
|
||||
function! s:prototype.PushFrontFilter(world, char) dict "{{{3
|
||||
let a:world.filter[0][0] .= a:char == 46 ? '\.\{-}' : nr2char(a:char)
|
||||
endf
|
||||
|
||||
|
||||
" :nodoc:
|
||||
function! s:prototype.CleanFilter(filter) dict "{{{3
|
||||
return substitute(a:filter, '\\.\\{-}', '.', 'g')
|
||||
endf
|
||||
|
@ -1,83 +0,0 @@
|
||||
" Filter_fuzzy.vim
|
||||
" @Author: Tom Link (mailto:micathom AT gmail com?subject=[vim])
|
||||
" @Website: http://www.vim.org/account/profile.php?user_id=4037
|
||||
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
|
||||
" @Created: 2008-11-25.
|
||||
" @Last Change: 2013-09-25.
|
||||
" @Revision: 0.0.47
|
||||
|
||||
let s:prototype = tlib#Filter_cnf#New({'_class': ['Filter_fuzzy'], 'name': 'fuzzy'}) "{{{2
|
||||
let s:prototype.highlight = g:tlib#input#higroup
|
||||
|
||||
|
||||
" Support for "fuzzy" pattern matching in |tlib#input#List()|.
|
||||
" Patterns are interpreted as if characters were connected with '.\{-}'.
|
||||
"
|
||||
" In "fuzzy" mode, the pretty printing of filenames is disabled.
|
||||
function! tlib#Filter_fuzzy#New(...) "{{{3
|
||||
let object = s:prototype.New(a:0 >= 1 ? a:1 : {})
|
||||
return object
|
||||
endf
|
||||
|
||||
|
||||
" :nodoc:
|
||||
function! s:prototype.Init(world) dict "{{{3
|
||||
" TLogVAR a:world.display_format
|
||||
" :nodoc:
|
||||
function! a:world.Set_display_format(value) dict
|
||||
if a:value == 'filename'
|
||||
let self.display_format = ''
|
||||
else
|
||||
let self.display_format = a:value
|
||||
endif
|
||||
endf
|
||||
endf
|
||||
|
||||
|
||||
let s:Help = s:prototype.Help
|
||||
|
||||
" :nodoc:
|
||||
function! s:prototype.Help(world) dict "{{{3
|
||||
call call(s:Help, [a:world], self)
|
||||
call a:world.PushHelp('Patterns are interpreted as if characters were connected with .\{-}')
|
||||
endf
|
||||
|
||||
|
||||
" :nodoc:
|
||||
function! s:prototype.DisplayFilter(filter) dict "{{{3
|
||||
" TLogVAR a:filter
|
||||
let filter1 = deepcopy(a:filter)
|
||||
call map(filter1, '"{". join(reverse(v:val), " OR ") ."}"')
|
||||
return join(reverse(filter1), ' AND ')
|
||||
endf
|
||||
|
||||
|
||||
" :nodoc:
|
||||
function! s:prototype.SetFrontFilter(world, pattern) dict "{{{3
|
||||
let a:world.filter[0] = map(reverse(split(a:pattern, '\s*|\s*')), 'join(map(split(v:val, ''\zs''), ''tlib#rx#Escape(v:val, "V")''), ''\.\{-}'')') + a:world.filter[0][1 : -1]
|
||||
endif
|
||||
endf
|
||||
|
||||
|
||||
" :nodoc:
|
||||
function! s:prototype.PushFrontFilter(world, char) dict "{{{3
|
||||
let ch = tlib#rx#Escape(nr2char(a:char), 'V')
|
||||
if empty(a:world.filter[0][0])
|
||||
let a:world.filter[0][0] .= ch
|
||||
else
|
||||
let a:world.filter[0][0] .= '\.\{-}'. ch
|
||||
endif
|
||||
endf
|
||||
|
||||
|
||||
" :nodoc:
|
||||
function! s:prototype.ReduceFrontFilter(world) dict "{{{3
|
||||
let a:world.filter[0][0] = substitute(a:world.filter[0][0], '\(\\\.\\{-}\)\?.$', '', '')
|
||||
endf
|
||||
|
||||
|
||||
" :nodoc:
|
||||
function! s:prototype.CleanFilter(filter) dict "{{{3
|
||||
return substitute(a:filter, '\\\.\\{-}', '', 'g')
|
||||
endf
|
||||
|
@ -1,68 +0,0 @@
|
||||
" @Author: Tom Link (mailto:micathom AT gmail com?subject=[vim])
|
||||
" @Website: http://www.vim.org/account/profile.php?user_id=4037
|
||||
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
|
||||
" @Created: 2008-11-25.
|
||||
" @Last Change: 2014-11-18.
|
||||
" @Revision: 0.0.82
|
||||
|
||||
let s:prototype = tlib#Filter_cnf#New({'_class': ['Filter_glob'], 'name': 'glob'}) "{{{2
|
||||
let s:prototype.highlight = g:tlib#input#higroup
|
||||
|
||||
|
||||
" A character that should be expanded to '\.\{-}'.
|
||||
TLet g:tlib#Filter_glob#seq = '*'
|
||||
|
||||
|
||||
" A character that should be expanded to '\.\?'.
|
||||
TLet g:tlib#Filter_glob#char = '?'
|
||||
|
||||
|
||||
" The same as |tlib#Filter_cnf#New()| but a a customizable character
|
||||
" |see tlib#Filter_glob#seq| is expanded to '\.\{-}' and
|
||||
" |g:tlib#Filter_glob#char| is expanded to '\.'.
|
||||
" The pattern is a '/\V' very no-'/magic' regexp pattern.
|
||||
function! tlib#Filter_glob#New(...) "{{{3
|
||||
let object = s:prototype.New(a:0 >= 1 ? a:1 : {})
|
||||
return object
|
||||
endf
|
||||
|
||||
|
||||
let s:Help = s:prototype.Help
|
||||
|
||||
" :nodoc:
|
||||
function! s:prototype.Help(world) dict "{{{3
|
||||
call call(s:Help, [a:world], self)
|
||||
call a:world.PushHelp(g:tlib#Filter_glob#seq, 'Any characters')
|
||||
call a:world.PushHelp(g:tlib#Filter_glob#char, 'Single characters')
|
||||
endf
|
||||
|
||||
|
||||
" :nodoc:
|
||||
function! s:prototype.SetFrontFilter(world, pattern) dict "{{{3
|
||||
let pattern = substitute(a:pattern, tlib#rx#Escape(g:tlib#Filter_glob#seq, 'V'), '\\.\\{-}', 'g')
|
||||
let pattern = substitute(a:pattern, tlib#rx#Escape(g:tlib#Filter_glob#char, 'V'), '\\.', 'g')
|
||||
let a:world.filter[0] = reverse(split(pattern, '\s*|\s*')) + a:world.filter[0][1 : -1]
|
||||
endf
|
||||
|
||||
|
||||
" :nodoc:
|
||||
function! s:prototype.PushFrontFilter(world, char) dict "{{{3
|
||||
" TLogVAR a:char, nr2char(a:char)
|
||||
if a:char == char2nr(g:tlib#Filter_glob#seq)
|
||||
let char = '\.\{-}'
|
||||
elseif a:char == char2nr(g:tlib#Filter_glob#char)
|
||||
let char = '\.'
|
||||
else
|
||||
let char = nr2char(a:char)
|
||||
endif
|
||||
let a:world.filter[0][0] .= char
|
||||
endf
|
||||
|
||||
|
||||
" :nodoc:
|
||||
function! s:prototype.CleanFilter(filter) dict "{{{3
|
||||
let filter = substitute(a:filter, '\\\.\\{-}', g:tlib#Filter_glob#seq, 'g')
|
||||
let filter = substitute(filter, '\\\.', g:tlib#Filter_glob#char, 'g')
|
||||
return filter
|
||||
endf
|
||||
|
@ -1,154 +0,0 @@
|
||||
" @Author: Tom Link (micathom AT gmail com?subject=[vim])
|
||||
" @Website: http://www.vim.org/account/profile.php?user_id=4037
|
||||
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
|
||||
" @Revision: 127
|
||||
|
||||
" :filedoc:
|
||||
" Provides a prototype plus some OO-like methods.
|
||||
|
||||
let s:id_counter = 0
|
||||
let s:prototype = {'_class': ['object'], '_super': [], '_id': 0} "{{{2
|
||||
|
||||
" :def: function! tlib#Object#New(?fields={})
|
||||
" This function creates a prototype that provides some kind of
|
||||
" inheritance mechanism and a way to call parent/super methods.
|
||||
"
|
||||
" The usage demonstrated in the following example works best when every
|
||||
" class/prototype is defined in a file of its own.
|
||||
"
|
||||
" The reason for why there is a dedicated constructor function is that
|
||||
" this layout facilitates the use of templates and that methods are
|
||||
" hidden from the user. Other solutions are possible.
|
||||
"
|
||||
" EXAMPLES: >
|
||||
" let s:prototype = tlib#Object#New({
|
||||
" \ '_class': ['FooBar'],
|
||||
" \ 'foo': 1,
|
||||
" \ 'bar': 2,
|
||||
" \ })
|
||||
" " Constructor
|
||||
" function! FooBar(...)
|
||||
" let object = s:prototype.New(a:0 >= 1 ? a:1 : {})
|
||||
" return object
|
||||
" endf
|
||||
" function! s:prototype.babble() {
|
||||
" echo "I think, therefore I am ". (self.foo * self.bar) ." months old."
|
||||
" }
|
||||
"
|
||||
" < This could now be used like this: >
|
||||
" let myfoo = FooBar({'foo': 3})
|
||||
" call myfoo.babble()
|
||||
" => I think, therefore I am 6 months old.
|
||||
" echo myfoo.IsA('FooBar')
|
||||
" => 1
|
||||
" echo myfoo.IsA('object')
|
||||
" => 1
|
||||
" echo myfoo.IsA('Foo')
|
||||
" => 0
|
||||
" echo myfoo.RespondTo('babble')
|
||||
" => 1
|
||||
" echo myfoo.RespondTo('speak')
|
||||
" => 0
|
||||
function! tlib#Object#New(...) "{{{3
|
||||
return s:prototype.New(a:0 >= 1 ? a:1 : {})
|
||||
endf
|
||||
|
||||
|
||||
function! s:prototype.New(...) dict "{{{3
|
||||
let object = deepcopy(self)
|
||||
let s:id_counter += 1
|
||||
let object._id = s:id_counter
|
||||
if a:0 >= 1 && !empty(a:1)
|
||||
" call object.Extend(deepcopy(a:1))
|
||||
call object.Extend(a:1)
|
||||
endif
|
||||
return object
|
||||
endf
|
||||
|
||||
|
||||
function! s:prototype.Inherit(object) dict "{{{3
|
||||
let class = copy(self._class)
|
||||
" TLogVAR class
|
||||
let objid = self._id
|
||||
for c in get(a:object, '_class', [])
|
||||
" TLogVAR c
|
||||
if index(class, c) == -1
|
||||
call add(class, c)
|
||||
endif
|
||||
endfor
|
||||
call extend(self, a:object, 'keep')
|
||||
let self._class = class
|
||||
" TLogVAR self._class
|
||||
let self._id = objid
|
||||
" let self._super = [super] + self._super
|
||||
call insert(self._super, a:object)
|
||||
return self
|
||||
endf
|
||||
|
||||
|
||||
function! s:prototype.Extend(dictionary) dict "{{{3
|
||||
let super = copy(self)
|
||||
let class = copy(self._class)
|
||||
" TLogVAR class
|
||||
let objid = self._id
|
||||
let thisclass = get(a:dictionary, '_class', [])
|
||||
for c in type(thisclass) == 3 ? thisclass : [thisclass]
|
||||
" TLogVAR c
|
||||
if index(class, c) == -1
|
||||
call add(class, c)
|
||||
endif
|
||||
endfor
|
||||
call extend(self, a:dictionary)
|
||||
let self._class = class
|
||||
" TLogVAR self._class
|
||||
let self._id = objid
|
||||
" let self._super = [super] + self._super
|
||||
call insert(self._super, super)
|
||||
return self
|
||||
endf
|
||||
|
||||
|
||||
function! s:prototype.IsA(class) dict "{{{3
|
||||
return index(self._class, a:class) != -1
|
||||
endf
|
||||
|
||||
|
||||
function! s:prototype.IsRelated(object) dict "{{{3
|
||||
return len(filter(a:object._class, 'self.IsA(v:val)')) > 1
|
||||
endf
|
||||
|
||||
|
||||
function! s:prototype.RespondTo(name) dict "{{{3
|
||||
" return has_key(self, a:name) && type(self[a:name]) == 2
|
||||
return has_key(self, a:name)
|
||||
endf
|
||||
|
||||
|
||||
function! s:prototype.Super(method, arglist) dict "{{{3
|
||||
for o in self._super
|
||||
" TLogVAR o
|
||||
if o.RespondTo(a:method)
|
||||
" let self._tmp_method = o[a:method]
|
||||
" TLogVAR self._tmp_method
|
||||
" return call(self._tmp_method, a:arglist, self)
|
||||
return call(o[a:method], a:arglist, self)
|
||||
endif
|
||||
endfor
|
||||
echoerr 'tlib#Object: Does not respond to '. a:method .': '. string(self)
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#Object#Methods(object, ...) "{{{3
|
||||
TVarArg ['pattern', '\d\+']
|
||||
let o = items(a:object)
|
||||
call filter(o, 'type(v:val[1]) == 2 && string(v:val[1]) =~ "^function(''\\d\\+'')"')
|
||||
let acc = {}
|
||||
for e in o
|
||||
let id = matchstr(string(e[1]), pattern)
|
||||
if !empty(id)
|
||||
let acc[id] = e[0]
|
||||
endif
|
||||
endfor
|
||||
return acc
|
||||
endf
|
||||
|
@ -1,19 +0,0 @@
|
||||
" @Author: Tom Link (micathom AT gmail com?subject=[vim])
|
||||
" @Website: http://www.vim.org/account/profile.php?user_id=4037
|
||||
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
|
||||
" @Revision: 11
|
||||
|
||||
" :enddoc:
|
||||
|
||||
|
||||
let s:prototype = tlib#Object#New({'_class': ['Test']}) "{{{2
|
||||
function! tlib#Test#New(...) "{{{3
|
||||
let object = s:prototype.New(a:0 >= 1 ? a:1 : {})
|
||||
return object
|
||||
endf
|
||||
|
||||
|
||||
function! s:prototype.Dummy() dict "{{{3
|
||||
return 'Test.vim'
|
||||
endf
|
||||
|
@ -1,19 +0,0 @@
|
||||
" @Author: Tom Link (micathom AT gmail com?subject=[vim])
|
||||
" @Website: http://www.vim.org/account/profile.php?user_id=4037
|
||||
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
|
||||
" @Revision: 15
|
||||
|
||||
" :enddoc:
|
||||
|
||||
|
||||
let s:prototype = tlib#Test#New({'_class': ['TestChild']}) "{{{2
|
||||
function! tlib#TestChild#New(...) "{{{3
|
||||
let object = s:prototype.New(a:0 >= 1 ? a:1 : {})
|
||||
return object
|
||||
endf
|
||||
|
||||
|
||||
function! s:prototype.Dummy() dict "{{{3
|
||||
return 'TestChild.vim'
|
||||
endf
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,664 +0,0 @@
|
||||
" @Author: Tom Link (micathom AT gmail com?subject=[vim])
|
||||
" @Website: http://www.vim.org/account/profile.php?user_id=4037
|
||||
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
|
||||
" @Revision: 328
|
||||
|
||||
|
||||
" :filedoc:
|
||||
" Various agents for use as key handlers in tlib#input#List()
|
||||
|
||||
" Number of items to move when pressing <c-up/down> in the input list window.
|
||||
TLet g:tlib_scroll_lines = 10
|
||||
|
||||
|
||||
" General {{{1
|
||||
|
||||
function! tlib#agent#Exit(world, selected) "{{{3
|
||||
if a:world.key_mode == 'default'
|
||||
call a:world.CloseScratch()
|
||||
let a:world.state = 'exit empty escape'
|
||||
let a:world.list = []
|
||||
" let a:world.base = []
|
||||
call a:world.ResetSelected()
|
||||
else
|
||||
let a:world.key_mode = 'default'
|
||||
let a:world.state = 'redisplay'
|
||||
endif
|
||||
return a:world
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#agent#CopyItems(world, selected) "{{{3
|
||||
let @* = join(a:selected, "\n")
|
||||
let a:world.state = 'redisplay'
|
||||
return a:world
|
||||
endf
|
||||
|
||||
|
||||
|
||||
" InputList related {{{1
|
||||
|
||||
function! tlib#agent#PageUp(world, selected) "{{{3
|
||||
let a:world.offset -= (winheight(0) / 2)
|
||||
let a:world.state = 'scroll'
|
||||
return a:world
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#agent#PageDown(world, selected) "{{{3
|
||||
let a:world.offset += (winheight(0) / 2)
|
||||
let a:world.state = 'scroll'
|
||||
return a:world
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#agent#Home(world, selected) "{{{3
|
||||
let a:world.prefidx = 1
|
||||
let a:world.state = 'redisplay'
|
||||
return a:world
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#agent#End(world, selected) "{{{3
|
||||
let a:world.prefidx = len(a:world.list)
|
||||
let a:world.state = 'redisplay'
|
||||
return a:world
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#agent#Up(world, selected, ...) "{{{3
|
||||
TVarArg ['lines', 1]
|
||||
let a:world.idx = ''
|
||||
if a:world.prefidx > lines
|
||||
let a:world.prefidx -= lines
|
||||
else
|
||||
let a:world.prefidx = len(a:world.list)
|
||||
endif
|
||||
let a:world.state = 'redisplay'
|
||||
return a:world
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#agent#Down(world, selected, ...) "{{{3
|
||||
TVarArg ['lines', 1]
|
||||
let a:world.idx = ''
|
||||
if a:world.prefidx <= (len(a:world.list) - lines)
|
||||
let a:world.prefidx += lines
|
||||
else
|
||||
let a:world.prefidx = 1
|
||||
endif
|
||||
let a:world.state = 'redisplay'
|
||||
return a:world
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#agent#UpN(world, selected) "{{{3
|
||||
return tlib#agent#Up(a:world, a:selected, g:tlib_scroll_lines)
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#agent#DownN(world, selected) "{{{3
|
||||
return tlib#agent#Down(a:world, a:selected, g:tlib_scroll_lines)
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#agent#ShiftLeft(world, selected) "{{{3
|
||||
let a:world.offset_horizontal -= (winwidth(0) / 2)
|
||||
if a:world.offset_horizontal < 0
|
||||
let a:world.offset_horizontal = 0
|
||||
endif
|
||||
let a:world.state = 'display shift'
|
||||
return a:world
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#agent#ShiftRight(world, selected) "{{{3
|
||||
let a:world.offset_horizontal += (winwidth(0) / 2)
|
||||
let a:world.state = 'display shift'
|
||||
return a:world
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#agent#Reset(world, selected) "{{{3
|
||||
let a:world.state = 'reset'
|
||||
return a:world
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#agent#ToggleRestrictView(world, selected) "{{{3
|
||||
if empty(a:world.filtered_items)
|
||||
return tlib#agent#RestrictView(a:world, a:selected)
|
||||
else
|
||||
return tlib#agent#UnrestrictView(a:world, a:selected)
|
||||
endif
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#agent#RestrictView(world, selected) "{{{3
|
||||
" TLogVAR a:selected
|
||||
let filtered_items = map(copy(a:selected), 'index(a:world.base, v:val) + 1')
|
||||
" TLogVAR 1, filtered_items
|
||||
let filtered_items = filter(filtered_items, 'v:val > 0')
|
||||
" TLogVAR 2, filtered_items
|
||||
if !empty(filtered_items)
|
||||
let a:world.filtered_items = filtered_items
|
||||
endif
|
||||
let a:world.state = 'display'
|
||||
return a:world
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#agent#UnrestrictView(world, selected) "{{{3
|
||||
let a:world.filtered_items = []
|
||||
let a:world.state = 'display'
|
||||
return a:world
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#agent#Input(world, selected) "{{{3
|
||||
let flt0 = a:world.CleanFilter(a:world.filter[0][0])
|
||||
let flt1 = input('Filter: ', flt0)
|
||||
echo
|
||||
if flt1 != flt0
|
||||
if empty(flt1)
|
||||
call getchar(0)
|
||||
else
|
||||
call a:world.SetFrontFilter(flt1)
|
||||
endif
|
||||
endif
|
||||
let a:world.state = 'display'
|
||||
return a:world
|
||||
endf
|
||||
|
||||
|
||||
" Suspend (see |tlib#agent#Suspend|) the input loop and jump back to the
|
||||
" original position in the parent window.
|
||||
function! tlib#agent#SuspendToParentWindow(world, selected) "{{{3
|
||||
let world = a:world
|
||||
let winnr = world.win_wnr
|
||||
" TLogVAR winnr
|
||||
if winnr != -1
|
||||
let world = tlib#agent#Suspend(world, a:selected)
|
||||
if world.state =~ '\<suspend\>'
|
||||
call world.SwitchWindow('win')
|
||||
" let pos = world.cursor
|
||||
" " TLogVAR pos
|
||||
" if !empty(pos)
|
||||
" call setpos('.', pos)
|
||||
" endif
|
||||
return world
|
||||
endif
|
||||
endif
|
||||
let world.state = 'redisplay'
|
||||
return world
|
||||
endf
|
||||
|
||||
|
||||
" Suspend lets you temporarily leave the input loop of
|
||||
" |tlib#input#List|. You can resume editing the list by pressing <c-z>,
|
||||
" <m-z>. <space>, <c-LeftMouse> or <MiddleMouse> in the suspended window.
|
||||
" <cr> and <LeftMouse> will immediatly select the item under the cursor.
|
||||
" < will select the item but the window will remain opened.
|
||||
function! tlib#agent#Suspend(world, selected) "{{{3
|
||||
if a:world.allow_suspend
|
||||
" TAssert IsNotEmpty(a:world.scratch)
|
||||
" TLogDBG bufnr('%')
|
||||
let br = tlib#buffer#Set(a:world.scratch)
|
||||
" TLogVAR br, a:world.bufnr, a:world.scratch
|
||||
if bufnr('%') != a:world.scratch
|
||||
echohl WarningMsg
|
||||
echom "tlib#agent#Suspend: Internal error: Not a scratch buffer:" bufname('%')
|
||||
echohl NONE
|
||||
endif
|
||||
" TLogVAR bufnr('%'), bufname('%'), a:world.scratch
|
||||
call tlib#autocmdgroup#Init()
|
||||
exec 'autocmd TLib BufEnter <buffer='. a:world.scratch .'> call tlib#input#Resume("world", 0, '. a:world.scratch .')'
|
||||
let b:tlib_world = a:world
|
||||
exec br
|
||||
let a:world.state = 'exit suspend'
|
||||
else
|
||||
echom 'Suspend disabled'
|
||||
let a:world.state = 'redisplay'
|
||||
endif
|
||||
return a:world
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#agent#Help(world, selected) "{{{3
|
||||
let a:world.state = 'help'
|
||||
return a:world
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#agent#OR(world, selected) "{{{3
|
||||
if !empty(a:world.filter[0])
|
||||
call insert(a:world.filter[0], '')
|
||||
endif
|
||||
let a:world.state = 'display'
|
||||
return a:world
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#agent#AND(world, selected) "{{{3
|
||||
if !empty(a:world.filter[0])
|
||||
call insert(a:world.filter, [''])
|
||||
endif
|
||||
let a:world.state = 'display'
|
||||
return a:world
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#agent#ReduceFilter(world, selected) "{{{3
|
||||
call a:world.ReduceFilter()
|
||||
let a:world.offset = 1
|
||||
let a:world.state = 'display'
|
||||
return a:world
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#agent#PopFilter(world, selected) "{{{3
|
||||
call a:world.PopFilter()
|
||||
let a:world.offset = 1
|
||||
let a:world.state = 'display'
|
||||
return a:world
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#agent#Debug(world, selected) "{{{3
|
||||
" echo string(world.state)
|
||||
echo string(a:world.filter)
|
||||
echo string(a:world.idx)
|
||||
echo string(a:world.prefidx)
|
||||
echo string(a:world.sel_idx)
|
||||
call getchar()
|
||||
let a:world.state = 'display'
|
||||
return a:world
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#agent#Select(world, selected) "{{{3
|
||||
call a:world.SelectItem('toggle', a:world.prefidx)
|
||||
" let a:world.state = 'display keepcursor'
|
||||
let a:world.state = 'redisplay'
|
||||
return a:world
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#agent#SelectUp(world, selected) "{{{3
|
||||
call a:world.SelectItem('toggle', a:world.prefidx)
|
||||
if a:world.prefidx > 1
|
||||
let a:world.prefidx -= 1
|
||||
endif
|
||||
let a:world.state = 'redisplay'
|
||||
return a:world
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#agent#SelectDown(world, selected) "{{{3
|
||||
call a:world.SelectItem('toggle', a:world.prefidx)
|
||||
if a:world.prefidx < len(a:world.list)
|
||||
let a:world.prefidx += 1
|
||||
endif
|
||||
let a:world.state = 'redisplay'
|
||||
return a:world
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#agent#SelectAll(world, selected) "{{{3
|
||||
let listrange = range(1, len(a:world.list))
|
||||
let mode = empty(filter(copy(listrange), 'index(a:world.sel_idx, a:world.GetBaseIdx(v:val)) == -1'))
|
||||
\ ? 'toggle' : 'set'
|
||||
for i in listrange
|
||||
call a:world.SelectItem(mode, i)
|
||||
endfor
|
||||
let a:world.state = 'display keepcursor'
|
||||
return a:world
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#agent#ToggleStickyList(world, selected) "{{{3
|
||||
let a:world.sticky = !a:world.sticky
|
||||
let a:world.state = 'display keepcursor'
|
||||
return a:world
|
||||
endf
|
||||
|
||||
|
||||
|
||||
" EditList related {{{1
|
||||
|
||||
function! tlib#agent#EditItem(world, selected) "{{{3
|
||||
let lidx = a:world.prefidx
|
||||
" TLogVAR lidx
|
||||
" TLogVAR a:world.table
|
||||
let bidx = a:world.GetBaseIdx(lidx)
|
||||
" TLogVAR bidx
|
||||
let item = a:world.GetBaseItem(bidx)
|
||||
let item = input(lidx .'@'. bidx .': ', item)
|
||||
if item != ''
|
||||
call a:world.SetBaseItem(bidx, item)
|
||||
endif
|
||||
let a:world.state = 'display'
|
||||
return a:world
|
||||
endf
|
||||
|
||||
|
||||
" Insert a new item below the current one.
|
||||
function! tlib#agent#NewItem(world, selected) "{{{3
|
||||
let basepi = a:world.GetBaseIdx(a:world.prefidx)
|
||||
let item = input('New item: ')
|
||||
call insert(a:world.base, item, basepi)
|
||||
let a:world.state = 'reset'
|
||||
return a:world
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#agent#DeleteItems(world, selected) "{{{3
|
||||
let remove = copy(a:world.sel_idx)
|
||||
let basepi = a:world.GetBaseIdx(a:world.prefidx)
|
||||
if index(remove, basepi) == -1
|
||||
call add(remove, basepi)
|
||||
endif
|
||||
" call map(remove, 'a:world.GetBaseIdx(v:val)')
|
||||
for idx in reverse(sort(remove))
|
||||
call remove(a:world.base, idx - 1)
|
||||
endfor
|
||||
let a:world.state = 'display'
|
||||
call a:world.ResetSelected()
|
||||
" let a:world.state = 'reset'
|
||||
return a:world
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#agent#Cut(world, selected) "{{{3
|
||||
let world = tlib#agent#Copy(a:world, a:selected)
|
||||
return tlib#agent#DeleteItems(world, a:selected)
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#agent#Copy(world, selected) "{{{3
|
||||
let a:world.clipboard = []
|
||||
let bidxs = copy(a:world.sel_idx)
|
||||
call add(bidxs, a:world.GetBaseIdx(a:world.prefidx))
|
||||
for bidx in sort(bidxs)
|
||||
call add(a:world.clipboard, a:world.GetBaseItem(bidx))
|
||||
endfor
|
||||
let a:world.state = 'redisplay'
|
||||
return a:world
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#agent#Paste(world, selected) "{{{3
|
||||
if has_key(a:world, 'clipboard')
|
||||
for e in reverse(copy(a:world.clipboard))
|
||||
call insert(a:world.base, e, a:world.prefidx)
|
||||
endfor
|
||||
endif
|
||||
let a:world.state = 'display'
|
||||
call a:world.ResetSelected()
|
||||
return a:world
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#agent#EditReturnValue(world, rv) "{{{3
|
||||
return [a:world.state !~ '\<exit\>', a:world.base]
|
||||
endf
|
||||
|
||||
|
||||
|
||||
" Files related {{{1
|
||||
|
||||
function! tlib#agent#ViewFile(world, selected) "{{{3
|
||||
if !empty(a:selected)
|
||||
let back = a:world.SwitchWindow('win')
|
||||
" TLogVAR back
|
||||
for filename in a:selected
|
||||
call tlib#file#Edit(filename)
|
||||
endfor
|
||||
" if !&hidden && &l:modified
|
||||
" let cmd0 = 'split'
|
||||
" let cmd1 = 'sbuffer'
|
||||
" else
|
||||
" let cmd0 = 'edit'
|
||||
" let cmd1 = 'buffer'
|
||||
" endif
|
||||
" call tlib#file#With(cmd0, cmd1, a:selected, a:world)
|
||||
" TLogVAR &filetype
|
||||
exec back
|
||||
let a:world.state = 'display'
|
||||
endif
|
||||
return a:world
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#agent#EditFile(world, selected) "{{{3
|
||||
return tlib#agent#Exit(tlib#agent#ViewFile(a:world, a:selected), a:selected)
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#agent#EditFileInSplit(world, selected) "{{{3
|
||||
call a:world.CloseScratch()
|
||||
" call tlib#file#With('edit', 'buffer', a:selected[0:0], a:world)
|
||||
" call tlib#file#With('split', 'sbuffer', a:selected[1:-1], a:world)
|
||||
call tlib#file#With('split', 'sbuffer', a:selected, a:world)
|
||||
return tlib#agent#Exit(a:world, a:selected)
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#agent#EditFileInVSplit(world, selected) "{{{3
|
||||
call a:world.CloseScratch()
|
||||
" call tlib#file#With('edit', 'buffer', a:selected[0:0], a:world)
|
||||
" call tlib#file#With('vertical split', 'vertical sbuffer', a:selected[1:-1], a:world)
|
||||
let winpos = tlib#fixes#Winpos()
|
||||
call tlib#file#With('vertical split', 'vertical sbuffer', a:selected, a:world)
|
||||
if !empty(winpos)
|
||||
exec winpos
|
||||
endif
|
||||
return tlib#agent#Exit(a:world, a:selected)
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#agent#EditFileInTab(world, selected) "{{{3
|
||||
" TLogVAR a:selected
|
||||
call a:world.CloseScratch()
|
||||
call tlib#file#With('tabedit', 'tab sbuffer', a:selected, a:world)
|
||||
return tlib#agent#Exit(a:world, a:selected)
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#agent#ToggleScrollbind(world, selected) "{{{3
|
||||
let a:world.scrollbind = get(a:world, 'scrollbind') ? 0 : 1
|
||||
let a:world.state = 'redisplay'
|
||||
return a:world
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#agent#ShowInfo(world, selected)
|
||||
let lines = []
|
||||
for f in a:selected
|
||||
if filereadable(f)
|
||||
let desc = [getfperm(f), strftime('%c', getftime(f)), getfsize(f) .' bytes', getftype(f)]
|
||||
call add(lines, fnamemodify(f, ':p'))
|
||||
call add(lines, ' '. join(desc, '; '))
|
||||
endif
|
||||
endfor
|
||||
let a:world.temp_lines = lines
|
||||
let a:world.state = 'printlines'
|
||||
return a:world
|
||||
endf
|
||||
|
||||
|
||||
|
||||
" Buffer related {{{1
|
||||
|
||||
function! tlib#agent#PreviewLine(world, selected) "{{{3
|
||||
let l = a:selected[0]
|
||||
let ww = winnr()
|
||||
exec a:world.win_wnr .'wincmd w'
|
||||
call tlib#buffer#ViewLine(l, 1)
|
||||
exec ww .'wincmd w'
|
||||
let a:world.state = 'redisplay'
|
||||
return a:world
|
||||
endf
|
||||
|
||||
|
||||
" If not called from the scratch, we assume/guess that we don't have to
|
||||
" suspend the input-evaluation loop.
|
||||
function! tlib#agent#GotoLine(world, selected) "{{{3
|
||||
if !empty(a:selected)
|
||||
|
||||
" let l = a:selected[0]
|
||||
" " TLogVAR l
|
||||
" let back = a:world.SwitchWindow('win')
|
||||
" " TLogVAR back
|
||||
" " if a:world.win_wnr != winnr()
|
||||
" " let world = tlib#agent#Suspend(a:world, a:selected)
|
||||
" " exec a:world.win_wnr .'wincmd w'
|
||||
" " endif
|
||||
" call tlib#buffer#ViewLine(l)
|
||||
" exec back
|
||||
" let a:world.state = 'display'
|
||||
|
||||
let l = a:selected[0]
|
||||
if a:world.win_wnr != winnr()
|
||||
let world = tlib#agent#Suspend(a:world, a:selected)
|
||||
exec a:world.win_wnr .'wincmd w'
|
||||
endif
|
||||
call tlib#buffer#ViewLine(l, 1)
|
||||
|
||||
endif
|
||||
return a:world
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#agent#DoAtLine(world, selected) "{{{3
|
||||
if !empty(a:selected)
|
||||
let cmd = input('Command: ', '', 'command')
|
||||
if !empty(cmd)
|
||||
call a:world.SwitchWindow('win')
|
||||
" let pos = getpos('.')
|
||||
let view = winsaveview()
|
||||
for l in a:selected
|
||||
call tlib#buffer#ViewLine(l, '')
|
||||
exec cmd
|
||||
endfor
|
||||
" call setpos('.', pos)
|
||||
call winrestview(view)
|
||||
endif
|
||||
endif
|
||||
call a:world.ResetSelected()
|
||||
let a:world.state = 'exit'
|
||||
return a:world
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#agent#Wildcard(world, selected) "{{{3
|
||||
if !empty(a:world.filter[0])
|
||||
let rx_type = a:world.matcher.FilterRxPrefix()
|
||||
let flt0 = a:world.CleanFilter(a:world.filter[0][0])
|
||||
if rx_type == '\V'
|
||||
let flt0 .= '\.\{-}'
|
||||
else
|
||||
let flt0 .= '.\{-}'
|
||||
endif
|
||||
call a:world.SetFrontFilter(flt0)
|
||||
endif
|
||||
let a:world.state = 'redisplay'
|
||||
return a:world
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#agent#Null(world, selected) "{{{3
|
||||
let a:world.state = 'redisplay'
|
||||
return a:world
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#agent#ExecAgentByName(world, selected) "{{{3
|
||||
let s:agent_names_world = a:world
|
||||
let agent_names = {'Help': 'tlib#agent#Help'}
|
||||
for def in values(a:world.key_map[a:world.key_mode])
|
||||
if has_key(def, 'help') && !empty(def.help) && has_key(def, 'agent') && !empty(def.agent)
|
||||
let agent_names[def.help] = def.agent
|
||||
endif
|
||||
endfor
|
||||
let s:agent_names = sort(keys(agent_names))
|
||||
let command = input('Command: ', '', 'customlist,tlib#agent#CompleteAgentNames')
|
||||
" TLogVAR command
|
||||
if !has_key(agent_names, command)
|
||||
" TLogVAR command
|
||||
silent! let matches = filter(keys(agent_names), 'v:val =~ command')
|
||||
" TLogVAR matches
|
||||
if len(matches) == 1
|
||||
let command = matches[0]
|
||||
endif
|
||||
endif
|
||||
if has_key(agent_names, command)
|
||||
let agent = agent_names[command]
|
||||
return call(agent, [a:world, a:selected])
|
||||
else
|
||||
if !empty(command)
|
||||
echohl WarningMsg
|
||||
echom "Unknown command:" command
|
||||
echohl NONE
|
||||
sleep 1
|
||||
endif
|
||||
let a:world.state = 'display'
|
||||
return a:world
|
||||
endif
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#agent#CompleteAgentNames(ArgLead, CmdLine, CursorPos)
|
||||
return filter(copy(s:agent_names), 'stridx(v:val, a:ArgLead) != -1')
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#agent#Complete(world, selected) abort "{{{3
|
||||
let rxprefix = a:world.matcher.FilterRxPrefix()
|
||||
let flt = a:world.filter[0][0]
|
||||
" TLogVAR flt
|
||||
let fltrx = rxprefix . flt . '\m[^[:space:][:cntrl:][:punct:]<>*+?&~{}()\[\]\\/]\+'
|
||||
let fltrx0 = '\m^' . fltrx
|
||||
" TLogVAR fltrx, fltrx0
|
||||
let words = {}
|
||||
for item in a:world.list
|
||||
let parts = split(item, '\ze'. fltrx)
|
||||
" TLogVAR item, parts
|
||||
for part in parts
|
||||
let word = matchstr(part, fltrx0)
|
||||
" TLogVAR part, word
|
||||
if !empty(word)
|
||||
let words[word] = 1
|
||||
endif
|
||||
endfor
|
||||
endfor
|
||||
" TLogVAR keys(words)
|
||||
let completions = keys(words)
|
||||
" let completions = filter(keys(words), 'matchstr(v:val, fltrx0)')
|
||||
let completions = sort(completions, 's:SortCompletions')
|
||||
let completions = tlib#list#Uniq(completions)
|
||||
" TLogVAR 0, completions
|
||||
while len(completions) > 1
|
||||
let nchar = strwidth(completions[0]) - 1
|
||||
let completions = map(completions, 'strpart(v:val, 0, nchar)')
|
||||
" TLogVAR 'reduce', completions
|
||||
let completions = tlib#list#Uniq(completions)
|
||||
" TLogVAR 'unique', len(completions), completions
|
||||
endwh
|
||||
" TLogVAR 9, completions
|
||||
if empty(completions)
|
||||
let a:world.state = 'redisplay update'
|
||||
else
|
||||
let a:world.filter[0][0] = completions[0]
|
||||
let a:world.state = 'display update'
|
||||
endif
|
||||
return a:world
|
||||
endf
|
||||
|
||||
|
||||
function! s:SortCompletions(a, b) abort "{{{3
|
||||
let i1 = strwidth(a:a)
|
||||
let i2 = strwidth(a:b)
|
||||
return i2 - i1
|
||||
endf
|
||||
|
@ -1,328 +0,0 @@
|
||||
" @Author: Tom Link (micathom AT gmail com?subject=[vim])
|
||||
" @Website: http://www.vim.org/account/profile.php?user_id=4037
|
||||
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
|
||||
" @Last Change: 2015-11-19.
|
||||
" @Revision: 251
|
||||
|
||||
|
||||
" :def: function! tlib#arg#Get(n, var, ?default="", ?test='')
|
||||
" Set a positional argument from a variable argument list.
|
||||
" See tlib#string#RemoveBackslashes() for an example.
|
||||
function! tlib#arg#Get(n, var, ...) "{{{3
|
||||
let default = a:0 >= 1 ? a:1 : ''
|
||||
let atest = a:0 >= 2 ? a:2 : ''
|
||||
" TLogVAR default, atest
|
||||
if !empty(atest)
|
||||
let atest = ' && (a:'. a:n .' '. atest .')'
|
||||
endif
|
||||
let test = printf('a:0 >= %d', a:n) . atest
|
||||
return printf('let %s = %s ? a:%d : %s', a:var, test, a:n, string(default))
|
||||
endf
|
||||
|
||||
|
||||
" :def: function! tlib#arg#Let(list, ?default='')
|
||||
" Set a positional arguments from a variable argument list.
|
||||
" See tlib#input#List() for an example.
|
||||
function! tlib#arg#Let(list, ...) "{{{3
|
||||
let default = a:0 >= 1 ? a:1 : ''
|
||||
let list = map(copy(a:list), 'type(v:val) == 3 ? v:val : [v:val, default]')
|
||||
let args = map(range(1, len(list)), 'call("tlib#arg#Get", [v:val] + list[v:val - 1])')
|
||||
return join(args, ' | ')
|
||||
endf
|
||||
|
||||
|
||||
" :def: function! tlib#arg#StringAsKeyArgs(string, ?keys=[], ?evaluate=0, ?sep=':', ?booleans=0)
|
||||
function! tlib#arg#StringAsKeyArgs(string, ...) "{{{1
|
||||
TVarArg ['keys', {}], ['evaluate', 0], ['sep', ':'], ['booleans', 0]
|
||||
let keyargs = {}
|
||||
let args = split(a:string, '\\\@<! ')
|
||||
let key_rx = booleans ? '\([-+]\?\w\+\)' : '\(\w\+\)'
|
||||
let arglist = map(args, 'matchlist(v:val, ''^\%('. key_rx . sep .'\(.*\)\|\(.*\)\)$'')')
|
||||
" TLogVAR a:string, args, arglist
|
||||
let pos = -1
|
||||
for matchlist in arglist
|
||||
if !empty(matchlist[3])
|
||||
if booleans && matchlist[3] =~ '^[-+]'
|
||||
let key = substitute(matchlist[3], '^[-+]', '', '')
|
||||
let val = matchstr(matchlist[3], '^[-+]')
|
||||
let keyargs[key] = val ==# '+'
|
||||
else
|
||||
let pos += 1
|
||||
let keyargs[pos] = matchlist[3]
|
||||
endif
|
||||
else
|
||||
let [match, key, val; rest] = matchlist
|
||||
if empty(keys) || has_key(keys, key)
|
||||
let val = substitute(val, '\\\\', '\\', 'g')
|
||||
if evaluate
|
||||
let val = eval(val)
|
||||
endif
|
||||
let keyargs[key] = val
|
||||
else
|
||||
echom 'Unknown key: '. key .'='. val
|
||||
endif
|
||||
endif
|
||||
endfor
|
||||
if pos >= 0
|
||||
let keyargs['__posargs__'] = range(0, pos)
|
||||
endif
|
||||
return keyargs
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#arg#StringAsKeyArgsEqual(string) "{{{1
|
||||
return tlib#arg#StringAsKeyArgs(a:string, [], 0, '=', 1)
|
||||
endf
|
||||
|
||||
|
||||
" :display: tlib#arg#GetOpts(args, ?def={})
|
||||
" Convert a list of strings of command-line arguments into a dictonary.
|
||||
"
|
||||
" The main use case is to pass [<f-args>], i.e. the command-line
|
||||
" arguments of a command as list, from a command definition to this
|
||||
" function.
|
||||
"
|
||||
" Example:
|
||||
" ['-h']
|
||||
" => If def contains a 'help' key, invoke |:help| on its value.
|
||||
"
|
||||
" ['-ab', '--foo', '--bar=BAR', 'bla', bla']
|
||||
" => {'a': 1, 'b': 1, 'foo': 1, 'bar': 'BAR', '__rest__': ['bla', 'bla']}
|
||||
"
|
||||
" ['-ab', '--', '--foo', '--bar=BAR']
|
||||
" => {'a': 1, 'b': 1, '__rest__': ['--foo', '--bar=BAR']}
|
||||
function! tlib#arg#GetOpts(args, ...) abort "{{{3
|
||||
let throw = a:0 == 0
|
||||
TVarArg ['def', {}]
|
||||
" TLogVAR def
|
||||
let opts = {'__exit__': 0}
|
||||
for [key, vdef] in items(get(def, 'values', {}))
|
||||
if has_key(vdef, 'default')
|
||||
let opts[key] = vdef.default
|
||||
endif
|
||||
endfor
|
||||
let idx = 0
|
||||
for o in a:args
|
||||
let [break, idx] = s:SetOpt(def, opts, idx, o)
|
||||
if break == 1
|
||||
break
|
||||
elseif break == 2
|
||||
if throw
|
||||
throw 'tlib#arg#GetOpts: Show help'
|
||||
else
|
||||
let opts.__exit__ = 5
|
||||
endif
|
||||
endif
|
||||
endfor
|
||||
let opts.__rest__ = a:args[idx : -1]
|
||||
return opts
|
||||
endf
|
||||
|
||||
|
||||
function! s:GetValueType(def) abort "{{{3
|
||||
return get(a:def, 'type', type(get(a:def, 'default', '')))
|
||||
endf
|
||||
|
||||
|
||||
function! s:SetOpt(def, opts, idx, opt) abort "{{{3
|
||||
" TLogVAR a:def
|
||||
let idx = a:idx + 1
|
||||
let break = 0
|
||||
let long = get(a:def, 'long', 1)
|
||||
let short = get(a:def, 'short', 1)
|
||||
if (short && a:opt =~# '^-[?h]$') || (long && a:opt ==# '--help')
|
||||
if has_key(a:def, 'help')
|
||||
exec 'help' a:def.help
|
||||
else
|
||||
" TLogVAR a:def
|
||||
let values = get(a:def, 'values', {})
|
||||
let flags = get(a:def, 'flags', {})
|
||||
if empty(values) && empty(flags)
|
||||
echom 'No help'
|
||||
else
|
||||
if !empty(values)
|
||||
echom 'Options:'
|
||||
for [key, vdef] in sort(items(values))
|
||||
let opt = key
|
||||
let default = get(vdef, 'default', '')
|
||||
let type = s:GetValueType(vdef)
|
||||
if default =~ '^-\?\d\+\%(\.\d\+\)$'
|
||||
if type == -1
|
||||
let opt .= ' (flag)'
|
||||
elseif type == 1
|
||||
let opt .= '=INT'
|
||||
else
|
||||
let opt .= '=INT or maybe BOOL'
|
||||
endif
|
||||
elseif type(default) == 1
|
||||
let opt .= '=STRING'
|
||||
elseif type(default) == 3
|
||||
let opt .= '=COMMA-LIST'
|
||||
endif
|
||||
echom printf(' --%20s (default: %s)', opt, string(default))
|
||||
endfor
|
||||
endif
|
||||
if !empty(flags)
|
||||
echom 'Short flags:'
|
||||
for [sflag, lflag] in sort(items(flags))
|
||||
echom printf(' -%s -> %s', sflag, lflag)
|
||||
endfor
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
let break = 2
|
||||
elseif long && a:opt =~# '^--no-.\+'
|
||||
let key = matchstr(a:opt, '^--no-\zs.\+$')
|
||||
let a:opts[key] = s:Validate(a:def, key, 0)
|
||||
elseif long && a:opt =~# '^--\w\+$'
|
||||
let key = matchstr(a:opt, '^--\zs.\+$')
|
||||
let a:opts[key] = s:Validate(a:def, key, 1)
|
||||
elseif long && a:opt =~# '^--\w\+='
|
||||
let ml = matchlist(a:opt, '^--\(\w\+\)=\(.*\)$')
|
||||
if empty(ml)
|
||||
throw 'tlib#arg#GetOpts: Cannot parse: '. a:opt
|
||||
else
|
||||
let values = get(a:def, 'values', {})
|
||||
if has_key(values, ml[1])
|
||||
let vdef = values[ml[1]]
|
||||
let type = s:GetValueType(vdef)
|
||||
if type == -1
|
||||
let opt_value = !!str2nr(ml[2])
|
||||
elseif type == 0
|
||||
let opt_value = str2nr(ml[2])
|
||||
elseif type == 1
|
||||
let opt_value = ml[2]
|
||||
elseif type == 2
|
||||
let opt_value = function(ml[2])
|
||||
elseif type == 3
|
||||
let opt_value = tlib#string#SplitCommaList(ml[2])
|
||||
elseif type == 4
|
||||
throw 'tlib#arg#GetOpts: Unsupported type conversion for '. ml[1]
|
||||
elseif type == 5
|
||||
let opt_value = str2float(ml[2])
|
||||
endif
|
||||
else
|
||||
let opt_value = ml[2]
|
||||
endif
|
||||
let a:opts[ml[1]] = s:Validate(a:def, ml[1], opt_value)
|
||||
unlet opt_value
|
||||
endif
|
||||
elseif short && a:opt =~# '^-\w='
|
||||
let flagdefs = get(a:def, 'flags', {})
|
||||
let flag = matchstr(a:opt, '^-\zs\w')
|
||||
let rest = matchstr(a:opt, '^-\w\zs.*$')
|
||||
call s:SetFlag(a:def, a:opts, idx, flag, rest, flagdefs)
|
||||
elseif short && a:opt =~# '^-\w\+$'
|
||||
let flagdefs = get(a:def, 'flags', {})
|
||||
for flag in split(substitute(a:opt, '^-', '', ''), '\zs')
|
||||
call s:SetFlag(a:def, a:opts, idx, flag, '', flagdefs)
|
||||
endfor
|
||||
else
|
||||
let break = 1
|
||||
if a:opt !=# '--'
|
||||
let idx -= 1
|
||||
endif
|
||||
endif
|
||||
return [break, idx]
|
||||
endf
|
||||
|
||||
|
||||
function! s:SetFlag(def, opts, idx, flag, rest, flagdefs) abort "{{{3
|
||||
" TLogVAR a:def
|
||||
if has_key(a:flagdefs, a:flag)
|
||||
call s:SetOpt(a:def, a:opts, a:idx, a:flagdefs[a:flag] . a:rest)
|
||||
else
|
||||
let a:opts[a:flag] = s:Validate(a:def, a:flag, 1)
|
||||
endif
|
||||
endf
|
||||
|
||||
|
||||
function! s:Validate(def, name, value) abort "{{{3
|
||||
let values = get(a:def, 'values', {})
|
||||
if has_key(values, a:name)
|
||||
let vdef = values[a:name]
|
||||
if has_key(vdef, 'validate')
|
||||
if !call(vdef.validate, [a:value])
|
||||
throw printf('tlib#arg: %s has invalid value: %s', string(a:name), string(a:value))
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
return a:value
|
||||
endf
|
||||
|
||||
|
||||
":nodoc:
|
||||
function! tlib#arg#CComplete(def, ArgLead) abort "{{{3
|
||||
let values = get(a:def, 'values', {})
|
||||
let opt = matchstr(a:ArgLead, '^--\zs\w\+\ze=')
|
||||
if has_key(values, opt)
|
||||
let words = []
|
||||
let vals = values[opt]
|
||||
let complete_customlist = get(vals, 'complete_customlist', '')
|
||||
if !empty(complete_customlist)
|
||||
let words = eval(complete_customlist)
|
||||
" else
|
||||
" let complete = get(vals, 'complete', '')
|
||||
" if !empty(complete)
|
||||
" endif
|
||||
endif
|
||||
if !empty(words)
|
||||
let lead = substitute(a:ArgLead, '^--\w\+=', '', '')
|
||||
if !empty(lead)
|
||||
let nchar = len(lead)
|
||||
call filter(words, 'strpart(v:val, 0, nchar) ==# lead')
|
||||
endif
|
||||
let words = map(words, '"--". opt ."=". v:val')
|
||||
return sort(words)
|
||||
endif
|
||||
endif
|
||||
let cs = {'-h': 1, '--help': 1}
|
||||
for [name, vdef] in items(values)
|
||||
let type = s:GetValueType(vdef)
|
||||
if type >= 0
|
||||
let name .= '='
|
||||
else
|
||||
let cs['--no-'. name] = 1
|
||||
endif
|
||||
let cs['--'. name] = 1
|
||||
endfor
|
||||
for [name, subst] in items(get(a:def, 'flags', {}))
|
||||
let ldef = get(values, substitute(subst, '^--', '', ''), {})
|
||||
let type = s:GetValueType(ldef)
|
||||
if type >= 0
|
||||
let name .= '='
|
||||
endif
|
||||
let cs['-'. name] = 1
|
||||
endfor
|
||||
let nchar = len(a:ArgLead)
|
||||
if nchar > 0
|
||||
call filter(cs, 'strpart(v:key, 0, nchar) ==# a:ArgLead')
|
||||
endif
|
||||
return sort(keys(cs))
|
||||
endf
|
||||
|
||||
|
||||
|
||||
""" Command line {{{1
|
||||
|
||||
" :def: function! tlib#arg#Ex(arg, ?chars='%#! ')
|
||||
" Escape some characters in a string.
|
||||
"
|
||||
" Use |fnamescape()| if available.
|
||||
"
|
||||
" EXAMPLES: >
|
||||
" exec 'edit '. tlib#arg#Ex('foo%#bar.txt')
|
||||
function! tlib#arg#Ex(arg, ...) "{{{3
|
||||
if exists('*fnameescape') && a:0 == 0
|
||||
return fnameescape(a:arg)
|
||||
else
|
||||
" let chars = '%# \'
|
||||
let chars = '%#! '
|
||||
if a:0 >= 1
|
||||
let chars .= a:1
|
||||
endif
|
||||
return escape(a:arg, chars)
|
||||
endif
|
||||
endf
|
||||
|
||||
|
@ -1,44 +0,0 @@
|
||||
" @Author: Tom Link (mailto:micathom AT gmail com?subject=[vim])
|
||||
" @Website: https://github.com/tomtom
|
||||
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
|
||||
" @Last Change: 2015-11-23
|
||||
" @Revision: 38
|
||||
|
||||
|
||||
" Enable tracing via |:Tlibassert|.
|
||||
function! tlib#assert#Enable() abort "{{{3
|
||||
" :nodoc:
|
||||
command! -nargs=+ -bar Tlibassert call tlib#assert#Assert(expand('<sfile>'), <q-args>, [<args>])
|
||||
endf
|
||||
|
||||
|
||||
" Disable tracing via |:Tlibassert|.
|
||||
function! tlib#assert#Disable() abort "{{{3
|
||||
" :nodoc:
|
||||
command! -nargs=+ -bang -bar Tlibassert :
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#assert#Assert(caller, check, vals) abort "{{{3
|
||||
for val in a:vals
|
||||
" TLogVAR val
|
||||
if type(val) == 3
|
||||
call tlib#assert#Assert(a:caller, a:check, val)
|
||||
elseif !val
|
||||
throw 'Tlibassert: '. tlib#trace#Backtrace(a:caller) .': '. a:check
|
||||
endif
|
||||
endfor
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#assert#Map(vals, expr) abort "{{{3
|
||||
return tlib#assert#All(map(a:vals, a:expr))
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#assert#All(vals) abort "{{{3
|
||||
" TLogVAR a:vals, empty(filter(a:vals, '!v:val'))
|
||||
return empty(filter(a:vals, '!v:val'))
|
||||
endf
|
||||
|
||||
|
@ -1,14 +0,0 @@
|
||||
" autocmdgroup.vim
|
||||
" @Author: Tom Link (mailto:micathom AT gmail com?subject=[vim])
|
||||
" @Website: http://www.vim.org/account/profile.php?user_id=4037
|
||||
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
|
||||
" @Revision: 7
|
||||
|
||||
augroup TLib
|
||||
autocmd!
|
||||
augroup END
|
||||
|
||||
|
||||
function! tlib#autocmdgroup#Init() "{{{3
|
||||
endf
|
||||
|
@ -1,73 +0,0 @@
|
||||
" @Author: Tom Link (micathom AT gmail com?subject=[vim])
|
||||
" @Website: http://www.vim.org/account/profile.php?user_id=4037
|
||||
" @GIT: http://github.com/tomtom/tlib_vim/
|
||||
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
|
||||
" @Created: 2010-08-30.
|
||||
" @Last Change: 2015-11-23.
|
||||
" @Revision: 48
|
||||
|
||||
|
||||
function! tlib#balloon#Register(expr) "{{{3
|
||||
if !has('balloon_eval')
|
||||
return
|
||||
endif
|
||||
if !exists('b:tlib_balloons')
|
||||
let b:tlib_balloons = []
|
||||
endif
|
||||
if !&ballooneval
|
||||
setlocal ballooneval
|
||||
endif
|
||||
if &balloonexpr != 'tlib#balloon#Expr()'
|
||||
if !empty(&balloonexpr)
|
||||
call add(b:tlib_balloons, &balloonexpr)
|
||||
endif
|
||||
setlocal ballooneval balloonexpr=tlib#balloon#Expr()
|
||||
endif
|
||||
if index(b:tlib_balloons, a:expr) == -1
|
||||
call add(b:tlib_balloons, a:expr)
|
||||
endif
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#balloon#Remove(expr) "{{{3
|
||||
if exists('b:tlib_balloons')
|
||||
call filter(b:tlib_balloons, 'v:val != a:expr')
|
||||
if empty(b:tlib_balloons)
|
||||
setlocal ballooneval&
|
||||
setlocal balloonexpr&
|
||||
unlet b:tlib_balloons
|
||||
endif
|
||||
endif
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#balloon#Expr() "{{{3
|
||||
" TLogVAR exists('b:tlib_balloons')
|
||||
if !exists('b:tlib_balloons')
|
||||
return ''
|
||||
endif
|
||||
let text = map(copy(b:tlib_balloons), 'eval(v:val)')
|
||||
" TLogVAR b:tlib_balloons, text
|
||||
call filter(text, '!empty(v:val)')
|
||||
if has('balloon_multiline')
|
||||
return join(text, "\n----------------------------------\n")
|
||||
else
|
||||
return get(text, 0, '')
|
||||
endif
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#balloon#Expand(expr) abort "{{{3
|
||||
if v:beval_bufnr != bufnr('%')
|
||||
" TLogVAR v:beval_bufnr, bufnr('%')
|
||||
return ''
|
||||
endif
|
||||
let win = winsaveview()
|
||||
try
|
||||
call setpos('.', [v:beval_bufnr, v:beval_lnum, v:beval_col, 0])
|
||||
return expand(a:expr)
|
||||
finally
|
||||
call winrestview(win)
|
||||
endtry
|
||||
endf
|
||||
|
@ -1,141 +0,0 @@
|
||||
" @Author: Tom Link (mailto:micathom AT gmail com?subject=[vim])
|
||||
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
|
||||
" @Revision: 124
|
||||
|
||||
|
||||
function! tlib#bitwise#Num2Bits(num) "{{{3
|
||||
if type(a:num) <= 1 || type(a:num) == 5
|
||||
let bits = reverse(tlib#number#ConvertBase(a:num, 2, 'list'))
|
||||
elseif type(a:num) == 3
|
||||
let bits = copy(a:num)
|
||||
else
|
||||
throw "tlib#bitwise#Num2Bits: Must be number of list: ". string(a:num)
|
||||
endif
|
||||
return bits
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#bitwise#Bits2Num(bits, ...) "{{{3
|
||||
let base = a:0 >= 1 ? a:1 : 10
|
||||
" TLogVAR a:bits
|
||||
let num = 0.0
|
||||
for i in range(len(a:bits))
|
||||
if get(a:bits, i, 0)
|
||||
let num += pow(2, i)
|
||||
endif
|
||||
endfor
|
||||
" TLogVAR num
|
||||
if base == 10
|
||||
if type(base) == 5
|
||||
return num
|
||||
else
|
||||
return float2nr(num)
|
||||
endif
|
||||
else
|
||||
return tlib#number#ConvertBase(num, base)
|
||||
endif
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#bitwise#AND(num1, num2, ...) "{{{3
|
||||
let rtype = a:0 >= 1 ? a:1 : 'num'
|
||||
return s:BitwiseComparison(a:num1, a:num2, rtype,
|
||||
\ 'get(bits1, v:val) && get(bits2, v:val)')
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#bitwise#OR(num1, num2, ...) "{{{3
|
||||
let rtype = a:0 >= 1 ? a:1 : 'num'
|
||||
return s:BitwiseComparison(a:num1, a:num2, rtype,
|
||||
\ 'get(bits1, v:val) || get(bits2, v:val)')
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#bitwise#XOR(num1, num2, ...) "{{{3
|
||||
let rtype = a:0 >= 1 ? a:1 : 'num'
|
||||
return s:BitwiseComparison(a:num1, a:num2, rtype,
|
||||
\ 'get(bits1, v:val) ? !get(bits2, v:val) : get(bits2, v:val)')
|
||||
endf
|
||||
|
||||
|
||||
function! s:BitwiseComparison(num1, num2, rtype, expr) "{{{3
|
||||
let bits1 = tlib#bitwise#Num2Bits(a:num1)
|
||||
let bits2 = tlib#bitwise#Num2Bits(a:num2)
|
||||
let range = range(max([len(bits1), len(bits2)]))
|
||||
let bits = map(range, a:expr)
|
||||
if a:rtype == 'num' || (a:rtype == 'auto' && type(a:num1) <= 1)
|
||||
return tlib#bitwise#Bits2Num(bits)
|
||||
else
|
||||
return bits
|
||||
endif
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#bitwise#ShiftRight(bits, n) "{{{3
|
||||
let bits = a:bits[a:n : -1]
|
||||
if empty(bits)
|
||||
let bits = [0]
|
||||
endif
|
||||
return bits
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#bitwise#ShiftLeft(bits, n) "{{{3
|
||||
let bits = repeat([0], a:n) + a:bits
|
||||
return bits
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#bitwise#Add(num1, num2, ...) "{{{3
|
||||
let rtype = a:0 >= 1 ? a:1 : 'num'
|
||||
let bits1 = tlib#bitwise#Num2Bits(a:num1)
|
||||
let bits2 = tlib#bitwise#Num2Bits(a:num2)
|
||||
let range = range(max([len(bits1), len(bits2)]))
|
||||
" TLogVAR bits1, bits2, range
|
||||
let carry = 0
|
||||
let bits = []
|
||||
for i in range
|
||||
let sum = get(bits1, i) + get(bits2, i) + carry
|
||||
if sum == 3
|
||||
let bit = 1
|
||||
let carry = 1
|
||||
elseif sum == 2
|
||||
let bit = 0
|
||||
let carry = 1
|
||||
elseif sum == 1
|
||||
let bit = 1
|
||||
let carry = 0
|
||||
elseif sum == 0
|
||||
let bit = 0
|
||||
let carry = 0
|
||||
endif
|
||||
call add(bits, bit)
|
||||
" TLogVAR i, bits, bit
|
||||
endfor
|
||||
if carry == 1
|
||||
call add(bits, carry)
|
||||
endif
|
||||
if rtype == 'num' || (rtype == 'auto' && type(a:num1) <= 1)
|
||||
return tlib#bitwise#Bits2Num(bits)
|
||||
else
|
||||
return bits
|
||||
endif
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#bitwise#Sub(num1, num2, ...) "{{{3
|
||||
let rtype = a:0 >= 1 ? a:1 : 'num'
|
||||
let bits1 = tlib#bitwise#Num2Bits(a:num1)
|
||||
let bits2 = tlib#bitwise#Num2Bits(a:num2)
|
||||
let range = range(max([len(bits1), len(bits2)]))
|
||||
let bits2 = map(range, '!get(bits2, v:val)')
|
||||
let bits2 = tlib#bitwise#Add(bits2, [1], 'bits')
|
||||
let bits3 = tlib#bitwise#Add(bits1, bits2, 'bits')
|
||||
let bits = bits3[0 : -2]
|
||||
if rtype == 'num' || (rtype == 'auto' && type(a:num1) <= 1)
|
||||
return tlib#bitwise#Bits2Num(bits)
|
||||
else
|
||||
return bits
|
||||
endif
|
||||
endf
|
||||
|
@ -1,401 +0,0 @@
|
||||
" buffer.vim
|
||||
" @Author: Tom Link (micathom AT gmail com?subject=[vim])
|
||||
" @Website: http://www.vim.org/account/profile.php?user_id=4037
|
||||
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
|
||||
" @Created: 2007-06-30.
|
||||
" @Last Change: 2015-11-06.
|
||||
" @Revision: 7.1.352
|
||||
|
||||
|
||||
" Where to display the line when using |tlib#buffer#ViewLine|.
|
||||
" For possible values for position see |scroll-cursor|.
|
||||
TLet g:tlib_viewline_position = 'zz'
|
||||
|
||||
|
||||
let s:bmru = []
|
||||
|
||||
|
||||
function! tlib#buffer#EnableMRU() "{{{3
|
||||
call tlib#autocmdgroup#Init()
|
||||
autocmd TLib BufEnter * call s:BMRU_Push(bufnr('%'))
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#buffer#DisableMRU() "{{{3
|
||||
call tlib#autocmdgroup#Init()
|
||||
autocmd! TLib BufEnter
|
||||
endf
|
||||
|
||||
|
||||
function! s:BMRU_Push(bnr) "{{{3
|
||||
let i = index(s:bmru, a:bnr)
|
||||
if i >= 0
|
||||
call remove(s:bmru, i)
|
||||
endif
|
||||
call insert(s:bmru, a:bnr)
|
||||
endf
|
||||
|
||||
|
||||
function! s:CompareBuffernameByBasename(a, b) "{{{3
|
||||
let rx = '"\zs.\{-}\ze" \+\S\+ \+\d\+$'
|
||||
let an = matchstr(a:a, rx)
|
||||
let an = fnamemodify(an, ':t')
|
||||
let bn = matchstr(a:b, rx)
|
||||
let bn = fnamemodify(bn, ':t')
|
||||
let rv = an == bn ? 0 : an > bn ? 1 : -1
|
||||
return rv
|
||||
endf
|
||||
|
||||
|
||||
function! s:CompareBufferNrByMRU(a, b) "{{{3
|
||||
let an = matchstr(a:a, '\s*\zs\d\+\ze')
|
||||
let bn = matchstr(a:b, '\s*\zs\d\+\ze')
|
||||
let ai = index(s:bmru, 0 + an)
|
||||
if ai == -1
|
||||
return 1
|
||||
else
|
||||
let bi = index(s:bmru, 0 + bn)
|
||||
if bi == -1
|
||||
return -1
|
||||
else
|
||||
return ai == bi ? 0 : ai > bi ? 1 : -1
|
||||
endif
|
||||
endif
|
||||
endf
|
||||
|
||||
|
||||
" Set the buffer to buffer and return a command as string that can be
|
||||
" evaluated by |:execute| in order to restore the original view.
|
||||
function! tlib#buffer#Set(buffer) "{{{3
|
||||
let lazyredraw = &lazyredraw
|
||||
set lazyredraw
|
||||
try
|
||||
let cb = bufnr('%')
|
||||
let sn = bufnr(a:buffer)
|
||||
if sn != cb
|
||||
let ws = bufwinnr(sn)
|
||||
if ws != -1
|
||||
let wb = bufwinnr('%')
|
||||
exec ws.'wincmd w'
|
||||
return wb.'wincmd w'
|
||||
else
|
||||
silent exec 'sbuffer! '. sn
|
||||
return 'wincmd c'
|
||||
endif
|
||||
else
|
||||
return ''
|
||||
endif
|
||||
finally
|
||||
let &lazyredraw = lazyredraw
|
||||
endtry
|
||||
endf
|
||||
|
||||
|
||||
" :def: function! tlib#buffer#Eval(buffer, code)
|
||||
" Evaluate CODE in BUFFER.
|
||||
"
|
||||
" EXAMPLES: >
|
||||
" call tlib#buffer#Eval('foo.txt', 'echo b:bar')
|
||||
function! tlib#buffer#Eval(buffer, code) "{{{3
|
||||
" let cb = bufnr('%')
|
||||
" let wb = bufwinnr('%')
|
||||
" " TLogVAR cb
|
||||
" let sn = bufnr(a:buffer)
|
||||
" let sb = sn != cb
|
||||
let lazyredraw = &lazyredraw
|
||||
set lazyredraw
|
||||
let restore = tlib#buffer#Set(a:buffer)
|
||||
try
|
||||
exec a:code
|
||||
" if sb
|
||||
" let ws = bufwinnr(sn)
|
||||
" if ws != -1
|
||||
" try
|
||||
" exec ws.'wincmd w'
|
||||
" exec a:code
|
||||
" finally
|
||||
" exec wb.'wincmd w'
|
||||
" endtry
|
||||
" else
|
||||
" try
|
||||
" silent exec 'sbuffer! '. sn
|
||||
" exec a:code
|
||||
" finally
|
||||
" wincmd c
|
||||
" endtry
|
||||
" endif
|
||||
" else
|
||||
" exec a:code
|
||||
" endif
|
||||
finally
|
||||
exec restore
|
||||
let &lazyredraw = lazyredraw
|
||||
endtry
|
||||
endf
|
||||
|
||||
|
||||
" :def: function! tlib#buffer#GetList(?show_hidden=0, ?show_number=0, " ?order='bufnr')
|
||||
" Possible values for the "order" argument:
|
||||
" bufnr :: Default behaviour
|
||||
" mru :: Sort buffers according to most recent use
|
||||
" basename :: Sort by the file's basename (last component)
|
||||
"
|
||||
" NOTE: MRU order works on second invocation only. If you want to always
|
||||
" use MRU order, call tlib#buffer#EnableMRU() in your ~/.vimrc file.
|
||||
function! tlib#buffer#GetList(...)
|
||||
TVarArg ['show_hidden', 0], ['show_number', 0], ['order', '']
|
||||
" TLogVAR show_hidden, show_number, order
|
||||
let ls_bang = show_hidden ? '!' : ''
|
||||
redir => bfs
|
||||
exec 'silent ls'. ls_bang
|
||||
redir END
|
||||
let buffer_list = split(bfs, '\n')
|
||||
if order == 'mru'
|
||||
if empty(s:bmru)
|
||||
call tlib#buffer#EnableMRU()
|
||||
echom 'tlib: Installed Buffer MRU logger; disable with: call tlib#buffer#DisableMRU()'
|
||||
else
|
||||
call sort(buffer_list, function('s:CompareBufferNrByMRU'))
|
||||
endif
|
||||
elseif order == 'basename'
|
||||
call sort(buffer_list, function('s:CompareBuffernameByBasename'))
|
||||
endif
|
||||
let buffer_nr = map(copy(buffer_list), 'str2nr(matchstr(v:val, ''\s*\zs\d\+\ze''))')
|
||||
" TLogVAR buffer_list, buffer_nr
|
||||
if show_number
|
||||
call map(buffer_list, 'matchstr(v:val, ''^\s*\d\+.\{-}\ze\s\+\S\+ \d\+\s*$'')')
|
||||
else
|
||||
call map(buffer_list, 'matchstr(v:val, ''^\s*\d\+\zs.\{-}\ze\s\+\S\+ \d\+\s*$'')')
|
||||
endif
|
||||
" TLogVAR buffer_list
|
||||
" call map(buffer_list, 'matchstr(v:val, ''^.\{-}\ze\s\+line \d\+\s*$'')')
|
||||
" TLogVAR buffer_list
|
||||
call map(buffer_list, 'matchstr(v:val, ''^[^"]\+''). printf("%-20s %s", fnamemodify(matchstr(v:val, ''"\zs.\{-}\ze"$''), ":t"), fnamemodify(matchstr(v:val, ''"\zs.\{-}\ze"$''), ":h"))')
|
||||
" TLogVAR buffer_list
|
||||
return [buffer_nr, buffer_list]
|
||||
endf
|
||||
|
||||
|
||||
" :def: function! tlib#buffer#ViewLine(line, ?position='z')
|
||||
" line is either a number or a string that begins with a number.
|
||||
" For possible values for position see |scroll-cursor|.
|
||||
" See also |g:tlib_viewline_position|.
|
||||
function! tlib#buffer#ViewLine(line, ...) "{{{3
|
||||
if a:line
|
||||
TVarArg 'pos'
|
||||
let ln = matchstr(a:line, '^\d\+')
|
||||
let lt = matchstr(a:line, '^\d\+: \zs.*')
|
||||
" TLogVAR pos, ln, lt
|
||||
exec ln
|
||||
if empty(pos)
|
||||
let pos = tlib#var#Get('tlib_viewline_position', 'wbg')
|
||||
endif
|
||||
" TLogVAR pos
|
||||
if !empty(pos)
|
||||
exec 'norm! '. pos
|
||||
endif
|
||||
call tlib#buffer#HighlightLine(ln)
|
||||
" let @/ = '\%'. ln .'l.*'
|
||||
endif
|
||||
endf
|
||||
|
||||
|
||||
function! s:UndoHighlightLine() "{{{3
|
||||
2match none
|
||||
autocmd! TLib CursorMoved,CursorMovedI <buffer>
|
||||
autocmd! TLib CursorHold,CursorHoldI <buffer>
|
||||
autocmd! TLib InsertEnter,InsertChange,InsertLeave <buffer>
|
||||
autocmd! TLib BufLeave,BufWinLeave,WinLeave,BufHidden <buffer>
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#buffer#HighlightLine(...) "{{{3
|
||||
TVarArg ['line', line('.')]
|
||||
" exec '2match MatchParen /^\%'. a:line .'l.*/'
|
||||
exec '2match Search /^\%'. line .'l.*/'
|
||||
call tlib#autocmdgroup#Init()
|
||||
exec 'autocmd TLib CursorMoved,CursorMovedI <buffer> if line(".") != '. line .' | call s:UndoHighlightLine() | endif'
|
||||
autocmd TLib CursorHold,CursorHoldI <buffer> call s:UndoHighlightLine()
|
||||
autocmd TLib InsertEnter <buffer> call s:UndoHighlightLine()
|
||||
" autocmd TLib BufLeave,BufWinLeave,WinLeave,BufHidden <buffer> call s:UndoHighlightLine()
|
||||
endf
|
||||
|
||||
|
||||
" Delete the lines in the current buffer. Wrapper for |:delete|.
|
||||
function! tlib#buffer#DeleteRange(line1, line2) "{{{3
|
||||
let r = @t
|
||||
try
|
||||
exec a:line1.','.a:line2.'delete t'
|
||||
finally
|
||||
let @t = r
|
||||
endtry
|
||||
endf
|
||||
|
||||
|
||||
" Replace a range of lines.
|
||||
function! tlib#buffer#ReplaceRange(line1, line2, lines)
|
||||
call tlib#buffer#DeleteRange(a:line1, a:line2)
|
||||
call append(a:line1 - 1, a:lines)
|
||||
endf
|
||||
|
||||
|
||||
" Initialize some scratch area at the bottom of the current buffer.
|
||||
function! tlib#buffer#ScratchStart() "{{{3
|
||||
norm! Go
|
||||
let b:tlib_inbuffer_scratch = line('$')
|
||||
return b:tlib_inbuffer_scratch
|
||||
endf
|
||||
|
||||
|
||||
" Remove the in-buffer scratch area.
|
||||
function! tlib#buffer#ScratchEnd() "{{{3
|
||||
if !exists('b:tlib_inbuffer_scratch')
|
||||
echoerr 'tlib: In-buffer scratch not initalized'
|
||||
endif
|
||||
call tlib#buffer#DeleteRange(b:tlib_inbuffer_scratch, line('$'))
|
||||
unlet b:tlib_inbuffer_scratch
|
||||
endf
|
||||
|
||||
|
||||
" Run exec on all buffers via bufdo and return to the original buffer.
|
||||
function! tlib#buffer#BufDo(exec) "{{{3
|
||||
let bn = bufnr('%')
|
||||
exec 'bufdo '. a:exec
|
||||
exec 'buffer! '. bn
|
||||
endf
|
||||
|
||||
|
||||
" :def: function! tlib#buffer#InsertText(text, keyargs)
|
||||
" Keyargs:
|
||||
" 'shift': 0|N
|
||||
" 'col': col('.')|N
|
||||
" 'lineno': line('.')|N
|
||||
" 'indent': 0|1
|
||||
" 'pos': 'e'|'s' ... Where to locate the cursor (somewhat like s and e in {offset})
|
||||
" Insert text (a string) in the buffer.
|
||||
function! tlib#buffer#InsertText(text, ...) "{{{3
|
||||
TVarArg ['keyargs', {}]
|
||||
" TLogVAR a:text, keyargs
|
||||
let keyargs = extend({
|
||||
\ 'shift': 0, 'col': col('.'), 'lineno': line('.'), 'pos': 'e', 'indent': 0
|
||||
\ }, keyargs)
|
||||
" TLogVAR keyargs
|
||||
let grow = 0
|
||||
let post_del_last_line = line('$') == 1
|
||||
let line = getline(keyargs.lineno)
|
||||
if keyargs.col + keyargs.shift > 0
|
||||
let pre = line[0 : (keyargs.col - 1 + keyargs.shift)]
|
||||
let post = line[(keyargs.col + keyargs.shift): -1]
|
||||
else
|
||||
let pre = ''
|
||||
let post = line
|
||||
endif
|
||||
" TLogVAR keyargs.lineno, line, pre, post
|
||||
let text0 = pre . a:text . post
|
||||
let text = split(text0, '\n', 1)
|
||||
" TLogVAR text
|
||||
let icol = len(pre)
|
||||
" exec 'norm! '. keyargs.lineno .'G'
|
||||
call cursor(keyargs.lineno, keyargs.col)
|
||||
if keyargs.indent && keyargs.col > 1
|
||||
if &fo =~# '[or]'
|
||||
" FIXME: Is the simple version sufficient?
|
||||
" VERSION 1
|
||||
" " This doesn't work because it's not guaranteed that the
|
||||
" " cursor is set.
|
||||
" let cline = getline('.')
|
||||
" norm! a
|
||||
" "norm! o
|
||||
" " TAssertExec redraw | sleep 3
|
||||
" let idt = strpart(getline('.'), 0, keyargs.col('.') + keyargs.shift)
|
||||
" " TLogVAR idt
|
||||
" let idtl = len(idt)
|
||||
" -1,.delete
|
||||
" " TAssertExec redraw | sleep 3
|
||||
" call append(keyargs.lineno - 1, cline)
|
||||
" call cursor(keyargs.lineno, keyargs.col)
|
||||
" " TAssertExec redraw | sleep 3
|
||||
" if idtl == 0 && icol != 0
|
||||
" let idt = matchstr(pre, '^\s\+')
|
||||
" let idtl = len(idt)
|
||||
" endif
|
||||
" VERSION 2
|
||||
let idt = matchstr(pre, '^\s\+')
|
||||
let idtl = len(idt)
|
||||
else
|
||||
let [m_0, idt, iline; rest] = matchlist(pre, '^\(\s*\)\(.*\)$')
|
||||
let idtl = len(idt)
|
||||
endif
|
||||
if idtl < icol
|
||||
let idt .= repeat(' ', icol - idtl)
|
||||
endif
|
||||
" TLogVAR idt
|
||||
let idtl1 = len(idt)
|
||||
for i in range(1, len(text) - 1)
|
||||
let text[i] = idt . text[i]
|
||||
let grow += idtl1
|
||||
endfor
|
||||
endif
|
||||
" TLogVAR text
|
||||
" exec 'norm! '. keyargs.lineno .'Gdd'
|
||||
call tlib#normal#WithRegister('"tdd', 't')
|
||||
call append(keyargs.lineno - 1, text)
|
||||
if post_del_last_line
|
||||
call tlib#buffer#KeepCursorPosition('$delete')
|
||||
endif
|
||||
let tlen = len(text)
|
||||
let posshift = matchstr(keyargs.pos, '\d\+')
|
||||
" TLogVAR keyargs.pos
|
||||
if keyargs.pos =~ '^e'
|
||||
exec keyargs.lineno + tlen - 1
|
||||
exec 'norm! 0'. (len(text[-1]) - len(post) + posshift - 1) .'l'
|
||||
elseif keyargs.pos =~ '^s'
|
||||
" TLogVAR keyargs.lineno, pre, posshift
|
||||
exec keyargs.lineno
|
||||
exec 'norm! '. len(pre) .'|'
|
||||
if !empty(posshift)
|
||||
exec 'norm! '. posshift .'h'
|
||||
endif
|
||||
endif
|
||||
" TLogDBG getline(keyargs.lineno)
|
||||
" TLogDBG string(getline(1, '$'))
|
||||
return grow
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#buffer#InsertText0(text, ...) "{{{3
|
||||
TVarArg ['keyargs', {}]
|
||||
let mode = get(keyargs, 'mode', 'i')
|
||||
" TLogVAR mode
|
||||
if !has_key(keyargs, 'shift')
|
||||
let col = col('.')
|
||||
" if mode =~ 'i'
|
||||
" let col += 1
|
||||
" endif
|
||||
let keyargs.shift = col >= col('$') ? 0 : -1
|
||||
" let keyargs.shift = col('.') >= col('$') ? 0 : -1
|
||||
" TLogVAR col
|
||||
" TLogDBG col('.') .'-'. col('$') .': '. string(getline('.'))
|
||||
endif
|
||||
" TLogVAR keyargs.shift
|
||||
return tlib#buffer#InsertText(a:text, keyargs)
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#buffer#CurrentByte() "{{{3
|
||||
return line2byte(line('.')) + col('.')
|
||||
endf
|
||||
|
||||
|
||||
" Evaluate cmd while maintaining the cursor position and jump registers.
|
||||
function! tlib#buffer#KeepCursorPosition(cmd) "{{{3
|
||||
" let pos = getpos('.')
|
||||
let view = winsaveview()
|
||||
try
|
||||
keepjumps exec a:cmd
|
||||
finally
|
||||
" call setpos('.', pos)
|
||||
call winrestview(view)
|
||||
endtry
|
||||
endf
|
||||
|
@ -1,356 +0,0 @@
|
||||
" cache.vim
|
||||
" @Author: Tom Link (micathom AT gmail com?subject=[vim])
|
||||
" @Website: http://www.vim.org/account/profile.php?user_id=4037
|
||||
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
|
||||
" @Created: 2007-06-30.
|
||||
" @Last Change: 2015-10-24.
|
||||
" @Revision: 31.1.243
|
||||
|
||||
|
||||
" The cache directory. If empty, use |tlib#dir#MyRuntime|.'/cache'.
|
||||
" You might want to delete old files from this directory from time to
|
||||
" time with a command like: >
|
||||
" find ~/vimfiles/cache/ -atime +31 -type f -print -delete
|
||||
TLet g:tlib_cache = ''
|
||||
|
||||
" |tlib#cache#Purge()|: Remove cache files older than N days.
|
||||
TLet g:tlib#cache#purge_days = 31
|
||||
|
||||
" Purge the cache every N days. Disable automatic purging by setting
|
||||
" this value to a negative value.
|
||||
TLet g:tlib#cache#purge_every_days = 31
|
||||
|
||||
" The encoding used for the purge-cache script.
|
||||
" Default: 'enc'
|
||||
TLet g:tlib#cache#script_encoding = &enc
|
||||
|
||||
" Whether to run the directory removal script:
|
||||
" 0 ... No
|
||||
" 1 ... Query user
|
||||
" 2 ... Yes
|
||||
TLet g:tlib#cache#run_script = 1
|
||||
|
||||
" Verbosity level:
|
||||
" 0 ... Be quiet
|
||||
" 1 ... Display informative message
|
||||
" 2 ... Display detailed messages
|
||||
TLet g:tlib#cache#verbosity = 1
|
||||
|
||||
" A list of regexps that are matched against partial filenames of the
|
||||
" cached files. If a regexp matches, the file won't be removed by
|
||||
" |tlib#cache#Purge()|.
|
||||
TLet g:tlib#cache#dont_purge = ['[\/]\.last_purge$']
|
||||
|
||||
" If the cache filename is longer than N characters, use
|
||||
" |pathshorten()|.
|
||||
TLet g:tlib#cache#max_filename = 200
|
||||
|
||||
let s:cache = {}
|
||||
|
||||
|
||||
" :display: tlib#cache#Dir(?mode = 'bg')
|
||||
" The default cache directory.
|
||||
function! tlib#cache#Dir(...) "{{{3
|
||||
TVarArg ['mode', 'bg']
|
||||
let dir = tlib#var#Get('tlib_cache', mode)
|
||||
if empty(dir)
|
||||
let dir = tlib#file#Join([tlib#dir#MyRuntime(), 'cache'])
|
||||
endif
|
||||
return dir
|
||||
endf
|
||||
|
||||
|
||||
" :def: function! tlib#cache#Filename(type, ?file=%, ?mkdir=0, ?dir='')
|
||||
function! tlib#cache#Filename(type, ...) "{{{3
|
||||
" TLogDBG 'bufname='. bufname('.')
|
||||
let dir0 = a:0 >= 3 && !empty(a:3) ? a:3 : tlib#cache#Dir()
|
||||
let dir = dir0
|
||||
if a:0 >= 1 && !empty(a:1)
|
||||
let file = a:1
|
||||
else
|
||||
if empty(expand('%:t'))
|
||||
return ''
|
||||
endif
|
||||
let file = expand('%:p')
|
||||
let file = tlib#file#Relative(file, tlib#file#Join([dir, '..']))
|
||||
endif
|
||||
" TLogVAR file, dir
|
||||
let mkdir = a:0 >= 2 ? a:2 : 0
|
||||
let file = substitute(file, '\.\.\|[:&<>]\|//\+\|\\\\\+', '_', 'g')
|
||||
let dirs = [dir, a:type]
|
||||
let dirf = fnamemodify(file, ':h')
|
||||
if dirf != '.'
|
||||
call add(dirs, dirf)
|
||||
endif
|
||||
let dir = tlib#file#Join(dirs)
|
||||
" TLogVAR dir
|
||||
let dir = tlib#dir#PlainName(dir)
|
||||
" TLogVAR dir
|
||||
let file = fnamemodify(file, ':t')
|
||||
" TLogVAR file, dir, mkdir
|
||||
let cache_file = tlib#file#Join([dir, file])
|
||||
if len(cache_file) > g:tlib#cache#max_filename
|
||||
if v:version >= 704
|
||||
let shortfilename = pathshorten(file) .'_'. sha256(file)
|
||||
else
|
||||
let shortfilename = pathshorten(file) .'_'. tlib#hash#Adler32(file)
|
||||
endif
|
||||
let cache_file = tlib#cache#Filename(a:type, shortfilename, mkdir, dir0)
|
||||
else
|
||||
if mkdir && !isdirectory(dir)
|
||||
try
|
||||
call mkdir(dir, 'p')
|
||||
catch /^Vim\%((\a\+)\)\=:E739:/
|
||||
if filereadable(dir) && !isdirectory(dir)
|
||||
echoerr 'TLib: Cannot create directory for cache file because a file with the same name exists (please delete it):' dir
|
||||
" call delete(dir)
|
||||
" call mkdir(dir, 'p')
|
||||
endif
|
||||
endtry
|
||||
endif
|
||||
endif
|
||||
" TLogVAR cache_file
|
||||
return cache_file
|
||||
endf
|
||||
|
||||
|
||||
let s:timestamps = {}
|
||||
|
||||
|
||||
function! s:SetTimestamp(cfile, type) "{{{3
|
||||
if !has_key(s:timestamps, a:cfile)
|
||||
let s:timestamps[a:cfile] = {}
|
||||
endif
|
||||
let s:timestamps[a:cfile].atime = getftime(a:cfile)
|
||||
let s:timestamps[a:cfile][a:type] = s:timestamps[a:cfile].atime
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#cache#Save(cfile, dictionary, ...) "{{{3
|
||||
TVarArg ['options', {}]
|
||||
let in_memory = get(options, 'in_memory', 0)
|
||||
if in_memory
|
||||
" TLogVAR in_memory, a:cfile, localtime()
|
||||
let s:cache[a:cfile] = {'mtime': localtime(), 'data': a:dictionary}
|
||||
elseif !empty(a:cfile)
|
||||
" TLogVAR a:dictionary
|
||||
call writefile([string(a:dictionary)], a:cfile, 'b')
|
||||
call s:SetTimestamp(a:cfile, 'write')
|
||||
endif
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#cache#MTime(cfile) "{{{3
|
||||
let mtime = {'mtime': getftime(a:cfile)}
|
||||
let mtime = extend(mtime, get(s:timestamps, a:cfile, {}))
|
||||
return mtime
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#cache#Get(cfile, ...) "{{{3
|
||||
TVarArg ['default', {}], ['options', {}]
|
||||
let in_memory = get(options, 'in_memory', 0)
|
||||
if in_memory
|
||||
" TLogVAR in_memory, a:cfile
|
||||
return get(get(s:cache, a:cfile, {}), 'data', default)
|
||||
else
|
||||
call tlib#cache#MaybePurge()
|
||||
if !empty(a:cfile) && filereadable(a:cfile)
|
||||
let val = readfile(a:cfile, 'b')
|
||||
call s:SetTimestamp(a:cfile, 'read')
|
||||
return eval(join(val, "\n"))
|
||||
else
|
||||
return default
|
||||
endif
|
||||
endif
|
||||
endf
|
||||
|
||||
|
||||
" :display: tlib#cache#Value(cfile, generator, ftime, ?generator_args=[], ?options={})
|
||||
" Get a cached value from cfile. If it is outdated (compared to ftime)
|
||||
" or does not exist, create it calling a generator function.
|
||||
function! tlib#cache#Value(cfile, generator, ftime, ...) "{{{3
|
||||
TVarArg ['args', []], ['options', {}]
|
||||
let in_memory = get(options, 'in_memory', 0)
|
||||
let not_found = in_memory ? !has_key(s:cache, a:cfile) : !filereadable(a:cfile)
|
||||
" TLogVAR in_memory, not_found
|
||||
let cftime = in_memory ? (not_found ? 0 : s:cache[a:cfile].mtime) : getftime(a:cfile)
|
||||
if not_found || (a:ftime != 0 && cftime < a:ftime)
|
||||
" TLogVAR a:generator, args
|
||||
let val = call(a:generator, args)
|
||||
" TLogVAR val
|
||||
let cval = {'val': val}
|
||||
" TLogVAR cval
|
||||
call tlib#cache#Save(a:cfile, cval, options)
|
||||
return val
|
||||
else
|
||||
let val = tlib#cache#Get(a:cfile, {}, options)
|
||||
if !has_key(val, 'val')
|
||||
throw 'tlib#cache#Value: Internal error: '. a:cfile
|
||||
else
|
||||
return val.val
|
||||
endif
|
||||
endif
|
||||
endf
|
||||
|
||||
|
||||
" Call |tlib#cache#Purge()| if the last purge was done before
|
||||
" |g:tlib#cache#purge_every_days|.
|
||||
function! tlib#cache#MaybePurge() "{{{3
|
||||
if g:tlib#cache#purge_every_days < 0
|
||||
return
|
||||
endif
|
||||
let dir = tlib#cache#Dir('g')
|
||||
let last_purge = tlib#file#Join([dir, '.last_purge'])
|
||||
let last_purge_exists = filereadable(last_purge)
|
||||
if last_purge_exists
|
||||
let threshold = localtime() - g:tlib#cache#purge_every_days * g:tlib#date#dayshift
|
||||
let should_purge = getftime(last_purge) < threshold
|
||||
else
|
||||
let should_purge = 0 " should ignore empty dirs, like the tmru one: !empty(glob(tlib#file#Join([dir, '**'])))
|
||||
endif
|
||||
if should_purge
|
||||
if last_purge_exists
|
||||
let yn = 'y'
|
||||
else
|
||||
let txt = "TLib: The cache directory '". dir ."' should be purged of old files.\nDelete files older than ". g:tlib#cache#purge_days ." days now?"
|
||||
let yn = tlib#input#Dialog(txt, ['yes', 'no'], 'no')
|
||||
endif
|
||||
if yn =~ '^y\%[es]$'
|
||||
call tlib#cache#Purge()
|
||||
else
|
||||
let g:tlib#cache#purge_every_days = -1
|
||||
if !last_purge_exists
|
||||
call s:PurgeTimestamp(dir)
|
||||
endif
|
||||
echohl WarningMsg
|
||||
echom "TLib: Please run :call tlib#cache#Purge() to clean up ". dir
|
||||
echohl NONE
|
||||
endif
|
||||
elseif !last_purge_exists
|
||||
call s:PurgeTimestamp(dir)
|
||||
endif
|
||||
endf
|
||||
|
||||
|
||||
" Delete old files.
|
||||
function! tlib#cache#Purge() "{{{3
|
||||
let threshold = localtime() - g:tlib#cache#purge_days * g:tlib#date#dayshift
|
||||
let dir = tlib#cache#Dir('g')
|
||||
if g:tlib#cache#verbosity >= 1
|
||||
echohl WarningMsg
|
||||
echom "TLib: Delete files older than ". g:tlib#cache#purge_days ." days from ". dir
|
||||
echohl NONE
|
||||
endif
|
||||
let files = tlib#cache#ListFilesInCache()
|
||||
let deldir = []
|
||||
let newer = []
|
||||
let msg = []
|
||||
let more = &more
|
||||
set nomore
|
||||
try
|
||||
for file in files
|
||||
if isdirectory(file)
|
||||
if empty(filter(copy(newer), 'strpart(v:val, 0, len(file)) ==# file'))
|
||||
call add(deldir, file)
|
||||
endif
|
||||
else
|
||||
if getftime(file) < threshold
|
||||
if delete(file)
|
||||
call add(msg, "TLib: Could not delete cache file: ". file)
|
||||
elseif g:tlib#cache#verbosity >= 2
|
||||
call add(msg, "TLib: Delete cache file: ". file)
|
||||
endif
|
||||
else
|
||||
call add(newer, file)
|
||||
endif
|
||||
endif
|
||||
endfor
|
||||
finally
|
||||
let &more = more
|
||||
endtry
|
||||
if !empty(msg) && g:tlib#cache#verbosity >= 1
|
||||
echo join(msg, "\n")
|
||||
endif
|
||||
if !empty(deldir)
|
||||
if &shell =~ 'sh\(\.exe\)\?$'
|
||||
let scriptfile = 'deldir.sh'
|
||||
let rmdir = 'rm -rf %s'
|
||||
else
|
||||
let scriptfile = 'deldir.bat'
|
||||
let rmdir = 'rmdir /S /Q %s'
|
||||
endif
|
||||
let enc = g:tlib#cache#script_encoding
|
||||
if has('multi_byte') && enc != &enc
|
||||
call map(deldir, 'iconv(v:val, &enc, enc)')
|
||||
endif
|
||||
let scriptfile = tlib#file#Join([dir, scriptfile])
|
||||
if filereadable(scriptfile)
|
||||
let script = readfile(scriptfile)
|
||||
else
|
||||
let script = []
|
||||
endif
|
||||
let script += map(copy(deldir), 'printf(rmdir, shellescape(v:val, 1))')
|
||||
let script = tlib#list#Uniq(script)
|
||||
call writefile(script, scriptfile)
|
||||
call inputsave()
|
||||
if g:tlib#cache#run_script == 0
|
||||
if g:tlib#cache#verbosity >= 1
|
||||
echohl WarningMsg
|
||||
if g:tlib#cache#verbosity >= 2
|
||||
echom "TLib: Purged cache. Need to run script to delete directories"
|
||||
endif
|
||||
echom "TLib: Please review and execute: ". scriptfile
|
||||
echohl NONE
|
||||
endif
|
||||
else
|
||||
try
|
||||
let yn = g:tlib#cache#run_script == 2 ? 'y' : tlib#input#Dialog("TLib: About to delete directories by means of a shell script.\nDirectory removal script: ". scriptfile ."\nRun script to delete directories now?", ['yes', 'no', 'edit'], 'no')
|
||||
if yn =~ '^y\%[es]$'
|
||||
exec 'cd '. fnameescape(dir)
|
||||
exec '! ' &shell shellescape(scriptfile, 1)
|
||||
exec 'cd -'
|
||||
call delete(scriptfile)
|
||||
elseif yn =~ '^e\%[dit]$'
|
||||
exec 'edit '. fnameescape(scriptfile)
|
||||
endif
|
||||
finally
|
||||
call inputrestore()
|
||||
endtry
|
||||
endif
|
||||
endif
|
||||
call s:PurgeTimestamp(dir)
|
||||
endf
|
||||
|
||||
|
||||
function! s:PurgeTimestamp(dir) "{{{3
|
||||
let last_purge = tlib#file#Join([a:dir, '.last_purge'])
|
||||
" TLogVAR last_purge
|
||||
call writefile([" "], last_purge)
|
||||
endf
|
||||
|
||||
function! tlib#cache#ListFilesInCache(...) "{{{3
|
||||
let dir = a:0 >= 1 ? a:1 : tlib#cache#Dir('g')
|
||||
if v:version > 702 || (v:version == 702 && has('patch51'))
|
||||
let filess = glob(tlib#file#Join([dir, '**']), 1)
|
||||
else
|
||||
let filess = glob(tlib#file#Join([dir, '**']))
|
||||
endif
|
||||
let files = reverse(split(filess, '\n'))
|
||||
let pos0 = len(tlib#dir#CanonicName(dir))
|
||||
call filter(files, 's:ShouldPurge(strpart(v:val, pos0))')
|
||||
return files
|
||||
endf
|
||||
|
||||
|
||||
function! s:ShouldPurge(partial_filename) "{{{3
|
||||
" TLogVAR a:partial_filename
|
||||
for rx in g:tlib#cache#dont_purge
|
||||
if a:partial_filename =~ rx
|
||||
" TLogVAR a:partial_filename, rx
|
||||
return 0
|
||||
endif
|
||||
endfor
|
||||
return 1
|
||||
endf
|
||||
|
@ -1,59 +0,0 @@
|
||||
" @Author: Tom Link (micathom AT gmail com?subject=[vim])
|
||||
" @Website: http://www.vim.org/account/profile.php?user_id=4037
|
||||
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
|
||||
" @Revision: 38
|
||||
|
||||
|
||||
" :def: function! tlib#char#Get(?timeout=0)
|
||||
" Get a character.
|
||||
"
|
||||
" EXAMPLES: >
|
||||
" echo tlib#char#Get()
|
||||
" echo tlib#char#Get(5)
|
||||
function! tlib#char#Get(...) "{{{3
|
||||
TVarArg ['timeout', 0], ['resolution', 0], ['getmod', 0]
|
||||
let char = -1
|
||||
let mode = 0
|
||||
if timeout == 0 || !has('reltime')
|
||||
let char = getchar()
|
||||
else
|
||||
let char = tlib#char#GetWithTimeout(timeout, resolution)
|
||||
endif
|
||||
if getmod
|
||||
if char != -1
|
||||
let mode = getcharmod()
|
||||
endif
|
||||
return [char, mode]
|
||||
else
|
||||
return char
|
||||
endif
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#char#IsAvailable() "{{{3
|
||||
let ch = getchar(1)
|
||||
return type(ch) == 0 && ch != 0
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#char#GetWithTimeout(timeout, ...) "{{{3
|
||||
TVarArg ['resolution', 2]
|
||||
" TLogVAR a:timeout, resolution
|
||||
let start = tlib#time#MSecs()
|
||||
while 1
|
||||
let c = getchar(0)
|
||||
if type(c) != 0 || c != 0
|
||||
return c
|
||||
else
|
||||
let now = tlib#time#MSecs()
|
||||
let diff = tlib#time#DiffMSecs(now, start, resolution)
|
||||
" TLogVAR diff
|
||||
if diff > a:timeout
|
||||
return -1
|
||||
endif
|
||||
endif
|
||||
endwh
|
||||
return -1
|
||||
endf
|
||||
|
||||
|
@ -1,117 +0,0 @@
|
||||
" @Author: Tom Link (micathom AT gmail com?subject=[vim])
|
||||
" @Website: http://www.vim.org/account/profile.php?user_id=4037
|
||||
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
|
||||
" @Revision: 58
|
||||
|
||||
|
||||
let g:tlib#cmd#last_output = []
|
||||
|
||||
|
||||
function! tlib#cmd#OutputAsList(command) "{{{3
|
||||
" TLogVAR a:command
|
||||
if exists('s:redir_lines')
|
||||
redir END
|
||||
let cache = s:redir_lines
|
||||
endif
|
||||
let s:redir_lines = ''
|
||||
redir =>> s:redir_lines
|
||||
silent! exec a:command
|
||||
redir END
|
||||
let g:tlib#cmd#last_output = split(s:redir_lines, '\n')
|
||||
unlet s:redir_lines
|
||||
if exists('cache')
|
||||
let s:redir_lines = cache
|
||||
redir =>> s:redir_lines
|
||||
endif
|
||||
return g:tlib#cmd#last_output
|
||||
endf
|
||||
|
||||
|
||||
" See |:TBrowseOutput|.
|
||||
function! tlib#cmd#BrowseOutput(command) "{{{3
|
||||
call tlib#cmd#BrowseOutputWithCallback("tlib#cmd#DefaultBrowseOutput", a:command)
|
||||
endf
|
||||
|
||||
" :def: function! tlib#cmd#BrowseOutputWithCallback(callback, command)
|
||||
" Execute COMMAND and present its output in a |tlib#input#List()|;
|
||||
" when a line is selected, execute the function named as the CALLBACK
|
||||
" and pass in that line as an argument.
|
||||
"
|
||||
" The CALLBACK function gives you an opportunity to massage the COMMAND output
|
||||
" and possibly act on it in a meaningful way. For example, if COMMAND listed
|
||||
" all URIs found in the current buffer, CALLBACK could validate and then open
|
||||
" the selected URI in the system's default browser.
|
||||
"
|
||||
" This function is meant to be a tool to help compose the implementations of
|
||||
" powerful commands that use |tlib#input#List()| as a common interface. See
|
||||
" |TBrowseScriptnames| as an example.
|
||||
"
|
||||
" EXAMPLES: >
|
||||
" call tlib#cmd#BrowseOutputWithCallback('tlib#cmd#ParseScriptname', 'scriptnames')
|
||||
function! tlib#cmd#BrowseOutputWithCallback(callback, command) "{{{3
|
||||
let list = tlib#cmd#OutputAsList(a:command)
|
||||
let cmds = tlib#input#List('m', 'Output of: '. a:command, list)
|
||||
if !empty(cmds)
|
||||
for cmd in cmds
|
||||
let Callback = function(a:callback)
|
||||
call call(Callback, [cmd])
|
||||
endfor
|
||||
endif
|
||||
endf
|
||||
|
||||
function! tlib#cmd#DefaultBrowseOutput(cmd) "{{{3
|
||||
call feedkeys(':'. a:cmd)
|
||||
endf
|
||||
|
||||
function! tlib#cmd#ParseScriptname(line) "{{{3
|
||||
" let parsedValue = substitute(a:line, '^.\{-}\/', '/', '')
|
||||
let parsedValue = matchstr(a:line, '^\s*\d\+:\s*\zs.*$')
|
||||
exe 'drop '. fnameescape(parsedValue)
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#cmd#TBrowseScriptnames() abort "{{{3
|
||||
call tlib#cmd#BrowseOutputWithCallback("tlib#cmd#ParseScriptname", "scriptnames")
|
||||
endf
|
||||
|
||||
|
||||
" :def: function! tlib#cmd#UseVertical(?rx='')
|
||||
" Look at the history whether the command was called with vertical. If
|
||||
" an rx is provided check first if the last entry in the history matches
|
||||
" this rx.
|
||||
function! tlib#cmd#UseVertical(...) "{{{3
|
||||
TVarArg ['rx']
|
||||
let h0 = histget(':')
|
||||
let rx0 = '\C\<vert\%[ical]\>\s\+'
|
||||
if !empty(rx)
|
||||
let rx0 .= '.\{-}'.rx
|
||||
endif
|
||||
" TLogVAR h0, rx0
|
||||
return h0 =~ rx0
|
||||
endf
|
||||
|
||||
|
||||
" Print the time in seconds or milliseconds (if your version of VIM
|
||||
" has |+reltime|) a command takes.
|
||||
function! tlib#cmd#Time(cmd) "{{{3
|
||||
if has('reltime')
|
||||
let start = tlib#time#Now()
|
||||
exec a:cmd
|
||||
let end = tlib#time#Now()
|
||||
let diff = string(tlib#time#Diff(end, start)) .'ms'
|
||||
else
|
||||
let start = localtime()
|
||||
exec a:cmd
|
||||
let diff = (localtime() - start) .'s'
|
||||
endif
|
||||
echom 'Time: '. diff .': '. a:cmd
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#cmd#Capture(cmd) "{{{3
|
||||
redir => s
|
||||
silent exec a:cmd
|
||||
redir END
|
||||
return s
|
||||
endf
|
||||
|
@ -1,26 +0,0 @@
|
||||
" @Author: Tom Link (mailto:micathom AT gmail com?subject=[vim])
|
||||
" @Website: http://www.vim.org/account/profile.php?user_id=4037
|
||||
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
|
||||
" @Revision: 25
|
||||
|
||||
|
||||
" function! tlib#comments#Comments(?rx='')
|
||||
function! tlib#comments#Comments(...)
|
||||
TVarArg ['rx', '']
|
||||
let comments = {}
|
||||
let co = &comments
|
||||
while !empty(co)
|
||||
" TLogVAR co
|
||||
let [m_0, m_key, m_val, m_val1, co0, co; rest] = matchlist(co, '^\([^:]*\):\(\(\\.\|[^,]*\)\+\)\(,\(.*\)$\|$\)')
|
||||
" TLogVAR m_key, m_val, co
|
||||
if empty(m_key)
|
||||
let m_key = ':'
|
||||
endif
|
||||
if empty(rx) || m_key =~ rx
|
||||
let comments[m_key] = m_val
|
||||
endif
|
||||
endwh
|
||||
return comments
|
||||
endf
|
||||
|
||||
|
@ -1,163 +0,0 @@
|
||||
" date.vim
|
||||
" @Author: Tom Link (mailto:micathom AT gmail com?subject=[vim])
|
||||
" @Website: http://www.vim.org/account/profile.php?user_id=4037
|
||||
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
|
||||
" @Created: 2010-03-25.
|
||||
" @Last Change: 2015-11-23.
|
||||
" @Revision: 21.0.34
|
||||
|
||||
|
||||
if !exists('g:tlib#date#ShortDatePrefix') | let g:tlib#date#ShortDatePrefix = '20' | endif "{{{2
|
||||
if !exists('g:tlib#date#TimeZoneShift') | let g:tlib#date#TimeZoneShift = 0 | endif "{{{2
|
||||
|
||||
let g:tlib#date#dayshift = 60 * 60 * 24
|
||||
" let g:tlib#date#date_rx = '\<\(\d\{4}\)-\(\d\d\)-\(\d\d\)\%(\s\+\(\(\d\d\):\(\d\d\)\)\)\?\>'
|
||||
let g:tlib#date#date_rx = '\<\(\d\{4}\)-\(\d\d\)-\(\d\d\)\>'
|
||||
let g:tlib#date#date_format = '%Y-%m-%d'
|
||||
|
||||
|
||||
function! tlib#date#IsDate(text) abort "{{{3
|
||||
return a:text =~# '^'. g:tlib#date#date_rx .'$'
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#date#Format(secs1970) abort "{{{3
|
||||
return strftime(g:tlib#date#date_format, a:secs1970)
|
||||
endf
|
||||
|
||||
|
||||
" :display: tlib#date#DiffInDays(date1, ?date2=localtime(), ?allow_zero=0)
|
||||
function! tlib#date#DiffInDays(date, ...)
|
||||
let allow_zero = a:0 >= 2 ? a:2 : 0
|
||||
let s0 = tlib#date#SecondsSince1970(a:date, 0, allow_zero)
|
||||
let s1 = a:0 >= 1 ? tlib#date#SecondsSince1970(a:1, 0, allow_zero) : localtime()
|
||||
let dd = (s0 - s1) / g:tlib#date#dayshift
|
||||
" TLogVAR dd
|
||||
return dd
|
||||
endf
|
||||
|
||||
|
||||
" :display: tlib#date#Parse(date, ?allow_zero=0) "{{{3
|
||||
function! tlib#date#Parse(date, ...) "{{{3
|
||||
let min = a:0 >= 1 && a:1 ? 0 : 1
|
||||
" TLogVAR a:date, min
|
||||
let m = matchlist(a:date, '^\(\d\{2}\|\d\{4}\)-\(\d\{1,2}\)-\(\d\{1,2}\)$')
|
||||
if !empty(m)
|
||||
let year = m[1]
|
||||
let month = m[2]
|
||||
let days = m[3]
|
||||
else
|
||||
let m = matchlist(a:date, '^\(\d\+\)/\(\d\{1,2}\)/\(\d\{1,2}\)$')
|
||||
if !empty(m)
|
||||
let year = m[1]
|
||||
let month = m[3]
|
||||
let days = m[2]
|
||||
else
|
||||
let m = matchlist(a:date, '^\(\d\{1,2}\)\.\s*\(\d\{1,2}\)\.\s*\(\d\d\{2}\|\d\{4}\)$')
|
||||
if !empty(m)
|
||||
let year = m[3]
|
||||
let month = m[2]
|
||||
let days = m[1]
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
if empty(m) || year == '' || month == '' || days == '' ||
|
||||
\ month < min || month > 12 || days < min || days > 31
|
||||
echoerr 'TLib: Invalid date: '. a:date
|
||||
return []
|
||||
endif
|
||||
if strlen(year) == 2
|
||||
let year = g:tlib#date#ShortDatePrefix . year
|
||||
endif
|
||||
return [0 + year, 0 + month, 0 + days]
|
||||
endf
|
||||
|
||||
|
||||
" tlib#date#SecondsSince1970(date, ?daysshift=0, ?allow_zero=0)
|
||||
function! tlib#date#SecondsSince1970(date, ...) "{{{3
|
||||
let allow_zero = a:0 >= 2 ? a:2 : 0
|
||||
" TLogVAR a:date, allow_zero
|
||||
let date = tlib#date#Parse(a:date, allow_zero)
|
||||
if empty(date)
|
||||
return 0
|
||||
endif
|
||||
let [year, month, days] = date
|
||||
if a:0 >= 1 && a:1 > 0
|
||||
let days = days + a:1
|
||||
end
|
||||
let days_passed = days
|
||||
let i = 1970
|
||||
while i < year
|
||||
let days_passed = days_passed + 365
|
||||
if i % 4 == 0 || i == 2000
|
||||
let days_passed = days_passed + 1
|
||||
endif
|
||||
let i = i + 1
|
||||
endwh
|
||||
let i = 1
|
||||
while i < month
|
||||
if i == 1
|
||||
let days_passed = days_passed + 31
|
||||
elseif i == 2
|
||||
let days_passed = days_passed + 28
|
||||
if year % 4 == 0 || year == 2000
|
||||
let days_passed = days_passed + 1
|
||||
endif
|
||||
elseif i == 3
|
||||
let days_passed = days_passed + 31
|
||||
elseif i == 4
|
||||
let days_passed = days_passed + 30
|
||||
elseif i == 5
|
||||
let days_passed = days_passed + 31
|
||||
elseif i == 6
|
||||
let days_passed = days_passed + 30
|
||||
elseif i == 7
|
||||
let days_passed = days_passed + 31
|
||||
elseif i == 8
|
||||
let days_passed = days_passed + 31
|
||||
elseif i == 9
|
||||
let days_passed = days_passed + 30
|
||||
elseif i == 10
|
||||
let days_passed = days_passed + 31
|
||||
elseif i == 11
|
||||
let days_passed = days_passed + 30
|
||||
endif
|
||||
let i = i + 1
|
||||
endwh
|
||||
let seconds = (days_passed - 1) * 24 * 60 * 60
|
||||
let seconds = seconds + (strftime('%H') + g:tlib#date#TimeZoneShift) * 60 * 60
|
||||
let seconds = seconds + strftime('%M') * 60
|
||||
let seconds = seconds + strftime('%S')
|
||||
return seconds
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#date#Shift(date, shift) abort "{{{3
|
||||
let n = str2nr(matchstr(a:shift, '\d\+'))
|
||||
let ml = matchlist(a:date, g:tlib#date#date_rx)
|
||||
" TLogVAR a:date, a:shift, n, ml
|
||||
if a:shift =~ 'd$'
|
||||
let secs = tlib#date#SecondsSince1970(a:date) + g:tlib#date#dayshift * n
|
||||
" TLogVAR secs
|
||||
let date = tlib#date#Format(secs)
|
||||
elseif a:shift =~ 'w$'
|
||||
let secs = tlib#date#SecondsSince1970(a:date) + g:tlib#date#dayshift * n * 7
|
||||
let date = tlib#date#Format(secs)
|
||||
elseif a:shift =~ 'm$'
|
||||
let d = str2nr(ml[3])
|
||||
let ms = str2nr(ml[2]) + n
|
||||
let m = (ms - 1) % 12 + 1
|
||||
let yr = str2nr(ml[1]) + ms / 12
|
||||
let date = printf('%04d-%02d-%02d', yr, m, d)
|
||||
" TLogVAR d, ms, m, yr, date
|
||||
elseif a:shift =~ 'y$'
|
||||
let yr = str2nr(ml[1]) + n
|
||||
let date = substitute(a:date, '^\d\{4}', yr, '')
|
||||
endif
|
||||
" if !empty(ml[4]) && date !~ '\s'. ml[4] .'$'
|
||||
" let date .= ' '. ml[4]
|
||||
" endif
|
||||
" TLogVAR date
|
||||
return date
|
||||
endf
|
||||
|
@ -1,15 +0,0 @@
|
||||
" @Author: Tom Link (mailto:micathom AT gmail com?subject=[vim])
|
||||
" @Website: https://github.com/tomtom
|
||||
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
|
||||
" @Last Change: 2015-10-14
|
||||
" @Revision: 2
|
||||
|
||||
|
||||
function! tlib#dictionary#Rev(dict) abort "{{{3
|
||||
let rev = {}
|
||||
for [m, f] in items(a:dict)
|
||||
let rev[f] = m
|
||||
endfor
|
||||
return rev
|
||||
endf
|
||||
|
@ -1,93 +0,0 @@
|
||||
" @Author: Tom Link (micathom AT gmail com?subject=[vim])
|
||||
" @Website: http://www.vim.org/account/profile.php?user_id=4037
|
||||
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
|
||||
" @Revision: 40
|
||||
|
||||
" TLet g:tlib#dir#sep = '/'
|
||||
TLet g:tlib#dir#sep = exists('+shellslash') && !&shellslash ? '\' : '/'
|
||||
|
||||
|
||||
let s:dir_stack = []
|
||||
|
||||
" EXAMPLES: >
|
||||
" tlib#dir#CanonicName('foo/bar')
|
||||
" => 'foo/bar/'
|
||||
function! tlib#dir#CanonicName(dirname) "{{{3
|
||||
let dirname = tlib#file#Canonic(a:dirname)
|
||||
if dirname !~ '[/\\]$'
|
||||
return dirname . g:tlib#dir#sep
|
||||
endif
|
||||
return dirname
|
||||
endf
|
||||
|
||||
|
||||
" EXAMPLES: >
|
||||
" tlib#dir#NativeName('foo/bar/')
|
||||
" On Windows:
|
||||
" => 'foo\bar\'
|
||||
" On Linux:
|
||||
" => 'foo/bar/'
|
||||
function! tlib#dir#NativeName(dirname) "{{{3
|
||||
let sep = tlib#rx#EscapeReplace(g:tlib#dir#sep)
|
||||
let dirname = substitute(a:dirname, '[\/]', sep, 'g')
|
||||
return dirname
|
||||
endf
|
||||
|
||||
|
||||
" EXAMPLES: >
|
||||
" tlib#dir#PlainName('foo/bar/')
|
||||
" => 'foo/bar'
|
||||
function! tlib#dir#PlainName(dirname) "{{{3
|
||||
let dirname = a:dirname
|
||||
while index(['/', '\'], dirname[-1 : -1]) != -1
|
||||
let dirname = dirname[0 : -2]
|
||||
endwh
|
||||
return dirname
|
||||
" return substitute(a:dirname, tlib#rx#Escape(g:tlib#dir#sep).'\+$', '', '')
|
||||
endf
|
||||
|
||||
|
||||
" Create a directory if it doesn't already exist.
|
||||
function! tlib#dir#Ensure(dir) "{{{3
|
||||
if !isdirectory(a:dir)
|
||||
let dir = tlib#dir#PlainName(a:dir)
|
||||
return mkdir(dir, 'p')
|
||||
endif
|
||||
return 1
|
||||
endf
|
||||
|
||||
|
||||
" Return the first directory in &rtp.
|
||||
function! tlib#dir#MyRuntime() "{{{3
|
||||
return get(split(&rtp, ','), 0)
|
||||
endf
|
||||
|
||||
|
||||
" :def: function! tlib#dir#CD(dir, ?locally=0) => CWD
|
||||
function! tlib#dir#CD(dir, ...) "{{{3
|
||||
TVarArg ['locally', 0]
|
||||
let cmd = locally ? 'lcd! ' : 'cd! '
|
||||
" let cwd = getcwd()
|
||||
let cmd .= tlib#arg#Ex(a:dir)
|
||||
" TLogVAR a:dir, locally, cmd
|
||||
exec cmd
|
||||
" return cwd
|
||||
return getcwd()
|
||||
endf
|
||||
|
||||
|
||||
" :def: function! tlib#dir#Push(dir, ?locally=0) => CWD
|
||||
function! tlib#dir#Push(dir, ...) "{{{3
|
||||
TVarArg ['locally', 0]
|
||||
call add(s:dir_stack, [getcwd(), locally])
|
||||
return tlib#dir#CD(a:dir, locally)
|
||||
endf
|
||||
|
||||
|
||||
" :def: function! tlib#dir#Pop() => CWD
|
||||
function! tlib#dir#Pop() "{{{3
|
||||
let [dir, locally] = remove(s:dir_stack, -1)
|
||||
return tlib#dir#CD(dir, locally)
|
||||
endf
|
||||
|
||||
|
@ -1,72 +0,0 @@
|
||||
" @Author: Tom Link (mailto:micathom AT gmail com?subject=[vim])
|
||||
" @Website: http://www.vim.org/account/profile.php?user_id=4037
|
||||
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
|
||||
" @Revision: 56
|
||||
|
||||
|
||||
function! tlib#eval#FormatValue(value, ...) "{{{3
|
||||
TVarArg ['indent', 0]
|
||||
" TLogVAR a:value, indent
|
||||
let indent1 = indent + 1
|
||||
let indenti = repeat(' ', &sw)
|
||||
let type = type(a:value)
|
||||
let acc = []
|
||||
if type == 0 || type == 1 || type == 2
|
||||
" TLogDBG 'Use string() for type='. type
|
||||
call add(acc, string(a:value))
|
||||
elseif type == 3 "List
|
||||
" TLogDBG 'List'
|
||||
call add(acc, '[')
|
||||
for e in a:value
|
||||
call add(acc, printf('%s%s,', indenti, tlib#eval#FormatValue(e, indent1)))
|
||||
unlet e
|
||||
endfor
|
||||
call add(acc, ']')
|
||||
elseif type == 4 "Dictionary
|
||||
" TLogDBG 'Dictionary'
|
||||
call add(acc, '{')
|
||||
let indent1 = indent + 1
|
||||
for [k, v] in items(a:value)
|
||||
call add(acc, printf("%s%s: %s,", indenti, string(k), tlib#eval#FormatValue(v, indent1)))
|
||||
unlet k v
|
||||
endfor
|
||||
call add(acc, '}')
|
||||
else
|
||||
" TLogDBG 'Unknown type: '. string(a:value)
|
||||
call add(acc, string(a:value))
|
||||
endif
|
||||
if indent > 0
|
||||
let is = repeat(' ', indent * &sw)
|
||||
for i in range(1,len(acc) - 1)
|
||||
let acc[i] = is . acc[i]
|
||||
endfor
|
||||
endif
|
||||
return join(acc, "\n")
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#eval#Extend(a, b, ...) abort "{{{3
|
||||
let mode = a:0 >= 1 ? a:1 : 'force'
|
||||
if type(a:a) != type(a:b)
|
||||
throw 'tlib#eval#Extend: Incompatible types: a='. string(a:a) .' b='. string(a:b)
|
||||
elseif type(a:a) == 3 " list
|
||||
return extend(a:a, a:b, mode)
|
||||
elseif type(a:a) == 4 " dict
|
||||
for k in keys(a:b)
|
||||
if has_key(a:a, k)
|
||||
if mode == 'force'
|
||||
let a:a[k] = tlib#eval#Extend(copy(a:a[k]), a:b[k], mode)
|
||||
elseif mode == 'error'
|
||||
throw 'tlib#eval#Extend: Key already exists: '. k
|
||||
endif
|
||||
else
|
||||
let a:a[k] = a:b[k]
|
||||
endif
|
||||
unlet! k
|
||||
endfor
|
||||
return a:a
|
||||
else
|
||||
return a:b
|
||||
endif
|
||||
endf
|
||||
|
@ -1,278 +0,0 @@
|
||||
" @Author: Tom Link (micathom AT gmail com?subject=[vim])
|
||||
" @Website: http://www.vim.org/account/profile.php?user_id=4037
|
||||
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
|
||||
" @Revision: 168
|
||||
|
||||
|
||||
if !exists('g:tlib#file#drop')
|
||||
" If true, use |:drop| to edit loaded buffers (only available with GUI).
|
||||
let g:tlib#file#drop = has('gui') "{{{2
|
||||
endif
|
||||
|
||||
|
||||
if !exists('g:tlib#file#use_tabs')
|
||||
let g:tlib#file#use_tabs = 0 "{{{2
|
||||
endif
|
||||
|
||||
|
||||
if !exists('g:tlib#file#edit_cmds')
|
||||
let g:tlib#file#edit_cmds = g:tlib#file#use_tabs ? {'buffer': 'tab split | buffer', 'edit': 'tabedit'} : {} "{{{2
|
||||
endif
|
||||
|
||||
|
||||
if !exists('g:tlib#file#absolute_filename_rx')
|
||||
let g:tlib#file#absolute_filename_rx = '^\~\?[\/]' "{{{2
|
||||
endif
|
||||
|
||||
""" File related {{{1
|
||||
" For the following functions please see ../../test/tlib.vim for examples.
|
||||
|
||||
|
||||
" EXAMPLES: >
|
||||
" tlib#file#Split('foo/bar/filename.txt')
|
||||
" => ['foo', 'bar', 'filename.txt']
|
||||
function! tlib#file#Split(filename) "{{{3
|
||||
let prefix = matchstr(a:filename, '^\(\w\+:\)\?/\+')
|
||||
" TLogVAR prefix
|
||||
if !empty(prefix)
|
||||
let filename = a:filename[len(prefix) : -1]
|
||||
else
|
||||
let filename = a:filename
|
||||
endif
|
||||
let rv = split(filename, '[\/]')
|
||||
" let rv = split(filename, '[\/]', 1)
|
||||
if !empty(prefix)
|
||||
call insert(rv, prefix[0:-2])
|
||||
endif
|
||||
return rv
|
||||
endf
|
||||
|
||||
|
||||
" :display: tlib#file#Join(filename_parts, ?strip_slashes=1, ?maybe_absolute=0)
|
||||
" EXAMPLES: >
|
||||
" tlib#file#Join(['foo', 'bar', 'filename.txt'])
|
||||
" => 'foo/bar/filename.txt'
|
||||
function! tlib#file#Join(filename_parts, ...) "{{{3
|
||||
TVarArg ['strip_slashes', 1], 'maybe_absolute'
|
||||
" TLogVAR a:filename_parts, strip_slashes
|
||||
if maybe_absolute
|
||||
let filename_parts = []
|
||||
for part in a:filename_parts
|
||||
if part =~ g:tlib#file#absolute_filename_rx
|
||||
let filename_parts = []
|
||||
endif
|
||||
call add(filename_parts, part)
|
||||
endfor
|
||||
else
|
||||
let filename_parts = a:filename_parts
|
||||
endif
|
||||
if strip_slashes
|
||||
" let rx = tlib#rx#Escape(g:tlib#dir#sep) .'$'
|
||||
let rx = '[/\\]\+$'
|
||||
let parts = map(copy(filename_parts), 'substitute(v:val, rx, "", "")')
|
||||
" TLogVAR parts
|
||||
return join(parts, g:tlib#dir#sep)
|
||||
else
|
||||
return join(filename_parts, g:tlib#dir#sep)
|
||||
endif
|
||||
endf
|
||||
|
||||
|
||||
" EXAMPLES: >
|
||||
" tlib#file#Relative('foo/bar/filename.txt', 'foo')
|
||||
" => 'bar/filename.txt'
|
||||
function! tlib#file#Relative(filename, basedir) "{{{3
|
||||
" TLogVAR a:filename, a:basedir
|
||||
" TLogDBG getcwd()
|
||||
" TLogDBG expand('%:p')
|
||||
let b0 = tlib#file#Absolute(a:basedir)
|
||||
let b = tlib#file#Split(b0)
|
||||
" TLogVAR b
|
||||
let f0 = tlib#file#Absolute(a:filename)
|
||||
let fn = fnamemodify(f0, ':t')
|
||||
let fd = fnamemodify(f0, ':h')
|
||||
let f = tlib#file#Split(fd)
|
||||
" TLogVAR f0, fn, fd, f
|
||||
if f[0] != b[0]
|
||||
let rv = f0
|
||||
else
|
||||
while !empty(f) && !empty(b)
|
||||
if f[0] != b[0]
|
||||
break
|
||||
endif
|
||||
call remove(f, 0)
|
||||
call remove(b, 0)
|
||||
endwh
|
||||
" TLogVAR f, b
|
||||
let rv = tlib#file#Join(repeat(['..'], len(b)) + f + [fn])
|
||||
endif
|
||||
" TLogVAR rv
|
||||
return rv
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#file#Absolute(filename, ...) "{{{3
|
||||
if filereadable(a:filename)
|
||||
let filename = fnamemodify(a:filename, ':p')
|
||||
elseif a:filename =~ '^\(/\|[^\/]\+:\)'
|
||||
let filename = a:filename
|
||||
else
|
||||
let cwd = a:0 >= 1 ? a:1 : getcwd()
|
||||
let filename = tlib#file#Join([cwd, a:filename])
|
||||
endif
|
||||
let filename = substitute(filename, '\(^\|[\/]\)\zs\.[\/]', '', 'g')
|
||||
let filename = substitute(filename, '[\/]\zs[^\/]\+[\/]\.\.[\/]', '', 'g')
|
||||
return filename
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#file#Canonic(filename, ...) "{{{3
|
||||
TVarArg ['mode', '']
|
||||
if a:filename =~ '^\\\\'
|
||||
let mode = 'windows'
|
||||
elseif a:filename =~ '^\(file\|ftp\|http\)s\?:'
|
||||
let mode = 'url'
|
||||
elseif (empty(mode) && g:tlib#sys#windows)
|
||||
let mode = 'windows'
|
||||
endif
|
||||
let filename = a:filename
|
||||
if mode == 'windows'
|
||||
let filename = substitute(filename, '/', '\\', 'g')
|
||||
else
|
||||
let filename = substitute(filename, '\\', '/', 'g')
|
||||
endif
|
||||
return filename
|
||||
endf
|
||||
|
||||
|
||||
function! s:SetScrollBind(world) "{{{3
|
||||
let sb = get(a:world, 'scrollbind', &scrollbind)
|
||||
if sb != &scrollbind
|
||||
let &scrollbind = sb
|
||||
endif
|
||||
endf
|
||||
|
||||
|
||||
" :def: function! tlib#file#With(fcmd, bcmd, files, ?world={})
|
||||
function! tlib#file#With(fcmd, bcmd, files, ...) "{{{3
|
||||
" TLogVAR a:fcmd, a:bcmd, a:files
|
||||
exec tlib#arg#Let([['world', {}]])
|
||||
call tlib#autocmdgroup#Init()
|
||||
augroup TLibFileRead
|
||||
autocmd!
|
||||
augroup END
|
||||
for f in a:files
|
||||
let bn = bufnr('^'.f.'$')
|
||||
" TLogVAR f, bn
|
||||
let bufloaded = bufloaded(bn)
|
||||
let ok = 0
|
||||
let s:bufread = ""
|
||||
if bn != -1 && buflisted(bn)
|
||||
if !empty(a:bcmd)
|
||||
" TLogDBG a:bcmd .' '. bn
|
||||
exec a:bcmd .' '. bn
|
||||
let ok = 1
|
||||
call s:SetScrollBind(world)
|
||||
endif
|
||||
else
|
||||
if filereadable(f)
|
||||
if !empty(a:fcmd)
|
||||
" TLogDBG a:fcmd .' '. tlib#arg#Ex(f)
|
||||
exec 'autocmd TLibFileRead BufRead' escape(f, '\ ') 'let s:bufread=expand("<afile>:p")'
|
||||
try
|
||||
exec a:fcmd .' '. tlib#arg#Ex(f)
|
||||
finally
|
||||
exec 'autocmd! TLibFileRead BufRead'
|
||||
endtry
|
||||
let ok = 1
|
||||
call s:SetScrollBind(world)
|
||||
endif
|
||||
else
|
||||
echohl error
|
||||
echom 'File not readable: '. f
|
||||
echohl NONE
|
||||
endif
|
||||
endif
|
||||
" TLogVAR ok, bufloaded, &filetype
|
||||
if empty(s:bufread) && ok && !bufloaded && empty(&filetype)
|
||||
doautocmd BufRead
|
||||
endif
|
||||
endfor
|
||||
augroup! TLibFileRead
|
||||
unlet! s:bufread
|
||||
" TLogDBG "done"
|
||||
endf
|
||||
|
||||
|
||||
" Return 0 if the file isn't readable/doesn't exist.
|
||||
" Otherwise return 1.
|
||||
function! tlib#file#Edit(fileid) "{{{3
|
||||
if type(a:fileid) == 0
|
||||
let bn = a:fileid
|
||||
let filename = fnamemodify(bufname(bn), ':p')
|
||||
else
|
||||
let filename = fnamemodify(a:fileid, ':p')
|
||||
let bn = bufnr(filename)
|
||||
endif
|
||||
if filename == expand('%:p')
|
||||
return 1
|
||||
else
|
||||
" TLogVAR a:fileid, bn, filename, g:tlib#file#drop, filereadable(filename)
|
||||
if bn != -1 && buflisted(bn)
|
||||
if g:tlib#file#drop
|
||||
" echom "DBG" get(g:tlib#file#edit_cmds, 'drop', 'drop') fnameescape(filename)
|
||||
exec get(g:tlib#file#edit_cmds, 'drop', 'drop') fnameescape(filename)
|
||||
else
|
||||
" echom "DBG" get(g:tlib#file#edit_cmds, 'buffer', 'buffer') bn
|
||||
exec get(g:tlib#file#edit_cmds, 'buffer', 'buffer') bn
|
||||
endif
|
||||
return 1
|
||||
elseif filereadable(filename)
|
||||
try
|
||||
" let file = tlib#arg#Ex(filename)
|
||||
" " TLogVAR file
|
||||
" echom "DBG" get(g:tlib#file#edit_cmds, 'edit', 'edit') fnameescape(filename)
|
||||
exec get(g:tlib#file#edit_cmds, 'edit', 'edit') fnameescape(filename)
|
||||
catch /E325/
|
||||
" swap file exists, let the user handle it
|
||||
catch
|
||||
echohl error
|
||||
echom v:exception
|
||||
echohl NONE
|
||||
endtry
|
||||
return 1
|
||||
else
|
||||
echom "TLIB: File not readable: " . filename
|
||||
if filename != a:fileid
|
||||
echom "TLIB: original filename: " . a:fileid
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
return 0
|
||||
endf
|
||||
|
||||
|
||||
if v:version > 704 || (v:version == 704 && has('patch279'))
|
||||
|
||||
function! tlib#file#Glob(pattern) abort "{{{3
|
||||
return glob(a:pattern, 0, 1)
|
||||
endf
|
||||
|
||||
function! tlib#file#Globpath(path, pattern) abort "{{{3
|
||||
return globpath(a:path, a:pattern, 0, 1)
|
||||
endf
|
||||
|
||||
else
|
||||
|
||||
" :nodoc:
|
||||
function! tlib#file#Glob(pattern) abort "{{{3
|
||||
return split(glob(a:pattern), '\n')
|
||||
endf
|
||||
|
||||
" :nodoc:
|
||||
function! tlib#file#Globpath(path, pattern) abort "{{{3
|
||||
return split(globpath(a:path, a:pattern), '\n')
|
||||
endf
|
||||
|
||||
endif
|
||||
|
@ -1,14 +0,0 @@
|
||||
" @Author: Tom Link (mailto:micathom AT gmail com?subject=[vim])
|
||||
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
|
||||
" @Last Change: 2013-02-22.
|
||||
" @Revision: 3
|
||||
|
||||
|
||||
function! tlib#fixes#Winpos() "{{{3
|
||||
if has('gui_win32')
|
||||
return 'winpos '. getwinposx() .' '. getwinposy()
|
||||
else
|
||||
return ''
|
||||
endif
|
||||
endf
|
||||
|
@ -1,38 +0,0 @@
|
||||
" @Author: Tom Link (mailto:micathom AT gmail com?subject=[vim])
|
||||
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
|
||||
" @Last Change: 2013-10-16.
|
||||
" @Revision: 31
|
||||
|
||||
|
||||
function! tlib#grep#Do(cmd, rx, files) "{{{3
|
||||
" TLogVAR a:cmd, a:rx, a:files
|
||||
let files = join(map(copy(a:files), 'tlib#arg#Ex(v:val, "")'), ' ')
|
||||
let rx = '/'. escape(a:rx, '/') .'/j'
|
||||
" TLogVAR rx, files
|
||||
silent exec a:cmd rx files
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#grep#LocList(rx, files) "{{{3
|
||||
return tlib#grep#Do('noautocmd lvimgrep', a:rx, a:files)
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#grep#QuickFixList(rx, files) "{{{3
|
||||
return tlib#grep#Do('noautocmd vimgrep', a:rx, a:files)
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#grep#List(rx, files) "{{{3
|
||||
call setqflist([])
|
||||
call tlib#grep#Do('noautocmd vimgrepadd', a:rx, a:files)
|
||||
let qfl = getqflist()
|
||||
" TLogVAR qfl
|
||||
" try
|
||||
silent! colder
|
||||
" catch
|
||||
" call setqflist([], 'r')
|
||||
" endtry
|
||||
return qfl
|
||||
endf
|
||||
|
@ -1,145 +0,0 @@
|
||||
" @Author: Tom Link (mailto:micathom AT gmail com?subject=[vim])
|
||||
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
|
||||
" @Revision: 276
|
||||
|
||||
|
||||
if !exists('g:tlib#hash#use_crc32')
|
||||
let g:tlib#hash#use_crc32 = '' "{{{2
|
||||
endif
|
||||
|
||||
|
||||
if !exists('g:tlib#hash#use_adler32')
|
||||
let g:tlib#hash#use_adler32 = '' "{{{2
|
||||
endif
|
||||
|
||||
|
||||
function! tlib#hash#CRC32B(chars) "{{{3
|
||||
if !empty(g:tlib#hash#use_crc32)
|
||||
let use = g:tlib#hash#use_crc32
|
||||
elseif has('ruby')
|
||||
let use = 'ruby'
|
||||
else
|
||||
let use = 'vim'
|
||||
endif
|
||||
if exists('*tlib#hash#CRC32B_'. use)
|
||||
return tlib#hash#CRC32B_{use}(a:chars)
|
||||
else
|
||||
throw "Unknown version of tlib#hash#CRC32B: ". use
|
||||
endif
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#hash#CRC32B_ruby(chars) "{{{3
|
||||
if has('ruby')
|
||||
let rv = ''
|
||||
if !exists('s:loaded_ruby_zlib')
|
||||
ruby require 'zlib'
|
||||
let s:loaded_ruby_zlib = 1
|
||||
endif
|
||||
ruby VIM::command('let rv = "%08X"' % Zlib.crc32(VIM::evaluate("a:chars")))
|
||||
return rv
|
||||
else
|
||||
throw "tlib#hash#CRC32B_ruby not supported in this version of vim"
|
||||
endif
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#hash#CRC32B_vim(chars) "{{{3
|
||||
if !exists('s:crc_table')
|
||||
let cfile = tlib#persistent#Filename('tlib', 'crc_table', 1)
|
||||
let s:crc_table = tlib#persistent#Value(cfile, 'tlib#hash#CreateCrcTable', 0)
|
||||
endif
|
||||
let xFFFF_FFFF = repeat([1], 32)
|
||||
let crc = tlib#bitwise#XOR([0], xFFFF_FFFF, 'bits')
|
||||
for char in split(a:chars, '\zs')
|
||||
let octet = char2nr(char)
|
||||
let r1 = tlib#bitwise#ShiftRight(crc, 8)
|
||||
let i0 = tlib#bitwise#AND(crc, xFFFF_FFFF, 'bits')
|
||||
let i1 = tlib#bitwise#XOR(i0, octet, 'bits')
|
||||
let i2 = tlib#bitwise#Bits2Num(tlib#bitwise#AND(i1, 0xff, 'bits'))
|
||||
let r2 = s:crc_table[i2]
|
||||
let crc = tlib#bitwise#XOR(r1, r2, 'bits')
|
||||
endfor
|
||||
let crc = tlib#bitwise#XOR(crc, xFFFF_FFFF, 'bits')
|
||||
let rv = tlib#bitwise#Bits2Num(crc, 16)
|
||||
if len(rv) < 8
|
||||
let rv = repeat('0', 8 - len(rv)) . rv
|
||||
endif
|
||||
return rv
|
||||
endf
|
||||
|
||||
|
||||
" :nodoc:
|
||||
function! tlib#hash#CreateCrcTable() "{{{3
|
||||
let sum = 0.0
|
||||
for exponent in [0, 1, 2, 4, 5, 7, 8, 10, 11, 12, 16, 22, 23, 26, 32]
|
||||
let exp = tlib#bitwise#Bits2Num(repeat([0], 32 - exponent) + [1], 10.0)
|
||||
let sum += exp
|
||||
endfor
|
||||
let divisor = tlib#bitwise#Num2Bits(sum)
|
||||
let crc_table = []
|
||||
for octet in range(256)
|
||||
let remainder = tlib#bitwise#Num2Bits(octet)
|
||||
for i in range(8)
|
||||
if get(remainder, i) != 0
|
||||
let remainder = tlib#bitwise#XOR(remainder, tlib#bitwise#ShiftLeft(divisor, i), "bits")
|
||||
endif
|
||||
endfor
|
||||
let remainder = tlib#bitwise#ShiftRight(remainder, 8)
|
||||
call add(crc_table, remainder)
|
||||
endfor
|
||||
return crc_table
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#hash#Adler32(chars) "{{{3
|
||||
if !empty(g:tlib#hash#use_adler32)
|
||||
let use = g:tlib#hash#use_adler32
|
||||
elseif exists('*or')
|
||||
let use = 'vim'
|
||||
else
|
||||
let use = 'tlib'
|
||||
endif
|
||||
if exists('*tlib#hash#Adler32_'. use)
|
||||
return tlib#hash#Adler32_{use}(a:chars)
|
||||
else
|
||||
throw "Unknown version of tlib#hash#Adler32_: ". use
|
||||
endif
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#hash#Adler32_vim(chars) "{{{3
|
||||
if exists('*or')
|
||||
let mod_adler = 65521
|
||||
let a = 1
|
||||
let b = 0
|
||||
for index in range(len(a:chars))
|
||||
let c = char2nr(a:chars[index])
|
||||
let a = (a + c) % mod_adler
|
||||
let b = (b + a) % mod_adler
|
||||
endfor
|
||||
let bb = b * float2nr(pow(2, 16))
|
||||
let checksum = or(bb, a)
|
||||
" TLogVAR checksum, a, b, bb
|
||||
return printf("%08X", checksum)
|
||||
else
|
||||
throw "TLIB: Vim version doesn't support bitwise or()"
|
||||
endif
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#hash#Adler32_tlib(chars) "{{{3
|
||||
let mod_adler = 65521
|
||||
let a = 1
|
||||
let b = 0
|
||||
for index in range(len(a:chars))
|
||||
let c = char2nr(a:chars[index])
|
||||
let a = (a + c) % mod_adler
|
||||
let b = (b + a) % mod_adler
|
||||
endfor
|
||||
let bb = tlib#bitwise#ShiftLeft(tlib#bitwise#Num2Bits(b), 16)
|
||||
let checksum = tlib#bitwise#OR(bb, a, "bits")
|
||||
return printf('%08s', tlib#bitwise#Bits2Num(checksum, 16))
|
||||
endf
|
||||
|
||||
|
@ -1,25 +0,0 @@
|
||||
" @Author: Tom Link (micathom AT gmail com?subject=[vim])
|
||||
" @Website: http://www.vim.org/account/profile.php?user_id=4037
|
||||
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
|
||||
" @Revision: 11
|
||||
|
||||
|
||||
" :def: function! tlib#hook#Run(hook, ?dict={})
|
||||
" Execute dict[hook], w:{hook}, b:{hook}, or g:{hook} if existent.
|
||||
function! tlib#hook#Run(hook, ...) "{{{3
|
||||
TVarArg ['dict', {}]
|
||||
if has_key(dict, a:hook)
|
||||
let hook = dict[a:hook]
|
||||
else
|
||||
let hook = tlib#var#Get(a:hook, 'wbg')
|
||||
endif
|
||||
if empty(hook)
|
||||
return 0
|
||||
else
|
||||
let world = dict
|
||||
exec hook
|
||||
return 1
|
||||
endif
|
||||
endf
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,183 +0,0 @@
|
||||
" list.vim
|
||||
" @Author: Tom Link (micathom AT gmail com?subject=[vim])
|
||||
" @Website: http://www.vim.org/account/profile.php?user_id=4037
|
||||
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
|
||||
" @Created: 2007-06-30.
|
||||
" @Last Change: 2015-10-21.
|
||||
" @Revision: 61
|
||||
|
||||
|
||||
""" List related functions {{{1
|
||||
" For the following functions please see ../../test/tlib.vim for examples.
|
||||
|
||||
" :def: function! tlib#list#Inject(list, initial_value, funcref)
|
||||
" EXAMPLES: >
|
||||
" echo tlib#list#Inject([1,2,3], 0, function('Add')
|
||||
" => 6
|
||||
function! tlib#list#Inject(list, value, Function) "{{{3
|
||||
if empty(a:list)
|
||||
return a:value
|
||||
else
|
||||
let item = a:list[0]
|
||||
let rest = a:list[1:-1]
|
||||
let value = call(a:Function, [a:value, item])
|
||||
return tlib#list#Inject(rest, value, a:Function)
|
||||
endif
|
||||
endf
|
||||
|
||||
|
||||
" EXAMPLES: >
|
||||
" tlib#list#Compact([0,1,2,3,[], {}, ""])
|
||||
" => [1,2,3]
|
||||
function! tlib#list#Compact(list) "{{{3
|
||||
return filter(copy(a:list), '!empty(v:val)')
|
||||
endf
|
||||
|
||||
|
||||
" EXAMPLES: >
|
||||
" tlib#list#Flatten([0,[1,2,[3,""]]])
|
||||
" => [0,1,2,3,""]
|
||||
function! tlib#list#Flatten(list) "{{{3
|
||||
let acc = []
|
||||
for e in a:list
|
||||
if type(e) == 3
|
||||
let acc += tlib#list#Flatten(e)
|
||||
else
|
||||
call add(acc, e)
|
||||
endif
|
||||
unlet e
|
||||
endfor
|
||||
return acc
|
||||
endf
|
||||
|
||||
|
||||
" :def: function! tlib#list#FindAll(list, filter, ?process_expr="")
|
||||
" Basically the same as filter()
|
||||
"
|
||||
" EXAMPLES: >
|
||||
" tlib#list#FindAll([1,2,3], 'v:val >= 2')
|
||||
" => [2, 3]
|
||||
function! tlib#list#FindAll(list, filter, ...) "{{{3
|
||||
let rv = filter(copy(a:list), a:filter)
|
||||
if a:0 >= 1 && a:1 != ''
|
||||
let rv = map(rv, a:1)
|
||||
endif
|
||||
return rv
|
||||
endf
|
||||
|
||||
|
||||
" :def: function! tlib#list#Find(list, filter, ?default="", ?process_expr="")
|
||||
"
|
||||
" EXAMPLES: >
|
||||
" tlib#list#Find([1,2,3], 'v:val >= 2')
|
||||
" => 2
|
||||
function! tlib#list#Find(list, filter, ...) "{{{3
|
||||
let default = a:0 >= 1 ? a:1 : ''
|
||||
let expr = a:0 >= 2 ? a:2 : ''
|
||||
return get(tlib#list#FindAll(a:list, a:filter, expr), 0, default)
|
||||
endf
|
||||
|
||||
|
||||
" EXAMPLES: >
|
||||
" tlib#list#Any([1,2,3], 'v:val >= 2')
|
||||
" => 1
|
||||
function! tlib#list#Any(list, expr) "{{{3
|
||||
return !empty(tlib#list#FindAll(a:list, a:expr))
|
||||
endf
|
||||
|
||||
|
||||
" EXAMPLES: >
|
||||
" tlib#list#All([1,2,3], 'v:val >= 2')
|
||||
" => 0
|
||||
function! tlib#list#All(list, expr) "{{{3
|
||||
return len(tlib#list#FindAll(a:list, a:expr)) == len(a:list)
|
||||
endf
|
||||
|
||||
|
||||
" EXAMPLES: >
|
||||
" tlib#list#Remove([1,2,1,2], 2)
|
||||
" => [1,1,2]
|
||||
function! tlib#list#Remove(list, element) "{{{3
|
||||
let idx = index(a:list, a:element)
|
||||
if idx != -1
|
||||
call remove(a:list, idx)
|
||||
endif
|
||||
return a:list
|
||||
endf
|
||||
|
||||
|
||||
" EXAMPLES: >
|
||||
" tlib#list#RemoveAll([1,2,1,2], 2)
|
||||
" => [1,1]
|
||||
function! tlib#list#RemoveAll(list, element) "{{{3
|
||||
call filter(a:list, 'v:val != a:element')
|
||||
return a:list
|
||||
endf
|
||||
|
||||
|
||||
" :def: function! tlib#list#Zip(lists, ?default='')
|
||||
" EXAMPLES: >
|
||||
" tlib#list#Zip([[1,2,3], [4,5,6]])
|
||||
" => [[1,4], [2,5], [3,6]]
|
||||
function! tlib#list#Zip(lists, ...) "{{{3
|
||||
TVarArg 'default'
|
||||
let lists = copy(a:lists)
|
||||
let max = 0
|
||||
for l in lists
|
||||
let ll = len(l)
|
||||
if ll > max
|
||||
let max = ll
|
||||
endif
|
||||
endfor
|
||||
" TLogVAR default, max
|
||||
return map(range(0, max - 1), 's:GetNthElement(v:val, lists, default)')
|
||||
endf
|
||||
|
||||
function! s:GetNthElement(n, lists, default) "{{{3
|
||||
" TLogVAR a:n, a:lists, a:default
|
||||
return map(copy(a:lists), 'get(v:val, a:n, a:default)')
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#list#Uniq(list, ...) "{{{3
|
||||
" TLogVAR a:list
|
||||
TVarArg ['get_value', ''], ['remove_empty', 0]
|
||||
if remove_empty
|
||||
call filter(a:list, 'type(v:val) == 0 || !empty(v:val)')
|
||||
endif
|
||||
" CREDITS: Based on syntastic#util#unique(list) by scrooloose
|
||||
let seen = {}
|
||||
let uniques = []
|
||||
if empty(get_value)
|
||||
for e in a:list
|
||||
if !has_key(seen, e)
|
||||
let seen[e] = 1
|
||||
call add(uniques, e)
|
||||
endif
|
||||
unlet e
|
||||
endfor
|
||||
else
|
||||
for e in a:list
|
||||
let v = eval(printf(get_value, string(e)))
|
||||
if !has_key(seen, v)
|
||||
let seen[v] = 1
|
||||
call add(uniques, e)
|
||||
endif
|
||||
unlet e
|
||||
endfor
|
||||
endif
|
||||
return uniques
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#list#ToDictionary(list, default, ...) "{{{3
|
||||
TVarArg ['generator', '']
|
||||
let dict = {}
|
||||
for item in a:list
|
||||
if !empty(item)
|
||||
let dict[item] = empty(generator) ? a:default : call(generator, [item, a:default])
|
||||
endif
|
||||
endfor
|
||||
return dict
|
||||
endf
|
||||
|
@ -1,13 +0,0 @@
|
||||
" @Author: Tom Link (mailto:micathom AT gmail com?subject=[vim])
|
||||
" @Website: http://www.vim.org/account/profile.php?user_id=4037
|
||||
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
|
||||
" @Last Change: 2015-10-24
|
||||
" @Revision: 2
|
||||
|
||||
|
||||
function! tlib#loclist#Browse(...) abort "{{{3
|
||||
let list = getloclist(0)
|
||||
return call(function('tlib#qfl#QflList'), [list] + a:000)
|
||||
endf
|
||||
|
||||
|
@ -1,23 +0,0 @@
|
||||
" map.vim
|
||||
" @Author: Tom Link (mailto:micathom AT gmail com?subject=[vim])
|
||||
" @Website: http://www.vim.org/account/profile.php?user_id=4037
|
||||
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
|
||||
" @Created: 2009-08-23.
|
||||
" @Last Change: 2009-08-23.
|
||||
" @Revision: 0.0.4
|
||||
|
||||
let s:save_cpo = &cpo
|
||||
set cpo&vim
|
||||
|
||||
|
||||
" If |pumvisible()| is true, return "\<c-y>". Otherwise return a:key.
|
||||
" For use in maps like: >
|
||||
" imap <expr> <cr> tlib#map#PumAccept("\<cr>")
|
||||
function! tlib#map#PumAccept(key) "{{{3
|
||||
return pumvisible() ? "\<c-y>" : a:key
|
||||
endf
|
||||
|
||||
|
||||
|
||||
let &cpo = s:save_cpo
|
||||
unlet s:save_cpo
|
@ -1,34 +0,0 @@
|
||||
" normal.vim
|
||||
" @Author: Tom Link (mailto:micathom AT gmail com?subject=[vim])
|
||||
" @Website: http://www.vim.org/account/profile.php?user_id=4037
|
||||
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
|
||||
" @Created: 2008-10-06.
|
||||
" @Last Change: 2010-09-22.
|
||||
" @Revision: 28
|
||||
|
||||
let s:save_cpo = &cpo
|
||||
set cpo&vim
|
||||
|
||||
|
||||
" :display: tlib#normal#WithRegister(cmd, ?register='t', ?norm_cmd='norm!')
|
||||
" Execute a normal command while maintaining all registers.
|
||||
function! tlib#normal#WithRegister(cmd, ...) "{{{3
|
||||
TVarArg ['register', 't'], ['norm_cmd', 'norm!']
|
||||
let registers = {}
|
||||
for reg in split('123456789'. register, '\zs')
|
||||
exec 'let registers[reg] = @'. reg
|
||||
endfor
|
||||
exec 'let reg = @'. register
|
||||
try
|
||||
exec norm_cmd .' '. a:cmd
|
||||
exec 'return @'. register
|
||||
finally
|
||||
for [reg, value] in items(registers)
|
||||
exec 'let @'. reg .' = value'
|
||||
endfor
|
||||
endtry
|
||||
endf
|
||||
|
||||
|
||||
let &cpo = s:save_cpo
|
||||
unlet s:save_cpo
|
@ -1,105 +0,0 @@
|
||||
" notify.vim
|
||||
" @Author: Tom Link (mailto:micathom AT gmail com?subject=[vim])
|
||||
" @Website: http://www.vim.org/account/profile.php?user_id=4037
|
||||
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
|
||||
" @Created: 2008-09-19.
|
||||
" @Last Change: 2015-04-07.
|
||||
" @Revision: 0.3.19
|
||||
|
||||
let s:save_cpo = &cpo
|
||||
set cpo&vim
|
||||
|
||||
|
||||
" :display: tlib#notify#Echo(text, ?style='')
|
||||
" Print text in the echo area. Temporarily disable 'ruler' and 'showcmd'
|
||||
" in order to prevent |press-enter| messages.
|
||||
function! tlib#notify#Echo(text, ...)
|
||||
TVarArg 'style'
|
||||
let ruler = &ruler
|
||||
let showcmd = &showcmd
|
||||
let text = substitute(a:text, '\n', '|', 'g')
|
||||
try
|
||||
set noruler
|
||||
set noshowcmd
|
||||
if !empty(style)
|
||||
exec 'echohl' style
|
||||
endif
|
||||
echo strpart(text, 0, &columns - 1)
|
||||
finally
|
||||
if !empty(style)
|
||||
echohl None
|
||||
endif
|
||||
let &ruler = ruler
|
||||
let &showcmd = showcmd
|
||||
endtry
|
||||
endf
|
||||
|
||||
|
||||
" Contributed by Erik Falor:
|
||||
" If the line containing the message is too long, echoing it will cause
|
||||
" a 'Hit ENTER' prompt to appear. This function cleans up the line so
|
||||
" that does not happen.
|
||||
" The echoed line is too long if it is wider than the width of the
|
||||
" window, minus cmdline space taken up by the ruler and showcmd
|
||||
" features.
|
||||
function! tlib#notify#TrimMessage(message) "{{{3
|
||||
let filler = '...'
|
||||
|
||||
" If length of message with tabs converted into spaces + length of
|
||||
" line number + 2 (for the ': ' that follows the line number) is
|
||||
" greater than the width of the screen, truncate in the middle
|
||||
let to_fill = &columns
|
||||
" TLogVAR to_fill
|
||||
|
||||
" Account for space used by elements in the command-line to avoid
|
||||
" 'Hit ENTER' prompts.
|
||||
" If showcmd is on, it will take up 12 columns.
|
||||
" If the ruler is enabled, but not displayed in the statusline, it
|
||||
" will in its default form take 17 columns. If the user defines a
|
||||
" custom &rulerformat, they will need to specify how wide it is.
|
||||
if has('cmdline_info')
|
||||
if &showcmd
|
||||
let to_fill -= 12
|
||||
else
|
||||
let to_fill -= 1
|
||||
endif
|
||||
" TLogVAR &showcmd, to_fill
|
||||
|
||||
" TLogVAR &laststatus, &ruler, &rulerformat
|
||||
if &ruler
|
||||
if &laststatus == 0 || winnr('$') == 1
|
||||
if has('statusline')
|
||||
if &rulerformat == ''
|
||||
" default ruler is 17 chars wide
|
||||
let to_fill -= 17
|
||||
elseif exists('g:MP_rulerwidth')
|
||||
let to_fill -= g:MP_rulerwidth
|
||||
else
|
||||
" tml: fallback: guess length
|
||||
let to_fill -= strlen(&rulerformat)
|
||||
endif
|
||||
else
|
||||
endif
|
||||
endif
|
||||
else
|
||||
endif
|
||||
else
|
||||
let to_fill -= 1
|
||||
endif
|
||||
|
||||
" TLogVAR to_fill
|
||||
" TLogDBG strlen(a:message)
|
||||
if strlen(a:message) > to_fill
|
||||
let front = to_fill / 2 - 1
|
||||
let back = front
|
||||
if to_fill % 2 == 0 | let back -= 1 | endif
|
||||
return strpart(a:message, 0, front) . filler .
|
||||
\strpart(a:message, strlen(a:message) - back)
|
||||
else
|
||||
return a:message
|
||||
endif
|
||||
endfunction
|
||||
|
||||
|
||||
let &cpo = s:save_cpo
|
||||
unlet s:save_cpo
|
@ -1,30 +0,0 @@
|
||||
" @Author: Tom Link (mailto:micathom AT gmail com?subject=[vim])
|
||||
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
|
||||
" @Revision: 14
|
||||
|
||||
|
||||
function! tlib#number#ConvertBase(num, base, ...) "{{{3
|
||||
let rtype = a:0 >= 1 ? a:1 : 'string'
|
||||
" TLogVAR a:num, a:base, rtype
|
||||
let rv = []
|
||||
let num = 0.0 + a:num
|
||||
while floor(num) > 0.0
|
||||
let div = floor(num / a:base)
|
||||
let num1 = float2nr(num - a:base * div)
|
||||
if a:base <= 10
|
||||
call insert(rv, num1)
|
||||
elseif a:base == 16
|
||||
let char = "0123456789ABCDEF"[num1]
|
||||
call insert(rv, char)
|
||||
endif
|
||||
let num = num / a:base
|
||||
endwh
|
||||
" TLogVAR rv
|
||||
if rtype == 'list'
|
||||
return rv
|
||||
else
|
||||
return join(rv, '')
|
||||
endif
|
||||
endf
|
||||
|
||||
|
@ -1,97 +0,0 @@
|
||||
" paragraph.vim
|
||||
" @Author: Tom Link (mailto:micathom AT gmail com?subject=[vim])
|
||||
" @Website: http://www.vim.org/account/profile.php?user_id=4037
|
||||
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
|
||||
" @Created: 2009-10-26.
|
||||
" @Last Change: 2011-04-03.
|
||||
" @Revision: 62
|
||||
|
||||
let s:save_cpo = &cpo
|
||||
set cpo&vim
|
||||
|
||||
|
||||
" Return an object describing a |paragraph|.
|
||||
function! tlib#paragraph#GetMetric() "{{{3
|
||||
let sp = {'text_start': line("'{") + 1}
|
||||
if line("'}") == line("$")
|
||||
let sp.last = 1
|
||||
let sp.text_end = line("'}")
|
||||
if line("'{") == 1
|
||||
let sp.ws_start = 0
|
||||
let sp.ws_end = 0
|
||||
let sp.top = sp.text_start
|
||||
let sp.bottom = sp.text_end
|
||||
else
|
||||
let sp.ws_start = prevnonblank(line("'{")) + 1
|
||||
let sp.ws_end = line("'{")
|
||||
let sp.top = sp.ws_start
|
||||
let sp.bottom = sp.text_end
|
||||
endif
|
||||
else
|
||||
let sp.last = 0
|
||||
let sp.text_end = line("'}") - 1
|
||||
let sp.ws_start = line("'}")
|
||||
for i in range(line("'}"), line('$'))
|
||||
if getline(i) =~ '\w'
|
||||
let sp.ws_end = i - 1
|
||||
break
|
||||
elseif i == line("$")
|
||||
let sp.ws_end = i
|
||||
endif
|
||||
endfor
|
||||
let sp.top = sp.text_start
|
||||
let sp.bottom = sp.ws_end
|
||||
endif
|
||||
return sp
|
||||
endf
|
||||
|
||||
|
||||
" This function can be used with the tinymode plugin to move around
|
||||
" paragraphs.
|
||||
"
|
||||
" Example configuration: >
|
||||
"
|
||||
" call tinymode#EnterMap("para_move", "gp")
|
||||
" call tinymode#ModeMsg("para_move", "Move paragraph: j/k")
|
||||
" call tinymode#Map("para_move", "j", "silent call tlib#paragraph#Move('Down', '[N]')")
|
||||
" call tinymode#Map("para_move", "k", "silent call tlib#paragraph#Move('Up', '[N]')")
|
||||
" call tinymode#ModeArg("para_move", "owncount", 1)
|
||||
function! tlib#paragraph#Move(direction, count)
|
||||
" TLogVAR a:direction, a:count
|
||||
let mycount = empty(a:count) ? 1 : a:count
|
||||
for i in range(1, mycount)
|
||||
let para = tlib#paragraph#GetMetric()
|
||||
" TLogVAR para
|
||||
let text = getline(para.text_start, para.text_end)
|
||||
let ws = getline(para.ws_start, para.ws_end)
|
||||
" TLogVAR text, ws
|
||||
exec para.top .','. para.bottom .'delete'
|
||||
if a:direction == "Down"
|
||||
let other = tlib#paragraph#GetMetric()
|
||||
let target = other.bottom + 1
|
||||
if other.last
|
||||
let lines = ws + text
|
||||
let pos = target + len(ws)
|
||||
else
|
||||
let lines = text + ws
|
||||
let pos = target
|
||||
endif
|
||||
elseif a:direction == "Up"
|
||||
if !para.last
|
||||
norm! {
|
||||
endif
|
||||
let other = tlib#paragraph#GetMetric()
|
||||
let target = other.text_start
|
||||
let lines = text + ws
|
||||
let pos = target
|
||||
endif
|
||||
" TLogVAR other, target
|
||||
" TLogVAR lines
|
||||
call append(target - 1, lines)
|
||||
exec pos
|
||||
endfor
|
||||
endf
|
||||
|
||||
|
||||
let &cpo = s:save_cpo
|
||||
unlet s:save_cpo
|
@ -1,47 +0,0 @@
|
||||
" persistent.vim -- Persistent data
|
||||
" @Author: Tom Link (mailto:micathom AT gmail com?subject=[vim])
|
||||
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
|
||||
" @Created: 2012-05-11.
|
||||
" @Last Change: 2012-05-11.
|
||||
" @Revision: 12
|
||||
|
||||
" The directory for persistent data files. If empty, use
|
||||
" |tlib#dir#MyRuntime|.'/share'.
|
||||
TLet g:tlib_persistent = ''
|
||||
|
||||
|
||||
" :display: tlib#persistent#Dir(?mode = 'bg')
|
||||
" Return the full directory name for persistent data files.
|
||||
function! tlib#persistent#Dir() "{{{3
|
||||
TVarArg ['mode', 'bg']
|
||||
let dir = tlib#var#Get('tlib_persistent', mode)
|
||||
if empty(dir)
|
||||
let dir = tlib#file#Join([tlib#dir#MyRuntime(), 'share'])
|
||||
endif
|
||||
return dir
|
||||
endf
|
||||
|
||||
" :def: function! tlib#persistent#Filename(type, ?file=%, ?mkdir=0)
|
||||
function! tlib#persistent#Filename(type, ...) "{{{3
|
||||
" TLogDBG 'bufname='. bufname('.')
|
||||
let file = a:0 >= 1 ? a:1 : ''
|
||||
let mkdir = a:0 >= 2 ? a:2 : 0
|
||||
return tlib#cache#Filename(a:type, file, mkdir, tlib#persistent#Dir())
|
||||
endf
|
||||
|
||||
function! tlib#persistent#Get(...) "{{{3
|
||||
return call('tlib#cache#Get', a:000)
|
||||
endf
|
||||
|
||||
function! tlib#persistent#MTime(cfile) "{{{3
|
||||
return tlib#cache#MTime(a:cfile)
|
||||
endf
|
||||
|
||||
function! tlib#persistent#Value(...) "{{{3
|
||||
return call('tlib#cache#Value', a:000)
|
||||
endf
|
||||
|
||||
function! tlib#persistent#Save(cfile, dictionary) "{{{3
|
||||
call tlib#cache#Save(a:cfile, a:dictionary)
|
||||
endf
|
||||
|
@ -1,72 +0,0 @@
|
||||
" @Author: Tom Link (mailto:micathom AT gmail com?subject=[vim])
|
||||
" @Website: http://www.vim.org/account/profile.php?user_id=4037
|
||||
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
|
||||
" @Revision: 72
|
||||
|
||||
let s:statusline = []
|
||||
let s:laststatus = []
|
||||
let s:max = []
|
||||
let s:format = []
|
||||
let s:width = []
|
||||
let s:value = []
|
||||
let s:timestamp = -1
|
||||
|
||||
" EXAMPLE: >
|
||||
" call tlib#progressbar#Init(20)
|
||||
" try
|
||||
" for i in range(20)
|
||||
" call tlib#progressbar#Display(i)
|
||||
" call DoSomethingThatTakesSomeTime(i)
|
||||
" endfor
|
||||
" finally
|
||||
" call tlib#progressbar#Restore()
|
||||
" endtry
|
||||
function! tlib#progressbar#Init(max, ...) "{{{3
|
||||
TVarArg ['format', '%s'], ['width', 10]
|
||||
call insert(s:statusline, &statusline)
|
||||
call insert(s:laststatus, &laststatus)
|
||||
call insert(s:max, a:max)
|
||||
call insert(s:format, format)
|
||||
call insert(s:width, width)
|
||||
call insert(s:value, -1)
|
||||
let &laststatus = 2
|
||||
let s:timestamp = localtime()
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#progressbar#Display(value, ...) "{{{3
|
||||
TVarArg 'extra', ['always', 0]
|
||||
let ts = localtime()
|
||||
if !always && ts == s:timestamp
|
||||
return
|
||||
else
|
||||
let s:timestamp = ts
|
||||
endif
|
||||
let val = a:value * s:width[0] / s:max[0]
|
||||
if always || val != s:value[0]
|
||||
let s:value[0] = val
|
||||
let pbl = repeat('#', val)
|
||||
let pbr = repeat('.', s:width[0] - val)
|
||||
let txt = printf(s:format[0], '['.pbl.pbr.']') . extra
|
||||
let &l:statusline = txt
|
||||
" TLogDBG txt
|
||||
redrawstatus
|
||||
" redraw
|
||||
" call tlib#notify#Echo(txt)
|
||||
endif
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#progressbar#Restore() "{{{3
|
||||
let &l:statusline = remove(s:statusline, 0)
|
||||
let &laststatus = remove(s:laststatus, 0)
|
||||
redrawstatus
|
||||
" redraw
|
||||
" echo
|
||||
call remove(s:max, 0)
|
||||
call remove(s:format, 0)
|
||||
call remove(s:width, 0)
|
||||
call remove(s:value, 0)
|
||||
endf
|
||||
|
||||
|
@ -1,314 +0,0 @@
|
||||
" @Author: Tom Link (mailto:micathom AT gmail com?subject=[vim])
|
||||
" @Website: https://github.com/tomtom
|
||||
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
|
||||
" @Last Change: 2015-11-13
|
||||
" @Revision: 59
|
||||
|
||||
" :nodoc:
|
||||
TLet g:tlib#qfl#world = {
|
||||
\ 'type': 'mi',
|
||||
\ 'query': 'Select entry',
|
||||
\ 'pick_last_item': 0,
|
||||
\ 'resize_vertical': 0,
|
||||
\ 'resize': 20,
|
||||
\ 'scratch': '__TLibQFL__',
|
||||
\ 'tlib_UseInputListScratch': 'call tlib#qfl#InitListBuffer(world)',
|
||||
\ 'key_handlers': [
|
||||
\ {'key': 5, 'agent': 'tlib#qfl#AgentWithSelected', 'key_name': '<c-e>', 'help': 'Run a command on selected lines'},
|
||||
\ {'key': 16, 'agent': 'tlib#qfl#AgentPreviewQFE', 'key_name': '<c-p>', 'help': 'Preview'},
|
||||
\ {'key': 60, 'agent': 'tlib#qfl#AgentGotoQFE', 'key_name': '<', 'help': 'Jump (don''t close the list)'},
|
||||
\ {'key': 19, 'agent': 'tlib#qfl#AgentSplitBuffer', 'key_name': '<c-s>', 'help': 'Show in split buffer'},
|
||||
\ {'key': 20, 'agent': 'tlib#qfl#AgentTabBuffer', 'key_name': '<c-t>', 'help': 'Show in tab'},
|
||||
\ {'key': 22, 'agent': 'tlib#qfl#AgentVSplitBuffer', 'key_name': '<c-v>', 'help': 'Show in vsplit buffer'},
|
||||
\ {'key': 12, 'agent': 'tlib#qfl#AgentEditLine', 'key_name': '<c-l>', 'help': 'Edit selected line(s)'},
|
||||
\ {'key': "\<c-insert>", 'agent': 'tlib#qfl#SetFollowCursor', 'key_name': '<c-ins>', 'help': 'Toggle trace cursor'},
|
||||
\ ],
|
||||
\ 'return_agent': 'tlib#qfl#AgentEditQFE',
|
||||
\ }
|
||||
|
||||
|
||||
function! tlib#qfl#FormatQFLE(qfe) dict abort "{{{3
|
||||
let filename = tlib#qfl#QfeFilename(a:qfe)
|
||||
if get(self, 'qfl_short_filename', '')
|
||||
let filename = pathshorten(filename)
|
||||
endif
|
||||
return printf("%s|%d| %s", filename, a:qfe.lnum, get(a:qfe, "text"))
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#qfl#QfeFilename(qfe) abort "{{{3
|
||||
let filename = get(a:qfe, 'filename')
|
||||
if empty(filename)
|
||||
let filename = bufname(get(a:qfe, 'bufnr'))
|
||||
endif
|
||||
return filename
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#qfl#InitListBuffer(world) "{{{3
|
||||
let set_syntax = get(a:world, 'set_syntax', 'tlib#qfl#SetSyntax')
|
||||
call call(set_syntax, [], a:world)
|
||||
if has('balloon_eval')
|
||||
setlocal ballooneval balloonexpr=tlib#qfl#Balloon()
|
||||
endif
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#qfl#SetSyntax() dict abort "{{{3
|
||||
let syntax = get(self, 'qfl_list_syntax', '')
|
||||
let nextgroup = get(self, 'qfl_list_syntax_nextgroup', '')
|
||||
" TLogVAR syntax, nextgroup
|
||||
if !empty(syntax)
|
||||
exec printf('runtime syntax/%s.vim', syntax)
|
||||
endif
|
||||
syn match TTagedFilesFilename /\%(\f\+\| \)\+\ze|\d\+| / nextgroup=TTagedFilesLNum
|
||||
if !empty(nextgroup)
|
||||
exec 'syn match TTagedFilesLNum /|\d\+|\s\+/ nextgroup='. nextgroup
|
||||
else
|
||||
syn match TTagedFilesLNum /|\d\+|/
|
||||
endif
|
||||
hi def link TTagedFilesFilename Directory
|
||||
hi def link TTagedFilesLNum LineNr
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#qfl#Balloon() "{{{3
|
||||
let world = getbufvar(v:beval_bufnr, 'tlibDisplayListWorld')
|
||||
let current = max([1, world.offset]) + v:beval_lnum - 1
|
||||
if current > len(world.table)
|
||||
let current = len(world.table)
|
||||
endif
|
||||
let baseidx = world.GetBaseIdx0(current)
|
||||
" TLogVAR world.offset, v:beval_lnum, current, baseidx
|
||||
let item = world.data[baseidx]
|
||||
let bufnr = get(item, 'bufnr', 0)
|
||||
let bufname = get(item, 'filename', '')
|
||||
if bufnr == 0 && !empty(bufname)
|
||||
let bufnr = bufnr(bufname)
|
||||
endif
|
||||
if empty(bufname) && bufnr > 0
|
||||
let bufname = bufname(bufnr)
|
||||
endif
|
||||
" TLogVAR item
|
||||
if bufnr == 0
|
||||
return ''
|
||||
else
|
||||
let lines = [printf("%d#%d: %s", bufnr, item.lnum, bufname)]
|
||||
if has('balloon_multiline')
|
||||
let desc = {'nr': 'Error number', 'type': 'Error type', 'text': ''}
|
||||
for key in ['nr', 'type', 'text']
|
||||
if has_key(item, key) && !empty(item[key])
|
||||
let keydesc = get(desc, key, key)
|
||||
if empty(keydesc)
|
||||
let text = item[key]
|
||||
else
|
||||
let text = printf("%s: %s", key, item[key])
|
||||
endif
|
||||
call add(lines, text)
|
||||
endif
|
||||
endfor
|
||||
endif
|
||||
return join(lines, "\n")
|
||||
endif
|
||||
" v:beval_bufnr number of the buffer in which balloon is going to show
|
||||
" v:beval_winnr number of the window
|
||||
" v:beval_lnum line number
|
||||
" v:beval_col column number (byte index)
|
||||
" v:beval_text word under or after the mouse pointer
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#qfl#AgentEditQFE(world, selected, ...) "{{{3
|
||||
TVarArg ['cmd_edit', ''], ['cmd_buffer', '']
|
||||
" TVarArg ['cmd_edit', 'edit'], ['cmd_buffer', 'buffer']
|
||||
" TLogVAR a:selected
|
||||
if empty(a:selected)
|
||||
call a:world.RestoreOrigin()
|
||||
" call a:world.ResetSelected()
|
||||
else
|
||||
call a:world.RestoreOrigin()
|
||||
for idx in a:selected
|
||||
let idx -= 1
|
||||
" TLogVAR idx
|
||||
if idx >= 0
|
||||
" TLogVAR a:world.data
|
||||
" call tlog#Debug(string(map(copy(a:world.data), 'v:val.bufnr')))
|
||||
" TLogVAR idx, a:world.data[idx]
|
||||
let qfe = a:world.data[idx]
|
||||
" let back = a:world.SwitchWindow('win')
|
||||
" TLogVAR cmd_edit, cmd_buffer, qfe
|
||||
let fn = tlib#qfl#QfeFilename(qfe)
|
||||
" TLogVAR cmd_edit, cmd_buffer, fn
|
||||
if empty(cmd_edit) && empty(cmd_buffer)
|
||||
if tlib#file#Edit(fn)
|
||||
call tlib#buffer#ViewLine(qfe.lnum)
|
||||
endif
|
||||
else
|
||||
call tlib#file#With(cmd_edit, cmd_buffer, [fn], a:world)
|
||||
" TLogDBG bufname('%')
|
||||
" TLogVAR &filetype
|
||||
call tlib#buffer#ViewLine(qfe.lnum)
|
||||
" call a:world.SetOrigin()
|
||||
" exec back
|
||||
endif
|
||||
endif
|
||||
endfor
|
||||
endif
|
||||
return a:world
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#qfl#AgentPreviewQFE(world, selected) "{{{3
|
||||
" TLogVAR a:selected
|
||||
let back = a:world.SwitchWindow('win')
|
||||
call tlib#qfl#AgentEditQFE(a:world, a:selected[0:0])
|
||||
exec back
|
||||
redraw
|
||||
let a:world.state = 'redisplay'
|
||||
return a:world
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#qfl#AgentGotoQFE(world, selected) "{{{3
|
||||
if !empty(a:selected)
|
||||
if a:world.win_wnr != winnr()
|
||||
let world = tlib#agent#Suspend(a:world, a:selected)
|
||||
exec a:world.win_wnr .'wincmd w'
|
||||
endif
|
||||
call tlib#qfl#AgentEditQFE(a:world, a:selected[0:0])
|
||||
endif
|
||||
return a:world
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#qfl#AgentWithSelected(world, selected, ...) "{{{3
|
||||
let cmd = a:0 >= 1 ? a:1 : input('Ex command: ', '', 'command')
|
||||
let world = a:world
|
||||
if !empty(cmd)
|
||||
let world = tlib#qfl#RunCmdOnSelected(world, a:selected, cmd)
|
||||
else
|
||||
let world.state = 'redisplay'
|
||||
endif
|
||||
return world
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#qfl#RunCmdOnSelected(world, selected, cmd, ...) "{{{3
|
||||
let close_scratch = a:0 >= 1 ? a:1 : 1
|
||||
if close_scratch
|
||||
call a:world.CloseScratch()
|
||||
endif
|
||||
" TLogVAR a:cmd
|
||||
for entry in a:selected
|
||||
" TLogVAR entry, a:world.GetBaseItem(entry)
|
||||
call tlib#qfl#AgentEditQFE(a:world, [entry])
|
||||
" TLogDBG bufname('%')
|
||||
exec a:cmd
|
||||
" let item = a:world.data[a:world.GetBaseIdx(entry - 1)]
|
||||
" <+TODO+>
|
||||
let item = a:world.data[entry - 1]
|
||||
" TLogVAR entry, item, getline('.')
|
||||
if has_key(a:world, 'GetBufferLines')
|
||||
let lines = a:world.GetBufferLines('.', '.')
|
||||
else
|
||||
let lines = getline('.', '.')
|
||||
endif
|
||||
let item['text'] = tlib#string#Strip(lines[0])
|
||||
endfor
|
||||
if has_key(a:world, 'AfterRunCmd')
|
||||
if bufnr('%') == a:world.bufnr
|
||||
call a:world.AfterRunCmd()
|
||||
else
|
||||
" <+TODO+> Run in other buffer
|
||||
endif
|
||||
endif
|
||||
" call s:FormatBase(a:world)
|
||||
call a:world.RestoreOrigin()
|
||||
let a:world.state = 'reset'
|
||||
return a:world
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#qfl#AgentSplitBuffer(world, selected) "{{{3
|
||||
call a:world.CloseScratch()
|
||||
return tlib#qfl#AgentEditQFE(a:world, a:selected, 'split', 'sbuffer')
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#qfl#AgentTabBuffer(world, selected) "{{{3
|
||||
call a:world.CloseScratch()
|
||||
return tlib#qfl#AgentEditQFE(a:world, a:selected, 'tabedit', 'tab sbuffer')
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#qfl#AgentVSplitBuffer(world, selected) "{{{3
|
||||
call a:world.CloseScratch()
|
||||
return tlib#qfl#AgentEditQFE(a:world, a:selected, 'vertical split', 'vertical sbuffer')
|
||||
endf
|
||||
|
||||
|
||||
" function! tlib#qfl#AgentOpenBuffer(world, selected) "{{{3
|
||||
" endf
|
||||
|
||||
|
||||
function! tlib#qfl#AgentEditLine(world, selected) "{{{3
|
||||
call a:world.CloseScratch()
|
||||
let cmd = 'call tlib#qfl#EditLine(".")'
|
||||
return tlib#qfl#RunCmdOnSelected(a:world, a:selected, cmd)
|
||||
let a:world.state = 'reset'
|
||||
return a:world
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#qfl#EditLine(lnum) "{{{3
|
||||
call inputsave()
|
||||
let line = input('', getline(a:lnum))
|
||||
call inputrestore()
|
||||
if !empty(line)
|
||||
call setline(line(a:lnum), line)
|
||||
endif
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#qfl#SetFollowCursor(world, selected) "{{{3
|
||||
if empty(a:world.follow_cursor)
|
||||
let a:world.follow_cursor = 'tlib#qfl#AgentPreviewQFE'
|
||||
else
|
||||
let a:world.follow_cursor = ''
|
||||
endif
|
||||
let a:world.state = 'redisplay'
|
||||
return a:world
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#qfl#QflList(list, ...) abort "{{{3
|
||||
TVarArg ['world_dict', {}], ['anyway', 0], ['suspended', 0]
|
||||
Tlibtrace 'tlib', world_dict, anyway, suspended
|
||||
" TLogVAR a:list, world_dict, anyway, suspended
|
||||
if !anyway && empty(a:list)
|
||||
return
|
||||
endif
|
||||
let world = copy(g:tlib#qfl#world)
|
||||
if !empty(world_dict)
|
||||
let world = tlib#eval#Extend(world, world_dict)
|
||||
endif
|
||||
" TLogVAR world
|
||||
let world = tlib#World#New(world)
|
||||
" echom "DBG world" string(sort(keys(world)))
|
||||
let world.data = copy(a:list)
|
||||
if !has_key(world, 'format_data')
|
||||
let world.format_data = 'tlib#qfl#FormatQFLE'
|
||||
endif
|
||||
" TLogVAR world
|
||||
" TLogVAR world.data
|
||||
" call s:FormatBase(world)
|
||||
" TLogVAR world.base
|
||||
return tlib#input#ListW(world, suspended ? 'hibernate' : '')
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#qfl#Browse(...) abort "{{{3
|
||||
let list = getqflist()
|
||||
return call(function('tlib#qfl#QflList'), [list] + a:000)
|
||||
endf
|
||||
|
@ -1,60 +0,0 @@
|
||||
" @Author: Tom Link (micathom AT gmail com?subject=[vim])
|
||||
" @Website: http://www.vim.org/account/profile.php?user_id=4037
|
||||
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
|
||||
" @Revision: 113
|
||||
|
||||
|
||||
" :def: function! tlib#rx#Escape(text, ?magic='m')
|
||||
" magic can be one of: m, M, v, V
|
||||
" See :help 'magic'
|
||||
function! tlib#rx#Escape(text, ...) "{{{3
|
||||
TVarArg 'magic'
|
||||
if empty(magic)
|
||||
let magic = 'm'
|
||||
endif
|
||||
if magic =~# '^\\\?m$'
|
||||
return escape(a:text, '^$.*\[]~')
|
||||
elseif magic =~# '^\\\?M$'
|
||||
return escape(a:text, '^$\')
|
||||
elseif magic =~# '^\\\?V$'
|
||||
return escape(a:text, '\')
|
||||
elseif magic =~# '^\\\?v$'
|
||||
return substitute(a:text, '[^0-9a-zA-Z_]', '\\&', 'g')
|
||||
else
|
||||
echoerr 'tlib: Unsupported magic type'
|
||||
return a:text
|
||||
endif
|
||||
endf
|
||||
|
||||
" :def: function! tlib#rx#EscapeReplace(text, ?magic='m')
|
||||
" Escape return |sub-replace-special|.
|
||||
function! tlib#rx#EscapeReplace(text, ...) "{{{3
|
||||
TVarArg ['magic', 'm']
|
||||
if magic ==# 'm' || magic ==# 'v'
|
||||
return escape(a:text, '\&~')
|
||||
elseif magic ==# 'M' || magic ==# 'V'
|
||||
return escape(a:text, '\')
|
||||
else
|
||||
echoerr 'magic must be one of: m, v, M, V'
|
||||
endif
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#rx#Suffixes(...) "{{{3
|
||||
TVarArg ['magic', 'm']
|
||||
let sfx = split(&suffixes, ',')
|
||||
call map(sfx, 'tlib#rx#Escape(v:val, magic)')
|
||||
if magic ==# 'v'
|
||||
return '('. join(sfx, '|') .')$'
|
||||
elseif magic ==# 'V'
|
||||
return '\('. join(sfx, '\|') .'\)\$'
|
||||
else
|
||||
return '\('. join(sfx, '\|') .'\)$'
|
||||
endif
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#rx#LooksLikeRegexp(text) abort "{{{3
|
||||
return a:text =~ '[.?*+{}\[\]]'
|
||||
endf
|
||||
|
@ -1,136 +0,0 @@
|
||||
" @Author: Tom Link (micathom AT gmail com?subject=[vim])
|
||||
" @Website: http://www.vim.org/account/profile.php?user_id=4037
|
||||
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
|
||||
" @Revision: 255
|
||||
|
||||
|
||||
" Scratch window position. By default the list window is opened on the
|
||||
" bottom. Set this variable to 'topleft' or '' to change this behaviour.
|
||||
" See |tlib#input#List()|.
|
||||
TLet g:tlib_scratch_pos = 'botright'
|
||||
|
||||
" If you want the scratch buffer to be fully removed, you might want to
|
||||
" set this variable to 'wipe'.
|
||||
" See also https://github.com/tomtom/tlib_vim/pull/16
|
||||
TLet g:tlib#scratch#hidden = 'hide'
|
||||
|
||||
|
||||
" :def: function! tlib#scratch#UseScratch(?keyargs={})
|
||||
" Display a scratch buffer (a buffer with no file). See :TScratch for an
|
||||
" example.
|
||||
" Return the scratch buffer's number.
|
||||
" Values for keyargs:
|
||||
" scratch_split ... 1: split, 0: window, -1: tab
|
||||
function! tlib#scratch#UseScratch(...) "{{{3
|
||||
exec tlib#arg#Let([['keyargs', {}]])
|
||||
" TLogDBG string(keys(keyargs))
|
||||
let id = get(keyargs, 'scratch', '__Scratch__')
|
||||
" TLogVAR id, bufwinnr(id)
|
||||
" TLogVAR bufnr(id), bufname(id)
|
||||
" TLogVAR 1, winnr(), bufnr('%'), bufname("%")
|
||||
if bufwinnr(id) != -1
|
||||
" echom 'DBG noautocmd keepalt keepj' bufwinnr(id) 'wincmd w'
|
||||
exec 'noautocmd keepalt keepj' bufwinnr(id) 'wincmd w'
|
||||
" TLogVAR "reuse", bufnr("%"), bufname("%")
|
||||
else
|
||||
let winpos = ''
|
||||
let bn = bufnr(id)
|
||||
let wpos = get(keyargs, 'scratch_pos', g:tlib_scratch_pos)
|
||||
" TLogVAR keyargs.scratch_vertical
|
||||
if get(keyargs, 'scratch_vertical')
|
||||
let wpos .= ' vertical'
|
||||
let winpos = tlib#fixes#Winpos()
|
||||
endif
|
||||
" TLogVAR wpos
|
||||
let scratch_split = get(keyargs, 'scratch_split', 1)
|
||||
if bn != -1
|
||||
" TLogVAR bn
|
||||
let wn = bufwinnr(bn)
|
||||
if wn != -1
|
||||
" TLogVAR wn
|
||||
exec 'noautocmd keepalt keepj' (wn .'wincmd w')
|
||||
else
|
||||
if scratch_split == 1
|
||||
let cmd = wpos.' sbuffer!'
|
||||
elseif scratch_split == -1
|
||||
let cmd = wpos.' tab sbuffer!'
|
||||
else
|
||||
let cmd = 'buffer!'
|
||||
endif
|
||||
" TLogVAR cmd, bn
|
||||
silent exec 'noautocmd keepalt keepj' cmd bn
|
||||
endif
|
||||
else
|
||||
" TLogVAR id
|
||||
if scratch_split == 1
|
||||
let cmd = wpos.' split'
|
||||
elseif scratch_split == -1
|
||||
let cmd = wpos.' tab split'
|
||||
else
|
||||
let cmd = 'edit'
|
||||
endif
|
||||
" TLogVAR cmd, id
|
||||
silent exec 'noautocmd keepalt keepj' cmd escape(id, '%#\ ')
|
||||
" silent exec 'split '. id
|
||||
endif
|
||||
let ft = get(keyargs, 'scratch_filetype', '')
|
||||
" TLogVAR ft, winpos
|
||||
if !empty(winpos)
|
||||
exec winpos
|
||||
endif
|
||||
setlocal buftype=nofile
|
||||
let &l:bufhidden = get(keyargs, 'scratch_hidden', g:tlib#scratch#hidden)
|
||||
setlocal noswapfile
|
||||
setlocal nobuflisted
|
||||
setlocal foldmethod=manual
|
||||
setlocal foldcolumn=0
|
||||
setlocal nospell
|
||||
setlocal modifiable
|
||||
setlocal noreadonly
|
||||
" TLogVAR &ft, ft
|
||||
if !empty(ft)
|
||||
let &l:ft = ft
|
||||
endif
|
||||
endif
|
||||
let keyargs.scratch = bufnr('%')
|
||||
let keyargs.scratch_tabpagenr = tabpagenr()
|
||||
let keyargs.scratch_winnr = winnr()
|
||||
" TLogVAR 2, winnr(), bufnr('%'), bufname("%"), keyargs.scratch
|
||||
return keyargs.scratch
|
||||
endf
|
||||
|
||||
|
||||
" Close a scratch buffer as defined in keyargs (usually a World).
|
||||
" Return 1 if the scratch buffer is closed (or if it already was
|
||||
" closed).
|
||||
function! tlib#scratch#CloseScratch(keyargs, ...) "{{{3
|
||||
TVarArg ['reset_scratch', 1]
|
||||
let scratch = get(a:keyargs, 'scratch', '')
|
||||
" TLogVAR scratch, reset_scratch
|
||||
" TLogDBG string(tlib#win#List())
|
||||
if !empty(scratch) && winnr('$') > 1
|
||||
let wn = bufwinnr(scratch)
|
||||
" TLogVAR wn
|
||||
try
|
||||
if wn != -1
|
||||
" TLogDBG winnr()
|
||||
let wb = tlib#win#Set(wn)
|
||||
let winpos = tlib#fixes#Winpos()
|
||||
wincmd c
|
||||
if get(a:keyargs, 'scratch_vertical') && !empty(winpos)
|
||||
exec winpos
|
||||
endif
|
||||
" exec wb
|
||||
" redraw
|
||||
" TLogVAR winnr()
|
||||
endif
|
||||
return 1
|
||||
finally
|
||||
if reset_scratch
|
||||
let a:keyargs.scratch = ''
|
||||
endif
|
||||
endtry
|
||||
endif
|
||||
return 0
|
||||
endf
|
||||
|
@ -1,103 +0,0 @@
|
||||
" @Author: Tom Link (mailto:micathom AT gmail com?subject=[vim])
|
||||
" @Website: http://www.vim.org/account/profile.php?user_id=4037
|
||||
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
|
||||
" @Created: 2009-03-12.
|
||||
" @Last Change: 2011-03-10.
|
||||
" @Revision: 0.0.45
|
||||
|
||||
let s:save_cpo = &cpo
|
||||
set cpo&vim
|
||||
|
||||
|
||||
let s:base = 2327
|
||||
let s:register = {}
|
||||
|
||||
|
||||
" Clear all signs with name SIGN.
|
||||
function! tlib#signs#ClearAll(sign) "{{{3
|
||||
" TLog a:sign
|
||||
for bn in keys(s:register)
|
||||
let idxs = keys(s:register)
|
||||
call filter(idxs, 's:register[v:val].sign == a:sign')
|
||||
" TLogVAR bns
|
||||
for idx in idxs
|
||||
exec 'sign unplace '. idx .' buffer='. s:register[idx].bn
|
||||
call remove(s:register, idx)
|
||||
endfor
|
||||
endfor
|
||||
endf
|
||||
|
||||
|
||||
" Clear all signs with name SIGN in buffer BUFNR.
|
||||
function! tlib#signs#ClearBuffer(sign, bufnr) "{{{3
|
||||
for bn in keys(s:register)
|
||||
let idxs = keys(s:register)
|
||||
call filter(idxs, 's:register[v:val].sign == a:sign && s:register[v:val].bn == a:bufnr')
|
||||
" TLogVAR bns
|
||||
for idx in idxs
|
||||
exec 'sign unplace '. idx .' buffer='. s:register[idx].bn
|
||||
call remove(s:register, idx)
|
||||
endfor
|
||||
endfor
|
||||
endf
|
||||
|
||||
|
||||
" function! tlib#signs#Clear(sign, list) "{{{3
|
||||
" " TLogVAR a:sign
|
||||
" let done = []
|
||||
" for item in a:list
|
||||
" let bn = get(item, 'bufnr', -1)
|
||||
" if index(done, bn) == -1
|
||||
" let idxs = keys(s:register)
|
||||
" call filter(idxs, 's:register[v:val].sign == a:sign && s:register[v:val].bn == bn')
|
||||
" for idx in idxs
|
||||
" exec 'sign unplace '. idx .' buffer='. s:register[idx].bn
|
||||
" call remove(s:register, idx)
|
||||
" endfor
|
||||
" call add(done, bn)
|
||||
" endif
|
||||
" endfor
|
||||
" endf
|
||||
|
||||
|
||||
" Add signs for all locations in LIST. LIST must adhere with the
|
||||
" quickfix list format (see |getqflist()|; only the fields lnum and
|
||||
" bufnr are required).
|
||||
"
|
||||
" list:: a quickfix or location list
|
||||
" sign:: a sign defined with |:sign-define|
|
||||
function! tlib#signs#Mark(sign, list) "{{{3
|
||||
" TLogVAR a:sign
|
||||
for item in a:list
|
||||
let idx = s:SignId(item)
|
||||
if idx >= 0
|
||||
let lnum = get(item, 'lnum', 0)
|
||||
if lnum > 0
|
||||
let bn = get(item, 'bufnr')
|
||||
exec ':sign place '. idx .' line='. lnum .' name='. a:sign .' buffer='. bn
|
||||
let s:register[idx] = {'sign': a:sign, 'bn': bn}
|
||||
endif
|
||||
endif
|
||||
endfor
|
||||
endf
|
||||
|
||||
|
||||
function! s:SignId(item) "{{{3
|
||||
" TLogVAR a:item
|
||||
" let bn = bufnr('%')
|
||||
let bn = get(a:item, 'bufnr', -1)
|
||||
if bn == -1
|
||||
return -1
|
||||
else
|
||||
let idx = s:base + bn * 500
|
||||
while has_key(s:register, idx)
|
||||
let idx += 1
|
||||
endwh
|
||||
return idx
|
||||
endif
|
||||
endf
|
||||
|
||||
|
||||
|
||||
let &cpo = s:save_cpo
|
||||
unlet s:save_cpo
|
@ -1,158 +0,0 @@
|
||||
" @Author: Tom Link (micathom AT gmail com?subject=[vim])
|
||||
" @Website: http://www.vim.org/account/profile.php?user_id=4037
|
||||
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
|
||||
" @Revision: 121
|
||||
|
||||
|
||||
" :def: function! tlib#string#RemoveBackslashes(text, ?chars=' ')
|
||||
" Remove backslashes from text (but only in front of the characters in
|
||||
" chars).
|
||||
function! tlib#string#RemoveBackslashes(text, ...) "{{{3
|
||||
exec tlib#arg#Get(1, 'chars', ' ')
|
||||
" TLogVAR chars
|
||||
let rv = substitute(a:text, '\\\(['. chars .']\)', '\1', 'g')
|
||||
return rv
|
||||
endf
|
||||
|
||||
|
||||
" :display: tlib#string#Chomp(string, ?max=0)
|
||||
function! tlib#string#Chomp(string, ...) "{{{3
|
||||
let quant = a:0 >= 1 ? '\{,'. a:1 .'}' : '\+'
|
||||
return substitute(a:string, '[[:cntrl:][:space:]]'. quant .'$', '', '')
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#string#Format(template, dict) "{{{3
|
||||
let parts = split(a:template, '\ze%\({.\{-}}\|.\)')
|
||||
let out = []
|
||||
for part in parts
|
||||
let ml = matchlist(part, '^%\({\(.\{-}\)}\|\(.\)\)\(.*\)$')
|
||||
if empty(ml)
|
||||
let rest = part
|
||||
else
|
||||
let var = empty(ml[2]) ? ml[3] : ml[2]
|
||||
let rest = ml[4]
|
||||
if has_key(a:dict, var)
|
||||
call add(out, a:dict[var])
|
||||
elseif var == '%%'
|
||||
call add(out, '%')
|
||||
else
|
||||
call add(out, ml[1])
|
||||
endif
|
||||
endif
|
||||
call add(out, rest)
|
||||
endfor
|
||||
return join(out, '')
|
||||
endf
|
||||
|
||||
|
||||
" This function deviates from |printf()| in certain ways.
|
||||
" Additional items:
|
||||
" %{rx} ... insert escaped regexp
|
||||
" %{fuzzyrx} ... insert typo-tolerant regexp
|
||||
function! tlib#string#Printf1(format, string) "{{{3
|
||||
let s = split(a:format, '%.\zs')
|
||||
" TLogVAR s
|
||||
return join(map(s, 's:PrintFormat(v:val, a:string)'), '')
|
||||
endf
|
||||
|
||||
function! s:PrintFormat(format, string) "{{{3
|
||||
let cut = match(a:format, '%\({.\{-}}\|.\)$')
|
||||
if cut == -1
|
||||
return a:format
|
||||
else
|
||||
let head = cut > 0 ? a:format[0 : cut - 1] : ''
|
||||
let tail = a:format[cut : -1]
|
||||
" TLogVAR head, tail
|
||||
if tail == '%{fuzzyrx}'
|
||||
let frx = []
|
||||
for i in range(len(a:string))
|
||||
if i > 0
|
||||
let pb = i - 1
|
||||
else
|
||||
let pb = 0
|
||||
endif
|
||||
let slice = tlib#rx#Escape(a:string[pb : i + 1])
|
||||
call add(frx, '['. slice .']')
|
||||
call add(frx, '.\?')
|
||||
endfor
|
||||
let tail = join(frx, '')
|
||||
elseif tail == '%{rx}'
|
||||
let tail = tlib#rx#Escape(a:string)
|
||||
elseif tail == '%%'
|
||||
let tail = '%'
|
||||
elseif tail == '%s'
|
||||
let tail = a:string
|
||||
endif
|
||||
" TLogVAR tail
|
||||
return head . tail
|
||||
endif
|
||||
endf
|
||||
" function! tlib#string#Printf1(format, string) "{{{3
|
||||
" let n = len(split(a:format, '%\@<!%s', 1)) - 1
|
||||
" let f = a:format
|
||||
" if f =~ '%\@<!%{fuzzyrx}'
|
||||
" let frx = []
|
||||
" for i in range(len(a:string))
|
||||
" if i > 0
|
||||
" let pb = i - 1
|
||||
" else
|
||||
" let pb = 0
|
||||
" endif
|
||||
" let slice = tlib#rx#Escape(a:string[pb : i + 1])
|
||||
" call add(frx, '['. slice .']')
|
||||
" call add(frx, '.\?')
|
||||
" endfor
|
||||
" let f = s:RewriteFormatString(f, '%{fuzzyrx}', join(frx, ''))
|
||||
" endif
|
||||
" if f =~ '%\@<!%{rx}'
|
||||
" let f = s:RewriteFormatString(f, '%{rx}', tlib#rx#Escape(a:string))
|
||||
" endif
|
||||
" if n == 0
|
||||
" return substitute(f, '%%', '%', 'g')
|
||||
" else
|
||||
" let a = repeat([a:string], n)
|
||||
" return call('printf', insert(a, f))
|
||||
" endif
|
||||
" endf
|
||||
|
||||
|
||||
function! s:RewriteFormatString(format, pattern, string) "{{{3
|
||||
let string = substitute(a:string, '%', '%%', 'g')
|
||||
return substitute(a:format, tlib#rx#Escape(a:pattern), escape(string, '\'), 'g')
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#string#TrimLeft(string) "{{{3
|
||||
return substitute(a:string, '^[[:space:][:cntrl:]]\+', '', '')
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#string#TrimRight(string) "{{{3
|
||||
return substitute(a:string, '[[:space:][:cntrl:]]\+$', '', '')
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#string#Strip(string) "{{{3
|
||||
return tlib#string#TrimRight(tlib#string#TrimLeft(a:string))
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#string#Count(string, rx) "{{{3
|
||||
let s:count = 0
|
||||
call substitute(a:string, a:rx, '\=s:CountHelper()', 'g')
|
||||
return s:count
|
||||
endf
|
||||
|
||||
function! s:CountHelper() "{{{3
|
||||
let s:count += 1
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#string#SplitCommaList(text, ...) abort "{{{3
|
||||
let sep = a:0 >= 1 ? a:1 : ',\s*'
|
||||
let parts = split(a:text, '\\\@<!\zs'. sep)
|
||||
let parts = map(parts, 'substitute(v:val, ''\\\(.\)'', ''\1'', ''g'')')
|
||||
return parts
|
||||
endf
|
||||
|
@ -1,38 +0,0 @@
|
||||
" @Author: Tom Link (mailto:micathom AT gmail com?subject=[vim])
|
||||
" @Website: http://www.vim.org/account/profile.php?user_id=4037
|
||||
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
|
||||
" @Revision: 13
|
||||
|
||||
|
||||
function! tlib#syntax#Collect() "{{{3
|
||||
let acc = {}
|
||||
let syn = ''
|
||||
for line in tlib#cmd#OutputAsList('syntax')
|
||||
if line =~ '^---'
|
||||
continue
|
||||
elseif line =~ '^\w'
|
||||
let ml = matchlist(line, '^\(\w\+\)\s\+\(xxx\s\+\(.*\)\|\(cluster.*\)\)$')
|
||||
if empty(ml)
|
||||
" echoerr 'Internal error: '. string(line)
|
||||
else
|
||||
let [m_0, syn, m_1, m_def1, m_def2; m_rest] = ml
|
||||
let acc[syn] = [empty(m_def1) ? m_def2 : m_def1]
|
||||
endif
|
||||
else
|
||||
call add(acc[syn], matchstr(line, '^\s\+\zs.*$'))
|
||||
endif
|
||||
endfor
|
||||
return acc
|
||||
endf
|
||||
|
||||
|
||||
" :def: function! tlib#syntax#Names(?rx='')
|
||||
function! tlib#syntax#Names(...) "{{{3
|
||||
TVarArg 'rx'
|
||||
let names = keys(tlib#syntax#Collect())
|
||||
if !empty(rx)
|
||||
call filter(names, 'v:val =~ rx')
|
||||
endif
|
||||
return names
|
||||
endf
|
||||
|
@ -1,211 +0,0 @@
|
||||
" @Author: Tom Link (mailto:micathom AT gmail com?subject=[vim])
|
||||
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
|
||||
" @Last Change: 2015-11-07.
|
||||
" @Revision: 51
|
||||
|
||||
|
||||
if !exists('g:tlib#sys#special_protocols')
|
||||
" A list of |regexp|s matching protocol names that should be handled
|
||||
" by |g:tlib#sys#system_browser|.
|
||||
" CAVEAT: Must be a |\V| |regexp|.
|
||||
let g:tlib#sys#special_protocols = ['https\?', 'nntp', 'mailto'] "{{{2
|
||||
endif
|
||||
|
||||
|
||||
if !exists('g:tlib#sys#special_suffixes')
|
||||
" A list of |regexp|s matching suffixes that should be handled by
|
||||
" |g:tlib#sys#system_browser|.
|
||||
" CAVEAT: Must be a |\V| |regexp|.
|
||||
let g:tlib#sys#special_suffixes = ['xlsx\?', 'docx\?', 'pptx\?', 'accdb', 'mdb', 'sqlite', 'pdf', 'jpg', 'png', 'gif'] "{{{2
|
||||
endif
|
||||
|
||||
|
||||
if !exists('g:tlib#sys#system_rx')
|
||||
" Open links matching this |regexp| with |g:tlib#sys#system_browser|.
|
||||
" CAVEAT: Must be a |\V| |regexp|.
|
||||
let g:tlib#sys#system_rx = printf('\V\%(\^\%(%s\):\|.\%(%s\)\)', join(g:tlib#sys#special_protocols, '\|'), join(g:tlib#sys#special_suffixes, '\|')) "{{{2
|
||||
endif
|
||||
|
||||
|
||||
if !exists("g:tlib#sys#system_browser")
|
||||
if exists('g:netrw_browsex_viewer')
|
||||
" Open files in the system browser.
|
||||
" :read: let g:tlib#sys#system_browser = ... "{{{2
|
||||
let g:tlib#sys#system_browser = "exec 'silent !'. g:netrw_browsex_viewer shellescape('%s')"
|
||||
elseif has("win32") || has("win16") || has("win64")
|
||||
" let g:tlib#sys#system_browser = "exec 'silent ! start \"\"' shellescape('%s')"
|
||||
let g:tlib#sys#system_browser = "exec 'silent ! RunDll32.EXE URL.DLL,FileProtocolHandler' shellescape('%s')"
|
||||
elseif has("mac")
|
||||
let g:tlib#sys#system_browser = "exec 'silent !open' shellescape('%s')"
|
||||
elseif exists('$XDG_CURRENT_DESKTOP') && !empty($XDG_CURRENT_DESKTOP)
|
||||
let g:tlib#sys#system_browser = "exec 'silent !xdg-open' shellescape('%s') '&'"
|
||||
elseif $GNOME_DESKTOP_SESSION_ID != "" || $DESKTOP_SESSION == 'gnome'
|
||||
let g:tlib#sys#system_browser = "exec 'silent !gnome-open' shellescape('%s')"
|
||||
elseif exists("$KDEDIR") && !empty($KDEDIR)
|
||||
let g:tlib#sys#system_browser = "exec 'silent !kfmclient exec' shellescape('%s')"
|
||||
else
|
||||
let g:tlib#sys#system_browser = ''
|
||||
endif
|
||||
endif
|
||||
|
||||
|
||||
if !exists('g:tlib#sys#windows')
|
||||
let g:tlib#sys#windows = &shell !~ 'sh' && (has('win16') || has('win32') || has('win64')) "{{{2
|
||||
endif
|
||||
|
||||
|
||||
if !exists('g:tlib#sys#null')
|
||||
let g:tlib#sys#null = g:tlib#sys#windows ? 'NUL' : (filereadable('/dev/null') ? '/dev/null' : '') "{{{2
|
||||
endif
|
||||
|
||||
|
||||
let s:cygwin = {}
|
||||
|
||||
function! tlib#sys#IsCygwinBin(cmd) "{{{3
|
||||
" TLogVAR a:cmd
|
||||
if !g:tlib#sys#windows
|
||||
return 0
|
||||
elseif has_key(s:cygwin, a:cmd)
|
||||
let rv = s:cygwin[a:cmd]
|
||||
else
|
||||
if !tlib#sys#IsExecutable('cygpath', 1) || !tlib#sys#IsExecutable('which', 1)
|
||||
let rv = 0
|
||||
else
|
||||
let which = substitute(system('which '. shellescape(a:cmd)), '\n$', '', '')
|
||||
" echom "DBG which:" which
|
||||
if which =~ '^/'
|
||||
let filename = system('cygpath -ma '. shellescape(which))
|
||||
" echom "DBG filename:" filename
|
||||
let rv = filename =~ g:tlib#sys#cygwin_path_rx
|
||||
else
|
||||
let rv = 0
|
||||
endif
|
||||
endif
|
||||
let s:cygwin[a:cmd] = rv
|
||||
endif
|
||||
" TLogVAR rv
|
||||
return rv
|
||||
endf
|
||||
|
||||
|
||||
let s:executables = {}
|
||||
|
||||
function! tlib#sys#IsExecutable(cmd, ...) "{{{3
|
||||
" TLogVAR a:cmd
|
||||
" echom "DBG has_key(s:executables, a:cmd)" has_key(s:executables, a:cmd)
|
||||
if !has_key(s:executables, a:cmd)
|
||||
let executable = executable(a:cmd)
|
||||
" TLogVAR 1, executable
|
||||
let ignore_cyg = a:0 >= 1 ? a:1 : !g:tlib#sys#windows
|
||||
if !executable && !ignore_cyg
|
||||
let executable = tlib#sys#IsCygwinBin(a:cmd)
|
||||
" TLogVAR 2, executable
|
||||
endif
|
||||
let s:executables[a:cmd] = executable
|
||||
endif
|
||||
" echom "DBG s:executables[a:cmd]" s:executables[a:cmd]
|
||||
return s:executables[a:cmd]
|
||||
endf
|
||||
|
||||
|
||||
if !exists('g:tlib#sys#check_cygpath')
|
||||
" If true, check whether we have to convert a path via cyppath --
|
||||
" see |tlib#sys#MaybeUseCygpath|
|
||||
let g:tlib#sys#check_cygpath = g:tlib#sys#windows && tlib#sys#IsExecutable('cygpath', 1) "{{{2
|
||||
endif
|
||||
|
||||
|
||||
if !exists('g:tlib#sys#cygwin_path_rx')
|
||||
" If a full windows filename (with slashes instead of backslashes)
|
||||
" matches this |regexp|, it is assumed to be a cygwin executable.
|
||||
let g:tlib#sys#cygwin_path_rx = '/cygwin/' "{{{2
|
||||
endif
|
||||
|
||||
|
||||
if !exists('g:tlib#sys#cygwin_expr')
|
||||
" For cygwin binaries, convert command calls using this vim
|
||||
" expression.
|
||||
let g:tlib#sys#cygwin_expr = '"bash -c ''". escape(%s, "''\\") ."''"' "{{{2
|
||||
endif
|
||||
|
||||
|
||||
function! tlib#sys#GetCmd(cmd) "{{{3
|
||||
if !empty(g:tlib#sys#cygwin_expr) && tlib#sys#IsCygwinBin(matchstr(a:cmd, '^\S\+'))
|
||||
let cmd = eval(printf(g:tlib#sys#cygwin_expr, string(a:cmd)))
|
||||
" TLogVAR cmd
|
||||
return cmd
|
||||
else
|
||||
return a:cmd
|
||||
endif
|
||||
endf
|
||||
|
||||
|
||||
" If cmd seems to be a cygwin executable, use cygpath to convert
|
||||
" filenames. This assumes that cygwin's which command returns full
|
||||
" filenames for non-cygwin executables.
|
||||
function! tlib#sys#MaybeUseCygpath(cmd) "{{{3
|
||||
" echom "DBG" a:cmd
|
||||
if g:tlib#sys#check_cygpath && tlib#sys#IsCygwinBin(a:cmd)
|
||||
return 'cygpath -u "%s"'
|
||||
endif
|
||||
return ''
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#sys#ConvertPath(converter, filename) "{{{3
|
||||
return tlib#string#Chomp(system(printf(a:converter, shellescape(a:filename))))
|
||||
endf
|
||||
|
||||
|
||||
let s:native_filenames = {}
|
||||
|
||||
function! tlib#sys#FileArgs(cmd, files) "{{{3
|
||||
let cygpath = tlib#sys#MaybeUseCygpath(a:cmd)
|
||||
" TLogVAR cygpath
|
||||
if empty(cygpath)
|
||||
return a:files
|
||||
else
|
||||
let files = map(copy(a:files), 'has_key(s:native_filenames, v:val) ? s:native_filenames[v:val] : tlib#sys#CygPath(v:val)')
|
||||
return files
|
||||
endif
|
||||
endf
|
||||
|
||||
|
||||
" Check whether filename matches |g:tlib#sys#system_rx|, i.e. whether it
|
||||
" is a special file that should not be opened in vim.
|
||||
function! tlib#sys#IsSpecial(filename) abort "{{{3
|
||||
return a:filename =~ g:tlib#sys#system_rx
|
||||
endf
|
||||
|
||||
|
||||
" Open filename with the default OS application (see
|
||||
" |g:tlib#sys#system_browser|), if |tlib#sys#IsSpecial()| return 1.
|
||||
" Returns 1 if successful or 0 otherwise.
|
||||
function! tlib#sys#Open(filename) abort "{{{3
|
||||
Tlibtrace 'tlib', a:filename
|
||||
if !empty(g:tlib#sys#system_browser) && tlib#sys#IsSpecial(a:filename)
|
||||
try
|
||||
let cmd = printf(g:tlib#sys#system_browser, escape(a:filename, ' %#!'))
|
||||
Tlibtrace 'tlib', cmd
|
||||
exec cmd
|
||||
return 1
|
||||
catch
|
||||
echohl ErrorMsg
|
||||
echom v:exception
|
||||
echohl NONE
|
||||
endtry
|
||||
endif
|
||||
return 0
|
||||
endf
|
||||
|
||||
|
||||
" :def: function! tlib#sys#SystemInDir(dir, expr, ?input='')
|
||||
function! tlib#sys#SystemInDir(dir, ...) abort "{{{3
|
||||
call tlib#dir#CD(a:dir)
|
||||
try
|
||||
return call(function('system'), a:000)
|
||||
finally
|
||||
cd! -
|
||||
endtry
|
||||
endf
|
||||
|
@ -1,49 +0,0 @@
|
||||
" @Author: Tom Link (micathom AT gmail com?subject=[vim])
|
||||
" @Website: http://www.vim.org/account/profile.php?user_id=4037
|
||||
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
|
||||
" @Revision: 31
|
||||
|
||||
|
||||
" Return a dictionary of bufnumbers => [[tabpage, winnr] ...]
|
||||
function! tlib#tab#BufMap() "{{{3
|
||||
let acc = {}
|
||||
for t in range(tabpagenr('$'))
|
||||
let bb = tabpagebuflist(t + 1)
|
||||
for b in range(len(bb))
|
||||
let bn = bb[b]
|
||||
let bd = [t + 1, b + 1]
|
||||
if has_key(acc, bn)
|
||||
call add(acc[bn], bd)
|
||||
else
|
||||
let acc[bn] = [bd]
|
||||
endif
|
||||
endfor
|
||||
endfor
|
||||
return acc
|
||||
endf
|
||||
|
||||
|
||||
" Find a buffer's window at some tab page.
|
||||
function! tlib#tab#TabWinNr(buffer) "{{{3
|
||||
let bn = bufnr(a:buffer)
|
||||
let bt = tlib#tab#BufMap()
|
||||
let tn = tabpagenr()
|
||||
let wn = winnr()
|
||||
let bc = get(bt, bn)
|
||||
if !empty(bc)
|
||||
for [t, w] in bc
|
||||
if t == tn
|
||||
return [t, w]
|
||||
endif
|
||||
endfor
|
||||
return bc[0]
|
||||
endif
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#tab#Set(tabnr) "{{{3
|
||||
if a:tabnr > 0
|
||||
exec a:tabnr .'tabnext'
|
||||
endif
|
||||
endf
|
||||
|
@ -1,132 +0,0 @@
|
||||
" @Author: Tom Link (mailto:micathom AT gmail com?subject=[vim])
|
||||
" @Website: http://www.vim.org/account/profile.php?user_id=4037
|
||||
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
|
||||
" @Revision: 59
|
||||
|
||||
|
||||
" Extra tags for |tlib#tag#Retrieve()| (see there). Can also be buffer-local.
|
||||
TLet g:tlib_tags_extra = ''
|
||||
|
||||
" Filter the tag description through |substitute()| for these filetypes.
|
||||
" This applies only if the tag cmd field (see |taglist()|) is used.
|
||||
" :nodefault:
|
||||
TLet g:tlib_tag_substitute = {
|
||||
\ 'java': [['\s*{\s*$', '', '']],
|
||||
\ 'ruby': [['\<\(def\|class\|module\)\>\s\+', '', '']],
|
||||
\ 'vim': [
|
||||
\ ['^\s*com\%[mand]!\?\(\s\+-\S\+\)*\s*\u\w*\zs.*$', '', ''],
|
||||
\ ['^\s*\(let\|aug\%[roup]\|fu\%[nction]!\?\|com\%[mand]!\?\(\s\+-\S\+\)*\)\s*', '', ''],
|
||||
\ ['"\?\s*{{{\d.*$', '', ''],
|
||||
\ ],
|
||||
\ }
|
||||
|
||||
|
||||
" :def: function! tlib#tag#Retrieve(rx, ?extra_tags=0)
|
||||
" Get all tags matching rx. Basically, this function simply calls
|
||||
" |taglist()|, but when extra_tags is true, the list of the tag files
|
||||
" (see 'tags') is temporarily expanded with |g:tlib_tags_extra|.
|
||||
"
|
||||
" Example use:
|
||||
" If you want to include tags for, eg, JDK, normal tags use can become
|
||||
" slow. You could proceed as follows:
|
||||
" 1. Create a tags file for the JDK sources. When creating the tags
|
||||
" file, make sure to include inheritance information and the like
|
||||
" (command-line options like --fields=+iaSm --extra=+q should be ok).
|
||||
" In this example, we want tags only for public methods (there are
|
||||
" most likely better ways to do this): >
|
||||
" ctags -R --fields=+iaSm --extra=+q ${JAVA_HOME}/src
|
||||
" head -n 6 tags > tags0
|
||||
" grep access:public tags >> tags0
|
||||
" < 2. Make 'tags' include project specific tags files. In
|
||||
" ~/vimfiles/after/ftplugin/java.vim insert: >
|
||||
" let b:tlib_tags_extra = $JAVA_HOME .'/tags0'
|
||||
" < 3. When this function is invoked as >
|
||||
" echo tlib#tag#Retrieve('print')
|
||||
" < it will return only project-local tags. If it is invoked as >
|
||||
" echo tlib#tag#Retrieve('print', 1)
|
||||
" < tags from the JDK will be included.
|
||||
function! tlib#tag#Retrieve(rx, ...) "{{{3
|
||||
TVarArg ['extra_tags', 0]
|
||||
" TLogVAR a:rx, extra_tags
|
||||
if extra_tags
|
||||
let tags_orig = &l:tags
|
||||
if empty(tags_orig)
|
||||
setlocal tags<
|
||||
endif
|
||||
try
|
||||
let more_tags = tlib#var#Get('tlib_tags_extra', 'bg')
|
||||
if !empty(more_tags)
|
||||
let &l:tags .= ','. more_tags
|
||||
endif
|
||||
let taglist = taglist(a:rx)
|
||||
finally
|
||||
let &l:tags = tags_orig
|
||||
endtry
|
||||
else
|
||||
let taglist = taglist(a:rx)
|
||||
endif
|
||||
return taglist
|
||||
endf
|
||||
|
||||
|
||||
" Retrieve tags that meet the constraints (a dictionnary of fields and
|
||||
" regexp, with the exception of the kind field which is a list of chars).
|
||||
" For the use of the optional use_extra argument see
|
||||
" |tlib#tag#Retrieve()|.
|
||||
" :def: function! tlib#tag#Collect(constraints, ?use_extra=1, ?match_front=1)
|
||||
function! tlib#tag#Collect(constraints, ...) "{{{3
|
||||
TVarArg ['use_extra', 0], ['match_end', 1], ['match_front', 1]
|
||||
" TLogVAR a:constraints, use_extra
|
||||
let rx = get(a:constraints, 'name', '')
|
||||
if empty(rx) || rx == '*'
|
||||
let rx = '.'
|
||||
else
|
||||
let rxl = ['\C']
|
||||
if match_front
|
||||
call add(rxl, '^')
|
||||
endif
|
||||
" call add(rxl, tlib#rx#Escape(rx))
|
||||
call add(rxl, rx)
|
||||
if match_end
|
||||
call add(rxl, '$')
|
||||
endif
|
||||
let rx = join(rxl, '')
|
||||
endif
|
||||
" TLogVAR rx, use_extra
|
||||
let tags = tlib#tag#Retrieve(rx, use_extra)
|
||||
" TLogDBG len(tags)
|
||||
for [field, rx] in items(a:constraints)
|
||||
if !empty(rx) && rx != '*'
|
||||
" TLogVAR field, rx
|
||||
if field == 'kind'
|
||||
call filter(tags, 'v:val.kind =~ "['. rx .']"')
|
||||
elseif field != 'name'
|
||||
call filter(tags, '!empty(get(v:val, field)) && get(v:val, field) =~ rx')
|
||||
endif
|
||||
endif
|
||||
endfor
|
||||
" TLogVAR tags
|
||||
return tags
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#tag#Format(tag) "{{{3
|
||||
if has_key(a:tag, 'signature')
|
||||
let name = a:tag.name . a:tag.signature
|
||||
elseif a:tag.cmd[0] == '/'
|
||||
let name = a:tag.cmd
|
||||
let name = substitute(name, '^/\^\?\s*', '', '')
|
||||
let name = substitute(name, '\s*\$\?/$', '', '')
|
||||
let name = substitute(name, '\s\{2,}', ' ', 'g')
|
||||
let tsub = tlib#var#Get('tlib_tag_substitute', 'bg')
|
||||
if has_key(tsub, &filetype)
|
||||
for [rx, rplc, sub] in tsub[&filetype]
|
||||
let name = substitute(name, rx, rplc, sub)
|
||||
endfor
|
||||
endif
|
||||
else
|
||||
let name = a:tag.name
|
||||
endif
|
||||
return name
|
||||
endf
|
||||
|
@ -1,45 +0,0 @@
|
||||
" textobjects.vim
|
||||
" @Author: Tom Link (mailto:micathom AT gmail com?subject=[vim])
|
||||
" @Website: http://www.vim.org/account/profile.php?user_id=4037
|
||||
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
|
||||
" @Created: 2010-01-09.
|
||||
" @Last Change: 2010-01-10.
|
||||
" @Revision: 0.0.29
|
||||
|
||||
let s:save_cpo = &cpo
|
||||
set cpo&vim
|
||||
|
||||
|
||||
" :tag: standard-paragraph
|
||||
" Select a "Standard Paragraph", i.e. a text block followed by blank
|
||||
" lines. Other than |ap|, the last paragraph in a document is handled
|
||||
" just the same.
|
||||
"
|
||||
" The |text-object| can be accessed as "sp". Example: >
|
||||
"
|
||||
" vsp ... select the current standard paragraph
|
||||
"
|
||||
" Return 1, if the paragraph is the last one in the document.
|
||||
function! tlib#textobjects#StandardParagraph() "{{{3
|
||||
if line("'}") == line('$')
|
||||
norm! vip
|
||||
return 1
|
||||
else
|
||||
norm! vap
|
||||
return 0
|
||||
endif
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#textobjects#Init() "{{{3
|
||||
if !exists('s:tlib_done_textobjects')
|
||||
" sp ... Standard paragraph (for use as |text-objects|).
|
||||
vnoremap <silent> sp <Esc>:call tlib#textobjects#StandardParagraph()<CR>
|
||||
onoremap <silent> sp :<C-u>normal Vsp<CR>
|
||||
let s:tlib_done_textobjects = 1
|
||||
endif
|
||||
endf
|
||||
|
||||
|
||||
let &cpo = s:save_cpo
|
||||
unlet s:save_cpo
|
@ -1,67 +0,0 @@
|
||||
" @Author: Tom Link (mailto:micathom AT gmail com?subject=[vim])
|
||||
" @Website: http://www.vim.org/account/profile.php?user_id=4037
|
||||
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
|
||||
" @Revision: 36
|
||||
|
||||
|
||||
function! tlib#time#MSecs() "{{{3
|
||||
let rts = reltimestr(reltime())
|
||||
return substitute(rts, '\.', '', '')
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#time#Now() "{{{3
|
||||
if has('reltime')
|
||||
let rts = reltimestr(reltime())
|
||||
let rtl = map(split(rts, '\.'), 'str2nr(v:val)')
|
||||
else
|
||||
let rtl = [localtime()]
|
||||
endif
|
||||
return rtl
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#time#FormatNow() "{{{3
|
||||
let rtl = tlib#time#Now()
|
||||
if len(rtl) == 2
|
||||
let rts = strftime(g:tlib#date#date_format .' %H:%M:%S', rtl[0]) .'.'. rtl[1]
|
||||
else
|
||||
let rts = strftime(g:tlib#date#date_format .' %H:%M:%S', rtl[0])
|
||||
endif
|
||||
return rts
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#time#Diff(a, b, ...) "{{{3
|
||||
TVarArg ['resolution', 2]
|
||||
let [as, am] = a:a
|
||||
let [bs, bm] = a:b
|
||||
let rv = 0 + (as - bs)
|
||||
if resolution > 0
|
||||
let rv .= repeat('0', resolution)
|
||||
let am = am[0 : resolution - 1]
|
||||
let bm = bm[0 : resolution - 1]
|
||||
let rv += (am - bm)
|
||||
endif
|
||||
return rv
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#time#DiffMSecs(a, b, ...) "{{{3
|
||||
TVarArg ['resolution', 2]
|
||||
if a:a == a:b
|
||||
return 0
|
||||
endif
|
||||
let a = printf('%30s', a:a[0 : -(7 - resolution)])
|
||||
let b = printf('%30s', a:b[0 : -(7 - resolution)])
|
||||
for i in range(0, 29)
|
||||
if a[i] != b[i]
|
||||
let a = a[i : -1]
|
||||
let b = b[i : -1]
|
||||
return a - b
|
||||
endif
|
||||
endfor
|
||||
return 0
|
||||
endf
|
||||
|
||||
|
@ -1,117 +0,0 @@
|
||||
" @Author: Tom Link (mailto:micathom AT gmail com?subject=[vim])
|
||||
" @Website: https://github.com/tomtom
|
||||
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
|
||||
" @Last Change: 2015-11-23
|
||||
" @Revision: 134
|
||||
|
||||
|
||||
if !exists('g:tlib#trace#backtrace')
|
||||
" The length of the backtrace that should be included in
|
||||
" |tlib#trace#Print()|.
|
||||
let g:tlib#trace#backtrace = 2 "{{{2
|
||||
endif
|
||||
|
||||
|
||||
if !exists('g:tlib#trace#printf')
|
||||
" The command used for printing traces from |tlib#trace#Print()|.
|
||||
let g:tlib#trace#printf = 'echom %s' "{{{2
|
||||
endif
|
||||
|
||||
|
||||
let s:trace_hl = {'error': 'ErrorMsg', 'fatal': 'ErrorMsg', 'warning': 'WarningMsg'}
|
||||
|
||||
|
||||
" Set |g:tlib#trace#printf| to make |tlib#trace#Print()| print to
|
||||
" `filename`.
|
||||
function! tlib#trace#PrintToFile(filename) abort "{{{3
|
||||
let g:tlib#trace#printf = 'call writefile([%s], '. string(a:filename) .', "a")'
|
||||
endf
|
||||
|
||||
|
||||
" Set the tracing |regexp|. See |:Tlibtrace|.
|
||||
" This will also call |tlib#trace#Enable()|.
|
||||
"
|
||||
" Examples:
|
||||
" call tlib#trace#Set(["+foo", "-bar"])
|
||||
" call tlib#trace#Set("+foo,-bar")
|
||||
function! tlib#trace#Set(vars) abort "{{{3
|
||||
call tlib#trace#Enable()
|
||||
if type(a:vars) == 1
|
||||
let vars = tlib#string#SplitCommaList(a:vars, '[,[:space:]]\+')
|
||||
else
|
||||
let vars = a:vars
|
||||
endif
|
||||
for rx in vars
|
||||
let rx1 = substitute(rx, '^[+-]', '', 'g')
|
||||
if rx1 !~# '^\%(error\|fatal\)$' && s:trace_rx !~# '[(|]'. tlib#rx#Escape(rx1) .'\\'
|
||||
" TLogVAR rx, rx1
|
||||
if rx =~ '^+'
|
||||
let s:trace_rx = substitute(s:trace_rx, '\ze\\)\$', '\\|'. tlib#rx#EscapeReplace(rx1), '')
|
||||
elseif rx =~ '^-'
|
||||
let s:trace_rx = substitute(s:trace_rx, '\\|'. tlib#rx#Escape(rx1), '', '')
|
||||
else
|
||||
echohl WarningMsg
|
||||
echom 'tlib#trace#Print: Unsupported syntax:' rx
|
||||
echohl NONE
|
||||
endif
|
||||
endif
|
||||
endfor
|
||||
echom "SetTrace:" s:trace_rx
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#trace#Backtrace(caller) abort "{{{3
|
||||
let caller = split(a:caller, '\.\.')
|
||||
let start = max([0, len(caller) - g:tlib#trace#backtrace - 1])
|
||||
let caller = caller[start : -1]
|
||||
return join(caller, '..')
|
||||
endf
|
||||
|
||||
|
||||
" Print the values of vars. The first value is a "guard" (see
|
||||
" |:Tlibtrace|).
|
||||
function! tlib#trace#Print(caller, vars, values) abort "{{{3
|
||||
let msg = ['TRACE']
|
||||
let guard = a:values[0]
|
||||
if type(guard) == 0
|
||||
let cond = guard
|
||||
else
|
||||
let cond = guard =~# s:trace_rx
|
||||
endif
|
||||
" TLogVAR guard, cond, a:vars, a:values
|
||||
if cond
|
||||
call add(msg, guard)
|
||||
call add(msg, tlib#time#FormatNow() .':')
|
||||
if g:tlib#trace#backtrace > 0
|
||||
let bt = tlib#trace#Backtrace(a:caller)
|
||||
if !empty(bt)
|
||||
call add(msg, bt .':')
|
||||
endif
|
||||
endif
|
||||
for i in range(1, len(a:vars) - 1)
|
||||
let v = substitute(a:vars[i], ',$', '', '')
|
||||
let r = string(a:values[i])
|
||||
call add(msg, v .'='. r .';')
|
||||
endfor
|
||||
exec printf(g:tlib#trace#printf, string(join(msg)))
|
||||
endif
|
||||
endf
|
||||
|
||||
|
||||
" Enable tracing via |:Tlibtrace|.
|
||||
function! tlib#trace#Enable() abort "{{{3
|
||||
if !exists('s:trace_rx')
|
||||
let s:trace_rx = '^\%(error\)$'
|
||||
" :nodoc:
|
||||
command! -nargs=+ -bar Tlibtrace call tlib#trace#Print(expand('<sfile>'), [<f-args>], [<args>])
|
||||
endif
|
||||
endf
|
||||
|
||||
|
||||
" Disable tracing via |:Tlibtrace|.
|
||||
function! tlib#trace#Disable() abort "{{{3
|
||||
" :nodoc:
|
||||
command! -nargs=+ -bang -bar Tlibtrace :
|
||||
unlet! s:trace_rx
|
||||
endf
|
||||
|
@ -1,71 +0,0 @@
|
||||
" @Author: Tom Link (mailto:micathom AT gmail com?subject=[vim])
|
||||
" @Website: http://www.vim.org/account/profile.php?user_id=4037
|
||||
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
|
||||
" @Created: 2007-09-30.
|
||||
" @Last Change: 2015-11-23.
|
||||
" @Revision: 6
|
||||
|
||||
|
||||
function! tlib#type#IsNumber(expr)
|
||||
return tlib#type#Is(a:expr, 0)
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#type#IsString(expr)
|
||||
return tlib#type#Is(a:expr, 1)
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#type#IsFuncref(expr)
|
||||
return tlib#type#Is(a:expr, 2)
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#type#IsList(expr)
|
||||
return tlib#type#Is(a:expr, 3)
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#type#IsDictionary(expr)
|
||||
return tlib#type#Is(a:expr, 4)
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#type#Is(val, type) abort "{{{3
|
||||
if type(a:type) == 0
|
||||
let type = a:type
|
||||
elseif a:type =~? '^n\%[umber]'
|
||||
let type = 0
|
||||
elseif a:type =~? '^s\%[tring]'
|
||||
let type = 1
|
||||
elseif a:type =~? '^fu\%[ncref]'
|
||||
let type = 2
|
||||
elseif a:type =~? '^l\%[ist]'
|
||||
let type = 3
|
||||
elseif a:type =~? '^d\%[ictionary]'
|
||||
let type = 4
|
||||
elseif a:type =~? '^fl\%[oat]'
|
||||
let type = 5
|
||||
else
|
||||
throw 'tlib#type#Is: Unknown type: ' a:type
|
||||
endif
|
||||
" TLogVAR a:val, a:type, type, type(a:val), type(a:val) == a:type
|
||||
return type(a:val) == type
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#type#Are(vals, type) abort "{{{3
|
||||
return tlib#assert#Map(a:vals, 'tlib#type#Is(v:val,'. string(a:type) .')')
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#type#Has(val, lst) abort "{{{3
|
||||
return tlib#assert#All(map(a:lst, 'has_key(a:val, v:val)'))
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#type#Have(vals, lst) abort "{{{3
|
||||
return tlib#assert#Map(a:vals, 'tlib#type#Has(v:val,'. string(a:lst) .')')
|
||||
endf
|
||||
|
||||
|
@ -1,52 +0,0 @@
|
||||
" url.vim
|
||||
" @Author: Tom Link (micathom AT gmail com?subject=[vim])
|
||||
" @Website: http://www.vim.org/account/profile.php?user_id=4037
|
||||
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
|
||||
" @Created: 2007-06-30.
|
||||
" @Last Change: 2011-03-10.
|
||||
" @Revision: 0.0.28
|
||||
|
||||
|
||||
" TODO: These functions could use printf() now.
|
||||
|
||||
" Decode an encoded URL.
|
||||
function! tlib#url#Decode(url) "{{{3
|
||||
return substitute(a:url, '\(+\|%\(%\|\x\x\)\)', '\=tlib#url#DecodeChar(submatch(1))', 'g')
|
||||
endf
|
||||
|
||||
|
||||
" Decode a single character.
|
||||
function! tlib#url#DecodeChar(char) "{{{3
|
||||
if a:char == '%%'
|
||||
return '%'
|
||||
elseif a:char == '+'
|
||||
return ' '
|
||||
else
|
||||
return nr2char("0x".a:char[1 : -1])
|
||||
endif
|
||||
endf
|
||||
|
||||
|
||||
" Encode a single character.
|
||||
function! tlib#url#EncodeChar(char) "{{{3
|
||||
if a:char == '%'
|
||||
return '%%'
|
||||
elseif a:char == ' '
|
||||
return '+'
|
||||
else
|
||||
return printf("%%%X", char2nr(a:char))
|
||||
endif
|
||||
endf
|
||||
|
||||
|
||||
" Encode an URL.
|
||||
function! tlib#url#Encode(url, ...) "{{{3
|
||||
TVarArg ['extrachars', '']
|
||||
let rx = '\([^a-zA-Z0-9_.'. extrachars .'-]\)'
|
||||
" TLogVAR a:url, rx
|
||||
let rv = substitute(a:url, rx, '\=tlib#url#EncodeChar(submatch(1))', 'g')
|
||||
" TLogVAR rv
|
||||
return rv
|
||||
endf
|
||||
|
||||
|
@ -1,83 +0,0 @@
|
||||
" @Author: Tom Link (micathom AT gmail com?subject=[vim])
|
||||
" @Website: http://www.vim.org/account/profile.php?user_id=4037
|
||||
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
|
||||
" @Revision: 30
|
||||
|
||||
|
||||
" Define a variable called NAME if yet undefined.
|
||||
" You can also use the :TLLet command.
|
||||
"
|
||||
" EXAMPLES: >
|
||||
" exec tlib#var#Let('g:foo', 1)
|
||||
" TLet g:foo = 1
|
||||
function! tlib#var#Let(name, val) "{{{3
|
||||
return printf('if !exists(%s) | let %s = %s | endif', string(a:name), a:name, string(a:val))
|
||||
" return printf('if !exists(%s) | let %s = %s | endif', string(a:name), a:name, a:val)
|
||||
endf
|
||||
|
||||
|
||||
" :def: function! tlib#var#EGet(var, namespace, ?default='')
|
||||
" Retrieve a variable by searching several namespaces.
|
||||
"
|
||||
" EXAMPLES: >
|
||||
" let g:foo = 1
|
||||
" let b:foo = 2
|
||||
" let w:foo = 3
|
||||
" echo eval(tlib#var#EGet('foo', 'vg')) => 1
|
||||
" echo eval(tlib#var#EGet('foo', 'bg')) => 2
|
||||
" echo eval(tlib#var#EGet('foo', 'wbg')) => 3
|
||||
function! tlib#var#EGet(var, namespace, ...) "{{{3
|
||||
let pre = []
|
||||
let post = []
|
||||
for namespace in split(a:namespace, '\zs')
|
||||
let var = namespace .':'. a:var
|
||||
call add(pre, printf('exists("%s") ? %s : (', var, var))
|
||||
call add(post, ')')
|
||||
endfor
|
||||
let default = a:0 >= 1 ? a:1 : ''
|
||||
return join(pre) . string(default) . join(post)
|
||||
endf
|
||||
|
||||
|
||||
" :def: function! tlib#var#Get(var, namespace, ?default='')
|
||||
" Retrieve a variable by searching several namespaces.
|
||||
"
|
||||
" EXAMPLES: >
|
||||
" let g:foo = 1
|
||||
" let b:foo = 2
|
||||
" let w:foo = 3
|
||||
" echo tlib#var#Get('foo', 'bg') => 1
|
||||
" echo tlib#var#Get('foo', 'bg') => 2
|
||||
" echo tlib#var#Get('foo', 'wbg') => 3
|
||||
function! tlib#var#Get(var, namespace, ...) "{{{3
|
||||
let var_ = substitute(a:var, '#', '_', 'g')
|
||||
for namespace in split(a:namespace, '\zs')
|
||||
let vname = namespace == 'g' ? a:var : var_
|
||||
let var = namespace .':'. vname
|
||||
if exists(var)
|
||||
return {var}
|
||||
endif
|
||||
endfor
|
||||
return a:0 >= 1 ? a:1 : ''
|
||||
endf
|
||||
|
||||
|
||||
" :def: function! tlib#var#List(rx, ?prefix='')
|
||||
" Get a list of variables matching rx.
|
||||
" EXAMPLE:
|
||||
" echo tlib#var#List('tlib_', 'g:')
|
||||
function! tlib#var#List(rx, ...) "{{{3
|
||||
TVarArg ['prefix', 'g:']
|
||||
if v:version >= 704
|
||||
exec 'let varlist = keys('. prefix .')'
|
||||
else
|
||||
redir => vars
|
||||
silent! exec 'let '. prefix
|
||||
redir END
|
||||
let varlist = split(vars, '\n')
|
||||
call map(varlist, 'matchstr(v:val, ''^\S\+'')')
|
||||
endif
|
||||
call filter(varlist, 'v:val =~ a:rx')
|
||||
return varlist
|
||||
endf
|
||||
|
@ -1,189 +0,0 @@
|
||||
" @Author: Tom Link (mailto:micathom AT gmail com?subject=[vim])
|
||||
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
|
||||
" @Created: 2012-03-08.
|
||||
" @Last Change: 2015-11-07.
|
||||
" @Revision: 190
|
||||
|
||||
scriptencoding utf-8
|
||||
|
||||
|
||||
" A dictionarie of supported VCS (currently: git, hg, svn, bzr).
|
||||
" :display: g:tlib#vcs#def {...}
|
||||
TLet g:tlib#vcs#def = {
|
||||
\ 'git': {
|
||||
\ 'dir': '.git',
|
||||
\ 'ls': 'git ls-files --full-name',
|
||||
\ 'ls.postprocess': '*tlib#vcs#GitLsPostprocess',
|
||||
\ 'diff': 'git diff --no-ext-diff -U0 %s'
|
||||
\ },
|
||||
\ 'hg': {
|
||||
\ 'dir': '.hg',
|
||||
\ 'diff': 'hg diff -U0 %s',
|
||||
\ 'ls': 'hg manifest'
|
||||
\ },
|
||||
\ 'svn': {
|
||||
\ 'dir': '.svn',
|
||||
\ 'diff': 'svn diff --diff-cmd diff --extensions -U0 %s',
|
||||
\ },
|
||||
\ 'bzr': {
|
||||
\ 'dir': '.bzr',
|
||||
\ 'diff': 'bzr diff --diff-options=-U0 %s',
|
||||
\ }
|
||||
\ }
|
||||
|
||||
|
||||
" A dictionary of custom executables for VCS commands. If the value is
|
||||
" empty, support for that VCS will be removed. If no key is present, it
|
||||
" is assumed that the VCS "type" is the name of the executable.
|
||||
" :display: g:tlib#vcs#executables {...}
|
||||
TLet g:tlib#vcs#executables = {}
|
||||
|
||||
|
||||
" If non-empty, use it as a format string to check whether a VCS is
|
||||
" installed on your computer.
|
||||
TLet g:tlib#vcs#check = has('win16') || has('win32') || has('win64') ? '%s.exe' : '%s'
|
||||
|
||||
|
||||
if !empty(g:tlib#vcs#check)
|
||||
for [s:cmd, s:def] in items(g:tlib#vcs#def)
|
||||
if !has_key(g:tlib#vcs#executables, s:cmd)
|
||||
let s:cmd1 = printf(g:tlib#vcs#check, s:cmd)
|
||||
let g:tlib#vcs#executables[s:cmd] = executable(s:cmd1) ? s:cmd1 : ''
|
||||
endif
|
||||
endfor
|
||||
unlet! s:cmd s:def s:cmd1
|
||||
endif
|
||||
|
||||
|
||||
function! tlib#vcs#Executable(type) "{{{3
|
||||
return get(g:tlib#vcs#executables, a:type, '')
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#vcs#FindVCS(filename) "{{{3
|
||||
let type = ''
|
||||
let dir = ''
|
||||
let dirname = fnamemodify(a:filename, isdirectory(a:filename) ? ':p' : ':p:h')
|
||||
let path = escape(dirname, ';') .';'
|
||||
" TLogVAR a:filename, dirname, path
|
||||
Tlibtrace 'tlib', a:filename, path
|
||||
let depth = -1
|
||||
for vcs in keys(g:tlib#vcs#def)
|
||||
let subdir = g:tlib#vcs#def[vcs].dir
|
||||
let vcsdir = finddir(subdir, path)
|
||||
" TLogVAR vcs, subdir, vcsdir
|
||||
Tlibtrace 'tlib', vcs, subdir, vcsdir
|
||||
if !empty(vcsdir)
|
||||
let vcsdir_depth = len(split(fnamemodify(vcsdir, ':p'), '\/'))
|
||||
if vcsdir_depth > depth
|
||||
let depth = vcsdir_depth
|
||||
let type = vcs
|
||||
let dir = vcsdir
|
||||
" TLogVAR type, depth
|
||||
endif
|
||||
endif
|
||||
endfor
|
||||
Tlibtrace 'tlib', type, dir
|
||||
" TLogVAR type, dir
|
||||
if empty(type)
|
||||
return ['', '']
|
||||
else
|
||||
return [type, dir]
|
||||
endif
|
||||
endf
|
||||
|
||||
|
||||
function! s:GetCmd(vcstype, cmd)
|
||||
let vcsdef = get(g:tlib#vcs#def, a:vcstype, {})
|
||||
if has_key(vcsdef, a:cmd)
|
||||
let cmd = vcsdef[a:cmd]
|
||||
if cmd =~ '^\*'
|
||||
let cmd = substitute(cmd, '^\*', '', '')
|
||||
else
|
||||
let bin = get(g:tlib#vcs#executables, a:vcstype, '')
|
||||
if empty(bin)
|
||||
let cmd = ''
|
||||
elseif bin != a:vcstype
|
||||
" let bin = escape(shellescape(bin), '\')
|
||||
let bin = escape(bin, '\')
|
||||
let cmd = substitute(cmd, '^.\{-}\zs'. escape(a:vcstype, '\'), bin, '')
|
||||
endif
|
||||
endif
|
||||
return cmd
|
||||
else
|
||||
return ''
|
||||
endif
|
||||
endf
|
||||
|
||||
|
||||
" :display: tlib#vcs#Ls(?filename=bufname('%'), ?vcs=[type, dir])
|
||||
" Return the files under VCS.
|
||||
function! tlib#vcs#Ls(...) "{{{3
|
||||
if a:0 >= 2
|
||||
let vcs = a:2
|
||||
else
|
||||
let vcs = tlib#vcs#FindVCS(a:0 >= 1 ? a:1 : bufname('%'))
|
||||
endif
|
||||
Tlibtrace 'tlib', vcs, a:000
|
||||
" TLogVAR vcs
|
||||
if !empty(vcs)
|
||||
let [vcstype, vcsdir] = vcs
|
||||
if has_key(g:tlib#vcs#def, vcstype)
|
||||
let ls = s:GetCmd(vcstype, 'ls')
|
||||
" TLogVAR ls
|
||||
if !empty(ls)
|
||||
let rootdir = fnamemodify(vcsdir, ':p:h:h')
|
||||
" TLogVAR vcsdir, rootdir
|
||||
if ls =~ '%s'
|
||||
let cmd = printf(ls, shellescape(rootdir))
|
||||
else
|
||||
let cmd = ls
|
||||
endif
|
||||
" TLogVAR cmd, getcwd()
|
||||
Tlibtrace 'tlib', getcwd(), vcstype, vcsdir, rootdir, cmd
|
||||
let filess = tlib#sys#SystemInDir(rootdir, cmd)
|
||||
" TLogVAR filess
|
||||
let files = split(filess, '\n')
|
||||
let postprocess = s:GetCmd(vcstype, 'ls.postprocess')
|
||||
if !empty(postprocess)
|
||||
call map(files, 'call(postprocess, [v:val])')
|
||||
endif
|
||||
call map(files, 'join([rootdir, v:val], "/")')
|
||||
" TLogVAR files
|
||||
return files
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
return []
|
||||
endf
|
||||
|
||||
|
||||
" :display: tlib#vcs#Diff(filename, ?vcs=[type, dir])
|
||||
" Return the diff for "filename"
|
||||
function! tlib#vcs#Diff(filename, ...) "{{{3
|
||||
let vcs = a:0 >= 1 ? a:1 : tlib#vcs#FindVCS(a:filename)
|
||||
if !empty(vcs)
|
||||
let [vcstype, vcsdir] = vcs
|
||||
let diff = s:GetCmd(vcstype, 'diff')
|
||||
if !empty(diff)
|
||||
let cmd = printf(diff, shellescape(fnamemodify(a:filename, ':p')))
|
||||
let patch = system(cmd)
|
||||
return patch
|
||||
endif
|
||||
endif
|
||||
return []
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#vcs#GitLsPostprocess(filename) abort "{{{3
|
||||
if a:filename =~ '^".\{-}"$'
|
||||
let filename = matchstr(a:filename, '^"\zs.\{-}\ze"$')
|
||||
let filename = substitute(filename, '\%(\\\@<!\\\(\d\d\d\)\)\+', '\=eval(''"''. submatch(0) .''"'')', 'g')
|
||||
" let filename = eval(a:filename)
|
||||
" TLogVAR a:filename, filename, &enc
|
||||
return filename
|
||||
else
|
||||
return a:filename
|
||||
endif
|
||||
endf
|
||||
|
@ -1,152 +0,0 @@
|
||||
" @Author: Tom Link (micathom AT gmail com?subject=[vim])
|
||||
" @Website: http://www.vim.org/account/profile.php?user_id=4037
|
||||
" @GIT: http://github.com/tomtom/tlib_vim/
|
||||
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
|
||||
" @Created: 2010-07-19.
|
||||
" @Last Change: 2012-06-08.
|
||||
" @Revision: 37
|
||||
|
||||
|
||||
let s:restoreframecmd = ''
|
||||
let s:fullscreen = 0
|
||||
|
||||
if has('win16') || has('win32') || has('win64')
|
||||
|
||||
if !exists('g:tlib#vim#simalt_maximize')
|
||||
" The alt-key for maximizing the window.
|
||||
" CAUTION: The value of this paramter depends on your locale and
|
||||
" maybe the windows version you are running.
|
||||
let g:tlib#vim#simalt_maximize = 'x' "{{{2
|
||||
endif
|
||||
|
||||
if !exists('g:tlib#vim#simalt_restore')
|
||||
" The alt-key for restoring the window.
|
||||
" CAUTION: The value of this paramter depends on your locale and
|
||||
" maybe the windows version you are running.
|
||||
let g:tlib#vim#simalt_restore = 'r' "{{{2
|
||||
endif
|
||||
|
||||
if !exists('g:tlib#vim#use_vimtweak')
|
||||
" If true, use the vimtweak.dll for windows. This will enable
|
||||
" tlib to remove the caption for fullscreen windows.
|
||||
let g:tlib#vim#use_vimtweak = 0 "{{{2
|
||||
endif
|
||||
|
||||
" Maximize the window.
|
||||
" You might need to redefine |g:tlib#vim#simalt_maximize| if it doesn't
|
||||
" work for you.
|
||||
fun! tlib#vim#Maximize(fullscreen) "{{{3
|
||||
if !has("gui_running")
|
||||
return
|
||||
endif
|
||||
call s:SaveFrameParams()
|
||||
let s:fullscreen = a:fullscreen
|
||||
if g:tlib#vim#use_vimtweak && a:fullscreen
|
||||
call libcallnr("vimtweak.dll", "EnableCaption", 0)
|
||||
endif
|
||||
exec 'simalt ~'. g:tlib#vim#simalt_maximize
|
||||
endf
|
||||
|
||||
" Restore the original vimsize after having called |tlib#vim#Maximize()|.
|
||||
function! tlib#vim#RestoreWindow() "{{{3
|
||||
if !has("gui_running")
|
||||
return
|
||||
endif
|
||||
if g:tlib#vim#use_vimtweak
|
||||
call libcallnr("vimtweak.dll", "EnableCaption", 1)
|
||||
endif
|
||||
exec 'simalt ~'. g:tlib#vim#simalt_restore
|
||||
call s:RestoreFrameParams()
|
||||
endf
|
||||
|
||||
else
|
||||
|
||||
if !exists('g:tlib#vim#use_wmctrl')
|
||||
" If true, use wmctrl for X windows to make a window
|
||||
" maximized/fullscreen.
|
||||
"
|
||||
" This is the preferred method for maximizing windows under X
|
||||
" windows. Some window managers have problem coping with the
|
||||
" default method of setting 'lines' and 'columns' to a large
|
||||
" value.
|
||||
let g:tlib#vim#use_wmctrl = executable('wmctrl') "{{{2
|
||||
endif
|
||||
|
||||
" :nodoc:
|
||||
fun! tlib#vim#Maximize(fullscreen) "{{{3
|
||||
if !has("gui_running")
|
||||
return
|
||||
endif
|
||||
call s:SaveFrameParams()
|
||||
let s:fullscreen = a:fullscreen
|
||||
if g:tlib#vim#use_wmctrl
|
||||
if a:fullscreen
|
||||
silent !wmctrl -r :ACTIVE: -b add,fullscreen
|
||||
else
|
||||
silent !wmctrl -r :ACTIVE: -b add,maximized_vert,maximized_horz
|
||||
endif
|
||||
else
|
||||
set lines=1000 columns=1000
|
||||
endif
|
||||
endf
|
||||
|
||||
" :nodoc:
|
||||
function! tlib#vim#RestoreWindow() "{{{3
|
||||
if !has("gui_running")
|
||||
return
|
||||
endif
|
||||
if g:tlib#vim#use_wmctrl
|
||||
if s:fullscreen
|
||||
silent !wmctrl -r :ACTIVE: -b remove,fullscreen
|
||||
else
|
||||
silent !wmctrl -r :ACTIVE: -b remove,maximized_vert,maximized_horz
|
||||
endif
|
||||
endif
|
||||
call s:RestoreFrameParams()
|
||||
endf
|
||||
|
||||
endif
|
||||
|
||||
|
||||
function! s:SaveFrameParams() "{{{3
|
||||
let s:restoreframecmd = printf("set lines=%d columns=%d | winpos %d %d", &lines, &columns, getwinposx(), getwinposy())
|
||||
endf
|
||||
|
||||
|
||||
function! s:RestoreFrameParams() "{{{3
|
||||
if !empty(s:restoreframecmd)
|
||||
exec s:restoreframecmd
|
||||
let s:restoreframecmd = ''
|
||||
endif
|
||||
endf
|
||||
|
||||
|
||||
" :display: tlib#vim##CopyFunction(old, new, overwrite=0)
|
||||
function! tlib#vim#CopyFunction(old, new, ...) "{{{3
|
||||
let overwrite = a:0 >= 1 ? a:1 : 0
|
||||
redir => oldfn
|
||||
exec 'silent function' a:old
|
||||
redir END
|
||||
if exists('*'. a:new)
|
||||
if overwrite > 0
|
||||
exec 'delfunction' a:new
|
||||
elseif overwrite < 0
|
||||
throw 'tlib#vim##CopyFunction: Function already exists: '. a:old .' -> '. a:new
|
||||
else
|
||||
return
|
||||
endif
|
||||
endif
|
||||
let fn = split(oldfn, '\n')
|
||||
let fn = map(fn, 'substitute(v:val, ''^\d\+'', "", "")')
|
||||
let fn[0] = substitute(fn[0], '\V\^\s\*fu\%[nction]!\?\s\+\zs'. a:old, a:new, '')
|
||||
let t = @t
|
||||
try
|
||||
let @t = join(fn, "\n")
|
||||
redir => out
|
||||
@t
|
||||
redir END
|
||||
finally
|
||||
let @t = t
|
||||
endtry
|
||||
endf
|
||||
|
@ -1,128 +0,0 @@
|
||||
" @Author: Tom Link (micathom AT gmail com?subject=[vim])
|
||||
" @Website: http://www.vim.org/account/profile.php?user_id=4037
|
||||
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
|
||||
" @Revision: 55
|
||||
|
||||
|
||||
" Return vim code to jump back to the original window.
|
||||
function! tlib#win#Set(winnr) "{{{3
|
||||
if a:winnr > 0
|
||||
" TLogVAR a:winnr
|
||||
" TLogDBG winnr()
|
||||
" TLogDBG string(tlib#win#List())
|
||||
if winnr() != a:winnr && winbufnr(a:winnr) != -1
|
||||
let rv = winnr().'wincmd w'
|
||||
exec a:winnr .'wincmd w'
|
||||
" TLogVAR rv
|
||||
" TLogDBG string(tlib#win#List())
|
||||
return rv
|
||||
endif
|
||||
endif
|
||||
return ''
|
||||
endf
|
||||
|
||||
|
||||
" :def: function! tlib#win#GetLayout(?save_view=0)
|
||||
function! tlib#win#GetLayout(...) "{{{3
|
||||
TVarArg ['save_view', 0]
|
||||
let views = {}
|
||||
if save_view
|
||||
let winnr = winnr()
|
||||
windo let views[winnr()] = winsaveview()
|
||||
" for w in range(1, winnr('$'))
|
||||
" call tlib#win#Set(w)
|
||||
" let views[w] = winsaveview()
|
||||
" endfor
|
||||
call tlib#win#Set(winnr)
|
||||
endif
|
||||
return {'winnr': winnr('$'), 'winrestcmd': winrestcmd(), 'views': views, 'cmdheight': &cmdheight, 'guioptions': &guioptions, 'tabpagenr': tabpagenr()}
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#win#SetLayout(layout) "{{{3
|
||||
if a:layout.tabpagenr == tabpagenr() && a:layout.winnr == winnr('$')
|
||||
" TLogVAR a:layout.winrestcmd
|
||||
" TLogDBG string(tlib#win#List())
|
||||
exec a:layout.winrestcmd
|
||||
if !empty(a:layout.views)
|
||||
let winnr = winnr()
|
||||
" TLogVAR winnr
|
||||
for [w, v] in items(a:layout.views)
|
||||
" TLogVAR w, v
|
||||
call tlib#win#Set(w)
|
||||
call winrestview(v)
|
||||
endfor
|
||||
call tlib#win#Set(winnr)
|
||||
endif
|
||||
if a:layout.cmdheight != &cmdheight
|
||||
let &cmdheight = a:layout.cmdheight
|
||||
endif
|
||||
" TLogDBG string(tlib#win#List())
|
||||
return 1
|
||||
endif
|
||||
return 0
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#win#List() "{{{3
|
||||
let wl = {}
|
||||
for wn in range(1, winnr('$'))
|
||||
let wl[wn] = bufname(winbufnr(wn))
|
||||
endfor
|
||||
return wl
|
||||
endf
|
||||
|
||||
|
||||
" " :def: function! tlib#win#GetLayout1(?save_view=0)
|
||||
" " Contrary to |tlib#win#GetLayout|, this version doesn't use
|
||||
" " |winrestcmd()|. It can also save windows views.
|
||||
" function! tlib#win#GetLayout1(...) "{{{3
|
||||
" TVarArg ['save_view', 0]
|
||||
" let winnr = winnr()
|
||||
" let acc = {}
|
||||
" for w in range(1, winnr('$'))
|
||||
" let def = {'h': winheight(w), 'w': winwidth(w)}
|
||||
" if save_view
|
||||
" call tlib#win#Set(w)
|
||||
" let def.view = winsaveview()
|
||||
" endif
|
||||
" let acc[w] = def
|
||||
" endfor
|
||||
" call tlib#win#Set(winnr)
|
||||
" return acc
|
||||
" endf
|
||||
"
|
||||
"
|
||||
" " Reset layout from the value of |tlib#win#GetLayout1|.
|
||||
" function! tlib#win#SetLayout1(layout) "{{{3
|
||||
" if len(a:layout) != winnr('$')
|
||||
" return 0
|
||||
" endif
|
||||
" let winnr = winnr()
|
||||
" for [w, def] in items(a:layout)
|
||||
" if tlib#win#Set(w)
|
||||
" exec 'resize '. def.h
|
||||
" exec 'vertical resize '. def.w
|
||||
" if has_key(def, 'view')
|
||||
" call winrestview(def.view)
|
||||
" endif
|
||||
" else
|
||||
" break
|
||||
" endif
|
||||
" endfor
|
||||
" call tlib#win#Set(winnr)
|
||||
" return 1
|
||||
" endf
|
||||
|
||||
|
||||
function! tlib#win#Width(wnr) "{{{3
|
||||
return winwidth(a:wnr) - &fdc
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#win#WinDo(ex) "{{{3
|
||||
let w = winnr()
|
||||
exec 'windo '. a:ex
|
||||
exec w .'wincmd w'
|
||||
endf
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,102 +0,0 @@
|
||||
" @Author: Tom Link (micathom AT gmail com?subject=[vim])
|
||||
" @Created: 2007-04-10.
|
||||
" @Last Change: 2015-11-23.
|
||||
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
|
||||
" @Revision: 808
|
||||
" @Website: http://www.vim.org/account/profile.php?user_id=4037
|
||||
" GetLatestVimScripts: 1863 1 tlib.vim
|
||||
" tlib.vim -- Some utility functions
|
||||
|
||||
if &cp || exists("g:loaded_tlib")
|
||||
finish
|
||||
endif
|
||||
if v:version < 700 "{{{2
|
||||
echoerr "tlib requires Vim >= 7"
|
||||
finish
|
||||
endif
|
||||
let g:loaded_tlib = 117
|
||||
|
||||
let s:save_cpo = &cpo
|
||||
set cpo&vim
|
||||
|
||||
|
||||
" :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': empty('<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: :TBrowseOutput COMMAND
|
||||
" 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>)
|
||||
|
||||
|
||||
" :display: :TBrowseScriptnames
|
||||
" 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#TBrowseScriptnames()
|
||||
|
||||
|
||||
" :display: :Tlibtrace GUARD, VAR1, VAR2...
|
||||
" Do nothing unless |tlib#trace#Enable()| was called.
|
||||
"
|
||||
" When |:Tlibtraceset| or |tlib#trace#Enable()| were called:
|
||||
"
|
||||
" If GUARD is a number that evaluates to true or if it is a string that
|
||||
" matches a |regexp|, which was added using Tlibtrace! (with '!'),
|
||||
" display the values of VAR1, VAR2 ...
|
||||
command! -nargs=+ -bang -bar Tlibtrace :
|
||||
|
||||
|
||||
" :Tlibtraceset +RX1, -RX2...
|
||||
" If |tlib#trace#Enable()| was called: With the optional <bang>, users
|
||||
" can add and remove GUARDs (actually a |regexp|) that should be traced.
|
||||
command! -nargs=+ -bang -bar Tlibtraceset call tlib#trace#Set(<q-args>)
|
||||
|
||||
|
||||
" :display: :Tlibtrace ASSERTION
|
||||
command! -nargs=+ -bang -bar Tlibassert :
|
||||
|
||||
|
||||
let &cpo = s:save_cpo
|
||||
unlet s:save_cpo
|
@ -1,219 +0,0 @@
|
||||
" tLib.vim
|
||||
" @Author: Thomas Link (mailto:micathom AT gmail com?subject=vim-tLib)
|
||||
" @Website: http://www.vim.org/account/profile.php?user_id=4037
|
||||
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
|
||||
" @Created: 2006-12-17.
|
||||
" @Last Change: 2008-11-23.
|
||||
" @Revision: 129
|
||||
|
||||
if !exists("loaded_tassert")
|
||||
echoerr 'tAssert (vimscript #1730) is required'
|
||||
endif
|
||||
|
||||
|
||||
TAssertBegin! "tlib"
|
||||
|
||||
|
||||
" List {{{2
|
||||
fun! Add(a,b)
|
||||
return a:a + a:b
|
||||
endf
|
||||
TAssert IsEqual(tlib#list#Inject([], 0, function('Add')), 0)
|
||||
TAssert IsEqual(tlib#list#Inject([1,2,3], 0, function('Add')), 6)
|
||||
delfunction Add
|
||||
|
||||
TAssert IsEqual(tlib#list#Compact([]), [])
|
||||
TAssert IsEqual(tlib#list#Compact([0,1,2,3,[], {}, ""]), [1,2,3])
|
||||
|
||||
TAssert IsEqual(tlib#list#Flatten([]), [])
|
||||
TAssert IsEqual(tlib#list#Flatten([1,2,3]), [1,2,3])
|
||||
TAssert IsEqual(tlib#list#Flatten([1,2, [1,2,3], 3]), [1,2,1,2,3,3])
|
||||
TAssert IsEqual(tlib#list#Flatten([0,[1,2,[3,""]]]), [0,1,2,3,""])
|
||||
|
||||
TAssert IsEqual(tlib#list#FindAll([1,2,3], 'v:val >= 2'), [2,3])
|
||||
TAssert IsEqual(tlib#list#FindAll([1,2,3], 'v:val >= 2', 'v:val * 10'), [20,30])
|
||||
|
||||
TAssert IsEqual(tlib#list#Find([1,2,3], 'v:val >= 2'), 2)
|
||||
TAssert IsEqual(tlib#list#Find([1,2,3], 'v:val >= 2', 0, 'v:val * 10'), 20)
|
||||
TAssert IsEqual(tlib#list#Find([1,2,3], 'v:val >= 5', 10), 10)
|
||||
|
||||
TAssert IsEqual(tlib#list#Any([1,2,3], 'v:val >= 2'), 1)
|
||||
TAssert IsEqual(tlib#list#Any([1,2,3], 'v:val >= 5'), 0)
|
||||
|
||||
TAssert IsEqual(tlib#list#All([1,2,3], 'v:val < 5'), 1)
|
||||
TAssert IsEqual(tlib#list#All([1,2,3], 'v:val >= 2'), 0)
|
||||
|
||||
TAssert IsEqual(tlib#list#Remove([1,2,1,2], 2), [1,1,2])
|
||||
TAssert IsEqual(tlib#list#RemoveAll([1,2,1,2], 2), [1,1])
|
||||
|
||||
TAssert IsEqual(tlib#list#Zip([[1,2,3], [4,5,6]]), [[1,4], [2,5], [3,6]])
|
||||
TAssert IsEqual(tlib#list#Zip([[1,2,3], [4,5,6,7]]), [[1,4], [2,5], [3,6], ['', 7]])
|
||||
TAssert IsEqual(tlib#list#Zip([[1,2,3], [4,5,6,7]], -1), [[1,4], [2,5], [3,6], [-1,7]])
|
||||
TAssert IsEqual(tlib#list#Zip([[1,2,3,7], [4,5,6]], -1), [[1,4], [2,5], [3,6], [7,-1]])
|
||||
|
||||
|
||||
" Vars {{{2
|
||||
let g:foo = 1
|
||||
let g:bar = 2
|
||||
let b:bar = 3
|
||||
let s:bar = 4
|
||||
|
||||
TAssert IsEqual(tlib#var#Get('bar', 'bg'), 3)
|
||||
TAssert IsEqual(tlib#var#Get('bar', 'g'), 2)
|
||||
TAssert IsEqual(tlib#var#Get('foo', 'bg'), 1)
|
||||
TAssert IsEqual(tlib#var#Get('foo', 'g'), 1)
|
||||
TAssert IsEqual(tlib#var#Get('none', 'l'), '')
|
||||
|
||||
TAssert IsEqual(eval(tlib#var#EGet('bar', 'bg')), 3)
|
||||
TAssert IsEqual(eval(tlib#var#EGet('bar', 'g')), 2)
|
||||
" TAssert IsEqual(eval(tlib#var#EGet('bar', 'sg')), 4)
|
||||
TAssert IsEqual(eval(tlib#var#EGet('foo', 'bg')), 1)
|
||||
TAssert IsEqual(eval(tlib#var#EGet('foo', 'g')), 1)
|
||||
TAssert IsEqual(eval(tlib#var#EGet('none', 'l')), '')
|
||||
|
||||
unlet g:foo
|
||||
unlet g:bar
|
||||
unlet b:bar
|
||||
|
||||
|
||||
|
||||
" Filenames {{{2
|
||||
TAssert IsEqual(tlib#file#Split('foo/bar/filename.txt'), ['foo', 'bar', 'filename.txt'])
|
||||
TAssert IsEqual(tlib#file#Split('/foo/bar/filename.txt'), ['', 'foo', 'bar', 'filename.txt'])
|
||||
TAssert IsEqual(tlib#file#Split('ftp://foo/bar/filename.txt'), ['ftp:/', 'foo', 'bar', 'filename.txt'])
|
||||
|
||||
TAssert IsEqual(tlib#file#Join(['foo', 'bar', 'filename.txt']), 'foo/bar/filename.txt')
|
||||
TAssert IsEqual(tlib#file#Join(['', 'foo', 'bar', 'filename.txt']), '/foo/bar/filename.txt')
|
||||
TAssert IsEqual(tlib#file#Join(['ftp:/', 'foo', 'bar', 'filename.txt']), 'ftp://foo/bar/filename.txt')
|
||||
|
||||
TAssert IsEqual(tlib#file#Relative('foo/bar/filename.txt', 'foo'), 'bar/filename.txt')
|
||||
TAssert IsEqual(tlib#file#Relative('foo/bar/filename.txt', 'foo/base'), '../bar/filename.txt')
|
||||
TAssert IsEqual(tlib#file#Relative('filename.txt', 'foo/base'), '../../filename.txt')
|
||||
TAssert IsEqual(tlib#file#Relative('/foo/bar/filename.txt', '/boo/base'), '../../foo/bar/filename.txt')
|
||||
TAssert IsEqual(tlib#file#Relative('/bar/filename.txt', '/boo/base'), '../../bar/filename.txt')
|
||||
TAssert IsEqual(tlib#file#Relative('/foo/bar/filename.txt', '/base'), '../foo/bar/filename.txt')
|
||||
TAssert IsEqual(tlib#file#Relative('c:/bar/filename.txt', 'x:/boo/base'), 'c:/bar/filename.txt')
|
||||
|
||||
|
||||
|
||||
" Prototype-based programming {{{2
|
||||
let test = tlib#Test#New()
|
||||
TAssert test.IsA('Test')
|
||||
TAssert !test.IsA('foo')
|
||||
TAssert test.RespondTo('RespondTo')
|
||||
TAssert !test.RespondTo('RespondToNothing')
|
||||
let test1 = tlib#Test#New()
|
||||
TAssert test.IsRelated(test1)
|
||||
let testworld = tlib#World#New()
|
||||
TAssert !test.IsRelated(testworld)
|
||||
|
||||
let testc = tlib#TestChild#New()
|
||||
TAssert IsEqual(testc.Dummy(), 'TestChild.vim')
|
||||
TAssert IsEqual(testc.Super('Dummy', []), 'Test.vim')
|
||||
|
||||
|
||||
|
||||
" Optional arguments {{{2
|
||||
function! TestGetArg(...) "{{{3
|
||||
exec tlib#arg#Get(1, 'foo', 1)
|
||||
return foo
|
||||
endf
|
||||
|
||||
function! TestGetArg1(...) "{{{3
|
||||
exec tlib#arg#Get(1, 'foo', 1, '!= ""')
|
||||
return foo
|
||||
endf
|
||||
|
||||
TAssert IsEqual(TestGetArg(), 1)
|
||||
TAssert IsEqual(TestGetArg(''), '')
|
||||
TAssert IsEqual(TestGetArg(2), 2)
|
||||
TAssert IsEqual(TestGetArg1(), 1)
|
||||
TAssert IsEqual(TestGetArg1(''), 1)
|
||||
TAssert IsEqual(TestGetArg1(2), 2)
|
||||
|
||||
function! TestArgs(...) "{{{3
|
||||
exec tlib#arg#Let([['foo', "o"], ['bar', 2]])
|
||||
return repeat(foo, bar)
|
||||
endf
|
||||
TAssert IsEqual(TestArgs(), 'oo')
|
||||
TAssert IsEqual(TestArgs('a'), 'aa')
|
||||
TAssert IsEqual(TestArgs('a', 3), 'aaa')
|
||||
|
||||
function! TestArgs1(...) "{{{3
|
||||
exec tlib#arg#Let(['foo', ['bar', 2]])
|
||||
return repeat(foo, bar)
|
||||
endf
|
||||
TAssert IsEqual(TestArgs1(), '')
|
||||
TAssert IsEqual(TestArgs1('a'), 'aa')
|
||||
TAssert IsEqual(TestArgs1('a', 3), 'aaa')
|
||||
|
||||
function! TestArgs2(...) "{{{3
|
||||
exec tlib#arg#Let(['foo', 'bar'], 1)
|
||||
return repeat(foo, bar)
|
||||
endf
|
||||
TAssert IsEqual(TestArgs2(), '1')
|
||||
TAssert IsEqual(TestArgs2('a'), 'a')
|
||||
TAssert IsEqual(TestArgs2('a', 3), 'aaa')
|
||||
|
||||
function! TestArgs3(...)
|
||||
TVarArg ['a', 1], 'b'
|
||||
return a . b
|
||||
endf
|
||||
TAssert IsEqual(TestArgs3(), '1')
|
||||
TAssert IsEqual(TestArgs3('a'), 'a')
|
||||
TAssert IsEqual(TestArgs3('a', 3), 'a3')
|
||||
|
||||
delfunction TestGetArg
|
||||
delfunction TestGetArg1
|
||||
delfunction TestArgs
|
||||
delfunction TestArgs1
|
||||
delfunction TestArgs2
|
||||
delfunction TestArgs3
|
||||
|
||||
|
||||
|
||||
" Strings {{{2
|
||||
TAssert IsString(tlib#string#RemoveBackslashes('foo bar'))
|
||||
TAssert IsEqual(tlib#string#RemoveBackslashes('foo bar'), 'foo bar')
|
||||
TAssert IsEqual(tlib#string#RemoveBackslashes('foo\ bar'), 'foo bar')
|
||||
TAssert IsEqual(tlib#string#RemoveBackslashes('foo\ \\bar'), 'foo \\bar')
|
||||
TAssert IsEqual(tlib#string#RemoveBackslashes('foo\ \\bar', '\ '), 'foo \bar')
|
||||
|
||||
|
||||
|
||||
" Regexp {{{2
|
||||
for c in split('^$.*+\()|{}[]~', '\zs')
|
||||
let s = printf('%sfoo%sbar%s', c, c, c)
|
||||
TAssert (s =~ '\m^'. tlib#rx#Escape(s, 'm') .'$')
|
||||
TAssert (s =~ '\M^'. tlib#rx#Escape(s, 'M') .'$')
|
||||
TAssert (s =~ '\v^'. tlib#rx#Escape(s, 'v') .'$')
|
||||
TAssert (s =~ '\V\^'. tlib#rx#Escape(s, 'V') .'\$')
|
||||
endfor
|
||||
|
||||
|
||||
" Encode, decode
|
||||
TAssert IsEqual(tlib#url#Decode('http://example.com/foo+bar%25bar'), 'http://example.com/foo bar%bar')
|
||||
TAssert IsEqual(tlib#url#Decode('Hello%20World.%20%20Good%2c%20bye.'), 'Hello World. Good, bye.')
|
||||
|
||||
TAssert IsEqual(tlib#url#Encode('foo bar%bar'), 'foo+bar%%bar')
|
||||
TAssert IsEqual(tlib#url#Encode('Hello World. Good, bye.'), 'Hello+World.+Good%2c+bye.')
|
||||
|
||||
TAssertEnd test test1 testc testworld
|
||||
|
||||
|
||||
TAssert IsEqual(tlib#string#Count("fooo", "o"), 3)
|
||||
TAssert IsEqual(tlib#string#Count("***", "\\*"), 3)
|
||||
TAssert IsEqual(tlib#string#Count("***foo", "\\*"), 3)
|
||||
TAssert IsEqual(tlib#string#Count("foo***", "\\*"), 3)
|
||||
|
||||
|
||||
finish "{{{1
|
||||
|
||||
|
||||
" Input {{{2
|
||||
echo tlib#input#List('s', 'Test', ['barfoobar', 'barFoobar'])
|
||||
echo tlib#input#List('s', 'Test', ['barfoobar', 'bar foo bar', 'barFoobar'])
|
||||
echo tlib#input#List('s', 'Test', ['barfoobar', 'bar1Foo1bar', 'barFoobar'])
|
||||
echo tlib#input#EditList('Test', ['bar1', 'bar2', 'bar3', 'foo1', 'foo2', 'foo3'])
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,649 +0,0 @@
|
||||
*fugitive.txt* A Git wrapper so awesome, it should be illegal
|
||||
|
||||
Author: Tim Pope <http://tpo.pe/>
|
||||
License: Same terms as Vim itself (see |license|)
|
||||
|
||||
This plugin is only available if 'compatible' is not set.
|
||||
|
||||
INTRODUCTION *fugitive*
|
||||
|
||||
Whenever you edit a file from a Git repository, a set of commands is defined
|
||||
that serve as a gateway to Git.
|
||||
|
||||
COMMANDS *fugitive-commands*
|
||||
|
||||
These commands are local to the buffers in which they work (generally, buffers
|
||||
that are part of Git repositories).
|
||||
|
||||
*:Git* *fugitive-:G*
|
||||
:Git {args} Run an arbitrary git command and display any output.
|
||||
:G {args} On UNIX this uses a pty and on other platforms it uses
|
||||
a pipe, which will cause some behavior differences
|
||||
such as the absence of progress bars. Any file the
|
||||
command edits (for example, a commit message) will be
|
||||
loaded into a split window. Closing that window will
|
||||
resume running the command. A few Git subcommands
|
||||
have different behavior; these are documented below.
|
||||
|
||||
*:Git_--paginate* *:Git_-p*
|
||||
:Git --paginate {args} Run an arbitrary git command, capture output to a temp
|
||||
:Git -p {args} file, and |:split| that temp file. Use :0Git to
|
||||
:G --paginate {args} |:edit| the temp file instead. A temp file is always
|
||||
:G -p {args} used for commands like diff and log that typically
|
||||
user a pager, and for any command that has the
|
||||
pager.<cmd> Git configuration option set.
|
||||
|
||||
*fugitive-summary*
|
||||
:Git With no arguments, bring up a summary window vaguely
|
||||
:G akin to git-status. Press g? or see |fugitive-maps|
|
||||
for usage.
|
||||
|
||||
*:Git_blame*
|
||||
:Git blame [flags] Run git-blame [flags] on the current file and open the
|
||||
results in a scroll-bound vertical split. The
|
||||
following maps, which work on the cursor line commit
|
||||
where sensible, are provided:
|
||||
|
||||
g? show this help
|
||||
A resize to end of author column
|
||||
C resize to end of commit column
|
||||
D resize to end of date/time column
|
||||
gq close blame, then |:Gedit| to return to work
|
||||
tree version
|
||||
<CR> close blame, and jump to patch that added line
|
||||
(or directly to blob for boundary commit)
|
||||
o jump to patch or blob in horizontal split
|
||||
O jump to patch or blob in new tab
|
||||
p jump to patch or blob in preview window
|
||||
- reblame at commit
|
||||
~ reblame at [count]th first grandparent
|
||||
P reblame at [count]th parent (like HEAD^[count])
|
||||
|
||||
*g:fugitive_dynamic_colors*
|
||||
In the GUI or a 256 color terminal, commit hashes will
|
||||
highlighted in different colors. To disable this:
|
||||
>
|
||||
let g:fugitive_dynamic_colors = 0
|
||||
<
|
||||
:[range]Git blame [...] If a range is given, just that part of the file will
|
||||
:Git blame [...] {file} be blamed, and a horizontal split without
|
||||
scrollbinding is used. You can also give an arbitrary
|
||||
filename.
|
||||
|
||||
*:Git_difftool*
|
||||
:Git[!] difftool [args] Invoke `git diff [args]` and load the changes into the
|
||||
quickfix list. Each changed hunk gets a separate
|
||||
quickfix entry unless you pass an option like
|
||||
--name-only or --name-status. Jumps to the first
|
||||
change unless [!] is given.
|
||||
|
||||
:Git difftool -y [args] Invoke `git diff [args]`, open each changed file in a
|
||||
new tab, and invoke |:Gdiffsplit!| against the
|
||||
appropriate commit.
|
||||
|
||||
*:Git_mergetool*
|
||||
:Git mergetool [args] Like |:Git_difftool|, but target merge conflicts.
|
||||
|
||||
*:Ggrep* *:Gcgrep* *:Git_grep*
|
||||
:Ggrep[!] [args] |:grep|[!] with git-grep as 'grepprg'.
|
||||
:Git[!] grep [args]
|
||||
|
||||
*:Glgrep*
|
||||
:Glgrep[!] [args] |:lgrep|[!] with git-grep as 'grepprg'.
|
||||
:0Git[!] grep [args]
|
||||
|
||||
*:Gclog*
|
||||
:Gclog[!] [args] Use git-log [args] to load the commit history into the
|
||||
|quickfix| list. Jumps to the first commit unless [!]
|
||||
is given.
|
||||
|
||||
The quickfix list can be awkward for many use cases
|
||||
and exhibits extremely poor performance with larger
|
||||
data sets. Consider using |:Git| log instead.
|
||||
|
||||
:{range}Gclog[!] [args] Use git-log -L to load previous revisions of the given
|
||||
range of the current file into the |quickfix| list.
|
||||
The cursor is positioned on the first line of the
|
||||
first diff hunk for each commit. Use :0Gclog to
|
||||
target the entire file.
|
||||
|
||||
*:Gllog*
|
||||
:Gllog [args] Like |:Gclog|, but use the location list instead of the
|
||||
|quickfix| list.
|
||||
|
||||
*:Gcd*
|
||||
:Gcd [directory] |:cd| relative to the repository.
|
||||
|
||||
*:Glcd*
|
||||
:Glcd [directory] |:lcd| relative to the repository.
|
||||
|
||||
*:Gedit* *fugitive-:Ge*
|
||||
:Gedit [object] |:edit| a |fugitive-object|.
|
||||
|
||||
*:Gsplit*
|
||||
:Gsplit [object] |:split| a |fugitive-object|.
|
||||
|
||||
*:Gvsplit*
|
||||
:Gvsplit [object] |:vsplit| a |fugitive-object|.
|
||||
|
||||
*:Gtabedit*
|
||||
:Gtabedit [object] |:tabedit| a |fugitive-object|.
|
||||
|
||||
*:Gpedit*
|
||||
:Gpedit [object] |:pedit| a |fugitive-object|.
|
||||
|
||||
*:Gread* *fugitive-:Gr*
|
||||
:Gread [object] Empty the buffer and |:read| a |fugitive-object|.
|
||||
When the argument is omitted, this is similar to
|
||||
git-checkout on a work tree file or git-add on a stage
|
||||
file, but without writing anything to disk.
|
||||
|
||||
:{range}Gread [object] |:read| in a |fugitive-object| after {range}.
|
||||
|
||||
*:Gread!* *fugitive-:Gr!*
|
||||
:Gread! [args] Empty the buffer and |:read| the output of a Git
|
||||
command. For example, :Gread! show HEAD:%.
|
||||
|
||||
:{range}Gread! [args] |:read| the output of a Git command after {range}.
|
||||
|
||||
*:Gwrite* *fugitive-:Gw*
|
||||
:Gwrite Write to the current file's path and stage the results.
|
||||
When run in a work tree file, it is effectively git
|
||||
add. Elsewhere, it is effectively git-checkout. A
|
||||
great deal of effort is expended to behave sensibly
|
||||
when the work tree or index version of the file is
|
||||
open in another buffer.
|
||||
|
||||
:Gwrite {path} You can give |:Gwrite| an explicit path of where in
|
||||
the work tree to write. You can also give a path like
|
||||
:0:foo.txt or :0:% to write to just that stage in
|
||||
the index.
|
||||
|
||||
*:Gwq*
|
||||
:Gwq [path] Like |:Gwrite| followed by |:quit| if the write
|
||||
succeeded.
|
||||
|
||||
:Gwq! [path] Like |:Gwrite|! followed by |:quit|! if the write
|
||||
succeeded.
|
||||
|
||||
*:Gdiffsplit*
|
||||
:Gdiffsplit [object] Perform a |vimdiff| against the given file, or if a
|
||||
commit is given, the current file in that commit.
|
||||
With no argument, the version in the index or work
|
||||
tree is used. The newer of the two files is placed to
|
||||
the right or bottom, depending on 'diffopt' and the
|
||||
width of the window relative to 'textwidth'. Use
|
||||
Vim's |do| and |dp| to stage and unstage changes.
|
||||
|
||||
*:Gdiffsplit!*
|
||||
:Gdiffsplit! Diff against any and all direct ancestors, retaining
|
||||
focus on the current window. During a merge conflict,
|
||||
this is a three-way diff against the "ours" and
|
||||
"theirs" ancestors. Additional d2o and d3o maps are
|
||||
provided to obtain the hunk from the "ours" or
|
||||
"theirs" ancestor, respectively.
|
||||
|
||||
:Gdiffsplit! {object} Like |:Gdiffsplit|, but retain focus on the current
|
||||
window.
|
||||
|
||||
*:Gvdiffsplit*
|
||||
:Gvdiffsplit [object] Like |:Gdiffsplit|, but always split vertically.
|
||||
|
||||
*:Ghdiffsplit*
|
||||
:Ghdiffsplit [object] Like |:Gdiffsplit|, but always split horizontally.
|
||||
|
||||
*:GMove*
|
||||
:GMove {destination} Wrapper around git-mv that renames the buffer
|
||||
afterward. Add a ! to pass -f.
|
||||
|
||||
*:GRename*
|
||||
:GRename {destination} Like |:GMove| but operates relative to the parent
|
||||
directory of the current file.
|
||||
|
||||
*:GDelete*
|
||||
:GDelete Wrapper around git-rm that deletes the buffer
|
||||
afterward. When invoked in an index file, --cached is
|
||||
passed. Add a ! to pass -f and forcefully discard the
|
||||
buffer.
|
||||
|
||||
*:GRemove*
|
||||
:GRemove Like |:GDelete|, but keep the (now empty) buffer around.
|
||||
|
||||
*:GBrowse*
|
||||
:GBrowse Open the current file, blob, tree, commit, or tag
|
||||
in your browser at the upstream hosting provider.
|
||||
Upstream providers can be added by installing an
|
||||
appropriate Vim plugin. For example, GitHub can be
|
||||
supported by installing rhubarb.vim, available at
|
||||
<https://github.com/tpope/vim-rhubarb>.
|
||||
|
||||
:GBrowse {object} Like :GBrowse, but for a given |fugitive-object|.
|
||||
|
||||
:{range}GBrowse [args] Appends an anchor to the URL that emphasizes the
|
||||
selected lines. This also forces the URL to include a
|
||||
commit rather than a branch name so it remains valid
|
||||
if the file changes. You can give a range of "0" to
|
||||
force this behavior without including an anchor.
|
||||
|
||||
:GBrowse [...]@{remote} Force using the given remote rather than the remote
|
||||
for the current branch. The remote is used to
|
||||
determine which upstream repository to link to.
|
||||
|
||||
:GBrowse {url} Open an arbitrary URL in your browser.
|
||||
|
||||
:[range]GBrowse! [args] Like :GBrowse, but put the URL on the clipboard rather
|
||||
than opening it.
|
||||
|
||||
MAPS *fugitive-maps*
|
||||
|
||||
These maps are available in both the |fugitive-summary| buffer and Fugitive
|
||||
object buffers, although not all maps make sense in all buffers. Mappings
|
||||
that operate on the file or hunk under the cursor are generally available in
|
||||
visual mode to operate on multiple files or partial hunks.
|
||||
|
||||
*fugitive-staging-maps*
|
||||
Staging/unstaging maps ~
|
||||
|
||||
*fugitive_s*
|
||||
s Stage (add) the file or hunk under the cursor.
|
||||
|
||||
*fugitive_u*
|
||||
u Unstage (reset) the file or hunk under the cursor.
|
||||
|
||||
*fugitive_-*
|
||||
- Stage or unstage the file or hunk under the cursor.
|
||||
|
||||
*fugitive_U*
|
||||
U Unstage everything.
|
||||
|
||||
*fugitive_X*
|
||||
X Discard the change under the cursor. This uses
|
||||
`checkout` or `clean` under the hood. A command is
|
||||
echoed that shows how to undo the change. Consult
|
||||
`:messages` to see it again. During a merge conflict,
|
||||
use 2X to call `checkout --ours` or 3X to call
|
||||
`checkout --theirs` .
|
||||
|
||||
*fugitive_=*
|
||||
= Toggle an inline diff of the file under the cursor.
|
||||
|
||||
*fugitive_>*
|
||||
> Insert an inline diff of the file under the cursor.
|
||||
|
||||
*fugitive_<*
|
||||
< Remove the inline diff of the file under the cursor.
|
||||
|
||||
*fugitive_gI*
|
||||
gI Open .git/info/exclude in a split and add the file
|
||||
under the cursor. Use a count to open .gitignore.
|
||||
|
||||
*fugitive_I*
|
||||
I Invoke |:Git| add --patch or reset --patch on the file
|
||||
P under the cursor. On untracked files, this instead
|
||||
calls |:Git| add --intent-to-add.
|
||||
|
||||
*fugitive_d*
|
||||
Diff maps ~
|
||||
*fugitive_dp*
|
||||
dp Invoke |:Git| diff on the file under the cursor.
|
||||
Deprecated in favor of inline diffs.
|
||||
|
||||
*fugitive_dd*
|
||||
dd Perform a |:Gdiffsplit| on the file under the cursor.
|
||||
|
||||
*fugitive_dv*
|
||||
dv Perform a |:Gvdiffsplit| on the file under the cursor.
|
||||
|
||||
*fugitive_ds* *fugitive_dh*
|
||||
ds Perform a |:Ghdiffsplit| on the file under the cursor.
|
||||
dh
|
||||
*fugitive_dq*
|
||||
dq Close all but one diff buffer, and |:diffoff|! the
|
||||
last one.
|
||||
|
||||
*fugitive_d?*
|
||||
d? Show this help.
|
||||
|
||||
*fugitive-navigation-maps*
|
||||
Navigation maps ~
|
||||
|
||||
*fugitive_<CR>*
|
||||
<CR> Open the file or |fugitive-object| under the cursor.
|
||||
In a blob, this and similar maps jump to the patch
|
||||
from the diff where this was added, or where it was
|
||||
removed if a count was given. If the line is still in
|
||||
the work tree version, passing a count takes you to
|
||||
it.
|
||||
|
||||
*fugitive_o*
|
||||
o Open the file or |fugitive-object| under the cursor in
|
||||
a new split.
|
||||
|
||||
*fugitive_gO*
|
||||
gO Open the file or |fugitive-object| under the cursor in
|
||||
a new vertical split.
|
||||
|
||||
*fugitive_O*
|
||||
O Open the file or |fugitive-object| under the cursor in
|
||||
a new tab.
|
||||
|
||||
*fugitive_p*
|
||||
p Open the file or |fugitive-object| under the cursor in
|
||||
a preview window. In the status buffer, 1p is
|
||||
required to bypass the legacy usage instructions.
|
||||
|
||||
*fugitive_~*
|
||||
~ Open the current file in the [count]th first ancestor.
|
||||
|
||||
*fugitive_P*
|
||||
P Open the current file in the [count]th parent.
|
||||
|
||||
*fugitive_C*
|
||||
C Open the commit containing the current file.
|
||||
|
||||
*fugitive_CTRL-P* *fugitive_(*
|
||||
( Jump to the previous file, hunk, or revision.
|
||||
|
||||
*fugitive_CTRL-N* *fugitive_)*
|
||||
) Jump to the next file, hunk, or revision.
|
||||
|
||||
*fugitive_[c*
|
||||
[c Jump to previous hunk, expanding inline diffs
|
||||
automatically. (This shadows the Vim built-in |[c|
|
||||
that provides a similar operation in |diff| mode.)
|
||||
|
||||
*fugitive_]c*
|
||||
]c Jump to next hunk, expanding inline diffs
|
||||
automatically. (This shadows the Vim built-in |]c|
|
||||
that provides a similar operation in |diff| mode.)
|
||||
|
||||
*fugitive_[/* *fugitive_[m*
|
||||
[/ Jump to previous file, collapsing inline diffs
|
||||
[m automatically. (Mnemonic: "/" appears in filenames,
|
||||
"m" appears in "filenames".)
|
||||
|
||||
*fugitive_]/* *fugitive_]m*
|
||||
]/ Jump to next file, collapsing inline diffs
|
||||
]m automatically. (Mnemonic: "/" appears in filenames,
|
||||
"m" appears in "filenames".)
|
||||
|
||||
*fugitive_i*
|
||||
i Jump to the next file or hunk, expanding inline diffs
|
||||
automatically.
|
||||
|
||||
*fugitive_[[*
|
||||
[[ Jump [count] sections backward.
|
||||
|
||||
*fugitive_]]*
|
||||
]] Jump [count] sections forward.
|
||||
|
||||
*fugitive_[]*
|
||||
[] Jump [count] section ends backward.
|
||||
|
||||
*fugitive_][*
|
||||
][ Jump [count] section ends forward.
|
||||
|
||||
*fugitive_star*
|
||||
* On the first column of a + or - diff line, search for
|
||||
the corresponding - or + line. Otherwise, defer to
|
||||
built-in |star|.
|
||||
|
||||
*fugitive_#*
|
||||
# Same as "*", but search backward.
|
||||
|
||||
*fugitive_gu*
|
||||
gu Jump to file [count] in the "Untracked" or "Unstaged"
|
||||
section.
|
||||
|
||||
*fugitive_gU*
|
||||
gU Jump to file [count] in the "Unstaged" section.
|
||||
|
||||
*fugitive_gs*
|
||||
gs Jump to file [count] in the "Staged" section.
|
||||
|
||||
*fugitive_gp*
|
||||
gp Jump to file [count] in the "Unpushed" section.
|
||||
|
||||
*fugitive_gP*
|
||||
gP Jump to file [count] in the "Unpulled" section.
|
||||
|
||||
*fugitive_gr*
|
||||
gr Jump to file [count] in the "Rebasing" section.
|
||||
|
||||
*fugitive_gi*
|
||||
gi Open .git/info/exclude in a split. Use a count to
|
||||
open .gitignore.
|
||||
|
||||
*fugitive_c*
|
||||
Commit maps ~
|
||||
|
||||
cc Create a commit.
|
||||
|
||||
ca Amend the last commit and edit the message.
|
||||
|
||||
ce Amend the last commit without editing the message.
|
||||
|
||||
cw Reword the last commit.
|
||||
|
||||
cvc Create a commit with -v.
|
||||
|
||||
cva Amend the last commit with -v
|
||||
|
||||
cf Create a `fixup!` commit for the commit under the
|
||||
cursor.
|
||||
|
||||
cF Create a `fixup!` commit for the commit under the
|
||||
cursor and immediately rebase it.
|
||||
|
||||
cs Create a `squash!` commit for the commit under the
|
||||
cursor.
|
||||
|
||||
cS Create a `squash!` commit for the commit under the
|
||||
cursor and immediately rebase it.
|
||||
|
||||
cA Create a `squash!` commit for the commit under the
|
||||
cursor and edit the message.
|
||||
|
||||
c<Space> Populate command line with ":Git commit ".
|
||||
|
||||
*fugitive_cr*
|
||||
crc Revert the commit under the cursor.
|
||||
|
||||
crn Revert the commit under the cursor in the index and
|
||||
work tree, but do not actually commit the changes.
|
||||
|
||||
cr<Space> Populate command line with ":Git revert ".
|
||||
|
||||
*fugitive_cm*
|
||||
cm<Space> Populate command line with ":Git merge ".
|
||||
|
||||
c? Show this help.
|
||||
|
||||
*fugitive_cb*
|
||||
*fugitive_co*
|
||||
Checkout/branch maps ~
|
||||
|
||||
coo Check out the commit under the cursor.
|
||||
|
||||
cb<Space> Populate command line with ":Git branch ".
|
||||
|
||||
co<Space> Populate command line with ":Git checkout ".
|
||||
|
||||
cb? Show this help.
|
||||
co?
|
||||
|
||||
*fugitive_cz*
|
||||
Stash maps ~
|
||||
|
||||
czz Push stash. Pass a [count] of 1 to add
|
||||
`--include-untracked` or 2 to add `--all`.
|
||||
|
||||
czw Push stash of worktree. Like `czz` with
|
||||
`--keep-index`.
|
||||
|
||||
czA Apply topmost stash, or stash@{count}.
|
||||
|
||||
cza Apply topmost stash, or stash@{count}, preserving the
|
||||
index.
|
||||
|
||||
czP Pop topmost stash, or stash@{count}.
|
||||
|
||||
czp Pop topmost stash, or stash@{count}, preserving the
|
||||
index.
|
||||
|
||||
cz<Space> Populate command line with ":Git stash ".
|
||||
|
||||
cz? Show this help.
|
||||
|
||||
*fugitive_r*
|
||||
Rebase maps ~
|
||||
|
||||
ri Perform an interactive rebase. Uses ancestor of
|
||||
u commit under cursor as upstream if available.
|
||||
|
||||
rf Perform an autosquash rebase without editing the todo
|
||||
list. Uses ancestor of commit under cursor as
|
||||
upstream if available.
|
||||
|
||||
ru Perform an interactive rebase against @{upstream}.
|
||||
|
||||
rp Perform an interactive rebase against @{push}.
|
||||
|
||||
rr Continue the current rebase.
|
||||
|
||||
rs Skip the current commit and continue the current
|
||||
rebase.
|
||||
|
||||
ra Abort the current rebase.
|
||||
|
||||
re Edit the current rebase todo list.
|
||||
|
||||
rw Perform an interactive rebase with the commit under
|
||||
the cursor set to `reword`.
|
||||
|
||||
rm Perform an interactive rebase with the commit under
|
||||
the cursor set to `edit`.
|
||||
|
||||
rd Perform an interactive rebase with the commit under
|
||||
the cursor set to `drop`.
|
||||
|
||||
r<Space> Populate command line with ":Git rebase ".
|
||||
|
||||
r? Show this help.
|
||||
|
||||
*fugitive-misc-maps*
|
||||
Miscellaneous maps ~
|
||||
|
||||
*fugitive_gq* *fugitive_q*
|
||||
gq Close the status buffer.
|
||||
|
||||
*fugitive_.*
|
||||
. Start a |:| command line with the file under the
|
||||
cursor prepopulated.
|
||||
|
||||
*fugitive_g?*
|
||||
g? Show help for |fugitive-maps|.
|
||||
|
||||
*fugitive-global-maps*
|
||||
Global maps ~
|
||||
|
||||
*fugitive_c_CTRL-R_CTRL-G*
|
||||
<C-R><C-G> On the command line, recall the path to the current
|
||||
|fugitive-object| (that is, a representation of the
|
||||
object recognized by |:Gedit|).
|
||||
|
||||
*fugitive_y_CTRL-G*
|
||||
["x]y<C-G> Yank the path to the current |fugitive-object|.
|
||||
|
||||
*g:fugitive_no_maps*
|
||||
Global maps can be disabled with the g:fugitive_no_maps option.
|
||||
>
|
||||
let g:fugitive_no_maps = 1
|
||||
<
|
||||
SPECIFYING OBJECTS *fugitive-object* *fugitive-revision*
|
||||
|
||||
Fugitive objects are either work tree files or Git revisions as defined in the
|
||||
"SPECIFYING REVISIONS" section in the git-rev-parse man page, with expansions
|
||||
inspired by |cmdline-special| layered on top. For commands that accept an
|
||||
optional object, the default is the file in the index for work tree files and
|
||||
the work tree file for everything else. Example objects follow.
|
||||
|
||||
Object Meaning ~
|
||||
@ The commit referenced by @ aka HEAD
|
||||
master The commit referenced by master
|
||||
master^ The parent of the commit referenced by master
|
||||
master...other The merge base of master and other
|
||||
master: The tree referenced by master
|
||||
./master The file named master in the working directory
|
||||
:(top)master The file named master in the work tree
|
||||
Makefile The file named Makefile in the work tree
|
||||
@^:Makefile The file named Makefile in the parent of HEAD
|
||||
:Makefile The file named Makefile in the index (writable)
|
||||
@~2:% The current file in the grandparent of HEAD
|
||||
:% The current file in the index
|
||||
:1:% The current file's common ancestor during a conflict
|
||||
:2:# The alternate file in the target branch during a conflict
|
||||
:3:#5 The file from buffer #5 in the merged branch during a conflict
|
||||
! The commit owning the current file
|
||||
!:Makefile The file named Makefile in the commit owning the current file
|
||||
!3^2 The second parent of the commit owning buffer #3
|
||||
.git/config The repo config file
|
||||
: The |fugitive-summary| buffer
|
||||
- A temp file containing the last |:Git| invocation's output
|
||||
<cfile> The file or commit under the cursor
|
||||
|
||||
STATUSLINE *fugitive-statusline*
|
||||
|
||||
*FugitiveStatusline()* *fugitive#statusline()*
|
||||
Add %{FugitiveStatusline()} to your statusline to get an indicator including
|
||||
the current branch and the currently edited file's commit. If you don't have
|
||||
a statusline, this one matches the default when 'ruler' is set:
|
||||
>
|
||||
set statusline=%<%f\ %h%m%r%{FugitiveStatusline()}%=%-14.(%l,%c%V%)\ %P
|
||||
<
|
||||
*FugitiveHead(...)* *fugitive#head(...)*
|
||||
Use FugitiveHead() to return the name of the current branch. If the current
|
||||
HEAD is detached, FugitiveHead() will return the empty string, unless the
|
||||
optional argument is given, in which case the hash of the current commit will
|
||||
be truncated to the given number of characters.
|
||||
|
||||
DEPRECATIONS *fugitive-deprecated*
|
||||
|
||||
The following commands are softly deprecated in favor of replacements that
|
||||
adhere to a new naming scheme. They will eventually be removed, but probably
|
||||
not in the near future.
|
||||
|
||||
Remember that |:Git| can be shortened to |:G|, so replacements using it are
|
||||
just one space character longer than the legacy version.
|
||||
|
||||
*:Gremove* Superseded by |:GRemove|.
|
||||
*:Gdelete* Superseded by |:GDelete|.
|
||||
*:Gmove* Superseded by |:GMove|.
|
||||
*:Grename* Superseded by |:GRename|.
|
||||
*:Gbrowse* Superseded by |:GBrowse|.
|
||||
*:Gdiff* Superseded by |:Gdiffsplit|
|
||||
*:Gsdiff* Superseded by |:Ghdiffsplit|
|
||||
*:Gvdiff* Superseded by |:Gvdiffsplit| or |:vert| |:Gdiffsplit|.
|
||||
*:Gblame* Superseded by |:Git_blame|.
|
||||
*:Gcommit* Superseded by |:Git| commit.
|
||||
*:Gmerge* Superseded by |:Git| merge and |:Git_mergetool|.
|
||||
*:Gpull* Superseded by |:Git| pull.
|
||||
*:Grebase* Superseded by |:Git| rebase.
|
||||
*:Grevert* Superseded by |:Git| revert.
|
||||
*:Gpush* Superseded by |:Git| push.
|
||||
*:Gfetch* Superseded by |:Git| fetch.
|
||||
*:Glog* Superseded by |:Gclog|.
|
||||
*:Gstatus* Superseded by |:Git| (with no arguments).
|
||||
*:Git!* Superseded by |:Git_--paginate|.
|
||||
*:Gsplit!* Superseded by |:Git_--paginate|.
|
||||
*:Gvsplit!* Superseded by :vert Git --paginate.
|
||||
*:Gtabsplit!* Superseded by :tab Git --paginate.
|
||||
*:Gpedit!* Superseded by :Git! --paginate.
|
||||
|
||||
ABOUT *fugitive-about*
|
||||
|
||||
Grab the latest version or report a bug on GitHub:
|
||||
|
||||
https://github.com/tpope/vim-fugitive
|
||||
|
||||
vim:tw=78:et:ft=help:norl:
|
@ -1 +0,0 @@
|
||||
autocmd BufReadPost *.fugitiveblame setfiletype fugitiveblame
|
@ -1,6 +0,0 @@
|
||||
if exists("b:did_ftplugin") || !exists("*FugitiveGitDir")
|
||||
finish
|
||||
endif
|
||||
let b:did_ftplugin = 1
|
||||
|
||||
call fugitive#BlameFileType()
|
@ -1,565 +0,0 @@
|
||||
" fugitive.vim - A Git wrapper so awesome, it should be illegal
|
||||
" Maintainer: Tim Pope <http://tpo.pe/>
|
||||
" Version: 3.3
|
||||
" GetLatestVimScripts: 2975 1 :AutoInstall: fugitive.vim
|
||||
|
||||
if exists('g:loaded_fugitive')
|
||||
finish
|
||||
endif
|
||||
let g:loaded_fugitive = 1
|
||||
|
||||
let s:bad_git_dir = '/$\|^fugitive:'
|
||||
|
||||
function! FugitiveGitDir(...) abort
|
||||
if v:version < 704
|
||||
return ''
|
||||
elseif !a:0 || type(a:1) == type(0) && a:1 < 0
|
||||
if exists('g:fugitive_event')
|
||||
return g:fugitive_event
|
||||
endif
|
||||
let dir = get(b:, 'git_dir', '')
|
||||
if empty(dir) && (empty(bufname('')) || &buftype =~# '^\%(nofile\|acwrite\|quickfix\|prompt\)$')
|
||||
return FugitiveExtractGitDir(getcwd())
|
||||
elseif (!exists('b:git_dir') || b:git_dir =~# s:bad_git_dir) && empty(&buftype)
|
||||
let b:git_dir = FugitiveExtractGitDir(expand('%:p'))
|
||||
return b:git_dir
|
||||
endif
|
||||
return dir =~# s:bad_git_dir ? '' : dir
|
||||
elseif type(a:1) == type(0)
|
||||
if a:1 == bufnr('') && (!exists('b:git_dir') || b:git_dir =~# s:bad_git_dir) && empty(&buftype)
|
||||
let b:git_dir = FugitiveExtractGitDir(expand('%:p'))
|
||||
endif
|
||||
let dir = getbufvar(a:1, 'git_dir')
|
||||
return dir =~# s:bad_git_dir ? '' : dir
|
||||
elseif type(a:1) == type('')
|
||||
return substitute(s:Slash(a:1), '/$', '', '')
|
||||
elseif type(a:1) == type({})
|
||||
return get(a:1, 'git_dir', '')
|
||||
else
|
||||
return ''
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" FugitiveReal() takes a fugitive:// URL and returns the corresponding path in
|
||||
" the work tree. This may be useful to get a cleaner path for inclusion in
|
||||
" the statusline, for example. Note that the file and its parent directories
|
||||
" are not guaranteed to exist.
|
||||
"
|
||||
" This is intended as an abstract API to be used on any "virtual" path. For a
|
||||
" buffer named foo://bar, check for a function named FooReal(), and if it
|
||||
" exists, call FooReal("foo://bar").
|
||||
function! FugitiveReal(...) abort
|
||||
let file = a:0 ? a:1 : @%
|
||||
if file =~# '^\a\a\+:' || a:0 > 1
|
||||
return call('fugitive#Real', [file] + a:000[1:-1])
|
||||
elseif file =~# '^/\|^\a:\|^$'
|
||||
return file
|
||||
else
|
||||
return fnamemodify(file, ':p' . (file =~# '[\/]$' ? '' : ':s?[\/]$??'))
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" FugitiveFind() takes a Fugitive object and returns the appropriate Vim
|
||||
" buffer name. You can use this to generate Fugitive URLs ("HEAD:README") or
|
||||
" to get the absolute path to a file in the Git dir (".git/HEAD"), the common
|
||||
" dir (".git/config"), or the work tree (":(top)Makefile").
|
||||
"
|
||||
" An optional second argument provides the Git dir, or the buffer number of a
|
||||
" buffer with a Git dir. The default is the current buffer.
|
||||
function! FugitiveFind(...) abort
|
||||
return fugitive#Find(a:0 ? a:1 : bufnr(''), FugitiveGitDir(a:0 > 1 ? a:2 : -1))
|
||||
endfunction
|
||||
|
||||
function! FugitivePath(...) abort
|
||||
if a:0 > 1
|
||||
return fugitive#Path(a:1, a:2, FugitiveGitDir(a:0 > 2 ? a:3 : -1))
|
||||
else
|
||||
return FugitiveReal(a:0 ? a:1 : @%)
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" FugitiveParse() takes a fugitive:// URL and returns a 2 element list
|
||||
" containing an object name ("commit:file") and the Git dir. It's effectively
|
||||
" the inverse of FugitiveFind().
|
||||
function! FugitiveParse(...) abort
|
||||
let path = s:Slash(a:0 ? a:1 : @%)
|
||||
if path !~# '^fugitive:'
|
||||
return ['', '']
|
||||
endif
|
||||
let vals = matchlist(path, '\c^fugitive:\%(//\)\=\(.\{-\}\)\%(//\|::\)\(\x\{40,\}\|[0-3]\)\(/.*\)\=$')
|
||||
if len(vals)
|
||||
return [(vals[2] =~# '^.$' ? ':' : '') . vals[2] . substitute(vals[3], '^/', ':', ''), vals[1]]
|
||||
endif
|
||||
let v:errmsg = 'fugitive: invalid Fugitive URL ' . path
|
||||
throw v:errmsg
|
||||
endfunction
|
||||
|
||||
" FugitiveResult() returns an object encapsulating the result of the most
|
||||
" recend :Git command. Will be empty if no result is available. Pass in the
|
||||
" name of a temp buffer to get the result object for that command instead.
|
||||
" Contains the following keys:
|
||||
"
|
||||
" * "args": List of command arguments, starting with the subcommand. Will be
|
||||
" empty for usages like :Git --help.
|
||||
" * "dir": Git dir of the relevant repository.
|
||||
" * "exit_status": The integer exit code of the process.
|
||||
" * "flags": Flags passed directly to Git, like -c and --help.
|
||||
" * "file": Path to file containing command output. Not guaranteed to exist,
|
||||
" so verify with filereadable() before trying to access it.
|
||||
function! FugitiveResult(...) abort
|
||||
return call('fugitive#Result', a:000)
|
||||
endfunction
|
||||
|
||||
" FugitivePrepare() constructs a Git command string which can be executed with
|
||||
" functions like system() and commands like :!. Integer arguments will be
|
||||
" treated as buffer numbers, and the appropriate relative path inserted in
|
||||
" their place.
|
||||
"
|
||||
" If the first argument is a string that looks like a path or an empty string,
|
||||
" it will be used as the Git dir. If it's a buffer number, the Git dir for
|
||||
" that buffer will be used. The default is the current buffer.
|
||||
function! FugitivePrepare(...) abort
|
||||
return call('fugitive#Prepare', a:000)
|
||||
endfunction
|
||||
|
||||
" FugitiveConfig() get returns an opaque structure that can be passed to other
|
||||
" FugitiveConfig functions in lieu of a Git directory. This can be faster
|
||||
" when performing multiple config queries. Do not rely on the internal
|
||||
" structure of the return value as it is not guaranteed. If you want a full
|
||||
" dictionary of every config value, use FugitiveConfigGetRegexp('.*').
|
||||
function! FugitiveConfig(...) abort
|
||||
return call('fugitive#Config', a:000)
|
||||
endfunction
|
||||
|
||||
" FugitiveConfigGet() retrieves a Git configuration value. An optional second
|
||||
" argument provides the Git dir as with FugitiveFind(). Pass a blank string
|
||||
" to limit to the global config.
|
||||
function! FugitiveConfigGet(name, ...) abort
|
||||
return get(call('FugitiveConfigGetAll', [a:name] + (a:0 ? [a:1] : [])), 0, get(a:, 2, ''))
|
||||
endfunction
|
||||
|
||||
" FugitiveConfigGetAll() is like FugitiveConfigGet() but returns a list of
|
||||
" all values.
|
||||
function! FugitiveConfigGetAll(name, ...) abort
|
||||
return call('fugitive#ConfigGetAll', [a:name] + a:000)
|
||||
endfunction
|
||||
|
||||
" FugitiveConfigGetRegexp() retrieves a dictionary of all configuration values
|
||||
" with a key matching the given pattern. Like git config --get-regexp, but
|
||||
" using a Vim regexp. Second argument has same semantics as
|
||||
" FugitiveConfigGet().
|
||||
function! FugitiveConfigGetRegexp(pattern, ...) abort
|
||||
return call('fugitive#ConfigGetRegexp', [a:pattern] + a:000)
|
||||
endfunction
|
||||
|
||||
function! FugitiveRemoteUrl(...) abort
|
||||
return fugitive#RemoteUrl(a:0 ? a:1 : '', FugitiveGitDir(a:0 > 1 ? a:2 : -1), a:0 > 2 ? a:3 : 0)
|
||||
endfunction
|
||||
|
||||
function! FugitiveHead(...) abort
|
||||
let dir = FugitiveGitDir(a:0 > 1 ? a:2 : -1)
|
||||
if empty(dir)
|
||||
return ''
|
||||
endif
|
||||
return fugitive#Head(a:0 ? a:1 : 0, dir)
|
||||
endfunction
|
||||
|
||||
function! FugitiveStatusline(...) abort
|
||||
if empty(get(b:, 'git_dir', ''))
|
||||
return ''
|
||||
endif
|
||||
return fugitive#Statusline()
|
||||
endfunction
|
||||
|
||||
function! FugitiveCommonDir(...) abort
|
||||
let dir = FugitiveGitDir(a:0 ? a:1 : -1)
|
||||
if empty(dir)
|
||||
return ''
|
||||
endif
|
||||
return fugitive#CommonDir(dir)
|
||||
endfunction
|
||||
|
||||
function! FugitiveWorkTree(...) abort
|
||||
return s:Tree(FugitiveGitDir(a:0 ? a:1 : -1))
|
||||
endfunction
|
||||
|
||||
function! FugitiveIsGitDir(path) abort
|
||||
let path = substitute(a:path, '[\/]$', '', '') . '/'
|
||||
return len(a:path) && getfsize(path.'HEAD') > 10 && (
|
||||
\ isdirectory(path.'objects') && isdirectory(path.'refs') ||
|
||||
\ getftype(path.'commondir') ==# 'file')
|
||||
endfunction
|
||||
|
||||
let s:worktree_for_dir = {}
|
||||
let s:dir_for_worktree = {}
|
||||
function! s:Tree(path) abort
|
||||
let dir = a:path
|
||||
if dir =~# '/\.git$'
|
||||
return len(dir) ==# 5 ? '/' : dir[0:-6]
|
||||
elseif dir ==# ''
|
||||
return ''
|
||||
endif
|
||||
if !has_key(s:worktree_for_dir, dir)
|
||||
let s:worktree_for_dir[dir] = ''
|
||||
let config_file = dir . '/config'
|
||||
if filereadable(config_file)
|
||||
let config = readfile(config_file,'',10)
|
||||
call filter(config,'v:val =~# "^\\s*worktree *="')
|
||||
if len(config) == 1
|
||||
let worktree = FugitiveVimPath(matchstr(config[0], '= *\zs.*'))
|
||||
endif
|
||||
elseif filereadable(dir . '/gitdir')
|
||||
let worktree = fnamemodify(FugitiveVimPath(readfile(dir . '/gitdir')[0]), ':h')
|
||||
if worktree ==# '.'
|
||||
unlet! worktree
|
||||
endif
|
||||
endif
|
||||
if exists('worktree')
|
||||
let s:worktree_for_dir[dir] = s:Slash(resolve(worktree))
|
||||
let s:dir_for_worktree[s:worktree_for_dir[dir]] = dir
|
||||
endif
|
||||
endif
|
||||
if s:worktree_for_dir[dir] =~# '^\.'
|
||||
return simplify(dir . '/' . s:worktree_for_dir[dir])
|
||||
else
|
||||
return s:worktree_for_dir[dir]
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! s:CeilingDirectories() abort
|
||||
if !exists('s:ceiling_directories')
|
||||
let s:ceiling_directories = []
|
||||
let resolve = 1
|
||||
for dir in split($GIT_CEILING_DIRECTORIES, has('win32') ? ';' : ':', 1)
|
||||
if empty(dir)
|
||||
let resolve = 0
|
||||
elseif resolve
|
||||
call add(s:ceiling_directories, resolve(dir))
|
||||
else
|
||||
call add(s:ceiling_directories, dir)
|
||||
endif
|
||||
endfor
|
||||
endif
|
||||
return s:ceiling_directories + get(g:, 'ceiling_directories', [])
|
||||
endfunction
|
||||
|
||||
function! FugitiveExtractGitDir(path) abort
|
||||
let path = s:Slash(a:path)
|
||||
if path =~# '^fugitive:'
|
||||
return matchstr(path, '\C^fugitive:\%(//\)\=\zs.\{-\}\ze\%(//\|::\|$\)')
|
||||
elseif empty(path)
|
||||
return ''
|
||||
elseif isdirectory(path)
|
||||
let path = fnamemodify(path, ':p:s?/$??')
|
||||
else
|
||||
let path = fnamemodify(path, ':p:h:s?/$??')
|
||||
endif
|
||||
let pre = substitute(matchstr(path, '^\a\a\+\ze:'), '^.', '\u&', '')
|
||||
if len(pre) && exists('*' . pre . 'Real')
|
||||
let path = s:Slash({pre}Real(path))
|
||||
endif
|
||||
let root = resolve(path)
|
||||
if root !=# path
|
||||
silent! exe (haslocaldir() ? 'lcd' : exists(':tcd') && haslocaldir(-1) ? 'tcd' : 'cd') '.'
|
||||
endif
|
||||
let previous = ""
|
||||
let env_git_dir = len($GIT_DIR) ? s:Slash(simplify(fnamemodify(FugitiveVimPath($GIT_DIR), ':p:s?[\/]$??'))) : ''
|
||||
call s:Tree(env_git_dir)
|
||||
while root !=# previous
|
||||
if root =~# '\v^//%([^/]+/?)?$'
|
||||
break
|
||||
endif
|
||||
if index(s:CeilingDirectories(), root) >= 0
|
||||
break
|
||||
endif
|
||||
if root ==# $GIT_WORK_TREE && FugitiveIsGitDir(env_git_dir)
|
||||
return env_git_dir
|
||||
elseif has_key(s:dir_for_worktree, root)
|
||||
return s:dir_for_worktree[root]
|
||||
endif
|
||||
let dir = substitute(root, '[\/]$', '', '') . '/.git'
|
||||
let type = getftype(dir)
|
||||
if type ==# 'dir' && FugitiveIsGitDir(dir)
|
||||
return dir
|
||||
elseif type ==# 'link' && FugitiveIsGitDir(dir)
|
||||
return resolve(dir)
|
||||
elseif type !=# '' && filereadable(dir)
|
||||
let line = get(readfile(dir, '', 1), 0, '')
|
||||
let file_dir = s:Slash(FugitiveVimPath(matchstr(line, '^gitdir: \zs.*')))
|
||||
if file_dir !~# '^/\|^\a:' && FugitiveIsGitDir(root . '/' . file_dir)
|
||||
return simplify(root . '/' . file_dir)
|
||||
elseif len(file_dir) && FugitiveIsGitDir(file_dir)
|
||||
return file_dir
|
||||
endif
|
||||
elseif FugitiveIsGitDir(root)
|
||||
return root
|
||||
endif
|
||||
let previous = root
|
||||
let root = fnamemodify(root, ':h')
|
||||
endwhile
|
||||
return ''
|
||||
endfunction
|
||||
|
||||
function! FugitiveDetect(path) abort
|
||||
if v:version < 704
|
||||
return ''
|
||||
endif
|
||||
if exists('b:git_dir') && b:git_dir =~# '^$\|' . s:bad_git_dir
|
||||
unlet b:git_dir
|
||||
endif
|
||||
if !exists('b:git_dir')
|
||||
let b:git_dir = FugitiveExtractGitDir(a:path)
|
||||
endif
|
||||
if empty(b:git_dir) || !exists('#User#Fugitive')
|
||||
return ''
|
||||
endif
|
||||
if v:version >= 704 || (v:version == 703 && has('patch442'))
|
||||
doautocmd <nomodeline> User Fugitive
|
||||
elseif &modelines > 0
|
||||
let modelines = &modelines
|
||||
try
|
||||
set modelines=0
|
||||
doautocmd User Fugitive
|
||||
finally
|
||||
let &modelines = modelines
|
||||
endtry
|
||||
else
|
||||
doautocmd User Fugitive
|
||||
endif
|
||||
return ''
|
||||
endfunction
|
||||
|
||||
function! FugitiveVimPath(path) abort
|
||||
if exists('+shellslash') && !&shellslash
|
||||
return tr(a:path, '/', '\')
|
||||
else
|
||||
return a:path
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! FugitiveGitPath(path) abort
|
||||
return s:Slash(a:path)
|
||||
endfunction
|
||||
|
||||
if exists('+shellslash')
|
||||
function! s:Slash(path) abort
|
||||
return tr(a:path, '\', '/')
|
||||
endfunction
|
||||
else
|
||||
function! s:Slash(path) abort
|
||||
return a:path
|
||||
endfunction
|
||||
endif
|
||||
|
||||
function! s:ProjectionistDetect() abort
|
||||
let file = s:Slash(get(g:, 'projectionist_file', ''))
|
||||
let dir = FugitiveExtractGitDir(file)
|
||||
let base = matchstr(file, '^fugitive://.\{-\}//\x\+')
|
||||
if empty(base)
|
||||
let base = s:Tree(dir)
|
||||
endif
|
||||
if len(base)
|
||||
if exists('+shellslash') && !&shellslash
|
||||
let base = tr(base, '/', '\')
|
||||
endif
|
||||
let file = FugitiveCommonDir(dir) . '/info/projections.json'
|
||||
if filereadable(file)
|
||||
call projectionist#append(base, file)
|
||||
endif
|
||||
endif
|
||||
endfunction
|
||||
|
||||
let s:addr_other = has('patch-8.1.560') ? '-addr=other' : ''
|
||||
let s:addr_tabs = has('patch-7.4.542') ? '-addr=tabs' : ''
|
||||
let s:addr_wins = has('patch-7.4.542') ? '-addr=windows' : ''
|
||||
|
||||
if exists(':G') != 2
|
||||
command! -bang -nargs=? -range=-1 -complete=customlist,fugitive#Complete G exe fugitive#Command(<line1>, <count>, +"<range>", <bang>0, "<mods>", <q-args>)
|
||||
endif
|
||||
command! -bang -nargs=? -range=-1 -complete=customlist,fugitive#Complete Git exe fugitive#Command(<line1>, <count>, +"<range>", <bang>0, "<mods>", <q-args>)
|
||||
|
||||
if exists(':Gstatus') != 2 && get(g:, 'fugitive_legacy_commands', 1)
|
||||
exe 'command! -bang -bar -range=-1' s:addr_other 'Gstatus exe fugitive#Command(<line1>, <count>, +"<range>", <bang>0, "<mods>", <q-args>)'
|
||||
\ '|echohl WarningMSG|echo ":Gstatus is deprecated in favor of :Git (with no arguments)"|echohl NONE'
|
||||
endif
|
||||
|
||||
for s:cmd in ['Commit', 'Revert', 'Merge', 'Rebase', 'Pull', 'Push', 'Fetch', 'Blame']
|
||||
if exists(':G' . tolower(s:cmd)) != 2 && get(g:, 'fugitive_legacy_commands', 1)
|
||||
exe 'command! -bang -nargs=? -range=-1 -complete=customlist,fugitive#' . s:cmd . 'Complete G' . tolower(s:cmd)
|
||||
\ 'echohl WarningMSG|echo ":G' . tolower(s:cmd) . ' is deprecated in favor of :Git ' . tolower(s:cmd) . '"|echohl NONE|'
|
||||
\ 'exe fugitive#Command(<line1>, <count>, +"<range>", <bang>0, "<mods>", "' . tolower(s:cmd) . ' " . <q-args>)'
|
||||
endif
|
||||
endfor
|
||||
unlet s:cmd
|
||||
|
||||
exe "command! -bar -bang -nargs=? -complete=customlist,fugitive#CdComplete Gcd exe fugitive#Cd(<q-args>, 0)"
|
||||
exe "command! -bar -bang -nargs=? -complete=customlist,fugitive#CdComplete Glcd exe fugitive#Cd(<q-args>, 1)"
|
||||
|
||||
exe 'command! -bang -nargs=? -range=-1' s:addr_wins '-complete=customlist,fugitive#GrepComplete Ggrep exe fugitive#GrepCommand(<line1>, <count>, +"<range>", <bang>0, "<mods>", <q-args>)'
|
||||
exe 'command! -bang -nargs=? -range=-1' s:addr_wins '-complete=customlist,fugitive#GrepComplete Gcgrep exe fugitive#GrepCommand(<line1>, <count>, +"<range>", <bang>0, "<mods>", <q-args>)'
|
||||
exe 'command! -bang -nargs=? -range=-1' s:addr_wins '-complete=customlist,fugitive#GrepComplete Glgrep exe fugitive#GrepCommand(0, <count> > 0 ? <count> : 0, +"<range>", <bang>0, "<mods>", <q-args>)'
|
||||
|
||||
if exists(':Glog') != 2 && get(g:, 'fugitive_legacy_commands', 1)
|
||||
exe 'command! -bang -nargs=? -range=-1 -complete=customlist,fugitive#LogComplete Glog :exe fugitive#LogCommand(<line1>,<count>,+"<range>",<bang>0,"<mods>",<q-args>, "")'
|
||||
\ '|echohl WarningMSG|echo ":Glog is deprecated in favor of :Gclog"|echohl NONE'
|
||||
endif
|
||||
exe 'command! -bang -nargs=? -range=-1 -complete=customlist,fugitive#LogComplete Gclog :exe fugitive#LogCommand(<line1>,<count>,+"<range>",<bang>0,"<mods>",<q-args>, "c")'
|
||||
exe 'command! -bang -nargs=? -range=-1 -complete=customlist,fugitive#LogComplete GcLog :exe fugitive#LogCommand(<line1>,<count>,+"<range>",<bang>0,"<mods>",<q-args>, "c")'
|
||||
exe 'command! -bang -nargs=? -range=-1 -complete=customlist,fugitive#LogComplete Gllog :exe fugitive#LogCommand(<line1>,<count>,+"<range>",<bang>0,"<mods>",<q-args>, "l")'
|
||||
exe 'command! -bang -nargs=? -range=-1 -complete=customlist,fugitive#LogComplete GlLog :exe fugitive#LogCommand(<line1>,<count>,+"<range>",<bang>0,"<mods>",<q-args>, "l")'
|
||||
|
||||
exe 'command! -bar -bang -nargs=* -complete=customlist,fugitive#EditComplete Ge exe fugitive#Open("edit<bang>", 0, "<mods>", <q-args>, [<f-args>])'
|
||||
exe 'command! -bar -bang -nargs=* -complete=customlist,fugitive#EditComplete Gedit exe fugitive#Open("edit<bang>", 0, "<mods>", <q-args>, [<f-args>])'
|
||||
exe 'command! -bar -bang -nargs=* -complete=customlist,fugitive#ReadComplete Gpedit exe fugitive#Open("pedit", <bang>0, "<mods>", <q-args>, [<f-args>])'
|
||||
exe 'command! -bar -bang -nargs=* -range=-1' s:addr_other '-complete=customlist,fugitive#ReadComplete Gsplit exe fugitive#Open((<count> > 0 ? <count> : "").(<count> ? "split" : "edit"), <bang>0, "<mods>", <q-args>, [<f-args>])'
|
||||
exe 'command! -bar -bang -nargs=* -range=-1' s:addr_other '-complete=customlist,fugitive#ReadComplete Gvsplit exe fugitive#Open((<count> > 0 ? <count> : "").(<count> ? "vsplit" : "edit!"), <bang>0, "<mods>", <q-args>, [<f-args>])'
|
||||
exe 'command! -bar -bang -nargs=* -range=-1' s:addr_tabs '-complete=customlist,fugitive#ReadComplete Gtabedit exe fugitive#Open((<count> >= 0 ? <count> : "")."tabedit", <bang>0, "<mods>", <q-args>, [<f-args>])'
|
||||
|
||||
if exists(':Gr') != 2
|
||||
exe 'command! -bar -bang -nargs=* -range=-1 -complete=customlist,fugitive#ReadComplete Gr exe fugitive#ReadCommand(<line1>, <count>, +"<range>", <bang>0, "<mods>", <q-args>, [<f-args>])'
|
||||
endif
|
||||
exe 'command! -bar -bang -nargs=* -range=-1 -complete=customlist,fugitive#ReadComplete Gread exe fugitive#ReadCommand(<line1>, <count>, +"<range>", <bang>0, "<mods>", <q-args>, [<f-args>])'
|
||||
|
||||
exe 'command! -bar -bang -nargs=* -complete=customlist,fugitive#EditComplete Gdiffsplit exe fugitive#Diffsplit(1, <bang>0, "<mods>", <q-args>, [<f-args>])'
|
||||
exe 'command! -bar -bang -nargs=* -complete=customlist,fugitive#EditComplete Ghdiffsplit exe fugitive#Diffsplit(0, <bang>0, "<mods>", <q-args>, [<f-args>])'
|
||||
exe 'command! -bar -bang -nargs=* -complete=customlist,fugitive#EditComplete Gvdiffsplit exe fugitive#Diffsplit(0, <bang>0, "vert <mods>", <q-args>, [<f-args>])'
|
||||
|
||||
exe 'command! -bar -bang -nargs=* -complete=customlist,fugitive#EditComplete Gw exe fugitive#WriteCommand(<line1>, <count>, +"<range>", <bang>0, "<mods>", <q-args>, [<f-args>])'
|
||||
exe 'command! -bar -bang -nargs=* -complete=customlist,fugitive#EditComplete Gwrite exe fugitive#WriteCommand(<line1>, <count>, +"<range>", <bang>0, "<mods>", <q-args>, [<f-args>])'
|
||||
exe 'command! -bar -bang -nargs=* -complete=customlist,fugitive#EditComplete Gwq exe fugitive#WqCommand( <line1>, <count>, +"<range>", <bang>0, "<mods>", <q-args>, [<f-args>])'
|
||||
|
||||
exe 'command! -bar -bang -nargs=0 -complete=customlist,fugitive#CompleteObject GRemove exe fugitive#RemoveCommand(<line1>, <count>, +"<range>", <bang>0, "<mods>", <q-args>, [<f-args>])'
|
||||
exe 'command! -bar -bang -nargs=0 -complete=customlist,fugitive#CompleteObject GDelete exe fugitive#DeleteCommand(<line1>, <count>, +"<range>", <bang>0, "<mods>", <q-args>, [<f-args>])'
|
||||
exe 'command! -bar -bang -nargs=1 -complete=customlist,fugitive#CompleteObject GMove exe fugitive#MoveCommand( <line1>, <count>, +"<range>", <bang>0, "<mods>", <q-args>, [<f-args>])'
|
||||
exe 'command! -bar -bang -nargs=1 -complete=customlist,fugitive#RenameComplete GRename exe fugitive#RenameCommand(<line1>, <count>, +"<range>", <bang>0, "<mods>", <q-args>, [<f-args>])'
|
||||
if exists(':Gremove') != 2 && get(g:, 'fugitive_legacy_commands', 1)
|
||||
exe 'command! -bar -bang -nargs=0 -complete=customlist,fugitive#CompleteObject Gremove exe fugitive#RemoveCommand(<line1>, <count>, +"<range>", <bang>0, "<mods>", <q-args>, [<f-args>])'
|
||||
\ '|echohl WarningMSG|echo ":Gremove is deprecated in favor of :GRemove"|echohl NONE'
|
||||
endif
|
||||
if exists(':Gdelete') != 2 && get(g:, 'fugitive_legacy_commands', 1)
|
||||
exe 'command! -bar -bang -nargs=0 -complete=customlist,fugitive#CompleteObject Gdelete exe fugitive#DeleteCommand(<line1>, <count>, +"<range>", <bang>0, "<mods>", <q-args>, [<f-args>])'
|
||||
\ '|echohl WarningMSG|echo ":Gdelete is deprecated in favor of :GDelete"|echohl NONE'
|
||||
endif
|
||||
if exists(':Gmove') != 2 && get(g:, 'fugitive_legacy_commands', 1)
|
||||
exe 'command! -bar -bang -nargs=1 -complete=customlist,fugitive#CompleteObject Gmove exe fugitive#MoveCommand( <line1>, <count>, +"<range>", <bang>0, "<mods>", <q-args>, [<f-args>])'
|
||||
\ '|echohl WarningMSG|echo ":Gmove is deprecated in favor of :GMove"|echohl NONE'
|
||||
endif
|
||||
if exists(':Grename') != 2 && get(g:, 'fugitive_legacy_commands', 1)
|
||||
exe 'command! -bar -bang -nargs=1 -complete=customlist,fugitive#RenameComplete Grename exe fugitive#RenameCommand(<line1>, <count>, +"<range>", <bang>0, "<mods>", <q-args>, [<f-args>])'
|
||||
\ '|echohl WarningMSG|echo ":Grename is deprecated in favor of :GRename"|echohl NONE'
|
||||
endif
|
||||
|
||||
exe 'command! -bar -bang -range=-1 -nargs=* -complete=customlist,fugitive#CompleteObject GBrowse exe fugitive#BrowseCommand(<line1>, <count>, +"<range>", <bang>0, "<mods>", <q-args>, [<f-args>])'
|
||||
if exists(':Gbrowse') != 2 && get(g:, 'fugitive_legacy_commands', 1)
|
||||
exe 'command! -bar -bang -range=-1 -nargs=* -complete=customlist,fugitive#CompleteObject Gbrowse exe fugitive#BrowseCommand(<line1>, <count>, +"<range>", <bang>0, "<mods>", <q-args>, [<f-args>])'
|
||||
\ '|if <bang>1|redraw!|endif|echohl WarningMSG|echo ":Gbrowse is deprecated in favor of :GBrowse"|echohl NONE'
|
||||
endif
|
||||
|
||||
if v:version < 704
|
||||
finish
|
||||
endif
|
||||
|
||||
let g:io_fugitive = {
|
||||
\ 'simplify': function('fugitive#simplify'),
|
||||
\ 'resolve': function('fugitive#resolve'),
|
||||
\ 'getftime': function('fugitive#getftime'),
|
||||
\ 'getfsize': function('fugitive#getfsize'),
|
||||
\ 'getftype': function('fugitive#getftype'),
|
||||
\ 'filereadable': function('fugitive#filereadable'),
|
||||
\ 'filewritable': function('fugitive#filewritable'),
|
||||
\ 'isdirectory': function('fugitive#isdirectory'),
|
||||
\ 'getfperm': function('fugitive#getfperm'),
|
||||
\ 'setfperm': function('fugitive#setfperm'),
|
||||
\ 'readfile': function('fugitive#readfile'),
|
||||
\ 'writefile': function('fugitive#writefile'),
|
||||
\ 'glob': function('fugitive#glob'),
|
||||
\ 'delete': function('fugitive#delete'),
|
||||
\ 'Real': function('FugitiveReal')}
|
||||
|
||||
augroup fugitive
|
||||
autocmd!
|
||||
|
||||
autocmd BufNewFile,BufReadPost * call FugitiveDetect(expand('<amatch>:p'))
|
||||
autocmd FileType netrw call FugitiveDetect(fnamemodify(get(b:, 'netrw_curdir', expand('<amatch>')), ':p'))
|
||||
|
||||
autocmd FileType git
|
||||
\ call fugitive#MapCfile()
|
||||
autocmd FileType gitcommit
|
||||
\ call fugitive#MapCfile('fugitive#MessageCfile()')
|
||||
autocmd FileType git,gitcommit
|
||||
\ if &foldtext ==# 'foldtext()' |
|
||||
\ setlocal foldtext=fugitive#Foldtext() |
|
||||
\ endif
|
||||
autocmd FileType fugitive
|
||||
\ call fugitive#MapCfile('fugitive#StatusCfile()')
|
||||
autocmd FileType gitrebase
|
||||
\ let &l:include = '^\%(pick\|squash\|edit\|reword\|fixup\|drop\|[pserfd]\)\>' |
|
||||
\ if &l:includeexpr !~# 'Fugitive' |
|
||||
\ let &l:includeexpr = 'v:fname =~# ''^\x\{4,\}$'' && len(FugitiveGitDir()) ? FugitiveFind(v:fname) : ' .
|
||||
\ (len(&l:includeexpr) ? &l:includeexpr : 'v:fname') |
|
||||
\ endif |
|
||||
\ let b:undo_ftplugin = get(b:, 'undo_ftplugin', 'exe') . '|setl inex= inc='
|
||||
|
||||
autocmd BufReadCmd index{,.lock}
|
||||
\ if FugitiveIsGitDir(expand('<amatch>:p:h')) |
|
||||
\ let b:git_dir = s:Slash(expand('<amatch>:p:h')) |
|
||||
\ exe fugitive#BufReadStatus() |
|
||||
\ elseif filereadable(expand('<amatch>')) |
|
||||
\ silent doautocmd BufReadPre |
|
||||
\ keepalt read <amatch> |
|
||||
\ 1delete_ |
|
||||
\ silent doautocmd BufReadPost |
|
||||
\ else |
|
||||
\ silent doautocmd BufNewFile |
|
||||
\ endif
|
||||
|
||||
autocmd BufReadCmd fugitive://*//* exe fugitive#BufReadCmd() |
|
||||
\ if &path =~# '^\.\%(,\|$\)' |
|
||||
\ let &l:path = substitute(&path, '^\.,\=', '', '') |
|
||||
\ endif
|
||||
autocmd BufWriteCmd fugitive://*//[0-3]/* exe fugitive#BufWriteCmd()
|
||||
autocmd FileReadCmd fugitive://*//* exe fugitive#FileReadCmd()
|
||||
autocmd FileWriteCmd fugitive://*//[0-3]/* exe fugitive#FileWriteCmd()
|
||||
if exists('##SourceCmd')
|
||||
autocmd SourceCmd fugitive://*//* nested exe fugitive#SourceCmd()
|
||||
endif
|
||||
|
||||
autocmd User Flags call Hoist('buffer', function('FugitiveStatusline'))
|
||||
|
||||
autocmd User ProjectionistDetect call s:ProjectionistDetect()
|
||||
augroup END
|
||||
|
||||
if get(g:, 'fugitive_no_maps')
|
||||
finish
|
||||
endif
|
||||
|
||||
let s:nowait = v:version >= 704 ? '<nowait>' : ''
|
||||
|
||||
function! s:Map(mode, lhs, rhs, ...) abort
|
||||
for mode in split(a:mode, '\zs')
|
||||
let flags = (a:0 ? a:1 : '') . (a:rhs =~# '<Plug>' ? '' : '<script>')
|
||||
let head = a:lhs
|
||||
let tail = ''
|
||||
let keys = get(g:, mode.'remap', {})
|
||||
if type(keys) == type([])
|
||||
return
|
||||
endif
|
||||
while !empty(head)
|
||||
if has_key(keys, head)
|
||||
let head = keys[head]
|
||||
if empty(head)
|
||||
return
|
||||
endif
|
||||
break
|
||||
endif
|
||||
let tail = matchstr(head, '<[^<>]*>$\|.$') . tail
|
||||
let head = substitute(head, '<[^<>]*>$\|.$', '', '')
|
||||
endwhile
|
||||
if flags !~# '<unique>' || empty(mapcheck(head.tail, mode))
|
||||
exe mode.'map' s:nowait flags head.tail a:rhs
|
||||
endif
|
||||
endfor
|
||||
endfunction
|
||||
|
||||
call s:Map('c', '<C-R><C-G>', 'fnameescape(fugitive#Object(@%))', '<expr>')
|
||||
call s:Map('n', 'y<C-G>', ':<C-U>call setreg(v:register, fugitive#Object(@%))<CR>', '<silent>')
|
@ -1,57 +0,0 @@
|
||||
if exists("b:current_syntax")
|
||||
finish
|
||||
endif
|
||||
|
||||
syn sync fromstart
|
||||
syn spell notoplevel
|
||||
|
||||
syn include @fugitiveDiff syntax/diff.vim
|
||||
|
||||
syn match fugitiveHeader /^[A-Z][a-z][^:]*:/ nextgroup=fugitiveHash,fugitiveSymbolicRef skipwhite
|
||||
syn match fugitiveBareHeader /^Bare:/
|
||||
syn match fugitiveHelpHeader /^Help:/ nextgroup=fugitiveHelpTag skipwhite
|
||||
syn match fugitiveHelpTag /\S\+/ contained
|
||||
|
||||
syn region fugitiveSection start=/^\%(.*(\d\+)$\)\@=/ contains=fugitiveHeading end=/^$/
|
||||
syn cluster fugitiveSection contains=fugitiveSection
|
||||
syn match fugitiveHeading /^[A-Z][a-z][^:]*\ze (\d\+)$/ contains=fugitivePreposition contained nextgroup=fugitiveCount skipwhite
|
||||
syn match fugitiveCount /(\d\+)/hs=s+1,he=e-1 contained
|
||||
syn match fugitivePreposition /\<\%([io]nto\|from\|to\|Rebasing\%( detached\)\=\)\>/ transparent contained nextgroup=fugitiveHash,fugitiveSymbolicRef skipwhite
|
||||
|
||||
syn match fugitiveInstruction /^\l\l\+\>/ contained containedin=@fugitiveSection nextgroup=fugitiveHash skipwhite
|
||||
syn match fugitiveDone /^done\>/ contained containedin=@fugitiveSection nextgroup=fugitiveHash skipwhite
|
||||
syn match fugitiveStop /^stop\>/ contained containedin=@fugitiveSection nextgroup=fugitiveHash skipwhite
|
||||
syn match fugitiveModifier /^[MADRCU?]\{1,2} / contained containedin=@fugitiveSection
|
||||
syn match fugitiveSymbolicRef /\.\@!\%(\.\.\@!\|[^[:space:][:cntrl:]\:.]\)\+\.\@<!/ contained
|
||||
syn match fugitiveHash /^\x\{4,\}\S\@!/ contained containedin=@fugitiveSection
|
||||
syn match fugitiveHash /\S\@<!\x\{4,\}\S\@!/ contained
|
||||
|
||||
syn region fugitiveHunk start=/^\%(@@\+ -\)\@=/ end=/^\%([A-Za-z?@]\|$\)\@=/ contains=diffLine,diffRemoved,diffAdded,diffNoEOL containedin=@fugitiveSection fold
|
||||
|
||||
for s:section in ['Untracked', 'Unstaged', 'Staged']
|
||||
exe 'syn region fugitive' . s:section . 'Section start=/^\%(' . s:section . ' .*(\d\+)$\)\@=/ contains=fugitive' . s:section . 'Heading end=/^$/'
|
||||
exe 'syn match fugitive' . s:section . 'Modifier /^[MADRCU?] / contained containedin=fugitive' . s:section . 'Section'
|
||||
exe 'syn cluster fugitiveSection add=fugitive' . s:section . 'Section'
|
||||
exe 'syn match fugitive' . s:section . 'Heading /^[A-Z][a-z][^:]*\ze (\d\+)$/ contains=fugitivePreposition contained nextgroup=fugitiveCount skipwhite'
|
||||
endfor
|
||||
unlet s:section
|
||||
|
||||
hi def link fugitiveBareHeader fugitiveHeader
|
||||
hi def link fugitiveHelpHeader fugitiveHeader
|
||||
hi def link fugitiveHeader Label
|
||||
hi def link fugitiveHelpTag Tag
|
||||
hi def link fugitiveHeading PreProc
|
||||
hi def link fugitiveUntrackedHeading PreCondit
|
||||
hi def link fugitiveUnstagedHeading Macro
|
||||
hi def link fugitiveStagedHeading Include
|
||||
hi def link fugitiveModifier Type
|
||||
hi def link fugitiveUntrackedModifier StorageClass
|
||||
hi def link fugitiveUnstagedModifier Structure
|
||||
hi def link fugitiveStagedModifier Typedef
|
||||
hi def link fugitiveInstruction Type
|
||||
hi def link fugitiveStop Function
|
||||
hi def link fugitiveHash Identifier
|
||||
hi def link fugitiveSymbolicRef Function
|
||||
hi def link fugitiveCount Number
|
||||
|
||||
let b:current_syntax = "fugitive"
|
@ -1,7 +0,0 @@
|
||||
if exists("b:current_syntax") || !exists("*FugitiveGitDir")
|
||||
finish
|
||||
endif
|
||||
|
||||
call fugitive#BlameSyntax()
|
||||
|
||||
let b:current_syntax = "fugitiveblame"
|
Loading…
Reference in New Issue
Block a user