GNU bug report logs -
#18031
24.3.92; bad indentation in shell script mode
Previous Next
Reported by: Gilles Pion <gpion <at> lfdj.com>
Date: Wed, 16 Jul 2014 12:09:01 UTC
Severity: minor
Found in version 24.3.92
Fixed in version 24.5
Done: Stefan Monnier <monnier <at> iro.umontreal.ca>
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 18031 in the body.
You can then email your comments to 18031 AT debbugs.gnu.org in the normal way.
Toggle the display of automated, internal messages from the tracker.
Report forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#18031
; Package
emacs
.
(Wed, 16 Jul 2014 12:09:01 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Gilles Pion <gpion <at> lfdj.com>
:
New bug report received and forwarded. Copy sent to
bug-gnu-emacs <at> gnu.org
.
(Wed, 16 Jul 2014 12:09:02 GMT)
Full text and
rfc822 format available.
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
Actions to reproduce the bug:
* lauch emacs in failsafe mode ("emacs -Q")
* create a new buffer named "anythingyouwant.ksh" and insert the following lines
========= cut here ===========
#!/bin/ksh
grep -e "^$userregexp:" /etc/passwd | cut -d : -f 1 | while read user ; do
print -u2 "user=$user"
sudo -U $user -ll | while read line ; do
:
done
done
========= cut here ===========
* M-x shell-script-mode
* M-x mark-whole-buffer
* M-x indent-region
Here's the result:
#!/bin/ksh
grep -e "^$userregexp:" /etc/passwd | cut -d : -f 1 | while read user ; do
print -u2
"user=$user"
sudo -U
$user -ll | while read line ; do
:
done
done
In GNU Emacs 24.3.92.1 (powerpc-ibm-aix6.1.0.0, X toolkit)
of 2014-07-01 on ax30001
Windowing system distributor `The Cygwin/X Project', version 11.0.11501000
Configured using:
`configure --prefix=/<SITE>/opt/emacs-24.3.92
--exec-prefix=/<SITE>/opt/emacs-24.3.92 --sysconfdir=/etc/<SITE>/opt/emacs
--localstatedir=/var/<SITE>/opt/emacs --without-all --with-x-toolkit=lucid
--with-xpm --with-x-toolkit=lucid
--enable-locallisppath=/<SITE>/share/emacs/site-lisp 'CFLAGS=-O3 -g3'
'CPPFLAGS=-I/<SITE>/opt/emacs-24.3.92/include -I/opt/freeware/include '
'LDFLAGS=-L/<SITE>/opt/emacs-24.3.92/lib -Wl,-bstatic -L/opt/freeware/lib
-lXpm -Wl,-bdynamic''
Important settings:
value of $LANG: C
locale-coding-system: iso-latin-1-unix
Major mode: Shell-script
Minor modes in effect:
sh-electric-here-document-mode: t
tooltip-mode: t
electric-indent-mode: t
mouse-wheel-mode: t
tool-bar-mode: t
menu-bar-mode: t
file-name-shadow-mode: t
global-font-lock-mode: t
font-lock-mode: t
blink-cursor-mode: t
auto-composition-mode: t
auto-encryption-mode: t
auto-compression-mode: t
line-number-mode: t
transient-mark-mode: t
Load-path shadows:
None found.
Features:
(shadow sort gnus-util mail-extr emacsbug message format-spec rfc822 mml
mml-sec mm-decode mm-bodies mm-encode mail-parse rfc2231 mailabbrev
gmm-utils mailheader sendmail rfc2047 rfc2045 ietf-drums mm-util
help-fns mail-prsvr mail-utils help-mode easymenu sh-script smie
executable dired time-date tooltip electric uniquify ediff-hook vc-hooks
lisp-float-type mwheel x-win x-dnd tool-bar dnd fontset image regexp-opt
fringe tabulated-list newcomment lisp-mode prog-mode register page
menu-bar rfn-eshadow timer select scroll-bar mouse jit-lock font-lock
syntax facemenu font-core frame cham georgian utf-8-lang misc-lang
vietnamese tibetan thai tai-viet lao korean japanese hebrew greek
romanian slovak czech european ethiopic indian cyrillic chinese
case-table epa-hook jka-cmpr-hook help simple abbrev minibuffer nadvice
loaddefs button faces cus-face macroexp files text-properties overlay
sha1 md5 base64 format env code-pages mule custom widget
hashtable-print-readable backquote make-network-process dynamic-setting
x-toolkit x multi-tty emacs)
Memory information:
((conses 8 87772 8428)
(symbols 24 18605 0)
(miscs 20 60 360)
(strings 16 14441 4333)
(string-bytes 1 359100)
(vectors 8 10219)
(vector-slots 4 413533 5420)
(floats 8 67 336)
(intervals 28 783 438)
(buffers 512 16))
--
Gilles
Reply sent
to
Stefan Monnier <monnier <at> iro.umontreal.ca>
:
You have taken responsibility.
(Thu, 04 Dec 2014 15:11:02 GMT)
Full text and
rfc822 format available.
Notification sent
to
Gilles Pion <gpion <at> lfdj.com>
:
bug acknowledged by developer.
(Thu, 04 Dec 2014 15:11:02 GMT)
Full text and
rfc822 format available.
Message #10 received at 18031-done <at> debbugs.gnu.org (full text, mbox):
Version:24.5
> Here's the result:
> #!/bin/ksh
> grep -e "^$userregexp:" /etc/passwd | cut -d : -f 1 | while read user ; do
> print -u2
> "user=$user"
> sudo -U
> $user -ll | while read line ; do
> :
> done
> done
After fixing the above line-wrapping to really reproduce what Emacs
does, you'll see that it's indented in a way which is sensible:
- The "print -u2" line is indented 4 chars deeper than the "while" in
which it's nested.
- The "user=$user" line is actually at the end of the previous line.
- The "sudo" line is aligned with the previous line.
- The ":" is indented 4 chars deeper than the "while" in which it's nested.
- The "done" are aligned with the "while" they close.
Now, I understand that "sensible" doesn't mean "good" or "desirable",
but at least the indentation works sanely (contrary to the bug#18756 case).
So it's a "small matter" of teaching sh-mode to indent the body of loops
less deeply when the loop itself doesn't start at the beginning of the line.
I installed the patch below which seems to do the trick.
Stefan
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 12e5ef0..26b09a6 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,9 @@
+2014-12-04 Stefan Monnier <monnier <at> iro.umontreal.ca>
+
+ * progmodes/sh-script.el (sh-smie-sh-rules): Go back to the beginning
+ of the whole pipe when indenting an opening keyword after a |.
+ Generalize this treatment to opening keywords like "while" (bug#18031).
+
2014-12-01 Stefan Monnier <monnier <at> iro.umontreal.ca>
* simple.el (newline): Place the hook buffer-locally,
diff --git a/lisp/progmodes/sh-script.el b/lisp/progmodes/sh-script.el
index 724d22a..1165144 100644
--- a/lisp/progmodes/sh-script.el
+++ b/lisp/progmodes/sh-script.el
@@ -1988,12 +1988,12 @@ May return nil if the line should not be treated as continued."
(and (numberp indent) (numberp initial)
(<= indent initial)))))
`(column . ,(+ initial sh-indentation)))
- (`(:before . ,(or `"(" `"{" `"["))
+ (`(:before . ,(or `"(" `"{" `"[" "while" "if" "for" "case"))
(if (not (smie-rule-prev-p "&&" "||" "|"))
(when (smie-rule-hanging-p)
(smie-rule-parent))
(unless (smie-rule-bolp)
- (smie-backward-sexp 'halfexp)
+ (while (equal "|" (nth 2 (smie-backward-sexp 'halfexp))))
`(column . ,(smie-indent-virtual)))))
;; FIXME: Maybe this handling of ;; should be made into
;; a smie-rule-terminator function that takes the substitute ";" as arg.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#18031
; Package
emacs
.
(Thu, 04 Dec 2014 15:55:02 GMT)
Full text and
rfc822 format available.
Message #13 received at 18031-done <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
Thanks!
Applied and tested: this fix works just fine.
--
Gilles
[Message part 2 (text/html, inline)]
[Message part 3 (text/plain, inline)]
Si vous n’êtes pas destinataires de ce message, merci d’avertir l’expéditeur de l’erreur de distribution et de le détruire immédiatement. Ce message contient des informations confidentielles ou appartement à la Française des jeux. Il est établi à l’intention exclusive de ses destinataires. Toute divulgation, utilisation, diffusion ou reproduction (totale ou partielle) de ce message ou des informations qu’il contient, doit être préalablement autorisée. Tout message électronique est susceptible d’altération et son intégrité ne peut être assure. La Française des Jeux décline toute responsabilité au titre de ce message s’il a été modifié ou falsifié.
[Message part 4 (text/html, inline)]
bug archived.
Request was from
Debbugs Internal Request <help-debbugs <at> gnu.org>
to
internal_control <at> debbugs.gnu.org
.
(Fri, 02 Jan 2015 12:24:04 GMT)
Full text and
rfc822 format available.
This bug report was last modified 10 years and 175 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.