comparison src/abbrev.c @ 398:74fd4e045ea6 r21-2-29

Import from CVS: tag r21-2-29
author cvs
date Mon, 13 Aug 2007 11:13:30 +0200
parents 8626e4521993
children 697ef44129c6
comparison
equal deleted inserted replaced
397:f4aeb21a5bad 398:74fd4e045ea6
75 Lisp_Object Vpre_abbrev_expand_hook, Qpre_abbrev_expand_hook; 75 Lisp_Object Vpre_abbrev_expand_hook, Qpre_abbrev_expand_hook;
76 76
77 77
78 struct abbrev_match_mapper_closure { 78 struct abbrev_match_mapper_closure {
79 struct buffer *buf; 79 struct buffer *buf;
80 struct Lisp_Char_Table *chartab; 80 Lisp_Char_Table *chartab;
81 Charcount point, maxlen; 81 Charcount point, maxlen;
82 struct Lisp_Symbol *found; 82 Lisp_Symbol *found;
83 }; 83 };
84 84
85 /* For use by abbrev_match(): Match SYMBOL's name against buffer text 85 /* For use by abbrev_match(): Match SYMBOL's name against buffer text
86 before point, case-insensitively. When found, return non-zero, so 86 before point, case-insensitively. When found, return non-zero, so
87 that map_obarray terminates mapping. */ 87 that map_obarray terminates mapping. */
89 abbrev_match_mapper (Lisp_Object symbol, void *arg) 89 abbrev_match_mapper (Lisp_Object symbol, void *arg)
90 { 90 {
91 struct abbrev_match_mapper_closure *closure = 91 struct abbrev_match_mapper_closure *closure =
92 (struct abbrev_match_mapper_closure *)arg; 92 (struct abbrev_match_mapper_closure *)arg;
93 Charcount abbrev_length; 93 Charcount abbrev_length;
94 struct Lisp_Symbol *sym = XSYMBOL (symbol); 94 Lisp_Symbol *sym = XSYMBOL (symbol);
95 struct Lisp_String *abbrev; 95 Lisp_String *abbrev;
96 96
97 /* symbol_value should be OK here, because abbrevs are not expected 97 /* symbol_value should be OK here, because abbrevs are not expected
98 to contain any SYMBOL_MAGIC stuff. */ 98 to contain any SYMBOL_MAGIC stuff. */
99 if (UNBOUNDP (symbol_value (sym)) || NILP (symbol_value (sym))) 99 if (UNBOUNDP (symbol_value (sym)) || NILP (symbol_value (sym)))
100 { 100 {
145 return 0; 145 return 0;
146 } 146 }
147 147
148 /* Match the buffer text against names of symbols in obarray. Returns 148 /* Match the buffer text against names of symbols in obarray. Returns
149 the matching symbol, or 0 if not found. */ 149 the matching symbol, or 0 if not found. */
150 static struct Lisp_Symbol * 150 static Lisp_Symbol *
151 abbrev_match (struct buffer *buf, Lisp_Object obarray) 151 abbrev_match (struct buffer *buf, Lisp_Object obarray)
152 { 152 {
153 struct abbrev_match_mapper_closure closure; 153 struct abbrev_match_mapper_closure closure;
154 154
155 /* Precalculate some stuff, so mapper function needn't to it in each 155 /* Precalculate some stuff, so mapper function needn't to it in each
173 but then again, vi is an order of magnitude faster than Emacs. 173 but then again, vi is an order of magnitude faster than Emacs.
174 174
175 This speed difference should be unnoticeable, though. I have tested 175 This speed difference should be unnoticeable, though. I have tested
176 the degenerated cases of thousands of abbrevs being defined, and 176 the degenerated cases of thousands of abbrevs being defined, and
177 abbrev_match() was still fast enough for normal operation. */ 177 abbrev_match() was still fast enough for normal operation. */
178 static struct Lisp_Symbol * 178 static Lisp_Symbol *
179 abbrev_oblookup (struct buffer *buf, Lisp_Object obarray) 179 abbrev_oblookup (struct buffer *buf, Lisp_Object obarray)
180 { 180 {
181 Bufpos wordstart, wordend; 181 Bufpos wordstart, wordend;
182 Bufbyte *word, *p; 182 Bufbyte *word, *p;
183 Bytecount idx; 183 Bytecount idx;
220 /* Unlike the original function, we allow expansion only after 220 /* Unlike the original function, we allow expansion only after
221 the abbrev, not preceded by a number of spaces. This is 221 the abbrev, not preceded by a number of spaces. This is
222 because of consistency with abbrev_match. */ 222 because of consistency with abbrev_match. */
223 if (wordend < point) 223 if (wordend < point)
224 return 0; 224 return 0;
225 if (wordend <= wordstart) 225 }
226 return 0; 226
227 } 227 if (wordend <= wordstart)
228 return 0;
228 229
229 p = word = (Bufbyte *) alloca (MAX_EMCHAR_LEN * (wordend - wordstart)); 230 p = word = (Bufbyte *) alloca (MAX_EMCHAR_LEN * (wordend - wordstart));
230 for (idx = wordstart; idx < wordend; idx++) 231 for (idx = wordstart; idx < wordend; idx++)
231 { 232 {
232 Emchar c = BUF_FETCH_CHAR (buf, idx); 233 Emchar c = BUF_FETCH_CHAR (buf, idx);
279 int oldmodiff = BUF_MODIFF (buf); 280 int oldmodiff = BUF_MODIFF (buf);
280 Lisp_Object pre_modiff_p; 281 Lisp_Object pre_modiff_p;
281 Bufpos point; /* position of point */ 282 Bufpos point; /* position of point */
282 Bufpos abbrev_start; /* position of abbreviation beginning */ 283 Bufpos abbrev_start; /* position of abbreviation beginning */
283 284
284 struct Lisp_Symbol *(*fun) (struct buffer *, Lisp_Object); 285 Lisp_Symbol *(*fun) (struct buffer *, Lisp_Object);
285 286
286 struct Lisp_Symbol *abbrev_symbol; 287 Lisp_Symbol *abbrev_symbol;
287 struct Lisp_String *abbrev_string; 288 Lisp_String *abbrev_string;
288 Lisp_Object expansion, count, hook; 289 Lisp_Object expansion, count, hook;
289 Charcount abbrev_length; 290 Charcount abbrev_length;
290 int lccount, uccount; 291 int lccount, uccount;
291 292
292 run_hook (Qpre_abbrev_expand_hook); 293 run_hook (Qpre_abbrev_expand_hook);