aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPhilippe Altherr2023-01-15 13:37:00 +0100
committerEli Zaretskii2023-03-02 12:49:32 +0200
commit68f49083af7ac5ffd9cde4bc7167d4e2ccbba4b6 (patch)
tree4c0b322bd1cf2a29796f92a53d0b0aeef65d8e3e
parent30e2a85717c4189994c7ae759888e257225f0a21 (diff)
downloademacs-68f49083af7ac5ffd9cde4bc7167d4e2ccbba4b6.tar.gz
emacs-68f49083af7ac5ffd9cde4bc7167d4e2ccbba4b6.zip
Add support for Zsh's case branches ;|.
* lisp/progmodes/sh-script.el (sh-font-lock-paren) (sh-smie-sh-grammar, sh-smie-sh-rules, sh-smie-rc-grammar): Support case branches ending with ";|", per Zsh. (Bug#60833) * test/manual/indent/shell.sh (bar): Add ";|".
-rw-r--r--lisp/progmodes/sh-script.el18
-rwxr-xr-xtest/manual/indent/shell.sh1
2 files changed, 12 insertions, 7 deletions
diff --git a/lisp/progmodes/sh-script.el b/lisp/progmodes/sh-script.el
index 741803a5175..398a2c8946b 100644
--- a/lisp/progmodes/sh-script.el
+++ b/lisp/progmodes/sh-script.el
@@ -1042,7 +1042,9 @@ subshells can nest."
1042 ;; Maybe we've bumped into an escaped newline. 1042 ;; Maybe we've bumped into an escaped newline.
1043 (sh-is-quoted-p (point))) 1043 (sh-is-quoted-p (point)))
1044 (backward-char 1)) 1044 (backward-char 1))
1045 (when (eq (char-before) ?|) 1045 (when (and
1046 (eq (char-before) ?|)
1047 (not (eq (char-before (1- (point))) ?\;)))
1046 (backward-char 1) t))) 1048 (backward-char 1) t)))
1047 (and (> (point) (1+ (point-min))) 1049 (and (> (point) (1+ (point-min)))
1048 (progn (backward-char 2) 1050 (progn (backward-char 2)
@@ -1053,7 +1055,7 @@ subshells can nest."
1053 ;; a normal command rather than the real `in' keyword. 1055 ;; a normal command rather than the real `in' keyword.
1054 ;; I.e. we should look back to try and find the 1056 ;; I.e. we should look back to try and find the
1055 ;; corresponding `case'. 1057 ;; corresponding `case'.
1056 (and (looking-at ";[;&]\\|\\_<in") 1058 (and (looking-at ";\\(?:;&?\\|[&|]\\)\\|\\_<in")
1057 ;; ";; esac )" is a case that looks 1059 ;; ";; esac )" is a case that looks
1058 ;; like a case-pattern but it's really just a close 1060 ;; like a case-pattern but it's really just a close
1059 ;; paren after a case statement. I.e. if we skipped 1061 ;; paren after a case statement. I.e. if we skipped
@@ -1784,8 +1786,9 @@ before the newline and in that case point should be just before the token."
1784 (pattern (rpattern) ("case-(" rpattern)) 1786 (pattern (rpattern) ("case-(" rpattern))
1785 (branches (branches ";;" branches) 1787 (branches (branches ";;" branches)
1786 (branches ";&" branches) (branches ";;&" branches) ;bash. 1788 (branches ";&" branches) (branches ";;&" branches) ;bash.
1789 (branches ";|" branches) ;zsh.
1787 (pattern "case-)" cmd))) 1790 (pattern "case-)" cmd)))
1788 '((assoc ";;" ";&" ";;&")) 1791 '((assoc ";;" ";&" ";;&" ";|"))
1789 '((assoc ";" "&") (assoc "&&" "||") (assoc "|" "|&"))))) 1792 '((assoc ";" "&") (assoc "&&" "||") (assoc "|" "|&")))))
1790 1793
1791(defconst sh-smie--sh-operators 1794(defconst sh-smie--sh-operators
@@ -2058,11 +2061,11 @@ May return nil if the line should not be treated as continued."
2058 `(column . ,(smie-indent-virtual)))))) 2061 `(column . ,(smie-indent-virtual))))))
2059 ;; FIXME: Maybe this handling of ;; should be made into 2062 ;; FIXME: Maybe this handling of ;; should be made into
2060 ;; a smie-rule-terminator function that takes the substitute ";" as arg. 2063 ;; a smie-rule-terminator function that takes the substitute ";" as arg.
2061 (`(:before . ,(or ";;" ";&" ";;&")) 2064 (`(:before . ,(or ";;" ";&" ";;&" ";|"))
2062 (if (and (smie-rule-bolp) (looking-at ";;?&?[ \t]*\\(#\\|$\\)")) 2065 (if (and (smie-rule-bolp) (looking-at ";\\(?:;&?\\|[&|]\\)?[ \t]*\\(#\\|$\\)"))
2063 (cons 'column (smie-indent-keyword ";")) 2066 (cons 'column (smie-indent-keyword ";"))
2064 (smie-rule-separator kind))) 2067 (smie-rule-separator kind)))
2065 (`(:after . ,(or ";;" ";&" ";;&")) 2068 (`(:after . ,(or ";;" ";&" ";;&" ";|"))
2066 (with-demoted-errors "SMIE rule error: %S" 2069 (with-demoted-errors "SMIE rule error: %S"
2067 (smie-backward-sexp token) 2070 (smie-backward-sexp token)
2068 (cons 'column 2071 (cons 'column
@@ -2151,8 +2154,9 @@ May return nil if the line should not be treated as continued."
2151 (pattern (pattern "|" pattern)) 2154 (pattern (pattern "|" pattern))
2152 (branches (branches ";;" branches) 2155 (branches (branches ";;" branches)
2153 (branches ";&" branches) (branches ";;&" branches) ;bash. 2156 (branches ";&" branches) (branches ";;&" branches) ;bash.
2157 (branches ";|" branches) ;zsh.
2154 (pattern "case-)" cmd))) 2158 (pattern "case-)" cmd)))
2155 '((assoc ";;" ";&" ";;&")) 2159 '((assoc ";;" ";&" ";;&" ";|"))
2156 '((assoc "case") (assoc ";" "&") (assoc "&&" "||") (assoc "|" "|&"))))) 2160 '((assoc "case") (assoc ";" "&") (assoc "&&" "||") (assoc "|" "|&")))))
2157 2161
2158(defun sh-smie--rc-after-special-arg-p () 2162(defun sh-smie--rc-after-special-arg-p ()
diff --git a/test/manual/indent/shell.sh b/test/manual/indent/shell.sh
index bd4a74f7054..5b3fb0e66fb 100755
--- a/test/manual/indent/shell.sh
+++ b/test/manual/indent/shell.sh
@@ -140,6 +140,7 @@ foo () {
140 5) hello ;; 140 5) hello ;;
141 4) hello ;& 141 4) hello ;&
142 4) hello ;;& 142 4) hello ;;&
143 4) hello ;|
143 5) hello ;; 144 5) hello ;;
144 5) hello ;; 145 5) hello ;;
145 esac 146 esac