Mercurial > hg > xemacs-beta
comparison src/abbrev.c @ 412:697ef44129c6 r21-2-14
Import from CVS: tag r21-2-14
author | cvs |
---|---|
date | Mon, 13 Aug 2007 11:20:41 +0200 |
parents | 74fd4e045ea6 |
children |
comparison
equal
deleted
inserted
replaced
411:12e008d41344 | 412:697ef44129c6 |
---|---|
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 Lisp_Char_Table *chartab; | 80 struct Lisp_Char_Table *chartab; |
81 Charcount point, maxlen; | 81 Charcount point, maxlen; |
82 Lisp_Symbol *found; | 82 struct 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 Lisp_Symbol *sym = XSYMBOL (symbol); | 94 struct Lisp_Symbol *sym = XSYMBOL (symbol); |
95 Lisp_String *abbrev; | 95 struct 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 Lisp_Symbol * | 150 static struct 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 Lisp_Symbol * | 178 static struct 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 } | 225 if (wordend <= wordstart) |
226 | 226 return 0; |
227 if (wordend <= wordstart) | 227 } |
228 return 0; | |
229 | 228 |
230 p = word = (Bufbyte *) alloca (MAX_EMCHAR_LEN * (wordend - wordstart)); | 229 p = word = (Bufbyte *) alloca (MAX_EMCHAR_LEN * (wordend - wordstart)); |
231 for (idx = wordstart; idx < wordend; idx++) | 230 for (idx = wordstart; idx < wordend; idx++) |
232 { | 231 { |
233 Emchar c = BUF_FETCH_CHAR (buf, idx); | 232 Emchar c = BUF_FETCH_CHAR (buf, idx); |
280 int oldmodiff = BUF_MODIFF (buf); | 279 int oldmodiff = BUF_MODIFF (buf); |
281 Lisp_Object pre_modiff_p; | 280 Lisp_Object pre_modiff_p; |
282 Bufpos point; /* position of point */ | 281 Bufpos point; /* position of point */ |
283 Bufpos abbrev_start; /* position of abbreviation beginning */ | 282 Bufpos abbrev_start; /* position of abbreviation beginning */ |
284 | 283 |
285 Lisp_Symbol *(*fun) (struct buffer *, Lisp_Object); | 284 struct Lisp_Symbol *(*fun) (struct buffer *, Lisp_Object); |
286 | 285 |
287 Lisp_Symbol *abbrev_symbol; | 286 struct Lisp_Symbol *abbrev_symbol; |
288 Lisp_String *abbrev_string; | 287 struct Lisp_String *abbrev_string; |
289 Lisp_Object expansion, count, hook; | 288 Lisp_Object expansion, count, hook; |
290 Charcount abbrev_length; | 289 Charcount abbrev_length; |
291 int lccount, uccount; | 290 int lccount, uccount; |
292 | 291 |
293 run_hook (Qpre_abbrev_expand_hook); | 292 run_hook (Qpre_abbrev_expand_hook); |