-
Notifications
You must be signed in to change notification settings - Fork 407
Conditional indent (\if, \fi, \else) #1078
Description
Indenting of conditional
Currently block between \if and \endif is not indented by default. As it is matter of taste vimtex could support optional indention of that syntax.
Introduction of g:vimtex_indent_delims (c146852) allows to mimic this behaviour with settings like
let g:vimtex_indent_delims = {
\ 'open' : ['\\if'],
\ 'close' : ['\\fi'],
\}However it will give the result
\ifnum=1
Hello world!
\else
Bye world!
\fiThe problem is with single line \else which should have temporary decreased indent (only for that line) and restored immediately. To keep the consistency, flexibility of user choice, I would suggest adding another entry in g:vimtex_indent_delims.
let g:vimtex_indent_delims = {
\ 'open' : ['\\if'],
\ 'close' : ['\\fi'],
\'hanging':['\\else']
\}So in the same manner one could provide a list of regex for hanging lines.
PS Be aware that it should be also regular expression to give full customization.
Also the example with '\\if' and '\\fi' are very simple ilustration.
Actually this expression should be like
'\(\\newif\)\@<!\\if\(field\|name\)\@!' to avoid indenting commands without ending \fi
like defining \newif\ifmyconditional or \iffieldundef or \ifnameundef from biblatex/biber commands, where action for true and false are just given in arguments without ending \fi.
Also closing should be changed to '\\fi\>' so it want parse for instance \field.
But the correct regex is up to user.