aboutsummaryrefslogtreecommitdiffstats
path: root/doc
diff options
context:
space:
mode:
authorStefan Monnier2007-10-28 02:41:00 +0000
committerStefan Monnier2007-10-28 02:41:00 +0000
commite047f448837314fb158e0571813e79fbac677cc7 (patch)
treee14390dd2f4cb89d066b1dd1decef1d57cae8942 /doc
parenta034393c29917271c100c3d55dff2a23ffcffeb4 (diff)
downloademacs-e047f448837314fb158e0571813e79fbac677cc7.tar.gz
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')
-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}.
47* Files: Abbrev Files. Saving abbrevs in files. 47* Files: Abbrev Files. Saving abbrevs in files.
48* Expansion: Abbrev Expansion. Controlling expansion; expansion subroutines. 48* Expansion: Abbrev Expansion. Controlling expansion; expansion subroutines.
49* Standard Abbrev Tables:: Abbrev tables used by various major modes. 49* Standard Abbrev Tables:: Abbrev tables used by various major modes.
50* Abbrev Properties:: How to read and set abbrev properties.
51 Which properties have which effect.
52* Abbrev Table Properties:: How to read and set abbrev table properties.
53 Which properties have which effect.
50@end menu 54@end menu
51 55
52@node Abbrev Mode, Abbrev Tables, Abbrevs, Abbrevs 56@node Abbrev Mode, Abbrev Tables, Abbrevs, Abbrevs
@@ -75,9 +79,14 @@ This is the same as @code{(default-value 'abbrev-mode)}.
75 79
76 This section describes how to create and manipulate abbrev tables. 80 This section describes how to create and manipulate abbrev tables.
77 81
78@defun make-abbrev-table 82@defun make-abbrev-table &rest props
79This function creates and returns a new, empty abbrev table---an obarray 83This function creates and returns a new, empty abbrev table---an obarray
80containing no symbols. It is a vector filled with zeros. 84containing no symbols. It is a vector filled with zeros. @var{props}
85is a property list that is applied to the new table.
86@end defun
87
88@defun abbrev-table-p table
89Return non-@code{nil} is @var{table} is an abbrev table.
81@end defun 90@end defun
82 91
83@defun clear-abbrev-table table 92@defun clear-abbrev-table table
@@ -92,15 +101,18 @@ difference between @var{table} and the returned copy is that this
92function sets the property lists of all copied abbrevs to 0. 101function sets the property lists of all copied abbrevs to 0.
93@end defun 102@end defun
94 103
95@defun define-abbrev-table tabname definitions 104@defun define-abbrev-table tabname definitions &optional docstring &rest props
96This function defines @var{tabname} (a symbol) as an abbrev table 105This function defines @var{tabname} (a symbol) as an abbrev table
97name, i.e., as a variable whose value is an abbrev table. It defines 106name, i.e., as a variable whose value is an abbrev table. It defines
98abbrevs in the table according to @var{definitions}, a list of 107abbrevs in the table according to @var{definitions}, a list of
99elements of the form @code{(@var{abbrevname} @var{expansion} 108elements of the form @code{(@var{abbrevname} @var{expansion}
100@var{hook} @var{usecount} @var{system-flag})}. If an element of 109[@var{hook}] [@var{props}...])}. These elements are passed as
101@var{definitions} has length less than five, omitted elements default 110arguments to @code{define-abbrev}. The return value is always
102to @code{nil}. A value of @code{nil} for @var{usecount} is equivalent 111@code{nil}.
103to zero. The return value is always @code{nil}. 112
113The optional string @var{docstring} is the documentation string of the
114variable @var{tabname}. The property list @var{props} is applied to
115the abbrev table (@pxref{Abbrev Table Properties}).
104 116
105If this function is called more than once for the same @var{tabname}, 117If this function is called more than once for the same @var{tabname},
106subsequent calls add the definitions in @var{definitions} to 118subsequent calls add the definitions in @var{definitions} to
@@ -132,20 +144,17 @@ to add these to @var{name} separately.)
132@section Defining Abbrevs 144@section Defining Abbrevs
133 @code{define-abbrev} is the low-level basic function for defining an 145 @code{define-abbrev} is the low-level basic function for defining an
134abbrev in a specified abbrev table. When major modes predefine standard 146abbrev in a specified abbrev table. When major modes predefine standard
135abbrevs, they should call @code{define-abbrev} and specify @code{t} for 147abbrevs, they should call @code{define-abbrev} and specify a @code{t} for
136@var{system-flag}. Be aware that any saved non-``system'' abbrevs are 148the @code{system-flag} property.
149Be aware that any saved non-``system'' abbrevs are
137restored at startup, i.e. before some major modes are loaded. Major modes 150restored at startup, i.e. before some major modes are loaded. Major modes
138should therefore not assume that when they are first loaded their abbrev 151should therefore not assume that when they are first loaded their abbrev
139tables are empty. 152tables are empty.
140 153
141@defun define-abbrev table name expansion &optional hook count system-flag 154@defun define-abbrev table name expansion &optional hook &rest props
142This function defines an abbrev named @var{name}, in @var{table}, to 155This function defines an abbrev named @var{name}, in @var{table}, to
143expand to @var{expansion} and call @var{hook}. The return value is 156expand to @var{expansion} and call @var{hook}, with properties
144@var{name}. 157@var{props} (@pxref{Abbrev Properties}). The return value is @var{name}.
145
146The value of @var{count}, if specified, initializes the abbrev's
147usage-count. If @var{count} is not specified or @code{nil}, the use
148count is initialized to zero.
149 158
150The argument @var{name} should be a string. The argument 159The argument @var{name} should be a string. The argument
151@var{expansion} is normally the desired expansion (a string), or 160@var{expansion} is normally the desired expansion (a string), or
@@ -167,12 +176,6 @@ inhibits insertion of the character. By contrast, if @var{hook}
167returns @code{nil}, @code{expand-abbrev} also returns @code{nil}, as 176returns @code{nil}, @code{expand-abbrev} also returns @code{nil}, as
168if expansion had not really occurred. 177if expansion had not really occurred.
169 178
170If @var{system-flag} is non-@code{nil}, that marks the abbrev as a
171``system'' abbrev with the @code{system-type} property. Unless
172@var{system-flag} has the value @code{force}, a ``system'' abbrev will
173not overwrite an existing definition for a non-``system'' abbrev of the
174same name.
175
176Normally the function @code{define-abbrev} sets the variable 179Normally the function @code{define-abbrev} sets the variable
177@code{abbrevs-changed} to @code{t}, if it actually changes the abbrev. 180@code{abbrevs-changed} to @code{t}, if it actually changes the abbrev.
178(This is so that some commands will offer to save the abbrevs.) It 181(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
329@code{expand-abbrev} for the sake of the @code{unexpand-abbrev} command. 332@code{expand-abbrev} for the sake of the @code{unexpand-abbrev} command.
330@end defvar 333@end defvar
331 334
332@c Emacs 19 feature 335@defvar abbrev-expand-functions
333@defvar pre-abbrev-expand-hook 336This is a special hook run @emph{around} the @code{expand-abbrev}
334This is a normal hook whose functions are executed, in sequence, just 337function. Functions on this hook are called with a single argument
335before any expansion of an abbrev. @xref{Hooks}. Since it is a normal 338which is a function that performs the normal abbrev expansion.
336hook, the hook functions receive no arguments. However, they can find 339The hook function can hence do anything it wants before and after
337the abbrev to be expanded by looking in the buffer before point. 340performing the expansion. It can also choose not to call its argument
338Running the hook is the first thing that @code{expand-abbrev} does, and 341and thus override the default behavior, or it may even call it
339so a hook function can be used to change the current abbrev table before 342several times. The function should return the abbrev symbol if
340abbrev lookup happens. (Although you have to do this carefully. See 343expansion took place.
341the example below.)
342@end defvar 344@end defvar
343 345
344 The following sample code shows a simple use of 346 The following sample code shows a simple use of
345@code{pre-abbrev-expand-hook}. It assumes that @code{foo-mode} is a 347@code{abbrev-expand-functions}. It assumes that @code{foo-mode} is a
346mode for editing certain files in which lines that start with @samp{#} 348mode for editing certain files in which lines that start with @samp{#}
347are comments. You want to use Text mode abbrevs for those lines. The 349are comments. You want to use Text mode abbrevs for those lines. The
348regular local abbrev table, @code{foo-mode-abbrev-table} is 350regular local abbrev table, @code{foo-mode-abbrev-table} is
@@ -351,30 +353,22 @@ in your @file{.emacs} file. @xref{Standard Abbrev Tables}, for the
351definitions of @code{local-abbrev-table} and @code{text-mode-abbrev-table}. 353definitions of @code{local-abbrev-table} and @code{text-mode-abbrev-table}.
352 354
353@smallexample 355@smallexample
354(defun foo-mode-pre-abbrev-expand () 356(defun foo-mode-abbrev-expand-function (expand)
355 (when (save-excursion (forward-line 0) (eq (char-after) ?#)) 357 (if (not (save-excursion (forward-line 0) (eq (char-after) ?#)))
356 (let ((local-abbrev-table text-mode-abbrev-table) 358 ;; Performs normal expansion.
357 ;; Avoid infinite loop. 359 (funcall expand)
358 (pre-abbrev-expand-hook nil)) 360 ;; We're inside a comment: use the text-mode abbrevs.
359 (expand-abbrev)) 361 (let ((local-abbrev-table text-mode-abbrev-table))
360 ;; We have already called `expand-abbrev' in this hook. 362 (funcall expand))))
361 ;; Hence we want the "actual" call following this hook to be a no-op.
362 (setq abbrev-start-location (point-max)
363 abbrev-start-location-buffer (current-buffer))))
364 363
365(add-hook 'foo-mode-hook 364(add-hook 'foo-mode-hook
366 #'(lambda () 365 #'(lambda ()
367 (add-hook 'pre-abbrev-expand-hook 366 (add-hook 'abbrev-expand-functions
368 'foo-mode-pre-abbrev-expand 367 'foo-mode-abbrev-expand-function
369 nil t))) 368 nil t)))
370@end smallexample 369@end smallexample
371 370
372Note that @code{foo-mode-pre-abbrev-expand} just returns @code{nil} 371@node Standard Abbrev Tables, Abbrev Properties, Abbrev Expansion, Abbrevs
373without doing anything for lines not starting with @samp{#}. Hence
374abbrevs expand normally using @code{foo-mode-abbrev-table} as local
375abbrev table for such lines.
376
377@node Standard Abbrev Tables, , Abbrev Expansion, Abbrevs
378@comment node-name, next, previous, up 372@comment node-name, next, previous, up
379@section Standard Abbrev Tables 373@section Standard Abbrev Tables
380 374
@@ -390,7 +384,16 @@ global table.
390 384
391@defvar local-abbrev-table 385@defvar local-abbrev-table
392The value of this buffer-local variable is the (mode-specific) 386The value of this buffer-local variable is the (mode-specific)
393abbreviation table of the current buffer. 387abbreviation table of the current buffer. It can also be a list of
388such tables.
389@end defvar
390
391@defvar abbrev-minor-mode-table-alist
392The value of this variable is a list of elements of the form
393@code{(@var{mode} . @var{abbrev-table})} where @var{mode} is the name
394of a variable: if the variable is bound to a non-@code{nil} value,
395then the @var{abbrev-table} is active, otherwise it is ignored.
396@var{abbrev-table} can also be a list of abbrev tables.
394@end defvar 397@end defvar
395 398
396@defvar fundamental-mode-abbrev-table 399@defvar fundamental-mode-abbrev-table
@@ -406,6 +409,105 @@ This is the local abbrev table used in Text mode.
406This is the local abbrev table used in Lisp mode and Emacs Lisp mode. 409This is the local abbrev table used in Lisp mode and Emacs Lisp mode.
407@end defvar 410@end defvar
408 411
412@node Abbrev Properties, Abbrev Table Properties, Standard Abbrev Tables, Abbrevs
413@section Abbrev Properties
414
415Abbrevs have properties, some of which influence the way they work.
416They are usually set by providing the relevant arguments to
417@code{define-abbrev} and can be manipulated with the functions:
418
419@defun abbrev-put abbrev prop val
420Set the property @var{prop} of abbrev @var{abbrev} to value @var{val}.
421@end defun
422
423@defun abbrev-get abbrev prop
424Return the property @var{prop} of abbrev @var{abbrev}, or @code{nil}
425if the abbrev has no such property.
426@end defun
427
428The following properties have special meaning:
429
430@table @code
431@item count
432This property counts the number of times the abbrev has
433been expanded. If not explicitly set, it is initialized to 0 by
434@code{define-abbrev}.
435
436@item system-flag
437If non-@code{nil}, this property marks the abbrev as a ``system''
438abbrev. Such abbrevs will not be saved to @var{abbrev-file-name}.
439Also, unless @code{system-flag} has the value @code{force},
440a ``system'' abbrev will not overwrite an existing definition for
441a non-``system'' abbrev of the same name.
442
443@item :enable-function
444If non-@code{nil}, this property should be set to a function of no
445arguments which returns @code{nil} if the abbrev should not be used
446and @code{t} otherwise.
447
448@item :case-fixed
449If non-@code{nil}, this property indicates that the case of the
450abbrev's name is significant and should only match a text with the
451same capitalization. It also disables the code that modifies the
452capitalization of the expansion.
453
454@end table
455
456@node Abbrev Table Properties, , Abbrev Properties, Abbrevs
457@section Abbrev Table Properties
458
459Like abbrevs, abble tables have properties, some of which influence
460the way they work. They are usually set by providing the relevant
461arguments to @code{define-abbrev-table} and can be manipulated with
462the functions:
463
464@defun abbrev-table-put table prop val
465Set the property @var{prop} of abbrev table @var{table} to value @var{val}.
466@end defun
467
468@defun abbrev-table-get table prop
469Return the property @var{prop} of abbrev table @var{table}, or @code{nil}
470if the abbrev has no such property.
471@end defun
472
473The following properties have special meaning:
474
475@table @code
476@item :enable-function
477If non-@code{nil}, this property should be set to a function of no
478arguments which returns @code{nil} if the abbrev table should not be
479used and @code{t} otherwise. This is like the @code{:enable-function}
480abbrev property except that it applies to all abbrevs in the table and
481is used even before trying to find the abbrev before point.
482
483@item :case-fixed
484If non-@code{nil}, this property indicates that the case of the names
485is significant for all abbrevs in the table and should only match
486a text with the same capitalization. It also disables the code that
487modifies the capitalization of the expansion. This is like the
488@code{:case-fixed} abbrev property except that it applies to all
489abbrevs in the table.
490
491@item :regexp
492If non-@code{nil}, this property is a regular expression that
493indicates how to extract the name of the abbrev before point before
494looking it up in the table. When the regular expression matches
495before point, the abbrev name is expected to be in submatch 1.
496If this property is nil, @code{expand-function} defaults to
497@code{"\\<\\(\\w+\\)\\W"}. This property allows the use of abbrevs
498whose name contains characters of non-word syntax.
499
500@item :parents
501This property holds the list of tables from which to inherit
502other abbrevs.
503
504@item :abbrev-table-modiff
505This property holds a counter incremented each time a new abbrev is
506added to the table.
507
508@end table
509
510
409@ignore 511@ignore
410 arch-tag: 5ffdbe08-2cd4-48ec-a5a8-080f95756eec 512 arch-tag: 5ffdbe08-2cd4-48ec-a5a8-080f95756eec
411@end ignore 513@end ignore