annotate src/casefiddle.c @ 14610:6c73b6046d21

(main, both definitions): Print a newline for normal termination.
author Karl Heuer <kwzh@gnu.org>
date Wed, 21 Feb 1996 20:53:01 +0000
parents ee40177f6c68
children 0d698228e98c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1 /* GNU Emacs case conversion functions.
7307
cd81dba38a49 Update copyright.
Karl Heuer <kwzh@gnu.org>
parents: 6221
diff changeset
2 Copyright (C) 1985, 1994 Free Software Foundation, Inc.
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
4 This file is part of GNU Emacs.
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
5
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
6 GNU Emacs is free software; you can redistribute it and/or modify
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
7 it under the terms of the GNU General Public License as published by
12244
ac7375e60931 Update GPL to version 2.
Karl Heuer <kwzh@gnu.org>
parents: 12089
diff changeset
8 the Free Software Foundation; either version 2, or (at your option)
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
9 any later version.
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
10
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
11 GNU Emacs is distributed in the hope that it will be useful,
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
14 GNU General Public License for more details.
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
15
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
16 You should have received a copy of the GNU General Public License
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
17 along with GNU Emacs; see the file COPYING. If not, write to
14186
ee40177f6c68 Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents: 14063
diff changeset
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
ee40177f6c68 Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents: 14063
diff changeset
19 Boston, MA 02111-1307, USA. */
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
20
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
21
4696
1fc792473491 Include <config.h> instead of "config.h".
Roland McGrath <roland@gnu.org>
parents: 2822
diff changeset
22 #include <config.h>
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
23 #include "lisp.h"
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
24 #include "buffer.h"
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
25 #include "commands.h"
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
26 #include "syntax.h"
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
27
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
28 enum case_action {CASE_UP, CASE_DOWN, CASE_CAPITALIZE, CASE_CAPITALIZE_UP};
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
29
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
30 Lisp_Object
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
31 casify_object (flag, obj)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
32 enum case_action flag;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
33 Lisp_Object obj;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
34 {
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
35 register int i, c, len;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
36 register int inword = flag == CASE_DOWN;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
37
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
38 while (1)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
39 {
9137
412e94c1dbf2 (casify_object): Use type test macros.
Karl Heuer <kwzh@gnu.org>
parents: 9053
diff changeset
40 if (INTEGERP (obj))
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
41 {
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
42 c = XINT (obj);
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
43 if (c >= 0 && c <= 0400)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
44 {
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
45 if (inword)
9299
e8c880f2723e (casify_object, operate_on_word, Fupcase_word, Fdowncase_word,
Karl Heuer <kwzh@gnu.org>
parents: 9137
diff changeset
46 XSETFASTINT (obj, DOWNCASE (c));
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
47 else if (!UPPERCASEP (c))
9299
e8c880f2723e (casify_object, operate_on_word, Fupcase_word, Fdowncase_word,
Karl Heuer <kwzh@gnu.org>
parents: 9137
diff changeset
48 XSETFASTINT (obj, UPCASE1 (c));
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
49 }
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
50 return obj;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
51 }
9137
412e94c1dbf2 (casify_object): Use type test macros.
Karl Heuer <kwzh@gnu.org>
parents: 9053
diff changeset
52 if (STRINGP (obj))
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
53 {
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
54 obj = Fcopy_sequence (obj);
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
55 len = XSTRING (obj)->size;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
56 for (i = 0; i < len; i++)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
57 {
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
58 c = XSTRING (obj)->data[i];
9052
6de22822cf72 (upcase_initials): New function.
Richard M. Stallman <rms@gnu.org>
parents: 7307
diff changeset
59 if (inword && flag != CASE_CAPITALIZE_UP)
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
60 c = DOWNCASE (c);
9052
6de22822cf72 (upcase_initials): New function.
Richard M. Stallman <rms@gnu.org>
parents: 7307
diff changeset
61 else if (!UPPERCASEP (c)
6de22822cf72 (upcase_initials): New function.
Richard M. Stallman <rms@gnu.org>
parents: 7307
diff changeset
62 && (!inword || flag != CASE_CAPITALIZE_UP))
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
63 c = UPCASE1 (c);
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
64 XSTRING (obj)->data[i] = c;
9052
6de22822cf72 (upcase_initials): New function.
Richard M. Stallman <rms@gnu.org>
parents: 7307
diff changeset
65 if ((int) flag >= (int) CASE_CAPITALIZE)
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
66 inword = SYNTAX (c) == Sword;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
67 }
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
68 return obj;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
69 }
1926
952f2a18f83d * callint.c (Fcall_interactively): Pass the correct number of
Jim Blandy <jimb@redhat.com>
parents: 1505
diff changeset
70 obj = wrong_type_argument (Qchar_or_string_p, obj);
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
71 }
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
72 }
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
73
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
74 DEFUN ("upcase", Fupcase, Supcase, 1, 1, 0,
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
75 "Convert argument to upper case and return that.\n\
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
76 The argument may be a character or string. The result has the same type.\n\
9053
4887fc1a2dda (Fupcase_initials_region): New function.
Richard M. Stallman <rms@gnu.org>
parents: 9052
diff changeset
77 The argument object is not altered--the value is a copy.\n\
4887fc1a2dda (Fupcase_initials_region): New function.
Richard M. Stallman <rms@gnu.org>
parents: 9052
diff changeset
78 See also `capitalize', `downcase' and `upcase-initials'.")
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
79 (obj)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
80 Lisp_Object obj;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
81 {
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
82 return casify_object (CASE_UP, obj);
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
83 }
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
84
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
85 DEFUN ("downcase", Fdowncase, Sdowncase, 1, 1, 0,
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
86 "Convert argument to lower case and return that.\n\
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
87 The argument may be a character or string. The result has the same type.\n\
9053
4887fc1a2dda (Fupcase_initials_region): New function.
Richard M. Stallman <rms@gnu.org>
parents: 9052
diff changeset
88 The argument object is not altered--the value is a copy.")
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
89 (obj)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
90 Lisp_Object obj;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
91 {
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
92 return casify_object (CASE_DOWN, obj);
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
93 }
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
94
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
95 DEFUN ("capitalize", Fcapitalize, Scapitalize, 1, 1, 0,
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
96 "Convert argument to capitalized form and return that.\n\
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
97 This means that each word's first character is upper case\n\
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
98 and the rest is lower case.\n\
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
99 The argument may be a character or string. The result has the same type.\n\
9053
4887fc1a2dda (Fupcase_initials_region): New function.
Richard M. Stallman <rms@gnu.org>
parents: 9052
diff changeset
100 The argument object is not altered--the value is a copy.")
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
101 (obj)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
102 Lisp_Object obj;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
103 {
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
104 return casify_object (CASE_CAPITALIZE, obj);
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
105 }
9052
6de22822cf72 (upcase_initials): New function.
Richard M. Stallman <rms@gnu.org>
parents: 7307
diff changeset
106
12089
f7cb17ca1815 (casify_region): Use explicit local vars for start
Karl Heuer <kwzh@gnu.org>
parents: 9299
diff changeset
107 /* Like Fcapitalize but change only the initials. */
f7cb17ca1815 (casify_region): Use explicit local vars for start
Karl Heuer <kwzh@gnu.org>
parents: 9299
diff changeset
108
9053
4887fc1a2dda (Fupcase_initials_region): New function.
Richard M. Stallman <rms@gnu.org>
parents: 9052
diff changeset
109 DEFUN ("upcase-initials", Fupcase_initials, Supcase_initials, 1, 1, 0,
4887fc1a2dda (Fupcase_initials_region): New function.
Richard M. Stallman <rms@gnu.org>
parents: 9052
diff changeset
110 "Convert the initial of each word in the argument to upper case.\n\
4887fc1a2dda (Fupcase_initials_region): New function.
Richard M. Stallman <rms@gnu.org>
parents: 9052
diff changeset
111 Do not change the other letters of each word.\n\
4887fc1a2dda (Fupcase_initials_region): New function.
Richard M. Stallman <rms@gnu.org>
parents: 9052
diff changeset
112 The argument may be a character or string. The result has the same type.\n\
4887fc1a2dda (Fupcase_initials_region): New function.
Richard M. Stallman <rms@gnu.org>
parents: 9052
diff changeset
113 The argument object is not altered--the value is a copy.")
4887fc1a2dda (Fupcase_initials_region): New function.
Richard M. Stallman <rms@gnu.org>
parents: 9052
diff changeset
114 (obj)
4887fc1a2dda (Fupcase_initials_region): New function.
Richard M. Stallman <rms@gnu.org>
parents: 9052
diff changeset
115 Lisp_Object obj;
4887fc1a2dda (Fupcase_initials_region): New function.
Richard M. Stallman <rms@gnu.org>
parents: 9052
diff changeset
116 {
4887fc1a2dda (Fupcase_initials_region): New function.
Richard M. Stallman <rms@gnu.org>
parents: 9052
diff changeset
117 return casify_object (CASE_CAPITALIZE_UP, obj);
4887fc1a2dda (Fupcase_initials_region): New function.
Richard M. Stallman <rms@gnu.org>
parents: 9052
diff changeset
118 }
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
119
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
120 /* flag is CASE_UP, CASE_DOWN or CASE_CAPITALIZE or CASE_CAPITALIZE_UP.
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
121 b and e specify range of buffer to operate on. */
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
122
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
123 casify_region (flag, b, e)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
124 enum case_action flag;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
125 Lisp_Object b, e;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
126 {
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
127 register int i;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
128 register int c;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
129 register int inword = flag == CASE_DOWN;
12089
f7cb17ca1815 (casify_region): Use explicit local vars for start
Karl Heuer <kwzh@gnu.org>
parents: 9299
diff changeset
130 int start, end;
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
131
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
132 if (EQ (b, e))
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
133 /* Not modifying because nothing marked */
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
134 return;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
135
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
136 validate_region (&b, &e);
12089
f7cb17ca1815 (casify_region): Use explicit local vars for start
Karl Heuer <kwzh@gnu.org>
parents: 9299
diff changeset
137 start = XFASTINT (b);
f7cb17ca1815 (casify_region): Use explicit local vars for start
Karl Heuer <kwzh@gnu.org>
parents: 9299
diff changeset
138 end = XFASTINT (e);
f7cb17ca1815 (casify_region): Use explicit local vars for start
Karl Heuer <kwzh@gnu.org>
parents: 9299
diff changeset
139 modify_region (current_buffer, start, end);
f7cb17ca1815 (casify_region): Use explicit local vars for start
Karl Heuer <kwzh@gnu.org>
parents: 9299
diff changeset
140 record_change (start, end - start);
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
141
12089
f7cb17ca1815 (casify_region): Use explicit local vars for start
Karl Heuer <kwzh@gnu.org>
parents: 9299
diff changeset
142 for (i = start; i < end; i++)
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
143 {
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
144 c = FETCH_CHAR (i);
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
145 if (inword && flag != CASE_CAPITALIZE_UP)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
146 c = DOWNCASE (c);
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
147 else if (!UPPERCASEP (c)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
148 && (!inword || flag != CASE_CAPITALIZE_UP))
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
149 c = UPCASE1 (c);
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
150 FETCH_CHAR (i) = c;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
151 if ((int) flag >= (int) CASE_CAPITALIZE)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
152 inword = SYNTAX (c) == Sword;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
153 }
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
154
12089
f7cb17ca1815 (casify_region): Use explicit local vars for start
Karl Heuer <kwzh@gnu.org>
parents: 9299
diff changeset
155 signal_after_change (start, end - start, end - start);
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
156 }
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
157
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
158 DEFUN ("upcase-region", Fupcase_region, Supcase_region, 2, 2, "r",
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
159 "Convert the region to upper case. In programs, wants two arguments.\n\
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
160 These arguments specify the starting and ending character numbers of\n\
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
161 the region to operate on. When used as a command, the text between\n\
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
162 point and the mark is operated on.\n\
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
163 See also `capitalize-region'.")
14063
ef7d4117c601 (Fupcase_region, Fdowncase_region, Fcapitalize_region,
Erik Naggum <erik@naggum.no>
parents: 12244
diff changeset
164 (beg, end)
ef7d4117c601 (Fupcase_region, Fdowncase_region, Fcapitalize_region,
Erik Naggum <erik@naggum.no>
parents: 12244
diff changeset
165 Lisp_Object beg, end;
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
166 {
14063
ef7d4117c601 (Fupcase_region, Fdowncase_region, Fcapitalize_region,
Erik Naggum <erik@naggum.no>
parents: 12244
diff changeset
167 casify_region (CASE_UP, beg, end);
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
168 return Qnil;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
169 }
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
170
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
171 DEFUN ("downcase-region", Fdowncase_region, Sdowncase_region, 2, 2, "r",
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
172 "Convert the region to lower case. In programs, wants two arguments.\n\
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
173 These arguments specify the starting and ending character numbers of\n\
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
174 the region to operate on. When used as a command, the text between\n\
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
175 point and the mark is operated on.")
14063
ef7d4117c601 (Fupcase_region, Fdowncase_region, Fcapitalize_region,
Erik Naggum <erik@naggum.no>
parents: 12244
diff changeset
176 (beg, end)
ef7d4117c601 (Fupcase_region, Fdowncase_region, Fcapitalize_region,
Erik Naggum <erik@naggum.no>
parents: 12244
diff changeset
177 Lisp_Object beg, end;
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
178 {
14063
ef7d4117c601 (Fupcase_region, Fdowncase_region, Fcapitalize_region,
Erik Naggum <erik@naggum.no>
parents: 12244
diff changeset
179 casify_region (CASE_DOWN, beg, end);
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
180 return Qnil;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
181 }
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
182
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
183 DEFUN ("capitalize-region", Fcapitalize_region, Scapitalize_region, 2, 2, "r",
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
184 "Convert the region to capitalized form.\n\
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
185 Capitalized form means each word's first character is upper case\n\
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
186 and the rest of it is lower case.\n\
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
187 In programs, give two arguments, the starting and ending\n\
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
188 character positions to operate on.")
14063
ef7d4117c601 (Fupcase_region, Fdowncase_region, Fcapitalize_region,
Erik Naggum <erik@naggum.no>
parents: 12244
diff changeset
189 (beg, end)
ef7d4117c601 (Fupcase_region, Fdowncase_region, Fcapitalize_region,
Erik Naggum <erik@naggum.no>
parents: 12244
diff changeset
190 Lisp_Object beg, end;
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
191 {
14063
ef7d4117c601 (Fupcase_region, Fdowncase_region, Fcapitalize_region,
Erik Naggum <erik@naggum.no>
parents: 12244
diff changeset
192 casify_region (CASE_CAPITALIZE, beg, end);
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
193 return Qnil;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
194 }
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
195
12089
f7cb17ca1815 (casify_region): Use explicit local vars for start
Karl Heuer <kwzh@gnu.org>
parents: 9299
diff changeset
196 /* Like Fcapitalize_region but change only the initials. */
f7cb17ca1815 (casify_region): Use explicit local vars for start
Karl Heuer <kwzh@gnu.org>
parents: 9299
diff changeset
197
9053
4887fc1a2dda (Fupcase_initials_region): New function.
Richard M. Stallman <rms@gnu.org>
parents: 9052
diff changeset
198 DEFUN ("upcase-initials-region", Fupcase_initials_region,
4887fc1a2dda (Fupcase_initials_region): New function.
Richard M. Stallman <rms@gnu.org>
parents: 9052
diff changeset
199 Supcase_initials_region, 2, 2, "r",
4887fc1a2dda (Fupcase_initials_region): New function.
Richard M. Stallman <rms@gnu.org>
parents: 9052
diff changeset
200 "Upcase the initial of each word in the region.\n\
4887fc1a2dda (Fupcase_initials_region): New function.
Richard M. Stallman <rms@gnu.org>
parents: 9052
diff changeset
201 Subsequent letters of each word are not changed.\n\
4887fc1a2dda (Fupcase_initials_region): New function.
Richard M. Stallman <rms@gnu.org>
parents: 9052
diff changeset
202 In programs, give two arguments, the starting and ending\n\
4887fc1a2dda (Fupcase_initials_region): New function.
Richard M. Stallman <rms@gnu.org>
parents: 9052
diff changeset
203 character positions to operate on.")
14063
ef7d4117c601 (Fupcase_region, Fdowncase_region, Fcapitalize_region,
Erik Naggum <erik@naggum.no>
parents: 12244
diff changeset
204 (beg, end)
ef7d4117c601 (Fupcase_region, Fdowncase_region, Fcapitalize_region,
Erik Naggum <erik@naggum.no>
parents: 12244
diff changeset
205 Lisp_Object beg, end;
9053
4887fc1a2dda (Fupcase_initials_region): New function.
Richard M. Stallman <rms@gnu.org>
parents: 9052
diff changeset
206 {
14063
ef7d4117c601 (Fupcase_region, Fdowncase_region, Fcapitalize_region,
Erik Naggum <erik@naggum.no>
parents: 12244
diff changeset
207 casify_region (CASE_CAPITALIZE_UP, beg, end);
9053
4887fc1a2dda (Fupcase_initials_region): New function.
Richard M. Stallman <rms@gnu.org>
parents: 9052
diff changeset
208 return Qnil;
4887fc1a2dda (Fupcase_initials_region): New function.
Richard M. Stallman <rms@gnu.org>
parents: 9052
diff changeset
209 }
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
210
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
211 Lisp_Object
6221
c2d29681d218 (operate_on_word): Don't move point; store in *NEWPOINT.
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
212 operate_on_word (arg, newpoint)
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
213 Lisp_Object arg;
6221
c2d29681d218 (operate_on_word): Don't move point; store in *NEWPOINT.
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
214 int *newpoint;
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
215 {
1505
4f138b03e5ab * casefiddle.c (operate_on_word): Declare end to be an int, not a
Jim Blandy <jimb@redhat.com>
parents: 484
diff changeset
216 Lisp_Object val;
6221
c2d29681d218 (operate_on_word): Don't move point; store in *NEWPOINT.
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
217 int farend;
12089
f7cb17ca1815 (casify_region): Use explicit local vars for start
Karl Heuer <kwzh@gnu.org>
parents: 9299
diff changeset
218 int iarg;
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
219
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
220 CHECK_NUMBER (arg, 0);
12089
f7cb17ca1815 (casify_region): Use explicit local vars for start
Karl Heuer <kwzh@gnu.org>
parents: 9299
diff changeset
221 iarg = XINT (arg);
f7cb17ca1815 (casify_region): Use explicit local vars for start
Karl Heuer <kwzh@gnu.org>
parents: 9299
diff changeset
222 farend = scan_words (point, iarg);
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
223 if (!farend)
12089
f7cb17ca1815 (casify_region): Use explicit local vars for start
Karl Heuer <kwzh@gnu.org>
parents: 9299
diff changeset
224 farend = iarg > 0 ? ZV : BEGV;
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
225
6221
c2d29681d218 (operate_on_word): Don't move point; store in *NEWPOINT.
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
226 *newpoint = point > farend ? point : farend;
9299
e8c880f2723e (casify_object, operate_on_word, Fupcase_word, Fdowncase_word,
Karl Heuer <kwzh@gnu.org>
parents: 9137
diff changeset
227 XSETFASTINT (val, farend);
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
228
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
229 return val;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
230 }
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
231
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
232 DEFUN ("upcase-word", Fupcase_word, Supcase_word, 1, 1, "p",
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
233 "Convert following word (or ARG words) to upper case, moving over.\n\
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
234 With negative argument, convert previous words but do not move.\n\
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
235 See also `capitalize-word'.")
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
236 (arg)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
237 Lisp_Object arg;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
238 {
6221
c2d29681d218 (operate_on_word): Don't move point; store in *NEWPOINT.
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
239 Lisp_Object beg, end;
c2d29681d218 (operate_on_word): Don't move point; store in *NEWPOINT.
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
240 int newpoint;
9299
e8c880f2723e (casify_object, operate_on_word, Fupcase_word, Fdowncase_word,
Karl Heuer <kwzh@gnu.org>
parents: 9137
diff changeset
241 XSETFASTINT (beg, point);
6221
c2d29681d218 (operate_on_word): Don't move point; store in *NEWPOINT.
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
242 end = operate_on_word (arg, &newpoint);
c2d29681d218 (operate_on_word): Don't move point; store in *NEWPOINT.
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
243 casify_region (CASE_UP, beg, end);
c2d29681d218 (operate_on_word): Don't move point; store in *NEWPOINT.
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
244 SET_PT (newpoint);
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
245 return Qnil;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
246 }
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
247
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
248 DEFUN ("downcase-word", Fdowncase_word, Sdowncase_word, 1, 1, "p",
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
249 "Convert following word (or ARG words) to lower case, moving over.\n\
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
250 With negative argument, convert previous words but do not move.")
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
251 (arg)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
252 Lisp_Object arg;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
253 {
6221
c2d29681d218 (operate_on_word): Don't move point; store in *NEWPOINT.
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
254 Lisp_Object beg, end;
c2d29681d218 (operate_on_word): Don't move point; store in *NEWPOINT.
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
255 int newpoint;
9299
e8c880f2723e (casify_object, operate_on_word, Fupcase_word, Fdowncase_word,
Karl Heuer <kwzh@gnu.org>
parents: 9137
diff changeset
256 XSETFASTINT (beg, point);
6221
c2d29681d218 (operate_on_word): Don't move point; store in *NEWPOINT.
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
257 end = operate_on_word (arg, &newpoint);
c2d29681d218 (operate_on_word): Don't move point; store in *NEWPOINT.
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
258 casify_region (CASE_DOWN, beg, end);
c2d29681d218 (operate_on_word): Don't move point; store in *NEWPOINT.
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
259 SET_PT (newpoint);
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
260 return Qnil;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
261 }
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
262
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
263 DEFUN ("capitalize-word", Fcapitalize_word, Scapitalize_word, 1, 1, "p",
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
264 "Capitalize the following word (or ARG words), moving over.\n\
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
265 This gives the word(s) a first character in upper case\n\
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
266 and the rest lower case.\n\
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
267 With negative argument, capitalize previous words but do not move.")
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
268 (arg)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
269 Lisp_Object arg;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
270 {
6221
c2d29681d218 (operate_on_word): Don't move point; store in *NEWPOINT.
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
271 Lisp_Object beg, end;
c2d29681d218 (operate_on_word): Don't move point; store in *NEWPOINT.
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
272 int newpoint;
9299
e8c880f2723e (casify_object, operate_on_word, Fupcase_word, Fdowncase_word,
Karl Heuer <kwzh@gnu.org>
parents: 9137
diff changeset
273 XSETFASTINT (beg, point);
6221
c2d29681d218 (operate_on_word): Don't move point; store in *NEWPOINT.
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
274 end = operate_on_word (arg, &newpoint);
c2d29681d218 (operate_on_word): Don't move point; store in *NEWPOINT.
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
275 casify_region (CASE_CAPITALIZE, beg, end);
c2d29681d218 (operate_on_word): Don't move point; store in *NEWPOINT.
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
276 SET_PT (newpoint);
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
277 return Qnil;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
278 }
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
279
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
280 syms_of_casefiddle ()
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
281 {
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
282 defsubr (&Supcase);
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
283 defsubr (&Sdowncase);
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
284 defsubr (&Scapitalize);
9053
4887fc1a2dda (Fupcase_initials_region): New function.
Richard M. Stallman <rms@gnu.org>
parents: 9052
diff changeset
285 defsubr (&Supcase_initials);
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
286 defsubr (&Supcase_region);
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
287 defsubr (&Sdowncase_region);
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
288 defsubr (&Scapitalize_region);
9053
4887fc1a2dda (Fupcase_initials_region): New function.
Richard M. Stallman <rms@gnu.org>
parents: 9052
diff changeset
289 defsubr (&Supcase_initials_region);
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
290 defsubr (&Supcase_word);
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
291 defsubr (&Sdowncase_word);
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
292 defsubr (&Scapitalize_word);
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
293 }
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
294
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
295 keys_of_casefiddle ()
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
296 {
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
297 initial_define_key (control_x_map, Ctl('U'), "upcase-region");
484
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 118
diff changeset
298 Fput (intern ("upcase-region"), Qdisabled, Qt);
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
299 initial_define_key (control_x_map, Ctl('L'), "downcase-region");
484
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 118
diff changeset
300 Fput (intern ("downcase-region"), Qdisabled, Qt);
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 118
diff changeset
301
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
302 initial_define_key (meta_map, 'u', "upcase-word");
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
303 initial_define_key (meta_map, 'l', "downcase-word");
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
304 initial_define_key (meta_map, 'c', "capitalize-word");
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
305 }