For Programmers: Free Programming Magazines  


Home > Archive > PERL Miscellaneous > March 2004 > Re: Text editor implemented in Perl









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: Text editor implemented in Perl
David Combs

2004-03-29, 6:50 pm

In article <c2sasr$4u0$1@nets3.rz.RWTH-Aachen.DE>,
Tassilo v. Parseval <tassilo.parseval@post.rwth-aachen.de> wrote:
>Also sprach J Krugman:
>




[color=darkred]
>People will probably be using one or the other, but not both.


Not that I'm all that good with either, but I
do use both.

Emacs is "up", and I'm "in" it, nearly 100% of the time:
things like *shell* and dired make dealing with the computer
*so much easier* -- and efficient too.

Vi{,m} has one rather unique featured: its "g" (and "v") command,
which work like this:

80,900g/mypat/<some ex-command>

where <some ex-command> can be *any* ex-command -- other than
another v or g command.

like this:

g/myregexp/.-2,.+2s/^/foo/

which works like this, using TWO PASSES:


pass-1: goes through lines 80 through 900, seeing which ones
have a match for myregexp, and for those that do,
turn on a bit (attached to the LINE ITSELF, not the
line-NUMBER).

pass-2 for every line in the file (I guess, so things work
out right), for those that have that bit turned on,
*do that <some ex-command>, in this case,

.-2,.+2s/^/foo/

, where "." is interpreted as the current 2nd-pass line-number.

That is, if in the 2nd pass, we're now at line 458, and
that line does have that bit turned "on", then this
is executed:

456,460s/^/foo/

What's is that it still works if the attached-command
changes the number of lines, eg if the command had been:

.-5r myfile.txt

, which of course changes the line-number that of the line
the 2nd-pass is now at.

But that does NOT screw-up everything, because as that line
"moves around (via its linenumber)", that bit MOVES ALONG WITH IT!

Which makes everything work.

Which is pretty darned .

And which seems to be fully documented only in the classic
Kernighan book, "Software Tools" (from way back in the mid
70's), and which is *still* very much reading (actually,
studying)

Not so easy to do in emacs, mainly because vi works via an
indexable *array* of lines, where emacs works one single
super=long array *of characters* -- which enables a whole
different kind wonderful magic too.

David


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com