Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!bloom-beacon!gatech!udel!rochester!rit!tropix!moscom!ur-valhalla!uhura.cc.rochester.edu!sunybcs!rutgers!tut.cis.ohio-state.edu!ucbvax!pasteur!ames!lll-winken!uunet!mcvax!unido!tub!astbe!eh From: eh@astbe.UUCP (H.Dr.Ehling) Newsgroups: comp.unix.questions Subject: Re: sh vs. csh format script (was: Re: Vi) Keywords: Vi formatting, Vi shift, Squeezing blanks Message-ID: <586@astbe.UUCP> Date: 22 Jul 89 20:42:50 GMT References: <297@ontek.UUCP> <2760@piraat.cs.vu.nl> Reply-To: eh@astbe.UUCP (H.Dr.Ehling) Organization: GEI Software Technik Berlin, Germany Lines: 74 In article <2760@piraat.cs.vu.nl> maart@cs.vu.nl (Maarten Litmaath) writes: >Well, here's a Bourne shell script: > ..... That script truly is smart in demonstrating what can be done with filedescriptors in sh and it's a bit cruel in it's commentless placing the of `rm' (I had to learn it the hard way that open files never die). Anyway, I'm really grateful having seen it. But `shift_lines', is on no *IX I happen to know. And although a C Programm could easily be written, let me hint to vi's Shift Operators "<" and ">". "<" shifts at most `shiftwidth' (sw) blanks to the left (it transposes tabs before doing that) and can be used to remove offset causing nroff to break filling. But You will not loose nonwhite text and deliberate indents greater than `sw' will leave a few blanks, so nroff will still break at that. The script below shows, how to use more of nroffs commands, so You can set indentation and linelength: (which actually is more of a right margin, as these lines show. They have been formatted with `3!!fill 4', as the text originally was (and incidently still is) 3 lines. As there usually has to be reformatting, the script uses 'tr', to squeeze out fill blanks from a previous formatting run. Otherwise gaps will became always bigger, as nroff respects existing blanks (except at the end of a line, I believe). A final remark: I never saw it documented, but vi remembers the last shel command. So after having said `!}fill 4 66' You just have to say `!}!' for the next paragraph or `!G!' for the remainder of the buffer. (But I did'nt do that, as filled programms are so hard to understand!) ------------------------------------------------------- : # << this substitute (: == `noop') for #\!/bin sh works # everywhere, I believe # usage: fill [indent] [linelength] # To be used with vi, e.g.: # se sw=4 # Set in Your EXINIT, just once; then # Iff there is leading WS to be removed: # <} # this shifts Paragraph by (at most) sw Blanks # !}fill 2 66 (def: 0 72) indent=${1-0} llength=${2-72} temp_file=/tmp/foobar.$$ umask 077 exec 3>&1 > $temp_file 4< $temp_file /bin/rm $temp_file echo ".hy 0 .ll $llength .in $indent" tr -s ' ' ' ' # To squeeze blanks nroff <&4 >&3 ------------------------------------------------------- Have fun! ------------------------------------------------------- -- Hans-Juergen Ehling | From Europe: eh@astbe.uucp | From USA: ...!pyramid!tub!astbe!eh GEI Software-Technik | Voice: +49 30/8282497