<comment>(edited 21-Jun)
<CHAPTER>(Using Macros and Command Files\macro_chap)
<p>
<x>(Using<xs>macros)
<x>(Macros<xs>using)
<x>(Repeating<xs>functions and commands)
<y>(Repeating functions and commands<xs>See Macros)
Some editing operations require the repetition of two or more KED functions 
or commands. For example, the following sequence deletes one or more spaces 
at the end of text lines in a large file.
<list>(numbered)
<le>Press <box>(ADVANCE).
<le>Press <box>(EOL) to move the cursor to the end of a text line.
<le>Press <box>(<delete_key>) as many times as necessary to delete the spaces 
at the end of that line, while making sure that you do not accidentally delete 
any printing characters.
<le>Repeat steps 2 and 3 as many times as necessary to delete the spaces at 
the end of all text lines in the file, while making sure that you do not 
accidentally delete any new-line terminators that precede blank lines.
<endlist>
<P>
The easiest and most accurate way to perform such tedious operations is to 
use a KED macro consisting of a sequence of functions or commands that can be 
repeated. For example, the following macro (described in 
<reference>(deletespaces_sec)) performs steps 1, 2, and 3 of the operation 
shown above and it does not accidentally delete any printing characters or 
new-line terminators.
<list>(simple)
<le><box>(GOLD) <box>(FIND) <box>(SPACE BAR) <box>(RETURN) <box>(ADVANCE)
<le><box>(BACKUP) <box>(WORD) <box>(GOLD) <box>(FIND) <box>(SPACE BAR) 
<box>(ADVANCE)
<le><box>(GOLD) <box>(DELEOL)
<endlist>
<p>
Also, if that macro is preceded by the repeat function ( <box>(GOLD) 
<code_example>(number-of-lines) ), it performs step 4 of the operation 
shown above.
<p>
This chapter tells you how to:
<LIST>(UNNUMBERED)
<LE>Create and store macros (<REFERENCE>(cre_sec))
<LE>Execute macros (<REFERENCE>(exe_sec))
<LE>Conserve space in the macro buffer (<REFERENCE>(con_sec))
<le>Clear the macro buffer (<REFERENCE>(clearmacbuf_sec))
<le>Create and execute macros in auxiliary files (<REFERENCE>(storesep_sec))
<le>Create and use KED command files (<REFERENCE>(kedcomfile_sec))
<le>Use KED command files as work-session initialization files 
(<reference>(initialize_sec))
<ENDLIST>

<HEAD1>(Creating and Storing Macros\CRE_SEC)
<P>
<x>(Creating<xs>macros)
<x>(Storing<xs>macros)
<x>(Macros<xs>creating)
<x>(Macros<xs>storing)
<y>(Saving<xs>See also Storing)
You can create and store one or more KED macros. In one work session, 
the total number of characters in the macros cannot exceed 512, unless you
perform a customization to increase the macro buffer capacity.
<p>
To create and store a KED macro, you must begin its definition 
(<reference>(beginmacro_sec)) and then end its definition 
(<reference>(endmacro_sec)).

<head2>(Beginning the Definition of a Macro\beginmacro_sec)
<p>
<x>(Beginning definition of macro)
<x>(Definition of macro<xs>beginning)
<x>(Macro definition<xs>beginning)
<x>(LEARN identifier command)
<x>(Commands<xs>LEARN identifier)
Use the LEARN command to begin the definition of your macro.
<LIST>(NUMBERED)
<LE>Press <box>(GOLD) and <box>(COMMAND).
<LE>Type:
<interactive>
<u>(LEARN [identifier])
<endinteractive>
<p>
<code_example>(identifier) can be any single letter 
in the alphabet or the backslash (\) character.
<p>
A single macro does not require an identifier and is, by default,
assigned the backslash character. Any subsequent macros you create 
in the same work session (that you want to preserve) do require 
a unique identifier. 
<p>
Subsequent LEARN operations close previous LEARN operations. If a
subsequent LEARN macro is given the same name as a previous LEARN
macro, the subsequent replaces the previous.
For example, if you do not identify a macro,
subsequently identifying another macro with the backslash
character will replace the unidentified macro.
<LE>Press <box>(ENTER) or <box>(RETURN).
<p>
If you press <box>(ENTER), KED returns to text insertion mode. If you
press <box>(RETURN), KED remains in command mode.
<LE>Press the function keys and enter the commands in the order you want them 
executed. 
<p>
You cannot include the GOLD S or GOLD X functions, or the LEARN, EXIT,
or QUIT commands in 
your macro. All other functions and commands are valid, up to a maximum of 
512 characters. KED executes and displays the 
effect of each successful function and command as you enter it. 
If your macro definition encounters an error condition, you
should stop the definition. 
<P>
KED places your sequence of functions and commands in a macro buffer. That 
sequence remains in the buffer until you enter a CLEAR command 
(<reference>(clearmacbuf_sec)).
<p>
Finally, encountering an error condition does not terminate the LEARN
macro creation. However, an error condition does terminate the
execution of a LEARN macro. Therefore, you should ensure that an error
encountered while creating a macro is avoided while executing the
macro. The safest procedure is to restart the LEARN operation and
avoid the condition that produced the error condition.
<ENDLIST>
<p>
In other words:
<list>(simple)
<le><box>(GOLD) <box>(COMMAND) <code_example>(LEARN [identifier]) <box>(ENTER)
<le>Press function keys and enter commands in the order you want them executed.
<endlist>
<p>
If your macro is too large for the buffer, KED clears that macro from the 
buffer and signals you by sounding a beeper or reversing the text and 
background on your terminal. If you press <box>(HELP), KED displays:
<code_example>
Macro buffer full
<endcode_example>
<P>
If your macro is too large for the buffer, you can reduce the size of your 
macro as described in <REFERENCE>(con_sec), or you can create and use a KED 
command file as described in <reference>(kedcomfile_sec).

<head2>(Ending the Definition of a Macro\endmacro_sec)
<p>
<x>(Ending definition of macro)
<x>(Definition of macro<xs>ending)
<x>(Macro definition<xs>ending)
Use the GOLD S or GOLD X function to end the definition of your macro.
<x>(GOLD S function)
<x>(Functions<xs>GOLD S)
<x>(GOLD X function)
<x>(Functions<xs>GOLD X)
<LIST>(NUMBERED)
<LE>Press <box>(GOLD).
<LE>Type:
<interactive>
<u>(S)
<endinteractive>
<P>
or 
<interactive>
<u>(X)
<endinteractive>
<P>
KED ends the definition of your macro and marks it as the current macro.
<list>(simple)
<le>If you type <code_example>(S), KED does not execute it.
<le>If you type <code_example>(X), KED executes it.
<endlist>
<ENDLIST>
<p>
In addition to storing macros in the macro buffer, you can store them in 
auxiliary files as described in <reference>(storesep_sec).

<HEAD1>(Executing Macros\EXE_SEC)
<P>
<x>(Executing macros)
<x>(Macros<xs>executing)
Regardless of how you created your macro or how it is marked, you can execute 
it once or a specified number of times. But if your macro encounters
an error while executing, KED stops executing the macro when the macro 
encounters that error condition. Consequently, 
you should watch your screen when you first execute the macro, 
to make sure that KED can complete all the operations you defined.

<subhead1>(To execute a macro marked as the current macro:)
<x>(GOLD X function)
<x>(Functions<xs>GOLD X)
<LIST>(NUMBERED)
<LE>Press <box>(GOLD).
<LE>Type:
<interactive>
<u>(X)
<endinteractive>
<P>
KED executes the current macro (one created previously and marked as the 
current macro).
<ENDLIST>
<p>
The GOLD X function will execute any macro marked as the current macro, 
regardless of how or when it was created. In other words, you can use the GOLD 
X function to execute a macro that you executed previously with the GOLD M 
identifier function described below.

<subhead1>(To execute any macro, whether or not it is marked as the current 
macro:)
<x>(GOLD M identifier function)
<x>(Functions<xs>GOLD M identifier)
<LIST>(NUMBERED)
<LE>Press <box>(GOLD).
<LE>Type:
<interactive>
<u>(M identifier)
<endinteractive>
<P>
<code_example>(identifier) must be the letter you specified in a 
<code_example>(LEARN identifier) command or the backslash (\) character for a 
macro you created with the <code_example>(LEARN) command.
<p>
KED executes the macro specified by your identifier and marks it as the 
current macro.
<ENDLIST>
<p>
Later, you can use the GOLD X function described above to execute the same 
macro, provided it is still marked as the current macro.

<subhead1>(If you want to execute a macro a certain number of times:)
<LIST>(NUMBERED)
<LE>Press <box>(GOLD).
<LE>Type a number (on your keyboard) to specify the number of times you want 
to execute your macro.
<LE>Press <box>(GOLD) and type:
<interactive>
<u>(X)
<endinteractive>
<P>
or
<interactive>
<u>(M identifier)
<endinteractive>
<P>
KED executes the macro the number of times you specified in step 2.
<ENDLIST>
<p>
In other words:
<list>(simple)
<le><box>(GOLD) <code_example>(number) <box>(GOLD) <code_example>(X)
<le>or
<le><box>(GOLD) <code_example>(number) <box>(GOLD) <code_example>(M 
identifier)
<endlist>
<p>
In addition to executing macros from the macro buffer, you can execute them 
from auxiliary files as described in <reference>(storesep_sec).
<subhead1>(When creating auxiliary files in a macro:)
<p>
KED assumes that any auxiliary file that currently exists on your
system can be overwritten and, therefore, does not prompt for
permission to overwrite (replace) the file. KED does not return the
prompt, <code_example>(Auxiliary file exists. Replace?), when an
auxiliary file is created in a macro.

<HEAD1>(Conserving Space in the Macro Buffer\CON_SEC)
<P>
<x>(Conserving space in macro buffer)
<x>(Space in macro buffer<xs>conserving)
<x>(Macro buffer<xs>conserving space)
<x>(Buffers<xs>macro<xs>conserving space)
The macro buffer can hold up to 512 characters (some systems allow a larger 
number). Each keypad or keyboard key you type adds one or more characters to 
that buffer.
<TABLE>
<TABLE_SETUP>(2\30)
<TABLE_HEADS>(Command, Function, or Key\Characters (Bytes) Added to Buffer)
<TABLE_ROW>(Keypad key\3)
<TABLE_ROW>(Arrow keyboard key\3)
<TABLE_ROW>(Other keyboard key\1)
<TABLE_ROW>(KED command\9 plus 1 for each keyboard key typed)
<TABLE_ROW>(GOLD number\3 plus 1 for each digit typed)
<ENDTABLE>
<p>
If your macro is too large for the buffer, KED signals you by sounding a 
beeper or reversing the text and background on your terminal, and clears that 
macro from the buffer. If you press <box>(HELP), KED displays:
<code_example>
Macro buffer full
<ENDcode_example>
<P>
The following suggestions will help you reduce the size of your macros and 
thus conserve space in the macro buffer.
<LIST>(UNNUMBERED)
<LE>Use command abbreviations or equivalent functions and commands as 
described in <REFERENCE>(func_ax).
<LE>If your macro finds a character string, specify the model string before 
you create the macro. Then, use the FINDNEXT function instead of the FIND 
function in the macro.
<le>Specify KED settings, such as screen width and page definitions, before 
you create the macro.
<LE>If your macro inserts text in your file, store that text in the paste 
buffer before you create the macro. Then, use the PASTE function in the macro.
<LE>Avoid using the ADVANCE and BACKUP functions in your macro by organizing 
it so that all operations proceed in one direction. Then, you can press 
<box>(ADVANCE) or <box>(BACKUP) (depending on the direction you want to go) 
before executing the macro.
<LE>Use the repeat (GOLD number) function in your macro to repeat an 
operation three or more times.
<ENDLIST>
<p>
In addition to reducing the size of your macros, you can clear one or more 
identified macros from the macro buffer as described in 
<reference>(clearmacbuf_sec), or create and use one or more command files as 
described in <reference>(kedcomfile_sec).

<head1>(Clearing the Macro Buffer\clearmacbuf_sec)
<p>
<x>(Clearing macro buffer)
<x>(Macro buffer<xs>clearing)
<x>(Buffers<xs>macro<xs>clearing)
You can clear (delete) all macros or individual macros from the macro buffer.

<subhead1>(To clear all macros:)
<x>(CLEAR ALL MACROS command)
<x>(Commands<xs>CLEAR ALL MACROS)
<LIST>(NUMBERED)
<LE>Press <box>(GOLD) and <box>(COMMAND).
<LE>Type:
<interactive>
<u>(CLEAR ALL MACROS)
<endinteractive>
<LE>Press <box>(ENTER).
<P>
KED clears all macros from the macro buffer.
<ENDLIST>
<p>
In other words:
<list>(simple)
<le><box>(GOLD) <box>(COMMAND) <code_example>(CLEAR ALL) <box>(ENTER)
<endlist>

<subhead1>(To clear individual macros:)
<x>(CLEAR MACRO identifier command)
<x>(Commands<xs>CLEAR MACRO identifier)
<LIST>(NUMBERED)
<LE>Press <box>(GOLD) and <box>(COMMAND).
<LE>Type:
<interactive>
<u>(CLEAR MACRO identifier)
<endinteractive>
<P>
<code_example>(identifier) must be the letter you specified in a 
<code_example>(LEARN identifier) command or the backslash (\) character for a 
macro you created with the <code_example>(LEARN) command.
<LE>Press <box>(ENTER).
<P>
KED clears the macro you identified and merely consolidates any other macros 
remaining in the buffer.
<ENDLIST>
<p>
In other words:
<list>(simple)
<le><box>(GOLD) <box>(COMMAND) <code_example>(CLEAR MACRO identifier) <box>(ENTER)
<endlist>

<head1>(Creating and Executing Macros in Auxiliary Files\storesep_sec)
<p>
<x>(Auxiliary files<xs>storing and using macros)
<x>(Files<xs>auxiliary<xs>storing and using macros)
<x>(Macros<xs>storing in auxiliary files)
<x>(Storing<xs>macros in auxiliary files)
<x>(Macros<xs>using in auxiliary files)
<x>(Using<xs>macros in auxiliary files)
<y>(Separate files<xs>See Auxiliary files)
<x>(Auxiliary files<xs>creating and executing macros)
<x>(Files<xs>auxiliary<xs>creating and executing macros)
<x>(Macros<xs>creating in auxiliary files)
<x>(Creating<xs>macros in auxiliary files)
<x>(Macros<xs>executing from auxiliary files)
<x>(Executing macros<xs>in auxiliary files)
You can create a macro in an auxiliary file and then execute it from the macro 
buffer or directly from the auxiliary file. Also, once a macro is in an 
auxiliary file, you can execute that macro from another macro.

<head2>(Creating Macros in Auxiliary Files\cremacaux_sec)
<p>
The procedure you should use for creating your macro depends on the size of 
the macro and how it will be executed.

<subhead1>(If you think your macro will not be too large for the macro buffer:)
<p>
You can use the LEARN identifier command, GOLD S function, and SAVE identifier 
command to create your macro in an auxiliary file.
<list>(numbered)
<le>Create and store your macro in the macro buffer, using the LEARN 
identifier command and the GOLD S function as described in 
<reference>(cre_sec). 
<le>Use the SAVE identifier command to copy your macro to an auxiliary file.
<x>(SAVE identifier filespec command)
<x>(Commands<xs>SAVE identifier filespec)
<LIST>(alphabetic)
<LE>Press <box>(GOLD) and <box>(COMMAND).
<LE>Type:
<interactive>
<u>(SAVE identifier [filespec])
<endinteractive>
<p>
<code_example>(identifier) must be the same identifier you used in creating 
and storing your macro (step 1). If the identifier is the 
backslash (\) character, you must include the file specification.
<p>
If you do not type <code_example>(filespec), the file name will be your 
identifier and the file type will be KED (identifier.KED).
If you type just the file name, the file type will be KED.
<LE>Press <box>(ENTER).
<P>
KED copies your macro to the auxiliary file you specified.
<ENDLIST>
<ENDLIST>
<p>
In other words:
<list>(simple)
<le>Create and store your macro in the macro buffer.
<le><box>(GOLD) <box>(COMMAND) <code_example>(SAVE identifier [filespec]) 
<box>(ENTER)
<endlist>

<subhead1>(If you think your macro will be too large for the macro buffer or 
if you plan to execute your macro from another macro:)
<p>
Do not use the LEARN identifier command, GOLD S function, and SAVE identifier 
command to create your macro in an auxiliary file. Instead:
<list>(numbered)
<le>End your current work session.
<le>Use KED in a second work session to create (type) your macro in an 
auxiliary file, as described in <reference>(kedcomfile_sec).
<endlist>
<p>
Although the auxiliary file can be any standard 
file specification in the form <emphasis>(filnam.typ), the 
following KED defaults are more useful:
<list>(simple)
<le>The file name is the single letter identifier you assigned the
file with the SAVE command.
<le>The file type is KED.
<endlist>
<p>
If you find that your macro is not too large for the macro buffer, you 
will not have to add a file specification to the LOAD identifier command. 
If you find that your macro is small enough to be executed from another 
macro 
(see example in <reference>(kedcomfile_sec)), those defaults will consume 
less space in the macro buffer.

<head2>(Executing Macros in Auxiliary Files\exemacaux_sec)
<p>
If the macro in your auxiliary file contains an error, KED will stop its 
execution when KED reaches that error. Consequently, 
you should watch your screen when you first execute the macro, 
to make sure that KED 
can complete all the operations you defined.
<p>
The procedure you use for executing your macro depends on the size of 
the auxiliary file.

<subhead1>(If your auxiliary file is not too large for the macro buffer:)
<p>
You can use the LOAD identifier command and the GOLD M identifier function to 
execute your macro.
<list>(numbered)
<le>Use the LOAD identifier command to copy the auxiliary file to the macro 
<x>(LOAD identifier filespec command)
<x>(Commands<xs>LOAD identifier filespec)
buffer.
<LIST>(alphabetic)
<LE>Press <box>(GOLD) and <box>(COMMAND).
<LE>Type:
<interactive>
<u>(LOAD identifier [filespec])
<endinteractive>
<p>
<code_example>(identifier) can be any single letter you choose, as long as you 
are not using it to identify another macro. If the identifier is the
backslash (\) character, you must include a file specification.
<p>
If you do not type <code_example>(filespec), the file name will be your 
identifier and the file type will be KED (identifier.KED).
If you type just the file name, the file type will be KED.
<LE>Press <box>(ENTER).
<P>
KED copies the auxiliary file you specified to the macro buffer.
<ENDLIST>
<le>Execute your macro, using the GOLD M identifier function as described in 
<reference>(exe_sec).
<p>
<code_example>(identifier) must be the same identifier you used with the LOAD 
command to copy the auxiliary file to the macro buffer (step 1b).
<endlist>
<p>
In other words:
<list>(simple)
<le><box>(GOLD) <box>(COMMAND) <code_example>(LOAD identifier [filespec]) <box>(ENTER)
<le><box>(GOLD) <code_example>(M identifier)
<endlist>

<subhead1>(If your auxiliary file is too large for the macro buffer:)
<p>
You can use the @filespec command to execute your macro.
<x>(At-sign (@) filespec command)
<x>(@filespec command)
<x>(Commands<xs>@filespec)
<LIST>(numbered)
<LE>Press <box>(GOLD) and <box>(COMMAND).
<LE>Type:
<interactive>
<u>(@filespec)
<endinteractive>
<p>
<code_example>(filespec) is the file specification you want to execute
(default file type is KED)
<LE>Press <box>(ENTER).
<P>
KED executes your macro directly from the file you specified.
<ENDLIST>
<p>
In other words:
<list>(simple)
<le><code_example>(<box>(GOLD) <box>(COMMAND)) <code_example>(@filespec) <box>(ENTER)
<endlist>

<head1>(Creating and Using KED Command Files\kedcomfile_sec)
<p>
<x>(Files<xs>command<xs>creating and using)
<x>(Command files<xs>creating and using)
<x>(Creating<xs>command files)
<x>(Using<xs>command files)
You can use KED in another work session to create an auxiliary file 
containing 
KED commands that you would normally type in response to the 
<code_example>(Command:) prompt. In that file:
<list>(unnumbered)
<le>You cannot use the LEARN command to define a macro.
<x>(Exclamation point)
<le>An exclamation point (!) can be used to indicate that the rest of a line 
is a comment, not a command. If you plan to copy the file to the macro buffer, 
keep your comments short.
<le>When the macro is executed, blank lines are skipped by KED when it is in 
the command mode.
<le>The CHANGE command, which returns KED to the text editing mode, can 
<x>(CHANGE command)
<x>(Commands<xs>CHANGE)
precede text that you want to insert directly into your output file.
<le>
KED assumes that any auxiliary file that currently exists on your
system can be overwritten and, therefore, does not prompt for
permission to overwrite (replace) the file. KED does not return the
prompt, <code_example>(Auxiliary file exists. Replace?), when run from
command files.
<endlist>
<p>
The following is an example of a command file.
<code_example>
! We are in command mode
SET WRAP 30     ! Set right margin

! Change to Insert mode
CHANGE
Use the R command if the input file is on your system volume.

If that file is on another volume, use the RUN command.
<endcode_example>
<p>
That command file sets the length of text lines to 30 columns
and then inserts the text 
as shown below.
<code_example>
Use the R command if the input 
file is on your system volume.

If that file is on another 
volume, use the RUN command.
<endcode_example>
<p>
After you create your command file:
<list>(unnumbered)
<le>If it is not too large for the macro buffer, you can load it as a macro 
with the LOAD identifier command and then execute it as a macro with the GOLD 
M identifier function, as described in <reference>(exemacaux_sec).
<le>If it is too large for the macro buffer or if you plan to use it
once, you can execute it with the @filespec command, as described in 
<reference>(exemacaux_sec).
<endlist>
<p>
If the macro in your command file contains an error, KED will stop its 
execution when KED reaches that error. Consequently, 
you should watch your screen when you first execute the macro, 
to make sure that KED 
can complete all the operations you defined.

<head1>(Using KED Command Files as Work-session Initialization 
Files\initialize_sec)
<p>
<x>(Using<xs>command files as work-session initialization files)
<x>(Command files<xs>using as work-session initialization files)
<x>(Creating<xs>work-session initialization files)
<x>(Using<xs>work-session initialization files)
<x>(Files<xs>work-session initialization, creating and using)
<x>(Work session<xs>initialization files, creating and using)
<y>(Initialization files<xs>See Work session, initialization files)
Work-session initialization files are KED command files 
(<reference>(kedcomfile_sec)). Initialization files can
preset KED to give you certain operations and characteristics in every 
work session or
let you complete a work session without typing any keypad or keyboard
keys.
<p>
Before beginning a work session, KED looks for initialization file 
KEDINI.KED. You can use KED to create KEDINI.KED if you want to use a 
default initialization file. If KEDINI.KED
exists, KED executes it. If it does not exist, KED does not 
report an error. 
<p>
If you want KED to execute a different initialization file
before beginning your work 
session, you can use KED to create the file and then use 
the following command to begin your work session:
<x>(/COMMAND:init-filespec command option)
<x>(Command options<xs>/COMMAND:init-filespec)
<syntax>
     EDIT/COMMAND:init-filespec filespec <box>(RET)
<endsyntax>
<TABLE>
<TABLE_SETUP>(2\15)
<TABLE_ROW>(init-filespec\is the specification for another 
initialization file.)
<TABLE_ROW>(filespec\is the specification for your input or 
output file.)
<ENDTABLE>
<p>
If the other initialization file exists, KED executes it instead of 
KEDINI.KED. If the other initialization file does not exist, KED displays:
<code_example>
?KED-W-Command file not found - Continue (Y,N)?
<endcode_example>
<p>
Type Y and press <box>(RETURN) to begin your work session without executing 
any initialization file. Type N and press <box>(RETURN) to return to your 
system prompt.
<p>
If you want to suppress that query and any others KED could generate, use the 
following command to begin your work session:
<x>(/NOQUERY command option)
<x>(Command options<xs>/NOQUERY)
<syntax>
     EDIT/NOQUERY filespec <box>(RET)
<endsyntax>
<p>
or 
<syntax>
     EDIT/COMMAND:init-filespec/NOQUERY filespec <box>(RET)
<endsyntax>
<p>
If KEDINI.KED exists and
you do not want KED to execute any initialization file, use the following 
command to begin your work session.
<x>(/NOCOMMAND command option)
<x>(Command options<xs>/NOCOMMAND)
<syntax>
     EDIT/NOCOMMAND filespec <box>(RET)
<endsyntax>
<p>
The following is an example of an initialization file that presets KED to give 
you certain operations and characteristics in every work session.
<code_example>
! Set Session Characteristics
SET QUIET                       ! Reverse screen to indicate errors
SET SECTION 10                  ! Define section as 10 lines
SET NOHELP                      ! Disable full help screens
SET SEARCH NOSELECT             ! Disable selection default
<endcode_example>
<p>
The following is an example of an initialization file that lets you complete a 
work session without typing any keypad or keyboard keys.
<list>(simple)
<le>! We start in command mode
<line>! So we want to change to insert mode to
<line>! Insert Page Head
<le>CHANGE
<line>For Internal Use Only
<le>! We now return to command mode
<line>!  by including the COMMAND escape equivalent
<le><math_char>(PI)OP<math_char>(PI)Ow
<le>! And
<le>EXIT
<endlist>
<p>
KED stops its execution
if the macro in your initialization file contains an error or
encounters an error condition. Consequently, 
you should watch your screen when you first execute the macro, 
to make sure that KED can complete all the operations you defined.

<head1>(Examples)
<p>
This section contains some examples of KED macros that you may find useful or 
want to modify to suit your needs.
<p>
Each example has three parts.
<list>(numbered)
<le>The commands and functions you use before entering the LEARN 
command
<le>The LEARN command and the combination of commands and functions you want 
KED to store as a macro
<le>The commands and functions that normally follow the GOLD S or GOLD X 
function you must use to end the macro
<endlist>
<p>
Each example is described as a series of numbered steps with at least one 
command or function in each step.

<head2>(Decreasing the Size of a BASIC--PLUS/RT Program by Removing the Text 
in REM Statements)
<p>
You can decrease the size of a BASIC--PLUS/RT program by removing the 
comments. But you should remove only the text, because transfer statements, 
such as the GO TO statement, may specify the line number of a REM statement.
<p>
You can remove the text in a series of REM statements by executing the 
following macro. It assumes that the program does not contain compound 
statements in the form <code_example>(10 REM This is a comment <backslash> 
PRINT X$).
<list>(numbered)
<le>Set KED for exact search matching.
<code_example>
<box>(GOLD) <box>(COMMAND) SET SEARCH EXACT <box>(ENTER)
<endcode_example>
<le>Specify that KED will place the cursor after the target in a successful 
search.
<code_example>
<box>(GOLD) <box>(COMMAND) SET SEARCH END <box>(ENTER)
<endcode_example>
<le>Specify the string REM as the search target.
<code_example>
<box>(GOLD) <box>(FIND) REM <box>(ADVANCE)
<endcode_example>
<le>Start storing a sequence of functions (the macro).
<code_example>
<box>(GOLD) <box>(COMMAND) LEARN <box>(ENTER)
<endcode_example>
<le>Delete the text in each REM statement but leave the line number and the 
word REM.
<code_example>
<box>(GOLD) <box>(DELEOL) <box>(FINDNEXT)
<endcode_example>
<le>End the sequence.
<code_example>
<box>(GOLD) S
<endcode_example>
<le>Execute the macro.
<code_example>
<box>(ADVANCE) <box>(GOLD) X
<endcode_example>
<p>
or
<code_example>
<box>(BACKUP) <box>(GOLD) X
<endcode_example>
<endlist>

<head2>(Extracting Addresses That Contain a Certain ZIP Code)
<p>
When you have a mailing list that uses the same format for each address, you 
may be able to use a macro to extract addresses that contain a certain ZIP 
code.
<p>
The following macro assumes that your mailing list has:
<list>(simple)
<le>A blank line before the first line of each address
<le>No 5-digit number except the ZIP code in any address
<endlist>
<p>
Since a blank line precedes each address, each address is preceded by two 
new-line terminators. The macro uses that format to guarantee that addresses 
with any number of lines will be extracted.
<list>(numbered)
<le>Define a page as the text between markers composed of two new-line 
terminators.
<code_example>
<box>(GOLD) <box>(COMMAND) SET PAGE "<box>(RETURN)<box>(RETURN)" <box>(ENTER)
<endcode_example>
<le>Open auxiliary output file ADDOUT.LST for the addresses to be extracted.
<code_example>
<box>(GOLD) <box>(COMMAND) OPEN OUTPUT ADDOUT.LST <box>(ENTER)
<endcode_example>
<le>Specify ZIP code 99999 as the search target.
<code_example>
<box>(GOLD) <box>(FIND) 99999 <box>(ADVANCE)
<endcode_example>
<p>
or
<code_example>
<box>(GOLD) <box>(FIND) 99999 <box>(BACKUP)
<endcode_example>
<le>Start storing a sequence of commands and functions (the macro).
<code_example>
<box>(GOLD) <box>(COMMAND) LEARN <box>(ENTER)
<endcode_example>
<le>Find the next address that contains the ZIP code you specified.
<code_example>
<box>(ADVANCE) <box>(FINDNEXT)
<endcode_example>
<le>Move the cursor back to the beginning of that address.
<code_example>
<box>(BACKUP) <box>(PAGE)
<endcode_example>
<le>Write the address to the auxiliary output file.
<code_example>
<box>(GOLD) <box>(COMMAND) WRITE 1 PAGE <box>(ENTER)
<endcode_example>
<le>End the sequence.
<code_example>
<box>(GOLD) S
<endcode_example>
<le>Execute the macro.
<code_example>
<box>(GOLD) X
<endcode_example>
<endlist>
<p>
You can use that macro to extract addresses for more than one ZIP code by 
using the FIND function again to specify a different ZIP code.

<head2>(Moving the Cursor to the End of a Word)
<p>
The WORD function moves the cursor to the first character in a word, but you 
may want to change the endings of several different words. For example, you 
may want to change some words from the singular to the plural.
<p>
In normal text, most of the words that KED detects end with one or more 
spaces. This macro uses that format to move the cursor to the first space that 
follows the printing characters in a word.
<list>(numbered)
<le>Specify a space as a search target.
<code_example>
<box>(GOLD) <box>(FIND) <box>(SPACE BAR) <box>(ADVANCE)
<endcode_example>
<le>Start storing a sequence of functions (the macro).
<code_example>
<box>(GOLD) <box>(COMMAND) LEARN <box>(ENTER)
<endcode_example>
<le>Move the cursor to the beginning of a word and then to the first space 
after that word.
<code_example>
<box>(WORD) <box>(FINDNEXT)
<endcode_example>
<le>End the sequence and execute the macro.
<code_example>
<box>(GOLD) X
<endcode_example>
<endlist>
<p>
That macro moves the cursor to the end of a word only when the word has 
trailing spaces. The macro skips words that end with line terminators and 
horizontal-tab characters.

<head2>(Deleting Spaces from the End of a Text Line\deletespaces_sec)
<p>
When you create a text file, each line in the file may have several spaces 
preceding the line terminator. The following macro assumes that a new-line 
terminator is at the end of each line and deletes any spaces that are between 
the last printing character and the terminator.
<list>(numbered)
<le>Start storing a sequence of functions (the macro).
<code_example>
<box>(GOLD) <box>(COMMAND) LEARN <box>(ENTER)
<endcode_example>
<le>Search for a text line that has one or more trailing spaces.
<code_example>
<box>(GOLD) <box>(FIND) <box>(SPACE BAR) <box>(RETURN) <box>(ADVANCE)
<endcode_example>
<le>Move the cursor to the first trailing space in the line.
<code_example>
<box>(BACKUP) <box>(WORD) <box>(GOLD) <box>(FIND) <box>(SPACE BAR) <box>(ADVANCE)
<endcode_example>
<le>Delete all trailing spaces.
<code_example>
<box>(GOLD) <box>(DELEOL)
<endcode_example>
<PAGE>
<le>End the sequence and execute the macro.
<code_example>
<box>(GOLD) X
<endcode_example>
<endlist>

<head2>(Reformatting Paragraphs)
<p>
The FILL function or command reformats selected text lines. When KED finishes 
processing the selected lines, no new line reaches beyond the right margin you 
are using.
<p>
When you want to reformat text lines that are in separate paragraphs, you must 
select each paragraph and then use the FILL function or command.
<p>
The following macro reformats paragraphs when they are separated by two 
new-line terminators that are followed by five spaces at the beginning of the 
first line. The macro assumes you will advance, not back up, through your file 
from paragraph to paragraph.
<list>(numbered)
<le>Specify two new-line terminators as the search target.
<code_example>
<box>(GOLD) <box>(FIND) <box>(RETURN)<box>(RETURN) <box>(ADVANCE)
<endcode_example>
<le>Start storing a sequence of commands and functions (the macro).
<code_example>
<box>(GOLD) <box>(COMMAND) LEARN <box>(ENTER)
<endcode_example>
<le>Move the cursor to the first printing character in the paragraph.
<code_example>
<box>(GOLD) 5 <box>(<math_char>(rightarrow))
<endcode_example>
<le>Select the text lines that are in the paragraph.
<code_example>
<box>(SELECT) <box>(FINDNEXT)
<endcode_example>
<le>Reformat the text lines in the paragraph.
<code_example>
<box>(GOLD) <box>(FILL)
<endcode_example>
<p>
or
<code_example>
<box>(GOLD) <box>(COMMAND) FILL <box>(ENTER)
<endcode_example>
<le>End the sequence.
<code_example>
<box>(GOLD) S
<endcode_example>
<le>Execute the macro.
<code_example>
<box>(GOLD) X
<endcode_example>
<endlist>

<head1>(Useful Command Files)
<p>
You can create the following command file, PRINT.KED, to
use during a work session to print selected text on a printer.
<code_example>
! PRINT.KED
!
OPEN OUTPUT LP:
WRITE SELECT
CLOSE
<endcode_example>
<PAGE>
<p>
Issue the @PRINT command to execute that file.
<p>
You can create the following command file, FORM.KED, to
use as an initialization file to insert an empty 
form (FORM.TXT) and then set some KED characteristics so your new 
form can be completed properly.
<code_example>
! FORM.KED
!
OPEN INPUT SY:FORM.TXT
INCLUDE REST
SET SCREEN 132
SET WRAP 120
SET TABS 10
<endcode_example>
<p>
Issue the following command to execute that file:
<code_example>
EDIT/CREATE/COMMAND:FORM.KED filespec <box>(RET)
<endcode_example>
<p>
where <code_example>(filespec) is your new form.
<p>
You can create the following command file, TRANSF.KED, to
use as an initialization file to display a 
transfer address from a link map and then end your work session without 
producing an output file.
<list>(simple)
<le>! TRANSF.KED
<line>! We are in command mode by default
<line>! Change to insert mode
<le>CHANGE
<le>! And
<line>! Include escape equivalents for FIND Transfer ADVANCE SELECT BLINE 
<le><math_char>(PI)OP<math_char>(PI)ORTransfer<math_char>(PI)Ot<math_char>(PI)On<math_char>(PI)Op
<le>! We now return to command mode
<line>!  by including the COMMAND escape equivalent
<line><math_char>(PI)OP<math_char>(PI)Ow
<line>! And
<le>OPEN OUTPUT TT:
<line>WRITE SELECT
<line>CLOSE
<line>QUIT
<endlist>
<p>
Issue the following command to execute that file:
<code_example>
EDIT/COMMAND:TRANSF.KED filespec <box>(RET)
<endcode_example>
<p>
where <code_example>(filespec) is the link map.
<p>
See <reference>(insertescape_sec) for a list of other keypad operations 
performed by escape equivalent characters like those shown above.
