diff options
-rw-r--r-- | autoload/ale/events.vim | 2 | ||||
-rw-r--r-- | autoload/ale/fix.vim | 28 | ||||
-rw-r--r-- | plugin/ale.vim | 2 |
3 files changed, 12 insertions, 20 deletions
diff --git a/autoload/ale/events.vim b/autoload/ale/events.vim index c7d17ea5..3d2aa32d 100644 --- a/autoload/ale/events.vim +++ b/autoload/ale/events.vim @@ -19,7 +19,7 @@ function! ale#events#SaveEvent(buffer) abort endif if ale#Var(a:buffer, 'fix_on_save') - let l:will_fix = ale#fix#Fix('save_file') + let l:will_fix = ale#fix#Fix(a:buffer, 'save_file') let l:should_lint = l:should_lint && !l:will_fix endif diff --git a/autoload/ale/fix.vim b/autoload/ale/fix.vim index 398f57d0..197a1862 100644 --- a/autoload/ale/fix.vim +++ b/autoload/ale/fix.vim @@ -356,14 +356,14 @@ function! s:RunFixer(options) abort call ale#fix#ApplyFixes(l:buffer, l:input) endfunction -function! s:GetCallbacks() abort +function! s:GetCallbacks(buffer) abort if type(get(b:, 'ale_fixers')) is type([]) " Lists can be used for buffer-local variables only let l:callback_list = b:ale_fixers else " buffer and global options can use dictionaries mapping filetypes to " callbacks to run. - let l:fixers = ale#Var(bufnr(''), 'fixers') + let l:fixers = ale#Var(a:buffer, 'fixers') let l:callback_list = [] for l:sub_type in split(&filetype, '\.') @@ -422,19 +422,13 @@ endfunction " Accepts an optional argument for what to do when fixing. " " Returns 0 if no fixes can be applied, and 1 if fixing can be done. -function! ale#fix#Fix(...) abort - if len(a:0) > 1 - throw 'too many arguments!' - endif - - let l:fixing_flag = get(a:000, 0, '') - - if l:fixing_flag isnot# '' && l:fixing_flag isnot# 'save_file' +function! ale#fix#Fix(buffer, fixing_flag) abort + if a:fixing_flag isnot# '' && a:fixing_flag isnot# 'save_file' throw "fixing_flag must be either '' or 'save_file'" endif try - let l:callback_list = s:GetCallbacks() + let l:callback_list = s:GetCallbacks(a:buffer) catch /E700\|BADNAME/ let l:function_name = join(split(split(v:exception, ':')[3])) let l:echo_message = printf( @@ -447,29 +441,27 @@ function! ale#fix#Fix(...) abort endtry if empty(l:callback_list) - if l:fixing_flag is# '' + if a:fixing_flag is# '' execute 'echom ''No fixers have been defined. Try :ALEFixSuggest''' endif return 0 endif - let l:buffer = bufnr('') - for l:job_id in keys(s:job_info_map) call remove(s:job_info_map, l:job_id) call ale#job#Stop(l:job_id) endfor " Clean up any files we might have left behind from a previous run. - call ale#fix#RemoveManagedFiles(l:buffer) - call ale#fix#InitBufferData(l:buffer, l:fixing_flag) + call ale#fix#RemoveManagedFiles(a:buffer) + call ale#fix#InitBufferData(a:buffer, a:fixing_flag) silent doautocmd <nomodeline> User ALEFixPre call s:RunFixer({ - \ 'buffer': l:buffer, - \ 'input': g:ale_fix_buffer_data[l:buffer].lines_before, + \ 'buffer': a:buffer, + \ 'input': g:ale_fix_buffer_data[a:buffer].lines_before, \ 'callback_index': 0, \ 'callback_list': l:callback_list, \}) diff --git a/plugin/ale.vim b/plugin/ale.vim index 56d5c447..d64229b3 100644 --- a/plugin/ale.vim +++ b/plugin/ale.vim @@ -263,7 +263,7 @@ command! -bar ALEInfoToClipboard :call ale#debugging#InfoToClipboard() command! -bar -nargs=1 ALEInfoToFile :call ale#debugging#InfoToFile(<f-args>) " Fix problems in files. -command! -bar ALEFix :call ale#fix#Fix() +command! -bar ALEFix :call ale#fix#Fix(bufnr(''), '') " Suggest registered functions to use for fixing problems. command! -bar ALEFixSuggest :call ale#fix#registry#Suggest(&filetype) |