GNU bug report logs -
#55764
29.0.50; sh-mode: Support mksh's alternate case brace syntax
Previous Next
Reported by: Visuwesh <visuweshm <at> gmail.com>
Date: Thu, 2 Jun 2022 13:35:02 UTC
Severity: wishlist
Tags: patch
Found in version 29.0.50
Done: Stefan Monnier <monnier <at> iro.umontreal.ca>
Bug is archived. No further changes may be made.
Full log
View this message in rfc822 format
[Message part 1 (text/plain, inline)]
[வியாழன் ஜூன் 02, 2022] Lars Ingebrigtsen wrote:
> Visuwesh <visuweshm <at> gmail.com> writes:
>
>> mksh and OpenBSD's ksh support an alternative case syntax for historical
>> reasons [1],
>>
>> case $i {
>> *pattern) do ;;
>> *pattern2) do2 ;;
>> }
>>
>> Currently, sh-mode cannot handle this and the easy way out of writing a
>> semicolon after $i is out since,
>>
>> % case "foo"; { *o) echo 1;; }
>> /bin/mksh: syntax error: unexpected ';'
>>
>> I came with the attached patch after a bit of trial and error but I'm
>> not sure if it is the right way to do it.
>
> I think that might make sense, but perhaps Stefan has some comments here
> (added to the CCs).
To no one's surprise, the patch is not the right approach. IIUC, when I
use braces, *pattern) thingies are not recognised as "case-)" anymore so
sh-indent-for-case-label does not get applied. I tried a bit more but I
only got it to respect the first line but still it is definitely not the
right approach,
[mksh-braces.patch (text/x-diff, inline)]
diff --git a/lisp/progmodes/sh-script.el b/lisp/progmodes/sh-script.el
index 4d2554c087..96ff8e8627 100644
--- a/lisp/progmodes/sh-script.el
+++ b/lisp/progmodes/sh-script.el
@@ -1971,9 +1971,9 @@ sh-smie-sh-rules
(sh-var-value 'sh-indent-for-case-label)))
(`(:before . ,(or "(" "{" "[" "while" "if" "for" "case"))
(cond
- ((and (equal token "{") (smie-rule-parent-p "for"))
+ ((and (equal token "{") (smie-rule-parent-p "for" "case"))
(let ((data (smie-backward-sexp "in")))
- (when (equal (nth 2 data) "for")
+ (when (member (nth 2 data) '("for" "case"))
`(column . ,(smie-indent-virtual)))))
((not (smie-rule-prev-p "&&" "||" "|"))
(when (smie-rule-hanging-p)
@@ -2021,10 +2021,13 @@ sh-smie-sh-rules
('(:after . "in") (sh-var-value 'sh-indent-for-case-label))
;; sh-indent-for-continuation: Line continuations are handled differently.
(`(:after . ,(or "(" "{" "["))
- (if (not (looking-at ".[ \t]*[^\n \t#]"))
- (sh-var-value 'sh-indent-after-open)
- (goto-char (1- (match-end 0)))
- `(column . ,(current-column))))
+ (cond
+ ((smie-rule-parent-p "case")
+ (sh-var-value 'sh-indent-for-case-label))
+ ((not (looking-at ".[ \t]*[^\n \t#]"))
+ (sh-var-value 'sh-indent-after-open))
+ (t (goto-char (1- (match-end 0)))
+ `(column . ,(current-column)))))
;; sh-indent-after-function: we don't handle it differently.
))
This bug report was last modified 1 year and 215 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.