annotate runtime/macros/maze/maze_mac @ 17807:b38fa4d37b7c v8.1.1900

patch 8.1.1900: sign test fails in the GUI Commit: https://github.com/vim/vim/commit/d933c82ff4e2c910bd533ed9a50377699c3f5ec9 Author: Bram Moolenaar <Bram@vim.org> Date: Wed Aug 21 13:45:16 2019 +0200 patch 8.1.1900: sign test fails in the GUI Problem: Sign test fails in the GUI. Solution: Catch and ignore the exception.
author Bram Moolenaar <Bram@vim.org>
date Wed, 21 Aug 2019 14:00:04 +0200
parents 3fc0f57ecb91
children d6dde6229b36
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1 " These macros 'solve' any maze produced by the a-maze-ing maze.c program.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2 "
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3 " First, a bit of maze theory.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4 " If you were put into a maze, a guaranteed method of finding your way
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5 " out of the maze is to put your left hand onto a wall and just keep walking,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6 " never taking your hand off the wall. This technique is only guaranteed to
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7 " work if the maze does not have any 'islands', or if the 'exit' is on the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8 " same island as your starting point. These conditions hold for the mazes
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9 " under consideration.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
10 "
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
11 " Assuming that the maze is made up of horizontal and vertical walls spaced
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
12 " one step apart and that you can move either north, south, east or west,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
13 " then you can automate this procedure by carrying out the following steps.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
14 "
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
15 " 1. Put yourself somewhere in the maze near a wall.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
16 " 2. Check if you have a wall on your left. If so, go to step 4.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
17 " 3. There is no wall on your left, so turn on the spot to your left and step
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
18 " forward by one step and repeat step 2.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
19 " 4. Check what is directly in front of you. If it is a wall, turn on the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
20 " spot to your right by 90 degrees and repeat step 4.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
21 " 5. There is no wall in front of you, so step forward one step and
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
22 " go to step 2.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
23 "
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
24 " In this way you will cover all the corridors of the maze (until you get back
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
25 " to where you started from, if you do not stop).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
26 "
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
27 " By examining a maze produced by the maze.c program you will see that
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
28 " each square of the maze is one character high and two characters wide.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
29 " To go north or south, you move by a one character step, but to move east or
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
30 " west you move by a two character step. Also note that in any position
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
31 " there are four places where walls could be put - to the north, to the south,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
32 " to the east and to the west.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
33 " A wall exists to the north of you if the character to the north of
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
34 " you is a _ (otherwise it is a space).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
35 " A wall exists to the east of you if the character to the east of you
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
36 " is a | (otherwise it is a .).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
37 " A wall exists to the west of you if the character to the west of you
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
38 " is a | (otherwise it is a .).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
39 " A wall exists to the south of you if the character where you are
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
40 " is a _ (otherwise it is a space).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
41 "
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
42 " Note the difference for direction south, where we must examine the character
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
43 " where the cursor is rather than an adjacent cell.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
44 "
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
45 " If you were implementing the above procedure is a normal computer language
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
46 " you could use a loop with if statements and continue statements,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
47 " However, these constructs are not available in vi macros so I have used
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
48 " a state machine with 8 states. Each state signifies the direction you
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
49 " are going in and whether or not you have checked if there is a wall on
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
50 " your left.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
51 "
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
52 " The transition from state to state and the actions taken on each transition
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
53 " are given in the state table below.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
54 " The names of the states are N1, N2, S1, S2, E1, E2, W1, W2, where each letter
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
55 " stands for a direction of the compass, the number 1 indicates that the we
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
56 " have not yet checked to see if there is a wall on our left and the number 2
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
57 " indicates that we have checked and there is a wall on our left.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
58 "
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
59 " For each state we must consider the existence or not of a wall in a
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
60 " particular direction. This direction is given in the following table.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
61 "
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
62 " NextChar table:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
63 " state direction vi commands
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
64 " N1 W hF
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
65 " N2 N kF
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
66 " S1 E lF
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
67 " S2 S F
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
68 " E1 N kF
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
69 " E2 E lF
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
70 " W1 S F
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
71 " W2 W hF
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
72 "
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
73 " where F is a macro which yanks the character under the cursor into
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
74 " the NextChar register (n).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
75 "
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
76 " State table:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
77 " In the 'vi commands' column is given the actions to carry out when in
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
78 " this state and the NextChar is as given. The commands k, j, ll, hh move
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
79 " the current position north, south, east and west respectively. The
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
80 " command mm is used as a no-op command.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
81 " In the 'next state' column is given the new state of the machine after
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
82 " the action is carried out.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
83 "
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
84 " current state NextChar vi commands next state
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
85 " N1 . hh W1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
86 " N1 | mm N2
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
87 " N2 _ mm E1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
88 " N2 space k N1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
89 " S1 . ll E1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
90 " S1 | mm S2
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
91 " S2 _ mm W1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
92 " S2 space j S1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
93 " E1 space k N1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
94 " E1 _ mm E2
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
95 " E2 | mm S1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
96 " E2 . ll E1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
97 " W1 space j S1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
98 " W1 _ mm W2
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
99 " W2 | mm N1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
100 " W2 . hh W1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
101 "
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
102 "
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
103 " Complaint about vi macros:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
104 " It seems that you cannot have more than one 'undo-able' vi command
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
105 " in the one macro, so you have to make lots of little macros and
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
106 " put them together.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
107 "
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
108 " I'll explain what I mean by an example. Edit a file and
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
109 " type ':map Q rXY'. This should map the Q key to 'replace the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
110 " character under the cursor with X and yank the line'.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
111 " But when I type Q, vi tells me 'Can't yank inside global/macro' and
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
112 " goes into ex mode. However if I type ':map Q rXT' and ':map T Y',
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
113 " everything is OK. I`m doing all this on a Sparcstation.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
114 " If anyone reading this has an answer to this problem, the author would
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
115 " love to find out. Mail to gregm@otc.otca.oz.au.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
116 "
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
117 " The macros:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
118 " The macro to run the maze solver is 'g'. This simply calls two other
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
119 " macros: I, to initialise everything, and L, to loop forever running
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
120 " through the state table.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
121 " Both of these macros are long sequences of calls to other macros. All
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
122 " of these other macros are quite simple and so to understand how this
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
123 " works, all you need to do is examine macros I and L and learn what they
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
124 " do (a simple sequence of vi actions) and how L loops (by calling U, which
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
125 " simply calls L again).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
126 "
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
127 " Macro I sets up the state table and NextChar table at the end of the file.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
128 " Macro L then searches these tables to find out what actions to perform and
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
129 " what state changes to make.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
130 "
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
131 " The entries in the state table all begin with a key consisting of the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
132 " letter 's', the current state and the NextChar. After this is the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
133 " action to take in this state and after this is the next state to change to.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
134 "
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
135 " The entries in the NextChar table begin with a key consisting of the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
136 " letter 'n' and the current state. After this is the action to take to
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
137 " obtain NextChar - the character that must be examined to change state.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
138 "
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
139 " One way to see what each part of the macros is doing is to type in the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
140 " body of the macros I and L manually (instead of typing 'g') and see
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
141 " what happens at each step.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
142 "
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
143 " Good luck.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
144 "
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
145 " Registers used by the macros:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
146 " s (State) - holds the state the machine is in
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
147 " c (Char) - holds the character under the current position
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
148 " m (Macro) - holds a vi command string to be executed later
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
149 " n (NextChar) - holds the character we must examine to change state
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
150 " r (Second Macro) - holds a second vi command string to be executed later
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
151 "
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
152 set remap
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
153 set nomagic
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
154 set noterse
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
155 set wrapscan
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
156 "
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
157 "================================================================
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
158 " g - go runs the whole show
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
159 " I - initialise
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
160 " L - then loop forever
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
161 map g IL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
162 "
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
163 "================================================================
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
164 " I - initialise everything before running the loop
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
165 " G$?.^M - find the last . in the maze
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
166 " ^ - replace it with an X (the goal)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
167 " GYKeDP - print the state table and next char table at the end of the file
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
168 " 0S - initialise the state of the machine to E1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
169 " 2Gl - move to the top left cell of the maze
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
170 map I G$?. ^GYKeDP0S2Gl
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
171 "
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
172 "================================================================
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
173 " L - the loop which is executed forever
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
174 " Q - save the current character in the Char register
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
175 " A - replace the current character with an 'O'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
176 " ma - mark the current position with mark 'a'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
177 " GNB - on bottom line, create a command to search the NextChar table
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
178 " for the current state
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
179 " 0M0E@m^M - yank the command into the Macro register and execute it
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
180 " wX - we have now found the entry in the table, now yank the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
181 " following word into the Macro register
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
182 " `a@m - go back to the current position and execute the macro, this will
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
183 " yank the NextChar in register n
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
184 " GT$B$R - on bottom line, create a command to search the state table
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
185 " for the current state and NextChar
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
186 " 0M0E@m^M - yank the command into the Macro register and execute it
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
187 " 2WS - we have now found the entry in the table, now yank the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
188 " next state into the State macro
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
189 " bX - and yank the action corresponding to this state table entry
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
190 " into the Macro register
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
191 " GVJ - on bottom line, create a command to restore the current character
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
192 " 0H - and save the command into the second Macro register
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
193 " `a@r - go back to the current position and exectute the macro to restore
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
194 " the current character
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
195 " @m - execute the action associated with this state
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
196 " U - and repeat
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
197 map L QAmaGNB0M0E@m wX`a@mGT$B$R0M0E@m 2WSbXGVJ0H`a@r@mU
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
198 "
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
199 "================================================================
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
200 " U - no tail recursion allowed in vi macros so cheat and set U = L
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
201 map U L
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
202 "
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
203 "================================================================
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
204 " S - yank the next two characters into the State register
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
205 map S "sy2l
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
206 "
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
207 "================================================================
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
208 " Q - save the current character in the Char register
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
209 map Q "cyl
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
210 "
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
211 "================================================================
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
212 " A - replace the current character with an 'O'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
213 map A rO
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
214 "
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
215 "================================================================
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
216 " N - replace this line with the string 'n'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
217 map N C/n
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
218 "
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
219 "================================================================
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
220 " B - put the current state
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
221 map B "sp
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
222 "
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
223 "================================================================
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
224 " M - yank this line into the Macro register
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
225 map M "my$
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
226 "
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
227 "================================================================
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
228 " E - delete to the end of the line
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
229 map E d$
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
230 "
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
231 "================================================================
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
232 " X - yank this word into the Macro register
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
233 map X "myt
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
234 "
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
235 "================================================================
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
236 " T - replace this line with the string 's'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
237 map T C/s
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
238 "
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
239 "================================================================
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
240 " R - put NextChar
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
241 map R "np
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
242 "
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
243 "================================================================
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
244 " V - add the letter 'r' (the replace vi command)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
245 map V ar
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
246 "
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
247 "================================================================
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
248 " J - restore the current character
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
249 map J "cp
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
250 "
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
251 "================================================================
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
252 " H - yank this line into the second Macro register
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
253 map H "ry$
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
254 "
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
255 "================================================================
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
256 " F - yank NextChar (this macro is called from the Macro register)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
257 map F "nyl
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
258 "
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
259 "================================================================
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
260 " ^ - replace the current character with an 'X'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
261 map ^ rX
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
262 "
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
263 "================================================================
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
264 " YKeDP - create the state table, NextChar table and initial state
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
265 " Note that you have to escape the bar character, since it is special to
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
266 " the map command (it indicates a new line).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
267 map Y osE1 k N1 sE1_ mm E2 sE2| mm S1 sE2. ll E1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
268 map K osW1 j S1 sW1_ mm W2 sW2| mm N1 sW2. hh W1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
269 map e osN1. hh W1 sN1| mm N2 sN2 k N1 sN2_ mm E1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
270 map D osS1. ll E1 sS1| mm S2 sS2 j S1 sS2_ mm W1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
271 map P onE1 kF nE2 lF nW1 G$JF nW2 hF nN1 hF nN2 kF nS1 lF nS2 G$JF E1