[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master a572b21: * lisp/progmodes/sh-script.el (sh-smie-sh-rules): Tweak
From: |
Stefan Monnier |
Subject: |
master a572b21: * lisp/progmodes/sh-script.el (sh-smie-sh-rules): Tweak indent of new `for` |
Date: |
Tue, 26 Jan 2021 17:58:53 -0500 (EST) |
branch: master
commit a572b21928a33b7ede445769bde5a67356327fef
Author: Stefan Monnier <monnier@iro.umontreal.ca>
Commit: Stefan Monnier <monnier@iro.umontreal.ca>
* lisp/progmodes/sh-script.el (sh-smie-sh-rules): Tweak indent of new `for`
The new `for (TEST) { BODY }` syntax introduces various challenges.
This patch just fixes a trivial subcase.
---
lisp/progmodes/sh-script.el | 14 ++++++++++----
test/manual/indent/shell.sh | 7 +++++++
2 files changed, 17 insertions(+), 4 deletions(-)
diff --git a/lisp/progmodes/sh-script.el b/lisp/progmodes/sh-script.el
index cc045a1..fd68952 100644
--- a/lisp/progmodes/sh-script.el
+++ b/lisp/progmodes/sh-script.el
@@ -1957,12 +1957,18 @@ May return nil if the line should not be treated as
continued."
('(: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")))
+ (when (equal (nth 2 data) "for")
+ `(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 ";;" ";&" ";;&"))
diff --git a/test/manual/indent/shell.sh b/test/manual/indent/shell.sh
index dc184ea..bd4a74f 100755
--- a/test/manual/indent/shell.sh
+++ b/test/manual/indent/shell.sh
@@ -6,6 +6,13 @@ setlock -n /tmp/getmail.lock && echo getmail isn\'t running
toto=$(grep hello foo |
wc)
+myfun () {
+ for ((it=0; it<${limit}; ++it))
+ {
+ echo "whatever $it"
+ }
+}
+
# adsgsdg
if foo; then
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- master a572b21: * lisp/progmodes/sh-script.el (sh-smie-sh-rules): Tweak indent of new `for`,
Stefan Monnier <=