]> git.eshelyaron.com Git - emacs.git/commitdiff
Add support for Zsh's case branches ;|.
authorPhilippe Altherr <philippe.altherr@gmail.com>
Sun, 15 Jan 2023 12:37:00 +0000 (13:37 +0100)
committerEli Zaretskii <eliz@gnu.org>
Thu, 2 Mar 2023 10:49:32 +0000 (12:49 +0200)
* 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 ";|".

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

index 741803a5175828dd83bb13975d3212918def0887..398a2c8946b139ca58fc8c7b5952480acc92a48e 100644 (file)
@@ -1042,7 +1042,9 @@ subshells can nest."
                        ;; Maybe we've bumped into an escaped newline.
                        (sh-is-quoted-p (point)))
                 (backward-char 1))
-              (when (eq (char-before) ?|)
+              (when (and
+                     (eq (char-before) ?|)
+                     (not (eq (char-before (1- (point))) ?\;)))
                 (backward-char 1) t)))
         (and (> (point) (1+ (point-min)))
              (progn (backward-char 2)
@@ -1053,7 +1055,7 @@ 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")
+                    (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
@@ -1784,8 +1786,9 @@ before the newline and in that case point should be just before the token."
       (pattern (rpattern) ("case-(" rpattern))
       (branches (branches ";;" branches)
                 (branches ";&" branches) (branches ";;&" branches) ;bash.
+                (branches ";|" branches) ;zsh.
                 (pattern "case-)" cmd)))
-    '((assoc ";;" ";&" ";;&"))
+    '((assoc ";;" ";&" ";;&" ";|"))
     '((assoc ";" "&") (assoc "&&" "||") (assoc "|" "|&")))))
 
 (defconst sh-smie--sh-operators
@@ -2058,11 +2061,11 @@ May return nil if the line should not be treated as continued."
         `(column . ,(smie-indent-virtual))))))
     ;; FIXME: Maybe this handling of ;; should be made into
     ;; a smie-rule-terminator function that takes the substitute ";" as arg.
-    (`(:before . ,(or ";;" ";&" ";;&"))
-     (if (and (smie-rule-bolp) (looking-at ";;?&?[ \t]*\\(#\\|$\\)"))
+    (`(:before . ,(or ";;" ";&" ";;&" ";|"))
+     (if (and (smie-rule-bolp) (looking-at ";\\(?:;&?\\|[&|]\\)?[ \t]*\\(#\\|$\\)"))
          (cons 'column (smie-indent-keyword ";"))
        (smie-rule-separator kind)))
-    (`(:after . ,(or ";;" ";&" ";;&"))
+    (`(:after . ,(or ";;" ";&" ";;&" ";|"))
      (with-demoted-errors "SMIE rule error: %S"
        (smie-backward-sexp token)
        (cons 'column
@@ -2151,8 +2154,9 @@ May return nil if the line should not be treated as continued."
       (pattern (pattern "|" pattern))
       (branches (branches ";;" branches)
                 (branches ";&" branches) (branches ";;&" branches) ;bash.
+                (branches ";|" branches) ;zsh.
                 (pattern "case-)" cmd)))
-    '((assoc ";;" ";&" ";;&"))
+    '((assoc ";;" ";&" ";;&" ";|"))
     '((assoc "case") (assoc ";" "&") (assoc "&&" "||") (assoc "|" "|&")))))
 
 (defun sh-smie--rc-after-special-arg-p ()
index bd4a74f705450959fb982626e7e88c43a361aeaf..5b3fb0e66fbddfe39bf70cab8dd52a43dd4e603e 100755 (executable)
@@ -140,6 +140,7 @@ foo () {
         5) hello ;;
         4) hello ;&
         4) hello ;;&
+        4) hello ;|
         5) hello ;;
         5) hello ;;
     esac