unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Philippe Altherr <philippe.altherr@gmail.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: 60833@debbugs.gnu.org
Subject: bug#60833: [PATCH] sh-script.el: Add support for Zsh's case branches ; |.
Date: Mon, 23 Jan 2023 05:13:36 +0100	[thread overview]
Message-ID: <CAGdYchsFnQNS+YvtffGNLS58F0RqmBCFAMUpXZRF6z5t0tz+SQ@mail.gmail.com> (raw)
In-Reply-To: <837cxgmjev.fsf@gnu.org>


[-- Attachment #1.1: Type: text/plain, Size: 519 bytes --]

>
> Thanks.  First, would it be possible to add tests for these
> situations?
>

I added a test case in the attached updated patch. I wasn't able to test it
though. Please make sure it works as expected.


> And second, your contributions (this and the other one) are larger
> than we can accept without your assigning the copyright to the FSF.
> Would you like to start your legal paperwork at this time, so that we
> could accept the changes after it is completed?  If so, I will send
> you the form to fill.
>

Sure

[-- Attachment #1.2: Type: text/html, Size: 934 bytes --]

[-- Attachment #2: 0001-Add-support-for-Zsh-s-case-branches.patch --]
[-- Type: application/octet-stream, Size: 3654 bytes --]

From 7d39639f0c1cdae468750b012a773b6b549753ac Mon Sep 17 00:00:00 2001
From: Philippe Altherr <philippe.altherr@gmail.com>
Date: Sun, 15 Jan 2023 13:37:00 +0100
Subject: [PATCH] Add support for Zsh's case branches ;|.

---
 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 17c22ff475..2982bb3f34 100644
--- a/lisp/progmodes/sh-script.el
+++ b/lisp/progmodes/sh-script.el
@@ -1042,7 +1042,9 @@ sh-font-lock-paren
                        ;; 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 @@ sh-font-lock-paren
                     ;; 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 @@ sh-smie-sh-grammar
       (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
@@ -2055,11 +2058,11 @@ sh-smie-sh-rules
 	 `(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
@@ -2148,8 +2151,9 @@ sh-smie-rc-grammar
       (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 bd4a74f705..5b3fb0e66f 100755
--- a/test/manual/indent/shell.sh
+++ b/test/manual/indent/shell.sh
@@ -140,6 +140,7 @@     bar ()
         5) hello ;;
         4) hello ;&
         4) hello ;;&
+        4) hello ;|
         5) hello ;;
         5) hello ;;
     esac
-- 
2.39.1


  reply	other threads:[~2023-01-23  4:13 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-15 13:28 bug#60833: [PATCH] sh-script.el: Add support for Zsh's case branches ; | Philippe Altherr
2023-01-21  7:33 ` Eli Zaretskii
2023-01-23  4:13   ` Philippe Altherr [this message]
2023-01-23 15:16     ` Eli Zaretskii
     [not found] ` <handler.60833.B.16737920195794.ack@debbugs.gnu.org>
2023-02-17 15:20   ` bug#60833: Acknowledgement ([PATCH] sh-script.el: Add support for Zsh's case branches ; |.) Philippe Altherr
2023-03-02 10:50     ` Eli Zaretskii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAGdYchsFnQNS+YvtffGNLS58F0RqmBCFAMUpXZRF6z5t0tz+SQ@mail.gmail.com \
    --to=philippe.altherr@gmail.com \
    --cc=60833@debbugs.gnu.org \
    --cc=eliz@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).