auctex
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [AUCTeX] Indentation of \if statements


From: Tassilo Horn
Subject: Re: [AUCTeX] Indentation of \if statements
Date: Fri, 19 Dec 2014 10:13:40 +0100
User-agent: Gnus/5.130012 (Ma Gnus v0.12) Emacs/25.0.50 (gnu/linux)

Oleh <address@hidden> writes:

>> What I basically had in mind was having two variables
>> `TeX-begin-macro-list' and `TeX-end-macro-list'.  From those
>> begin/end regexes could be created using `regexp-opt' and used
>> analogously to `LaTeX-begin-regexp'/`LaTeX-end-regexp'.
>>
>> This has the benefit that a hypothetical ifplatform.el style simply
>> can add \ifwindows and friends to the `TeX-begin-macro-list' and
>> indentation should just work.
>>
>> By default, `TeX-begin-macro-list' should contain all the standard
>> TeX if variations: if, ifx, ifnum, ifodd, ifdim, iftrue, iffalse,
>> ....  Then the begin regex would be computed by (concat "\\\\"
>> (regexp-opt TeX-begin-macro-list) "\\b").  Note that "\\\\if\\b" also
>> matches "address@hidden" solving your original issue.
>>
>> Likewise, `TeX-end-macro-list' would contain "else" and "fi".
>>
>> Does that make sense?
>
> Sounds good, although a case can be made for "convention over
> configuration" (the only thing that stuck with me after that Rails
> course). In my second patch (somewhere above in the discussion
> branch), the convention is that this adds to indentation:
>
>     \ifblahblahwhatever
>
> , while this doesn't:
>
>     \iface{10pt}{red}
>
> The convention is that if a command starts with "\if" and has no
> arguments, e.g no "{" on the same line, it's an "if" switch and the
> indentation should be added. This way we can sidestep any need for
> configuration:

But I could also write

  \iface
    {10pt}
    {red}

    ups, now this paragraph is indented for no reason!

and now it won't return to normal indentation anymore because there's no
\fi.  (Ok, that's probably a corner-case and nobody writes it like
that.)

> with your approach, the user has to add a custom command "\iffoo" she
> just wrote to `TeX-begin-macro-list' before the indentation starts
> working again.

Yes, and I consider that a feature.  It's better to have stuff not
indented at all than to have something that adds to the indentation
without ever being removed again.

> The convention could be tweaked a little, e.g. maybe consider the
> closing brace as well or something.

Well, I just checked and indeed except for "if", "iff", and "iffy" there
are no English words starting with "if" (but that might be different in
other languages, and everybody is free to define macros in his native
language).  But maybe you can convince me of that convention over config
approach anyway.  But still I'd at least want to have two separate
defcustoms for that which could then be regexes rather than lists, e.g.,
`TeX-begin-macro-regex' and `TeX-end-macro-regex'.  The former can then
easily be made more specific for people that need to have their \iffy
macro.  The reasons are that (1) it has nothing to do with LaTeX but
with TeX in general, and (2) people might already have customized
`LaTeX-begin-regexp' and `LaTeX-end-regexp' and thus won't recognize the
change in their defaults.

Bye,
Tassilo



reply via email to

[Prev in Thread] Current Thread [Next in Thread]