GNU bug report logs - #15613
Wrong indentation in Shell-script[sh] mode?

Previous Next

Package: emacs;

Reported by: Angelo Graziosi <angelo.graziosi <at> alice.it>

Date: Mon, 14 Oct 2013 20:54:01 UTC

Severity: normal

Fixed in version 24.4

Done: Glenn Morris <rgm <at> gnu.org>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 15613 in the body.
You can then email your comments to 15613 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#15613; Package emacs. (Mon, 14 Oct 2013 20:54:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Angelo Graziosi <angelo.graziosi <at> alice.it>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Mon, 14 Oct 2013 20:54:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Angelo Graziosi <angelo.graziosi <at> alice.it>
To: bug-emacs <bug-gnu-emacs <at> gnu.org>
Subject: Wrong indentation in Shell-script[sh] mode?
Date: Mon, 14 Oct 2013 22:53:04 +0200
In the current trunk the indentation for bash scripts looks as in this 
test case:

$ cat test_indent.sh
#!/bin/bash

if [ "${foo_a}" != "${foo_b}" ]; then

    if [ "${foo_c}" = "${foo_d}" ]; then
	echo
	echo "Hello..."
	echo
	exit 1
    fi

    fi


The inner if-fi looks ok but in the outer one expects the last fi under 
the first if.. Or not?

This happens with

$ emacs -Q &

and using TAB to indent..


Ciao,
 Angelo.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#15613; Package emacs. (Tue, 15 Oct 2013 14:38:04 GMT) Full text and rfc822 format available.

Message #8 received at 15613 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Angelo Graziosi <angelo.graziosi <at> alice.it>
Cc: 15613 <at> debbugs.gnu.org
Subject: Re: bug#15613: Wrong indentation in Shell-script[sh] mode?
Date: Tue, 15 Oct 2013 10:37:44 -0400
> In the current trunk the indentation for bash scripts looks as in this test
> case:

> $ cat test_indent.sh
> #!/bin/bash

> if [ "${foo_a}" != "${foo_b}" ]; then

>     if [ "${foo_c}" = "${foo_d}" ]; then
> 	echo
> 	echo "Hello..."
> 	echo
> 	exit 1
>     fi

>     fi

This works correctly if you use (setq sh-use-smie t) which I recommend.

It is currently not the default setting because it doesn't yet support
all the indentation-config variables of the old indentation code, and
doesn't support the "guess indentation settings" feature either.  But in
most other respects it should work "as well or better".


        Stefan




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#15613; Package emacs. (Tue, 15 Oct 2013 14:57:01 GMT) Full text and rfc822 format available.

Message #11 received at 15613 <at> debbugs.gnu.org (full text, mbox):

From: Glenn Morris <rgm <at> gnu.org>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: 15613 <at> debbugs.gnu.org, Angelo Graziosi <angelo.graziosi <at> alice.it>
Subject: Re: bug#15613: Wrong indentation in Shell-script[sh] mode?
Date: Tue, 15 Oct 2013 10:56:09 -0400
Stefan Monnier wrote:

> This works correctly if you use (setq sh-use-smie t) which I recommend.

It works fine in 24.3 out-of-the-box.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#15613; Package emacs. (Tue, 15 Oct 2013 22:24:02 GMT) Full text and rfc822 format available.

Message #14 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Angelo Graziosi <angelo.graziosi <at> alice.it>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: bug-emacs <bug-gnu-emacs <at> gnu.org>
Subject: Re: bug#15613: Wrong indentation in Shell-script[sh] mode?
Date: Wed, 16 Oct 2013 00:23:15 +0200
Il 15/10/2013 16.37, Stefan Monnier ha scritto:
>> In the current trunk the indentation for bash scripts looks as in this test
>> case:
>
>> $ cat test_indent.sh
>> #!/bin/bash
>
>> if [ "${foo_a}" != "${foo_b}" ]; then
>
>>      if [ "${foo_c}" = "${foo_d}" ]; then
>> 	echo
>> 	echo "Hello..."
>> 	echo
>> 	exit 1
>>      fi
>
>>      fi
>
> This works correctly if you use (setq sh-use-smie t) which I recommend.
>
> It is currently not the default setting because it doesn't yet support
> all the indentation-config variables of the old indentation code, and
> doesn't support the "guess indentation settings" feature either.  But in
> most other respects it should work "as well or better".

Why, by default, the last "fi" should be under the previous and not 
under _its_ "if"? Should "indent" mean that the matching if-fi, {-}, 
begin-end, if-endif etc. start the same column?

Instead the test case shows that all statements after the first "if"

  if [ "${foo_a}" != "${foo_b}" ]; then

are considered belonging to its block statements. All the next formatted 
code is lost.

This should be called "regression"..


Ciao,
 Angelo.





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#15613; Package emacs. (Tue, 15 Oct 2013 22:27:01 GMT) Full text and rfc822 format available.

Message #17 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Angelo Graziosi <angelo.graziosi <at> alice.it>
To: Glenn Morris <rgm <at> gnu.org>, Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: bug-emacs <bug-gnu-emacs <at> gnu.org>
Subject: Re: bug#15613: Wrong indentation in Shell-script[sh] mode?
Date: Wed, 16 Oct 2013 00:26:13 +0200
Il 15/10/2013 16.56, Glenn Morris ha scritto:
> Stefan Monnier wrote:
>
>> This works correctly if you use (setq sh-use-smie t) which I recommend.
>
> It works fine in 24.3 out-of-the-box.
>

Also in trunk rev. 114585 (09 October 2013). So, some recent changes 
have broken the indentation of Shell-script[sh] mode...

Ciao,
Angelo.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#15613; Package emacs. (Wed, 16 Oct 2013 22:42:02 GMT) Full text and rfc822 format available.

Message #20 received at 15613 <at> debbugs.gnu.org (full text, mbox):

From: Glenn Morris <rgm <at> gnu.org>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: 15613 <at> debbugs.gnu.org, Angelo Graziosi <angelo.graziosi <at> alice.it>
Subject: Re: bug#15613: Wrong indentation in Shell-script[sh] mode?
Date: Wed, 16 Oct 2013 18:41:27 -0400
By experiment, reverting the "Always setup SMIE..." part of your
2013-10-11 change fixes this regression.


*** lisp/progmodes/sh-script.el	2013-10-13 23:21:56 +0000
--- lisp/progmodes/sh-script.el	2013-10-16 22:35:56 +0000
***************
*** 2248,2253 ****
--- 2248,2254 ----
  		  (sh-feature sh-indent-supported))
        (progn
  	(message "Setting up indent for shell type %s" sh-shell)
+         (if sh-use-smie
              (let ((mksym (lambda (name)
                             (intern (format "sh-smie-%s-%s"
                                             sh-indent-supported-here name)))))
***************
*** 2255,2261 ****
                        (funcall mksym "rules")
                        :forward-token  (funcall mksym "forward-token")
                        :backward-token (funcall mksym "backward-token")))
-         (unless sh-use-smie
            (setq-local parse-sexp-lookup-properties t)
            (setq-local sh-kw-alist (sh-feature sh-kw))
            (let ((regexp (sh-feature sh-kws-for-done)))
--- 2256,2261 ----





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#15613; Package emacs. (Thu, 17 Oct 2013 01:04:02 GMT) Full text and rfc822 format available.

Message #23 received at 15613 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Glenn Morris <rgm <at> gnu.org>
Cc: 15613 <at> debbugs.gnu.org, Angelo Graziosi <angelo.graziosi <at> alice.it>
Subject: Re: bug#15613: Wrong indentation in Shell-script[sh] mode?
Date: Wed, 16 Oct 2013 21:03:42 -0400
> By experiment, reverting the "Always setup SMIE..." part of your
> 2013-10-11 change fixes this regression.

Aha!  I'll try and see why that introduces such breakage.
Probably a call to backward-sexp somewhere.


        Stefan




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#15613; Package emacs. (Thu, 17 Oct 2013 02:04:02 GMT) Full text and rfc822 format available.

Message #26 received at 15613 <at> debbugs.gnu.org (full text, mbox):

From: Glenn Morris <rgm <at> gnu.org>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: 15613 <at> debbugs.gnu.org, Angelo Graziosi <angelo.graziosi <at> alice.it>
Subject: Re: bug#15613: Wrong indentation in Shell-script[sh] mode?
Date: Wed, 16 Oct 2013 22:03:14 -0400
Stefan Monnier wrote:

>> By experiment, reverting the "Always setup SMIE..." part of your
>> 2013-10-11 change fixes this regression.
>
> Aha!  I'll try and see why that introduces such breakage.
> Probably a call to backward-sexp somewhere.

This specific problem seems due to smie-setup's

  (setq-local forward-sexp-function #'smie-forward-sexp-command)




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#15613; Package emacs. (Thu, 17 Oct 2013 03:58:02 GMT) Full text and rfc822 format available.

Message #29 received at 15613 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Glenn Morris <rgm <at> gnu.org>
Cc: 15613 <at> debbugs.gnu.org, Angelo Graziosi <angelo.graziosi <at> alice.it>
Subject: Re: bug#15613: Wrong indentation in Shell-script[sh] mode?
Date: Wed, 16 Oct 2013 23:57:34 -0400
I installed the patch below which should fix it, thank you,


        Stefan


--- lisp/progmodes/sh-script.el	2013-10-13 23:21:56 +0000
+++ lisp/progmodes/sh-script.el	2013-10-17 03:53:43 +0000
@@ -3097,6 +3097,7 @@
 OPEN and CLOSE are regexps denoting the tokens to be matched.
 Optional parameter DEPTH (usually 1) says how many to look for."
   (let ((parse-sexp-ignore-comments t)
+        (forward-sexp-function nil)
 	prev)
     (setq depth (or depth 1))
     (save-excursion





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#15613; Package emacs. (Thu, 17 Oct 2013 16:48:02 GMT) Full text and rfc822 format available.

Message #32 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Angelo Graziosi <angelo.graziosi <at> alice.it>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>, Glenn Morris <rgm <at> gnu.org>
Cc: bug-emacs <bug-gnu-emacs <at> gnu.org>
Subject: Re: bug#15613: Wrong indentation in Shell-script[sh] mode?
Date: Thu, 17 Oct 2013 18:46:07 +0200
Il 17/10/2013 5.57, Stefan Monnier ha scritto:
> I installed the patch below which should fix it, thank you,

Confirmed!

Thanks,
  Angelo.


>
> --- lisp/progmodes/sh-script.el	2013-10-13 23:21:56 +0000
> +++ lisp/progmodes/sh-script.el	2013-10-17 03:53:43 +0000
> @@ -3097,6 +3097,7 @@
>   OPEN and CLOSE are regexps denoting the tokens to be matched.
>   Optional parameter DEPTH (usually 1) says how many to look for."
>     (let ((parse-sexp-ignore-comments t)
> +        (forward-sexp-function nil)
>   	prev)
>       (setq depth (or depth 1))
>       (save-excursion
>





bug marked as fixed in version 24.4, send any further explanations to 15613 <at> debbugs.gnu.org and Angelo Graziosi <angelo.graziosi <at> alice.it> Request was from Glenn Morris <rgm <at> gnu.org> to control <at> debbugs.gnu.org. (Thu, 17 Oct 2013 17:20:03 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Fri, 15 Nov 2013 12:24:03 GMT) Full text and rfc822 format available.

This bug report was last modified 11 years and 217 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.