aboutsummaryrefslogtreecommitdiffstats
path: root/src/casefiddle.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/casefiddle.c')
-rw-r--r--src/casefiddle.c56
1 files changed, 21 insertions, 35 deletions
diff --git a/src/casefiddle.c b/src/casefiddle.c
index 30bb457b17d..b6551618b2f 100644
--- a/src/casefiddle.c
+++ b/src/casefiddle.c
@@ -33,9 +33,7 @@ enum case_action {CASE_UP, CASE_DOWN, CASE_CAPITALIZE, CASE_CAPITALIZE_UP};
33Lisp_Object Qidentity; 33Lisp_Object Qidentity;
34 34
35Lisp_Object 35Lisp_Object
36casify_object (flag, obj) 36casify_object (enum case_action flag, Lisp_Object obj)
37 enum case_action flag;
38 Lisp_Object obj;
39{ 37{
40 register int c, c1; 38 register int c, c1;
41 register int inword = flag == CASE_DOWN; 39 register int inword = flag == CASE_DOWN;
@@ -130,7 +128,7 @@ casify_object (flag, obj)
130 unsigned char *old_dst = dst; 128 unsigned char *old_dst = dst;
131 o_size += o_size; /* Probably overkill, but extremely rare. */ 129 o_size += o_size; /* Probably overkill, but extremely rare. */
132 SAFE_ALLOCA (dst, void *, o_size); 130 SAFE_ALLOCA (dst, void *, o_size);
133 bcopy (old_dst, dst, o - old_dst); 131 memcpy (dst, old_dst, o - old_dst);
134 o = dst + (o - old_dst); 132 o = dst + (o - old_dst);
135 } 133 }
136 c = STRING_CHAR_AND_LENGTH (SDATA (obj) + i_byte, len); 134 c = STRING_CHAR_AND_LENGTH (SDATA (obj) + i_byte, len);
@@ -155,8 +153,7 @@ DEFUN ("upcase", Fupcase, Supcase, 1, 1, 0,
155The argument may be a character or string. The result has the same type. 153The argument may be a character or string. The result has the same type.
156The argument object is not altered--the value is a copy. 154The argument object is not altered--the value is a copy.
157See also `capitalize', `downcase' and `upcase-initials'. */) 155See also `capitalize', `downcase' and `upcase-initials'. */)
158 (obj) 156 (Lisp_Object obj)
159 Lisp_Object obj;
160{ 157{
161 return casify_object (CASE_UP, obj); 158 return casify_object (CASE_UP, obj);
162} 159}
@@ -165,8 +162,7 @@ DEFUN ("downcase", Fdowncase, Sdowncase, 1, 1, 0,
165 doc: /* Convert argument to lower case and return that. 162 doc: /* Convert argument to lower case and return that.
166The argument may be a character or string. The result has the same type. 163The argument may be a character or string. The result has the same type.
167The argument object is not altered--the value is a copy. */) 164The argument object is not altered--the value is a copy. */)
168 (obj) 165 (Lisp_Object obj)
169 Lisp_Object obj;
170{ 166{
171 return casify_object (CASE_DOWN, obj); 167 return casify_object (CASE_DOWN, obj);
172} 168}
@@ -177,8 +173,7 @@ This means that each word's first character is upper case
177and the rest is lower case. 173and the rest is lower case.
178The argument may be a character or string. The result has the same type. 174The argument may be a character or string. The result has the same type.
179The argument object is not altered--the value is a copy. */) 175The argument object is not altered--the value is a copy. */)
180 (obj) 176 (Lisp_Object obj)
181 Lisp_Object obj;
182{ 177{
183 return casify_object (CASE_CAPITALIZE, obj); 178 return casify_object (CASE_CAPITALIZE, obj);
184} 179}
@@ -190,8 +185,7 @@ DEFUN ("upcase-initials", Fupcase_initials, Supcase_initials, 1, 1, 0,
190Do not change the other letters of each word. 185Do not change the other letters of each word.
191The argument may be a character or string. The result has the same type. 186The argument may be a character or string. The result has the same type.
192The argument object is not altered--the value is a copy. */) 187The argument object is not altered--the value is a copy. */)
193 (obj) 188 (Lisp_Object obj)
194 Lisp_Object obj;
195{ 189{
196 return casify_object (CASE_CAPITALIZE_UP, obj); 190 return casify_object (CASE_CAPITALIZE_UP, obj);
197} 191}
@@ -200,9 +194,7 @@ The argument object is not altered--the value is a copy. */)
200 b and e specify range of buffer to operate on. */ 194 b and e specify range of buffer to operate on. */
201 195
202void 196void
203casify_region (flag, b, e) 197casify_region (enum case_action flag, Lisp_Object b, Lisp_Object e)
204 enum case_action flag;
205 Lisp_Object b, e;
206{ 198{
207 register int c; 199 register int c;
208 register int inword = flag == CASE_DOWN; 200 register int inword = flag == CASE_DOWN;
@@ -229,6 +221,8 @@ casify_region (flag, b, e)
229 start_byte = CHAR_TO_BYTE (start); 221 start_byte = CHAR_TO_BYTE (start);
230 end_byte = CHAR_TO_BYTE (end); 222 end_byte = CHAR_TO_BYTE (end);
231 223
224 SETUP_BUFFER_SYNTAX_TABLE(); /* For syntax_prefix_flag_p. */
225
232 while (start < end) 226 while (start < end)
233 { 227 {
234 int c2, len; 228 int c2, len;
@@ -251,7 +245,8 @@ casify_region (flag, b, e)
251 && (!inword || flag != CASE_CAPITALIZE_UP)) 245 && (!inword || flag != CASE_CAPITALIZE_UP))
252 c = UPCASE1 (c); 246 c = UPCASE1 (c);
253 if ((int) flag >= (int) CASE_CAPITALIZE) 247 if ((int) flag >= (int) CASE_CAPITALIZE)
254 inword = ((SYNTAX (c) == Sword) && (inword || !SYNTAX_PREFIX (c))); 248 inword = ((SYNTAX (c) == Sword)
249 && (inword || !syntax_prefix_flag_p (c)));
255 if (c != c2) 250 if (c != c2)
256 { 251 {
257 last = start; 252 last = start;
@@ -310,8 +305,7 @@ These arguments specify the starting and ending character numbers of
310the region to operate on. When used as a command, the text between 305the region to operate on. When used as a command, the text between
311point and the mark is operated on. 306point and the mark is operated on.
312See also `capitalize-region'. */) 307See also `capitalize-region'. */)
313 (beg, end) 308 (Lisp_Object beg, Lisp_Object end)
314 Lisp_Object beg, end;
315{ 309{
316 casify_region (CASE_UP, beg, end); 310 casify_region (CASE_UP, beg, end);
317 return Qnil; 311 return Qnil;
@@ -322,8 +316,7 @@ DEFUN ("downcase-region", Fdowncase_region, Sdowncase_region, 2, 2, "r",
322These arguments specify the starting and ending character numbers of 316These arguments specify the starting and ending character numbers of
323the region to operate on. When used as a command, the text between 317the region to operate on. When used as a command, the text between
324point and the mark is operated on. */) 318point and the mark is operated on. */)
325 (beg, end) 319 (Lisp_Object beg, Lisp_Object end)
326 Lisp_Object beg, end;
327{ 320{
328 casify_region (CASE_DOWN, beg, end); 321 casify_region (CASE_DOWN, beg, end);
329 return Qnil; 322 return Qnil;
@@ -335,8 +328,7 @@ Capitalized form means each word's first character is upper case
335and the rest of it is lower case. 328and the rest of it is lower case.
336In programs, give two arguments, the starting and ending 329In programs, give two arguments, the starting and ending
337character positions to operate on. */) 330character positions to operate on. */)
338 (beg, end) 331 (Lisp_Object beg, Lisp_Object end)
339 Lisp_Object beg, end;
340{ 332{
341 casify_region (CASE_CAPITALIZE, beg, end); 333 casify_region (CASE_CAPITALIZE, beg, end);
342 return Qnil; 334 return Qnil;
@@ -350,17 +342,14 @@ DEFUN ("upcase-initials-region", Fupcase_initials_region,
350Subsequent letters of each word are not changed. 342Subsequent letters of each word are not changed.
351In programs, give two arguments, the starting and ending 343In programs, give two arguments, the starting and ending
352character positions to operate on. */) 344character positions to operate on. */)
353 (beg, end) 345 (Lisp_Object beg, Lisp_Object end)
354 Lisp_Object beg, end;
355{ 346{
356 casify_region (CASE_CAPITALIZE_UP, beg, end); 347 casify_region (CASE_CAPITALIZE_UP, beg, end);
357 return Qnil; 348 return Qnil;
358} 349}
359 350
360static Lisp_Object 351static Lisp_Object
361operate_on_word (arg, newpoint) 352operate_on_word (Lisp_Object arg, EMACS_INT *newpoint)
362 Lisp_Object arg;
363 EMACS_INT *newpoint;
364{ 353{
365 Lisp_Object val; 354 Lisp_Object val;
366 int farend; 355 int farend;
@@ -382,8 +371,7 @@ DEFUN ("upcase-word", Fupcase_word, Supcase_word, 1, 1, "p",
382 doc: /* Convert following word (or ARG words) to upper case, moving over. 371 doc: /* Convert following word (or ARG words) to upper case, moving over.
383With negative argument, convert previous words but do not move. 372With negative argument, convert previous words but do not move.
384See also `capitalize-word'. */) 373See also `capitalize-word'. */)
385 (arg) 374 (Lisp_Object arg)
386 Lisp_Object arg;
387{ 375{
388 Lisp_Object beg, end; 376 Lisp_Object beg, end;
389 EMACS_INT newpoint; 377 EMACS_INT newpoint;
@@ -397,8 +385,7 @@ See also `capitalize-word'. */)
397DEFUN ("downcase-word", Fdowncase_word, Sdowncase_word, 1, 1, "p", 385DEFUN ("downcase-word", Fdowncase_word, Sdowncase_word, 1, 1, "p",
398 doc: /* Convert following word (or ARG words) to lower case, moving over. 386 doc: /* Convert following word (or ARG words) to lower case, moving over.
399With negative argument, convert previous words but do not move. */) 387With negative argument, convert previous words but do not move. */)
400 (arg) 388 (Lisp_Object arg)
401 Lisp_Object arg;
402{ 389{
403 Lisp_Object beg, end; 390 Lisp_Object beg, end;
404 EMACS_INT newpoint; 391 EMACS_INT newpoint;
@@ -414,8 +401,7 @@ DEFUN ("capitalize-word", Fcapitalize_word, Scapitalize_word, 1, 1, "p",
414This gives the word(s) a first character in upper case 401This gives the word(s) a first character in upper case
415and the rest lower case. 402and the rest lower case.
416With negative argument, capitalize previous words but do not move. */) 403With negative argument, capitalize previous words but do not move. */)
417 (arg) 404 (Lisp_Object arg)
418 Lisp_Object arg;
419{ 405{
420 Lisp_Object beg, end; 406 Lisp_Object beg, end;
421 EMACS_INT newpoint; 407 EMACS_INT newpoint;
@@ -427,7 +413,7 @@ With negative argument, capitalize previous words but do not move. */)
427} 413}
428 414
429void 415void
430syms_of_casefiddle () 416syms_of_casefiddle (void)
431{ 417{
432 Qidentity = intern_c_string ("identity"); 418 Qidentity = intern_c_string ("identity");
433 staticpro (&Qidentity); 419 staticpro (&Qidentity);
@@ -445,7 +431,7 @@ syms_of_casefiddle ()
445} 431}
446 432
447void 433void
448keys_of_casefiddle () 434keys_of_casefiddle (void)
449{ 435{
450 initial_define_key (control_x_map, Ctl('U'), "upcase-region"); 436 initial_define_key (control_x_map, Ctl('U'), "upcase-region");
451 Fput (intern ("upcase-region"), Qdisabled, Qt); 437 Fput (intern ("upcase-region"), Qdisabled, Qt);