335 |
@end defvar |
@end defvar |
336 |
|
|
337 |
The following sample code shows a simple use of |
The following sample code shows a simple use of |
338 |
@code{pre-abbrev-expand-hook}. If the user terminates an abbrev with a |
@code{pre-abbrev-expand-hook}. If the user terminates an abbrev with |
339 |
punctuation character, the hook function asks for confirmation. Thus, |
a punctuation character, the hook function asks for confirmation. It |
340 |
this hook allows the user to decide whether to expand the abbrev, and |
aborts expansion if the user does not confirm. |
|
aborts expansion if it is not confirmed. |
|
341 |
|
|
342 |
@smallexample |
@smallexample |
343 |
(add-hook 'pre-abbrev-expand-hook 'query-if-not-space) |
(add-hook 'pre-abbrev-expand-hook 'query-if-not-space) |
349 |
;; @r{user entered some other character, this function asks whether} |
;; @r{user entered some other character, this function asks whether} |
350 |
;; @r{expansion should continue.} |
;; @r{expansion should continue.} |
351 |
|
|
352 |
;; @r{If the user answers the prompt with @kbd{y}, the function returns} |
;; @r{The function's return value makes no difference.} |
|
;; @r{@code{nil} (because of the @code{not} function), but that is} |
|
|
;; @r{acceptable; the return value has no effect on expansion.} |
|
353 |
|
|
354 |
(defun query-if-not-space () |
(defun query-if-not-space () |
355 |
(if (/= ?\s (preceding-char)) |
(if (/= ?\s last-command-char) |
356 |
(if (not (y-or-n-p "Do you want to expand this abbrev? ")) |
(if (not (y-or-n-p "Do you want to expand this abbrev? ")) |
357 |
(error "Not expanding this abbrev")))) |
(error "Not expanding this abbrev")))) |
358 |
@end smallexample |
@end smallexample |