@@ -33,6 +33,9 @@ enum case_action {CASE_UP, CASE_DOWN, CASE_CAPITALIZE, CASE_CAPITALIZE_UP};
33
33
34
34
/* State for casing individual characters. */
35
35
struct casing_context {
36
+ /* A char-table with title-case character mappings or nil. Non-nil implies
37
+ flag is CASE_CAPITALIZE or CASE_CAPITALIZE_UP. */
38
+ Lisp_Object titlecase_char_table ;
36
39
/* User-requested action. */
37
40
enum case_action flag ;
38
41
/* If true, function operates on a buffer as opposed to a string or character.
@@ -53,6 +56,8 @@ prepare_casing_context (struct casing_context *ctx,
53
56
ctx -> flag = flag ;
54
57
ctx -> inbuffer = inbuffer ;
55
58
ctx -> inword = flag == CASE_DOWN ;
59
+ ctx -> titlecase_char_table = (int )flag < (int )CASE_CAPITALIZE ? Qnil :
60
+ uniprop_table (intern_c_string ("titlecase" ));
56
61
57
62
/* If the case table is flagged as modified, rescan it. */
58
63
if (NILP (XCHAR_TABLE (BVAR (current_buffer , downcase_table ))-> extras [1 ]))
@@ -67,10 +72,16 @@ prepare_casing_context (struct casing_context *ctx,
67
72
static int
68
73
case_character (struct casing_context * ctx , int ch )
69
74
{
75
+ Lisp_Object prop ;
76
+
70
77
if (ctx -> inword )
71
78
ch = ctx -> flag == CASE_CAPITALIZE_UP ? ch : downcase (ch );
79
+ else if (!NILP (ctx -> titlecase_char_table ) &&
80
+ CHARACTERP (prop = CHAR_TABLE_REF (ctx -> titlecase_char_table , ch )))
81
+ ch = XFASTINT (prop );
72
82
else
73
83
ch = upcase (ch );
84
+
74
85
if ((int ) ctx -> flag >= (int ) CASE_CAPITALIZE )
75
86
ctx -> inword = SYNTAX (ch ) == Sword &&
76
87
(!ctx -> inbuffer || ctx -> inword || !syntax_prefix_flag_p (ch ));
@@ -198,8 +209,8 @@ The argument object is not altered--the value is a copy. */)
198
209
199
210
DEFUN ("capitalize" , Fcapitalize , Scapitalize , 1 , 1 , 0 ,
200
211
doc : /* Convert argument to capitalized form and return that.
201
- This means that each word's first character is upper case
202
- and the rest is lower case.
212
+ This means that each word's first character is converted to either
213
+ title case or upper case, and the rest to lower case.
203
214
The argument may be a character or string. The result has the same type.
204
215
The argument object is not altered--the value is a copy. */ )
205
216
(Lisp_Object obj )
@@ -211,7 +222,8 @@ The argument object is not altered--the value is a copy. */)
211
222
212
223
DEFUN ("upcase-initials" , Fupcase_initials , Supcase_initials , 1 , 1 , 0 ,
213
224
doc : /* Convert the initial of each word in the argument to upper case.
214
- Do not change the other letters of each word.
225
+ This means that each word's first character is converted to either
226
+ title case or upper case, and the rest are left unchanged.
215
227
The argument may be a character or string. The result has the same type.
216
228
The argument object is not altered--the value is a copy. */ )
217
229
(Lisp_Object obj )
@@ -375,8 +387,8 @@ point and the mark is operated on. */)
375
387
376
388
DEFUN ("capitalize-region" , Fcapitalize_region , Scapitalize_region , 2 , 2 , "r" ,
377
389
doc : /* Convert the region to capitalized form.
378
- Capitalized form means each word's first character is upper case
379
- and the rest of it is lower case.
390
+ This means that each word's first character is converted to either
391
+ title case or upper case, and the rest to lower case.
380
392
In programs, give two arguments, the starting and ending
381
393
character positions to operate on. */ )
382
394
(Lisp_Object beg , Lisp_Object end )
@@ -390,7 +402,8 @@ character positions to operate on. */)
390
402
DEFUN ("upcase-initials-region" , Fupcase_initials_region ,
391
403
Supcase_initials_region , 2 , 2 , "r" ,
392
404
doc : /* Upcase the initial of each word in the region.
393
- Subsequent letters of each word are not changed.
405
+ This means that each word's first character is converted to either
406
+ title case or upper case, and the rest are left unchanged.
394
407
In programs, give two arguments, the starting and ending
395
408
character positions to operate on. */ )
396
409
(Lisp_Object beg , Lisp_Object end )
0 commit comments