comparison src/casefiddle.c @ 12089:f7cb17ca1815

(casify_region): Use explicit local vars for start and end, so that the type will be correct. (operate_on_word): Likewise for iarg in this function. (upcase_initials, upcase_initials_region): Deleted; these were redundant copies of Fupcase_initials and Fupcase_initials_region.
author Karl Heuer <kwzh@gnu.org>
date Tue, 06 Jun 1995 01:43:42 +0000
parents e8c880f2723e
children ac7375e60931
comparison
equal deleted inserted replaced
12088:f0c9d02fb6e4 12089:f7cb17ca1815
101 Lisp_Object obj; 101 Lisp_Object obj;
102 { 102 {
103 return casify_object (CASE_CAPITALIZE, obj); 103 return casify_object (CASE_CAPITALIZE, obj);
104 } 104 }
105 105
106 /* Like Fcapitalize but change only the initials. */
107
106 DEFUN ("upcase-initials", Fupcase_initials, Supcase_initials, 1, 1, 0, 108 DEFUN ("upcase-initials", Fupcase_initials, Supcase_initials, 1, 1, 0,
107 "Convert the initial of each word in the argument to upper case.\n\ 109 "Convert the initial of each word in the argument to upper case.\n\
108 Do not change the other letters of each word.\n\ 110 Do not change the other letters of each word.\n\
109 The argument may be a character or string. The result has the same type.\n\ 111 The argument may be a character or string. The result has the same type.\n\
110 The argument object is not altered--the value is a copy.") 112 The argument object is not altered--the value is a copy.")
111 (obj) 113 (obj)
112 Lisp_Object obj; 114 Lisp_Object obj;
113 { 115 {
114 return casify_object (CASE_CAPITALIZE_UP, obj); 116 return casify_object (CASE_CAPITALIZE_UP, obj);
115 } 117 }
116
117 /* Like Fcapitalize but change only the initials. */
118
119 Lisp_Object
120 upcase_initials (obj)
121 Lisp_Object obj;
122 {
123 return casify_object (CASE_CAPITALIZE_UP, obj);
124 }
125 118
126 /* flag is CASE_UP, CASE_DOWN or CASE_CAPITALIZE or CASE_CAPITALIZE_UP. 119 /* flag is CASE_UP, CASE_DOWN or CASE_CAPITALIZE or CASE_CAPITALIZE_UP.
127 b and e specify range of buffer to operate on. */ 120 b and e specify range of buffer to operate on. */
128 121
129 casify_region (flag, b, e) 122 casify_region (flag, b, e)
131 Lisp_Object b, e; 124 Lisp_Object b, e;
132 { 125 {
133 register int i; 126 register int i;
134 register int c; 127 register int c;
135 register int inword = flag == CASE_DOWN; 128 register int inword = flag == CASE_DOWN;
129 int start, end;
136 130
137 if (EQ (b, e)) 131 if (EQ (b, e))
138 /* Not modifying because nothing marked */ 132 /* Not modifying because nothing marked */
139 return; 133 return;
140 134
141 validate_region (&b, &e); 135 validate_region (&b, &e);
142 modify_region (current_buffer, XFASTINT (b), XFASTINT (e)); 136 start = XFASTINT (b);
143 record_change (XFASTINT (b), XFASTINT (e) - XFASTINT (b)); 137 end = XFASTINT (e);
144 138 modify_region (current_buffer, start, end);
145 for (i = XFASTINT (b); i < XFASTINT (e); i++) 139 record_change (start, end - start);
140
141 for (i = start; i < end; i++)
146 { 142 {
147 c = FETCH_CHAR (i); 143 c = FETCH_CHAR (i);
148 if (inword && flag != CASE_CAPITALIZE_UP) 144 if (inword && flag != CASE_CAPITALIZE_UP)
149 c = DOWNCASE (c); 145 c = DOWNCASE (c);
150 else if (!UPPERCASEP (c) 146 else if (!UPPERCASEP (c)
153 FETCH_CHAR (i) = c; 149 FETCH_CHAR (i) = c;
154 if ((int) flag >= (int) CASE_CAPITALIZE) 150 if ((int) flag >= (int) CASE_CAPITALIZE)
155 inword = SYNTAX (c) == Sword; 151 inword = SYNTAX (c) == Sword;
156 } 152 }
157 153
158 signal_after_change (XFASTINT (b), 154 signal_after_change (start, end - start, end - start);
159 XFASTINT (e) - XFASTINT (b),
160 XFASTINT (e) - XFASTINT (b));
161 } 155 }
162 156
163 DEFUN ("upcase-region", Fupcase_region, Supcase_region, 2, 2, "r", 157 DEFUN ("upcase-region", Fupcase_region, Supcase_region, 2, 2, "r",
164 "Convert the region to upper case. In programs, wants two arguments.\n\ 158 "Convert the region to upper case. In programs, wants two arguments.\n\
165 These arguments specify the starting and ending character numbers of\n\ 159 These arguments specify the starting and ending character numbers of\n\
196 { 190 {
197 casify_region (CASE_CAPITALIZE, b, e); 191 casify_region (CASE_CAPITALIZE, b, e);
198 return Qnil; 192 return Qnil;
199 } 193 }
200 194
195 /* Like Fcapitalize_region but change only the initials. */
196
201 DEFUN ("upcase-initials-region", Fupcase_initials_region, 197 DEFUN ("upcase-initials-region", Fupcase_initials_region,
202 Supcase_initials_region, 2, 2, "r", 198 Supcase_initials_region, 2, 2, "r",
203 "Upcase the initial of each word in the region.\n\ 199 "Upcase the initial of each word in the region.\n\
204 Subsequent letters of each word are not changed.\n\ 200 Subsequent letters of each word are not changed.\n\
205 In programs, give two arguments, the starting and ending\n\ 201 In programs, give two arguments, the starting and ending\n\
208 Lisp_Object b, e; 204 Lisp_Object b, e;
209 { 205 {
210 casify_region (CASE_CAPITALIZE_UP, b, e); 206 casify_region (CASE_CAPITALIZE_UP, b, e);
211 return Qnil; 207 return Qnil;
212 } 208 }
213
214 /* Like Fcapitalize_region but change only the initials. */
215
216 Lisp_Object
217 upcase_initials_region (b, e)
218 Lisp_Object b, e;
219 {
220 casify_region (CASE_CAPITALIZE_UP, b, e);
221 return Qnil;
222 }
223 209
224 Lisp_Object 210 Lisp_Object
225 operate_on_word (arg, newpoint) 211 operate_on_word (arg, newpoint)
226 Lisp_Object arg; 212 Lisp_Object arg;
227 int *newpoint; 213 int *newpoint;
228 { 214 {
229 Lisp_Object val; 215 Lisp_Object val;
230 int farend; 216 int farend;
217 int iarg;
231 218
232 CHECK_NUMBER (arg, 0); 219 CHECK_NUMBER (arg, 0);
233 farend = scan_words (point, XINT (arg)); 220 iarg = XINT (arg);
221 farend = scan_words (point, iarg);
234 if (!farend) 222 if (!farend)
235 farend = XINT (arg) > 0 ? ZV : BEGV; 223 farend = iarg > 0 ? ZV : BEGV;
236 224
237 *newpoint = point > farend ? point : farend; 225 *newpoint = point > farend ? point : farend;
238 XSETFASTINT (val, farend); 226 XSETFASTINT (val, farend);
239 227
240 return val; 228 return val;