]> git.eshelyaron.com Git - emacs.git/commitdiff
sh-script.el: Add support for `case FOO {...}` (bug#55764)
authorStefan Monnier <monnier@iro.umontreal.ca>
Fri, 12 Jan 2024 03:12:34 +0000 (22:12 -0500)
committerStefan Monnier <monnier@iro.umontreal.ca>
Fri, 12 Jan 2024 03:12:34 +0000 (22:12 -0500)
* lisp/progmodes/sh-script.el (sh-font-lock-paren): Also recognize
`FOO)` after `{`.
(sh-smie-sh-rules): Make `for` rule apply to `case FOO { ...}` as well.

* test/manual/indent/shell.sh: Add new test case.

lisp/progmodes/sh-script.el
test/manual/indent/shell.sh

index 0562415b4e5faa710db8dcd55bab452806c70118..2a650fe0ea66eeb81f4b755a068add65513acc0f 100644 (file)
@@ -1054,7 +1054,8 @@ subshells can nest."
                     ;; a normal command rather than the real `in' keyword.
                     ;; I.e. we should look back to try and find the
                     ;; corresponding `case'.
-                    (and (looking-at ";\\(?:;&?\\|[&|]\\)\\|\\_<in")
+                    ;; Also recognize OpenBSD's case X { ... } (bug#55764).
+                    (and (looking-at ";\\(?:;&?\\|[&|]\\)\\|\\_<in\\|.{")
                          ;; ";; esac )" is a case that looks
                          ;; like a case-pattern but it's really just a close
                          ;; paren after a case statement.  I.e. if we skipped
@@ -2057,9 +2058,9 @@ May return nil if the line should not be treated as continued."
                              (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)
index 5b3fb0e66fbddfe39bf70cab8dd52a43dd4e603e..42a981d312ed6324f88ecd6104de3d9ba5a4c804 100755 (executable)
@@ -189,3 +189,10 @@ bar () {
 
     fi
 }
+
+case $i {                       # Bug#55764
+    *pattern)
+        (cd .; echo hi);
+        do1 ;;
+    *pattern2) do2 ;;
+}