unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#18031: 24.3.92; bad indentation in shell script mode
@ 2014-07-16 12:08 Gilles Pion
  2014-12-04 15:09 ` Stefan Monnier
  0 siblings, 1 reply; 3+ messages in thread
From: Gilles Pion @ 2014-07-16 12:08 UTC (permalink / raw)
  To: 18031

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





^ permalink raw reply	[flat|nested] 3+ messages in thread

* bug#18031: 24.3.92; bad indentation in shell script mode
  2014-07-16 12:08 bug#18031: 24.3.92; bad indentation in shell script mode Gilles Pion
@ 2014-12-04 15:09 ` Stefan Monnier
  2014-12-04 15:54   ` Gilles Pion
  0 siblings, 1 reply; 3+ messages in thread
From: Stefan Monnier @ 2014-12-04 15:09 UTC (permalink / raw)
  To: Gilles Pion; +Cc: 18031-done

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@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@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.





^ permalink raw reply related	[flat|nested] 3+ messages in thread

* bug#18031: 24.3.92; bad indentation in shell script mode
  2014-12-04 15:09 ` Stefan Monnier
@ 2014-12-04 15:54   ` Gilles Pion
  0 siblings, 0 replies; 3+ messages in thread
From: Gilles Pion @ 2014-12-04 15:54 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: 18031-done


[-- Attachment #1.1: Type: text/plain, Size: 66 bytes --]

Thanks!

Applied and tested: this fix works just fine.

--
Gilles

[-- Attachment #1.2: Type: text/html, Size: 202 bytes --]

[-- Attachment #2.1: Type: text/plain, Size: 695 bytes --]

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é.

[-- Attachment #2.2: Type: text/html, Size: 700 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-12-04 15:54 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-07-16 12:08 bug#18031: 24.3.92; bad indentation in shell script mode Gilles Pion
2014-12-04 15:09 ` Stefan Monnier
2014-12-04 15:54   ` Gilles Pion

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).