Mercurial > emacs
comparison src/abbrev.c @ 484:3165b2697c78
entered into RCS
author | Jim Blandy <jimb@redhat.com> |
---|---|
date | Mon, 13 Jan 1992 21:48:03 +0000 |
parents | 8f18e7e89008 |
children | 341171b49f96 |
comparison
equal
deleted
inserted
replaced
483:00f564a647fa | 484:3165b2697c78 |
---|---|
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ | 18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ |
19 | 19 |
20 | 20 |
21 #include "config.h" | 21 #include "config.h" |
22 #include <stdio.h> | 22 #include <stdio.h> |
23 #undef NULL | |
24 #include "lisp.h" | 23 #include "lisp.h" |
25 #include "commands.h" | 24 #include "commands.h" |
26 #include "buffer.h" | 25 #include "buffer.h" |
27 #include "window.h" | 26 #include "window.h" |
28 | 27 |
111 Lisp_Object table, name, expansion, hook, count; | 110 Lisp_Object table, name, expansion, hook, count; |
112 { | 111 { |
113 Lisp_Object sym, oexp, ohook, tem; | 112 Lisp_Object sym, oexp, ohook, tem; |
114 CHECK_VECTOR (table, 0); | 113 CHECK_VECTOR (table, 0); |
115 CHECK_STRING (name, 1); | 114 CHECK_STRING (name, 1); |
116 if (!NULL (expansion)) | 115 if (!NILP (expansion)) |
117 CHECK_STRING (expansion, 2); | 116 CHECK_STRING (expansion, 2); |
118 if (NULL (count)) | 117 if (NILP (count)) |
119 count = make_number (0); | 118 count = make_number (0); |
120 else | 119 else |
121 CHECK_NUMBER (count, 0); | 120 CHECK_NUMBER (count, 0); |
122 | 121 |
123 sym = Fintern (name, table); | 122 sym = Fintern (name, table); |
124 | 123 |
125 oexp = XSYMBOL (sym)->value; | 124 oexp = XSYMBOL (sym)->value; |
126 ohook = XSYMBOL (sym)->function; | 125 ohook = XSYMBOL (sym)->function; |
127 if (!((EQ (oexp, expansion) | 126 if (!((EQ (oexp, expansion) |
128 || (XTYPE (oexp) == Lisp_String && XTYPE (expansion) == Lisp_String | 127 || (XTYPE (oexp) == Lisp_String && XTYPE (expansion) == Lisp_String |
129 && (tem = Fstring_equal (oexp, expansion), !NULL (tem)))) | 128 && (tem = Fstring_equal (oexp, expansion), !NILP (tem)))) |
130 && | 129 && |
131 (EQ (ohook, hook) | 130 (EQ (ohook, hook) |
132 || (tem = Fequal (ohook, hook), !NULL (tem))))) | 131 || (tem = Fequal (ohook, hook), !NILP (tem))))) |
133 abbrevs_changed = 1; | 132 abbrevs_changed = 1; |
134 | 133 |
135 Fset (sym, expansion); | 134 Fset (sym, expansion); |
136 Ffset (sym, hook); | 135 Ffset (sym, hook); |
137 Fsetplist (sym, count); | 136 Fsetplist (sym, count); |
154 "sDefine mode abbrev: \nsExpansion for %s: ", | 153 "sDefine mode abbrev: \nsExpansion for %s: ", |
155 "Define ABBREV as a mode-specific abbreviation for EXPANSION.") | 154 "Define ABBREV as a mode-specific abbreviation for EXPANSION.") |
156 (name, expansion) | 155 (name, expansion) |
157 Lisp_Object name, expansion; | 156 Lisp_Object name, expansion; |
158 { | 157 { |
159 if (NULL (current_buffer->abbrev_table)) | 158 if (NILP (current_buffer->abbrev_table)) |
160 error ("Major mode has no abbrev table"); | 159 error ("Major mode has no abbrev table"); |
161 | 160 |
162 Fdefine_abbrev (current_buffer->abbrev_table, Fdowncase (name), | 161 Fdefine_abbrev (current_buffer->abbrev_table, Fdowncase (name), |
163 expansion, Qnil, make_number (0)); | 162 expansion, Qnil, make_number (0)); |
164 return name; | 163 return name; |
174 (abbrev, table) | 173 (abbrev, table) |
175 Lisp_Object abbrev, table; | 174 Lisp_Object abbrev, table; |
176 { | 175 { |
177 Lisp_Object sym; | 176 Lisp_Object sym; |
178 CHECK_STRING (abbrev, 0); | 177 CHECK_STRING (abbrev, 0); |
179 if (!NULL (table)) | 178 if (!NILP (table)) |
180 sym = Fintern_soft (abbrev, table); | 179 sym = Fintern_soft (abbrev, table); |
181 else | 180 else |
182 { | 181 { |
183 sym = Qnil; | 182 sym = Qnil; |
184 if (!NULL (current_buffer->abbrev_table)) | 183 if (!NILP (current_buffer->abbrev_table)) |
185 sym = Fintern_soft (abbrev, current_buffer->abbrev_table); | 184 sym = Fintern_soft (abbrev, current_buffer->abbrev_table); |
186 if (NULL (XSYMBOL (sym)->value)) | 185 if (NILP (XSYMBOL (sym)->value)) |
187 sym = Qnil; | 186 sym = Qnil; |
188 if (NULL (sym)) | 187 if (NILP (sym)) |
189 sym = Fintern_soft (abbrev, Vglobal_abbrev_table); | 188 sym = Fintern_soft (abbrev, Vglobal_abbrev_table); |
190 } | 189 } |
191 if (NULL (XSYMBOL (sym)->value)) return Qnil; | 190 if (NILP (XSYMBOL (sym)->value)) return Qnil; |
192 return sym; | 191 return sym; |
193 } | 192 } |
194 | 193 |
195 DEFUN ("abbrev-expansion", Fabbrev_expansion, Sabbrev_expansion, 1, 2, 0, | 194 DEFUN ("abbrev-expansion", Fabbrev_expansion, Sabbrev_expansion, 1, 2, 0, |
196 "Return the string that ABBREV expands into in the current buffer.\n\ | 195 "Return the string that ABBREV expands into in the current buffer.\n\ |
199 (abbrev, table) | 198 (abbrev, table) |
200 Lisp_Object abbrev, table; | 199 Lisp_Object abbrev, table; |
201 { | 200 { |
202 Lisp_Object sym; | 201 Lisp_Object sym; |
203 sym = Fabbrev_symbol (abbrev, table); | 202 sym = Fabbrev_symbol (abbrev, table); |
204 if (NULL (sym)) return sym; | 203 if (NILP (sym)) return sym; |
205 return Fsymbol_value (sym); | 204 return Fsymbol_value (sym); |
206 } | 205 } |
207 | 206 |
208 /* Expand the word before point, if it is an abbrev. | 207 /* Expand the word before point, if it is an abbrev. |
209 Returns 1 if an expansion is done. */ | 208 Returns 1 if an expansion is done. */ |
219 int whitecnt; | 218 int whitecnt; |
220 int uccount = 0, lccount = 0; | 219 int uccount = 0, lccount = 0; |
221 register Lisp_Object sym; | 220 register Lisp_Object sym; |
222 Lisp_Object expansion, hook, tem; | 221 Lisp_Object expansion, hook, tem; |
223 | 222 |
224 if (!NULL (Vrun_hooks)) | 223 if (!NILP (Vrun_hooks)) |
225 call1 (Vrun_hooks, Qpre_abbrev_expand_hook); | 224 call1 (Vrun_hooks, Qpre_abbrev_expand_hook); |
226 | 225 |
227 if (XBUFFER (Vabbrev_start_location_buffer) != current_buffer) | 226 if (XBUFFER (Vabbrev_start_location_buffer) != current_buffer) |
228 Vabbrev_start_location = Qnil; | 227 Vabbrev_start_location = Qnil; |
229 if (!NULL (Vabbrev_start_location)) | 228 if (!NILP (Vabbrev_start_location)) |
230 { | 229 { |
231 tem = Vabbrev_start_location; | 230 tem = Vabbrev_start_location; |
232 CHECK_NUMBER_COERCE_MARKER (tem, 0); | 231 CHECK_NUMBER_COERCE_MARKER (tem, 0); |
233 wordstart = XINT (tem); | 232 wordstart = XINT (tem); |
234 Vabbrev_start_location = Qnil; | 233 Vabbrev_start_location = Qnil; |
265 | 264 |
266 if (XTYPE (current_buffer->abbrev_table) == Lisp_Vector) | 265 if (XTYPE (current_buffer->abbrev_table) == Lisp_Vector) |
267 sym = oblookup (current_buffer->abbrev_table, buffer, p - buffer); | 266 sym = oblookup (current_buffer->abbrev_table, buffer, p - buffer); |
268 else | 267 else |
269 XFASTINT (sym) = 0; | 268 XFASTINT (sym) = 0; |
270 if (XTYPE (sym) == Lisp_Int || NULL (XSYMBOL (sym)->value)) | 269 if (XTYPE (sym) == Lisp_Int || NILP (XSYMBOL (sym)->value)) |
271 sym = oblookup (Vglobal_abbrev_table, buffer, p - buffer); | 270 sym = oblookup (Vglobal_abbrev_table, buffer, p - buffer); |
272 if (XTYPE (sym) == Lisp_Int || NULL (XSYMBOL (sym)->value)) | 271 if (XTYPE (sym) == Lisp_Int || NILP (XSYMBOL (sym)->value)) |
273 return Qnil; | 272 return Qnil; |
274 | 273 |
275 if (INTERACTIVE && !EQ (minibuf_window, selected_window)) | 274 if (INTERACTIVE && !EQ (minibuf_window, selected_window)) |
276 { | 275 { |
277 SET_PT (wordend); | 276 SET_PT (wordend); |
325 SET_PT (old_pt); | 324 SET_PT (old_pt); |
326 ZV = old_zv; | 325 ZV = old_zv; |
327 } | 326 } |
328 | 327 |
329 hook = XSYMBOL (sym)->function; | 328 hook = XSYMBOL (sym)->function; |
330 if (!NULL (hook)) | 329 if (!NILP (hook)) |
331 call0 (hook); | 330 call0 (hook); |
332 | 331 |
333 return Qt; | 332 return Qt; |
334 } | 333 } |
335 | 334 |
365 static | 364 static |
366 write_abbrev (sym, stream) | 365 write_abbrev (sym, stream) |
367 Lisp_Object sym, stream; | 366 Lisp_Object sym, stream; |
368 { | 367 { |
369 Lisp_Object name; | 368 Lisp_Object name; |
370 if (NULL (XSYMBOL (sym)->value)) | 369 if (NILP (XSYMBOL (sym)->value)) |
371 return; | 370 return; |
372 insert (" (", 5); | 371 insert (" (", 5); |
373 XSET (name, Lisp_String, XSYMBOL (sym)->name); | 372 XSET (name, Lisp_String, XSYMBOL (sym)->name); |
374 Fprin1 (name, stream); | 373 Fprin1 (name, stream); |
375 insert (" ", 1); | 374 insert (" ", 1); |
385 describe_abbrev (sym, stream) | 384 describe_abbrev (sym, stream) |
386 Lisp_Object sym, stream; | 385 Lisp_Object sym, stream; |
387 { | 386 { |
388 Lisp_Object one; | 387 Lisp_Object one; |
389 | 388 |
390 if (NULL (XSYMBOL (sym)->value)) | 389 if (NILP (XSYMBOL (sym)->value)) |
391 return; | 390 return; |
392 one = make_number (1); | 391 one = make_number (1); |
393 Fprin1 (Fsymbol_name (sym), stream); | 392 Fprin1 (Fsymbol_name (sym), stream); |
394 Findent_to (make_number (15), one); | 393 Findent_to (make_number (15), one); |
395 Fprin1 (XSYMBOL (sym)->plist, stream); | 394 Fprin1 (XSYMBOL (sym)->plist, stream); |
396 Findent_to (make_number (20), one); | 395 Findent_to (make_number (20), one); |
397 Fprin1 (XSYMBOL (sym)->value, stream); | 396 Fprin1 (XSYMBOL (sym)->value, stream); |
398 if (!NULL (XSYMBOL (sym)->function)) | 397 if (!NILP (XSYMBOL (sym)->function)) |
399 { | 398 { |
400 Findent_to (make_number (45), one); | 399 Findent_to (make_number (45), one); |
401 Fprin1 (XSYMBOL (sym)->function, stream); | 400 Fprin1 (XSYMBOL (sym)->function, stream); |
402 } | 401 } |
403 Fterpri (stream); | 402 Fterpri (stream); |
422 table = Fsymbol_value (name); | 421 table = Fsymbol_value (name); |
423 CHECK_VECTOR (table, 0); | 422 CHECK_VECTOR (table, 0); |
424 | 423 |
425 XSET (stream, Lisp_Buffer, current_buffer); | 424 XSET (stream, Lisp_Buffer, current_buffer); |
426 | 425 |
427 if (!NULL (readable)) | 426 if (!NILP (readable)) |
428 { | 427 { |
429 insert_string ("("); | 428 insert_string ("("); |
430 Fprin1 (name, stream); | 429 Fprin1 (name, stream); |
431 insert_string (")\n\n"); | 430 insert_string (")\n\n"); |
432 map_obarray (table, describe_abbrev, stream); | 431 map_obarray (table, describe_abbrev, stream); |
455 Lisp_Object name, exp, hook, count; | 454 Lisp_Object name, exp, hook, count; |
456 Lisp_Object table, elt; | 455 Lisp_Object table, elt; |
457 | 456 |
458 CHECK_SYMBOL (tabname, 0); | 457 CHECK_SYMBOL (tabname, 0); |
459 table = Fboundp (tabname); | 458 table = Fboundp (tabname); |
460 if (NULL (table) || (table = Fsymbol_value (tabname), NULL (table))) | 459 if (NILP (table) || (table = Fsymbol_value (tabname), NILP (table))) |
461 { | 460 { |
462 table = Fmake_abbrev_table (); | 461 table = Fmake_abbrev_table (); |
463 Fset (tabname, table); | 462 Fset (tabname, table); |
464 Vabbrev_table_name_list = | 463 Vabbrev_table_name_list = |
465 Fcons (tabname, Vabbrev_table_name_list); | 464 Fcons (tabname, Vabbrev_table_name_list); |
466 } | 465 } |
467 CHECK_VECTOR (table, 0); | 466 CHECK_VECTOR (table, 0); |
468 | 467 |
469 for (;!NULL (defns); defns = Fcdr (defns)) | 468 for (;!NILP (defns); defns = Fcdr (defns)) |
470 { | 469 { |
471 elt = Fcar (defns); | 470 elt = Fcar (defns); |
472 name = Fcar (elt); | 471 name = Fcar (elt); |
473 elt = Fcdr (elt); | 472 elt = Fcdr (elt); |
474 exp = Fcar (elt); | 473 exp = Fcar (elt); |