summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard M. Stallman <rms@gnu.org>1996-11-12 04:13:06 +0000
committerRichard M. Stallman <rms@gnu.org>1996-11-12 04:13:06 +0000
commitfc7dd8b8016f01c4deda77013971290984030c50 (patch)
treed763ecf56ac5c454049bc7597785af4db2f94bfe
parent9ee4158095d92f9f3d12ab4616bdf8c16420ecfc (diff)
downloademacs-fc7dd8b8016f01c4deda77013971290984030c50.tar.gz
(Fexpand_abbrev): If the abbrev's expansion is nil,
don't expand it, but do still call the hook. (Fdefine_abbrev): Allow anything for EXPANSION.
-rw-r--r--src/abbrev.c86
1 files changed, 48 insertions, 38 deletions
diff --git a/src/abbrev.c b/src/abbrev.c
index 240f668d090..61f053b4d46 100644
--- a/src/abbrev.c
+++ b/src/abbrev.c
@@ -104,18 +104,20 @@ DEFUN ("clear-abbrev-table", Fclear_abbrev_table, Sclear_abbrev_table, 1, 1, 0,
DEFUN ("define-abbrev", Fdefine_abbrev, Sdefine_abbrev, 3, 5, 0,
"Define an abbrev in TABLE named NAME, to expand to EXPANSION and call HOOK.\n\
-NAME and EXPANSION are strings.\n\
+NAME must be a string.\n\
+EXPANSION should usually be a string.\n\
To undefine an abbrev, define it with EXPANSION = nil.\n\
If HOOK is non-nil, it should be a function of no arguments;\n\
-it is called after EXPANSION is inserted.")
+it is called after EXPANSION is inserted.\n\
+If EXPANSION is not a string, the abbrev is a special one,\n\
+ which does not expand in the usual way but only runs HOOK.")
(table, name, expansion, hook, count)
Lisp_Object table, name, expansion, hook, count;
{
Lisp_Object sym, oexp, ohook, tem;
CHECK_VECTOR (table, 0);
CHECK_STRING (name, 1);
- if (!NILP (expansion))
- CHECK_STRING (expansion, 2);
+
if (NILP (count))
count = make_number (0);
else
@@ -289,12 +291,11 @@ Returns t if expansion took place.")
SET_PT (wordend);
Fundo_boundary ();
}
- SET_PT (wordstart);
+
Vlast_abbrev_text
= Fbuffer_substring (make_number (wordstart), make_number (wordend));
- del_range (wordstart, wordend);
- /* Now sym is the abbrev symbol. */
+ /* Now sym is the abbrev symbol. */
Vlast_abbrev = sym;
last_abbrev_point = wordstart;
@@ -302,39 +303,48 @@ Returns t if expansion took place.")
XSETINT (XSYMBOL (sym)->plist,
XINT (XSYMBOL (sym)->plist) + 1); /* Increment use count */
+ /* If this abbrev has an expansion, delete the abbrev
+ and insert the expansion. */
expansion = XSYMBOL (sym)->value;
- insert_from_string (expansion, 0, XSTRING (expansion)->size, 1);
- SET_PT (PT + whitecnt);
-
- if (uccount && !lccount)
+ if (STRINGP (expansion))
{
- /* Abbrev was all caps */
- /* If expansion is multiple words, normally capitalize each word */
- /* This used to be if (!... && ... >= ...) Fcapitalize; else Fupcase
- but Megatest 68000 compiler can't handle that */
- if (!abbrev_all_caps)
- if (scan_words (PT, -1) > scan_words (wordstart, 1))
- {
- Fupcase_initials_region (make_number (wordstart),
- make_number (PT));
- goto caped;
- }
- /* If expansion is one word, or if user says so, upcase it all. */
- Fupcase_region (make_number (wordstart), make_number (PT));
- caped: ;
- }
- else if (uccount)
- {
- /* Abbrev included some caps. Cap first initial of expansion */
- int pos = wordstart;
-
- /* Find the initial. */
- while (pos < PT
- && SYNTAX (*BUF_CHAR_ADDRESS (current_buffer, pos)) != Sword)
- pos++;
-
- /* Change just that. */
- Fupcase_initials_region (make_number (pos), make_number (pos + 1));
+ SET_PT (wordstart);
+
+ del_range (wordstart, wordend);
+
+ insert_from_string (expansion, 0, XSTRING (expansion)->size, 1);
+ SET_PT (PT + whitecnt);
+
+ if (uccount && !lccount)
+ {
+ /* Abbrev was all caps */
+ /* If expansion is multiple words, normally capitalize each word */
+ /* This used to be if (!... && ... >= ...) Fcapitalize; else Fupcase
+ but Megatest 68000 compiler can't handle that */
+ if (!abbrev_all_caps)
+ if (scan_words (PT, -1) > scan_words (wordstart, 1))
+ {
+ Fupcase_initials_region (make_number (wordstart),
+ make_number (PT));
+ goto caped;
+ }
+ /* If expansion is one word, or if user says so, upcase it all. */
+ Fupcase_region (make_number (wordstart), make_number (PT));
+ caped: ;
+ }
+ else if (uccount)
+ {
+ /* Abbrev included some caps. Cap first initial of expansion */
+ int pos = wordstart;
+
+ /* Find the initial. */
+ while (pos < PT
+ && SYNTAX (*BUF_CHAR_ADDRESS (current_buffer, pos)) != Sword)
+ pos++;
+
+ /* Change just that. */
+ Fupcase_initials_region (make_number (pos), make_number (pos + 1));
+ }
}
hook = XSYMBOL (sym)->function;