Next: Standard Abbrev Tables, Previous: Abbrev Files, Up: Abbrevs
Abbrevs are usually expanded by certain interactive commands,
including self-insert-command
. This section describes the
subroutines used in writing such commands, as well as the variables they
use for communication.
This function returns the symbol representing the abbrev named abbrev. The value returned is
nil
if that abbrev is not defined. The optional second argument table is the abbrev table to look it up in. If table isnil
, this function tries first the current buffer's local abbrev table, and second the global abbrev table.
This function returns the string that abbrev would expand into (as defined by the abbrev tables used for the current buffer). The optional argument table specifies the abbrev table to use, as in
abbrev-symbol
.
This command expands the abbrev before point, if any. If point does not follow an abbrev, this command does nothing. The command returns the abbrev symbol if it did expansion,
nil
otherwise.If the abbrev symbol has a hook function which is a symbol whose
no-self-insert
property is non-nil
, and if the hook function returnsnil
as its value, thenexpand-abbrev
returnsnil
even though expansion did occur.
Mark current point as the beginning of an abbrev. The next call to
expand-abbrev
will use the text from here to point (where it is then) as the abbrev to expand, rather than using the previous word as usual.
When this is set non-
nil
, an abbrev entered entirely in upper case is expanded using all upper case. Otherwise, an abbrev entered entirely in upper case is expanded by capitalizing each word of the expansion.
This is the buffer position for
expand-abbrev
to use as the start of the next abbrev to be expanded. (nil
means use the word before point instead.)abbrev-start-location
is set tonil
each timeexpand-abbrev
is called. This variable is also set byabbrev-prefix-mark
.
The value of this variable is the buffer for which
abbrev-start-location
has been set. Trying to expand an abbrev in any other buffer clearsabbrev-start-location
. This variable is set byabbrev-prefix-mark
.
This is the
abbrev-symbol
of the most recent abbrev expanded. This information is left byexpand-abbrev
for the sake of theunexpand-abbrev
command (see Expanding Abbrevs).
This is the location of the most recent abbrev expanded. This contains information left by
expand-abbrev
for the sake of theunexpand-abbrev
command.
This is the exact expansion text of the most recent abbrev expanded, after case conversion (if any). Its value is
nil
if the abbrev has already been unexpanded. This contains information left byexpand-abbrev
for the sake of theunexpand-abbrev
command.
This is a normal hook whose functions are executed, in sequence, just before any expansion of an abbrev. See Hooks. Since it is a normal hook, the hook functions receive no arguments. However, they can find the abbrev to be expanded by looking in the buffer before point. Running the hook is the first thing that
expand-abbrev
does, and so a hook function can be used to change the current abbrev table before abbrev lookup happens.
The following sample code shows a simple use of
pre-abbrev-expand-hook
. If the user terminates an abbrev with a
punctuation character, the hook function asks for confirmation. Thus,
this hook allows the user to decide whether to expand the abbrev, and
aborts expansion if it is not confirmed.
(add-hook 'pre-abbrev-expand-hook 'query-if-not-space) ;; This is the function invoked bypre-abbrev-expand-hook
. ;; If the user terminated the abbrev with a space, the function does ;; nothing (that is, it returns so that the abbrev can expand). If the ;; user entered some other character, this function asks whether ;; expansion should continue. ;; If the user answers the prompt with y, the function returns ;;nil
(because of thenot
function), but that is ;; acceptable; the return value has no effect on expansion. (defun query-if-not-space () (if (/= ?\ (preceding-char)) (if (not (y-or-n-p "Do you want to expand this abbrev? ")) (error "Not expanding this abbrev"))))