4 Statement-oriented commands

The most basic facility provided by REDUCE mode is the ability to move forwards and backwards by statements or expressions through a file of REDUCE source code. Moving by one statement means moving to the beginning or end of the logical statement currently containing (or respectively preceding or following) point, which may involve skipping many actual statements that are contained within the current statement. In particular, as REDUCE mode looks for the beginning or end of a statement it will skip complete compound or block statements (begin … end), group statements (<< … >>), and bracketed expressions ((…), {…} and […], although square brackets are not normally used in REDUCE). Bracket skipping is controlled entirely by the Emacs syntax table.

Hence, “statement” in this manual will normally mean a complete logical statement. A syntax-directed editor clearly must perform a limited amount of parsing, but it must be remembered that a syntax-directed editor has the following important differences from a normal parser, because their basic purposes are different:

In particular, the REDUCE-mode movement commands may fail if point is within a comment or string, although they should skip complete comments and strings.

REDUCE mode considers REDUCE statements to be terminated by either of the characters ; or $. It also considers statements contained within any kind of brackets to be delimited by those brackets, statements within compound or block statements (begin … end) to be delimited by the begin and end keywords, and statements within group statements (<< … >>) to be delimited by the << and >> tokens. Commas are not considered to delimited statements.

More precisely, a statement is considered to begin at the first non-white-space character following the previous statement terminator, opening bracket, begin or <<. It is considered to end immediately after the first statement terminator or immediately after the last non-white-space character preceding a closing bracket, end or >>. Comments are treated as white space by all REDUCE-mode commands other than those specifically related to comments; Support for REDUCE comments.

The current philosophy of REDUCE mode is that the statements within a compound or group statement form an essentially isolated system, and that the basic statement-oriented commands should not move point either into or out of this system, for which separate commands are provided. However, if you try hard enough, REDUCE mode will let a simple statement-oriented command move out of (but never into) a compound or group statement. Trying hard enough means repeating the same command enough times, which is determined by the value of the option reduce-max-escape-tries, which currently has the default value 2; Options that control REDUCE IDE. The overall effect of this is to enforce a brief pause (one ineffective command execution) that serves to prevent you from skipping out of a compound or group statement accidentally, but without causing any serious inconvenience.

The following commands all accept a numerical argument, which defaults to 1. The commands to move forwards or backwards by statements do not move in the opposite direction if given a negative argument, in which case they do not move at all. They contain special code to handle the keyword end followed by a terminator when used as the end-of-file marker, provided it appears at the start of a line (optionally preceded by a terminator but no space), and they do not regard comment statements as statements, i.e. they treat them as white space. They report a user error if they fail.

C-c C-n
M-x reduce-forward-statement

Move forwards to the end of the current statement if within a statement or to the end of the following statement otherwise. With an argument, do it that many times. If looking at the end of a block or group, or the end-of-file marker, move over it after reduce-max-escape-tries consecutive interactive tries.

C-c C-p
M-x reduce-backward-statement

Move backwards to the start of the current statement if within a statement or to the start of the previous statement otherwise. With an argument, do it that many times. If looking at the beginning of a block or group move over it after reduce-max-escape-tries consecutive interactive tries. The end-of-file marker is treated as a statement.

C-c C-k
M-x reduce-kill-statement

Kill the rest of the current statement from point. With a prefix argument, kill that many statements from point. Negative arguments kill statements backwards, where the prefix argument minus (-) is equivalent to -1.

C-c C-u
M-x reduce-up-block-or-group

Move backwards up one level of block or group, i.e. to the beginning of the begin or << at the start of the block or group containing point. A universal argument means move forwards, i.e. to the end of the end or >> at the end of the block or group containing point. Report a user error if the move fails. With a numeric argument, do it that many times, where a negative argument means move forwards instead of backwards.

C-c C-d
M-x reduce-down-block-or-group

Move forwards down one level of block or group, i.e. to the end of the nearest begin or << within the current block or group, if any. A universal argument means move backwards to the beginning of the nearest end or >> within the current block or group, if any. Report a user error if the move fails. With a numeric argument, do it that many times, where a negative argument means move backwards instead of forwards.

The following two commands move by “balanced expression”, which means a symbol, string, bracketed expression, block or group. A symbol or bracketed expression may be quoted. The commands skip any preceding or intervening white space or terminator characters, but assume point is not in a string or comment.

C-M-f
M-x reduce-forward-sexp

Move forwards across one “balanced expression”. With a numeric argument, move that many times, where a negative argument means move backwards instead of forwards. This command is modelled on forward-sexp.

C-M-b
M-x reduce-backward-sexp

Move backwards across one “balanced expression”. With a numeric argument, move that many times, where a negative argument means move forwards instead of backwards. This command is modelled on backward-sexp.