@node Macro, Meta, Lweight, Commands @iftex @syntax Macro. @end iftex @example Syntax: MACRO EDIT name MACRO LIST [begin end ] MACRO name [ narg ] @{ body @} MACRO name [ narg ] < body > MACRO name DELETE MACRO name #1 #2 MACRO READ file MACRO WRITE file MACRO DELETE file MACRO WRITE name [ + ] file @end example @pindex Macro @findex plot macros MACRO EDIT name allows you to edit a macro. All the commands available to the history editor area available (including the @ctrl{} history), except that @ctrl{M} inserts a line before the cursor, @ctrl{N} and @ctrl{P} get the next and previous lines respectively, and @ctrl{V} and ESC-v move forwards and backwards 5 lines at a time. To exit use @ctrl{X} (or whatever you have bound to @code{exit_editor}). The macro need not exist, and both its name and number of arguments can be changed by editing the zeroth line of the macro (@ctrl{P} from the first line. If this line is corrupted, or deleted, no changes are made to the macro when you exit. If the number of arguments is negative, the macro will be deleted when you exit.) You may prefer to use the macro @code{ed} instead of MACRO EDIT, as it doesn't appear on the history list and, if invoked without a macro name will edit the macro that you edited last. Incidently, @code{hm} (`help macro') will list the last macro that you edited with @code{ed}. The keybindings may be changed with READ EDIT. LIST MACRO lists all currently defined macros, or all those which are between @code{begin} and @code{end} alphabetically (asciily). If VERBOSE is 0, macros starting with ## are not listed. MACRO @code{name [narg] @{ body @}} defines @code{name} to be @code{body}, where @code{name} is a single word, and @code{body} may be anything (most users need not worry about the form in angle brackets; it is occasionally useful when writing clever macros). A macro is invoked by typing its name. The optional @code{nargs} is the number of arguments the macro expects, default 0. If the macro's body is defined to be @code{delete}, the macro is deleted. MACRO @code{name} DELETE also deletes a macro. Arguments are referred to as $1, $2, @dots{} $n, up to a maximum of $9. $0 gives the name of the macro. If the number of arguments is declared as more than 9, the macro is taken to have a variable number of arguments, up to the number declared modulo 10. If the number declared is greater than 99 the last argument will extend to the end of the line, and may consist of many words. When called, all the arguments must appear on the same line as the macro itself. This line may, as usual, be ended with an explicit \n. The macro can determine whether it has been supplied a given argument by using the @code{$?} construction (see DEFINE). It is also possible to change the values of arguments using DEFINE just as usual, and even to DEFINE arguments that you didn't declare. These are temporary variables, local to the macro, and will disappear when you exit the macro. MACRO @code{name #1 #2} defines macro name to consist of lines #1 --- #2 of the history buffer. If #1 or #2 is negative it is interpreted relative to the current command, so saying @code{MACRO last2 -1 -2} will define a macro @code{last2} consisting of the last 2 commands issued. MACRO READ @code{file} reads the macros in @code{file} and defines them. See RESTORE for how to also restore the history buffer from macro @code{all}. MACRO DELETE @code{file} has the effect of deleting all macros defined in @code{file}. MACRO WRITE @code{file} writes all currently defined macros to @code{file} in alphabetical order. If the file exists, and @code{$noclobber} is defined, SM will refuse to overwrite the file. You can set @code{noclobber} by specifying it in your @file{.sm} file. MACRO WRITE @code{name [ + ] file} writes the macro @code{name} to @code{file}. If the @code{+} is specified, or the file is the same as for the previous use of this command, the macro is written to the bottom of the file, otherwise the file is created. If the file exists and you aren't simply appending, and @code{$noclobber} is defined, SM will refuse to overwrite the file. You can set @code{noclobber} by specifying it in your @file{.sm} file.