Timer functions – Crunch CRiSP File Editor 6 User Manual

Page 45

Advertising
background image

Page 45

undoing back to the point where the buffer no longer needs saving. You should call the
inq_modified() primitive to determine which of the two states you are in.

37

(REG_DEFAULT_FILE). This callback is identical to REG_NEW but is called after
REG_NEW and only if the input file does not have an extension. This allows a macro to
set up things like colorization type to be written based on the contents of the file, if it
cannot be determined from the file extension

38

(REG_CHANGE_DIRECTORY). The current directory has been changed, e.g. by
executing the cd() primitive.

39

(REG_STARTUP). This trigger is called after all the startup code has completed, and
gives macros a chance to do something before going live. Typically this may be used by
pre-loaded macros.

40

(REG_DEFAULT_EXTENSION). Used by the CRiSP macros to intercept editing of files
which do not have an extension. The callback macro then attempts to determine the file
type.

41

(REG_SELECTION_REQUEST). Used when an external task asks for a copy of the
current marked area.

42

(REG_LINE_CHANGED). Callback when a line has been modified. Not officially
supported at present.

43.

(REG_CRISP_IPC). Callback to handle special IPC communication under Windows;
used to detect multiple instances of CRiSP running.

44.

(REG_PRE_COMMAND). Callback which happens after a keystroke has been typed but
before the keystroke is dispatched. Used to implement blinking brackets.

45

(REG_POST_COMMAND) Callback which occurs just after CRiSP processes a
keystroke and before going to sleep to await the next event. Used to implement blinking
brackets.

46

(REG_BUFFER_MOD2). Called when a buffer is modified. Used to implement file
locking.

Timer functions

CRiSP provides a couple of primitives which can be useful for macros which want to perform some activity
on a regular time basis. For example, the mail macro allows the user to view mail and uses two functions to
watch for mail. When the mail macro isn't actively being used (but has been loaded) then a REG_IDLE
registered macro is set up so that every time the idle timer goes off it checks to see if any new mail has been
received.

In addition, if you execute the mail macro and are viewing the main mail contents screen, then a timer is
setup to poll the mail file to check for new mail whilst you are looking at the current mail file.

This mechanism is implemented using the primitives: register_timer and unregister_timer. The
register_timer() macro takes two arguments - a time value in milliseconds, and the name of a macro to call
when the timer expires. When the timer goes off the timer entry is automatically cleared. If you want
repeated pulses from a timer then the simplest thing to do is to call the register_timer() macro from the
callback function. The register_timer() primitive returns a timer identifier which can be used to cancel the
timer via the unregister_macro().

Although the time period is measured in milliseconds there is no guarantee that this level of granularity will
be available on the system you are using, and in fact CRiSP may round up your timing request to the next 1
second interval.

The timer may go off some time later than the interval requested, e.g. if a macro is busily performing a lot of
computation. Internally, CRiSP checks the timer queues before every keystroke is read, so if you wish to
make sure that a timer goes off it may be necessary to force the keyboard to be read.

You should be careful when using timers because you may be called from any environment. For example,
you might build a timer to do something at regular time periods. But you will need to consider the fact that
the user has popped up a popup window, e.g. the buffer list, or help window and the environment you are in
may not be compatable with the operation you wish to perform.

Advertising