From unknown Sun Jun 22 22:41:31 2025 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Mailer: MIME-tools 5.509 (Entity 5.509) Content-Type: text/plain; charset=utf-8 From: bug#17620 <17620@debbugs.gnu.org> To: bug#17620 <17620@debbugs.gnu.org> Subject: Status: sh-mode indentation of continued do loop lists Reply-To: bug#17620 <17620@debbugs.gnu.org> Date: Mon, 23 Jun 2025 05:41:31 +0000 retitle 17620 sh-mode indentation of continued do loop lists reassign 17620 emacs submitter 17620 Glenn Morris severity 17620 minor thanks From debbugs-submit-bounces@debbugs.gnu.org Wed May 28 17:26:24 2014 Received: (at submit) by debbugs.gnu.org; 28 May 2014 21:26:25 +0000 Received: from localhost ([127.0.0.1]:34866 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1WplMc-0007Eq-Ux for submit@debbugs.gnu.org; Wed, 28 May 2014 17:26:24 -0400 Received: from fencepost.gnu.org ([208.118.235.10]:46340 ident=Debian-exim) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1WplMa-0007Ei-JR for submit@debbugs.gnu.org; Wed, 28 May 2014 17:26:21 -0400 Received: from rgm by fencepost.gnu.org with local (Exim 4.71) (envelope-from ) id 1WplMZ-00065T-Kl; Wed, 28 May 2014 17:26:19 -0400 From: Glenn Morris To: submit@debbugs.gnu.org Subject: sh-mode indentation of continued do loop lists X-Spook: Steve Case Compsec Qaddafi FSF S Key SCUD missile anarchy X-Ran: Sw01T5d*7NWhU>b]Y$KMxYo>_Ph|:h#4|EKIT$fL0^67wNFVxkmj7g1E29_wNR)8%H86"M X-Hue: yellow X-Debbugs-No-Ack: yes X-Attribution: GM Date: Wed, 28 May 2014 17:26:19 -0400 Message-ID: User-Agent: Gnus (www.gnus.org), GNU Emacs (www.gnu.org/software/emacs/) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Spam-Score: -5.7 (-----) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -5.7 (-----) Package: emacs Version: 24.3.91 Severity: minor emacs -Q foo.sh, where foo.sh is as follows: for foo in a \ b; do echo $foo done In 24.3, using indent-region or indenting line-by-line produces the above. In 24.3.91, the continued line gets way too much indentation: for foo in a \ b; do echo $foo done From debbugs-submit-bounces@debbugs.gnu.org Wed May 28 22:24:00 2014 Received: (at 17620) by debbugs.gnu.org; 29 May 2014 02:24:00 +0000 Received: from localhost ([127.0.0.1]:34999 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Wpq0e-00086A-19 for submit@debbugs.gnu.org; Wed, 28 May 2014 22:24:00 -0400 Received: from ironport2-out.teksavvy.com ([206.248.154.181]:50388) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Wpq0a-00085l-TS for 17620@debbugs.gnu.org; Wed, 28 May 2014 22:23:57 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ArUGAIDvNVNLd/fU/2dsb2JhbABZgwaDSsA9gRcXdIIlAQEBAQIBViMFCwsOJhIUGA0kiAQI0hkXjnoHhDgEqRmBaoNMIQ X-IPAS-Result: ArUGAIDvNVNLd/fU/2dsb2JhbABZgwaDSsA9gRcXdIIlAQEBAQIBViMFCwsOJhIUGA0kiAQI0hkXjnoHhDgEqRmBaoNMIQ X-IronPort-AV: E=Sophos;i="4.97,753,1389762000"; d="scan'208";a="64920202" Received: from 75-119-247-212.dsl.teksavvy.com (HELO pastel.home) ([75.119.247.212]) by ironport2-out.teksavvy.com with ESMTP/TLS/ADH-AES256-SHA; 28 May 2014 22:23:51 -0400 Received: by pastel.home (Postfix, from userid 20848) id B7547601CB; Wed, 28 May 2014 22:23:50 -0400 (EDT) From: Stefan Monnier To: Glenn Morris Subject: Re: bug#17620: sh-mode indentation of continued do loop lists Message-ID: References: Date: Wed, 28 May 2014 22:23:50 -0400 In-Reply-To: (Glenn Morris's message of "Wed, 28 May 2014 17:26:19 -0400") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4.50 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: 0.3 (/) X-Debbugs-Envelope-To: 17620 Cc: 17620@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.3 (/) > In 24.3.91, the continued line gets way too much indentation: > for foo in a \ > b; do > echo $foo > done I think this requires a config variable: - The indentation you show above is the one that makes sense to me, where the \ is just a way to write "a b" on multiple logical lines, like you can do in most free-form programming languages, in which case "b", being an argument to "a", should be indented a bit deeper than "a". I.e. the indentation rule pretends the \ don't really exist. - The indentation you ask for seems to be based on the idea that "\" is a way to split a single logical line into several physical lines, doing a kind of manual "word wrap". IOW the first view would want for f in a; do \ for g in b; do \ echo toto; \ done; \ done [ tho I see now that the current code fails here (probably because it doesn't understand that the "do"s are "hanging"). ] whereas the second view would want for f in a; do \ for g in b; do \ echo toto; \ done; \ done I don't see a way to reconcile those two views, hence the need for a config variable to choose between those two schools. Stefan From debbugs-submit-bounces@debbugs.gnu.org Wed May 28 23:06:16 2014 Received: (at 17620) by debbugs.gnu.org; 29 May 2014 03:06:16 +0000 Received: from localhost ([127.0.0.1]:35014 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1WpqfX-000137-Rq for submit@debbugs.gnu.org; Wed, 28 May 2014 23:06:16 -0400 Received: from fencepost.gnu.org ([208.118.235.10]:51319 ident=Debian-exim) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1WpqfV-00012w-FN for 17620@debbugs.gnu.org; Wed, 28 May 2014 23:06:14 -0400 Received: from rgm by fencepost.gnu.org with local (Exim 4.71) (envelope-from ) id 1WpqfU-0007qK-CP; Wed, 28 May 2014 23:06:12 -0400 From: Glenn Morris To: Stefan Monnier Subject: Re: bug#17620: sh-mode indentation of continued do loop lists References: X-Spook: 64 Vauxhall Cross Janet Reno Noriega Dick Cheney bemd X-Ran: {#`o];J}.x4yys~o[?]ZPsy46vC"|Cxx(qF!DqfF5F.s=(Lk88,V-lOpP;^hG3pG\gv8fw X-Hue: red X-Debbugs-No-Ack: yes X-Attribution: GM Date: Wed, 28 May 2014 23:06:12 -0400 In-Reply-To: (Stefan Monnier's message of "Wed, 28 May 2014 22:23:50 -0400") Message-ID: <7e61kpnv17.fsf@fencepost.gnu.org> User-Agent: Gnus (www.gnus.org), GNU Emacs (www.gnu.org/software/emacs/) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Spam-Score: -5.7 (-----) X-Debbugs-Envelope-To: 17620 Cc: 17620@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -5.7 (-----) Stefan Monnier wrote: > I think this requires a config variable: > > - The indentation you show above is the one that makes sense to me, > where the \ is just a way to write "a b" on multiple logical lines, > like you can do in most free-form programming languages, in which case > "b", being an argument to "a", should be indented a bit deeper than > "a". I.e. the indentation rule pretends the \ don't really exist. > > - The indentation you ask for seems to be based on the idea that "\" is > a way to split a single logical line into several physical lines, > doing a kind of manual "word wrap". Oh right, I see, now we get: some-really-rather-long-command arg1 \ arg2 rather than the old some-really-rather-long-command arg1 \ arg2 where continued lines were always just indented +4. I'm accustomed to the old dumb method. A config var would make me happy. From debbugs-submit-bounces@debbugs.gnu.org Wed Feb 18 14:14:51 2015 Received: (at 17620) by debbugs.gnu.org; 18 Feb 2015 19:14:51 +0000 Received: from localhost ([127.0.0.1]:48035 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1YOA5D-0006Jo-5c for submit@debbugs.gnu.org; Wed, 18 Feb 2015 14:14:51 -0500 Received: from mail-lb0-f180.google.com ([209.85.217.180]:33023) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1YOA1o-0006EC-MN for 17620@debbugs.gnu.org; Wed, 18 Feb 2015 14:11:21 -0500 Received: by lbvp9 with SMTP id p9so3187078lbv.0 for <17620@debbugs.gnu.org>; Wed, 18 Feb 2015 11:11:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:from:date:message-id:subject:to:content-type; bh=NNKfsGe/pmSglQO3+lyPrg11cXZfGBTm03sA8bhH7QY=; b=gUt5FhuaicRGtCLylDIoDQfcdyo06l1JX2nsg8k7yCjTjSXTNp3J0GGBTuwA1ZZQZZ R/XpwrmwMsCUEUeqplDJoLSWm5gLE812MAFA879LduSsWKRTZZ/BtMJ2eNYd/yP1POvB ogXI4ZXJTCG1q4Q9OFOQySQW8gEQq4jvBQ6NbNDTCOMl/K604STyo/uFVjvWHPwBW9Pt 0XMBYTyt9bf3umh6oLQm5jAbgFuUd9PXUj0xfJ3zbppFi0ER7YrRJl65F4SBEIGISsL4 8b2hr+69wm1u12qs6PsF/7Tn19F9iDyyJAXQ72krA+TBpg4WRrMWqX+uHv4F/sK7vvke 3QYg== X-Received: by 10.152.87.84 with SMTP id v20mr669423laz.81.1424286679872; Wed, 18 Feb 2015 11:11:19 -0800 (PST) MIME-Version: 1.0 From: Philipp Stephani Date: Wed, 18 Feb 2015 19:11:19 +0000 Message-ID: Subject: Re: bug#17620: sh-mode indentation of continued do loop lists To: 17620@debbugs.gnu.org Content-Type: multipart/alternative; boundary=001a11c3337e9cbc2e050f61959f X-Spam-Score: -0.4 (/) X-Debbugs-Envelope-To: 17620 X-Mailman-Approved-At: Wed, 18 Feb 2015 14:14:49 -0500 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.4 (/) --001a11c3337e9cbc2e050f61959f Content-Type: text/plain; charset=UTF-8 This affects me as well, is there any workaround? --001a11c3337e9cbc2e050f61959f Content-Type: text/html; charset=UTF-8
This affects me as well, is there any workaround?
--001a11c3337e9cbc2e050f61959f-- From debbugs-submit-bounces@debbugs.gnu.org Wed Feb 18 14:18:14 2015 Received: (at 17620) by debbugs.gnu.org; 18 Feb 2015 19:18:14 +0000 Received: from localhost ([127.0.0.1]:48040 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1YOA8U-0006PO-2n for submit@debbugs.gnu.org; Wed, 18 Feb 2015 14:18:14 -0500 Received: from fencepost.gnu.org ([208.118.235.10]:46297) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1YOA8S-0006PG-JT for 17620@debbugs.gnu.org; Wed, 18 Feb 2015 14:18:12 -0500 Received: from rgm by fencepost.gnu.org with local (Exim 4.71) (envelope-from ) id 1YOA8R-00032s-Kx; Wed, 18 Feb 2015 14:18:11 -0500 From: Glenn Morris To: Philipp Stephani Subject: Re: bug#17620: sh-mode indentation of continued do loop lists References: X-Spook: Cohiba bluebird oil LABLINK Crypto AG bce Afghanistan PLO X-Ran: vN^Y9k1^p|B;%5~1VYV==iNje77KT,(Kzr7C:#U)UCq(PzO6K|:6M=&>eGP!aXB\vPye~J X-Hue: red X-Debbugs-No-Ack: yes X-Attribution: GM Date: Wed, 18 Feb 2015 14:18:11 -0500 In-Reply-To: (Philipp Stephani's message of "Wed, 18 Feb 2015 19:11:19 +0000") Message-ID: User-Agent: Gnus (www.gnus.org), GNU Emacs (www.gnu.org/software/emacs/) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Spam-Score: -5.0 (-----) X-Debbugs-Envelope-To: 17620 Cc: 17620@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -5.0 (-----) I haven't checked, but the sledgehammer approach of (setq sh-use-smie nil) before loading sh-script ought to work, in theory. Presumably this option will go away at some point in the future though. From debbugs-submit-bounces@debbugs.gnu.org Tue Sep 29 21:46:41 2015 Received: (at 17620-done) by debbugs.gnu.org; 30 Sep 2015 01:46:41 +0000 Received: from localhost ([127.0.0.1]:48360 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Zh6Th-0000S8-2u for submit@debbugs.gnu.org; Tue, 29 Sep 2015 21:46:41 -0400 Received: from ironport2-out.teksavvy.com ([206.248.154.181]:40198) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Zh6Tf-0000Rz-1f for 17620-done@debbugs.gnu.org; Tue, 29 Sep 2015 21:46:39 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A0A2FgA731xV/wihxEVcgxCEAoVVu0CEfoJNBAICgTw6EwEBAQEBAQGBCkEFg10BAQMBViMQCw4mEhQYDSSINwjPIwEBAQEBAQQBAQEBHos6hQUHhC0FhQmWW5dbgUUjgWaCLiKCeAEBAQ X-IPAS-Result: A0A2FgA731xV/wihxEVcgxCEAoVVu0CEfoJNBAICgTw6EwEBAQEBAQGBCkEFg10BAQMBViMQCw4mEhQYDSSINwjPIwEBAQEBAQQBAQEBHos6hQUHhC0FhQmWW5dbgUUjgWaCLiKCeAEBAQ X-IronPort-AV: E=Sophos;i="5.13,465,1427774400"; d="scan'208";a="166437498" Received: from 69-196-161-8.dsl.teksavvy.com (HELO pastel.home) ([69.196.161.8]) by ironport2-out.teksavvy.com with ESMTP; 29 Sep 2015 21:46:37 -0400 Received: by pastel.home (Postfix, from userid 20848) id 7B20C627CC; Tue, 29 Sep 2015 21:46:37 -0400 (EDT) From: Stefan Monnier To: Glenn Morris Subject: Re: bug#17620: sh-mode indentation of continued do loop lists Message-ID: References: Date: Tue, 29 Sep 2015 21:46:37 -0400 In-Reply-To: (Stefan Monnier's message of "Wed, 28 May 2014 22:23:50 -0400") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: 0.3 (/) X-Debbugs-Envelope-To: 17620-done Cc: 17620-done@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.3 (/) >> In 24.3.91, the continued line gets way too much indentation: >> for foo in a \ >> b; do >> echo $foo >> done > I think this requires a config variable: You can now set sh-indent-after-continuation to `always' to get the "dumb" behavior. Stefan diff --git a/lisp/progmodes/sh-script.el b/lisp/progmodes/sh-script.el index 049c93d..89d36bc 100644 --- a/lisp/progmodes/sh-script.el +++ b/lisp/progmodes/sh-script.el @@ -1991,9 +1991,30 @@ Does not preserve point." (t tok))))))) (defcustom sh-indent-after-continuation t - "If non-nil, try to make sure text is indented after a line continuation." - :version "24.3" - :type 'boolean + "If non-nil, indent relative to the continued line's beginning. +Continued lines can either be indented as \"one long wrapped line\" without +paying attention to the actual syntactic structure, as in: + + for f \ + in a; do \ + toto; \ + done + +or as lines that just don't have implicit semi-colons between them, as in: + + for f \ + in a; do \ + toto; \ + done + +With `always' you get the former behavior whereas with nil you get the latter. +With t, you get the latter except if that would not indent the continuation line +deeper than the initial line." + :version "25.1" + :type '(choice + (const nil :tag "Never") + (const t :tag "Only if needed to make it deeper") + (const always :tag "Always")) :group 'sh-indentation) (defun sh-smie--continuation-start-indent () @@ -2004,24 +2025,49 @@ May return nil if the line should not be treated as continued." (unless (sh-smie--looking-back-at-continuation-p) (current-indentation)))) +(defun sh-smie--indent-continuation () + (cond + ((not (and sh-indent-after-continuation + (save-excursion + (ignore-errors + (skip-chars-backward " \t") + (sh-smie--looking-back-at-continuation-p))))) + nil) + ((eq sh-indent-after-continuation 'always) + (save-excursion + (forward-line -1) + (if (sh-smie--looking-back-at-continuation-p) + (current-indentation) + (+ (current-indentation) sh-indentation)))) + (t + ;; Just make sure a line-continuation is indented deeper. + (save-excursion + (let ((indent (let ((sh-indent-after-continuation nil)) + (smie-indent-calculate))) + (max most-positive-fixnum)) + (if (not (numberp indent)) indent + (while (progn + (forward-line -1) + (let ((ci (current-indentation))) + (cond + ;; Previous line is less indented, we're good. + ((< ci indent) nil) + ((sh-smie--looking-back-at-continuation-p) + (setq max (min max ci)) + ;; Previous line is itself a continuation. + ;; If it's indented like us, we're good, otherwise + ;; check the line before that one. + (> ci indent)) + (t ;Previous line is the beginning of the continued line. + (setq indent (min (+ ci sh-indentation) max)) + nil))))) + indent)))))) + (defun sh-smie-sh-rules (kind token) (pcase (cons kind token) (`(:elem . basic) sh-indentation) (`(:after . "case-)") (- (sh-var-value 'sh-indent-for-case-alt) (sh-var-value 'sh-indent-for-case-label))) - ((and `(:before . ,_) - ;; After a line-continuation, make sure the rest is indented. - (guard sh-indent-after-continuation) - (guard (save-excursion - (ignore-errors - (skip-chars-backward " \t") - (sh-smie--looking-back-at-continuation-p)))) - (let initial (sh-smie--continuation-start-indent)) - (guard (let* ((sh-indent-after-continuation nil) - (indent (smie-indent-calculate))) - (and (numberp indent) (numberp initial) - (<= indent initial))))) - `(column . ,(+ initial sh-indentation))) (`(:before . ,(or `"(" `"{" `"[" "while" "if" "for" "case")) (if (not (smie-rule-prev-p "&&" "||" "|")) (when (smie-rule-hanging-p) @@ -2363,6 +2409,7 @@ Calls the value of `sh-set-shell-hook' if set." (if (looking-at "[ \t]*\\\\\n") (goto-char (match-end 0)) (funcall orig)))) + (add-hook 'smie-indent-functions #'sh-smie--indent-continuation nil t) (smie-setup (symbol-value (funcall mksym "grammar")) (funcall mksym "rules") :forward-token (funcall mksym "forward-token") From unknown Sun Jun 22 22:41:31 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Wed, 28 Oct 2015 11:24:04 +0000 User-Agent: Fakemail v42.6.9 # This is a fake control message. # # The action: # bug archived. thanks # This fakemail brought to you by your local debbugs # administrator