emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 68f49083af7: Add support for Zsh's case branches ;|.


From: Eli Zaretskii
Subject: master 68f49083af7: Add support for Zsh's case branches ;|.
Date: Thu, 2 Mar 2023 05:50:01 -0500 (EST)

branch: master
commit 68f49083af7ac5ffd9cde4bc7167d4e2ccbba4b6
Author: Philippe Altherr <philippe.altherr@gmail.com>
Commit: Eli Zaretskii <eliz@gnu.org>

    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 ";|".
---
 lisp/progmodes/sh-script.el | 18 +++++++++++-------
 test/manual/indent/shell.sh |  1 +
 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."
                        ;; 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 ()
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 () {
         5) hello ;;
         4) hello ;&
         4) hello ;;&
+        4) hello ;|
         5) hello ;;
         5) hello ;;
     esac



reply via email to

[Prev in Thread] Current Thread [Next in Thread]