All Manuals > Editor User Guide > 3 Command Reference

3.26 Modes

A buffer can be in two kinds of mode at once: major and minor. The following two sections give a description of each, along with details of some commands which alter the modes.

In most cases, the current buffer can be put in a certain mode using the mode name as an Editor Command.

3.26.1 Major modes

The major modes govern how certain commands behave and how text is displayed. Major modes adapt a few editor commands so that their use is more appropriate to the text being edited. Some movement commands are affected by the major mode, as word, sentence, and paragraph delimiters vary with the mode. Indentation commands are very much affected by the major mode (see 3.18 Indentation).

Major modes available in the LispWorks editor are as follows:

The major mode of most buffers may be altered explicitly by using the commands described below.

By default, Lisp mode is the major mode whenever you edit a file with type lisp (as with several other file types). If you have Lisp source code in files with another file type foo, put a form like this in your .lispworks file, adding your file extension to the default set:

(editor:define-file-type-hook 
    ("lispworks" "lisp" "slisp" "l" "lsp" "mcl" "cl" "foo")
    (buffer type)
  (declare (ignore type))
  (setf (editor:buffer-major-mode buffer) "Lisp"))

Fundamental Mode Editor Command

Arguments: None
Key sequence: None

Puts the current buffer into Fundamental mode.

Text Mode Editor Command

Arguments: None
Key sequence: None

Puts the current buffer into Text mode.

Lisp Mode Editor Command

Arguments: None
Key sequence: None

Puts the current buffer into Lisp mode. Notice how syntax coloring is used for Lisp symbols. Also the balanced parentheses delimiting a Lisp form at or immediately preceding the cursor are highlighted, by default in green.

3.26.2 Minor modes

The minor modes determine whether or not certain actions take place. Buffers may be in any number of minor modes. No command details are given here as they are covered in other sections of the manuals.

Minor modes available in the LispWorks editor are as follows:

3.26.3 Default modes

default-modes Editor Variable

Default value: ("Fundamental")

This editor variable contains the default list of modes for new buffers.

3.26.4 Defining modes

New modes can be defined using the defmode function.

editor:defmode Function

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

Defines a new editor mode called name.

name is a string containing the name of the mode being defined. setup-function is a function which sets up a buffer in this mode. key-bindings is a quoted list of key-binding directions. no-redefine is a boolean: if true, the mode cannot be re-defined. The default value of no-redefine is nil. vars is a quoted list of editor variables and values. aliases is a quoted list of synonyms for name. cleanup-function is a function which is called upon exit from a buffer in this mode. major-p is a boolean: if true, the mode is defined as major, otherwise minor. The default value of major-p is nil.

By default, any mode defined is a minor one—specification of major-mode status is made by supplying a true value for major-p.

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 6 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 vars of dotted pairs, where the first element of the pair is the (symbol) name of the editor variable to be changed, and the second is the new value.

Both setup-function and cleanup-function are called with the mode and the buffer locked. They can modify the buffer itself, but they must not wait for anything that happens on another process, and they must not modify the mode (for example by setting a variable in the mode), and must not try to update the display.

As an example tet us define a minor mode, Foo. Foo has a set-up function, called setup-foo-mode. All files with suffix .foo invoke Foo-mode.

Here is the defmode form:

(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 form 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 -*-~2%(in-package \"CL-USER\")~2%")))))

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


Editor User Guide (Windows version) - 01 Dec 2021 19:35:26