Very often, the programmer or the text writer has to repeat some complex
editing action over a series of similar blocks of text. Unless you are an
awk
wizard, this is where macros come in.
Macros allows you to record complex actions and play them many times. They can be saved on disk for further usage, edited, loaded, or bound to any key. This allows to reconfigure each key of your keyboard with a complex action, if you want so.
Recording a macro is very simple. The keystroke CONTROL
-T starts
and stop a macro recording (you can see you are actually recording if an
`R
' appears on the status bar). Whatever you do is registered, and when
you stop (again with CONTROL
-T) the recording process, you can play
the macro with the `Play Once
' item of the `Macros
' menu, or with the
F9
key. If you want to repeat the action many times, the Play
command allows you to specify a number of times to repeat the macro. You
can always interrupt the execution with CONTROL
-\.
After recording a macro, you can save it with the `Save Macro...
' menu
item. Any macro file can be played (without modifying the current macro)
with the `Macro...
' menu item. Useful macros can be permanently bound
to a keystroke, as explained in Key Bindings. Moreover, whenever
a command line does not specify an ``internal'' command, it is assumed
to specify the name of a macro to execute. Thus, you can execute macros
just by typing their complete file name.
In order to make this mechanism even more transparent, if the first attempt to
open a macro fails ne
checks for a macro with the given name in the
`.ne
' subdirectory of your home directory. This allows you to program
simple extensions to ne
's language. For instance, all automatic
preferences macros can be executed just by typing their names---if you have an
automatic preference for the `doc
' extension, by typing the command
doc#ap
you will set ne
's flags exactly as if you loaded a file
ending with `.doc
'. In general, it is a good idea to save frequently used
macros in `$HOME/.ne
', so that you can invoke them just by name (of course,
you cannot recall in this way macros with the same name as a command).
Since loading a macro each time it is invoked would be a rather slow and expensive process, once a macro has been executed it is cached internally. The next invocations of the macro will used the cached version.
path sensitive. ne
caches internally only the file name of a macro, not
the path name, and uses a case insensitive comparison. That is, if you call
`~/foobar/macro
', a subsequent call for `/usr/MACRO
' will use the
cached version. You can clear the cache by using the UnloadMacros
command. See UnloadMacros.