[comp.editors] Yes, vi can reformat a paragraph without using !child.

wyle@inf.ethz.ch (Mitchell Wyle) (06/28/89)

>But it's not too much harder to expand on Mr. Olekshy's macro to make it
>call itself recursively until the end of a paragraph is reached.
>Perhaps adding a "+f k" will work to abort the macro when the next line
>doesn't contain more than one word (but I haven't tried it...)

I have; the recursion is endless.  If you really MUST stay in vi (not
fork a subshell) to format your paragraph, one ugly solution to the
problem is:

map ^XF jf k0J72^V|EB^Hr^V^M
map F {j^XF^XF^XF^XF^XF^XF^XF^XF^XF^XF^XF^XF^XF^XF^XF^XF^XF^XF^XF^XF^XF

Or put as many control-X F's in your format-paragraph macro as you
want.  I usually don't format paragraphs longer than 20 lines, though. 
This solution is much faster than forking a sub-shell, but an ugly hack.

I looked for that weird turing-machine in vi macro language, but
couldn't find it.  Was it archived anywhere?  Did Brandon post it in
.sources.misc?  Anyone want to re-post it or send it to me?

Cheers y'all,  -Mitch
-- 
-Mitchell F. Wyle
Institut fuer Informationssysteme         wyle@inf.ethz.ch 
ETH Zentrum / 8092 Zurich, Switzerland    +41 1 256 5237

hitz@auspex.auspex.com (Dave Hitz) (07/06/89)

In article <284@ethz-inf.UUCP> wyle@ethz.UUCP (Mitchell Wyle) writes:
>I looked for that weird turing-machine in vi macro language, but
>couldn't find it.  Was it archived anywhere?  Did Brandon post it in
>.sources.misc?  Anyone want to re-post it or send it to me?

Here you go:

The shar file below contains the macros themselves in a file called
tm.uuencode and some turing machine descriptions in files named TM*.

The following sequence executes the TMupdown turing machine.

        1) Decode the tm file:                  $ uudecode tm.uuencode
        2) Edit the TM file:                    $ vi TMupdown
        3) Source the macros:                   :so tm
        4) From vi ESC mode, type g (for go):   g

I've included three turing machine descriptions.  TMupdown just moves
the turing machine tape head up and down.  TMabc and TMabc2 both
recognize the pattern of N "a"s followed by N "b"s followed by N "c"s
for any integer N.

The README file describes the format of the Turning Machines themselves.
I have an annotated version of the tm macros for people who care.

#------------------------------------- cut here --------------------------------
# To unbundle, sh this file as root.
echo tm
sed -e "s/^- //" <<\'end_of_tm\' >tm
- map	C	: 
- map	C	: 	Turing Machine Emulation Macros.
- map	C	: 
- map	C	:	Copywrite 1987 Dave Hitz
- map	C	: 
- map	C	:	UUCP: {decvax,ucbvax,ihnp4}!decwrl!mips!hitz 	
- map	C	:	DDD: hitz@408-991-0345
- map	C	: 
- set	remap
- map	g	xS
- map	S	'tl1GkwVvX's@bf:lmsW'tkwmtO`sf:lmsW@bC`sf:le1GkwEX@bmn`sq`nQmss
- map	s	S
- map	X	"bY
- map		"by$
- map	W	"byt:
- map	e	"byt}
- map	w	"bP
- map	R	't+mt
- map	L	't-mt
- map	N	'tmt
- map	E	^i/^[* ]
- map	C	^hr*
- map	c	^h l
- map	Q	^hr*
- map	q	?\*
- map	V	I/{
- map	v	A:
- map	O	^i 
- map	k	|D
- map	x	:%s/^/ /
'end_of_tm'
echo README
sed -e "s/^- //" <<\'end_of_README\' >README
- 
- 			Vi Turing Machine Emulation
- 			---------------------------
- 
- This directory contains a set of macros which allow vi to simulate a
- Turing Machine.  The file "tm" contains the macros.
- 
- The "TM*" files each contain a turing machine description.
- 
- To execute the TMupdown machine, do the following:
- 
- 	$ vi TMupdown
- 	:so tm
- 
- Then, from escape mode in vi, type 'g' for go.
- 
- I've included a simple turing machine description to use as an example
- in explaining the format.
- 
- ----------------------- cut here for sample turing machine ---------------------
- 
- START{####:####:R:DOWN:}
- DOWN{up:down:R:DOWN:}{%%%%:%%%%:L:UP:}
- UP{down:up:L:UP:}{####:####:R:DOWN:}
- ####
- up
- up
- up
- up
- %%%%
- --------------------------- end of turing machine ------------------------------
- 
- The top line is used as a scratch pad by the macros and must not be
- removed. The lines from the second line to the line containing "####"
- encode the turing machine's state table, and the lines from "####" to
- "%%%%" represent the turing machine's tape.
- 
- The tape is lying on its side such that left is up and right is down.
- Each line represents one tape symbol.  "####" is the start symbol on
- the tape, and "%%%%" is the end symbol.
- 
- Each line above "####" represents the information for one state
- of the turing machine.   I'll describe the format using an example:
- 
- 	DOWN{up:down:R:DOWN:}{%%%%:%%%%:L:UP:}
- 
- The name of the state, in this case "DOWN", comes first.  Following that
- comes any number of 4-tuples describing the action to take for a particular
- tape symbol.   The first 4-tuple states that if the current tape symbol
- is "up", then that symbol should be replaced by "down", the current position
- on the tape should be moved "R" -- that is, to the right -- and the
- turing machine should enter the "DOWN" state.
- 
- The general format of these 4-tuples is:
- 
-    '{' <current symbol> ':' <new symbol> ':' <direction> ':' <next state> ':}'
- 
- Where <direction> is "R", "L", or "N" for move left, move right, or no move.
- The other fields can contain any alpha-numeric string.  (In fact, any string
- that does not include "{}:" or any vi magic characters will probably work.)
- 
- When a turing machine first starts, after the 'g' command, it is in the
- "START" state with its head positioned on the "####" symbol on the tape.
'end_of_README'
echo tm.uuencode
sed -e "s/^- //" <<\'end_of_tm.uuencode\' >tm.uuencode
- begin 644 tm
- M;6%P"4,).B`*;6%P"4,).B`)5'5R:6YG($UA8VAI;F4@16UU;&%T:6]N($UA
- M8W)O<RX*;6%P"4,).B`*;6%P"4,).@E#;W!Y=W)I=&4@,3DX-R!$879E($AI
- M='H*;6%P"4,).B`*;6%P"4,).@E554-0.B![9&5C=F%X+'5C8G9A>"QI:&YP
- M-'TA9&5C=W)L(6UI<',A:&ET>B`)"FUA<`E#"3H)1$1$.B!H:71Z0#0P."TY
- M.3$M,#,T-0IM87`)0PDZ(`IS970)<F5M87`*;6%P"6<)>%,*;6%P"5,))W1L
- M&#%':W=6=E@G<T!B9CIL;7-7)W1K=VUT3V!S9CIL;7-70&)#8'-F.FQE,4=K
- M=T580&)M;F!S<6!N46US<PIM87`)<PE3"FUA<`E8"2)B60IM87`)&`DB8GDD
- M"FUA<`E7"2)B>70Z"FUA<`EE"2)B>71]"FUA<`EW"2)B4`IM87`)4@DG="MM
- M=`IM87`)3`DG="UM=`IM87`)3@DG=&UT"FUA<`E%"5YI+UY;*B!=&PIM87`)
- M0PE>:'(J"FUA<`EC"5YH(&P*;6%P"5$)7FAR*@IM87`)<0D_7"H-7G(@;`IM
- M87`)5@E)+WL;"FUA<`EV"4$Z&PIM87`)3PE>:2`;"FUA<`EK"19\1`IM87`)
- F>`DZ)7,O7B\@+PTO7B`C(R,C)"\-;71#+UX@4U1!4E0O#6US40I\
- `
- end
'end_of_tm.uuencode'
echo TMabc
sed -e "s/^- //" <<\'end_of_TMabc\' >TMabc
- 
- 
- START{####:####:R:check}
- check{a:a:N:find_b}{b:REJECT:N:HALT}{c:REJECT:N:HALT}{%%%%:ACCEPT:N:HALT}
- find_b{a:a:R:find_b}{b:b:L:kill_a1}{c:REJECT:N:HALT}{%%%%:REJECT:N:HALT}
- kill_a1{a:b:R:find_c}
- find_c{b:b:R:find_c}{c:c:L:kill_b2}{%%%%:REJECT:N:HALT}
- kill_b2{b:c:L:kill_b1}
- kill_b1{b:c:R:find_end}
- find_end{c:c:R:find_end}{%%%%:%%%%:L:kill_c3}
- kill_c3{c:%%%%:L:kill_c2}
- kill_c2{c:%%%%:L:kill_c1}
- kill_c1{c:%%%%:L:RETURN}
- RETURN{a:a:L:RETURN}{b:b:L:RETURN}{c:c:L:RETURN}{####:####:N:START}
- 
- ####
- a
- a
- b
- b
- c
- c
- %%%%
'end_of_TMabc'
echo TMabc2
sed -e "s/^- //" <<\'end_of_TMabc2\' >TMabc2
- 
- START	{a:a:L:START}    {b:b:L:START}    {c:c:L:START}    {####:####:R:kill_a}
- 	{a':a':L:START}  {b':b':L:START}  {c':c':L:START}
- kill_a	{a:a':R:kill_b}  {b:NO:N:NO}       {c:NO:N:NO}       {%%%%:YES:N:YES}
- 	{a':a':R:kill_a} {b':b':R:kill_a} {c':c':R:kill_a}
- kill_b	{a:a:R:kill_b}   {b:b':R:kill_c}  {c:NO:N:NO}       {%%%%:NO:N:NO}
- 	{a':NO:N:NO}     {b':b':R:kill_b} {c':NO:N:NO}
- kill_c	{a:NO:N:NO}       {b:b:R:kill_c}   {c:c':L:START}   {%%%%:NO:N:NO}
- 	{a':NO:N:NO}     {b':NO:N:NO}     {c':c':R:kill_c}
- 
- ####
- a
- a
- a
- b
- b
- b
- c
- c
- c
- %%%%
'end_of_TMabc2'
echo TMupdown
sed -e "s/^- //" <<\'end_of_TMupdown\' >TMupdown
- 
- 
- START{####:####:R:DOWN}
- DOWN{up:down:R:DOWN}{%%%%:%%%%:L:UP}
- UP{down:up:L:UP}{####:####:R:DOWN}
- 
- ####
- up
- up
- up
- up
- up
- up
- up
- %%%%
'end_of_TMupdown'
exit
#-------------------------------------------------------------------------------


-- 
Dave Hitz					home: 408-739-7116
UUCP: {uunet,mips,sun,bridge2}!auspex!hitz 	play: 408-970-8970