* Issue with bash new syntax.
[not found] <20210126141706.uk5dtaenpdbydfr6.ref@Ergus>
@ 2021-01-26 14:17 ` Ergus
2021-01-26 22:53 ` Stefan Monnier
0 siblings, 1 reply; 2+ messages in thread
From: Ergus @ 2021-01-26 14:17 UTC (permalink / raw)
To: emacs-devel
Hi:
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.
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?
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Issue with bash new syntax.
2021-01-26 14:17 ` Issue with bash new syntax Ergus
@ 2021-01-26 22:53 ` Stefan Monnier
0 siblings, 0 replies; 2+ messages in thread
From: Stefan Monnier @ 2021-01-26 22:53 UTC (permalink / raw)
To: Ergus; +Cc: emacs-devel
> 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 ";;" ";&" ";;&"))
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-01-26 22:53 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20210126141706.uk5dtaenpdbydfr6.ref@Ergus>
2021-01-26 14:17 ` Issue with bash new syntax Ergus
2021-01-26 22:53 ` Stefan Monnier
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.