From: "Russ Cox" <rsc@swtch.com>
To: 9fans@9fans.net
Subject: Re: [9fans] acme g/$/ funny
Date: Thu, 17 Jul 2008 10:43:32 -0400 [thread overview]
Message-ID: <20080717144047.3C6EE1E8C1C@holo.morphisms.net> (raw)
In-Reply-To: <F683F1B8-6821-4227-A06D-069CDBDC3434@mac.com>
> On Jul 17, 2008, at 6:03 AM, roger peppe wrote:
>> Edit ,x/.*/g/$/a/foo/
>>
>> shouldn't this append "foo" after every line?
>>
>> sam gives slightly different behaviour here
>> (but still questionable) - it appends "foo" after
>> every empty line.
>>
>> is this actually a bug, or have i misunderstood the
>> way that '$' is meant to work?
>>
>> it does seem strange that in the following edit
>> command, the guard never matches anything.
>>
>> Edit ,x/foo$/g/foo$/d
>>
pietro:
> You misunderstood how Pike regexps work
> ...
> That appends foo at the beginning of the next line. Try i/foo/.
It always brings a smile to my face when you say
things like that to people who have forgotten more
about Plan 9 than you know. Thank you.
rog:
> Edit ,x/.*/g/$/a/foo/
>
> shouldn't this append "foo" after every line?
I would have expected it to.
pietro:
> The pattern /./ matches everything EXCEPT a newline,
> which would be matched with $.
This is only half right. $ matches the empty string before a newline,
not the newline itself. Don't believe me? Search for $$.
The real issue here is that inside an x/.*/ loop, the text being
considered has no newline, so the position at the end is no longer
an "empty string before a newline." (The newline is outside the
search window.)
One possible fix would be to redefine $ to match the end
of the text as well as before newlines. I've sometimes wanted
that in x loops that don't iterate over whole lines. That would
have the unfortunate effect that if you had a four-line file like:
abc\n
def\n
ghi\n
jkl\n
and you ran ,s/$/!/g you would then have the four-and-a-half line file:
abc!\n
def!\n
ghi!\n
jkl!\n
!
so you'd have to then define that $ matches the end of the text
unless the last character is a newline. This is the point where
I usually give up and decide the current semantics are not worth
fiddling with.
Russ
prev parent reply other threads:[~2008-07-17 14:43 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-07-17 10:03 roger peppe
2008-07-17 12:44 ` Charles Forsyth
2008-07-17 13:07 ` Pietro Gagliardi
2008-07-17 14:01 ` roger peppe
2008-07-17 14:43 ` Russ Cox [this message]
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20080717144047.3C6EE1E8C1C@holo.morphisms.net \
--to=rsc@swtch.com \
--cc=9fans@9fans.net \
/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.
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 NNTP newsgroup(s).