aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKarl Heuer1997-05-15 07:47:29 +0000
committerKarl Heuer1997-05-15 07:47:29 +0000
commita04538dade7ccd41887026fa5582640fca3b785b (patch)
tree31204a002728af06c88d08f9945d2e5e61039281
parente16696bacc4aa567d04fa725cc4c1f2913d6e2c7 (diff)
downloademacs-a04538dade7ccd41887026fa5582640fca3b785b.tar.gz
emacs-a04538dade7ccd41887026fa5582640fca3b785b.zip
Include charset.h.
(Qidentity): Define this variable. (syms_of_casefiddle): Initialize and staticpro it. (casify_object, casify_region): Handle multibyte.
-rw-r--r--src/casefiddle.c107
1 files changed, 91 insertions, 16 deletions
diff --git a/src/casefiddle.c b/src/casefiddle.c
index b0cc0b94991..7780b29d0e3 100644
--- a/src/casefiddle.c
+++ b/src/casefiddle.c
@@ -22,10 +22,13 @@ Boston, MA 02111-1307, USA. */
22#include <config.h> 22#include <config.h>
23#include "lisp.h" 23#include "lisp.h"
24#include "buffer.h" 24#include "buffer.h"
25#include "charset.h"
25#include "commands.h" 26#include "commands.h"
26#include "syntax.h" 27#include "syntax.h"
27 28
28enum case_action {CASE_UP, CASE_DOWN, CASE_CAPITALIZE, CASE_CAPITALIZE_UP}; 29enum case_action {CASE_UP, CASE_DOWN, CASE_CAPITALIZE, CASE_CAPITALIZE_UP};
30
31Lisp_Object Qidentity;
29 32
30Lisp_Object 33Lisp_Object
31casify_object (flag, obj) 34casify_object (flag, obj)
@@ -34,6 +37,7 @@ casify_object (flag, obj)
34{ 37{
35 register int i, c, len; 38 register int i, c, len;
36 register int inword = flag == CASE_DOWN; 39 register int inword = flag == CASE_DOWN;
40 Lisp_Object tem;
37 41
38 /* If the case table is flagged as modified, rescan it. */ 42 /* If the case table is flagged as modified, rescan it. */
39 if (NILP (XCHAR_TABLE (current_buffer->downcase_table)->extras[1])) 43 if (NILP (XCHAR_TABLE (current_buffer->downcase_table)->extras[1]))
@@ -43,13 +47,16 @@ casify_object (flag, obj)
43 { 47 {
44 if (INTEGERP (obj)) 48 if (INTEGERP (obj))
45 { 49 {
46 c = XINT (obj); 50 tem = Faref (current_buffer->downcase_table, obj);
47 if (c >= 0 && c <= 0400) 51 if (EQ (tem, Qidentity))
52 tem = obj;
53 if (inword)
54 obj = tem;
55 else if (EQ (tem, obj))
48 { 56 {
49 if (inword) 57 tem = Faref (current_buffer->upcase_table, obj);
50 XSETFASTINT (obj, DOWNCASE (c)); 58 if (!EQ (tem, Qidentity))
51 else if (!UPPERCASEP (c)) 59 obj = tem;
52 XSETFASTINT (obj, UPCASE1 (c));
53 } 60 }
54 return obj; 61 return obj;
55 } 62 }
@@ -132,6 +139,7 @@ casify_region (flag, b, e)
132 register int c; 139 register int c;
133 register int inword = flag == CASE_DOWN; 140 register int inword = flag == CASE_DOWN;
134 int start, end; 141 int start, end;
142 Lisp_Object ch, downch, val;
135 143
136 if (EQ (b, e)) 144 if (EQ (b, e))
137 /* Not modifying because nothing marked */ 145 /* Not modifying because nothing marked */
@@ -147,17 +155,82 @@ casify_region (flag, b, e)
147 modify_region (current_buffer, start, end); 155 modify_region (current_buffer, start, end);
148 record_change (start, end - start); 156 record_change (start, end - start);
149 157
150 for (i = start; i < end; i++) 158 if (NILP (current_buffer->enable_multibyte_characters))
159 {
160 for (i = start; i < end; i++)
161 {
162 c = FETCH_BYTE (i);
163 if (inword && flag != CASE_CAPITALIZE_UP)
164 c = DOWNCASE (c);
165 else if (!UPPERCASEP (c)
166 && (!inword || flag != CASE_CAPITALIZE_UP))
167 c = UPCASE1 (c);
168 FETCH_BYTE (i) = c;
169 if ((int) flag >= (int) CASE_CAPITALIZE)
170 inword = SYNTAX (c) == Sword;
171 }
172 }
173 else
151 { 174 {
152 c = FETCH_BYTE (i); 175 Lisp_Object down, up;
153 if (inword && flag != CASE_CAPITALIZE_UP) 176 int opoint = PT;
154 c = DOWNCASE (c); 177
155 else if (!UPPERCASEP (c) 178 down = current_buffer->downcase_table;
156 && (!inword || flag != CASE_CAPITALIZE_UP)) 179 up = current_buffer->upcase_table;
157 c = UPCASE1 (c); 180 for (i = start; i < end;)
158 FETCH_BYTE (i) = c; 181 {
159 if ((int) flag >= (int) CASE_CAPITALIZE) 182 c = FETCH_MULTIBYTE_CHAR (i);
160 inword = SYNTAX (c) == Sword; 183 XSETFASTINT (ch, c);
184 downch = Faref (down, ch);
185 if (EQ (downch, Qidentity))
186 downch = ch;
187 if (inword && flag != CASE_CAPITALIZE_UP)
188 val = downch;
189 else if (EQ (downch, ch)
190 && (!inword || flag != CASE_CAPITALIZE_UP))
191 {
192 val = Faref (up, ch);
193 if (EQ (val, Qidentity))
194 val = ch;
195 }
196 else
197 val = ch;
198 if (!EQ (val, ch))
199 {
200 int fromlen, tolen, j;
201 char workbuf[4], *str;
202
203 if (!NATNUMP (val))
204 error ("Inappropriate value found in case table");
205 /* Handle the most likely case */
206 if (c < 0400 && XFASTINT (val) < 0400)
207 FETCH_BYTE (i) = XFASTINT (val);
208 else if (fromlen = CHAR_STRING (c, workbuf, str),
209 tolen = CHAR_STRING (XFASTINT (val), workbuf, str),
210 fromlen == tolen)
211 {
212 for (j = 0; j < tolen; ++j)
213 FETCH_BYTE (i + j) = str[j];
214 }
215 else
216 {
217 error ("Can't casify letters that change length");
218#if 0 /* This is approximately what we'd like to be able to do here */
219 if (tolen < fromlen)
220 del_range_1 (i + tolen, i + fromlen, 0);
221 else if (tolen > fromlen)
222 {
223 TEMP_SET_PT (i + fromlen);
224 insert_1 (str + fromlen, tolen - fromlen, 1, 0);
225 }
226#endif
227 }
228 }
229 if ((int) flag >= (int) CASE_CAPITALIZE)
230 inword = SYNTAX (XFASTINT (val)) == Sword;
231 INC_POS (i);
232 }
233 TEMP_SET_PT (opoint);
161 } 234 }
162 235
163 signal_after_change (start, end - start, end - start); 236 signal_after_change (start, end - start, end - start);
@@ -287,6 +360,8 @@ With negative argument, capitalize previous words but do not move.")
287 360
288syms_of_casefiddle () 361syms_of_casefiddle ()
289{ 362{
363 Qidentity = intern ("identity");
364 staticpro (&Qidentity);
290 defsubr (&Supcase); 365 defsubr (&Supcase);
291 defsubr (&Sdowncase); 366 defsubr (&Sdowncase);
292 defsubr (&Scapitalize); 367 defsubr (&Scapitalize);