From 24d277384ce98f4e38f0bfdf45a9cebbf940b213 Mon Sep 17 00:00:00 2001 From: w0rp Date: Mon, 15 Apr 2019 23:15:18 +0100 Subject: [PATCH] #1930 - Add ale_fix_on_save_ignore for disabling some fixers on save --- autoload/ale/fix.vim | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/autoload/ale/fix.vim b/autoload/ale/fix.vim index c0f05611..f5a3c0c2 100644 --- a/autoload/ale/fix.vim +++ b/autoload/ale/fix.vim @@ -1,3 +1,5 @@ +call ale#Set('fix_on_save_ignore', {}) + " Apply fixes queued up for buffers which may be hidden. " Vim doesn't let you modify hidden buffers. function! ale#fix#ApplyQueuedFixes() abort @@ -265,7 +267,21 @@ function! s:AddSubCallbacks(full_list, callbacks) abort return 1 endfunction -function! s:GetCallbacks(buffer, fixers) abort +function! s:IgnoreFixers(callback_list, filetype, config) abort + if type(a:config) is v:t_list + let l:ignore_list = a:config + endif + + let l:ignore_list = [] + + for l:part in split(a:filetype , '\.') + call extend(l:ignore_list, get(a:config, l:part, [])) + endfor + + call filter(a:callback_list, 'index(l:ignore_list, v:val) < 0') +endfunction + +function! s:GetCallbacks(buffer, fixing_flag, fixers) abort if len(a:fixers) let l:callback_list = a:fixers elseif type(get(b:, 'ale_fixers')) is v:t_list @@ -290,8 +306,12 @@ function! s:GetCallbacks(buffer, fixers) abort endif endif - if empty(l:callback_list) - return [] + if a:fixing_flag is# 'save_file' + let l:config = ale#Var(a:buffer, 'fix_on_save_ignore') + + if !empty(l:config) + call s:IgnoreFixers(l:callback_list, &filetype, l:config) + endif endif let l:corrected_list = [] @@ -339,7 +359,7 @@ function! ale#fix#Fix(buffer, fixing_flag, ...) abort endif try - let l:callback_list = s:GetCallbacks(a:buffer, a:000) + let l:callback_list = s:GetCallbacks(a:buffer, a:fixing_flag, a:000) catch /E700\|BADNAME/ let l:function_name = join(split(split(v:exception, ':')[3])) let l:echo_message = printf(