14.3.4 Macro Conditionals

Macros can take different actions depending on certain conditions. Such macros take advantage of the fact that PWB editing functions return values— a TRUE (nonzero) value if successful or FALSE (zero) if unsuccessful.

Macros can use four conditional operators:

Operator Description

:>label Defines a label that can be targeted by other operators
=>label Jumps to label
+>label Jumps to label if the previous function returns TRUE
–>label Jumps to label if the previous function returns FALSE

leftmarg:=:>leftmore left +>leftmore

The macro above invokes the left function repeatedly (jumping to the label leftmore) until it returns FALSE, indicating the cursor has reached the left margin.

Summary: Macro execution depends on the status of conditionals.

The label must appear immediately after the conditional operator, with no intervening spaces. A conditional operator without a label exits the macro immediately if the condition is satisfied. If the condition is not satisfied, the macro continues execution. The following example demonstrates this:

turnon:=insertmode +> insertmode

This macro turns on insert mode regardless of whether insert mode is currently on or off. If insert mode is off, the first invocation of insertmode toggles the mode on and returns TRUE, causing the +> operator to terminate the macro. If insert mode is currently on, the first invocation of insertmode turns insert mode off and returns FALSE. The macro then invokes insertmode a second time, turning insert mode back on.