An overview of the programming facilities – Crunch CRiSP File Editor 6 User Manual

Page 8

Advertising
background image

Page 8

# include

<crisp.h>

void

mymacro()

{

message("This is my macro!");

}

The #include statement is something you will need sooner or later in the macros you write. Although it is not
needed for this simple macro, you may need it as you extend your macro. The crisp.h file contains
numerous constant definitions which you need for some of the builtin functions of CRiSP.

This macro file contains a single macro, called mymacro. You can execute this macro after you have
compiled and loaded the macro. On most machines, just press the key <Alt-F10> and the macro file will be
compiled and loaded into memory.

On some Unix platforms running the Motif window manager, you may find that <Alt-F10> zooms the CRiSP
editing window to the full screen size. In this case, execute the command load at the Command: prompt.
You can access the Command: prompt by pressing the <F10> key.

After compilation, you will find a file called mymacro.cm in the same directory as the original source. This is
the file which is important to CRiSP. (On the other hand, the file mymacro.cr is important to you).

You can add multiple macros to your macro file and build up complex personal macros to do whatever you
want. It is a good idea if you are going to do extensive macro writing to browse the CRiSP supplied macros
and investigate whether some function you want to write is not already available directly, or callable as a
subroutine.

If you want to have your macro file loaded automatically on startup then enable the
Options

Startup

Startup macro menu option. Type in the full path to your .cm or .cr file.

An Overview of the Programming Facilities

CRiSP is an interpretive language execution engine, combined with support for very high level data objects.
The types of objects CRiSP knows how to manipulate is much more than for a standard programming
language. CRiSP supports basic primitive data types, such as integers, floating point numbers and strings,
as well as high level data objects such as buffers, dialog boxes, keyboard mappings, etc.

The function of CRiSP as a file editor is the combination of the execution engine (the CRiSP binary) and the
various macros supplied as part of the distribution. The supplied macros provide a wide variety of user
interface functions which can be tailored, by virtue of the various set up options, or reprogrammed by
changing the macro sources.

The macros are supplied in a source form, which is a language loosely based on the ANSI-C language, and
a compiled format. The source language provides various programming facilities and is designed so that
macro programmers can write and document maintainable macros. Macros can be very sophisticated and
involved, so macro programmers should create and support macros with respect. It is possible to write
powerful one-liner macros, but if you are going to be writing a lot of macros, then you will need to organise
things so that you can review and update the macros at a later date. This is no different from programming
in any ordinary language.

The compiled format is designed to be loaded into CRiSP much faster than raw interpretation of the macro
source can be. But this does mean that you have to actually compile the macro sources before CRiSP can
execute them. Fortunately this is very easy and CRiSP provides various facilities to help in this.

The underlying machine-code of CRiSP is a Lisp-like language. The CRUNCH language is compiled into an
internal form of the lisp language. The Lisp-like language has no official name, but files written using this
syntax normally have a '.m' file extension. Crunch language files have a .cr file extension. Compiled macros
have a .cm extension.

The lisp language may be considered the assembly language of CRiSP. It is exceptionally rare to code
directly in the lisp language since the CRUNCH language provides a superset of functionality (such as
consistency checking, common expression elimination, and other optimisations), plus the code is much
more maintainable.

See also

Getting started with macro programming (pg. 7).

Advertising