Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!uunet!zaphod.mps.ohio-state.edu!sdd.hp.com!elroy.jpl.nasa.gov!zardoz.cpd.com!dhw68k!felix!asylvain@felix.UUCP From: asylvain@felix.UUCP (Alvin "the Chipmunk" Sylvain) Newsgroups: comp.editors Subject: Re: Global Empty Line Removal in vi? (lex solution) Message-ID: <156999@felix.UUCP> Date: 5 Feb 91 20:36:09 GMT References: <1991Jan24.064310.8077@midway.uchicago.edu> <156430@felix.UUCP> <30211@megaron.cs.arizona.edu> Sender: daemon@felix.UUCP Reply-To: asylvain@felix.UUCP (Alvin "the Chipmunk" Sylvain) Organization: Foundation for the Increased Wealth of Chipmunks Lines: 55 In article <30211@megaron.cs.arizona.edu> rupley@cs.arizona.edu (John Rupley) writes: > > In article <156430@felix.UUCP>, asylvain@felix.UUCP (Alvin "the Chipmunk" > Sylvain) writes: > :In article <1991Jan24.064310.8077@midway.uchicago.edu> zi0h@quads.uchicago.edu > :(W. Ishii) writes: > :> I've been stuck for about a week now trying to figure out how to > :> globally remove multiple blank lines from text. > : > :Thot I'd go ahead and add one more way to do this. This uses the `lex' > :tool available on most UNIX systems and look-alikes. > : [......] > : %% > : ^[ \t]*\n[ \t\n]* printf ("\n"); > : . ECHO; > > This fails for two reasons: > > 1. It deletes leading whitespace after a blank line. > > 2. A sufficiently large number of blank lines blow the > lex buffer. > > The following works, I believe: > > %% > ^[ \t]*\n/[ \t]*\n ; > .|\n ECHO; John, you're right, mine does fail for reason 1. (I'm not that con- cerned over reason 2. Any tool has it's limitations. I'm assuming the poster didn't want to write specialized code, which could have very easily handled the problem, just throwing away unwanted newlines. Out- side of that, you use the tool and accept the limits.) Yours does overcome reason 1. Obviously, I didn't test for 2. That's why I don't much like lex. The level of unpredictability rises very quickly with a slow increase of complexity. Sometimes, it seems quicker to write specialized code. Nevertheless, once you work the bugs out, it's a very useful tool. And, once you've figured out lex's quirks, it should be quicker than cutting code for the applications it's designed for. It almost certainly will be faster than any sed or awk program written for this particular job. -- asylvain@felix.UUCP (Alvin "the Chipmunk" Sylvain) =========== Opinions are Mine, Typos belong to /usr/ucb/vi =========== "We're sorry, but the reality you have dialed is no longer in service. Please check the value of pi, or see your SysOp for assistance." =============== Factual Errors belong to /usr/local/rn =============== UUCP: uunet!{hplabs,fiuggi,dhw68k,pyramid}!felix!asylvain ARPA: {same choices}!felix!asylvain@uunet.uu.net