[comp.editors] reformat

msb@sq.sq.com (Mark Brader) (06/28/90)

> map #4 i.pl 1^M.ll 6i^M.na^M.nh^M^[4-!2}nroff^M

This could cause some nasty surprises if your paragraph has a
'single quotation mark' at the beginning of a line, or contains
a backslash, as in "Hello, world\n".  (Tabs and control-A's are
also special to nroff, but are unlikely to occur in paragraphs of
normal text.)  To be safe, you want to turn off the escape character
and set the control characters to something that will never occur.

Still another problem is that nroff assumes that, even if hyphenation
is turned off, existing words containing hyphens can be divided at
those hyphens.  You might *want* this effect, actually, but it
would mean that you couldn't reformat the paragraph a second time.
One way to avoid this is to replace existing hyphens by, say,
control-B's, then .tr them back into hyphens.

If you want to use nroff for this sort of thing, then, for safety
you need to do more than is shown above.

      map #4 0mzi-^[}:'z,.s/-/^B/g^M`zxO.pl 1^M.ll 6i^M.na^M.nh^M
        .tr ^B-^M.eo^M.c2 ^G^M.cc ^G^[7-!2}nroff^M

      (the above should be all on one line with no spaces before .tr)

should suffice, assuming your paragraph has no control-B's or
control-G's in it to start with.  It would probably be easier to
do this in a shell script, though, as it could take arguments such
as the line length.  And, of course, you have to watch all the actions
happening one by one if you use a vi macro.


-- 
nroff by Mark Brader		"Great things are not done by those
SoftQuad Inc., Toronto		 who sit down and count the cost
utzoo!sq!msb, msb@sq.com	 of every thought and act."  -- Daniel Gooch

Converted to vi macro by Liam Quin, utzoo!sq!lee, lee@sq.com

This article is in the public domain.