Fix #1619 - Rewrite lint on enter events so they behave better

This commit is contained in:
w0rp
2018-07-17 00:18:20 +01:00
parent 37df1f8ceb
commit a01fab2ee6
12 changed files with 156 additions and 116 deletions

View File

@@ -1,11 +1,6 @@
" Author: w0rp <devw0rp@gmail.com>
" Description: Set options in files based on regex patterns.
" A dictionary mapping regular expression patterns to arbitrary buffer
" variables to be set. Useful for configuring ALE based on filename patterns.
let g:ale_pattern_options = get(g:, 'ale_pattern_options', {})
let g:ale_pattern_options_enabled = get(g:, 'ale_pattern_options_enabled', !empty(g:ale_pattern_options))
" These variables are used to cache the sorting of patterns below.
let s:last_pattern_options = {}
let s:sorted_items = []
@@ -23,17 +18,19 @@ function! s:CmpPatterns(left_item, right_item) abort
endfunction
function! ale#pattern_options#SetOptions(buffer) abort
if !get(g:, 'ale_pattern_options_enabled', 0)
\|| empty(get(g:, 'ale_pattern_options', 0))
let l:pattern_options = get(g:, 'ale_pattern_options', {})
if empty(l:pattern_options)
" Stop if no options are set.
return
endif
" The items will only be sorted whenever the patterns change.
if g:ale_pattern_options != s:last_pattern_options
let s:last_pattern_options = deepcopy(g:ale_pattern_options)
if l:pattern_options != s:last_pattern_options
let s:last_pattern_options = deepcopy(l:pattern_options)
" The patterns are sorted, so they are applied consistently.
let s:sorted_items = sort(
\ items(g:ale_pattern_options),
\ items(l:pattern_options),
\ function('s:CmpPatterns')
\)
endif