Next: , Previous: , Up: Autotyping   [Contents][Index]

11 Skeleton Language

Skeletons are a shorthand extension to the Lisp language, where various atoms directly perform either actions on the current buffer or rudimentary flow control mechanisms. Skeletons are interpreted by the function skeleton-insert.

A skeleton is a list starting with an interactor, which is usually a prompt-string, or nil when not needed, but can also be a Lisp expression for complex read functions or for returning some calculated value. The rest of the list are any number of elements as described in the following table:

"string", ?c, ?\c

Insert string or character. Literal strings and characters are passed through skeleton-transformation when that is non-nil.

\n

Insert a newline and align under current line, but not if this is the last element of a skeleton and the newline would be inserted at end of line, or this is the first element and the newline would be inserted at beginning of line. Use newline character ?\n to prevent alignment. Use "\n" as the first or last string element of a skeleton to insert a newline unconditionally.

_

Interesting point. When wrapping skeletons around successive regions, they are put at these places. Point is left at first _ where nothing is wrapped.

-

Interesting point with no inter-region interaction; overrides interesting point set by _.

>

Indent line according to major mode. When following element is _, and there is an interregion that will be wrapped here, indent that interregion.

&

Logical and. If preceding element moved point, i.e., usually inserted something, do following element.

|

Logical xor. If preceding element didn’t move point, i.e., usually inserted nothing, do following element.

@

Add position to skeleton-positions.

-number

Delete preceding number characters. Depends on value of skeleton-untabify.

() or nil

Ignored.

lisp-expression

Evaluated, and the return value is again interpreted as a skeleton element.

str

A special variable that, when evaluated the first time, usually prompts for input according to the skeleton’s interactor. It is then set to the return value resulting from the interactor. Each subskeleton has its local copy of this variable.

v1, v2

Skeleton-local user variables.

'expression

Evaluate following Lisp expression for its side-effect, but prevent it from being interpreted as a skeleton element.

skeleton

Subskeletons are inserted recursively, not once, but as often as the user enters something at the subskeletons interactor. Thus there must be a str in the subskeleton. They can also be used non-interactively, when prompt is a lisp-expression that returns successive list-elements.

resume:

Ignored. Execution resumes here if the user quits during skeleton interpretation.

help

Help form during interaction with the user or nil.

input

Initial input (a string or a cons with index) while reading the input.

quit

A constant which is non-nil when the resume: section was entered because the user quit.

Some modes also use other skeleton elements they themselves defined. For example in shell script mode’s skeletons you will find < which does a rigid indentation backwards, or in CC mode’s skeletons you find the self-inserting elements { and }. These are defined by the buffer-local variable skeleton-further-elements which is a list of variables bound while interpreting a skeleton.

The macro define-skeleton defines a command for interpreting a skeleton. The first argument is the command name, the second is a documentation string, and the rest is an interactor and any number of skeleton elements together forming a skeleton. This skeleton is assigned to a variable of the same name as the command and can thus be overridden from your ~/.emacs file (see Init File in The GNU Emacs Manual).

Next: GNU Free Documentation License, Previous: “Hippie” Expansion, Up: Autotyping   [Contents][Index]