aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuc Teirlinck2004-08-28 00:41:31 +0000
committerLuc Teirlinck2004-08-28 00:41:31 +0000
commit73b740878793bf03550e29d3be459c2cbc5fb80f (patch)
tree62b7bbaa8aa9c9ffae7942afc7cbb73ba54571c9
parent9933ae48747f32b48be6a50a9d2c09213da5da78 (diff)
downloademacs-73b740878793bf03550e29d3be459c2cbc5fb80f.tar.gz
emacs-73b740878793bf03550e29d3be459c2cbc5fb80f.zip
(Abbrev Expansion): `abbrev-start-location' can be an integer or a marker.
(Abbrev Expansion): Replace example for `pre-abbrev-expand-hook'.
-rw-r--r--lispref/abbrevs.texi53
1 files changed, 32 insertions, 21 deletions
diff --git a/lispref/abbrevs.texi b/lispref/abbrevs.texi
index d586d0bbc13..1f873312222 100644
--- a/lispref/abbrevs.texi
+++ b/lispref/abbrevs.texi
@@ -1,6 +1,6 @@
1@c -*-texinfo-*- 1@c -*-texinfo-*-
2@c This is part of the GNU Emacs Lisp Reference Manual. 2@c This is part of the GNU Emacs Lisp Reference Manual.
3@c Copyright (C) 1990, 1991, 1992, 1993, 1994, 1999 3@c Copyright (C) 1990, 1991, 1992, 1993, 1994, 1999, 2004
4@c Free Software Foundation, Inc. 4@c Free Software Foundation, Inc.
5@c See the file elisp.texi for copying conditions. 5@c See the file elisp.texi for copying conditions.
6@setfilename ../info/abbrevs 6@setfilename ../info/abbrevs
@@ -288,7 +288,7 @@ expansion.
288@end defopt 288@end defopt
289 289
290@defvar abbrev-start-location 290@defvar abbrev-start-location
291The value of this variable is a marker pointing to the buffer position 291The value of this variable is a buffer position (an integer or a marker)
292for @code{expand-abbrev} to use as the start of the next abbrev to be 292for @code{expand-abbrev} to use as the start of the next abbrev to be
293expanded. The value can also be @code{nil}, which means to use the 293expanded. The value can also be @code{nil}, which means to use the
294word before point instead. @code{abbrev-start-location} is set to 294word before point instead. @code{abbrev-start-location} is set to
@@ -331,32 +331,43 @@ hook, the hook functions receive no arguments. However, they can find
331the abbrev to be expanded by looking in the buffer before point. 331the abbrev to be expanded by looking in the buffer before point.
332Running the hook is the first thing that @code{expand-abbrev} does, and 332Running the hook is the first thing that @code{expand-abbrev} does, and
333so a hook function can be used to change the current abbrev table before 333so a hook function can be used to change the current abbrev table before
334abbrev lookup happens. 334abbrev lookup happens. (Although you have to do this carefully. See
335the example below.)
335@end defvar 336@end defvar
336 337
337 The following sample code shows a simple use of 338 The following sample code shows a simple use of
338@code{pre-abbrev-expand-hook}. If the user terminates an abbrev with 339@code{pre-abbrev-expand-hook}. It assumes that @code{foo-mode} is a
339a punctuation character, the hook function asks for confirmation. It 340mode for editing certain files in which lines that start with @samp{#}
340aborts expansion if the user does not confirm. 341are comments. You want to use Text mode abbrevs for those lines. The
342regular local abbrev table, @code{foo-mode-abbrev-table} is
343appropriate for all other lines. Then you can put the following code
344in your @file{.emacs} file. @xref{Standard Abbrev Tables}, for the
345definitions of @code{local-abbrev-table} and @code{text-mode-abbrev-table}.
341 346
342@smallexample 347@smallexample
343(add-hook 'pre-abbrev-expand-hook 'query-if-not-space) 348(defun foo-mode-pre-abbrev-expand ()
344 349 (when (save-excursion (forward-line 0) (eq (char-after) ?#))
345;; @r{This is the function invoked by @code{pre-abbrev-expand-hook}.} 350 (let ((local-abbrev-table text-mode-abbrev-table)
346 351 ;; Avoid infinite loop.
347;; @r{If the user terminated the abbrev with a space, the function does} 352 (pre-abbrev-expand-hook nil))
348;; @r{nothing (that is, it returns so that the abbrev can expand). If the} 353 (expand-abbrev))
349;; @r{user entered some other character, this function asks whether} 354 ;; We have already called `expand-abbrev' in this hook.
350;; @r{expansion should continue.} 355 ;; Hence we want the "actual" call following this hook to be a no-op.
351 356 (setq abbrev-start-location (point-max)
352;; @r{The function's return value makes no difference.} 357 abbrev-start-location-buffer (current-buffer))))
353 358
354(defun query-if-not-space () 359(add-hook 'foo-mode-hook
355 (if (/= ?\s last-command-char) 360 #'(lambda ()
356 (if (not (y-or-n-p "Do you want to expand this abbrev? ")) 361 (add-hook 'pre-abbrev-expand-hook
357 (error "Not expanding this abbrev")))) 362 'foo-mode-pre-abbrev-expand
363 nil t)))
358@end smallexample 364@end smallexample
359 365
366Note that @code{foo-mode-pre-abbrex-expand} just returns @code{nil}
367without doing anything for lines not starting with @samp{#}. Hence
368abbrevs expand normally using @code{foo-mode-abbrev-table} as local
369abbrev table for such lines.
370
360@node Standard Abbrev Tables, , Abbrev Expansion, Abbrevs 371@node Standard Abbrev Tables, , Abbrev Expansion, Abbrevs
361@comment node-name, next, previous, up 372@comment node-name, next, previous, up
362@section Standard Abbrev Tables 373@section Standard Abbrev Tables