mirror of
https://github.com/dense-analysis/ale.git
synced 2025-12-16 01:07:06 +08:00
#1095 Apply all patterns for g:ale_pattern_options, instead of just the first match
This commit is contained in:
@@ -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 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
|
||||
|
||||
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
|
||||
let l:options = g:ale_pattern_options[l:pattern]
|
||||
break
|
||||
endif
|
||||
endfor
|
||||
|
||||
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]
|
||||
for [l:key, l:value] in items(l:options)
|
||||
call setbufvar(a:buffer, l:key, l:value)
|
||||
endfor
|
||||
endif
|
||||
endfor
|
||||
endfunction
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user