P - Prestore
Defines and/or executes a sequence of Editor commands for execution by one or two keystrokes.
Syntax
P{n} {command{[command}...}
Syntax Elements
n is the number of the prestored command sequence to be created or executed.
command is one or more valid Editor commands, separated by ESC or another command delimiter, as defined by the CD (Change Delimiter) command.
Prestore Limits
Any Editor command can be prestored by using the P (prestore) commands.
The prestores are numbered P0 through P9. A P
by
itself refers to P0 which is pre-set to L22.
Each of the 10 prestore command buffers can hold one command (or a sequence of commands when separated with command delimiters).
Creating a Prestore
To create a prestore, enter P{n}, a space, followed by the command (or string of commands) separated by command delimiters. The default command delimiter is ESC (X'1B'). Command delimiters are defined by the CD (Change Delimiter) command.
Multiple Editor Commands
Multiple commands can be specified in the same input line by separating them with escape characters (ESC, or CTRL+[). You must be cautious when doing this to avoid creating illegal sequences of commands, or programming infinite loops. If any command produces an error, the remaining commands in the line are skipped.
Calling and Looping
In addition, prestores can call other prestores and can loop back to themselves. This provides the capability of performing complex editing jobs with just one command.
You should exercise extreme caution when using multiple commands in a prestore and when creating loops to ensure that all operations are stated in exactly the same sequence as would be required if each command were entered separately.
Common Mistakes
Common mistakes are to forget the F (Flip) and G (Goto) or n commands when multiple replacements are done on the same data, or to form an infinite loop.
Filing Capabilities
If:
-
an FI (File), FD (File Delete), or EX (Exit) command appears in the prestored command sequence,
-
and if multiple items are being edited (item-list in effect),
-
and if a loop has been constructed
you can perform complex updates on all items with just a single command. Again, you must take care to avoid updating items that should not be updated.
All prestored loops should contain an FI, FD, or EX to
avoid infinite loops. If an infinite loop occurs, press BREAK and type
END
. The item is not filed
(unless an FS was entered) and remains in its initial condition.
Conditional Command Execution
A prestored command has the capability of executing one or other of a pair of command sequences depending on the result of an L (Locate) command.
The commands to be executed conditionally are preceded by the L (Locate) command.
Following this command, each command to be executed if the string is found is prefixed by a colon (:). If more than one command is to be executed in this case, each command must be preceded by a colon and these commands must be entered one after the other.
Similarly, each command to be executed if the string is not
found must be prefixed by a semicolon (;
). Again, these commands must be entered
one after the other.
The set of commands to be executed if the search is successful can be given first or second, as required. But in either case, each set must be entered together as a single sequence.
The first command after the locate that is not prefixed by a colon or a semicolon is always executed regardless of the outcome of the search, and ends conditional execution.
Within the conditional sequences, a further L (Locate) command can be executed. In this case, the outcome of the new locate determines which of the following conditional statements is executed. However, this should be used with caution as there is no way of marking where the embedded locate sequence ends and the original locate sequence continues.
When you use this technique in a multiple item editing session, and a prestore command that begins with either a colon or a semicolon causes the editing session for the current item to terminate, the first prestore command that is neither a colon nor a semicolon is the first command executed upon editing the next item in the item list.
Running a Prestore
To run the prestore, enter P{n}, where n is the number of the desired prestored command. If n is omitted, P0 is executed, that is, the command L22 is executed.
Example 1
|
|
Example 2
|
English selection of
items with a description of "TRANSISTOR". |
Example 3
.
P5 L1/A[:R15/Z//[:FI[;EX[P5
In this example, an L (Locate) command is executed to find an 'A' in the current line. If found, the first occurrence of 'Z' (if any) in that and the next 14 lines is deleted. The item is then filed. If 'A' is not found in the current line, the item is exited. The prestore is now executed again on the next item in the list being processed (the current line in this item is now its first line). This continues until the list is exhausted.
Note
The [
character represents the ESC key.
Example 4
.
P6 L/A[;T[;R15//*/[FI[P5
In this example, an L (Locate) command is executed to find 'A' in any line in the current item (starting from the current line). If A is not found, an asterisk (*) is inserted at the beginning of each of the current and next 14 lines. Whether the A is found or not, the item is filed and the prestore is executed again on the next item in the list.