GNU bug report logs - #60833
[PATCH] sh-script.el: Add support for Zsh's case branches ;|.

Previous Next

Package: emacs;

Reported by: Philippe Altherr <philippe.altherr <at> gmail.com>

Date: Sun, 15 Jan 2023 14:14:03 UTC

Severity: normal

Tags: patch

Done: Eli Zaretskii <eliz <at> gnu.org>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: help-debbugs <at> gnu.org (GNU bug Tracking System)
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: tracker <at> debbugs.gnu.org
Subject: bug#60833: closed ([PATCH] sh-script.el: Add support for Zsh's
 case branches ;|.)
Date: Thu, 02 Mar 2023 10:51:02 +0000
[Message part 1 (text/plain, inline)]
Your message dated Thu, 02 Mar 2023 12:50:27 +0200
with message-id <83h6v3e8b0.fsf <at> gnu.org>
and subject line Re: bug#60833: Acknowledgement ([PATCH] sh-script.el: Add support for Zsh's case branches ; |.)
has caused the debbugs.gnu.org bug report #60833,
regarding [PATCH] sh-script.el: Add support for Zsh's case branches ;|.
to be marked as done.

(If you believe you have received this mail in error, please contact
help-debbugs <at> gnu.org.)


-- 
60833: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=60833
GNU Bug Tracking System
Contact help-debbugs <at> gnu.org with problems
[Message part 2 (message/rfc822, inline)]
From: Philippe Altherr <philippe.altherr <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: [PATCH] sh-script.el: Add support for Zsh's case branches ;|.
Date: Sun, 15 Jan 2023 14:28:08 +0100
[Message part 3 (text/plain, inline)]
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
[Message part 4 (text/html, inline)]
[0001-Add-support-for-Zsh-s-case-branches.patch (application/x-patch, attachment)]
[Message part 6 (message/rfc822, inline)]
From: Eli Zaretskii <eliz <at> gnu.org>
To: Philippe Altherr <philippe.altherr <at> gmail.com>
Cc: 60833-done <at> debbugs.gnu.org
Subject: Re: bug#60833: Acknowledgement ([PATCH] sh-script.el: Add support for
 Zsh's case branches ; |.)
Date: Thu, 02 Mar 2023 12:50:27 +0200
> From: Philippe Altherr <philippe.altherr <at> gmail.com>
> Date: Fri, 17 Feb 2023 16:20:59 +0100
> 
> Here is an updated patch against the current master branch.

Thanks, installed on master, and closing the bug.


This bug report was last modified 2 years and 134 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.