spacevim/bundle/vim-matchup/autoload/matchup/util.vim
JIe 2bb7059579
Some checks failed
Detach Plugins / check (FlyGrep.vim) (push) Has been cancelled
Detach Plugins / check (GitHub.vim) (push) Has been cancelled
Detach Plugins / check (JavaUnit.vim) (push) Has been cancelled
Detach Plugins / check (SourceCounter.vim) (push) Has been cancelled
Detach Plugins / check (cpicker.nvim) (push) Has been cancelled
Detach Plugins / check (dein-ui.vim) (push) Has been cancelled
Detach Plugins / check (git.vim) (push) Has been cancelled
Detach Plugins / check (iedit.vim) (push) Has been cancelled
Detach Plugins / check (scrollbar.vim) (push) Has been cancelled
Detach Plugins / check (vim-chat) (push) Has been cancelled
Detach Plugins / check (vim-cheat) (push) Has been cancelled
Detach Plugins / check (vim-todo) (push) Has been cancelled
Detach Plugins / check (xmake.vim) (push) Has been cancelled
test / Linux (nvim, nightly) (push) Has been cancelled
test / Linux (nvim, v0.3.8) (push) Has been cancelled
test / Linux (nvim, v0.4.0) (push) Has been cancelled
test / Linux (nvim, v0.4.2) (push) Has been cancelled
test / Linux (nvim, v0.4.3) (push) Has been cancelled
test / Linux (nvim, v0.4.4) (push) Has been cancelled
test / Linux (nvim, v0.5.0) (push) Has been cancelled
test / Linux (nvim, v0.5.1) (push) Has been cancelled
test / Linux (nvim, v0.6.0) (push) Has been cancelled
test / Linux (nvim, v0.6.1) (push) Has been cancelled
test / Linux (nvim, v0.7.0) (push) Has been cancelled
test / Linux (nvim, v0.7.2) (push) Has been cancelled
test / Linux (nvim, v0.8.0) (push) Has been cancelled
test / Linux (nvim, v0.8.1) (push) Has been cancelled
test / Linux (nvim, v0.8.2) (push) Has been cancelled
test / Linux (nvim, v0.8.3) (push) Has been cancelled
test / Linux (nvim, v0.9.0) (push) Has been cancelled
test / Linux (nvim, v0.9.1) (push) Has been cancelled
test / Linux (true, vim, v7.4.052) (push) Has been cancelled
test / Linux (true, vim, v7.4.1689) (push) Has been cancelled
test / Linux (true, vim, v7.4.629) (push) Has been cancelled
test / Linux (true, vim, v8.0.0027) (push) Has been cancelled
test / Linux (true, vim, v8.0.0183) (push) Has been cancelled
test / Linux (vim, nightly) (push) Has been cancelled
test / Linux (vim, v8.0.0184) (push) Has been cancelled
test / Linux (vim, v8.0.1453) (push) Has been cancelled
test / Linux (vim, v8.1.2269) (push) Has been cancelled
test / Linux (vim, v8.2.2434) (push) Has been cancelled
test / Linux (vim, v8.2.3995) (push) Has been cancelled
test / Windows (nvim, nightly) (push) Has been cancelled
test / Windows (nvim, v0.3.8) (push) Has been cancelled
test / Windows (nvim, v0.4.2) (push) Has been cancelled
test / Windows (nvim, v0.4.3) (push) Has been cancelled
test / Windows (nvim, v0.4.4) (push) Has been cancelled
test / Windows (nvim, v0.5.0) (push) Has been cancelled
test / Windows (nvim, v0.5.1) (push) Has been cancelled
test / Windows (nvim, v0.6.0) (push) Has been cancelled
test / Windows (nvim, v0.6.1) (push) Has been cancelled
test / Windows (nvim, v0.7.0) (push) Has been cancelled
test / Windows (nvim, v0.7.2) (push) Has been cancelled
test / Windows (nvim, v0.8.0) (push) Has been cancelled
test / Windows (nvim, v0.8.1) (push) Has been cancelled
test / Windows (nvim, v0.8.2) (push) Has been cancelled
test / Windows (nvim, v0.8.3) (push) Has been cancelled
test / Windows (nvim, v0.9.0) (push) Has been cancelled
test / Windows (nvim, v0.9.1) (push) Has been cancelled
test / Windows (vim, nightly) (push) Has been cancelled
test / Windows (vim, v7.4.1185) (push) Has been cancelled
test / Windows (vim, v7.4.1689) (push) Has been cancelled
test / Windows (vim, v8.0.0027) (push) Has been cancelled
test / Windows (vim, v8.0.1453) (push) Has been cancelled
test / Windows (vim, v8.1.2269) (push) Has been cancelled
test / Windows (vim, v8.2.2434) (push) Has been cancelled
test / Windows (vim, v8.2.3995) (push) Has been cancelled
docker / docker (push) Has been cancelled
mirror / check (coding) (push) Has been cancelled
mirror / check (gitee) (push) Has been cancelled
mirror / check (gitlab) (push) Has been cancelled
init
2024-08-21 14:17:26 +08:00

154 lines
3.6 KiB
VimL

" vim match-up - even better matching
"
" Maintainer: Andy Massimino
" Email: a@normed.space
"
let s:save_cpo = &cpo
set cpo&vim
function! matchup#util#command(cmd) " {{{1
let l:lines = ''
try
silent! redir => l:lines
silent! execute a:cmd
redir END
finally
return split(l:lines, '\n')
endtry
endfunction
" }}}1
function! matchup#util#in_comment(...) " {{{1
return call('matchup#util#in_syntax', ['^Comment$'] + a:000)
endfunction
" }}}1
function! matchup#util#in_string(...) " {{{1
return call('matchup#util#in_syntax', ['^String$'] + a:000)
endfunction
" }}}1
function! matchup#util#in_comment_or_string(...) " {{{1
return call('matchup#util#in_syntax',
\ ['^\%(String\|Comment\)$'] + a:000)
endfunction
" }}}1
function! matchup#util#in_syntax(name, ...) " {{{1
" usage: matchup#util#in_syntax(name, [line, col])
let l:pos = a:0 > 0 ? [a:1, a:2] : [line('.'), col('.')]
" check syntax at position (same as matchit's s: method)
let l:syn = synIDattr(synID(l:pos[0], l:pos[1], 1), 'name')
return l:syn =~? a:name
endfunction
" }}}1
function! matchup#util#in_whitespace(...) " {{{1
let l:pos = a:0 > 0 ? [a:1, a:2] : [line('.'), col('.')]
return matchstr(getline(l:pos[0]), '\%'.l:pos[1].'c.') =~# '\s'
endfunction
" }}}1
function! matchup#util#in_indent(...) " {{{1
let l:pos = a:0 > 0 ? [a:1, a:2] : [line('.'), col('.')]
return l:pos[1] > 0 && getline(l:pos[0]) =~# '^\s*\%'.(l:pos[1]+1).'c'
endfunction
" }}}1
function! matchup#util#uniq(list) " {{{1
if exists('*uniq') | return uniq(a:list) | endif
if len(a:list) <= 1 | return a:list | endif
let l:uniq = [a:list[0]]
for l:next in a:list[1:]
if l:uniq[-1] != l:next
call add(l:uniq, l:next)
endif
endfor
return l:uniq
endfunction
" }}}1
function! matchup#util#uniq_unsorted(list) " {{{1
if len(a:list) <= 1 | return a:list | endif
let l:visited = [a:list[0]]
for l:index in reverse(range(1, len(a:list)-1))
if index(l:visited, a:list[l:index]) >= 0
call remove(a:list, l:index)
else
call add(l:visited, a:list[l:index])
endif
endfor
return a:list
endfunction
" }}}1
function! matchup#util#has_duplicate_str(list) " {{{1
if len(a:list) <= 1 | return 0 | endif
let l:seen = {}
for l:elem in a:list
if has_key(l:seen, l:elem)
return 1
endif
let l:seen[l:elem] = 1
endfor
return 0
endfunction
" }}}1
function! matchup#util#patch_match_words(from, to, ...) abort " {{{1
if !exists('b:match_words') | return | endif
" if extra argument is given, give diagnostic information
if a:0
let l:first = stridx(b:match_words, a:from)
if l:first < 0
echoerr 'match-up: patch_match_words:' a:from 'not found'
return
elseif stridx(b:match_words, a:from, l:first+1) > -1
echoerr 'match-up: patch_match_words: multiple occurences of' a:from
return
endif
endif
let b:match_words = substitute(b:match_words,
\ '\V'.escape(a:from, '\'),
\ escape(a:to, '\'),
\ '')
endfunction
" }}}1
function! matchup#util#check_match_words(sha256) " {{{1
if !exists('b:match_words') | return 0 | endif
return sha256(b:match_words) =~# '^'.a:sha256
endfunction
" }}}1
function! matchup#util#append_match_words(str) abort " {{{1
if !exists('b:match_words') | return | endif
if len(b:match_words) && b:match_words[-1] !=# ',' && a:str[0] !=# ','
let b:match_words .= ','
endif
let b:match_words .= a:str
endfunction
" }}}1
function! matchup#util#matchpref(id, default) " {{{1
return get(get(g:matchup_matchpref, &filetype, {}), a:id, a:default)
endfunction
" }}}1
let &cpo = s:save_cpo
" vim: fdm=marker sw=2