Change doc-string comments to `new style' [w/`doc:' keyword].
[bpt/emacs.git] / src / abbrev.c
CommitLineData
7942b8ae 1/* Primitives for word-abbrev mode.
a97569cb
GM
2 Copyright (C) 1985, 1986, 1993, 1996, 1998, 2001
3 Free Software Foundation, Inc.
7942b8ae
RS
4
5This file is part of GNU Emacs.
6
7GNU Emacs is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
c89475dc 9the Free Software Foundation; either version 2, or (at your option)
7942b8ae
RS
10any later version.
11
12GNU Emacs is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with GNU Emacs; see the file COPYING. If not, write to
3b7ad313
EN
19the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20Boston, MA 02111-1307, USA. */
7942b8ae
RS
21
22
18160b98 23#include <config.h>
7942b8ae 24#include <stdio.h>
7ee72033 25
7942b8ae
RS
26#include "lisp.h"
27#include "commands.h"
28#include "buffer.h"
29#include "window.h"
9192a027 30#include "charset.h"
7169beb1 31#include "syntax.h"
7942b8ae
RS
32
33/* An abbrev table is an obarray.
34 Each defined abbrev is represented by a symbol in that obarray
35 whose print name is the abbreviation.
36 The symbol's value is a string which is the expansion.
37 If its function definition is non-nil, it is called
38 after the expansion is done.
39 The plist slot of the abbrev symbol is its usage count. */
40
41/* List of all abbrev-table name symbols:
42 symbols whose values are abbrev tables. */
43
44Lisp_Object Vabbrev_table_name_list;
45
46/* The table of global abbrevs. These are in effect
47 in any buffer in which abbrev mode is turned on. */
48
49Lisp_Object Vglobal_abbrev_table;
50
51/* The local abbrev table used by default (in Fundamental Mode buffers) */
52
53Lisp_Object Vfundamental_mode_abbrev_table;
54
55/* Set nonzero when an abbrev definition is changed */
56
57int abbrevs_changed;
58
59int abbrev_all_caps;
60
61/* Non-nil => use this location as the start of abbrev to expand
62 (rather than taking the word before point as the abbrev) */
63
64Lisp_Object Vabbrev_start_location;
65
66/* Buffer that Vabbrev_start_location applies to */
67Lisp_Object Vabbrev_start_location_buffer;
68
69/* The symbol representing the abbrev most recently expanded */
70
71Lisp_Object Vlast_abbrev;
72
73/* A string for the actual text of the abbrev most recently expanded.
74 This has more info than Vlast_abbrev since case is significant. */
75
76Lisp_Object Vlast_abbrev_text;
77
78/* Character address of start of last abbrev expanded */
79
80int last_abbrev_point;
81
dbd7a969
RS
82/* Hook to run before expanding any abbrev. */
83
84Lisp_Object Vpre_abbrev_expand_hook, Qpre_abbrev_expand_hook;
7942b8ae
RS
85\f
86DEFUN ("make-abbrev-table", Fmake_abbrev_table, Smake_abbrev_table, 0, 0, 0,
7ee72033
MB
87 doc: /* Create a new, empty abbrev table object. */)
88 ()
7942b8ae
RS
89{
90 return Fmake_vector (make_number (59), make_number (0));
91}
92
93DEFUN ("clear-abbrev-table", Fclear_abbrev_table, Sclear_abbrev_table, 1, 1, 0,
7ee72033
MB
94 doc: /* Undefine all abbrevs in abbrev table TABLE, leaving it empty. */)
95 (table)
7942b8ae
RS
96 Lisp_Object table;
97{
98 int i, size;
99
100 CHECK_VECTOR (table, 0);
101 size = XVECTOR (table)->size;
102 abbrevs_changed = 1;
103 for (i = 0; i < size; i++)
104 XVECTOR (table)->contents[i] = make_number (0);
105 return Qnil;
106}
107\f
108DEFUN ("define-abbrev", Fdefine_abbrev, Sdefine_abbrev, 3, 5, 0,
7ee72033 109 doc: /* Define an abbrev in TABLE named NAME, to expand to EXPANSION and call HOOK.
b39fb64b
PJ
110NAME must be a string.
111EXPANSION should usually be a string.
112To undefine an abbrev, define it with EXPANSION = nil.
113If HOOK is non-nil, it should be a function of no arguments;
114it is called after EXPANSION is inserted.
115If EXPANSION is not a string, the abbrev is a special one,
116 which does not expand in the usual way but only runs HOOK.
117COUNT, if specified, initializes the abbrev's usage-count
7ee72033
MB
118which is incremented each time the abbrev is used. */)
119 (table, name, expansion, hook, count)
7942b8ae
RS
120 Lisp_Object table, name, expansion, hook, count;
121{
122 Lisp_Object sym, oexp, ohook, tem;
123 CHECK_VECTOR (table, 0);
124 CHECK_STRING (name, 1);
b7734773 125
d427b66a 126 if (NILP (count))
7942b8ae
RS
127 count = make_number (0);
128 else
129 CHECK_NUMBER (count, 0);
130
131 sym = Fintern (name, table);
132
a97569cb 133 oexp = SYMBOL_VALUE (sym);
7942b8ae
RS
134 ohook = XSYMBOL (sym)->function;
135 if (!((EQ (oexp, expansion)
09e82d7c 136 || (STRINGP (oexp) && STRINGP (expansion)
d427b66a 137 && (tem = Fstring_equal (oexp, expansion), !NILP (tem))))
7942b8ae
RS
138 &&
139 (EQ (ohook, hook)
d427b66a 140 || (tem = Fequal (ohook, hook), !NILP (tem)))))
7942b8ae
RS
141 abbrevs_changed = 1;
142
143 Fset (sym, expansion);
144 Ffset (sym, hook);
145 Fsetplist (sym, count);
146
147 return name;
148}
149
150DEFUN ("define-global-abbrev", Fdefine_global_abbrev, Sdefine_global_abbrev, 2, 2,
b39fb64b 151 "sDefine global abbrev: \nsExpansion for %s: ",
7ee72033
MB
152 doc: /* Define ABBREV as a global abbreviation for EXPANSION. */)
153 (abbrev, expansion)
78ce396a 154 Lisp_Object abbrev, expansion;
7942b8ae 155{
78ce396a 156 Fdefine_abbrev (Vglobal_abbrev_table, Fdowncase (abbrev),
7942b8ae 157 expansion, Qnil, make_number (0));
78ce396a 158 return abbrev;
7942b8ae
RS
159}
160
161DEFUN ("define-mode-abbrev", Fdefine_mode_abbrev, Sdefine_mode_abbrev, 2, 2,
b39fb64b 162 "sDefine mode abbrev: \nsExpansion for %s: ",
7ee72033
MB
163 doc: /* Define ABBREV as a mode-specific abbreviation for EXPANSION. */)
164 (abbrev, expansion)
78ce396a 165 Lisp_Object abbrev, expansion;
7942b8ae 166{
d427b66a 167 if (NILP (current_buffer->abbrev_table))
7942b8ae
RS
168 error ("Major mode has no abbrev table");
169
78ce396a 170 Fdefine_abbrev (current_buffer->abbrev_table, Fdowncase (abbrev),
7942b8ae 171 expansion, Qnil, make_number (0));
78ce396a 172 return abbrev;
7942b8ae
RS
173}
174
175DEFUN ("abbrev-symbol", Fabbrev_symbol, Sabbrev_symbol, 1, 2, 0,
7ee72033 176 doc: /* Return the symbol representing abbrev named ABBREV.
b39fb64b
PJ
177This symbol's name is ABBREV, but it is not the canonical symbol of that name;
178it is interned in an abbrev-table rather than the normal obarray.
179The value is nil if that abbrev is not defined.
180Optional second arg TABLE is abbrev table to look it up in.
7ee72033
MB
181The default is to try buffer's mode-specific abbrev table, then global table. */)
182 (abbrev, table)
7942b8ae
RS
183 Lisp_Object abbrev, table;
184{
185 Lisp_Object sym;
186 CHECK_STRING (abbrev, 0);
d427b66a 187 if (!NILP (table))
7942b8ae
RS
188 sym = Fintern_soft (abbrev, table);
189 else
190 {
191 sym = Qnil;
d427b66a 192 if (!NILP (current_buffer->abbrev_table))
7942b8ae 193 sym = Fintern_soft (abbrev, current_buffer->abbrev_table);
a97569cb 194 if (NILP (SYMBOL_VALUE (sym)))
7942b8ae 195 sym = Qnil;
d427b66a 196 if (NILP (sym))
7942b8ae
RS
197 sym = Fintern_soft (abbrev, Vglobal_abbrev_table);
198 }
a97569cb
GM
199 if (NILP (SYMBOL_VALUE (sym)))
200 return Qnil;
7942b8ae
RS
201 return sym;
202}
203
204DEFUN ("abbrev-expansion", Fabbrev_expansion, Sabbrev_expansion, 1, 2, 0,
7ee72033 205 doc: /* Return the string that ABBREV expands into in the current buffer.
b39fb64b 206Optionally specify an abbrev table as second arg;
7ee72033
MB
207then ABBREV is looked up in that table only. */)
208 (abbrev, table)
7942b8ae
RS
209 Lisp_Object abbrev, table;
210{
211 Lisp_Object sym;
212 sym = Fabbrev_symbol (abbrev, table);
d427b66a 213 if (NILP (sym)) return sym;
7942b8ae
RS
214 return Fsymbol_value (sym);
215}
216\f
217/* Expand the word before point, if it is an abbrev.
218 Returns 1 if an expansion is done. */
219
220DEFUN ("expand-abbrev", Fexpand_abbrev, Sexpand_abbrev, 0, 0, "",
7ee72033 221 doc: /* Expand the abbrev before point, if there is an abbrev there.
b39fb64b 222Effective when explicitly called even when `abbrev-mode' is nil.
7ee72033
MB
223Returns the abbrev symbol, if expansion took place. */)
224 ()
7942b8ae
RS
225{
226 register char *buffer, *p;
aa406bac
RS
227 int wordstart, wordend;
228 register int wordstart_byte, wordend_byte, idx;
7942b8ae
RS
229 int whitecnt;
230 int uccount = 0, lccount = 0;
231 register Lisp_Object sym;
232 Lisp_Object expansion, hook, tem;
ba70da8f 233 Lisp_Object value;
7942b8ae 234
f530ce27
RS
235 value = Qnil;
236
d427b66a 237 if (!NILP (Vrun_hooks))
dbd7a969
RS
238 call1 (Vrun_hooks, Qpre_abbrev_expand_hook);
239
dc7e2b30 240 wordstart = 0;
f530ce27
RS
241 if (!(BUFFERP (Vabbrev_start_location_buffer)
242 && XBUFFER (Vabbrev_start_location_buffer) == current_buffer))
7942b8ae 243 Vabbrev_start_location = Qnil;
d427b66a 244 if (!NILP (Vabbrev_start_location))
7942b8ae
RS
245 {
246 tem = Vabbrev_start_location;
247 CHECK_NUMBER_COERCE_MARKER (tem, 0);
248 wordstart = XINT (tem);
249 Vabbrev_start_location = Qnil;
dc7e2b30
KH
250 if (wordstart < BEGV || wordstart > ZV)
251 wordstart = 0;
aa406bac
RS
252 if (wordstart && wordstart != ZV)
253 {
254 wordstart_byte = CHAR_TO_BYTE (wordstart);
255 if (FETCH_BYTE (wordstart_byte) == '-')
256 del_range (wordstart, wordstart + 1);
257 }
7942b8ae 258 }
dc7e2b30 259 if (!wordstart)
6ec8bbd2 260 wordstart = scan_words (PT, -1);
7942b8ae
RS
261
262 if (!wordstart)
ba70da8f 263 return value;
7942b8ae 264
aa406bac 265 wordstart_byte = CHAR_TO_BYTE (wordstart);
7942b8ae
RS
266 wordend = scan_words (wordstart, 1);
267 if (!wordend)
ba70da8f 268 return value;
7942b8ae 269
6ec8bbd2
KH
270 if (wordend > PT)
271 wordend = PT;
aa406bac
RS
272
273 wordend_byte = CHAR_TO_BYTE (wordend);
6ec8bbd2 274 whitecnt = PT - wordend;
7942b8ae 275 if (wordend <= wordstart)
ba70da8f 276 return value;
7942b8ae 277
aa406bac 278 p = buffer = (char *) alloca (wordend_byte - wordstart_byte);
7942b8ae 279
aa406bac 280 for (idx = wordstart_byte; idx < wordend_byte; idx++)
7942b8ae 281 {
aa406bac 282 /* ??? This loop needs to go by characters! */
fc44dfab 283 register int c = FETCH_BYTE (idx);
7942b8ae
RS
284 if (UPPERCASEP (c))
285 c = DOWNCASE (c), uccount++;
286 else if (! NOCASEP (c))
287 lccount++;
288 *p++ = c;
289 }
290
09e82d7c 291 if (VECTORP (current_buffer->abbrev_table))
fc412686
RS
292 sym = oblookup (current_buffer->abbrev_table, buffer,
293 wordend - wordstart, wordend_byte - wordstart_byte);
7942b8ae 294 else
2a43e2bc 295 XSETFASTINT (sym, 0);
a97569cb 296 if (INTEGERP (sym) || NILP (SYMBOL_VALUE (sym)))
fc412686
RS
297 sym = oblookup (Vglobal_abbrev_table, buffer,
298 wordend - wordstart, wordend_byte - wordstart_byte);
a97569cb 299 if (INTEGERP (sym) || NILP (SYMBOL_VALUE (sym)))
ba70da8f 300 return value;
7942b8ae
RS
301
302 if (INTERACTIVE && !EQ (minibuf_window, selected_window))
303 {
aba686ed
RS
304 /* Add an undo boundary, in case we are doing this for
305 a self-inserting command which has avoided making one so far. */
7942b8ae
RS
306 SET_PT (wordend);
307 Fundo_boundary ();
308 }
b7734773 309
7942b8ae
RS
310 Vlast_abbrev_text
311 = Fbuffer_substring (make_number (wordstart), make_number (wordend));
7942b8ae 312
b7734773 313 /* Now sym is the abbrev symbol. */
7942b8ae 314 Vlast_abbrev = sym;
f530ce27 315 value = sym;
7942b8ae
RS
316 last_abbrev_point = wordstart;
317
09e82d7c 318 if (INTEGERP (XSYMBOL (sym)->plist))
7942b8ae
RS
319 XSETINT (XSYMBOL (sym)->plist,
320 XINT (XSYMBOL (sym)->plist) + 1); /* Increment use count */
321
b7734773
RS
322 /* If this abbrev has an expansion, delete the abbrev
323 and insert the expansion. */
a97569cb 324 expansion = SYMBOL_VALUE (sym);
b7734773 325 if (STRINGP (expansion))
7942b8ae 326 {
b7734773
RS
327 SET_PT (wordstart);
328
bc69581b 329 del_range_both (wordstart, wordstart_byte, wordend, wordend_byte, 1);
b7734773 330
fc412686 331 insert_from_string (expansion, 0, 0, XSTRING (expansion)->size,
fc932ac6 332 STRING_BYTES (XSTRING (expansion)), 1);
b7734773
RS
333 SET_PT (PT + whitecnt);
334
335 if (uccount && !lccount)
336 {
337 /* Abbrev was all caps */
338 /* If expansion is multiple words, normally capitalize each word */
339 /* This used to be if (!... && ... >= ...) Fcapitalize; else Fupcase
340 but Megatest 68000 compiler can't handle that */
341 if (!abbrev_all_caps)
342 if (scan_words (PT, -1) > scan_words (wordstart, 1))
343 {
344 Fupcase_initials_region (make_number (wordstart),
345 make_number (PT));
346 goto caped;
347 }
348 /* If expansion is one word, or if user says so, upcase it all. */
349 Fupcase_region (make_number (wordstart), make_number (PT));
350 caped: ;
351 }
352 else if (uccount)
353 {
354 /* Abbrev included some caps. Cap first initial of expansion */
aa406bac 355 int pos = wordstart_byte;
b7734773
RS
356
357 /* Find the initial. */
aa406bac
RS
358 while (pos < PT_BYTE
359 && SYNTAX (*BUF_BYTE_ADDRESS (current_buffer, pos)) != Sword)
b7734773
RS
360 pos++;
361
362 /* Change just that. */
aa406bac 363 pos = BYTE_TO_CHAR (pos);
b7734773
RS
364 Fupcase_initials_region (make_number (pos), make_number (pos + 1));
365 }
7942b8ae
RS
366 }
367
368 hook = XSYMBOL (sym)->function;
d427b66a 369 if (!NILP (hook))
79d2af9c
GM
370 {
371 Lisp_Object expanded, prop;
372
c87dbfd0 373 /* If the abbrev has a hook function, run it. */
79d2af9c 374 expanded = call0 (hook);
c87dbfd0
RS
375
376 /* In addition, if the hook function is a symbol with a a
377 non-nil `no-self-insert' property, let the value it returned
378 specify whether we consider that an expansion took place. If
379 it returns nil, no expansion has been done. */
380
79d2af9c
GM
381 if (SYMBOLP (hook)
382 && NILP (expanded)
383 && (prop = Fget (hook, intern ("no-self-insert")),
384 !NILP (prop)))
385 value = Qnil;
386 }
7942b8ae 387
f530ce27 388 return value;
7942b8ae
RS
389}
390
391DEFUN ("unexpand-abbrev", Funexpand_abbrev, Sunexpand_abbrev, 0, 0, "",
7ee72033 392 doc: /* Undo the expansion of the last abbrev that expanded.
b39fb64b 393This differs from ordinary undo in that other editing done since then
7ee72033
MB
394is not undone. */)
395 ()
7942b8ae 396{
6ec8bbd2 397 int opoint = PT;
7942b8ae
RS
398 int adjust = 0;
399 if (last_abbrev_point < BEGV
400 || last_abbrev_point > ZV)
401 return Qnil;
402 SET_PT (last_abbrev_point);
09e82d7c 403 if (STRINGP (Vlast_abbrev_text))
7942b8ae
RS
404 {
405 /* This isn't correct if Vlast_abbrev->function was used
406 to do the expansion */
407 Lisp_Object val;
aa406bac
RS
408 int zv_before;
409
a97569cb 410 val = SYMBOL_VALUE (Vlast_abbrev);
09e82d7c 411 if (!STRINGP (val))
4458687c 412 error ("value of abbrev-symbol must be a string");
aa406bac 413 zv_before = ZV;
fc932ac6 414 del_range_byte (PT_BYTE, PT_BYTE + STRING_BYTES (XSTRING (val)), 1);
0c287112 415 /* Don't inherit properties here; just copy from old contents. */
fc412686
RS
416 insert_from_string (Vlast_abbrev_text, 0, 0,
417 XSTRING (Vlast_abbrev_text)->size,
fc932ac6 418 STRING_BYTES (XSTRING (Vlast_abbrev_text)), 0);
7942b8ae 419 Vlast_abbrev_text = Qnil;
aa406bac
RS
420 /* Total number of characters deleted. */
421 adjust = ZV - zv_before;
7942b8ae 422 }
57522629 423 SET_PT (last_abbrev_point < opoint ? opoint + adjust : opoint);
7942b8ae
RS
424 return Qnil;
425}
426\f
aa406bac 427static void
7942b8ae
RS
428write_abbrev (sym, stream)
429 Lisp_Object sym, stream;
430{
431 Lisp_Object name;
a97569cb 432 if (NILP (SYMBOL_VALUE (sym)))
7942b8ae
RS
433 return;
434 insert (" (", 5);
6520d056 435 XSETSTRING (name, XSYMBOL (sym)->name);
7942b8ae
RS
436 Fprin1 (name, stream);
437 insert (" ", 1);
a97569cb 438 Fprin1 (SYMBOL_VALUE (sym), stream);
7942b8ae
RS
439 insert (" ", 1);
440 Fprin1 (XSYMBOL (sym)->function, stream);
441 insert (" ", 1);
442 Fprin1 (XSYMBOL (sym)->plist, stream);
443 insert (")\n", 2);
444}
445
aa406bac 446static void
7942b8ae
RS
447describe_abbrev (sym, stream)
448 Lisp_Object sym, stream;
449{
450 Lisp_Object one;
451
a97569cb 452 if (NILP (SYMBOL_VALUE (sym)))
7942b8ae
RS
453 return;
454 one = make_number (1);
455 Fprin1 (Fsymbol_name (sym), stream);
456 Findent_to (make_number (15), one);
457 Fprin1 (XSYMBOL (sym)->plist, stream);
458 Findent_to (make_number (20), one);
a97569cb 459 Fprin1 (SYMBOL_VALUE (sym), stream);
d427b66a 460 if (!NILP (XSYMBOL (sym)->function))
7942b8ae
RS
461 {
462 Findent_to (make_number (45), one);
463 Fprin1 (XSYMBOL (sym)->function, stream);
464 }
465 Fterpri (stream);
466}
467
a0d76c27
EN
468DEFUN ("insert-abbrev-table-description", Finsert_abbrev_table_description,
469 Sinsert_abbrev_table_description, 1, 2, 0,
7ee72033 470 doc: /* Insert before point a full description of abbrev table named NAME.
b39fb64b
PJ
471NAME is a symbol whose value is an abbrev table.
472If optional 2nd arg READABLE is non-nil, a human-readable description
473is inserted. Otherwise the description is an expression,
474a call to `define-abbrev-table', which would
7ee72033
MB
475define the abbrev table NAME exactly as it is currently defined. */)
476 (name, readable)
7942b8ae
RS
477 Lisp_Object name, readable;
478{
479 Lisp_Object table;
480 Lisp_Object stream;
481
482 CHECK_SYMBOL (name, 0);
483 table = Fsymbol_value (name);
484 CHECK_VECTOR (table, 0);
485
6520d056 486 XSETBUFFER (stream, current_buffer);
7942b8ae 487
d427b66a 488 if (!NILP (readable))
7942b8ae
RS
489 {
490 insert_string ("(");
491 Fprin1 (name, stream);
492 insert_string (")\n\n");
493 map_obarray (table, describe_abbrev, stream);
494 insert_string ("\n\n");
495 }
496 else
497 {
498 insert_string ("(define-abbrev-table '");
499 Fprin1 (name, stream);
500 insert_string (" '(\n");
501 map_obarray (table, write_abbrev, stream);
502 insert_string (" ))\n\n");
503 }
504
505 return Qnil;
506}
507\f
508DEFUN ("define-abbrev-table", Fdefine_abbrev_table, Sdefine_abbrev_table,
509 2, 2, 0,
7ee72033 510 doc: /* Define TABLENAME (a symbol) as an abbrev table name.
b39fb64b 511Define abbrevs in it according to DEFINITIONS, which is a list of elements
7ee72033
MB
512of the form (ABBREVNAME EXPANSION HOOK USECOUNT). */)
513 (tablename, definitions)
b9d613cc 514 Lisp_Object tablename, definitions;
7942b8ae
RS
515{
516 Lisp_Object name, exp, hook, count;
517 Lisp_Object table, elt;
518
78ce396a
EN
519 CHECK_SYMBOL (tablename, 0);
520 table = Fboundp (tablename);
521 if (NILP (table) || (table = Fsymbol_value (tablename), NILP (table)))
7942b8ae
RS
522 {
523 table = Fmake_abbrev_table ();
78ce396a 524 Fset (tablename, table);
b9d613cc 525 Vabbrev_table_name_list = Fcons (tablename, Vabbrev_table_name_list);
7942b8ae
RS
526 }
527 CHECK_VECTOR (table, 0);
528
b9d613cc 529 for (; !NILP (definitions); definitions = Fcdr (definitions))
7942b8ae 530 {
78ce396a 531 elt = Fcar (definitions);
0292bcb1
JB
532 name = Fcar (elt); elt = Fcdr (elt);
533 exp = Fcar (elt); elt = Fcdr (elt);
534 hook = Fcar (elt); elt = Fcdr (elt);
7942b8ae
RS
535 count = Fcar (elt);
536 Fdefine_abbrev (table, name, exp, hook, count);
537 }
538 return Qnil;
539}
540\f
dfcf069d 541void
7942b8ae
RS
542syms_of_abbrev ()
543{
7ee72033
MB
544 DEFVAR_LISP ("abbrev-table-name-list", &Vabbrev_table_name_list,
545 doc: /* List of symbols whose values are abbrev tables. */);
7942b8ae
RS
546 Vabbrev_table_name_list = Fcons (intern ("fundamental-mode-abbrev-table"),
547 Fcons (intern ("global-abbrev-table"),
548 Qnil));
549
7ee72033
MB
550 DEFVAR_LISP ("global-abbrev-table", &Vglobal_abbrev_table,
551 doc: /* The abbrev table whose abbrevs affect all buffers.
b39fb64b
PJ
552Each buffer may also have a local abbrev table.
553If it does, the local table overrides the global one
554for any particular abbrev defined in both. */);
7942b8ae
RS
555 Vglobal_abbrev_table = Fmake_abbrev_table ();
556
7ee72033
MB
557 DEFVAR_LISP ("fundamental-mode-abbrev-table", &Vfundamental_mode_abbrev_table,
558 doc: /* The abbrev table of mode-specific abbrevs for Fundamental Mode. */);
7942b8ae
RS
559 Vfundamental_mode_abbrev_table = Fmake_abbrev_table ();
560 current_buffer->abbrev_table = Vfundamental_mode_abbrev_table;
c8bb8167 561 buffer_defaults.abbrev_table = Vfundamental_mode_abbrev_table;
7942b8ae 562
7ee72033
MB
563 DEFVAR_LISP ("last-abbrev", &Vlast_abbrev,
564 doc: /* The abbrev-symbol of the last abbrev expanded. See `abbrev-symbol'. */);
7942b8ae 565
7ee72033
MB
566 DEFVAR_LISP ("last-abbrev-text", &Vlast_abbrev_text,
567 doc: /* The exact text of the last abbrev expanded.
b39fb64b 568nil if the abbrev has already been unexpanded. */);
7942b8ae 569
7ee72033
MB
570 DEFVAR_INT ("last-abbrev-location", &last_abbrev_point,
571 doc: /* The location of the start of the last abbrev expanded. */);
7942b8ae
RS
572
573 Vlast_abbrev = Qnil;
574 Vlast_abbrev_text = Qnil;
575 last_abbrev_point = 0;
576
7ee72033
MB
577 DEFVAR_LISP ("abbrev-start-location", &Vabbrev_start_location,
578 doc: /* Buffer position for `expand-abbrev' to use as the start of the abbrev.
b39fb64b
PJ
579nil means use the word before point as the abbrev.
580Calling `expand-abbrev' sets this to nil. */);
7942b8ae
RS
581 Vabbrev_start_location = Qnil;
582
7ee72033
MB
583 DEFVAR_LISP ("abbrev-start-location-buffer", &Vabbrev_start_location_buffer,
584 doc: /* Buffer that `abbrev-start-location' has been set for.
b39fb64b 585Trying to expand an abbrev in any other buffer clears `abbrev-start-location'. */);
7942b8ae
RS
586 Vabbrev_start_location_buffer = Qnil;
587
7ee72033
MB
588 DEFVAR_PER_BUFFER ("local-abbrev-table", &current_buffer->abbrev_table, Qnil,
589 doc: /* Local (mode-specific) abbrev table of current buffer. */);
7942b8ae 590
7ee72033
MB
591 DEFVAR_BOOL ("abbrevs-changed", &abbrevs_changed,
592 doc: /* Set non-nil by defining or altering any word abbrevs.
b39fb64b 593This causes `save-some-buffers' to offer to save the abbrevs. */);
7942b8ae
RS
594 abbrevs_changed = 0;
595
7ee72033
MB
596 DEFVAR_BOOL ("abbrev-all-caps", &abbrev_all_caps,
597 doc: /* *Set non-nil means expand multi-word abbrevs all caps if abbrev was so. */);
7942b8ae
RS
598 abbrev_all_caps = 0;
599
7ee72033
MB
600 DEFVAR_LISP ("pre-abbrev-expand-hook", &Vpre_abbrev_expand_hook,
601 doc: /* Function or functions to be called before abbrev expansion is done.
b39fb64b
PJ
602This is the first thing that `expand-abbrev' does, and so this may change
603the current abbrev table before abbrev lookup happens. */);
dbd7a969
RS
604 Vpre_abbrev_expand_hook = Qnil;
605 Qpre_abbrev_expand_hook = intern ("pre-abbrev-expand-hook");
606 staticpro (&Qpre_abbrev_expand_hook);
607
7942b8ae
RS
608 defsubr (&Smake_abbrev_table);
609 defsubr (&Sclear_abbrev_table);
610 defsubr (&Sdefine_abbrev);
611 defsubr (&Sdefine_global_abbrev);
612 defsubr (&Sdefine_mode_abbrev);
613 defsubr (&Sabbrev_expansion);
614 defsubr (&Sabbrev_symbol);
615 defsubr (&Sexpand_abbrev);
616 defsubr (&Sunexpand_abbrev);
617 defsubr (&Sinsert_abbrev_table_description);
618 defsubr (&Sdefine_abbrev_table);
619}