Skip to content

Commit 8293adc

Browse files
committed
Only remove undo point if s:RunRustfmt is executed from BufWritePre
Otherwise, we remove unintended undo points. We can use the already existing parameter to figure out whether we are executing from BufWritePre context. Fixes #358. Issue existed since #33c3e214a606, introduced by #111.
1 parent 776800d commit 8293adc

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

autoload/rustfmt.vim

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ function! s:DeleteLines(start, end) abort
110110
silent! execute a:start . ',' . a:end . 'delete _'
111111
endfunction
112112

113-
function! s:RunRustfmt(command, tmpname, fail_silently)
113+
function! s:RunRustfmt(command, tmpname, from_writepre)
114114
mkview!
115115

116116
let l:stderr_tmpname = tempname()
@@ -147,8 +147,10 @@ function! s:RunRustfmt(command, tmpname, fail_silently)
147147

148148
let l:open_lwindow = 0
149149
if v:shell_error == 0
150-
" remove undo point caused via BufWritePre
151-
try | silent undojoin | catch | endtry
150+
if a:from_writepre
151+
" remove undo point caused via BufWritePre
152+
try | silent undojoin | catch | endtry
153+
endif
152154

153155
if a:tmpname ==# ''
154156
let l:content = l:out
@@ -168,7 +170,7 @@ function! s:RunRustfmt(command, tmpname, fail_silently)
168170
call setloclist(0, [])
169171
let l:open_lwindow = 1
170172
endif
171-
elseif g:rustfmt_fail_silently == 0 && a:fail_silently == 0
173+
elseif g:rustfmt_fail_silently == 0 && !a:from_writepre
172174
" otherwise get the errors and put them in the location list
173175
let l:errors = []
174176

@@ -222,12 +224,12 @@ function! rustfmt#FormatRange(line1, line2)
222224
let l:tmpname = tempname()
223225
call writefile(getline(1, '$'), l:tmpname)
224226
let command = s:RustfmtCommandRange(l:tmpname, a:line1, a:line2)
225-
call s:RunRustfmt(command, l:tmpname, 0)
227+
call s:RunRustfmt(command, l:tmpname, v:false)
226228
call delete(l:tmpname)
227229
endfunction
228230

229231
function! rustfmt#Format()
230-
call s:RunRustfmt(s:RustfmtCommand(), '', 0)
232+
call s:RunRustfmt(s:RustfmtCommand(), '', v:false)
231233
endfunction
232234

233235
function! rustfmt#Cmd()
@@ -255,7 +257,7 @@ function! rustfmt#PreWrite()
255257
return
256258
endif
257259

258-
call s:RunRustfmt(s:RustfmtCommand(), '', 1)
260+
call s:RunRustfmt(s:RustfmtCommand(), '', v:true)
259261
endfunction
260262

261263

0 commit comments

Comments
 (0)