From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: Issue with bash new syntax. Date: Tue, 26 Jan 2021 17:53:42 -0500 Message-ID: References: <20210126141706.uk5dtaenpdbydfr6.ref@Ergus> <20210126141706.uk5dtaenpdbydfr6@Ergus> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="35707"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: emacs-devel@gnu.org To: Ergus Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Tue Jan 26 23:54:44 2021 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1l4XES-0009Bb-Ji for ged-emacs-devel@m.gmane-mx.org; Tue, 26 Jan 2021 23:54:44 +0100 Original-Received: from localhost ([::1]:33856 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l4XER-0000QA-LH for ged-emacs-devel@m.gmane-mx.org; Tue, 26 Jan 2021 17:54:43 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:43724) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l4XDj-0008Q1-Ou for emacs-devel@gnu.org; Tue, 26 Jan 2021 17:54:00 -0500 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:58484) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l4XDh-0005CY-4M for emacs-devel@gnu.org; Tue, 26 Jan 2021 17:53:58 -0500 Original-Received: from pmg3.iro.umontreal.ca (localhost [127.0.0.1]) by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id 885E54406B2; Tue, 26 Jan 2021 17:53:55 -0500 (EST) Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id E4281440642; Tue, 26 Jan 2021 17:53:52 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1611701632; bh=JyLOKDTeqg52PW3Dyoxs9KACIr1xATHqINMjsXTV+5Q=; h=From:To:Cc:Subject:References:Date:In-Reply-To:From; b=Tw8ovKcUpPEjIFeBOm+aET4tPIPCOqsFI5KtctQbkzIvAHsnhlxSnI1BFK/SLb+wE OWFxsx2Xvx9l16eWtqOrC1tSdI6aFM65GqErb+YOX8SlI10AUshlZIjCNr9QHm+Nt8 O9S1xlo7/QNJRQeTHibZLkbKBBAyUM8//zhPj8wwdqVIcTKFSIsinUbvownfyUxPWc mmIbWffGY7orfPebsQXdYfWiM5Zc7EGsfCjd610DoHyfHSyb0N760TgtoR4/J2BFjj TGFOMhWpzaYR9EBEYYaPGVzfcEI6s2ZtdRafZ+HgaknGC6+KXMxKjxFdT9nMqcTejk Olwlfh0ad9Q9w== Original-Received: from alfajor (69-196-141-46.dsl.teksavvy.com [69.196.141.46]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id AE45D120263; Tue, 26 Jan 2021 17:53:52 -0500 (EST) In-Reply-To: <20210126141706.uk5dtaenpdbydfr6@Ergus> (Ergus's message of "Tue, 26 Jan 2021 15:17:06 +0100") Received-SPF: pass client-ip=132.204.25.50; envelope-from=monnier@iro.umontreal.ca; helo=mailscanner.iro.umontreal.ca X-Spam_score_int: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:263484 Archived-At: > I am observing some issues with the indentation of the modern for loop > syntax in bash: > > for ((it=0; it<${limit}; ++it)) > { > echo "whatever $it" > } > > > The question-issue comes in two parts. > > Question: How can I configure to remove the extra indentation before `{`? > In cc-mode there is a procedure, a bit cumbersome, but working. But > sh-mode does not have such a thing. You can't really configure it easily, currently. The patch below should take care of it, tho. > Issue: > When this loop is nested inside an if or another for loop the > closing indentation seems to be broken > > for dim in ${dims[@]}; do > for bs in ${blocksizes[@]}; do > if [ something ]; then > for ((it=0; it<${ARGS[R]}; ++it)) > { > whatever... > } > --> else > somethingelse > --> fi > --> done > --> done > > Should I report a bug for this? Yes. The problem is that sh expects `for` to be followed by `do...done` before the loop is over, so as far as `sh-mode` is concerned we're still in the part of the `for` loop before the `do...done`. It's not trivial to fix, so better make it a real bug report so it doesn't get lost. Stefan diff --git a/lisp/progmodes/sh-script.el b/lisp/progmodes/sh-script.el index cc045a1b2d..a8e7c9f70e 100644 --- a/lisp/progmodes/sh-script.el +++ b/lisp/progmodes/sh-script.el @@ -1957,12 +1957,17 @@ sh-smie-sh-rules ('(:after . "case-)") (- (sh-var-value 'sh-indent-for-case-alt) (sh-var-value 'sh-indent-for-case-label))) (`(:before . ,(or "(" "{" "[" "while" "if" "for" "case")) - (if (not (smie-rule-prev-p "&&" "||" "|")) - (when (smie-rule-hanging-p) - (smie-rule-parent)) + (cond + ((and (equal token "{") (smie-rule-parent-p "for")) + (let ((data (smie-backward-sexp "in"))) + `(column . ,(smie-indent-virtual)))) + ((not (smie-rule-prev-p "&&" "||" "|")) + (when (smie-rule-hanging-p) + (smie-rule-parent))) + (t (unless (smie-rule-bolp) (while (equal "|" (nth 2 (smie-backward-sexp 'halfexp)))) - `(column . ,(smie-indent-virtual))))) + `(column . ,(smie-indent-virtual)))))) ;; FIXME: Maybe this handling of ;; should be made into ;; a smie-rule-terminator function that takes the substitute ";" as arg. (`(:before . ,(or ";;" ";&" ";;&"))