all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#60833: [PATCH] sh-script.el: Add support for Zsh's case branches ; |.
@ 2023-01-15 13:28 Philippe Altherr
  2023-01-21  7:33 ` Eli Zaretskii
       [not found] ` <handler.60833.B.16737920195794.ack@debbugs.gnu.org>
  0 siblings, 2 replies; 6+ messages in thread
From: Philippe Altherr @ 2023-01-15 13:28 UTC (permalink / raw)
  To: 60833


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

In shell scripts, case branches traditionally end with ;;. Bash
additionally supports case branches ending with ;& and ;;&. Zsh similarly
supports case branches ending with ;& and ;|. Currently sh-script.el
supports case branches ending with ;;, ;&, and ;;&, but not with ;|. The
attached patch adds support for case branches ending with ;|.

I have tested the patch by defining all the modified functions
(sh-smie-sh-rules, sh-font-lock-paren) and constants (sh-smie-sh-grammar,
sh-smie-rc-grammar, sh-smie--sh-operators, sh-smie--sh-operators-re,
sh-smie--sh-operators-back-re) in my .emacs (in a (with-eval-after-load
'sh-script ...) statement).

Here is an example indented without the patch:

case $input in
    *a* ) echo A;;
    *b* ) echo B;&
    *c* ) echo C;;&
    *d* ) echo D;|
*e* ) echo E;;
esac

and with the (simulated) patch:

case $input in
    *a* ) echo A;;
    *b* ) echo B;&
    *c* ) echo C;;&
    *d* ) echo D;|
    *e* ) echo E;;
esac

The first change in the patch replaces an (eq (char-before) ?|)
<https://github.com/emacs-mirror/emacs/blob/77ca6aa56e3425c87861cab8abce52bee3697cf4/lisp/progmodes/sh-script.el#L1045>
with
(and (eq (char-before) ?|) (not (eq (char-before (1- (point))) ?\;))). It
is needed to avoid confusing ;| tokens with plain | tokens. I wonder
however whether there would be a cleaner way of expressing the same.

The second change replaces a (looking-at ";[;&]\\|\\_<in")
<https://github.com/emacs-mirror/emacs/blob/77ca6aa56e3425c87861cab8abce52bee3697cf4/lisp/progmodes/sh-script.el#L1056>
with (looking-at ";\\(?:;&?\\|[&|]\\)\\|\\_<in"). The original expression
is looking for ;; and ;& tokens but not for ;;& tokens, which looks like an
oversight to me. That's why I have changed it to look for ;;, ;&, ;| but
also ;;&.

The other changes simply add support for ;| where there was previously
support for ;;, ;&, and ;;&.

Philippe

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

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2023-03-02 10:50 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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

Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.