File tree Expand file tree Collapse file tree 2 files changed +30
-9
lines changed
Expand file tree Collapse file tree 2 files changed +30
-9
lines changed Original file line number Diff line number Diff line change @@ -25,19 +25,30 @@ def UndoFormatting()
2525 endif
2626enddef
2727
28- export def FormatWithoutMoving (a: number = 0 , b: number = 0 )
29- # To be used for formatting through autocmds
28+ export def FormatWithoutMoving (type : string = ' ' )
29+ # ' gq' is remapped to use this function .
30+ # However, when running the ' gq' as formatter, we need to use as it is
31+ # shipped with Vim, and therefore we use the bang in ' normal!'
3032 var view = winsaveview ()
3133
34+ # defer so if the function gets error of any kind, the following are run
35+ # anyways
3236 defer UndoFormatting ()
33- if a == 0 && b == 0
37+ defer winrestview (view )
38+
39+ var start = 0
40+ var end = 0
41+ if type != ' '
42+ start = line (" '[" )
43+ end = line (" ']" )
44+ endif
45+
46+ if start == 0 && end == 0
3447 normal ! gggqG
3548 else
36- var interval = b - a + 1
37- silent exe $ " :norm ! {a }gg{interval}gqq"
49+ var interval = end - start + 1
50+ silent exe $ " normal ! {start }gg{interval}gqq"
3851 endif
39-
40- winrestview (view )
4152enddef
4253
4354export def KeysFromValue (dict : dict <string> , target_value: string ): list <string>
Original file line number Diff line number Diff line change @@ -29,9 +29,10 @@ command! -buffer -nargs=0 MDEConvertLinks links.ConvertLinks()
2929# Jump back to the previous file
3030nnoremap <buffer> <backspace> <ScriptCmd> funcs.GoToPrevVisitedBuffer()<cr>
3131
32-
3332# -------------- prettier ------------------------
34- #
33+ # TODO : you may want to use the same mechanism used in my personal
34+ # after/ftplugin/ python .vim , where I set the local opfunc to
35+ # FormatWithoutMoving and where I hack the ' gq' operator
3536if markdown_extras.use_prettier
3637 if exists (' g:markdown_extras_config' ) != 0
3738 && has_key (g: markdown_extras_config , ' formatprg' )
@@ -51,6 +52,15 @@ if markdown_extras.use_prettier
5152 augroup END
5253 endif
5354endif
55+
56+ def SetMarkdownOpFunc ()
57+ &l: opfunc = function (' utils.FormatWithoutMoving' )
58+ enddef
59+
60+ # Hack on ' gq'
61+ nnoremap <silent> gq <ScriptCmd> SetMarkdownOpFunc()<cr> g@
62+ xnoremap <silent> gq <ScriptCmd> SetMarkdownOpFunc()<cr> g@
63+
5464# -------------- End prettier ------------------------
5565
5666# -------------------- pandoc -----------------------
You can’t perform that action at this time.
0 commit comments