GNU bug report logs - #55764
29.0.50; sh-mode: Support mksh's alternate case brace syntax

Previous Next

Package: emacs;

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

From: help-debbugs <at> gnu.org (GNU bug Tracking System)
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: tracker <at> debbugs.gnu.org
Subject: bug#55764: closed (29.0.50; sh-mode: Support mksh's alternate
 case brace syntax)
Date: Fri, 12 Jan 2024 03:14:01 +0000
[Message part 1 (text/plain, inline)]
Your message dated Thu, 11 Jan 2024 22:13:10 -0500
with message-id <jwvle8vnt1u.fsf-monnier+emacs <at> gnu.org>
and subject line Re: bug#55764: 29.0.50; sh-mode: Support mksh's alternate case brace syntax
has caused the debbugs.gnu.org bug report #55764,
regarding 29.0.50; sh-mode: Support mksh's alternate case brace syntax
to be marked as done.

(If you believe you have received this mail in error, please contact
help-debbugs <at> gnu.org.)


-- 
55764: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=55764
GNU Bug Tracking System
Contact help-debbugs <at> gnu.org with problems
[Message part 2 (message/rfc822, inline)]
From: Visuwesh <visuweshm <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: 29.0.50; sh-mode: Support mksh's alternate case brace syntax
Date: Thu, 02 Jun 2022 19:03:47 +0530
[Message part 3 (text/plain, inline)]
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.

[mksh-braces.patch (text/x-diff, inline)]
diff --git a/lisp/progmodes/sh-script.el b/lisp/progmodes/sh-script.el
index 4d2554c087..588d9038e5 100644
--- a/lisp/progmodes/sh-script.el
+++ b/lisp/progmodes/sh-script.el
@@ -1971,9 +1971,10 @@
                              (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 "{") (or (smie-rule-parent-p "for")
+                                  (smie-rule-parent-p "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)
[Message part 5 (text/plain, inline)]
--

[1] Here's what the mksh manual says,

    For historical reasons, open and close braces may be used instead
    of in and esac, for example: “case $foo { (ba[rz]|blah) date ;; }”

and OpenBSD's ksh manual says,

    For historical reasons, open and close braces may be used instead of
    in and esac e.g. case $foo { *) echo bar; }.
[Message part 6 (message/rfc822, inline)]
From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Stefan Kangas <stefankangas <at> gmail.com>
Cc: Lars Ingebrigtsen <larsi <at> gnus.org>, 55764-done <at> debbugs.gnu.org,
 Visuwesh <visuweshm <at> gmail.com>
Subject: Re: bug#55764: 29.0.50; sh-mode: Support mksh's alternate case
 brace syntax
Date: Thu, 11 Jan 2024 22:13:10 -0500
>> The patch below seems to do the trick.
> If you think it looks good, then please install.  Nothing stood out
> when I read it over, FWIW.

Thanks for the reminder.  Pushed.
Closing,


        Stefan



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.