diff options
author | w0rp <devw0rp@gmail.com> | 2017-11-11 13:44:05 +0000 |
---|---|---|
committer | w0rp <devw0rp@gmail.com> | 2017-11-11 13:44:12 +0000 |
commit | 8c1d6eda81d408de767916c00d20139ddf6fc9c6 (patch) | |
tree | 71922e7a086219ead03fc8a5fcf76d43f527f37f /autoload | |
parent | 6c014a25e86c864c893c59ee3f30ce80cfd5fbb6 (diff) | |
download | ale-8c1d6eda81d408de767916c00d20139ddf6fc9c6.zip |
#1095 Apply all patterns for g:ale_pattern_options, instead of just the first match
Diffstat (limited to 'autoload')
-rw-r--r-- | autoload/ale/pattern_options.vim | 40 | ||||
-rw-r--r-- | autoload/ale/toggle.vim | 5 |
2 files changed, 27 insertions, 18 deletions
diff --git a/autoload/ale/pattern_options.vim b/autoload/ale/pattern_options.vim index a603c980..a55a27f6 100644 --- a/autoload/ale/pattern_options.vim +++ b/autoload/ale/pattern_options.vim @@ -1,22 +1,34 @@ " Author: w0rp <devw0rp@gmail.com> " Description: Set options in files based on regex patterns. -function! ale#pattern_options#SetOptions() abort - let l:filename = expand('%:p') " no-custom-checks - let l:options = {} +function! s:CmpPatterns(left_item, right_item) abort + if a:left_item[0] < a:right_item[0] + return -1 + endif - for l:pattern in keys(g:ale_pattern_options) - if match(l:filename, l:pattern) >= 0 - let l:options = g:ale_pattern_options[l:pattern] - break - endif - endfor + if a:left_item[0] > a:right_item[0] + return 1 + endif + + return 0 +endfunction + +function! ale#pattern_options#SetOptions(buffer) abort + if !g:ale_pattern_options_enabled || empty(g:ale_pattern_options) + return + endif - for l:key in keys(l:options) - if l:key[:0] is# '&' - call setbufvar(bufnr(''), l:key, l:options[l:key]) - else - let b:[l:key] = l:options[l:key] + let l:filename = expand('#' . a:buffer . ':p') + + " The patterns are sorted, so they are applied consistently. + for [l:pattern, l:options] in sort( + \ items(g:ale_pattern_options), + \ function('s:CmpPatterns') + \) + if match(l:filename, l:pattern) >= 0 + for [l:key, l:value] in items(l:options) + call setbufvar(a:buffer, l:key, l:value) + endfor endif endfor endfunction diff --git a/autoload/ale/toggle.vim b/autoload/ale/toggle.vim index 6809edd1..aa6d113b 100644 --- a/autoload/ale/toggle.vim +++ b/autoload/ale/toggle.vim @@ -4,9 +4,7 @@ function! ale#toggle#InitAuGroups() abort augroup ALEPatternOptionsGroup autocmd! - if g:ale_enabled && g:ale_pattern_options_enabled - autocmd BufEnter,BufRead * call ale#pattern_options#SetOptions() - endif + autocmd BufEnter,BufRead * call ale#pattern_options#SetOptions(str2nr(expand('<abuf>'))) augroup END augroup ALERunOnTextChangedGroup @@ -71,7 +69,6 @@ function! ale#toggle#InitAuGroups() abort augroup END if !g:ale_enabled - augroup! ALEPatternOptionsGroup augroup! ALERunOnTextChangedGroup augroup! ALERunOnEnterGroup augroup! ALERunOnInsertLeave |