diff options
| author | Richard M. Stallman | 1996-11-12 04:13:06 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1996-11-12 04:13:06 +0000 |
| commit | b7734773b91ec2de50d1fe6c886b078556a4cff7 (patch) | |
| tree | c8b80d93cf310cdce5966c5c91e214784247afb8 /src | |
| parent | 07d402c8dbd99e2da1c365d26ce2b3f18a3a4a2b (diff) | |
| download | emacs-b7734773b91ec2de50d1fe6c886b078556a4cff7.tar.gz emacs-b7734773b91ec2de50d1fe6c886b078556a4cff7.zip | |
(Fexpand_abbrev): If the abbrev's expansion is nil,
don't expand it, but do still call the hook.
(Fdefine_abbrev): Allow anything for EXPANSION.
Diffstat (limited to 'src')
| -rw-r--r-- | src/abbrev.c | 86 |
1 files changed, 48 insertions, 38 deletions
diff --git a/src/abbrev.c b/src/abbrev.c index 240f668d090..61f053b4d46 100644 --- a/src/abbrev.c +++ b/src/abbrev.c | |||
| @@ -104,18 +104,20 @@ DEFUN ("clear-abbrev-table", Fclear_abbrev_table, Sclear_abbrev_table, 1, 1, 0, | |||
| 104 | 104 | ||
| 105 | DEFUN ("define-abbrev", Fdefine_abbrev, Sdefine_abbrev, 3, 5, 0, | 105 | DEFUN ("define-abbrev", Fdefine_abbrev, Sdefine_abbrev, 3, 5, 0, |
| 106 | "Define an abbrev in TABLE named NAME, to expand to EXPANSION and call HOOK.\n\ | 106 | "Define an abbrev in TABLE named NAME, to expand to EXPANSION and call HOOK.\n\ |
| 107 | NAME and EXPANSION are strings.\n\ | 107 | NAME must be a string.\n\ |
| 108 | EXPANSION should usually be a string.\n\ | ||
| 108 | To undefine an abbrev, define it with EXPANSION = nil.\n\ | 109 | To undefine an abbrev, define it with EXPANSION = nil.\n\ |
| 109 | If HOOK is non-nil, it should be a function of no arguments;\n\ | 110 | If HOOK is non-nil, it should be a function of no arguments;\n\ |
| 110 | it is called after EXPANSION is inserted.") | 111 | it is called after EXPANSION is inserted.\n\ |
| 112 | If EXPANSION is not a string, the abbrev is a special one,\n\ | ||
| 113 | which does not expand in the usual way but only runs HOOK.") | ||
| 111 | (table, name, expansion, hook, count) | 114 | (table, name, expansion, hook, count) |
| 112 | Lisp_Object table, name, expansion, hook, count; | 115 | Lisp_Object table, name, expansion, hook, count; |
| 113 | { | 116 | { |
| 114 | Lisp_Object sym, oexp, ohook, tem; | 117 | Lisp_Object sym, oexp, ohook, tem; |
| 115 | CHECK_VECTOR (table, 0); | 118 | CHECK_VECTOR (table, 0); |
| 116 | CHECK_STRING (name, 1); | 119 | CHECK_STRING (name, 1); |
| 117 | if (!NILP (expansion)) | 120 | |
| 118 | CHECK_STRING (expansion, 2); | ||
| 119 | if (NILP (count)) | 121 | if (NILP (count)) |
| 120 | count = make_number (0); | 122 | count = make_number (0); |
| 121 | else | 123 | else |
| @@ -289,12 +291,11 @@ Returns t if expansion took place.") | |||
| 289 | SET_PT (wordend); | 291 | SET_PT (wordend); |
| 290 | Fundo_boundary (); | 292 | Fundo_boundary (); |
| 291 | } | 293 | } |
| 292 | SET_PT (wordstart); | 294 | |
| 293 | Vlast_abbrev_text | 295 | Vlast_abbrev_text |
| 294 | = Fbuffer_substring (make_number (wordstart), make_number (wordend)); | 296 | = Fbuffer_substring (make_number (wordstart), make_number (wordend)); |
| 295 | del_range (wordstart, wordend); | ||
| 296 | 297 | ||
| 297 | /* Now sym is the abbrev symbol. */ | 298 | /* Now sym is the abbrev symbol. */ |
| 298 | Vlast_abbrev = sym; | 299 | Vlast_abbrev = sym; |
| 299 | last_abbrev_point = wordstart; | 300 | last_abbrev_point = wordstart; |
| 300 | 301 | ||
| @@ -302,39 +303,48 @@ Returns t if expansion took place.") | |||
| 302 | XSETINT (XSYMBOL (sym)->plist, | 303 | XSETINT (XSYMBOL (sym)->plist, |
| 303 | XINT (XSYMBOL (sym)->plist) + 1); /* Increment use count */ | 304 | XINT (XSYMBOL (sym)->plist) + 1); /* Increment use count */ |
| 304 | 305 | ||
| 306 | /* If this abbrev has an expansion, delete the abbrev | ||
| 307 | and insert the expansion. */ | ||
| 305 | expansion = XSYMBOL (sym)->value; | 308 | expansion = XSYMBOL (sym)->value; |
| 306 | insert_from_string (expansion, 0, XSTRING (expansion)->size, 1); | 309 | if (STRINGP (expansion)) |
| 307 | SET_PT (PT + whitecnt); | ||
| 308 | |||
| 309 | if (uccount && !lccount) | ||
| 310 | { | 310 | { |
| 311 | /* Abbrev was all caps */ | 311 | SET_PT (wordstart); |
| 312 | /* If expansion is multiple words, normally capitalize each word */ | 312 | |
| 313 | /* This used to be if (!... && ... >= ...) Fcapitalize; else Fupcase | 313 | del_range (wordstart, wordend); |
| 314 | but Megatest 68000 compiler can't handle that */ | 314 | |
| 315 | if (!abbrev_all_caps) | 315 | insert_from_string (expansion, 0, XSTRING (expansion)->size, 1); |
| 316 | if (scan_words (PT, -1) > scan_words (wordstart, 1)) | 316 | SET_PT (PT + whitecnt); |
| 317 | { | 317 | |
| 318 | Fupcase_initials_region (make_number (wordstart), | 318 | if (uccount && !lccount) |
| 319 | make_number (PT)); | 319 | { |
| 320 | goto caped; | 320 | /* Abbrev was all caps */ |
| 321 | } | 321 | /* If expansion is multiple words, normally capitalize each word */ |
| 322 | /* If expansion is one word, or if user says so, upcase it all. */ | 322 | /* This used to be if (!... && ... >= ...) Fcapitalize; else Fupcase |
| 323 | Fupcase_region (make_number (wordstart), make_number (PT)); | 323 | but Megatest 68000 compiler can't handle that */ |
| 324 | caped: ; | 324 | if (!abbrev_all_caps) |
| 325 | } | 325 | if (scan_words (PT, -1) > scan_words (wordstart, 1)) |
| 326 | else if (uccount) | 326 | { |
| 327 | { | 327 | Fupcase_initials_region (make_number (wordstart), |
| 328 | /* Abbrev included some caps. Cap first initial of expansion */ | 328 | make_number (PT)); |
| 329 | int pos = wordstart; | 329 | goto caped; |
| 330 | 330 | } | |
| 331 | /* Find the initial. */ | 331 | /* If expansion is one word, or if user says so, upcase it all. */ |
| 332 | while (pos < PT | 332 | Fupcase_region (make_number (wordstart), make_number (PT)); |
| 333 | && SYNTAX (*BUF_CHAR_ADDRESS (current_buffer, pos)) != Sword) | 333 | caped: ; |
| 334 | pos++; | 334 | } |
| 335 | 335 | else if (uccount) | |
| 336 | /* Change just that. */ | 336 | { |
| 337 | Fupcase_initials_region (make_number (pos), make_number (pos + 1)); | 337 | /* Abbrev included some caps. Cap first initial of expansion */ |
| 338 | int pos = wordstart; | ||
| 339 | |||
| 340 | /* Find the initial. */ | ||
| 341 | while (pos < PT | ||
| 342 | && SYNTAX (*BUF_CHAR_ADDRESS (current_buffer, pos)) != Sword) | ||
| 343 | pos++; | ||
| 344 | |||
| 345 | /* Change just that. */ | ||
| 346 | Fupcase_initials_region (make_number (pos), make_number (pos + 1)); | ||
| 347 | } | ||
| 338 | } | 348 | } |
| 339 | 349 | ||
| 340 | hook = XSYMBOL (sym)->function; | 350 | hook = XSYMBOL (sym)->function; |