summaryrefslogtreecommitdiff
path: root/autoload
diff options
context:
space:
mode:
authorw0rp <devw0rp@gmail.com>2018-04-13 20:59:05 +0100
committerw0rp <devw0rp@gmail.com>2018-04-13 20:59:05 +0100
commitf5f3424fcf23b942257892537491d61decbe7aa9 (patch)
tree252c42d7946babe1781b814ba90c68aa2c44fe9f /autoload
parent56c7957a75d08b011c44cda7ec55864dd7cb5d31 (diff)
downloadale-f5f3424fcf23b942257892537491d61decbe7aa9.zip
#1501 Pass the buffer number from BufWritePost on to ale#fix#Fix
Diffstat (limited to 'autoload')
-rw-r--r--autoload/ale/events.vim2
-rw-r--r--autoload/ale/fix.vim28
2 files changed, 11 insertions, 19 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,
\})