-
Notifications
You must be signed in to change notification settings - Fork 390
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conditional indent (\if
, \fi
, \else
)
#1078
Comments
I'm not very accustomed to let g:vimtex_indent_conditionals = {
\ 'open': '\\if\%(num\|false\)\?\>',
\ 'else': '\\else'
\ 'close': '\\fi',
\} I would suspect it suffices with a single regex here, no need for a list. I'll look into this a little bit now. I think I want to keep this separate from delimiters and use a different option. |
Ok, first version of this is added. It is probably not perfect. As an example of this, the current version assumes that all conditionals are written linewise, e.g., there are never two clauses on a single line, such as The first thing is to find a good default setting for the regexes. |
Good job. I agree that simple regex should suffice (until one encounter very specific case, which I do not foresee now). 'open': '\v\\if%(num|false)?>' allows only \newif\ifenglish % define new conditional
\ifenglish
\usepackage[english]{babel}
\else
\usepackage[polish]{babel}
\fi So the list of possible 'open' : '\(\\newif\)\@<!\\if\(field\|name\|numequal\)\@!' so it will properly indent this example with PS If I try to set only one dictionary entry let g:vimtex_indent_conditionals = {
\ 'open' : '\(\\newif\)\@<!\\if\(field\|name\|numequal\)\@!'
\ } then it does not work. Is that on purpose? |
And about linewise. If you see some \ifdefined\myvar\else
hello world!
\fi
So I will not bother nested if in one line.
|
and another exception ( 'open' : '\(\\newif\)\@<!\\if\(field\|name\|numequal\|thenelse\)\@!' |
I've updated the default values per your suggestion, and I've also updated so you can set only a single key without affecting the other defaults. Regarding linewise: I think it can be possible to implement support for more complex constructs. But I don't know how "necessary" it is. How often do people write such expressions without structuring it "logically"? Please don't hesitate to open a new issue if you want me to look into supporting more complex constructs where the current implementation breaks. |
Yes, all works good. I do not really know why you prefer introducing another key 'disabled' instead of using empty dictionary to disable indenting of conditionals, but that is as I understand part of design (I think that this is not uniform within different settings in vimtex, thought). |
A moment of confusion from my part. I think checking for an empty dictionary is still better, so I'll revert that part. Thanks for raising the issue and for the useful comments! |
Yes, that is better idea, I did not want to suggest you that directly, as it is your right to decide on user interface, but now I admit it is better.
And just information: it still works if you set only one of open|close|else regex (the other are then assumed default) -- I think this is correct and expected behavior.
|
I never mind direct suggestions, even though I sometimes wave my right to decide. In any case, the confusion was due to adding support for only overriding one of the keys, where I did not immediately notice that it still could and would work to allow disabling with an empty dict. Again, thanks! |
So maybe one last small suggestion to completely
automate conditional indention would be adding
`indentkeys`. Something like:
````vim
setlocal indentkeys+=[,(,{,),},],\&,=item,=else,=fi
````
|
Good idea. But should this not also include |
if is working. Do not know why? Is is my hidden setting? |
Ah, yes, I think it is not necessary, because indentation occurs when typing |
Sorry to be that guy, but this broke indentation for me when using a macro |
Yes, you can disable this. Add this to your vimrc file: let g:vimtex_indent_conditionals = {
\ 'open': '\v(\\newif)@<!\\if(f>|field|name|numequal|thenelse)@!',
\ } The change is to add let g:vimtex_indent_conditionals = {} |
Indenting of conditional
Currently block between
\if
and\endif
is not indented by default. As it is matter of tastevimtex
could support optional indention of that syntax.Introduction of
g:vimtex_indent_delims
(c146852) allows to mimic this behaviour with settings likeHowever it will give the result
The 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 ing:vimtex_indent_delims
.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
frombiblatex/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.
The text was updated successfully, but these errors were encountered: