Skip to content

Commit 054fa9b

Browse files
authored
Merge pull request #4 from ubaldot/robustify_formatting
robustified formatting through defer feature
2 parents 32671f1 + 5787283 commit 054fa9b

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

autoload/mde_utils.vim

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,7 @@ export def Echowarn(msg: string)
1010
echohl WarningMsg | echom $'[markdown_extras] {msg}' | echohl None
1111
enddef
1212

13-
export def FormatWithoutMoving(a: number = 0, b: number = 0)
14-
# To be used for formatting through autocmds
15-
var view = winsaveview()
16-
if a == 0 && b == 0
17-
silent exe $":norm! gggqG"
18-
else
19-
var interval = b - a + 1
20-
silent exe $":norm! {a}gg{interval}gqq"
21-
endif
22-
13+
def UndoFormatting()
2314
if v:shell_error != 0
2415
undo
2516
Echoerr($"'{&l:formatprg->matchstr('^\s*\S*')}' returned errors.")
@@ -32,6 +23,20 @@ export def FormatWithoutMoving(a: number = 0, b: number = 0)
3223
Echowarn("'formatprg' is empty. Using default formatter.")
3324
endif
3425
endif
26+
enddef
27+
28+
export def FormatWithoutMoving(a: number = 0, b: number = 0)
29+
# To be used for formatting through autocmds
30+
var view = winsaveview()
31+
32+
defer UndoFormatting()
33+
if a == 0 && b == 0
34+
silent exe $":norm! gggqG"
35+
else
36+
var interval = b - a + 1
37+
silent exe $":norm! {a}gg{interval}gqq"
38+
endif
39+
3540
winrestview(view)
3641
enddef
3742

0 commit comments

Comments
 (0)