NextPrevUpTopContentsIndex

defmode

Function

Summary

Defines new editor modes.

Package

editor

Signature

defmode name &key setup-function syntax-table key-bindings no-redefine vars cleanup-function major-p transparent-p precedence => nil

Arguments

name

A string containing the name of the mode being defined.

setup-function

Name of function which sets up a buffer in this mode.

key-bindings

A quoted list of key-binding directions.

no-redefine

If t , the mode cannot be re-defined. The default value is nil .

vars

A quoted list of Editor variable definitions.

aliases

A quoted list of synonyms for name.

cleanup-function

Called upon exit from a buffer in this mode.

major-p

If t , the mode is defined as major, otherwise minor. The default value is nil .

Values

defmode returns nil .

Description

This function defines an Editor mode called name. By default, any mode defined is a minor one--specification of major-mode status is made by supplying t to the major-p argument.

defmode is essentially for the purposes of mode specification--not all of the essential definitions required to establish a new Editor mode are made in a defmode call. In the example, below, other required calls are shown.

Key-bindings can be defined by supplying a quoted list of bindings, where a binding is a list containing as a first element the (string) name of the Editor command being bound, and as the second, the key binding description (see Advanced Features, for example key-bindings).

The state of Editor variables can be changed in the definition of a mode. These are supplied as a quoted list of dotted pairs, where the first element of the pair is the (string) name of the variable to be changed, and the second is the new value.

Example

Let us define a minor mode, Foo . Foo has a set-up function, called setup-foo-mode . All files with suffix .foo invoke Foo -mode. First, the defmode call itself:

(editor:defmode "Foo" :setup-function 'setup-foo-mode)

The next piece of code makes .foo files invoke Foo -mode:

(editor:define-file-type-hook ("foo") (buffer type)
   (declare (ignore type))
   (setf (editor:buffer-minor-mode buffer "Foo") t))

The next line defines the set-up function:

(defun setup-foo-mode (buffer)
   (setf (editor:buffer-major-mode buffer) "Lisp")
   (let ((pathname (editor:buffer-pathname buffer)))
     (unless (and pathname
                (probe-file pathname))
       (editor:insert-string
         (editor:buffer-point buffer)
       #.(format nil ";;; -*- mode :foo -*-~@
                    (in-package foo)~2%")))))

Now, any files loaded into the Editor with the suffix .foo invoke the Foo minor mode.


LispWorks Editor User Guide (Windows version) - 23 Feb 2006

NextPrevUpTopContentsIndex