aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Monnier2024-01-11 22:12:34 -0500
committerStefan Monnier2024-01-11 22:12:34 -0500
commiteac3f2a80778b3904c55ae7b65ff862a79eebf2a (patch)
treebe74433945c3d27e4ecfc09460b68b116cfd617e
parentbfb486d8026424ec0859036b3686df9cab1383df (diff)
downloademacs-eac3f2a80778b3904c55ae7b65ff862a79eebf2a.tar.gz
emacs-eac3f2a80778b3904c55ae7b65ff862a79eebf2a.zip
sh-script.el: Add support for `case FOO {...}` (bug#55764)
* 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.
-rw-r--r--lisp/progmodes/sh-script.el7
-rwxr-xr-xtest/manual/indent/shell.sh7
2 files changed, 11 insertions, 3 deletions
diff --git a/lisp/progmodes/sh-script.el b/lisp/progmodes/sh-script.el
index 0562415b4e5..2a650fe0ea6 100644
--- a/lisp/progmodes/sh-script.el
+++ b/lisp/progmodes/sh-script.el
@@ -1054,7 +1054,8 @@ subshells can nest."
1054 ;; a normal command rather than the real `in' keyword. 1054 ;; a normal command rather than the real `in' keyword.
1055 ;; I.e. we should look back to try and find the 1055 ;; I.e. we should look back to try and find the
1056 ;; corresponding `case'. 1056 ;; corresponding `case'.
1057 (and (looking-at ";\\(?:;&?\\|[&|]\\)\\|\\_<in") 1057 ;; Also recognize OpenBSD's case X { ... } (bug#55764).
1058 (and (looking-at ";\\(?:;&?\\|[&|]\\)\\|\\_<in\\|.{")
1058 ;; ";; esac )" is a case that looks 1059 ;; ";; esac )" is a case that looks
1059 ;; like a case-pattern but it's really just a close 1060 ;; like a case-pattern but it's really just a close
1060 ;; paren after a case statement. I.e. if we skipped 1061 ;; 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."
2057 (sh-var-value 'sh-indent-for-case-label))) 2058 (sh-var-value 'sh-indent-for-case-label)))
2058 (`(:before . ,(or "(" "{" "[" "while" "if" "for" "case")) 2059 (`(:before . ,(or "(" "{" "[" "while" "if" "for" "case"))
2059 (cond 2060 (cond
2060 ((and (equal token "{") (smie-rule-parent-p "for")) 2061 ((and (equal token "{") (smie-rule-parent-p "for" "case"))
2061 (let ((data (smie-backward-sexp "in"))) 2062 (let ((data (smie-backward-sexp "in")))
2062 (when (equal (nth 2 data) "for") 2063 (when (member (nth 2 data) '("for" "case"))
2063 `(column . ,(smie-indent-virtual))))) 2064 `(column . ,(smie-indent-virtual)))))
2064 ((not (smie-rule-prev-p "&&" "||" "|")) 2065 ((not (smie-rule-prev-p "&&" "||" "|"))
2065 (when (smie-rule-hanging-p) 2066 (when (smie-rule-hanging-p)
diff --git a/test/manual/indent/shell.sh b/test/manual/indent/shell.sh
index 5b3fb0e66fb..42a981d312e 100755
--- a/test/manual/indent/shell.sh
+++ b/test/manual/indent/shell.sh
@@ -189,3 +189,10 @@ bar () {
189 189
190 fi 190 fi
191} 191}
192
193case $i { # Bug#55764
194 *pattern)
195 (cd .; echo hi);
196 do1 ;;
197 *pattern2) do2 ;;
198}