From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.bugs Subject: bug#18031: 24.3.92; bad indentation in shell script mode Date: Thu, 04 Dec 2014 10:09:59 -0500 Message-ID: References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1417705886 10502 80.91.229.3 (4 Dec 2014 15:11:26 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 4 Dec 2014 15:11:26 +0000 (UTC) Cc: 18031-done@debbugs.gnu.org To: Gilles Pion Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Thu Dec 04 16:11:19 2014 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1XwY3q-0003iM-9E for geb-bug-gnu-emacs@m.gmane.org; Thu, 04 Dec 2014 16:11:18 +0100 Original-Received: from localhost ([::1]:46314 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XwY3p-0002pB-PU for geb-bug-gnu-emacs@m.gmane.org; Thu, 04 Dec 2014 10:11:17 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:46242) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XwY3g-0002oz-W4 for bug-gnu-emacs@gnu.org; Thu, 04 Dec 2014 10:11:14 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XwY3b-00019K-3z for bug-gnu-emacs@gnu.org; Thu, 04 Dec 2014 10:11:08 -0500 Original-Received: from debbugs.gnu.org ([140.186.70.43]:56515) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XwY3b-000197-1d for bug-gnu-emacs@gnu.org; Thu, 04 Dec 2014 10:11:03 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1XwY3a-0001uc-Lb for bug-gnu-emacs@gnu.org; Thu, 04 Dec 2014 10:11:02 -0500 Resent-From: Stefan Monnier Original-Sender: "Debbugs-submit" Resent-To: bug-gnu-emacs@gnu.org Resent-Date: Thu, 04 Dec 2014 15:11:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: cc-closed 18031 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Mail-Followup-To: 18031@debbugs.gnu.org, monnier@iro.umontreal.ca, gpion@lfdj.com Original-Received: via spool by 18031-done@debbugs.gnu.org id=D18031.14177058037274 (code D ref 18031); Thu, 04 Dec 2014 15:11:02 +0000 Original-Received: (at 18031-done) by debbugs.gnu.org; 4 Dec 2014 15:10:03 +0000 Original-Received: from localhost ([127.0.0.1]:53726 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1XwY2c-0001t5-BW for submit@debbugs.gnu.org; Thu, 04 Dec 2014 10:10:03 -0500 Original-Received: from ironport2-out.teksavvy.com ([206.248.154.181]:2487) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1XwY2a-0001sk-5M for 18031-done@debbugs.gnu.org; Thu, 04 Dec 2014 10:10:01 -0500 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Am8PAOwQflRMCqTq/2dsb2JhbABbgweBK4I1hVrFHQQCAoEkFwEBAQEBAXyEAwEBAwFWIwULCw4mEhQYDSQTiDcJ1lkBAQEBAQEEAQEBAQEdkG8HhEgFiwGSMYZRiyyBeIQZITCCRwEBAQ X-IPAS-Result: Am8PAOwQflRMCqTq/2dsb2JhbABbgweBK4I1hVrFHQQCAoEkFwEBAQEBAXyEAwEBAwFWIwULCw4mEhQYDSQTiDcJ1lkBAQEBAQEEAQEBAQEdkG8HhEgFiwGSMYZRiyyBeIQZITCCRwEBAQ X-IronPort-AV: E=Sophos;i="5.07,502,1413259200"; d="scan'208";a="99548122" Original-Received: from 76-10-164-234.dsl.teksavvy.com (HELO pastel.home) ([76.10.164.234]) by ironport2-out.teksavvy.com with ESMTP/TLS/DHE-RSA-AES256-SHA; 04 Dec 2014 10:09:59 -0500 Original-Received: by pastel.home (Postfix, from userid 20848) id 49359996B; Thu, 4 Dec 2014 10:09:59 -0500 (EST) In-Reply-To: (Gilles Pion's message of "Wed, 16 Jul 2014 14:08:26 +0200") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (gnu/linux) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:96859 Archived-At: 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 + + * 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 * 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.