Skip to content

Commit

Permalink
Update end_line when using g:neoformat_run_all_formatters
Browse files Browse the repository at this point in the history
Picked from: sbdchd#257
  • Loading branch information
novadev94 committed Feb 17, 2020
1 parent b7ccdb2 commit 6bd5c88
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions autoload/neoformat.vim
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ function! neoformat#Neoformat(bang, user_input, start_line, end_line) abort
endfunction

function! s:neoformat(bang, user_input, start_line, end_line) abort
let start_line = a:start_line
let end_line = a:end_line

if !&modifiable
return neoformat#utils#warn('buffer not modifiable')
endif

let using_visual_selection = a:start_line != 1 || a:end_line != line('$')
let using_visual_selection = start_line != 1 || end_line != line('$')

let inputs = split(a:user_input)
if a:bang
Expand Down Expand Up @@ -75,7 +77,7 @@ function! s:neoformat(bang, user_input, start_line, end_line) abort
continue
endif

let stdin = getbufline(bufnr('%'), a:start_line, a:end_line)
let stdin = getbufline(bufnr('%'), start_line, end_line)
let original_buffer = getbufline(bufnr('%'), 1, '$')

call neoformat#utils#log(stdin)
Expand All @@ -102,15 +104,15 @@ function! s:neoformat(bang, user_input, start_line, end_line) abort
call neoformat#utils#log(v:shell_error)

let process_ran_succesfully = index(cmd.valid_exit_codes, v:shell_error) != -1

if cmd.stderr_log != ''
call neoformat#utils#log('stderr output redirected to file' . cmd.stderr_log)
call neoformat#utils#log_file_content(cmd.stderr_log)
endif
if process_ran_succesfully
" 1. append the lines that are before and after the formatterd content
let lines_after = getbufline(bufnr('%'), a:end_line + 1, '$')
let lines_before = getbufline(bufnr('%'), 1, a:start_line - 1)
let lines_after = getbufline(bufnr('%'), end_line + 1, '$')
let lines_before = getbufline(bufnr('%'), 1, start_line - 1)

let new_buffer = lines_before + stdout + lines_after
if new_buffer !=# original_buffer
Expand All @@ -128,6 +130,9 @@ function! s:neoformat(bang, user_input, start_line, end_line) abort
if !neoformat#utils#var('neoformat_run_all_formatters')
return neoformat#utils#msg(endmsg)
endif
" If the number of lines changed, update the end_line so that the
" next formatter grabs the correct lines
let end_line = a:start_line + len(stdout)
call neoformat#utils#log('running next formatter')
else
call add(formatters_failed, cmd.name)
Expand Down

0 comments on commit 6bd5c88

Please sign in to comment.