Macros – Crunch CRiSP File Editor 6 User Manual

Page 41

Advertising
background image

Page 41

Key

Description

<Alt-L>

Drops a line marker. When a cut or copy command is issued, whole lines will be
affected in the operation.

<Alt-C>

Drops a column marker. Text falling within a rectangular region from where the
anchor was dropped to the current cursor will be highlighted.

<Alt-M>

Drops an inclusive marker. When a cut or copy command is issued, the character
under the cursor will be included in the operation.

<Alt-A>

Drops a non-inclusive marker. When a cut or copy command is issued, the
character under the cursor will not be included in the operation.

Macros

One of the most important features about CRiSP is that it is extensible, i.e. if you do not like some aspect of
the user interface, you can change it without having to recompile the source code (usually). This extensibility
is provided by macros.

A macro is a sequence of instructions which performs a high-level function. Different people have different
ideas about what a programming editor should look like. Some people want simple options, others need
complicated macros which can perform tasks as complicated as sort the functions in a .c file into
alphabetical order.

CRiSP is designed to allow it to be easy to customise the editing tasks that a user wants, no matter how
complicated the editing facility required.

Rather than complicate CRiSP internally with hard to change ideas about what facilities should be available,
CRiSP provides a set of builtin primitives which manipulate the objects CRiSP knows about, e.g. files, buffer,
windows, etc.

CRiSP has a programming language which allows users to combine these primitives into more complex
functions.

For example, CRiSP provides a set of functions to search the current buffer for a string. One of the high
level macros provided with CRiSP matches braces, i.e. it checks that there are an equal number of opening
and closing brackets. This is an example of a macro. The macro is built from the primitives which CRiSP has
compiled into its code.

If you do not like the way these macros are written, then you may easily customise them.

CRiSP provides a complete language for writing macros in. This language, called crunch, is similar to ANSI
C. Experienced C programmers should have little problem understanding the macros supplied with CRiSP,
and can use a lot of ideas from C in writing macros.

Global and Static macros

CRiSP supports the definition of global and static macros, in a manner similar to C. Using the CRUNCH
compiler it is possible to define a static function simply by use of the static storage-class specifier
keyword.

Because CRUNCH is an interpretive language it is necessary to be careful how you use static functions
otherwise you may not achieve what you expect.

CRiSP maintains essentially two sorts of macro tables internally -- a list of global macros, and a list of static
functions. There is actually a list of static function per macro file loaded.

When a macro attempts to execute a macro, CRiSP will check to see whether a macro of the desired name
was declared as static in the same file that the calling macro was defined. If so, then the static macro will be
called. If not, then CRiSP will try the global macro table. This is the ONLY way to invoke a statically declared
macro, i.e. by a macro within the same .cr file attempting to call it. This means a user cannot directly or
indirectly attempt to call a static macro, e.g. from the Command: prompt.

Additionally, a static macro cannot be invoked dynamically, e.g. as a result of a call to the
execute_macro()

or assign_to_key primitives. In fact, any callback functions from CRiSP must not

be declared as static since the macro will not be in scope.

Advertising