Zsh Mailing List Archive
Messages sorted by:
Re: Prepend/append to the members of a list
- X-seq: zsh-workers 22937
- From: Peter Stephenson <pws@xxxxxxx>
- To: zsh-workers@xxxxxxxxxx
- Subject: Re: Prepend/append to the members of a list
- Date: Tue, 31 Oct 2006 17:08:30 +0000
- In-reply-to: <061031083123.ZM10976@xxxxxxxxxxxxxxxxxxxxxx>
- Mailing-list: contact zsh-workers-help@xxxxxxxxxx; run by ezmlm
- References: <20061030170919.GA9507@xxxxxxxxxxxx> <200610311452.k9VEqKNI013158@xxxxxxxxxxxxxx> <061031083123.ZM10976@xxxxxxxxxxxxxxxxxxxxxx>
Bart Schaefer wrote:
> On Oct 31, 2:52pm, Peter Stephenson wrote:
> } +When tt(HIST_SUBST_PATTERN) is set, var(l) may start with a tt(#)
> } +to indicate that the pattern must match at the start of the string
> } +to be substituted, and a tt(%) may appear at the start or after an tt(#)
> } +to indicate that the pattern must match at the end of the string
> } +to be substituted.
> The doc in parameter expansion says
> The PATTERN may begin with a `#', in which case the PATTERN must
> match at the start of the string, or `%', in which case it must
> match at the end of the string.
> Should that doc also say that #% is a legal pattern meaning "anchor
> the match at both ends of the string"?
With the current code, no, because that's not supported. I
suppose it would be sensible to add that for compatibility---although
it does change the syntax in the not particularly likely but by no means
impossible case that you're substituting a % at the head of a string,
so I'm not so sure.
I didn't add it before because I assumed we already had other ways of
doing it; now I come to think of it, I can't actually think of one that
doesn't involve the use of extended globbing (i.e. (#s) or (#e)).
:# removes a complete match, but doesn't replace it. None of the
flags that modify matching tell it to force a complete match. So maybe it
could do with adding. Any strong views?
However, I screwed up: it doesn't work even for :s/#%.../.../ because
I'd forgotten there was no way to tell the underlying pattern
substitution code to anchor at both ends. So it accepts the syntax but
actually anchors only at the tail. That turns out to be easy to fix,
and I'll do it in whatever I commit.
Another annoyance, again to do with the horrors of tokenization when you
do things out of the usual order of parsing, is that you need to quote %
and # with two backslashes. I'll document this. It's for basically the
same reason that in glob qualifiers you need an extra layer of quotes
round parameters; I'm not sure I can deal with both problems
consistently and it's probably best to leave this for consistency.
Peter Stephenson <pws@xxxxxxx> Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK Tel: +44 (0)1223 692070
To access the latest news from CSR copy this link into a web browser: http://www.csr.com/email_sig.php
Messages sorted by: