annotate src/casefiddle.c @ 0:376386a54a3c r19-14

Import from CVS: tag r19-14
author cvs
date Mon, 13 Aug 2007 08:45:50 +0200
parents
children 859a2309aef8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 /* XEmacs case conversion functions.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2 Copyright (C) 1985, 1992, 1993, 1994 Free Software Foundation, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4 This file is part of XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 XEmacs is free software; you can redistribute it and/or modify it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 under the terms of the GNU General Public License as published by the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 Free Software Foundation; either version 2, or (at your option) any
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 XEmacs is distributed in the hope that it will be useful, but WITHOUT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 You should have received a copy of the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 along with XEmacs; see the file COPYING. If not, write to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 Boston, MA 02111-1307, USA. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 /* Synched up with: FSF 19.30. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23 #include <config.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 #include "lisp.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 #include "buffer.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 #include "commands.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 #include "insdel.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 #include "syntax.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 enum case_action {CASE_UP, CASE_DOWN, CASE_CAPITALIZE, CASE_CAPITALIZE_UP};
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 static Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 casify_object (struct buffer *buf, enum case_action flag, Lisp_Object obj)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 REGISTER Emchar c;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 REGISTER Charcount i, len;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 REGISTER int inword = flag == CASE_DOWN;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 Lisp_Object syntax_table = buf->syntax_table;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 while (1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 if (CHAR_OR_CHAR_INTP (obj))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 CHECK_CHAR_COERCE_INT (obj);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 c = XCHAR (obj);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 if (IN_TRT_TABLE_DOMAIN (c))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 if (inword)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 obj = make_char (DOWNCASE (buf, c));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 else if (!UPPERCASEP (buf, c))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 obj = make_char (UPCASE1 (buf, c));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 return obj;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 if (STRINGP (obj))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 obj = Fcopy_sequence (obj);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 len = string_char_length (XSTRING (obj));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 for (i = 0; i < len; i++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 c = string_char (XSTRING (obj), i);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 if (inword)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 c = DOWNCASE (buf, c);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 else if (!UPPERCASEP (buf, c)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 && (!inword || flag != CASE_CAPITALIZE_UP))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 c = UPCASE1 (buf, c);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 set_string_char (XSTRING (obj), i, c);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 if ((int) flag >= (int) CASE_CAPITALIZE)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 inword = WORD_SYNTAX_P (syntax_table, c);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 return obj;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 obj = wrong_type_argument (Qchar_or_string_p, obj);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 DEFUN ("upcase", Fupcase, Supcase, 1, 2, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 Convert argument to upper case and return that.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 The argument may be a character or string. The result has the same type.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 The argument object is not altered--the value is a copy.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 See also `capitalize', `downcase' and `upcase-initials'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 Optional second arg BUFFER specifies which buffer's case tables to use,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 and defaults to the current buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 (obj, buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 Lisp_Object obj, buffer;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 return casify_object (decode_buffer (buffer, 0), CASE_UP, obj);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 DEFUN ("downcase", Fdowncase, Sdowncase, 1, 2, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 Convert argument to lower case and return that.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 The argument may be a character or string. The result has the same type.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 The argument object is not altered--the value is a copy.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 Optional second arg BUFFER specifies which buffer's case tables to use,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 and defaults to the current buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 (obj, buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 Lisp_Object obj, buffer;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 return casify_object (decode_buffer (buffer, 0), CASE_DOWN, obj);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 DEFUN ("capitalize", Fcapitalize, Scapitalize, 1, 2, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 Convert argument to capitalized form and return that.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 This means that each word's first character is upper case
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 and the rest is lower case.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 The argument may be a character or string. The result has the same type.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 The argument object is not altered--the value is a copy.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 Optional second arg BUFFER specifies which buffer's case tables to use,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 and defaults to the current buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 (obj, buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 Lisp_Object obj, buffer;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 return casify_object (decode_buffer (buffer, 0), CASE_CAPITALIZE, obj);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 /* Like Fcapitalize but change only the initials. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 DEFUN ("upcase-initials", Fupcase_initials, Supcase_initials, 1, 2, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 Convert the initial of each word in the argument to upper case.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 Do not change the other letters of each word.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 The argument may be a character or string. The result has the same type.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 The argument object is not altered--the value is a copy.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 Optional second arg BUFFER specifies which buffer's case tables to use,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 and defaults to the current buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 (obj, buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 Lisp_Object obj, buffer;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 return casify_object (decode_buffer (buffer, 0), CASE_CAPITALIZE_UP, obj);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 /* flag is CASE_UP, CASE_DOWN or CASE_CAPITALIZE or CASE_CAPITALIZE_UP.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 b and e specify range of buffer to operate on. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 casify_region (struct buffer *buf, enum case_action flag, Lisp_Object b,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 Lisp_Object e)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 /* This function can GC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 REGISTER Bufpos i;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 Bufpos start, end;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 REGISTER Emchar c;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 REGISTER int inword = flag == CASE_DOWN;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 Lisp_Object syntax_table = buf->syntax_table;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 int mccount;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 if (EQ (b, e))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 /* Not modifying because nothing marked */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 get_buffer_range_char (buf, b, e, &start, &end, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 mccount = begin_multiple_change (buf, start, end);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 record_change (buf, start, end - start);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 BUF_MODIFF (buf)++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 for (i = start; i < end; i++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 c = BUF_FETCH_CHAR (buf, i);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 if (inword && flag != CASE_CAPITALIZE_UP)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 c = DOWNCASE (buf, c);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 else if (!UPPERCASEP (buf, c)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 && (!inword || flag != CASE_CAPITALIZE_UP))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 c = UPCASE1 (buf, c);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 buffer_replace_char (buf, i, c, 1, (i == start));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 /* !!#### need to revalidate the start and end pointers in case
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 the buffer was changed */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 if ((int) flag >= (int) CASE_CAPITALIZE)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 inword = WORD_SYNTAX_P (syntax_table, c);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 end_multiple_change (buf, mccount);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 DEFUN ("upcase-region", Fupcase_region, Supcase_region, 2, 3, "r" /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 Convert the region to upper case. In programs, wants two arguments.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 These arguments specify the starting and ending character numbers of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 the region to operate on. When used as a command, the text between
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 point and the mark is operated on.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 See also `capitalize-region'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 Optional third arg BUFFER defaults to the current buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 (b, e, buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 Lisp_Object b, e, buffer;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 /* This function can GC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 casify_region (decode_buffer (buffer, 1), CASE_UP, b, e);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 DEFUN ("downcase-region", Fdowncase_region, Sdowncase_region, 2, 3, "r" /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 Convert the region to lower case. In programs, wants two arguments.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 These arguments specify the starting and ending character numbers of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 the region to operate on. When used as a command, the text between
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 point and the mark is operated on.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 Optional third arg BUFFER defaults to the current buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 (b, e, buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 Lisp_Object b, e, buffer;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 /* This function can GC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 casify_region (decode_buffer (buffer, 1), CASE_DOWN, b, e);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 DEFUN ("capitalize-region", Fcapitalize_region, Scapitalize_region, 2, 3, "r" /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 Convert the region to capitalized form.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 Capitalized form means each word's first character is upper case
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 and the rest of it is lower case.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 In programs, give two arguments, the starting and ending
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 character positions to operate on.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 Optional third arg BUFFER defaults to the current buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 (b, e, buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 Lisp_Object b, e, buffer;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 /* This function can GC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 casify_region (decode_buffer (buffer, 1), CASE_CAPITALIZE, b, e);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 /* Like Fcapitalize_region but change only the initials. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 DEFUN ("upcase-initials-region", Fupcase_initials_region,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 Supcase_initials_region, 2, 3, "r" /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 Upcase the initial of each word in the region.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 Subsequent letters of each word are not changed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 In programs, give two arguments, the starting and ending
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 character positions to operate on.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 Optional third arg BUFFER defaults to the current buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 (b, e, buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 Lisp_Object b, e, buffer;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 casify_region (decode_buffer (buffer, 1), CASE_CAPITALIZE_UP, b, e);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 static Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 operate_on_word (struct buffer *buf, Lisp_Object arg, int *newpoint)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 Bufpos farend;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 CHECK_INT (arg);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 farend = scan_words (buf, BUF_PT (buf), XINT (arg));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 if (!farend)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 farend = XINT (arg) > 0 ? BUF_ZV (buf) : BUF_BEGV (buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 *newpoint = ((BUF_PT (buf) > farend) ? BUF_PT (buf) : farend);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 return (make_int (farend));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 DEFUN ("upcase-word", Fupcase_word, Supcase_word, 1, 2, "p" /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 Convert following word (or ARG words) to upper case, moving over.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 With negative argument, convert previous words but do not move.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 See also `capitalize-word'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 Optional second arg BUFFER defaults to the current buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 (arg, buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 Lisp_Object arg, buffer;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 /* This function can GC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 Lisp_Object beg, end;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 Bufpos newpoint;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 struct buffer *buf = decode_buffer (buffer, 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 beg = make_int (BUF_PT (buf));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 end = operate_on_word (buf, arg, &newpoint);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 casify_region (buf, CASE_UP, beg, end);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 BUF_SET_PT (buf, newpoint);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 DEFUN ("downcase-word", Fdowncase_word, Sdowncase_word, 1, 2, "p" /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 Convert following word (or ARG words) to lower case, moving over.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 With negative argument, convert previous words but do not move.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 Optional second arg BUFFER defaults to the current buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 (arg, buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 Lisp_Object arg, buffer;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 /* This function can GC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 Lisp_Object beg, end;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289 Bufpos newpoint;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290 struct buffer *buf = decode_buffer (buffer, 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 beg = make_int (BUF_PT (buf));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 end = operate_on_word (buf, arg, &newpoint);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 casify_region (buf, CASE_DOWN, beg, end);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 BUF_SET_PT (buf, newpoint);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 DEFUN ("capitalize-word", Fcapitalize_word, Scapitalize_word, 1, 2, "p" /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300 Capitalize the following word (or ARG words), moving over.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301 This gives the word(s) a first character in upper case
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 and the rest lower case.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 With negative argument, capitalize previous words but do not move.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 Optional second arg BUFFER defaults to the current buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 (arg, buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 Lisp_Object arg, buffer;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 /* This function can GC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310 Lisp_Object beg, end;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 Bufpos newpoint;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312 struct buffer *buf = decode_buffer (buffer, 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 beg = make_int (BUF_PT (buf));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 end = operate_on_word (buf, arg, &newpoint);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316 casify_region (buf, CASE_CAPITALIZE, beg, end);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 BUF_SET_PT (buf, newpoint);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323 syms_of_casefiddle (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325 defsubr (&Supcase);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326 defsubr (&Sdowncase);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327 defsubr (&Scapitalize);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328 defsubr (&Supcase_initials);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 defsubr (&Supcase_region);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330 defsubr (&Sdowncase_region);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331 defsubr (&Scapitalize_region);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332 defsubr (&Supcase_initials_region);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333 defsubr (&Supcase_word);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334 defsubr (&Sdowncase_word);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335 defsubr (&Scapitalize_word);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336 }