annotate src/abbrev.c @ 8:4b173ad71786 r19-15b5

Import from CVS: tag r19-15b5
author cvs
date Mon, 13 Aug 2007 08:47:35 +0200
parents 376386a54a3c
children 859a2309aef8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 /* Primitives for word-abbrev mode.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2 Copyright (C) 1985, 1986, 1992, 1993 Free Software Foundation, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4 This file is part of XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 XEmacs is free software; you can redistribute it and/or modify it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 under the terms of the GNU General Public License as published by the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 Free Software Foundation; either version 2, or (at your option) any
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 XEmacs is distributed in the hope that it will be useful, but WITHOUT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 You should have received a copy of the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 along with XEmacs; see the file COPYING. If not, write to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 Boston, MA 02111-1307, USA. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 /* Synched up with: FSF 19.30. Note that there are many more functions in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 FSF's abbrev.c. These have been moved into Lisp in XEmacs. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 /* Authorship:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 FSF: Original version; a long time ago.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 JWZ or Mly: Mostly moved into Lisp; maybe 1992.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 Ben Wing: Some changes for Mule for 19.12.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 /* This file has been Mule-ized. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 #include <config.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 #include "lisp.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 #include "buffer.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 #include "commands.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 #include "insdel.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 #include "syntax.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 #include "window.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 /* An abbrev table is an obarray.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 Each defined abbrev is represented by a symbol in that obarray
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 whose print name is the abbreviation.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 The symbol's value is a string which is the expansion.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 If its function definition is non-nil, it is called
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 after the expansion is done.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 The plist slot of the abbrev symbol is its usage count. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 /* The table of global abbrevs. These are in effect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 in any buffer in which abbrev mode is turned on. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 Lisp_Object Vglobal_abbrev_table;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 int abbrev_all_caps;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 /* Non-nil => use this location as the start of abbrev to expand
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 (rather than taking the word before point as the abbrev) */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 Lisp_Object Vabbrev_start_location;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 /* Buffer that Vabbrev_start_location applies to */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 Lisp_Object Vabbrev_start_location_buffer;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 /* The symbol representing the abbrev most recently expanded */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 Lisp_Object Vlast_abbrev;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 /* A string for the actual text of the abbrev most recently expanded.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 This has more info than Vlast_abbrev since case is significant. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 Lisp_Object Vlast_abbrev_text;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 /* Character address of start of last abbrev expanded */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 int last_abbrev_point;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 /* Hook to run before expanding any abbrev. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 Lisp_Object Vpre_abbrev_expand_hook, Qpre_abbrev_expand_hook;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 /* Expand the word before point, if it is an abbrev.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 Returns Qt if an expansion is done. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 DEFUN ("expand-abbrev", Fexpand_abbrev, Sexpand_abbrev, 0, 0, "" /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 Expand the abbrev before point, if there is an abbrev there.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 Effective when explicitly called even when `abbrev-mode' is nil.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 Returns t if expansion took place.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 /* This function can GC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 REGISTER Bufbyte *buffer, *p;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 REGISTER Bufpos wordstart, wordend, idx;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 Charcount whitecnt;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 Charcount uccount = 0, lccount = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 REGISTER Lisp_Object sym;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 Lisp_Object expansion, hook, value;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 struct buffer *buf = current_buffer;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 Lisp_Object lbuf;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 int oldmodiff = BUF_MODIFF (buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 XSETBUFFER (lbuf, buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 run_hook (Qpre_abbrev_expand_hook);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 /* If the hook changes the buffer, treat that as having "done an
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 expansion". */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 value = (BUF_MODIFF (buf) != oldmodiff ? Qt : Qnil);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 wordstart = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 if (!BUFFERP (Vabbrev_start_location_buffer) ||
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 XBUFFER (Vabbrev_start_location_buffer) != buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 Vabbrev_start_location = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 if (!NILP (Vabbrev_start_location))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 wordstart = get_buffer_pos_char (buf, Vabbrev_start_location, GB_COERCE_RANGE);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 Vabbrev_start_location = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 if (wordstart < BUF_BEGV (buf) || wordstart > BUF_ZV (buf))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 wordstart = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 if (wordstart && wordstart != BUF_ZV (buf) &&
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 BUF_FETCH_CHAR (buf, wordstart) == '-')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 buffer_delete_range (buf, wordstart, wordstart + 1, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 if (!wordstart)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 wordstart = scan_words (buf, BUF_PT (buf), -1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 if (!wordstart)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 return value;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 wordend = scan_words (buf, wordstart, 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 if (!wordend)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 return value;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 if (wordend > BUF_PT (buf))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 wordend = BUF_PT (buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 whitecnt = BUF_PT (buf) - wordend;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 if (wordend <= wordstart)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 return value;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 p = buffer = (Bufbyte *) alloca (MAX_EMCHAR_LEN*(wordend - wordstart));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 for (idx = wordstart; idx < wordend; idx++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 REGISTER Emchar c = BUF_FETCH_CHAR (buf, idx);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 if (UPPERCASEP (buf, c))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 c = DOWNCASE (buf, c), uccount++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 else if (! NOCASEP (buf, c))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 lccount++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 p += set_charptr_emchar (p, c);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 if (VECTORP (buf->abbrev_table))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 sym = oblookup (buf->abbrev_table,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 buffer,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 p - buffer);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 sym = Qzero;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 if (INTP (sym) || NILP (XSYMBOL (sym)->value))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 sym = oblookup (Vglobal_abbrev_table,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 buffer,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 p - buffer);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 if (INTP (sym) || NILP (XSYMBOL (sym)->value))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 return value;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 if (INTERACTIVE && !EQ (minibuf_window, Fselected_window (Qnil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 /* Add an undo boundary, in case we are doing this for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 a self-inserting command which has avoided making one so far. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 BUF_SET_PT (buf, wordend);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 Fundo_boundary ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 BUF_SET_PT (buf, wordstart);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 Vlast_abbrev_text =
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 make_string_from_buffer (buf, wordstart, wordend - wordstart);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 buffer_delete_range (buf, wordstart, wordend, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 /* Now sym is the abbrev symbol. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 Vlast_abbrev = sym;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 last_abbrev_point = wordstart;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 if (INTP (XSYMBOL (sym)->plist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 XSETINT (XSYMBOL (sym)->plist,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 XINT (XSYMBOL (sym)->plist) + 1); /* Increment use count */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 expansion = XSYMBOL (sym)->value;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 buffer_insert_lisp_string (buf, expansion);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 BUF_SET_PT (buf, BUF_PT (buf) + whitecnt);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 if (uccount && !lccount)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 /* Abbrev was all caps */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 /* If expansion is multiple words, normally capitalize each word */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 /* This used to be if (!... && ... >= ...) Fcapitalize; else Fupcase
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 but Megatest 68000 compiler can't handle that */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 if (!abbrev_all_caps)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 if (scan_words (buf, BUF_PT (buf), -1) >
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 scan_words (buf, wordstart, 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 Fupcase_initials_region (make_int (wordstart),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 make_int (BUF_PT (buf)),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 lbuf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 goto caped;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 /* If expansion is one word, or if user says so, upcase it all. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 Fupcase_region (make_int (wordstart), make_int (BUF_PT (buf)),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 lbuf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 caped: ;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 else if (uccount)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 /* Abbrev included some caps. Cap first initial of expansion */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 Bufpos pos = wordstart;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 /* Find the initial. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 while (pos < BUF_PT (buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 && !WORD_SYNTAX_P (buf->syntax_table, BUF_FETCH_CHAR (buf, pos)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 pos++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 /* Change just that. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 Fupcase_initials_region (make_int (pos), make_int (pos + 1), lbuf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 hook = XSYMBOL (sym)->function;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 if (!NILP (hook) && !UNBOUNDP (hook))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 call0 (hook);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 return Qt;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 syms_of_abbrev (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 defsymbol (&Qpre_abbrev_expand_hook, "pre-abbrev-expand-hook");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 defsubr (&Sexpand_abbrev);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 vars_of_abbrev (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 DEFVAR_LISP ("global-abbrev-table", &Vglobal_abbrev_table /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 The abbrev table whose abbrevs affect all buffers.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 Each buffer may also have a local abbrev table.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 If it does, the local table overrides the global one
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 for any particular abbrev defined in both.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 */ );
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 Vglobal_abbrev_table = Qnil; /* setup by Lisp code */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 DEFVAR_LISP ("last-abbrev", &Vlast_abbrev /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 The abbrev-symbol of the last abbrev expanded.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 See the function `abbrev-symbol'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 */ );
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 DEFVAR_LISP ("last-abbrev-text", &Vlast_abbrev_text /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 The exact text of the last abbrev expanded.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 nil if the abbrev has already been unexpanded.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 */ );
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 DEFVAR_INT ("last-abbrev-location", &last_abbrev_point /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 The location of the start of the last abbrev expanded.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 */ );
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 Vlast_abbrev = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 Vlast_abbrev_text = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 last_abbrev_point = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 DEFVAR_LISP ("abbrev-start-location", &Vabbrev_start_location /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 Buffer position for `expand-abbrev' to use as the start of the abbrev.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 nil means use the word before point as the abbrev.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 Calling `expand-abbrev' sets this to nil.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 */ );
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 Vabbrev_start_location = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 DEFVAR_LISP ("abbrev-start-location-buffer", &Vabbrev_start_location_buffer /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 Buffer that `abbrev-start-location' has been set for.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 Trying to expand an abbrev in any other buffer clears `abbrev-start-location'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 */ );
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 Vabbrev_start_location_buffer = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 DEFVAR_BOOL ("abbrev-all-caps", &abbrev_all_caps /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 *Set non-nil means expand multi-word abbrevs all caps if abbrev was so.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 */ );
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 abbrev_all_caps = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 DEFVAR_LISP ("pre-abbrev-expand-hook", &Vpre_abbrev_expand_hook /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 Function or functions to be called before abbrev expansion is done.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 This is the first thing that `expand-abbrev' does, and so this may change
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 the current abbrev table before abbrev lookup happens.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 */ );
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 Vpre_abbrev_expand_hook = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 }