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: Markus Triska
Subject: bug#21526: 24.5; prolog-mode: broken indentation for if-then-else construct
Date: Wed, 23 Sep 2015 23:08:24 +0200

Here are some further cases I found when trying the latest version:

(a) The indentation of (\+)/1 (not provable) is not correct and yields
an error. For example, when I press RET when point is at the "H":

   test :-
           \+ a,HERE

then I get:

   test :-
   \+ a,
   HERE

and the message:

   Error: (error "Bumped into unknown token")

The expected result is:

   test :-
           \+ a,
           HERE

(and no error). For example, the clause may eventually look like:

   test :-
           \+ a,
           b,
           \+ \+ c,
           d.

In connection with if-then-else, we expect the layout:

   test :-
           (   \+ a ->
               b
           ;   \+ c,
               \+ d
           ).

but currently get:

   test :-
           (   \+ a ->
               b
           ;   \+ c,
   \+ d
           ).


(b) Comments within if-then-else constructs are also not correctly
indented. For example, a block like:

   test :-
           (   a ->
               % what should we do
               % with two lines?
               b

is still indented exactly as expected. However, when I then add two
subsequent comment lines also in the else branch, I get:

   test :-
           (   a ->
               % what should we do
               % on two lines?
               b
           ;   % what else should
           % we do on two lines
           c
           ).

Whereas we expect (and Stefan Bruda's version also yields):

   test :-
           (   a ->
               % what should we do
               % on two lines?
               b
           ;   % what else should
               % we do on two lines
               c
           ).

The remaining two issues are not related to if-then-else, but I still
include them in this report for easy reference. I will of course file
separate issues for them if you prefer that.

(c) Arguments of directives should be more indented. For example, a
directive whose arguments span several lines should look like this:

   :- multifile
           pred1,
           pred2,
           pred3.

Instead, when I press RET when point is at the H:

   :- multifileHERE

I unexpectedly get:


   :- multifile
      HERE

`prolog-keywords' contains the directives where a hanging indentation of
prolog-indent-width in subsequent lines would be very welcome.


(d) Code patterns like the following are quite common:

   test_predicate(a) :- !.
   test_predicate(b) :- !.
   test_predicate(c) :- !,
           test_goal1,
           test_goal2.
   test_predicate(d) :- !,
           test_goal3.

For a block like that, I get with the current git version:

   test_predicate(a) :- !.
   test_predicate(b) :- !.
   test_predicate(c) :- !,
                        test_goal1,
                        test_goal2.
   test_predicate(d) :- !,
                        test_goal3.

Whereas with Stefan Bruda's original version, I get the first layout.


I have used the following two source files, together amounting to more
than 8,000 lines of Prolog code written using Stefan Bruda's version
with the settings I posted, to find such regressions:

One is a constraint solver over Boolean variables:

   https://github.com/SWI-Prolog/swipl-devel/blob/master/library/clp/clpb.pl

And the other is a constraint solver over integers:

   https://github.com/SWI-Prolog/swipl-devel/blob/master/library/clp/clpfd.pl   
I hope that these files are useful as further test cases for you.

All the best!
Markus






reply via email to

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