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: Mon, 05 Oct 2015 22:23:48 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (gnu/linux)

>    test :-
>            X = [
>                    a,
>                    b
>            ].


> We expect instead, as with Stefan Bruda's version, the layout:

>    test :-
>            X = [
>                    a,
>                    b
>                ].

Try M-x smie-edebug RET to see where this is decided.  The above is just
the standard behavior used in many other major modes.  I prefer the
behavior above, so it probably requires a config var.

> The indentation for this new line is already different from Stefan
> Bruda's version, but not in itself a serious mistake at that point

Disagreement with Bruda's version is indeed not considered a bug, in
general, since Bruda's indentation code is far from perfect.

> Then, if you press RET (as most users certainly would here), you get:

>    :- module(x, [
>                      a,
>                      b
>              ]).

> and this is clearly not the intended layout for a term like that.
> Instead, the indentation level of "[" should equal that of "]".

Actually, I would personally prefer something like

       :- module(x, [
                         a,
                         b
                ]).
or
       :- module(x, [
                         a,
                         b
          ]).
or even
       :- module(x, [
                         a,
                         b
       ]).

> Another deviation from Stefan Bruda's mode is an unusually large
> indentation for arguments of declarations like:

>    :- public
>                    a,
>                    b.

Indeed, that's a poor choice, and oddly enough it's not the result of
a simple bug.  The patch below should improve the behavior.


        Stefan


diff --git a/lisp/progmodes/prolog.el b/lisp/progmodes/prolog.el
index 81aeb8d..61d3a3c 100644
--- a/lisp/progmodes/prolog.el
+++ b/lisp/progmodes/prolog.el
@@ -988,7 +988,16 @@ This is really kludgy, and unneeded (i.e. obsolete) in 
Emacs>=24."
             (smie-indent-backward-token) ;Skip !
             (equal ":-" (car (smie-indent-backward-token))))
           (smie-rule-parent prolog-indent-width)))
-    (`(:after . ,(or `":-" `"-->")) prolog-indent-width)))
+    (`(:after . ":-")
+     (if (bolp)
+         (save-excursion
+           (smie-indent-forward-token)
+           (skip-chars-forward " \t")
+           (if (eolp)
+               prolog-indent-width
+             (min prolog-indent-width (current-column))))
+       prolog-indent-width))
+    (`(:after . "-->") prolog-indent-width)))
 
 
 ;;-------------------------------------------------------------------





reply via email to

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