Commit e047f448 authored by Stefan Monnier's avatar Stefan Monnier

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".
parent a034393c
......@@ -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
......@@ -166,6 +166,20 @@ its usage.
* Changes in Specialized Modes and Packages in Emacs 23.1
** abbrev was rewritten in Elisp and extended with more flexibility.
*** New functions: abbrev-get, abbrev-put, abbrev-table-get, abbrev-table-put,
abbrev-table-p.
*** Special hook `abbrev-expand-functions' obsoletes `pre-abbrev-expand-hook'.
*** `make-abbrev-table', `define-abbrev', `define-abbrev-table' all take
extra arguments for arbitrary properties.
*** New variable `abbrev-minor-mode-table-alist'.
*** `local-abbrev-table' can hold a list of abbrev-tables.
*** Abbrevs have now the following special properties:
`count', `system-flag', `:enable-function', `:case-fixed'.
*** Abbrev-tables have now the following special properties:
`:parents', `:case-fixed', `:enable-function', `:regexp',
`abbrev-table-modiff'.
** isearch can now search through multiple ChangeLog files.
When running isearch in a ChangeLog file, if the search fails,
then another C-s tries searching the previous ChangeLog,
......
2007-10-28 Stefan Monnier <monnier@iro.umontreal.ca>
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".
2007-10-27 Glenn Morris <rgm@gnu.org>
* shell.el (shell-dirtrack-verbose, shell-directory-tracker): Doc fix.
......
This diff is collapsed.
......@@ -374,11 +374,6 @@
:prefix "custom-"
:group 'customize)
(defgroup abbrev-mode nil
"Word abbreviations mode."
:link '(custom-manual "(emacs)Abbrevs")
:group 'abbrev)
(defgroup alloc nil
"Storage allocation and gc for GNU Emacs Lisp interpreter."
:tag "Storage Allocation"
......
......@@ -35,10 +35,7 @@
;;; Code:
(let ((all '(;; abbrev.c
(abbrev-all-caps abbrev-mode boolean)
(pre-abbrev-expand-hook abbrev-mode hook)
;; alloc.c
(let ((all '(;; alloc.c
(gc-cons-threshold alloc integer)
(garbage-collection-messages alloc boolean)
;; buffer.c
......
......@@ -160,6 +160,7 @@
(load "textmodes/page")
(load "register")
(load "textmodes/paragraphs")
(load "abbrev") ;lisp-mode.el uses define-abbrev-table.
(load "emacs-lisp/lisp-mode")
(load "textmodes/text-mode")
(load "textmodes/fill")
......@@ -169,7 +170,6 @@
(if (eq system-type 'vax-vms)
(progn
(load "vmsproc")))
(load "abbrev")
(load "buff-menu")
(if (fboundp 'x-create-frame)
......
2007-10-28 Stefan Monnier <monnier@iro.umontreal.ca>
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.
2007-10-26 Martin Rudalics <rudalics@gmx.at>
* window.c (window_min_size_2): Don't count header-line.
......
......@@ -603,7 +603,7 @@ obj= dispnew.o frame.o scroll.o xdisp.o $(XMENU_OBJ) window.o \
cmds.o casetab.o casefiddle.o indent.o search.o regex.o undo.o \
alloc.o data.o doc.o editfns.o callint.o \
eval.o floatfns.o fns.o print.o lread.o \
abbrev.o syntax.o UNEXEC bytecode.o \
syntax.o UNEXEC bytecode.o \
process.o callproc.o \
region-cache.o sound.o atimer.o \
doprnt.o strftime.o intervals.o textprop.o composite.o md5.o \
......@@ -1094,8 +1094,6 @@ stamp-oldxmenu:
it is so often changed in ways that do not require any recompilation
and so rarely changed in ways that do require any. */
abbrev.o: abbrev.c buffer.h window.h dispextern.h commands.h charset.h \
syntax.h $(config_h)
buffer.o: buffer.c buffer.h region-cache.h commands.h window.h \
dispextern.h $(INTERVAL_SRC) blockinput.h atimer.h systime.h charset.h \
$(config_h)
......@@ -1279,7 +1277,7 @@ composite.o: composite.c buffer.h charset.h $(INTERVAL_SRC) $(config_h)
sunfns.o: sunfns.c buffer.h window.h dispextern.h termhooks.h $(config_h)
#ifdef HAVE_CARBON
abbrev.o buffer.o callint.o cmds.o dispnew.o editfns.o fileio.o frame.o \
buffer.o callint.o cmds.o dispnew.o editfns.o fileio.o frame.o \
fontset.o indent.o insdel.o keyboard.o macros.o minibuf.o msdos.o process.o \
scroll.o sysdep.o term.o terminal.o widget.o window.o xdisp.o xfaces.o xfns.o xmenu.o \
xterm.o xselect.o sound.o: macgui.h
......
This diff is collapsed.
......@@ -1543,7 +1543,6 @@ main (argc, argv
syms_of_fns ();
syms_of_floatfns ();
syms_of_abbrev ();
syms_of_buffer ();
syms_of_bytecode ();
syms_of_callint ();
......
......@@ -733,9 +733,9 @@ Lisp_Object Qxbm;
/* Keywords. */
extern Lisp_Object QCwidth, QCheight, QCforeground, QCbackground, QCfile;
extern Lisp_Object QCdata, QCtype, Qcount;
extern Lisp_Object QCdata, QCtype;
extern Lisp_Object Qcenter;
Lisp_Object QCascent, QCmargin, QCrelief;
Lisp_Object QCascent, QCmargin, QCrelief, Qcount;
Lisp_Object QCconversion, QCcolor_symbols, QCheuristic_mask;
Lisp_Object QCindex, QCmatrix, QCcolor_adjustment, QCmask;
......@@ -9089,6 +9089,9 @@ non-numeric, there is no explicit limit on the size of images. */);
define_image_type (&xbm_type, 1);
define_image_type (&pbm_type, 1);
Qcount = intern ("count");
staticpro (&Qcount);
QCascent = intern (":ascent");
staticpro (&QCascent);
QCmargin = intern (":margin");
......
......@@ -43,7 +43,7 @@ Boston, MA 02110-1301, USA. */
#endif
#ifndef BASE_PURESIZE
#define BASE_PURESIZE (1170000 + SYSTEM_PURESIZE_EXTRA + SITELOAD_PURESIZE_EXTRA)
#define BASE_PURESIZE (1180000 + SYSTEM_PURESIZE_EXTRA + SITELOAD_PURESIZE_EXTRA)
#endif
/* Increase BASE_PURESIZE by a ratio depending on the machine's word size. */
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment