bug-gnu-emacs
[Top][All Lists]
Advanced

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

bug#21526: 24.5; prolog-mode: broken indentation for if-then-else constr


From: Stefan Monnier
Subject: bug#21526: 24.5; prolog-mode: broken indentation for if-then-else construct
Date: Sun, 20 Sep 2015 22:34:47 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (gnu/linux)

>    test :-
>            (   HERE

> with point again being at the "H". In other words, the electric
> parenthesis indents `prolog-paren-indent', which is typically 4.

Good, thanks.  I think this does work correctly, currently, right?

> That is, notice in particular that this new line is NOT indented the
> same amount as the immediately preceding Prolog goals. There is a clear
> reason for this: The immediately preceding Prolog goal, namely c, is
> NOT followed by a comma. This means that where HERE appears, only two
> things can realistically follow:

Right, this is a current problem in SMIE, as mentioned: it doesn't know
about such "realistically".  It just knows that the grammar would allow
a comma at that point just as much as a semi-colon or lots of other
things, and it even thinks that there are yet further possibilities
(which actually aren't allowed by Prolog).

I'll have to think about how to best teach SMIE about this.

> To (unexpectedly) first indent the block and then only re-indent it when
> "." is pressed would in my view be a regression compared to that.

No doubt it's a regression.

>> 
>> - there are two desired indentations for "b".  IIUC You want
>> 
>> (a ->
>> b1,
>> b2
>> ;c1,
>> c2)
>> 
>> whereas the current code tries to accommodate
>> 
>> (a ->
>> b1,
>> b2;
>> c1,
>> c2)

> The two most common ways to indent Prolog's if-then-else are:
>
>         (   a ->
>             b,
>             c
>         ;   d,
>             e
>         ),
>
> and:
>
>         (   a
>         ->  b,
>             c
>         ;   d,
>             e
>         )

OK, the latter should be easy to support.  The former might require
a bit more works (or a config var).

>> (   a ->
>>         b
>> ;  c
>> ).

> I've never seen this indentation style in a decade

I'm not surprised.  This indentation is only the indirect result of
supporting

   (a ->
        b1,
        b2;
    c).

and since indentation normally only looks at the previous lines, the
indentation of "b1," can't depend on whether the following semi-colon is
at the end of a line, or at the beginning of a line.


        Stefan





reply via email to

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