diff options
| author | Stefan Monnier | 2007-10-28 02:41:00 +0000 |
|---|---|---|
| committer | Stefan Monnier | 2007-10-28 02:41:00 +0000 |
| commit | e047f448837314fb158e0571813e79fbac677cc7 (patch) | |
| tree | e14390dd2f4cb89d066b1dd1decef1d57cae8942 /doc | |
| parent | a034393c29917271c100c3d55dff2a23ffcffeb4 (diff) | |
| download | emacs-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.texi | 206 |
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 |
| 79 | This function creates and returns a new, empty abbrev table---an obarray | 83 | This function creates and returns a new, empty abbrev table---an obarray |
| 80 | containing no symbols. It is a vector filled with zeros. | 84 | containing no symbols. It is a vector filled with zeros. @var{props} |
| 85 | is a property list that is applied to the new table. | ||
| 86 | @end defun | ||
| 87 | |||
| 88 | @defun abbrev-table-p table | ||
| 89 | Return 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 | |||
| 92 | function sets the property lists of all copied abbrevs to 0. | 101 | function 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 |
| 96 | This function defines @var{tabname} (a symbol) as an abbrev table | 105 | This function defines @var{tabname} (a symbol) as an abbrev table |
| 97 | name, i.e., as a variable whose value is an abbrev table. It defines | 106 | name, i.e., as a variable whose value is an abbrev table. It defines |
| 98 | abbrevs in the table according to @var{definitions}, a list of | 107 | abbrevs in the table according to @var{definitions}, a list of |
| 99 | elements of the form @code{(@var{abbrevname} @var{expansion} | 108 | elements 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 | 110 | arguments to @code{define-abbrev}. The return value is always |
| 102 | to @code{nil}. A value of @code{nil} for @var{usecount} is equivalent | 111 | @code{nil}. |
| 103 | to zero. The return value is always @code{nil}. | 112 | |
| 113 | The optional string @var{docstring} is the documentation string of the | ||
| 114 | variable @var{tabname}. The property list @var{props} is applied to | ||
| 115 | the abbrev table (@pxref{Abbrev Table Properties}). | ||
| 104 | 116 | ||
| 105 | If this function is called more than once for the same @var{tabname}, | 117 | If this function is called more than once for the same @var{tabname}, |
| 106 | subsequent calls add the definitions in @var{definitions} to | 118 | subsequent 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 |
| 134 | abbrev in a specified abbrev table. When major modes predefine standard | 146 | abbrev in a specified abbrev table. When major modes predefine standard |
| 135 | abbrevs, they should call @code{define-abbrev} and specify @code{t} for | 147 | abbrevs, 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 | 148 | the @code{system-flag} property. |
| 149 | Be aware that any saved non-``system'' abbrevs are | ||
| 137 | restored at startup, i.e. before some major modes are loaded. Major modes | 150 | restored at startup, i.e. before some major modes are loaded. Major modes |
| 138 | should therefore not assume that when they are first loaded their abbrev | 151 | should therefore not assume that when they are first loaded their abbrev |
| 139 | tables are empty. | 152 | tables 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 |
| 142 | This function defines an abbrev named @var{name}, in @var{table}, to | 155 | This function defines an abbrev named @var{name}, in @var{table}, to |
| 143 | expand to @var{expansion} and call @var{hook}. The return value is | 156 | expand 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 | |||
| 146 | The value of @var{count}, if specified, initializes the abbrev's | ||
| 147 | usage-count. If @var{count} is not specified or @code{nil}, the use | ||
| 148 | count is initialized to zero. | ||
| 149 | 158 | ||
| 150 | The argument @var{name} should be a string. The argument | 159 | The 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} | |||
| 167 | returns @code{nil}, @code{expand-abbrev} also returns @code{nil}, as | 176 | returns @code{nil}, @code{expand-abbrev} also returns @code{nil}, as |
| 168 | if expansion had not really occurred. | 177 | if expansion had not really occurred. |
| 169 | 178 | ||
| 170 | If @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 | ||
| 173 | not overwrite an existing definition for a non-``system'' abbrev of the | ||
| 174 | same name. | ||
| 175 | |||
| 176 | Normally the function @code{define-abbrev} sets the variable | 179 | Normally 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 | 336 | This is a special hook run @emph{around} the @code{expand-abbrev} |
| 334 | This is a normal hook whose functions are executed, in sequence, just | 337 | function. Functions on this hook are called with a single argument |
| 335 | before any expansion of an abbrev. @xref{Hooks}. Since it is a normal | 338 | which is a function that performs the normal abbrev expansion. |
| 336 | hook, the hook functions receive no arguments. However, they can find | 339 | The hook function can hence do anything it wants before and after |
| 337 | the abbrev to be expanded by looking in the buffer before point. | 340 | performing the expansion. It can also choose not to call its argument |
| 338 | Running the hook is the first thing that @code{expand-abbrev} does, and | 341 | and thus override the default behavior, or it may even call it |
| 339 | so a hook function can be used to change the current abbrev table before | 342 | several times. The function should return the abbrev symbol if |
| 340 | abbrev lookup happens. (Although you have to do this carefully. See | 343 | expansion took place. |
| 341 | the 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 |
| 346 | mode for editing certain files in which lines that start with @samp{#} | 348 | mode for editing certain files in which lines that start with @samp{#} |
| 347 | are comments. You want to use Text mode abbrevs for those lines. The | 349 | are comments. You want to use Text mode abbrevs for those lines. The |
| 348 | regular local abbrev table, @code{foo-mode-abbrev-table} is | 350 | 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 | |||
| 351 | definitions of @code{local-abbrev-table} and @code{text-mode-abbrev-table}. | 353 | definitions 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 | ||
| 372 | Note that @code{foo-mode-pre-abbrev-expand} just returns @code{nil} | 371 | @node Standard Abbrev Tables, Abbrev Properties, Abbrev Expansion, Abbrevs |
| 373 | without doing anything for lines not starting with @samp{#}. Hence | ||
| 374 | abbrevs expand normally using @code{foo-mode-abbrev-table} as local | ||
| 375 | abbrev 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 |
| 392 | The value of this buffer-local variable is the (mode-specific) | 386 | The value of this buffer-local variable is the (mode-specific) |
| 393 | abbreviation table of the current buffer. | 387 | abbreviation table of the current buffer. It can also be a list of |
| 388 | such tables. | ||
| 389 | @end defvar | ||
| 390 | |||
| 391 | @defvar abbrev-minor-mode-table-alist | ||
| 392 | The 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 | ||
| 394 | of a variable: if the variable is bound to a non-@code{nil} value, | ||
| 395 | then 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. | |||
| 406 | This is the local abbrev table used in Lisp mode and Emacs Lisp mode. | 409 | This 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 | |||
| 415 | Abbrevs have properties, some of which influence the way they work. | ||
| 416 | They 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 | ||
| 420 | Set the property @var{prop} of abbrev @var{abbrev} to value @var{val}. | ||
| 421 | @end defun | ||
| 422 | |||
| 423 | @defun abbrev-get abbrev prop | ||
| 424 | Return the property @var{prop} of abbrev @var{abbrev}, or @code{nil} | ||
| 425 | if the abbrev has no such property. | ||
| 426 | @end defun | ||
| 427 | |||
| 428 | The following properties have special meaning: | ||
| 429 | |||
| 430 | @table @code | ||
| 431 | @item count | ||
| 432 | This property counts the number of times the abbrev has | ||
| 433 | been expanded. If not explicitly set, it is initialized to 0 by | ||
| 434 | @code{define-abbrev}. | ||
| 435 | |||
| 436 | @item system-flag | ||
| 437 | If non-@code{nil}, this property marks the abbrev as a ``system'' | ||
| 438 | abbrev. Such abbrevs will not be saved to @var{abbrev-file-name}. | ||
| 439 | Also, unless @code{system-flag} has the value @code{force}, | ||
| 440 | a ``system'' abbrev will not overwrite an existing definition for | ||
| 441 | a non-``system'' abbrev of the same name. | ||
| 442 | |||
| 443 | @item :enable-function | ||
| 444 | If non-@code{nil}, this property should be set to a function of no | ||
| 445 | arguments which returns @code{nil} if the abbrev should not be used | ||
| 446 | and @code{t} otherwise. | ||
| 447 | |||
| 448 | @item :case-fixed | ||
| 449 | If non-@code{nil}, this property indicates that the case of the | ||
| 450 | abbrev's name is significant and should only match a text with the | ||
| 451 | same capitalization. It also disables the code that modifies the | ||
| 452 | capitalization of the expansion. | ||
| 453 | |||
| 454 | @end table | ||
| 455 | |||
| 456 | @node Abbrev Table Properties, , Abbrev Properties, Abbrevs | ||
| 457 | @section Abbrev Table Properties | ||
| 458 | |||
| 459 | Like abbrevs, abble tables have properties, some of which influence | ||
| 460 | the way they work. They are usually set by providing the relevant | ||
| 461 | arguments to @code{define-abbrev-table} and can be manipulated with | ||
| 462 | the functions: | ||
| 463 | |||
| 464 | @defun abbrev-table-put table prop val | ||
| 465 | Set the property @var{prop} of abbrev table @var{table} to value @var{val}. | ||
| 466 | @end defun | ||
| 467 | |||
| 468 | @defun abbrev-table-get table prop | ||
| 469 | Return the property @var{prop} of abbrev table @var{table}, or @code{nil} | ||
| 470 | if the abbrev has no such property. | ||
| 471 | @end defun | ||
| 472 | |||
| 473 | The following properties have special meaning: | ||
| 474 | |||
| 475 | @table @code | ||
| 476 | @item :enable-function | ||
| 477 | If non-@code{nil}, this property should be set to a function of no | ||
| 478 | arguments which returns @code{nil} if the abbrev table should not be | ||
| 479 | used and @code{t} otherwise. This is like the @code{:enable-function} | ||
| 480 | abbrev property except that it applies to all abbrevs in the table and | ||
| 481 | is used even before trying to find the abbrev before point. | ||
| 482 | |||
| 483 | @item :case-fixed | ||
| 484 | If non-@code{nil}, this property indicates that the case of the names | ||
| 485 | is significant for all abbrevs in the table and should only match | ||
| 486 | a text with the same capitalization. It also disables the code that | ||
| 487 | modifies the capitalization of the expansion. This is like the | ||
| 488 | @code{:case-fixed} abbrev property except that it applies to all | ||
| 489 | abbrevs in the table. | ||
| 490 | |||
| 491 | @item :regexp | ||
| 492 | If non-@code{nil}, this property is a regular expression that | ||
| 493 | indicates how to extract the name of the abbrev before point before | ||
| 494 | looking it up in the table. When the regular expression matches | ||
| 495 | before point, the abbrev name is expected to be in submatch 1. | ||
| 496 | If this property is nil, @code{expand-function} defaults to | ||
| 497 | @code{"\\<\\(\\w+\\)\\W"}. This property allows the use of abbrevs | ||
| 498 | whose name contains characters of non-word syntax. | ||
| 499 | |||
| 500 | @item :parents | ||
| 501 | This property holds the list of tables from which to inherit | ||
| 502 | other abbrevs. | ||
| 503 | |||
| 504 | @item :abbrev-table-modiff | ||
| 505 | This property holds a counter incremented each time a new abbrev is | ||
| 506 | added 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 |