8.1 Using Regi

Regi works by interpreting frames with the function regi-interpret. A frame is a list of arbitrary size where each element is an entry of the following form:

(pred func [negate-p [case-fold-search]])

Regi starts with the first entry in a frame, evaluating the pred of that entry against the beginning of the line that ‘point’ is on. If the pred evaluates to true (or false if the optional negate-p is non-nil), then the func for that entry is evaluated. How processing continues is determined by the return value for func, and is described below. If pred was false the next entry in the frame is checked until all entries have been matched against the current line. If no entry matches, ‘point’ is moved forward one line and the frame is reset to the first entry.

pred can be a string, a variable, a list or one of the following symbols: t, begin, end, or every. If pred is a string, or a variable or list that evaluates to a string, it is interpreted as a regular expression. This regexp is matched against the current line, from the beginning, using looking-at. This match folds case if the optional case-fold-search is non-nil. If pred is not a string, or does not evaluate to a string, it is interpreted as a binary value (nil or non-nil).

The four special symbol values for pred are recognized:

t

Always produces a true outcome.

begin

Always executed before the frame is interpreted. This can be used to initialize some global variables for example.

end

Always executed after frame interpreting is completed. This can be used to perform any necessary post-processing.

every

Executes whenever the frame is reset, usually after the entire frame has been matched against the current line.

Note that negate-p and case-fold-search are ignored if pred is one of these special symbols. Only the first occurrence of each symbol in a frame is used; any duplicates are ignored. Also note that for performance reasons, the entries associated with these symbols are removed from the frame during the main interpreting loop.

Your func can return certain values which control continued Regi processing. By default, if your func returns nil (as it should be careful to do explicitly), Regi will reset the frame to the first entry, and advance ‘point’ to the beginning of the next line. If a list is returned from your function, it can contain any combination of the following elements:

the symbol continue

This tells Regi to continue processing entries after a match, instead of resetting the frame and moving ‘point’. In this way, lines of text can have multiple matches, but you have to be careful to avoid entering infinite loops.

the symbol abort

This tells Regi to terminate frame processing. However, any end entry is still processed.

the list (frame . newframe)

This tells Regi to substitute newframe as the frame it is interpreting. In other words, your func can modify the Regi frame on the fly. newframe can be a variable containing a frame, or it can be the frame in-lined.

the list (step . step)

Tells Regi to move step number of lines forward as it continues processing. By default, Regi moves forward one line. step can be zero or negative of course, but watch out for infinite loops.

During execution of your func, the following variables will be temporarily bound to some useful information:

curline

The current line in the buffer that Regi is looking-at, as a string.

curframe

The current frame being interpreted.

curentry

The current frame entry being interpreted.