summaryrefslogtreecommitdiff
path: root/doc/lispref/abbrevs.texi
diff options
context:
space:
mode:
authorStefan Monnier <monnier@iro.umontreal.ca>2007-10-28 02:41:00 +0000
committerStefan Monnier <monnier@iro.umontreal.ca>2007-10-28 02:41:00 +0000
commite047f448837314fb158e0571813e79fbac677cc7 (patch)
treee14390dd2f4cb89d066b1dd1decef1d57cae8942 /doc/lispref/abbrevs.texi
parenta034393c29917271c100c3d55dff2a23ffcffeb4 (diff)
downloademacs-e047f448837314fb158e0571813e79fbac677cc7.tar.gz
emacs-e047f448837314fb158e0571813e79fbac677cc7.tar.bz2
emacs-e047f448837314fb158e0571813e79fbac677cc7.zip
Rewrite abbrev.c in Elisp.
* image.c (Qcount): Don't declare as extern. (syms_of_image): Initialize and staticpro `Qcount'. * puresize.h (BASE_PURESIZE): Increase for the new abbrev.el functions. * emacs.c (main): Don't call syms_of_abbrev. * Makefile.in (obj): Remove abbrev.o. (abbrev.o): Remove. * abbrev.c: Remove. Rewrite abbrev.c in Elisp. * abbrev.el (abbrev-mode): Move custom group from cus-edit.el. (abbrev-table-get, abbrev-table-put, abbrev-get) (abbrev-put, make-abbrev-table, abbrev-table-p, clear-abbrev-table) (define-abbrev, abbrev--check-chars, define-global-abbrev) (define-mode-abbrev, abbrev--active-tables, abbrev-symbol) (abbrev-expansion, abbrev--before-point, expand-abbrev) (unexpand-abbrev, abbrev--write, abbrev--describe) (insert-abbrev-table-description, define-abbrev-table): New funs, largely transcribed from abbrev.c. (abbrev-with-wrapper-hook): New macro. (abbrev-table-name-list, global-abbrev-table) (abbrev-minor-mode-table-alist, fundamental-mode-abbrev-table) (abbrevs-changed, abbrev-all-caps, abbrev-start-location) (abbrev-start-location-buffer, last-abbrev, last-abbrev-text) (last-abbrev-location, pre-abbrev-expand-hook, abbrev-expand-function): New vars, largely transcribed from abbrev.c. * cus-edit.el (abbrev-mode): Remove. Move to abbrev.el. * cus-start.el: Remove abbrev-all-caps and pre-abbrev-expand-hook. * loadup.el: Load "abbrev.el" before "lisp-mode.el".
Diffstat (limited to 'doc/lispref/abbrevs.texi')
-rw-r--r--doc/lispref/abbrevs.texi206
1 files changed, 154 insertions, 52 deletions
diff --git a/doc/lispref/abbrevs.texi b/doc/lispref/abbrevs.texi
index a52ba2c6c86..9ccafe2de24 100644
--- a/doc/lispref/abbrevs.texi
+++ b/doc/lispref/abbrevs.texi
@@ -47,6 +47,10 @@ Mode, emacs, The GNU Emacs Manual}.
* Files: Abbrev Files. Saving abbrevs in files.
* Expansion: Abbrev Expansion. Controlling expansion; expansion subroutines.
* Standard Abbrev Tables:: Abbrev tables used by various major modes.
+* Abbrev Properties:: How to read and set abbrev properties.
+ Which properties have which effect.
+* Abbrev Table Properties:: How to read and set abbrev table properties.
+ Which properties have which effect.
@end menu
@node Abbrev Mode, Abbrev Tables, Abbrevs, Abbrevs
@@ -75,9 +79,14 @@ This is the same as @code{(default-value 'abbrev-mode)}.
This section describes how to create and manipulate abbrev tables.
-@defun make-abbrev-table
+@defun make-abbrev-table &rest props
This function creates and returns a new, empty abbrev table---an obarray
-containing no symbols. It is a vector filled with zeros.
+containing no symbols. It is a vector filled with zeros. @var{props}
+is a property list that is applied to the new table.
+@end defun
+
+@defun abbrev-table-p table
+Return non-@code{nil} is @var{table} is an abbrev table.
@end defun
@defun clear-abbrev-table table
@@ -92,15 +101,18 @@ difference between @var{table} and the returned copy is that this
function sets the property lists of all copied abbrevs to 0.
@end defun
-@defun define-abbrev-table tabname definitions
+@defun define-abbrev-table tabname definitions &optional docstring &rest props
This function defines @var{tabname} (a symbol) as an abbrev table
name, i.e., as a variable whose value is an abbrev table. It defines
abbrevs in the table according to @var{definitions}, a list of
elements of the form @code{(@var{abbrevname} @var{expansion}
-@var{hook} @var{usecount} @var{system-flag})}. If an element of
-@var{definitions} has length less than five, omitted elements default
-to @code{nil}. A value of @code{nil} for @var{usecount} is equivalent
-to zero. The return value is always @code{nil}.
+[@var{hook}] [@var{props}...])}. These elements are passed as
+arguments to @code{define-abbrev}. The return value is always
+@code{nil}.
+
+The optional string @var{docstring} is the documentation string of the
+variable @var{tabname}. The property list @var{props} is applied to
+the abbrev table (@pxref{Abbrev Table Properties}).
If this function is called more than once for the same @var{tabname},
subsequent calls add the definitions in @var{definitions} to
@@ -132,20 +144,17 @@ to add these to @var{name} separately.)
@section Defining Abbrevs
@code{define-abbrev} is the low-level basic function for defining an
abbrev in a specified abbrev table. When major modes predefine standard
-abbrevs, they should call @code{define-abbrev} and specify @code{t} for
-@var{system-flag}. Be aware that any saved non-``system'' abbrevs are
+abbrevs, they should call @code{define-abbrev} and specify a @code{t} for
+the @code{system-flag} property.
+Be aware that any saved non-``system'' abbrevs are
restored at startup, i.e. before some major modes are loaded. Major modes
should therefore not assume that when they are first loaded their abbrev
tables are empty.
-@defun define-abbrev table name expansion &optional hook count system-flag
+@defun define-abbrev table name expansion &optional hook &rest props
This function defines an abbrev named @var{name}, in @var{table}, to
-expand to @var{expansion} and call @var{hook}. The return value is
-@var{name}.
-
-The value of @var{count}, if specified, initializes the abbrev's
-usage-count. If @var{count} is not specified or @code{nil}, the use
-count is initialized to zero.
+expand to @var{expansion} and call @var{hook}, with properties
+@var{props} (@pxref{Abbrev Properties}). The return value is @var{name}.
The argument @var{name} should be a string. The argument
@var{expansion} is normally the desired expansion (a string), or
@@ -167,12 +176,6 @@ inhibits insertion of the character. By contrast, if @var{hook}
returns @code{nil}, @code{expand-abbrev} also returns @code{nil}, as
if expansion had not really occurred.
-If @var{system-flag} is non-@code{nil}, that marks the abbrev as a
-``system'' abbrev with the @code{system-type} property. Unless
-@var{system-flag} has the value @code{force}, a ``system'' abbrev will
-not overwrite an existing definition for a non-``system'' abbrev of the
-same name.
-
Normally the function @code{define-abbrev} sets the variable
@code{abbrevs-changed} to @code{t}, if it actually changes the abbrev.
(This is so that some commands will offer to save the abbrevs.) It
@@ -329,20 +332,19 @@ has already been unexpanded. This contains information left by
@code{expand-abbrev} for the sake of the @code{unexpand-abbrev} command.
@end defvar
-@c Emacs 19 feature
-@defvar pre-abbrev-expand-hook
-This is a normal hook whose functions are executed, in sequence, just
-before any expansion of an abbrev. @xref{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 @code{expand-abbrev} does, and
-so a hook function can be used to change the current abbrev table before
-abbrev lookup happens. (Although you have to do this carefully. See
-the example below.)
+@defvar abbrev-expand-functions
+This is a special hook run @emph{around} the @code{expand-abbrev}
+function. Functions on this hook are called with a single argument
+which is a function that performs the normal abbrev expansion.
+The hook function can hence do anything it wants before and after
+performing the expansion. It can also choose not to call its argument
+and thus override the default behavior, or it may even call it
+several times. The function should return the abbrev symbol if
+expansion took place.
@end defvar
The following sample code shows a simple use of
-@code{pre-abbrev-expand-hook}. It assumes that @code{foo-mode} is a
+@code{abbrev-expand-functions}. It assumes that @code{foo-mode} is a
mode for editing certain files in which lines that start with @samp{#}
are comments. You want to use Text mode abbrevs for those lines. The
regular local abbrev table, @code{foo-mode-abbrev-table} is
@@ -351,30 +353,22 @@ in your @file{.emacs} file. @xref{Standard Abbrev Tables}, for the
definitions of @code{local-abbrev-table} and @code{text-mode-abbrev-table}.
@smallexample
-(defun foo-mode-pre-abbrev-expand ()
- (when (save-excursion (forward-line 0) (eq (char-after) ?#))
- (let ((local-abbrev-table text-mode-abbrev-table)
- ;; Avoid infinite loop.
- (pre-abbrev-expand-hook nil))
- (expand-abbrev))
- ;; We have already called `expand-abbrev' in this hook.
- ;; Hence we want the "actual" call following this hook to be a no-op.
- (setq abbrev-start-location (point-max)
- abbrev-start-location-buffer (current-buffer))))
+(defun foo-mode-abbrev-expand-function (expand)
+ (if (not (save-excursion (forward-line 0) (eq (char-after) ?#)))
+ ;; Performs normal expansion.
+ (funcall expand)
+ ;; We're inside a comment: use the text-mode abbrevs.
+ (let ((local-abbrev-table text-mode-abbrev-table))
+ (funcall expand))))
(add-hook 'foo-mode-hook
#'(lambda ()
- (add-hook 'pre-abbrev-expand-hook
- 'foo-mode-pre-abbrev-expand
+ (add-hook 'abbrev-expand-functions
+ 'foo-mode-abbrev-expand-function
nil t)))
@end smallexample
-Note that @code{foo-mode-pre-abbrev-expand} just returns @code{nil}
-without doing anything for lines not starting with @samp{#}. Hence
-abbrevs expand normally using @code{foo-mode-abbrev-table} as local
-abbrev table for such lines.
-
-@node Standard Abbrev Tables, , Abbrev Expansion, Abbrevs
+@node Standard Abbrev Tables, Abbrev Properties, Abbrev Expansion, Abbrevs
@comment node-name, next, previous, up
@section Standard Abbrev Tables
@@ -390,7 +384,16 @@ global table.
@defvar local-abbrev-table
The value of this buffer-local variable is the (mode-specific)
-abbreviation table of the current buffer.
+abbreviation table of the current buffer. It can also be a list of
+such tables.
+@end defvar
+
+@defvar abbrev-minor-mode-table-alist
+The value of this variable is a list of elements of the form
+@code{(@var{mode} . @var{abbrev-table})} where @var{mode} is the name
+of a variable: if the variable is bound to a non-@code{nil} value,
+then the @var{abbrev-table} is active, otherwise it is ignored.
+@var{abbrev-table} can also be a list of abbrev tables.
@end defvar
@defvar fundamental-mode-abbrev-table
@@ -406,6 +409,105 @@ This is the local abbrev table used in Text mode.
This is the local abbrev table used in Lisp mode and Emacs Lisp mode.
@end defvar
+@node Abbrev Properties, Abbrev Table Properties, Standard Abbrev Tables, Abbrevs
+@section Abbrev Properties
+
+Abbrevs have properties, some of which influence the way they work.
+They are usually set by providing the relevant arguments to
+@code{define-abbrev} and can be manipulated with the functions:
+
+@defun abbrev-put abbrev prop val
+Set the property @var{prop} of abbrev @var{abbrev} to value @var{val}.
+@end defun
+
+@defun abbrev-get abbrev prop
+Return the property @var{prop} of abbrev @var{abbrev}, or @code{nil}
+if the abbrev has no such property.
+@end defun
+
+The following properties have special meaning:
+
+@table @code
+@item count
+This property counts the number of times the abbrev has
+been expanded. If not explicitly set, it is initialized to 0 by
+@code{define-abbrev}.
+
+@item system-flag
+If non-@code{nil}, this property marks the abbrev as a ``system''
+abbrev. Such abbrevs will not be saved to @var{abbrev-file-name}.
+Also, unless @code{system-flag} has the value @code{force},
+a ``system'' abbrev will not overwrite an existing definition for
+a non-``system'' abbrev of the same name.
+
+@item :enable-function
+If non-@code{nil}, this property should be set to a function of no
+arguments which returns @code{nil} if the abbrev should not be used
+and @code{t} otherwise.
+
+@item :case-fixed
+If non-@code{nil}, this property indicates that the case of the
+abbrev's name is significant and should only match a text with the
+same capitalization. It also disables the code that modifies the
+capitalization of the expansion.
+
+@end table
+
+@node Abbrev Table Properties, , Abbrev Properties, Abbrevs
+@section Abbrev Table Properties
+
+Like abbrevs, abble tables have properties, some of which influence
+the way they work. They are usually set by providing the relevant
+arguments to @code{define-abbrev-table} and can be manipulated with
+the functions:
+
+@defun abbrev-table-put table prop val
+Set the property @var{prop} of abbrev table @var{table} to value @var{val}.
+@end defun
+
+@defun abbrev-table-get table prop
+Return the property @var{prop} of abbrev table @var{table}, or @code{nil}
+if the abbrev has no such property.
+@end defun
+
+The following properties have special meaning:
+
+@table @code
+@item :enable-function
+If non-@code{nil}, this property should be set to a function of no
+arguments which returns @code{nil} if the abbrev table should not be
+used and @code{t} otherwise. This is like the @code{:enable-function}
+abbrev property except that it applies to all abbrevs in the table and
+is used even before trying to find the abbrev before point.
+
+@item :case-fixed
+If non-@code{nil}, this property indicates that the case of the names
+is significant for all abbrevs in the table and should only match
+a text with the same capitalization. It also disables the code that
+modifies the capitalization of the expansion. This is like the
+@code{:case-fixed} abbrev property except that it applies to all
+abbrevs in the table.
+
+@item :regexp
+If non-@code{nil}, this property is a regular expression that
+indicates how to extract the name of the abbrev before point before
+looking it up in the table. When the regular expression matches
+before point, the abbrev name is expected to be in submatch 1.
+If this property is nil, @code{expand-function} defaults to
+@code{"\\<\\(\\w+\\)\\W"}. This property allows the use of abbrevs
+whose name contains characters of non-word syntax.
+
+@item :parents
+This property holds the list of tables from which to inherit
+other abbrevs.
+
+@item :abbrev-table-modiff
+This property holds a counter incremented each time a new abbrev is
+added to the table.
+
+@end table
+
+
@ignore
arch-tag: 5ffdbe08-2cd4-48ec-a5a8-080f95756eec
@end ignore