unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#55764: 29.0.50; sh-mode: Support mksh's alternate case brace syntax
@ 2022-06-02 13:33 Visuwesh
  2022-06-02 13:40 ` Lars Ingebrigtsen
  0 siblings, 1 reply; 7+ messages in thread
From: Visuwesh @ 2022-06-02 13:33 UTC (permalink / raw)
  To: 55764

[-- Attachment #1: Type: text/plain, Size: 448 bytes --]

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.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: mksh-braces.patch --]
[-- Type: text/x-diff, Size: 810 bytes --]

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)

[-- Attachment #3: Type: text/plain, Size: 356 bytes --]


--

[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; }.

^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2024-01-12  3:13 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-02 13:33 bug#55764: 29.0.50; sh-mode: Support mksh's alternate case brace syntax Visuwesh
2022-06-02 13:40 ` Lars Ingebrigtsen
2022-06-02 14:01   ` Visuwesh
2023-10-01  2:30     ` Stefan Kangas
2023-10-01  3:37     ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-01-10 22:24       ` Stefan Kangas
2024-01-12  3:13         ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).