diff options
author | w0rp <devw0rp@gmail.com> | 2017-04-18 00:35:53 +0100 |
---|---|---|
committer | w0rp <devw0rp@gmail.com> | 2017-04-18 00:35:53 +0100 |
commit | bdad25eefd6526f8130f97edbe25a1179e27aadc (patch) | |
tree | c2e563e959121e77f6d96a256583849f6851f0a4 /autoload | |
parent | e237add9fdec64c80ed57f383e2b73464fb4b43d (diff) | |
download | ale-bdad25eefd6526f8130f97edbe25a1179e27aadc.zip |
Add a function for getting matches, and use it to simplify a lot of code
Diffstat (limited to 'autoload')
-rw-r--r-- | autoload/ale/util.vim | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/autoload/ale/util.vim b/autoload/ale/util.vim index 37085432..b796d638 100644 --- a/autoload/ale/util.vim +++ b/autoload/ale/util.vim @@ -101,3 +101,27 @@ endfunction function! ale#util#ClockMilliseconds() abort return float2nr(reltimefloat(reltime()) * 1000) endfunction + +" Given a single line, or a List of lines, and a single pattern, or a List +" of patterns, return all of the matches for the lines(s) from the given +" patterns, using matchlist(). +" +" Only the first pattern which matches a line will be returned. +function! ale#util#GetMatches(lines, patterns) abort + let l:matches = [] + let l:lines = type(a:lines) == type([]) ? a:lines : [a:lines] + let l:patterns = type(a:patterns) == type([]) ? a:patterns : [a:patterns] + + for l:line in l:lines + for l:pattern in l:patterns + let l:match = matchlist(l:line, l:pattern) + + if !empty(l:match) + call add(l:matches, l:match) + break + endif + endfor + endfor + + return l:matches +endfunction |