unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Stefan Kangas <stefankangas@gmail.com>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: Lars Ingebrigtsen <larsi@gnus.org>,
	55764@debbugs.gnu.org, Visuwesh <visuweshm@gmail.com>
Subject: bug#55764: 29.0.50; sh-mode: Support mksh's alternate case brace syntax
Date: Wed, 10 Jan 2024 14:24:34 -0800	[thread overview]
Message-ID: <CADwFkmkuALQGchhtc-VKEvaEcxc3iPQs5jPA5vU4h0Aw3gbq3Q@mail.gmail.com> (raw)
In-Reply-To: <jwvcyxz2f3w.fsf-monnier+emacs@gnu.org> (Stefan Monnier's message of "Sat, 30 Sep 2023 23:37:28 -0400")

Stefan Monnier <monnier@iro.umontreal.ca> writes:

>> To no one's surprise, the patch is not the right approach.  IIUC, when I
>> use braces, *pattern) thingies are not recognised as "case-)" anymore so
>> sh-indent-for-case-label does not get applied.  I tried a bit more but I
>> only got it to respect the first line but still it is definitely not the
>> right approach,
>
> The first part of the puzzle is to fix the syntax-category of the `)` so
> it's recognized as a "case-)" rather than a normal ("matched") paren.
>
> The patch below seems to do the trick.

If you think it looks good, then please install.  Nothing stood out
when I read it over, FWIW.

>
>
>         Stefan
>
>
> diff --git a/lisp/progmodes/sh-script.el b/lisp/progmodes/sh-script.el
> index cc521cb0591..b34be83367a 100644
> --- a/lisp/progmodes/sh-script.el
> +++ b/lisp/progmodes/sh-script.el
> @@ -1053,7 +1053,8 @@ 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")
> +                    ;; Also recognize OpenBSD's case X { ... } (bug#55764).
> +                    (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
> @@ -2053,9 +2054,9 @@ sh-smie-sh-rules
>                               (sh-var-value 'sh-indent-for-case-label)))
>      (`(:before . ,(or "(" "{" "[" "while" "if" "for" "case"))
>       (cond
> -      ((and (equal token "{") (smie-rule-parent-p "for"))
> +      ((and (equal token "{") (smie-rule-parent-p "for" "case"))
>         (let ((data (smie-backward-sexp "in")))
> -         (when (equal (nth 2 data) "for")
> +         (when (member (nth 2 data) '("for" "case"))
>             `(column . ,(smie-indent-virtual)))))
>        ((not (smie-rule-prev-p "&&" "||" "|"))
>         (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 ()
>
>      fi
>  }
> +
> +case $i {                       # Bug#55764
> +    *pattern)
> +        (cd .; echo hi);
> +        do1 ;;
> +    *pattern2) do2 ;;
> +}





  reply	other threads:[~2024-01-10 22:24 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-02 13:33 bug#55764: 29.0.50; sh-mode: Support mksh's alternate case brace syntax Visuwesh
2022-06-02 13:40 ` Lars Ingebrigtsen
2022-06-02 14:01   ` Visuwesh
2023-10-01  2:30     ` Stefan Kangas
2023-10-01  3:37     ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-01-10 22:24       ` Stefan Kangas [this message]
2024-01-12  3:13         ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors

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=CADwFkmkuALQGchhtc-VKEvaEcxc3iPQs5jPA5vU4h0Aw3gbq3Q@mail.gmail.com \
    --to=stefankangas@gmail.com \
    --cc=55764@debbugs.gnu.org \
    --cc=larsi@gnus.org \
    --cc=monnier@iro.umontreal.ca \
    --cc=visuweshm@gmail.com \
    /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).