5 Procedure-oriented commands

Files of REDUCE source code frequently consist mainly of procedure definitions. This is certainly true of symbolic-mode code, and hence it is true of most of the source code of the REDUCE system itself. REDUCE mode provides the following operations on procedures. They work on all kinds of REDUCE procedures provided they contain one of the procedural keywords procedure, listproc or matrixproc within their header. Procedure type declarations (symbolic, inline, real, etc.) preceding the procedural keyword are also supported.

A procedure is considered to begin at the first non-white-space character of the definition, and to end after the statement defining the procedure body. White space and the first newline after the procedure body are always considered to be part of the procedure. The commands to mark and kill a procedure also include all blank lines before the procedure definition. Many procedure-oriented commands support a prefix argument.

The two commands for moving over procedures accept a positive integer argument that indicates by how many procedures to move – the default is 1. These commands do not move in the opposite direction if given a negative argument, in which case they do not move at all.

C-M-e
M-x reduce-forward-procedure

Move forwards to the end of the procedure ending after point. With a positive argument, do it that many times. If this fails, move forwards by as many complete procedures as possible and report a user error. Skip to the first following non-blank character or the next line.

C-M-a
M-x reduce-backward-procedure

Move backwards to the start of the procedure starting before point. With a positive argument, do it that many times. If this fails, move backwards by as many complete procedures as possible and report a user error. Skip to the start of any procedural types.

Regardless of whether point is within a procedure or not, these two commands move respectively to the first following end of a procedure, or the first preceding start of a procedure. One way to move to the start of the next procedure is to move forwards to its end and then move backwards to its start.

Marking is the basis for many operations on procedures.

C-M-h
M-x reduce-mark-procedure

Mark the procedure ending after point. With a positive argument, mark that many procedures ending after point. Put mark at the first non-blank character or next line after the appropriate end of procedure. If this fails, do not mark anything and report a user error. Leave point at the start of the first procedure before any preceding blank lines.

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

Kill the procedure ending after point. With a positive argument, kill that many procedures ending after point, including any preceding blank lines. If this fails, do not kill anything and report a user error.

C-M-q
M-x reduce-indent-procedure

Indent the procedure (and trailing white space) ending after point. See Indenting REDUCE code automatically.

It is often desirable to be able to see as much as possible of a procedure definition within the current window. The standard Emacs command reposition-window (see Scrolling in The Emacs Editor) attempts to do this for Lisp functions, and the command reduce-reposition-window provides a harness to apply this function to REDUCE procedures, to which the standard key C-M-l is rebound.

C-M-l
M-x reduce-reposition-window

Reposition the procedure containing point to maximize its visibility within the window. See Scrolling in The Emacs Editor, and see the documentation for the function reposition-window for details.

To restrict all editing to a single REDUCE procedure, the standard Emacs key C-x n d that runs the command narrow-to-defun is rebound to a function to narrow to the current procedure.

C-x n d
M-x reduce-narrow-to-procedure

Narrow to the procedure ending after point. In other words, make all text outside this procedure invisible. With a positive argument, include that many procedures ending after point. Also include any preceding blank lines. If narrowing fails, report a user error. See Narrowing in The Emacs Editor.