3 Editing Oz Code

The commands in this chapter assist in editing Oz code. To achieve this, many of these are aware of the lexical or syntactical structure of Oz programs.

3.1 Managing Oz Buffers

The Oz modes offer commands for creating new interactive buffers and quickly switching between Oz buffers:

oz-new-buffer (C-. n)

Create a new buffer using the Oz major mode. Note that this buffer has no associated file name, so quitting Emacs will kill it without warning.

oz-next-buffer (M-n)
oz-previous-buffer (M-p)

Switch to the previous resp. next buffer in the buffer list that runs in an Oz mode. If no such buffer exists, an error is signalled.

3.2 Indentation

The preferred indentation style can currently be customized through the following user option:

oz-indent-chars (default: 3)

Number of columns that statements are indented w. r. t. the block containing them.

Several commands assist in formatting existing Oz code.

oz-indent-line &optional COUNT (TAB)

Reindent the current line. If COUNT is given, reindent that many lines above and below point as well.

oz-indent-region

Reindent all lines at least partly covered by the current region.

oz-indent-buffer

Reindent every line in the buffer.

indent-oz-expr (M-C-q)

Reindent all lines at least partly covered by the Oz expression following point. For a description of what constitutes an Oz expression, see Section 3.5.

The following command assists in authoring Oz code.

oz-electric-terminate-line (RET)

Terminate the current line, i. e., delete all whitespace around point and break the line. If the user option oz-auto-indent is non-nil, indent both lines.

oz-auto-indent (default: t)

See oz-electric-terminate-line.

Additionally, DEL is bound to the Emacs command backward-delete-char-untabify.

3.3 Fontification

Fontification is the term used in Emacs for displaying text in different font faces, depending on its syntactical form and context, to ease reading of code. For example, comments and strings may be displayed in different colours.

Many major modes in Emacs provide several levels of fontification with increasing use of faces, but also increasing resource consumption. In the Oz modes, there are three levels. You can select one using the font-lock-maximum-decoration user option, e. g., add the following line to your .emacs:

(setq font-lock-maximum-decoration 3)

The default level depends on your version of Emacs.

The following user option controls automatic fontification in the OPI.

oz-want-font-lock (default: t)

If non-nil, automatically invoke font-lock-mode when any of the Oz modes is activated. If you prefer to control this via global-font-lock-mode, you can set this to nil.

You might like the following user option and command if you care about superfluous (usually invisible) spaces:

oz-pedantic-spaces (default: nil)

If non-nil, highlight ill-placed whitespace. Note that this user option must be set before the oz library is loaded.

oz-space-face

The face in which ill-placed whitespace is highlighted.

oz-remove-annoying-spaces

Remove all ill-placed whitespace from the current buffer. This is all the whitespace that is highlighted in oz-space-face.

3.4 Comments

oz-fill-paragraph &optional JUSTIFY

Like the fill-paragraph command, but handles Oz comments. If any of the current line is a comment, fill the comment or the paragraph of it that point is in, preserving the comment's indentation and initial percent signs. The buffer-local variable fill-paragraph-function is bound to this command, so it will also be invoked by M-x fill-paragraph (M-q).

oz-comment-region START END &optional ARG

Comment or uncomment each line in the region. With just C-u as prefix argument, uncomment each line in region. A numeric prefix argument ARG means use ARG comment characters. If ARG is negative, delete that many comment characters instead. Blank lines do not get comments.

oz-uncomment-region START END &optional ARG

Comment or uncomment each line in the region. See the oz-comment-region command for more information; note that the prefix argument is negated though.

3.5 Expression-Level Commands

In this section, we use the term Oz definition to stand for the text from a proc, fun, class or meth keyword up to its matching end. Also, we use the term Oz expression to stand for the text corresponding to either a bracketed Oz construct (such as proc ... end or local ... end) or a single word.

forward-oz-expr &optional COUNT (M-C-f)

Move point forward by one balanced Oz expression. With COUNT, do it that many times. Negative COUNT means backwards.

backward-oz-expr &optional COUNT (M-C-b)

Move point backward by one balanced Oz expression. With COUNT, do it that many times. COUNT must be positive.

mark-oz-expr COUNT (M-C-@, M-C-SPC)

Set mark COUNT balanced Oz expressions from point. The place mark goes to is the same place the forward-oz-expr command would move to with the same argument.

transpose-oz-exprs ARG (M-C-t)

Like the transpose-words command (M-t) but applies to balanced Oz expressions. Caveat: This might not produce nice results in all cases.

kill-oz-expr COUNT (M-C-k)

Kill the balanced Oz expression following point. With COUNT, kill that many Oz expressions after point. Negative COUNT means kill -COUNT Oz expressions before point.

backward-kill-oz-expr COUNT (M-C-DEL 1)

Kill the balanced Oz expression preceding point. With COUNT, kill that many Oz expressions before point. Negative COUNT means kill -COUNT Oz expressions after point.

oz-beginning-of-defun (M-C-a)

Move point to the start of the Oz definition it is in. If point is not inside an Oz definition, move to start of buffer. Returns t unless search stops due to beginning or end of buffer.

oz-end-of-defun (M-C-e)

Move point to the end of the Oz definition it is in. If point is not inside an Oz definition, move to end of buffer.


1. Note that under some configurations, this key combination kills the X server.

Leif Kornstaedt and Denys Duchier
Version 1.4.0 (20080702)