\f
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
DEFUN ("expand-abbrev", Fexpand_abbrev, Sexpand_abbrev, 0, 0, "",
"Expand the abbrev before point, if there is an abbrev there.\n\
Effective when explicitly called even when `abbrev-mode' is nil.\n\
-Returns t if expansion took place.")
+Returns the abbrev symbol, if expansion took place.")
()
{
register char *buffer, *p;
int oldmodiff = MODIFF;
Lisp_Object value;
+ value = Qnil;
+
if (!NILP (Vrun_hooks))
call1 (Vrun_hooks, Qpre_abbrev_expand_hook);
- /* If the hook changes the buffer, treat that as having "done an
- expansion". */
- value = (MODIFF != oldmodiff ? Qt : Qnil);
wordstart = 0;
- if (!(BUFFERP (Vabbrev_start_location_buffer) &&
- XBUFFER (Vabbrev_start_location_buffer) == current_buffer))
+ if (!(BUFFERP (Vabbrev_start_location_buffer)
+ && XBUFFER (Vabbrev_start_location_buffer) == current_buffer))
Vabbrev_start_location = Qnil;
if (!NILP (Vabbrev_start_location))
{
Vabbrev_start_location = Qnil;
if (wordstart < BEGV || wordstart > ZV)
wordstart = 0;
- if (wordstart && wordstart != ZV && FETCH_CHAR (wordstart) == '-')
+ if (wordstart && wordstart != ZV && FETCH_BYTE (wordstart) == '-')
del_range (wordstart, wordstart + 1);
}
if (!wordstart)
for (idx = wordstart; idx < wordend; idx++)
{
- register int c = FETCH_CHAR (idx);
+ register int c = FETCH_BYTE (idx);
if (UPPERCASEP (c))
c = DOWNCASE (c), uccount++;
else if (! NOCASEP (c))
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;
+ value = sym;
last_abbrev_point = wordstart;
if (INTEGERP (XSYMBOL (sym)->plist))
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;
if (!NILP (hook))
call0 (hook);
- return Qt;
+ return value;
}
DEFUN ("unexpand-abbrev", Funexpand_abbrev, Sunexpand_abbrev, 0, 0, "",
Fterpri (stream);
}
-DEFUN ("insert-abbrev-table-description",
- Finsert_abbrev_table_description, Sinsert_abbrev_table_description,
- 1, 2, 0,
+DEFUN ("insert-abbrev-table-description", Finsert_abbrev_table_description,
+ Sinsert_abbrev_table_description, 1, 2, 0,
"Insert before point a full description of abbrev table named NAME.\n\
NAME is a symbol whose value is an abbrev table.\n\
If optional 2nd arg READABLE is non-nil, a human-readable description\n\