Mercurial > emacs
annotate src/fns.c @ 10538:48c620ae0853
(compute_motion): Don't get hung in selective-display loop.
author | Karl Heuer <kwzh@gnu.org> |
---|---|
date | Tue, 24 Jan 1995 07:01:08 +0000 |
parents | 40c59e55775a |
children | 2a8f29cd9e9f |
rev | line source |
---|---|
211 | 1 /* Random utility Lisp functions. |
7307 | 2 Copyright (C) 1985, 1986, 1987, 1993, 1994 Free Software Foundation, Inc. |
211 | 3 |
4 This file is part of GNU Emacs. | |
5 | |
6 GNU Emacs is free software; you can redistribute it and/or modify | |
7 it under the terms of the GNU General Public License as published by | |
10405
609f34c0c7bc
(internal_equal): Once again use a switch.
Richard M. Stallman <rms@gnu.org>
parents:
10289
diff
changeset
|
8 the Free Software Foundation; either version 2, or (at your option) |
211 | 9 any later version. |
10 | |
11 GNU Emacs is distributed in the hope that it will be useful, | |
12 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 GNU General Public License for more details. | |
15 | |
16 You should have received a copy of the GNU General Public License | |
17 along with GNU Emacs; see the file COPYING. If not, write to | |
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
19 | |
20 | |
4696
1fc792473491
Include <config.h> instead of "config.h".
Roland McGrath <roland@gnu.org>
parents:
4616
diff
changeset
|
21 #include <config.h> |
211 | 22 |
23 /* Note on some machines this defines `vector' as a typedef, | |
24 so make sure we don't use that name in this file. */ | |
25 #undef vector | |
26 #define vector ***** | |
27 | |
28 #include "lisp.h" | |
29 #include "commands.h" | |
30 | |
31 #include "buffer.h" | |
1513
7381accd610d
* fns.c: #include keyboard.h.
Jim Blandy <jimb@redhat.com>
parents:
1194
diff
changeset
|
32 #include "keyboard.h" |
4004
71541ea16adf
* fns.c (Fsubstring, concat): Pass all six arguments to
Jim Blandy <jimb@redhat.com>
parents:
3379
diff
changeset
|
33 #include "intervals.h" |
211 | 34 |
8901
ab65a3dae221
(Frandom): Fix Lisp_Object vs. int problems.
Karl Heuer <kwzh@gnu.org>
parents:
8388
diff
changeset
|
35 extern Lisp_Object Flookup_key (); |
ab65a3dae221
(Frandom): Fix Lisp_Object vs. int problems.
Karl Heuer <kwzh@gnu.org>
parents:
8388
diff
changeset
|
36 |
2546
c8cd694d70eb
(provide, require): Put appropriately-marked
Richard M. Stallman <rms@gnu.org>
parents:
2525
diff
changeset
|
37 Lisp_Object Qstring_lessp, Qprovide, Qrequire; |
4456
cbfcf187b5da
(Fyes_or_no_p): Use Qyes_or_no_p_history.
Richard M. Stallman <rms@gnu.org>
parents:
4004
diff
changeset
|
38 Lisp_Object Qyes_or_no_p_history; |
211 | 39 |
9927
05aa745fc829
(internal_equal): Use new overlay substructure.
Karl Heuer <kwzh@gnu.org>
parents:
9439
diff
changeset
|
40 static int internal_equal (); |
399
21aa17a1560d
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
350
diff
changeset
|
41 |
211 | 42 DEFUN ("identity", Fidentity, Sidentity, 1, 1, 0, |
43 "Return the argument unchanged.") | |
44 (arg) | |
45 Lisp_Object arg; | |
46 { | |
47 return arg; | |
48 } | |
49 | |
10485
40c59e55775a
(Frandom): Call seed_random and get_random.
Karl Heuer <kwzh@gnu.org>
parents:
10411
diff
changeset
|
50 extern long get_random (); |
40c59e55775a
(Frandom): Call seed_random and get_random.
Karl Heuer <kwzh@gnu.org>
parents:
10411
diff
changeset
|
51 extern void seed_random (); |
40c59e55775a
(Frandom): Call seed_random and get_random.
Karl Heuer <kwzh@gnu.org>
parents:
10411
diff
changeset
|
52 extern long time (); |
40c59e55775a
(Frandom): Call seed_random and get_random.
Karl Heuer <kwzh@gnu.org>
parents:
10411
diff
changeset
|
53 |
211 | 54 DEFUN ("random", Frandom, Srandom, 0, 1, 0, |
55 "Return a pseudo-random number.\n\ | |
10411
b3c03881e6f6
(internal_equal): Delete redundant tests.
Karl Heuer <kwzh@gnu.org>
parents:
10405
diff
changeset
|
56 All integers representable in Lisp are equally likely.\n\ |
b3c03881e6f6
(internal_equal): Delete redundant tests.
Karl Heuer <kwzh@gnu.org>
parents:
10405
diff
changeset
|
57 On most systems, this is 28 bits' worth.\n\ |
10485
40c59e55775a
(Frandom): Call seed_random and get_random.
Karl Heuer <kwzh@gnu.org>
parents:
10411
diff
changeset
|
58 With positive integer argument N, return random number in interval [0,N).\n\ |
211 | 59 With argument t, set the random number seed from the current time and pid.") |
1743
a1933e20a2a3
(Frandom): Change arg name.
Richard M. Stallman <rms@gnu.org>
parents:
1513
diff
changeset
|
60 (limit) |
a1933e20a2a3
(Frandom): Change arg name.
Richard M. Stallman <rms@gnu.org>
parents:
1513
diff
changeset
|
61 Lisp_Object limit; |
211 | 62 { |
63 int val; | |
6376
3fe339cf2dde
(Frandom): Eliminate bias in random number generator.
Karl Heuer <kwzh@gnu.org>
parents:
6344
diff
changeset
|
64 unsigned long denominator; |
211 | 65 |
1743
a1933e20a2a3
(Frandom): Change arg name.
Richard M. Stallman <rms@gnu.org>
parents:
1513
diff
changeset
|
66 if (EQ (limit, Qt)) |
10485
40c59e55775a
(Frandom): Call seed_random and get_random.
Karl Heuer <kwzh@gnu.org>
parents:
10411
diff
changeset
|
67 seed_random (getpid () + time (0)); |
10411
b3c03881e6f6
(internal_equal): Delete redundant tests.
Karl Heuer <kwzh@gnu.org>
parents:
10405
diff
changeset
|
68 if (NATNUMP (limit) && XFASTINT (limit) != 0) |
211 | 69 { |
10411
b3c03881e6f6
(internal_equal): Delete redundant tests.
Karl Heuer <kwzh@gnu.org>
parents:
10405
diff
changeset
|
70 /* Try to take our random number from the higher bits of VAL, |
b3c03881e6f6
(internal_equal): Delete redundant tests.
Karl Heuer <kwzh@gnu.org>
parents:
10405
diff
changeset
|
71 not the lower, since (says Gentzel) the low bits of `random' |
b3c03881e6f6
(internal_equal): Delete redundant tests.
Karl Heuer <kwzh@gnu.org>
parents:
10405
diff
changeset
|
72 are less random than the higher ones. We do this by using the |
b3c03881e6f6
(internal_equal): Delete redundant tests.
Karl Heuer <kwzh@gnu.org>
parents:
10405
diff
changeset
|
73 quotient rather than the remainder. At the high end of the RNG |
b3c03881e6f6
(internal_equal): Delete redundant tests.
Karl Heuer <kwzh@gnu.org>
parents:
10405
diff
changeset
|
74 it's possible to get a quotient larger than limit; discarding |
b3c03881e6f6
(internal_equal): Delete redundant tests.
Karl Heuer <kwzh@gnu.org>
parents:
10405
diff
changeset
|
75 these values eliminates the bias that would otherwise appear |
b3c03881e6f6
(internal_equal): Delete redundant tests.
Karl Heuer <kwzh@gnu.org>
parents:
10405
diff
changeset
|
76 when using a large limit. */ |
b3c03881e6f6
(internal_equal): Delete redundant tests.
Karl Heuer <kwzh@gnu.org>
parents:
10405
diff
changeset
|
77 denominator = ((unsigned long)1 << VALBITS) / XFASTINT (limit); |
b3c03881e6f6
(internal_equal): Delete redundant tests.
Karl Heuer <kwzh@gnu.org>
parents:
10405
diff
changeset
|
78 do |
10485
40c59e55775a
(Frandom): Call seed_random and get_random.
Karl Heuer <kwzh@gnu.org>
parents:
10411
diff
changeset
|
79 val = get_random () / denominator; |
10411
b3c03881e6f6
(internal_equal): Delete redundant tests.
Karl Heuer <kwzh@gnu.org>
parents:
10405
diff
changeset
|
80 while (val >= XFASTINT (limit)); |
211 | 81 } |
6376
3fe339cf2dde
(Frandom): Eliminate bias in random number generator.
Karl Heuer <kwzh@gnu.org>
parents:
6344
diff
changeset
|
82 else |
10485
40c59e55775a
(Frandom): Call seed_random and get_random.
Karl Heuer <kwzh@gnu.org>
parents:
10411
diff
changeset
|
83 val = get_random (); |
211 | 84 return make_number (val); |
85 } | |
86 | |
87 /* Random data-structure functions */ | |
88 | |
89 DEFUN ("length", Flength, Slength, 1, 1, 0, | |
90 "Return the length of vector, list or string SEQUENCE.\n\ | |
91 A byte-code function object is also allowed.") | |
92 (obj) | |
93 register Lisp_Object obj; | |
94 { | |
95 register Lisp_Object tail, val; | |
96 register int i; | |
97 | |
98 retry: | |
9965
f68eab303ddb
(Flength): Don't call Farray_length, just use size field.
Karl Heuer <kwzh@gnu.org>
parents:
9927
diff
changeset
|
99 if (STRINGP (obj)) |
f68eab303ddb
(Flength): Don't call Farray_length, just use size field.
Karl Heuer <kwzh@gnu.org>
parents:
9927
diff
changeset
|
100 XSETFASTINT (val, XSTRING (obj)->size); |
10289
9dd21ecf6b0f
(Flength): Handle compiled function as pseudovector.
Richard M. Stallman <rms@gnu.org>
parents:
10114
diff
changeset
|
101 else if (VECTORP (obj)) |
9965
f68eab303ddb
(Flength): Don't call Farray_length, just use size field.
Karl Heuer <kwzh@gnu.org>
parents:
9927
diff
changeset
|
102 XSETFASTINT (val, XVECTOR (obj)->size); |
10289
9dd21ecf6b0f
(Flength): Handle compiled function as pseudovector.
Richard M. Stallman <rms@gnu.org>
parents:
10114
diff
changeset
|
103 else if (COMPILEDP (obj)) |
9dd21ecf6b0f
(Flength): Handle compiled function as pseudovector.
Richard M. Stallman <rms@gnu.org>
parents:
10114
diff
changeset
|
104 XSETFASTINT (val, XVECTOR (obj)->size & PSEUDOVECTOR_SIZE_MASK); |
211 | 105 else if (CONSP (obj)) |
106 { | |
9965
f68eab303ddb
(Flength): Don't call Farray_length, just use size field.
Karl Heuer <kwzh@gnu.org>
parents:
9927
diff
changeset
|
107 for (i = 0, tail = obj; !NILP (tail); i++) |
211 | 108 { |
109 QUIT; | |
110 tail = Fcdr (tail); | |
111 } | |
112 | |
9308
2c594629baaa
(Flength, concat, mapcar1): Don't use XFASTINT as an lvalue.
Karl Heuer <kwzh@gnu.org>
parents:
9289
diff
changeset
|
113 XSETFASTINT (val, i); |
211 | 114 } |
9965
f68eab303ddb
(Flength): Don't call Farray_length, just use size field.
Karl Heuer <kwzh@gnu.org>
parents:
9927
diff
changeset
|
115 else if (NILP (obj)) |
f68eab303ddb
(Flength): Don't call Farray_length, just use size field.
Karl Heuer <kwzh@gnu.org>
parents:
9927
diff
changeset
|
116 XSETFASTINT (val, 0); |
211 | 117 else |
118 { | |
119 obj = wrong_type_argument (Qsequencep, obj); | |
120 goto retry; | |
121 } | |
9965
f68eab303ddb
(Flength): Don't call Farray_length, just use size field.
Karl Heuer <kwzh@gnu.org>
parents:
9927
diff
changeset
|
122 return val; |
211 | 123 } |
124 | |
125 DEFUN ("string-equal", Fstring_equal, Sstring_equal, 2, 2, 0, | |
126 "T if two strings have identical contents.\n\ | |
10114
6f6db8f5b8a0
(internal_equal): Call compare_string_intervals.
Richard M. Stallman <rms@gnu.org>
parents:
10059
diff
changeset
|
127 Case is significant, but text properties are ignored.\n\ |
211 | 128 Symbols are also allowed; their print names are used instead.") |
129 (s1, s2) | |
130 register Lisp_Object s1, s2; | |
131 { | |
9128
04a702d7f662
(Frandom, Flength, Fstring_equal, Fstring_lessp, Fcopy_sequence, concat, Felt,
Karl Heuer <kwzh@gnu.org>
parents:
8966
diff
changeset
|
132 if (SYMBOLP (s1)) |
9289
e5a850de0ba8
(Fstring_equal, Fstring_lessp): Delete now-redundant XSETTYPE.
Karl Heuer <kwzh@gnu.org>
parents:
9128
diff
changeset
|
133 XSETSTRING (s1, XSYMBOL (s1)->name); |
9128
04a702d7f662
(Frandom, Flength, Fstring_equal, Fstring_lessp, Fcopy_sequence, concat, Felt,
Karl Heuer <kwzh@gnu.org>
parents:
8966
diff
changeset
|
134 if (SYMBOLP (s2)) |
9289
e5a850de0ba8
(Fstring_equal, Fstring_lessp): Delete now-redundant XSETTYPE.
Karl Heuer <kwzh@gnu.org>
parents:
9128
diff
changeset
|
135 XSETSTRING (s2, XSYMBOL (s2)->name); |
211 | 136 CHECK_STRING (s1, 0); |
137 CHECK_STRING (s2, 1); | |
138 | |
139 if (XSTRING (s1)->size != XSTRING (s2)->size || | |
140 bcmp (XSTRING (s1)->data, XSTRING (s2)->data, XSTRING (s1)->size)) | |
141 return Qnil; | |
142 return Qt; | |
143 } | |
144 | |
145 DEFUN ("string-lessp", Fstring_lessp, Sstring_lessp, 2, 2, 0, | |
146 "T if first arg string is less than second in lexicographic order.\n\ | |
147 Case is significant.\n\ | |
148 Symbols are also allowed; their print names are used instead.") | |
149 (s1, s2) | |
150 register Lisp_Object s1, s2; | |
151 { | |
152 register int i; | |
153 register unsigned char *p1, *p2; | |
154 register int end; | |
155 | |
9128
04a702d7f662
(Frandom, Flength, Fstring_equal, Fstring_lessp, Fcopy_sequence, concat, Felt,
Karl Heuer <kwzh@gnu.org>
parents:
8966
diff
changeset
|
156 if (SYMBOLP (s1)) |
9289
e5a850de0ba8
(Fstring_equal, Fstring_lessp): Delete now-redundant XSETTYPE.
Karl Heuer <kwzh@gnu.org>
parents:
9128
diff
changeset
|
157 XSETSTRING (s1, XSYMBOL (s1)->name); |
9128
04a702d7f662
(Frandom, Flength, Fstring_equal, Fstring_lessp, Fcopy_sequence, concat, Felt,
Karl Heuer <kwzh@gnu.org>
parents:
8966
diff
changeset
|
158 if (SYMBOLP (s2)) |
9289
e5a850de0ba8
(Fstring_equal, Fstring_lessp): Delete now-redundant XSETTYPE.
Karl Heuer <kwzh@gnu.org>
parents:
9128
diff
changeset
|
159 XSETSTRING (s2, XSYMBOL (s2)->name); |
211 | 160 CHECK_STRING (s1, 0); |
161 CHECK_STRING (s2, 1); | |
162 | |
163 p1 = XSTRING (s1)->data; | |
164 p2 = XSTRING (s2)->data; | |
165 end = XSTRING (s1)->size; | |
166 if (end > XSTRING (s2)->size) | |
167 end = XSTRING (s2)->size; | |
168 | |
169 for (i = 0; i < end; i++) | |
170 { | |
171 if (p1[i] != p2[i]) | |
172 return p1[i] < p2[i] ? Qt : Qnil; | |
173 } | |
174 return i < XSTRING (s2)->size ? Qt : Qnil; | |
175 } | |
176 | |
177 static Lisp_Object concat (); | |
178 | |
179 /* ARGSUSED */ | |
180 Lisp_Object | |
181 concat2 (s1, s2) | |
182 Lisp_Object s1, s2; | |
183 { | |
184 #ifdef NO_ARG_ARRAY | |
185 Lisp_Object args[2]; | |
186 args[0] = s1; | |
187 args[1] = s2; | |
188 return concat (2, args, Lisp_String, 0); | |
189 #else | |
190 return concat (2, &s1, Lisp_String, 0); | |
191 #endif /* NO_ARG_ARRAY */ | |
192 } | |
193 | |
8966
cafc16f356c2
(concat3): New function.
Richard M. Stallman <rms@gnu.org>
parents:
8901
diff
changeset
|
194 /* ARGSUSED */ |
cafc16f356c2
(concat3): New function.
Richard M. Stallman <rms@gnu.org>
parents:
8901
diff
changeset
|
195 Lisp_Object |
cafc16f356c2
(concat3): New function.
Richard M. Stallman <rms@gnu.org>
parents:
8901
diff
changeset
|
196 concat3 (s1, s2, s3) |
cafc16f356c2
(concat3): New function.
Richard M. Stallman <rms@gnu.org>
parents:
8901
diff
changeset
|
197 Lisp_Object s1, s2, s3; |
cafc16f356c2
(concat3): New function.
Richard M. Stallman <rms@gnu.org>
parents:
8901
diff
changeset
|
198 { |
cafc16f356c2
(concat3): New function.
Richard M. Stallman <rms@gnu.org>
parents:
8901
diff
changeset
|
199 #ifdef NO_ARG_ARRAY |
cafc16f356c2
(concat3): New function.
Richard M. Stallman <rms@gnu.org>
parents:
8901
diff
changeset
|
200 Lisp_Object args[3]; |
cafc16f356c2
(concat3): New function.
Richard M. Stallman <rms@gnu.org>
parents:
8901
diff
changeset
|
201 args[0] = s1; |
cafc16f356c2
(concat3): New function.
Richard M. Stallman <rms@gnu.org>
parents:
8901
diff
changeset
|
202 args[1] = s2; |
cafc16f356c2
(concat3): New function.
Richard M. Stallman <rms@gnu.org>
parents:
8901
diff
changeset
|
203 args[2] = s3; |
cafc16f356c2
(concat3): New function.
Richard M. Stallman <rms@gnu.org>
parents:
8901
diff
changeset
|
204 return concat (3, args, Lisp_String, 0); |
cafc16f356c2
(concat3): New function.
Richard M. Stallman <rms@gnu.org>
parents:
8901
diff
changeset
|
205 #else |
cafc16f356c2
(concat3): New function.
Richard M. Stallman <rms@gnu.org>
parents:
8901
diff
changeset
|
206 return concat (3, &s1, Lisp_String, 0); |
cafc16f356c2
(concat3): New function.
Richard M. Stallman <rms@gnu.org>
parents:
8901
diff
changeset
|
207 #endif /* NO_ARG_ARRAY */ |
cafc16f356c2
(concat3): New function.
Richard M. Stallman <rms@gnu.org>
parents:
8901
diff
changeset
|
208 } |
cafc16f356c2
(concat3): New function.
Richard M. Stallman <rms@gnu.org>
parents:
8901
diff
changeset
|
209 |
211 | 210 DEFUN ("append", Fappend, Sappend, 0, MANY, 0, |
211 "Concatenate all the arguments and make the result a list.\n\ | |
212 The result is a list whose elements are the elements of all the arguments.\n\ | |
213 Each argument may be a list, vector or string.\n\ | |
1037 | 214 The last argument is not copied, just used as the tail of the new list.") |
211 | 215 (nargs, args) |
216 int nargs; | |
217 Lisp_Object *args; | |
218 { | |
219 return concat (nargs, args, Lisp_Cons, 1); | |
220 } | |
221 | |
222 DEFUN ("concat", Fconcat, Sconcat, 0, MANY, 0, | |
223 "Concatenate all the arguments and make the result a string.\n\ | |
224 The result is a string whose elements are the elements of all the arguments.\n\ | |
5664 | 225 Each argument may be a string, a list of characters (integers),\n\ |
226 or a vector of characters (integers).") | |
211 | 227 (nargs, args) |
228 int nargs; | |
229 Lisp_Object *args; | |
230 { | |
231 return concat (nargs, args, Lisp_String, 0); | |
232 } | |
233 | |
234 DEFUN ("vconcat", Fvconcat, Svconcat, 0, MANY, 0, | |
235 "Concatenate all the arguments and make the result a vector.\n\ | |
236 The result is a vector whose elements are the elements of all the arguments.\n\ | |
237 Each argument may be a list, vector or string.") | |
238 (nargs, args) | |
239 int nargs; | |
240 Lisp_Object *args; | |
241 { | |
10006
402c87cbc4fa
(Fvconcat, concat): Use Lisp_Vectorlike.
Karl Heuer <kwzh@gnu.org>
parents:
9965
diff
changeset
|
242 return concat (nargs, args, Lisp_Vectorlike, 0); |
211 | 243 } |
244 | |
245 DEFUN ("copy-sequence", Fcopy_sequence, Scopy_sequence, 1, 1, 0, | |
246 "Return a copy of a list, vector or string.\n\ | |
247 The elements of a list or vector are not copied; they are shared\n\ | |
248 with the original.") | |
249 (arg) | |
250 Lisp_Object arg; | |
251 { | |
485 | 252 if (NILP (arg)) return arg; |
9128
04a702d7f662
(Frandom, Flength, Fstring_equal, Fstring_lessp, Fcopy_sequence, concat, Felt,
Karl Heuer <kwzh@gnu.org>
parents:
8966
diff
changeset
|
253 if (!CONSP (arg) && !VECTORP (arg) && !STRINGP (arg)) |
211 | 254 arg = wrong_type_argument (Qsequencep, arg); |
255 return concat (1, &arg, CONSP (arg) ? Lisp_Cons : XTYPE (arg), 0); | |
256 } | |
257 | |
258 static Lisp_Object | |
259 concat (nargs, args, target_type, last_special) | |
260 int nargs; | |
261 Lisp_Object *args; | |
262 enum Lisp_Type target_type; | |
263 int last_special; | |
264 { | |
265 Lisp_Object val; | |
266 Lisp_Object len; | |
267 register Lisp_Object tail; | |
268 register Lisp_Object this; | |
269 int toindex; | |
270 register int leni; | |
271 register int argnum; | |
272 Lisp_Object last_tail; | |
273 Lisp_Object prev; | |
274 | |
275 /* In append, the last arg isn't treated like the others */ | |
276 if (last_special && nargs > 0) | |
277 { | |
278 nargs--; | |
279 last_tail = args[nargs]; | |
280 } | |
281 else | |
282 last_tail = Qnil; | |
283 | |
284 for (argnum = 0; argnum < nargs; argnum++) | |
285 { | |
286 this = args[argnum]; | |
9128
04a702d7f662
(Frandom, Flength, Fstring_equal, Fstring_lessp, Fcopy_sequence, concat, Felt,
Karl Heuer <kwzh@gnu.org>
parents:
8966
diff
changeset
|
287 if (!(CONSP (this) || NILP (this) || VECTORP (this) || STRINGP (this) |
04a702d7f662
(Frandom, Flength, Fstring_equal, Fstring_lessp, Fcopy_sequence, concat, Felt,
Karl Heuer <kwzh@gnu.org>
parents:
8966
diff
changeset
|
288 || COMPILEDP (this))) |
211 | 289 { |
9128
04a702d7f662
(Frandom, Flength, Fstring_equal, Fstring_lessp, Fcopy_sequence, concat, Felt,
Karl Heuer <kwzh@gnu.org>
parents:
8966
diff
changeset
|
290 if (INTEGERP (this)) |
2429
96b55f2f19cd
Rename int-to-string to number-to-string, since it can handle
Jim Blandy <jimb@redhat.com>
parents:
2369
diff
changeset
|
291 args[argnum] = Fnumber_to_string (this); |
211 | 292 else |
293 args[argnum] = wrong_type_argument (Qsequencep, this); | |
294 } | |
295 } | |
296 | |
297 for (argnum = 0, leni = 0; argnum < nargs; argnum++) | |
298 { | |
299 this = args[argnum]; | |
300 len = Flength (this); | |
301 leni += XFASTINT (len); | |
302 } | |
303 | |
9308
2c594629baaa
(Flength, concat, mapcar1): Don't use XFASTINT as an lvalue.
Karl Heuer <kwzh@gnu.org>
parents:
9289
diff
changeset
|
304 XSETFASTINT (len, leni); |
211 | 305 |
306 if (target_type == Lisp_Cons) | |
307 val = Fmake_list (len, Qnil); | |
10006
402c87cbc4fa
(Fvconcat, concat): Use Lisp_Vectorlike.
Karl Heuer <kwzh@gnu.org>
parents:
9965
diff
changeset
|
308 else if (target_type == Lisp_Vectorlike) |
211 | 309 val = Fmake_vector (len, Qnil); |
310 else | |
311 val = Fmake_string (len, len); | |
312 | |
313 /* In append, if all but last arg are nil, return last arg */ | |
314 if (target_type == Lisp_Cons && EQ (val, Qnil)) | |
315 return last_tail; | |
316 | |
317 if (CONSP (val)) | |
318 tail = val, toindex = -1; /* -1 in toindex is flag we are making a list */ | |
319 else | |
320 toindex = 0; | |
321 | |
322 prev = Qnil; | |
323 | |
324 for (argnum = 0; argnum < nargs; argnum++) | |
325 { | |
326 Lisp_Object thislen; | |
327 int thisleni; | |
328 register int thisindex = 0; | |
329 | |
330 this = args[argnum]; | |
331 if (!CONSP (this)) | |
332 thislen = Flength (this), thisleni = XINT (thislen); | |
333 | |
9128
04a702d7f662
(Frandom, Flength, Fstring_equal, Fstring_lessp, Fcopy_sequence, concat, Felt,
Karl Heuer <kwzh@gnu.org>
parents:
8966
diff
changeset
|
334 if (STRINGP (this) && STRINGP (val) |
4004
71541ea16adf
* fns.c (Fsubstring, concat): Pass all six arguments to
Jim Blandy <jimb@redhat.com>
parents:
3379
diff
changeset
|
335 && ! NULL_INTERVAL_P (XSTRING (this)->intervals)) |
71541ea16adf
* fns.c (Fsubstring, concat): Pass all six arguments to
Jim Blandy <jimb@redhat.com>
parents:
3379
diff
changeset
|
336 { |
71541ea16adf
* fns.c (Fsubstring, concat): Pass all six arguments to
Jim Blandy <jimb@redhat.com>
parents:
3379
diff
changeset
|
337 copy_text_properties (make_number (0), thislen, this, |
71541ea16adf
* fns.c (Fsubstring, concat): Pass all six arguments to
Jim Blandy <jimb@redhat.com>
parents:
3379
diff
changeset
|
338 make_number (toindex), val, Qnil); |
71541ea16adf
* fns.c (Fsubstring, concat): Pass all six arguments to
Jim Blandy <jimb@redhat.com>
parents:
3379
diff
changeset
|
339 } |
71541ea16adf
* fns.c (Fsubstring, concat): Pass all six arguments to
Jim Blandy <jimb@redhat.com>
parents:
3379
diff
changeset
|
340 |
211 | 341 while (1) |
342 { | |
343 register Lisp_Object elt; | |
344 | |
4004
71541ea16adf
* fns.c (Fsubstring, concat): Pass all six arguments to
Jim Blandy <jimb@redhat.com>
parents:
3379
diff
changeset
|
345 /* Fetch next element of `this' arg into `elt', or break if |
71541ea16adf
* fns.c (Fsubstring, concat): Pass all six arguments to
Jim Blandy <jimb@redhat.com>
parents:
3379
diff
changeset
|
346 `this' is exhausted. */ |
485 | 347 if (NILP (this)) break; |
211 | 348 if (CONSP (this)) |
349 elt = Fcar (this), this = Fcdr (this); | |
350 else | |
351 { | |
352 if (thisindex >= thisleni) break; | |
9128
04a702d7f662
(Frandom, Flength, Fstring_equal, Fstring_lessp, Fcopy_sequence, concat, Felt,
Karl Heuer <kwzh@gnu.org>
parents:
8966
diff
changeset
|
353 if (STRINGP (this)) |
9308
2c594629baaa
(Flength, concat, mapcar1): Don't use XFASTINT as an lvalue.
Karl Heuer <kwzh@gnu.org>
parents:
9289
diff
changeset
|
354 XSETFASTINT (elt, XSTRING (this)->data[thisindex++]); |
211 | 355 else |
356 elt = XVECTOR (this)->contents[thisindex++]; | |
357 } | |
358 | |
359 /* Store into result */ | |
360 if (toindex < 0) | |
361 { | |
362 XCONS (tail)->car = elt; | |
363 prev = tail; | |
364 tail = XCONS (tail)->cdr; | |
365 } | |
9128
04a702d7f662
(Frandom, Flength, Fstring_equal, Fstring_lessp, Fcopy_sequence, concat, Felt,
Karl Heuer <kwzh@gnu.org>
parents:
8966
diff
changeset
|
366 else if (VECTORP (val)) |
211 | 367 XVECTOR (val)->contents[toindex++] = elt; |
368 else | |
369 { | |
9128
04a702d7f662
(Frandom, Flength, Fstring_equal, Fstring_lessp, Fcopy_sequence, concat, Felt,
Karl Heuer <kwzh@gnu.org>
parents:
8966
diff
changeset
|
370 while (!INTEGERP (elt)) |
211 | 371 elt = wrong_type_argument (Qintegerp, elt); |
372 { | |
373 #ifdef MASSC_REGISTER_BUG | |
374 /* Even removing all "register"s doesn't disable this bug! | |
375 Nothing simpler than this seems to work. */ | |
376 unsigned char *p = & XSTRING (val)->data[toindex++]; | |
377 *p = XINT (elt); | |
378 #else | |
379 XSTRING (val)->data[toindex++] = XINT (elt); | |
380 #endif | |
381 } | |
382 } | |
383 } | |
384 } | |
485 | 385 if (!NILP (prev)) |
211 | 386 XCONS (prev)->cdr = last_tail; |
387 | |
388 return val; | |
389 } | |
390 | |
391 DEFUN ("copy-alist", Fcopy_alist, Scopy_alist, 1, 1, 0, | |
392 "Return a copy of ALIST.\n\ | |
393 This is an alist which represents the same mapping from objects to objects,\n\ | |
394 but does not share the alist structure with ALIST.\n\ | |
395 The objects mapped (cars and cdrs of elements of the alist)\n\ | |
396 are shared, however.\n\ | |
397 Elements of ALIST that are not conses are also shared.") | |
398 (alist) | |
399 Lisp_Object alist; | |
400 { | |
401 register Lisp_Object tem; | |
402 | |
403 CHECK_LIST (alist, 0); | |
485 | 404 if (NILP (alist)) |
211 | 405 return alist; |
406 alist = concat (1, &alist, Lisp_Cons, 0); | |
407 for (tem = alist; CONSP (tem); tem = XCONS (tem)->cdr) | |
408 { | |
409 register Lisp_Object car; | |
410 car = XCONS (tem)->car; | |
411 | |
412 if (CONSP (car)) | |
413 XCONS (tem)->car = Fcons (XCONS (car)->car, XCONS (car)->cdr); | |
414 } | |
415 return alist; | |
416 } | |
417 | |
418 DEFUN ("substring", Fsubstring, Ssubstring, 2, 3, 0, | |
419 "Return a substring of STRING, starting at index FROM and ending before TO.\n\ | |
420 TO may be nil or omitted; then the substring runs to the end of STRING.\n\ | |
421 If FROM or TO is negative, it counts from the end.") | |
422 (string, from, to) | |
423 Lisp_Object string; | |
424 register Lisp_Object from, to; | |
425 { | |
4004
71541ea16adf
* fns.c (Fsubstring, concat): Pass all six arguments to
Jim Blandy <jimb@redhat.com>
parents:
3379
diff
changeset
|
426 Lisp_Object res; |
71541ea16adf
* fns.c (Fsubstring, concat): Pass all six arguments to
Jim Blandy <jimb@redhat.com>
parents:
3379
diff
changeset
|
427 |
211 | 428 CHECK_STRING (string, 0); |
429 CHECK_NUMBER (from, 1); | |
485 | 430 if (NILP (to)) |
211 | 431 to = Flength (string); |
432 else | |
433 CHECK_NUMBER (to, 2); | |
434 | |
435 if (XINT (from) < 0) | |
436 XSETINT (from, XINT (from) + XSTRING (string)->size); | |
437 if (XINT (to) < 0) | |
438 XSETINT (to, XINT (to) + XSTRING (string)->size); | |
439 if (!(0 <= XINT (from) && XINT (from) <= XINT (to) | |
440 && XINT (to) <= XSTRING (string)->size)) | |
441 args_out_of_range_3 (string, from, to); | |
442 | |
4004
71541ea16adf
* fns.c (Fsubstring, concat): Pass all six arguments to
Jim Blandy <jimb@redhat.com>
parents:
3379
diff
changeset
|
443 res = make_string (XSTRING (string)->data + XINT (from), |
71541ea16adf
* fns.c (Fsubstring, concat): Pass all six arguments to
Jim Blandy <jimb@redhat.com>
parents:
3379
diff
changeset
|
444 XINT (to) - XINT (from)); |
71541ea16adf
* fns.c (Fsubstring, concat): Pass all six arguments to
Jim Blandy <jimb@redhat.com>
parents:
3379
diff
changeset
|
445 copy_text_properties (from, to, string, make_number (0), res, Qnil); |
71541ea16adf
* fns.c (Fsubstring, concat): Pass all six arguments to
Jim Blandy <jimb@redhat.com>
parents:
3379
diff
changeset
|
446 return res; |
211 | 447 } |
448 | |
449 DEFUN ("nthcdr", Fnthcdr, Snthcdr, 2, 2, 0, | |
450 "Take cdr N times on LIST, returns the result.") | |
451 (n, list) | |
452 Lisp_Object n; | |
453 register Lisp_Object list; | |
454 { | |
455 register int i, num; | |
456 CHECK_NUMBER (n, 0); | |
457 num = XINT (n); | |
485 | 458 for (i = 0; i < num && !NILP (list); i++) |
211 | 459 { |
460 QUIT; | |
461 list = Fcdr (list); | |
462 } | |
463 return list; | |
464 } | |
465 | |
466 DEFUN ("nth", Fnth, Snth, 2, 2, 0, | |
467 "Return the Nth element of LIST.\n\ | |
468 N counts from zero. If LIST is not that long, nil is returned.") | |
469 (n, list) | |
470 Lisp_Object n, list; | |
471 { | |
472 return Fcar (Fnthcdr (n, list)); | |
473 } | |
474 | |
475 DEFUN ("elt", Felt, Selt, 2, 2, 0, | |
476 "Return element of SEQUENCE at index N.") | |
477 (seq, n) | |
478 register Lisp_Object seq, n; | |
479 { | |
480 CHECK_NUMBER (n, 0); | |
481 while (1) | |
482 { | |
9128
04a702d7f662
(Frandom, Flength, Fstring_equal, Fstring_lessp, Fcopy_sequence, concat, Felt,
Karl Heuer <kwzh@gnu.org>
parents:
8966
diff
changeset
|
483 if (CONSP (seq) || NILP (seq)) |
211 | 484 return Fcar (Fnthcdr (n, seq)); |
9128
04a702d7f662
(Frandom, Flength, Fstring_equal, Fstring_lessp, Fcopy_sequence, concat, Felt,
Karl Heuer <kwzh@gnu.org>
parents:
8966
diff
changeset
|
485 else if (STRINGP (seq) || VECTORP (seq)) |
211 | 486 return Faref (seq, n); |
487 else | |
488 seq = wrong_type_argument (Qsequencep, seq); | |
489 } | |
490 } | |
491 | |
492 DEFUN ("member", Fmember, Smember, 2, 2, 0, | |
6990 | 493 "Return non-nil if ELT is an element of LIST. Comparison done with `equal'.\n\ |
211 | 494 The value is actually the tail of LIST whose car is ELT.") |
495 (elt, list) | |
496 register Lisp_Object elt; | |
497 Lisp_Object list; | |
498 { | |
499 register Lisp_Object tail; | |
485 | 500 for (tail = list; !NILP (tail); tail = Fcdr (tail)) |
211 | 501 { |
502 register Lisp_Object tem; | |
503 tem = Fcar (tail); | |
485 | 504 if (! NILP (Fequal (elt, tem))) |
211 | 505 return tail; |
506 QUIT; | |
507 } | |
508 return Qnil; | |
509 } | |
510 | |
511 DEFUN ("memq", Fmemq, Smemq, 2, 2, 0, | |
512 "Return non-nil if ELT is an element of LIST. Comparison done with EQ.\n\ | |
513 The value is actually the tail of LIST whose car is ELT.") | |
514 (elt, list) | |
515 register Lisp_Object elt; | |
516 Lisp_Object list; | |
517 { | |
518 register Lisp_Object tail; | |
485 | 519 for (tail = list; !NILP (tail); tail = Fcdr (tail)) |
211 | 520 { |
521 register Lisp_Object tem; | |
522 tem = Fcar (tail); | |
523 if (EQ (elt, tem)) return tail; | |
524 QUIT; | |
525 } | |
526 return Qnil; | |
527 } | |
528 | |
529 DEFUN ("assq", Fassq, Sassq, 2, 2, 0, | |
5661
066830a71a63
(Fassq, Fassoc): Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents:
5437
diff
changeset
|
530 "Return non-nil if KEY is `eq' to the car of an element of LIST.\n\ |
066830a71a63
(Fassq, Fassoc): Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents:
5437
diff
changeset
|
531 The value is actually the element of LIST whose car is KEY.\n\ |
211 | 532 Elements of LIST that are not conses are ignored.") |
533 (key, list) | |
534 register Lisp_Object key; | |
535 Lisp_Object list; | |
536 { | |
537 register Lisp_Object tail; | |
485 | 538 for (tail = list; !NILP (tail); tail = Fcdr (tail)) |
211 | 539 { |
540 register Lisp_Object elt, tem; | |
541 elt = Fcar (tail); | |
542 if (!CONSP (elt)) continue; | |
543 tem = Fcar (elt); | |
544 if (EQ (key, tem)) return elt; | |
545 QUIT; | |
546 } | |
547 return Qnil; | |
548 } | |
549 | |
550 /* Like Fassq but never report an error and do not allow quits. | |
551 Use only on lists known never to be circular. */ | |
552 | |
553 Lisp_Object | |
554 assq_no_quit (key, list) | |
555 register Lisp_Object key; | |
556 Lisp_Object list; | |
557 { | |
558 register Lisp_Object tail; | |
559 for (tail = list; CONSP (tail); tail = Fcdr (tail)) | |
560 { | |
561 register Lisp_Object elt, tem; | |
562 elt = Fcar (tail); | |
563 if (!CONSP (elt)) continue; | |
564 tem = Fcar (elt); | |
565 if (EQ (key, tem)) return elt; | |
566 } | |
567 return Qnil; | |
568 } | |
569 | |
570 DEFUN ("assoc", Fassoc, Sassoc, 2, 2, 0, | |
5661
066830a71a63
(Fassq, Fassoc): Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents:
5437
diff
changeset
|
571 "Return non-nil if KEY is `equal' to the car of an element of LIST.\n\ |
066830a71a63
(Fassq, Fassoc): Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents:
5437
diff
changeset
|
572 The value is actually the element of LIST whose car is KEY.") |
211 | 573 (key, list) |
574 register Lisp_Object key; | |
575 Lisp_Object list; | |
576 { | |
577 register Lisp_Object tail; | |
485 | 578 for (tail = list; !NILP (tail); tail = Fcdr (tail)) |
211 | 579 { |
580 register Lisp_Object elt, tem; | |
581 elt = Fcar (tail); | |
582 if (!CONSP (elt)) continue; | |
583 tem = Fequal (Fcar (elt), key); | |
485 | 584 if (!NILP (tem)) return elt; |
211 | 585 QUIT; |
586 } | |
587 return Qnil; | |
588 } | |
589 | |
590 DEFUN ("rassq", Frassq, Srassq, 2, 2, 0, | |
591 "Return non-nil if ELT is `eq' to the cdr of an element of LIST.\n\ | |
592 The value is actually the element of LIST whose cdr is ELT.") | |
593 (key, list) | |
594 register Lisp_Object key; | |
595 Lisp_Object list; | |
596 { | |
597 register Lisp_Object tail; | |
485 | 598 for (tail = list; !NILP (tail); tail = Fcdr (tail)) |
211 | 599 { |
600 register Lisp_Object elt, tem; | |
601 elt = Fcar (tail); | |
602 if (!CONSP (elt)) continue; | |
603 tem = Fcdr (elt); | |
604 if (EQ (key, tem)) return elt; | |
605 QUIT; | |
606 } | |
607 return Qnil; | |
608 } | |
609 | |
610 DEFUN ("delq", Fdelq, Sdelq, 2, 2, 0, | |
611 "Delete by side effect any occurrences of ELT as a member of LIST.\n\ | |
612 The modified LIST is returned. Comparison is done with `eq'.\n\ | |
613 If the first member of LIST is ELT, there is no way to remove it by side effect;\n\ | |
614 therefore, write `(setq foo (delq element foo))'\n\ | |
615 to be sure of changing the value of `foo'.") | |
616 (elt, list) | |
617 register Lisp_Object elt; | |
618 Lisp_Object list; | |
619 { | |
620 register Lisp_Object tail, prev; | |
621 register Lisp_Object tem; | |
622 | |
623 tail = list; | |
624 prev = Qnil; | |
485 | 625 while (!NILP (tail)) |
211 | 626 { |
627 tem = Fcar (tail); | |
628 if (EQ (elt, tem)) | |
629 { | |
485 | 630 if (NILP (prev)) |
211 | 631 list = Fcdr (tail); |
632 else | |
633 Fsetcdr (prev, Fcdr (tail)); | |
634 } | |
635 else | |
636 prev = tail; | |
637 tail = Fcdr (tail); | |
638 QUIT; | |
639 } | |
640 return list; | |
641 } | |
642 | |
414 | 643 DEFUN ("delete", Fdelete, Sdelete, 2, 2, 0, |
401 | 644 "Delete by side effect any occurrences of ELT as a member of LIST.\n\ |
645 The modified LIST is returned. Comparison is done with `equal'.\n\ | |
6990 | 646 If the first member of LIST is ELT, deleting it is not a side effect;\n\ |
647 it is simply using a different list.\n\ | |
648 Therefore, write `(setq foo (delete element foo))'\n\ | |
401 | 649 to be sure of changing the value of `foo'.") |
650 (elt, list) | |
651 register Lisp_Object elt; | |
652 Lisp_Object list; | |
653 { | |
654 register Lisp_Object tail, prev; | |
655 register Lisp_Object tem; | |
656 | |
657 tail = list; | |
658 prev = Qnil; | |
485 | 659 while (!NILP (tail)) |
401 | 660 { |
661 tem = Fcar (tail); | |
1513
7381accd610d
* fns.c: #include keyboard.h.
Jim Blandy <jimb@redhat.com>
parents:
1194
diff
changeset
|
662 if (! NILP (Fequal (elt, tem))) |
401 | 663 { |
485 | 664 if (NILP (prev)) |
401 | 665 list = Fcdr (tail); |
666 else | |
667 Fsetcdr (prev, Fcdr (tail)); | |
668 } | |
669 else | |
670 prev = tail; | |
671 tail = Fcdr (tail); | |
672 QUIT; | |
673 } | |
674 return list; | |
675 } | |
676 | |
211 | 677 DEFUN ("nreverse", Fnreverse, Snreverse, 1, 1, 0, |
678 "Reverse LIST by modifying cdr pointers.\n\ | |
679 Returns the beginning of the reversed list.") | |
680 (list) | |
681 Lisp_Object list; | |
682 { | |
683 register Lisp_Object prev, tail, next; | |
684 | |
485 | 685 if (NILP (list)) return list; |
211 | 686 prev = Qnil; |
687 tail = list; | |
485 | 688 while (!NILP (tail)) |
211 | 689 { |
690 QUIT; | |
691 next = Fcdr (tail); | |
692 Fsetcdr (tail, prev); | |
693 prev = tail; | |
694 tail = next; | |
695 } | |
696 return prev; | |
697 } | |
698 | |
699 DEFUN ("reverse", Freverse, Sreverse, 1, 1, 0, | |
700 "Reverse LIST, copying. Returns the beginning of the reversed list.\n\ | |
701 See also the function `nreverse', which is used more often.") | |
702 (list) | |
703 Lisp_Object list; | |
704 { | |
705 Lisp_Object length; | |
706 register Lisp_Object *vec; | |
707 register Lisp_Object tail; | |
708 register int i; | |
709 | |
710 length = Flength (list); | |
711 vec = (Lisp_Object *) alloca (XINT (length) * sizeof (Lisp_Object)); | |
712 for (i = XINT (length) - 1, tail = list; i >= 0; i--, tail = Fcdr (tail)) | |
713 vec[i] = Fcar (tail); | |
714 | |
715 return Flist (XINT (length), vec); | |
716 } | |
717 | |
718 Lisp_Object merge (); | |
719 | |
720 DEFUN ("sort", Fsort, Ssort, 2, 2, 0, | |
721 "Sort LIST, stably, comparing elements using PREDICATE.\n\ | |
722 Returns the sorted list. LIST is modified by side effects.\n\ | |
723 PREDICATE is called with two elements of LIST, and should return T\n\ | |
724 if the first element is \"less\" than the second.") | |
725 (list, pred) | |
726 Lisp_Object list, pred; | |
727 { | |
728 Lisp_Object front, back; | |
729 register Lisp_Object len, tem; | |
730 struct gcpro gcpro1, gcpro2; | |
731 register int length; | |
732 | |
733 front = list; | |
734 len = Flength (list); | |
735 length = XINT (len); | |
736 if (length < 2) | |
737 return list; | |
738 | |
739 XSETINT (len, (length / 2) - 1); | |
740 tem = Fnthcdr (len, list); | |
741 back = Fcdr (tem); | |
742 Fsetcdr (tem, Qnil); | |
743 | |
744 GCPRO2 (front, back); | |
745 front = Fsort (front, pred); | |
746 back = Fsort (back, pred); | |
747 UNGCPRO; | |
748 return merge (front, back, pred); | |
749 } | |
750 | |
751 Lisp_Object | |
752 merge (org_l1, org_l2, pred) | |
753 Lisp_Object org_l1, org_l2; | |
754 Lisp_Object pred; | |
755 { | |
756 Lisp_Object value; | |
757 register Lisp_Object tail; | |
758 Lisp_Object tem; | |
759 register Lisp_Object l1, l2; | |
760 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4; | |
761 | |
762 l1 = org_l1; | |
763 l2 = org_l2; | |
764 tail = Qnil; | |
765 value = Qnil; | |
766 | |
767 /* It is sufficient to protect org_l1 and org_l2. | |
768 When l1 and l2 are updated, we copy the new values | |
769 back into the org_ vars. */ | |
770 GCPRO4 (org_l1, org_l2, pred, value); | |
771 | |
772 while (1) | |
773 { | |
485 | 774 if (NILP (l1)) |
211 | 775 { |
776 UNGCPRO; | |
485 | 777 if (NILP (tail)) |
211 | 778 return l2; |
779 Fsetcdr (tail, l2); | |
780 return value; | |
781 } | |
485 | 782 if (NILP (l2)) |
211 | 783 { |
784 UNGCPRO; | |
485 | 785 if (NILP (tail)) |
211 | 786 return l1; |
787 Fsetcdr (tail, l1); | |
788 return value; | |
789 } | |
790 tem = call2 (pred, Fcar (l2), Fcar (l1)); | |
485 | 791 if (NILP (tem)) |
211 | 792 { |
793 tem = l1; | |
794 l1 = Fcdr (l1); | |
795 org_l1 = l1; | |
796 } | |
797 else | |
798 { | |
799 tem = l2; | |
800 l2 = Fcdr (l2); | |
801 org_l2 = l2; | |
802 } | |
485 | 803 if (NILP (tail)) |
211 | 804 value = tem; |
805 else | |
806 Fsetcdr (tail, tem); | |
807 tail = tem; | |
808 } | |
809 } | |
810 | |
811 DEFUN ("get", Fget, Sget, 2, 2, 0, | |
812 "Return the value of SYMBOL's PROPNAME property.\n\ | |
813 This is the last VALUE stored with `(put SYMBOL PROPNAME VALUE)'.") | |
814 (sym, prop) | |
815 Lisp_Object sym; | |
816 register Lisp_Object prop; | |
817 { | |
818 register Lisp_Object tail; | |
485 | 819 for (tail = Fsymbol_plist (sym); !NILP (tail); tail = Fcdr (Fcdr (tail))) |
211 | 820 { |
821 register Lisp_Object tem; | |
822 tem = Fcar (tail); | |
823 if (EQ (prop, tem)) | |
824 return Fcar (Fcdr (tail)); | |
825 } | |
826 return Qnil; | |
827 } | |
828 | |
829 DEFUN ("put", Fput, Sput, 3, 3, 0, | |
830 "Store SYMBOL's PROPNAME property with value VALUE.\n\ | |
831 It can be retrieved with `(get SYMBOL PROPNAME)'.") | |
832 (sym, prop, val) | |
833 Lisp_Object sym; | |
834 register Lisp_Object prop; | |
835 Lisp_Object val; | |
836 { | |
837 register Lisp_Object tail, prev; | |
838 Lisp_Object newcell; | |
839 prev = Qnil; | |
485 | 840 for (tail = Fsymbol_plist (sym); !NILP (tail); tail = Fcdr (Fcdr (tail))) |
211 | 841 { |
842 register Lisp_Object tem; | |
843 tem = Fcar (tail); | |
844 if (EQ (prop, tem)) | |
845 return Fsetcar (Fcdr (tail), val); | |
846 prev = tail; | |
847 } | |
848 newcell = Fcons (prop, Fcons (val, Qnil)); | |
485 | 849 if (NILP (prev)) |
211 | 850 Fsetplist (sym, newcell); |
851 else | |
852 Fsetcdr (Fcdr (prev), newcell); | |
853 return val; | |
854 } | |
855 | |
856 DEFUN ("equal", Fequal, Sequal, 2, 2, 0, | |
857 "T if two Lisp objects have similar structure and contents.\n\ | |
858 They must have the same data type.\n\ | |
859 Conses are compared by comparing the cars and the cdrs.\n\ | |
860 Vectors and strings are compared element by element.\n\ | |
3379
68f28e378f50
(internal_equal): Don't let ints be equal to floats.
Richard M. Stallman <rms@gnu.org>
parents:
3332
diff
changeset
|
861 Numbers are compared by value, but integers cannot equal floats.\n\ |
68f28e378f50
(internal_equal): Don't let ints be equal to floats.
Richard M. Stallman <rms@gnu.org>
parents:
3332
diff
changeset
|
862 (Use `=' if you want integers and floats to be able to be equal.)\n\ |
68f28e378f50
(internal_equal): Don't let ints be equal to floats.
Richard M. Stallman <rms@gnu.org>
parents:
3332
diff
changeset
|
863 Symbols must match exactly.") |
211 | 864 (o1, o2) |
865 register Lisp_Object o1, o2; | |
866 { | |
9927
05aa745fc829
(internal_equal): Use new overlay substructure.
Karl Heuer <kwzh@gnu.org>
parents:
9439
diff
changeset
|
867 return internal_equal (o1, o2, 0) ? Qt : Qnil; |
399
21aa17a1560d
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
350
diff
changeset
|
868 } |
21aa17a1560d
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
350
diff
changeset
|
869 |
9927
05aa745fc829
(internal_equal): Use new overlay substructure.
Karl Heuer <kwzh@gnu.org>
parents:
9439
diff
changeset
|
870 static int |
399
21aa17a1560d
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
350
diff
changeset
|
871 internal_equal (o1, o2, depth) |
21aa17a1560d
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
350
diff
changeset
|
872 register Lisp_Object o1, o2; |
21aa17a1560d
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
350
diff
changeset
|
873 int depth; |
21aa17a1560d
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
350
diff
changeset
|
874 { |
21aa17a1560d
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
350
diff
changeset
|
875 if (depth > 200) |
21aa17a1560d
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
350
diff
changeset
|
876 error ("Stack overflow in equal"); |
10405
609f34c0c7bc
(internal_equal): Once again use a switch.
Richard M. Stallman <rms@gnu.org>
parents:
10289
diff
changeset
|
877 |
9927
05aa745fc829
(internal_equal): Use new overlay substructure.
Karl Heuer <kwzh@gnu.org>
parents:
9439
diff
changeset
|
878 tail_recurse: |
211 | 879 QUIT; |
10405
609f34c0c7bc
(internal_equal): Once again use a switch.
Richard M. Stallman <rms@gnu.org>
parents:
10289
diff
changeset
|
880 if (EQ (o1, o2)) |
609f34c0c7bc
(internal_equal): Once again use a switch.
Richard M. Stallman <rms@gnu.org>
parents:
10289
diff
changeset
|
881 return 1; |
609f34c0c7bc
(internal_equal): Once again use a switch.
Richard M. Stallman <rms@gnu.org>
parents:
10289
diff
changeset
|
882 if (XTYPE (o1) != XTYPE (o2)) |
609f34c0c7bc
(internal_equal): Once again use a switch.
Richard M. Stallman <rms@gnu.org>
parents:
10289
diff
changeset
|
883 return 0; |
609f34c0c7bc
(internal_equal): Once again use a switch.
Richard M. Stallman <rms@gnu.org>
parents:
10289
diff
changeset
|
884 |
609f34c0c7bc
(internal_equal): Once again use a switch.
Richard M. Stallman <rms@gnu.org>
parents:
10289
diff
changeset
|
885 switch (XTYPE (o1)) |
211 | 886 { |
10405
609f34c0c7bc
(internal_equal): Once again use a switch.
Richard M. Stallman <rms@gnu.org>
parents:
10289
diff
changeset
|
887 #ifdef LISP_FLOAT_TYPE |
609f34c0c7bc
(internal_equal): Once again use a switch.
Richard M. Stallman <rms@gnu.org>
parents:
10289
diff
changeset
|
888 case Lisp_Float: |
609f34c0c7bc
(internal_equal): Once again use a switch.
Richard M. Stallman <rms@gnu.org>
parents:
10289
diff
changeset
|
889 return (extract_float (o1) == extract_float (o2)); |
609f34c0c7bc
(internal_equal): Once again use a switch.
Richard M. Stallman <rms@gnu.org>
parents:
10289
diff
changeset
|
890 #endif |
609f34c0c7bc
(internal_equal): Once again use a switch.
Richard M. Stallman <rms@gnu.org>
parents:
10289
diff
changeset
|
891 |
609f34c0c7bc
(internal_equal): Once again use a switch.
Richard M. Stallman <rms@gnu.org>
parents:
10289
diff
changeset
|
892 case Lisp_Cons: |
10411
b3c03881e6f6
(internal_equal): Delete redundant tests.
Karl Heuer <kwzh@gnu.org>
parents:
10405
diff
changeset
|
893 if (!internal_equal (XCONS (o1)->car, XCONS (o2)->car, depth + 1)) |
b3c03881e6f6
(internal_equal): Delete redundant tests.
Karl Heuer <kwzh@gnu.org>
parents:
10405
diff
changeset
|
894 return 0; |
b3c03881e6f6
(internal_equal): Delete redundant tests.
Karl Heuer <kwzh@gnu.org>
parents:
10405
diff
changeset
|
895 o1 = XCONS (o1)->cdr; |
b3c03881e6f6
(internal_equal): Delete redundant tests.
Karl Heuer <kwzh@gnu.org>
parents:
10405
diff
changeset
|
896 o2 = XCONS (o2)->cdr; |
b3c03881e6f6
(internal_equal): Delete redundant tests.
Karl Heuer <kwzh@gnu.org>
parents:
10405
diff
changeset
|
897 goto tail_recurse; |
10405
609f34c0c7bc
(internal_equal): Once again use a switch.
Richard M. Stallman <rms@gnu.org>
parents:
10289
diff
changeset
|
898 |
609f34c0c7bc
(internal_equal): Once again use a switch.
Richard M. Stallman <rms@gnu.org>
parents:
10289
diff
changeset
|
899 case Lisp_Misc: |
10411
b3c03881e6f6
(internal_equal): Delete redundant tests.
Karl Heuer <kwzh@gnu.org>
parents:
10405
diff
changeset
|
900 if (XMISC (o1)->type != XMISC (o2)->type) |
9927
05aa745fc829
(internal_equal): Use new overlay substructure.
Karl Heuer <kwzh@gnu.org>
parents:
9439
diff
changeset
|
901 return 0; |
10405
609f34c0c7bc
(internal_equal): Once again use a switch.
Richard M. Stallman <rms@gnu.org>
parents:
10289
diff
changeset
|
902 if (OVERLAYP (o1)) |
211 | 903 { |
10405
609f34c0c7bc
(internal_equal): Once again use a switch.
Richard M. Stallman <rms@gnu.org>
parents:
10289
diff
changeset
|
904 if (!internal_equal (OVERLAY_START (o1), OVERLAY_START (o1), |
609f34c0c7bc
(internal_equal): Once again use a switch.
Richard M. Stallman <rms@gnu.org>
parents:
10289
diff
changeset
|
905 depth + 1) |
609f34c0c7bc
(internal_equal): Once again use a switch.
Richard M. Stallman <rms@gnu.org>
parents:
10289
diff
changeset
|
906 || !internal_equal (OVERLAY_END (o1), OVERLAY_END (o1), |
609f34c0c7bc
(internal_equal): Once again use a switch.
Richard M. Stallman <rms@gnu.org>
parents:
10289
diff
changeset
|
907 depth + 1)) |
9927
05aa745fc829
(internal_equal): Use new overlay substructure.
Karl Heuer <kwzh@gnu.org>
parents:
9439
diff
changeset
|
908 return 0; |
10405
609f34c0c7bc
(internal_equal): Once again use a switch.
Richard M. Stallman <rms@gnu.org>
parents:
10289
diff
changeset
|
909 o1 = XOVERLAY (o1)->plist; |
609f34c0c7bc
(internal_equal): Once again use a switch.
Richard M. Stallman <rms@gnu.org>
parents:
10289
diff
changeset
|
910 o2 = XOVERLAY (o2)->plist; |
609f34c0c7bc
(internal_equal): Once again use a switch.
Richard M. Stallman <rms@gnu.org>
parents:
10289
diff
changeset
|
911 goto tail_recurse; |
609f34c0c7bc
(internal_equal): Once again use a switch.
Richard M. Stallman <rms@gnu.org>
parents:
10289
diff
changeset
|
912 } |
609f34c0c7bc
(internal_equal): Once again use a switch.
Richard M. Stallman <rms@gnu.org>
parents:
10289
diff
changeset
|
913 if (MARKERP (o1)) |
609f34c0c7bc
(internal_equal): Once again use a switch.
Richard M. Stallman <rms@gnu.org>
parents:
10289
diff
changeset
|
914 { |
609f34c0c7bc
(internal_equal): Once again use a switch.
Richard M. Stallman <rms@gnu.org>
parents:
10289
diff
changeset
|
915 return (XMARKER (o1)->buffer == XMARKER (o2)->buffer |
609f34c0c7bc
(internal_equal): Once again use a switch.
Richard M. Stallman <rms@gnu.org>
parents:
10289
diff
changeset
|
916 && (XMARKER (o1)->buffer == 0 |
609f34c0c7bc
(internal_equal): Once again use a switch.
Richard M. Stallman <rms@gnu.org>
parents:
10289
diff
changeset
|
917 || XMARKER (o1)->bufpos == XMARKER (o2)->bufpos)); |
211 | 918 } |
10405
609f34c0c7bc
(internal_equal): Once again use a switch.
Richard M. Stallman <rms@gnu.org>
parents:
10289
diff
changeset
|
919 break; |
609f34c0c7bc
(internal_equal): Once again use a switch.
Richard M. Stallman <rms@gnu.org>
parents:
10289
diff
changeset
|
920 |
609f34c0c7bc
(internal_equal): Once again use a switch.
Richard M. Stallman <rms@gnu.org>
parents:
10289
diff
changeset
|
921 case Lisp_Vectorlike: |
10411
b3c03881e6f6
(internal_equal): Delete redundant tests.
Karl Heuer <kwzh@gnu.org>
parents:
10405
diff
changeset
|
922 { |
b3c03881e6f6
(internal_equal): Delete redundant tests.
Karl Heuer <kwzh@gnu.org>
parents:
10405
diff
changeset
|
923 register int i, size; |
b3c03881e6f6
(internal_equal): Delete redundant tests.
Karl Heuer <kwzh@gnu.org>
parents:
10405
diff
changeset
|
924 size = XVECTOR (o1)->size; |
b3c03881e6f6
(internal_equal): Delete redundant tests.
Karl Heuer <kwzh@gnu.org>
parents:
10405
diff
changeset
|
925 /* Pseudovectors have the type encoded in the size field, so this test |
b3c03881e6f6
(internal_equal): Delete redundant tests.
Karl Heuer <kwzh@gnu.org>
parents:
10405
diff
changeset
|
926 actually checks that the objects have the same type as well as the |
b3c03881e6f6
(internal_equal): Delete redundant tests.
Karl Heuer <kwzh@gnu.org>
parents:
10405
diff
changeset
|
927 same size. */ |
b3c03881e6f6
(internal_equal): Delete redundant tests.
Karl Heuer <kwzh@gnu.org>
parents:
10405
diff
changeset
|
928 if (XVECTOR (o2)->size != size) |
b3c03881e6f6
(internal_equal): Delete redundant tests.
Karl Heuer <kwzh@gnu.org>
parents:
10405
diff
changeset
|
929 return 0; |
b3c03881e6f6
(internal_equal): Delete redundant tests.
Karl Heuer <kwzh@gnu.org>
parents:
10405
diff
changeset
|
930 /* But only true vectors and compiled functions are actually sensible |
b3c03881e6f6
(internal_equal): Delete redundant tests.
Karl Heuer <kwzh@gnu.org>
parents:
10405
diff
changeset
|
931 to compare, so eliminate the others now. */ |
b3c03881e6f6
(internal_equal): Delete redundant tests.
Karl Heuer <kwzh@gnu.org>
parents:
10405
diff
changeset
|
932 if (size & PSEUDOVECTOR_FLAG) |
b3c03881e6f6
(internal_equal): Delete redundant tests.
Karl Heuer <kwzh@gnu.org>
parents:
10405
diff
changeset
|
933 { |
b3c03881e6f6
(internal_equal): Delete redundant tests.
Karl Heuer <kwzh@gnu.org>
parents:
10405
diff
changeset
|
934 if (!(size & PVEC_COMPILED)) |
b3c03881e6f6
(internal_equal): Delete redundant tests.
Karl Heuer <kwzh@gnu.org>
parents:
10405
diff
changeset
|
935 return 0; |
b3c03881e6f6
(internal_equal): Delete redundant tests.
Karl Heuer <kwzh@gnu.org>
parents:
10405
diff
changeset
|
936 size &= PSEUDOVECTOR_SIZE_MASK; |
b3c03881e6f6
(internal_equal): Delete redundant tests.
Karl Heuer <kwzh@gnu.org>
parents:
10405
diff
changeset
|
937 } |
b3c03881e6f6
(internal_equal): Delete redundant tests.
Karl Heuer <kwzh@gnu.org>
parents:
10405
diff
changeset
|
938 for (i = 0; i < size; i++) |
b3c03881e6f6
(internal_equal): Delete redundant tests.
Karl Heuer <kwzh@gnu.org>
parents:
10405
diff
changeset
|
939 { |
b3c03881e6f6
(internal_equal): Delete redundant tests.
Karl Heuer <kwzh@gnu.org>
parents:
10405
diff
changeset
|
940 Lisp_Object v1, v2; |
b3c03881e6f6
(internal_equal): Delete redundant tests.
Karl Heuer <kwzh@gnu.org>
parents:
10405
diff
changeset
|
941 v1 = XVECTOR (o1)->contents [i]; |
b3c03881e6f6
(internal_equal): Delete redundant tests.
Karl Heuer <kwzh@gnu.org>
parents:
10405
diff
changeset
|
942 v2 = XVECTOR (o2)->contents [i]; |
b3c03881e6f6
(internal_equal): Delete redundant tests.
Karl Heuer <kwzh@gnu.org>
parents:
10405
diff
changeset
|
943 if (!internal_equal (v1, v2, depth + 1)) |
b3c03881e6f6
(internal_equal): Delete redundant tests.
Karl Heuer <kwzh@gnu.org>
parents:
10405
diff
changeset
|
944 return 0; |
b3c03881e6f6
(internal_equal): Delete redundant tests.
Karl Heuer <kwzh@gnu.org>
parents:
10405
diff
changeset
|
945 } |
b3c03881e6f6
(internal_equal): Delete redundant tests.
Karl Heuer <kwzh@gnu.org>
parents:
10405
diff
changeset
|
946 return 1; |
b3c03881e6f6
(internal_equal): Delete redundant tests.
Karl Heuer <kwzh@gnu.org>
parents:
10405
diff
changeset
|
947 } |
10405
609f34c0c7bc
(internal_equal): Once again use a switch.
Richard M. Stallman <rms@gnu.org>
parents:
10289
diff
changeset
|
948 break; |
609f34c0c7bc
(internal_equal): Once again use a switch.
Richard M. Stallman <rms@gnu.org>
parents:
10289
diff
changeset
|
949 |
609f34c0c7bc
(internal_equal): Once again use a switch.
Richard M. Stallman <rms@gnu.org>
parents:
10289
diff
changeset
|
950 case Lisp_String: |
10411
b3c03881e6f6
(internal_equal): Delete redundant tests.
Karl Heuer <kwzh@gnu.org>
parents:
10405
diff
changeset
|
951 if (XSTRING (o1)->size != XSTRING (o2)->size) |
b3c03881e6f6
(internal_equal): Delete redundant tests.
Karl Heuer <kwzh@gnu.org>
parents:
10405
diff
changeset
|
952 return 0; |
b3c03881e6f6
(internal_equal): Delete redundant tests.
Karl Heuer <kwzh@gnu.org>
parents:
10405
diff
changeset
|
953 if (bcmp (XSTRING (o1)->data, XSTRING (o2)->data, |
b3c03881e6f6
(internal_equal): Delete redundant tests.
Karl Heuer <kwzh@gnu.org>
parents:
10405
diff
changeset
|
954 XSTRING (o1)->size)) |
b3c03881e6f6
(internal_equal): Delete redundant tests.
Karl Heuer <kwzh@gnu.org>
parents:
10405
diff
changeset
|
955 return 0; |
10114
6f6db8f5b8a0
(internal_equal): Call compare_string_intervals.
Richard M. Stallman <rms@gnu.org>
parents:
10059
diff
changeset
|
956 #ifdef USE_TEXT_PROPERTIES |
10411
b3c03881e6f6
(internal_equal): Delete redundant tests.
Karl Heuer <kwzh@gnu.org>
parents:
10405
diff
changeset
|
957 /* If the strings have intervals, verify they match; |
b3c03881e6f6
(internal_equal): Delete redundant tests.
Karl Heuer <kwzh@gnu.org>
parents:
10405
diff
changeset
|
958 if not, they are unequal. */ |
b3c03881e6f6
(internal_equal): Delete redundant tests.
Karl Heuer <kwzh@gnu.org>
parents:
10405
diff
changeset
|
959 if ((XSTRING (o1)->intervals != 0 || XSTRING (o2)->intervals != 0) |
b3c03881e6f6
(internal_equal): Delete redundant tests.
Karl Heuer <kwzh@gnu.org>
parents:
10405
diff
changeset
|
960 && ! compare_string_intervals (o1, o2)) |
b3c03881e6f6
(internal_equal): Delete redundant tests.
Karl Heuer <kwzh@gnu.org>
parents:
10405
diff
changeset
|
961 return 0; |
10114
6f6db8f5b8a0
(internal_equal): Call compare_string_intervals.
Richard M. Stallman <rms@gnu.org>
parents:
10059
diff
changeset
|
962 #endif |
10411
b3c03881e6f6
(internal_equal): Delete redundant tests.
Karl Heuer <kwzh@gnu.org>
parents:
10405
diff
changeset
|
963 return 1; |
211 | 964 } |
9927
05aa745fc829
(internal_equal): Use new overlay substructure.
Karl Heuer <kwzh@gnu.org>
parents:
9439
diff
changeset
|
965 return 0; |
211 | 966 } |
967 | |
968 DEFUN ("fillarray", Ffillarray, Sfillarray, 2, 2, 0, | |
969 "Store each element of ARRAY with ITEM. ARRAY is a vector or string.") | |
970 (array, item) | |
971 Lisp_Object array, item; | |
972 { | |
973 register int size, index, charval; | |
974 retry: | |
9128
04a702d7f662
(Frandom, Flength, Fstring_equal, Fstring_lessp, Fcopy_sequence, concat, Felt,
Karl Heuer <kwzh@gnu.org>
parents:
8966
diff
changeset
|
975 if (VECTORP (array)) |
211 | 976 { |
977 register Lisp_Object *p = XVECTOR (array)->contents; | |
978 size = XVECTOR (array)->size; | |
979 for (index = 0; index < size; index++) | |
980 p[index] = item; | |
981 } | |
9128
04a702d7f662
(Frandom, Flength, Fstring_equal, Fstring_lessp, Fcopy_sequence, concat, Felt,
Karl Heuer <kwzh@gnu.org>
parents:
8966
diff
changeset
|
982 else if (STRINGP (array)) |
211 | 983 { |
984 register unsigned char *p = XSTRING (array)->data; | |
985 CHECK_NUMBER (item, 1); | |
986 charval = XINT (item); | |
987 size = XSTRING (array)->size; | |
988 for (index = 0; index < size; index++) | |
989 p[index] = charval; | |
990 } | |
991 else | |
992 { | |
993 array = wrong_type_argument (Qarrayp, array); | |
994 goto retry; | |
995 } | |
996 return array; | |
997 } | |
998 | |
999 /* ARGSUSED */ | |
1000 Lisp_Object | |
1001 nconc2 (s1, s2) | |
1002 Lisp_Object s1, s2; | |
1003 { | |
1004 #ifdef NO_ARG_ARRAY | |
1005 Lisp_Object args[2]; | |
1006 args[0] = s1; | |
1007 args[1] = s2; | |
1008 return Fnconc (2, args); | |
1009 #else | |
1010 return Fnconc (2, &s1); | |
1011 #endif /* NO_ARG_ARRAY */ | |
1012 } | |
1013 | |
1014 DEFUN ("nconc", Fnconc, Snconc, 0, MANY, 0, | |
1015 "Concatenate any number of lists by altering them.\n\ | |
1016 Only the last argument is not altered, and need not be a list.") | |
1017 (nargs, args) | |
1018 int nargs; | |
1019 Lisp_Object *args; | |
1020 { | |
1021 register int argnum; | |
1022 register Lisp_Object tail, tem, val; | |
1023 | |
1024 val = Qnil; | |
1025 | |
1026 for (argnum = 0; argnum < nargs; argnum++) | |
1027 { | |
1028 tem = args[argnum]; | |
485 | 1029 if (NILP (tem)) continue; |
211 | 1030 |
485 | 1031 if (NILP (val)) |
211 | 1032 val = tem; |
1033 | |
1034 if (argnum + 1 == nargs) break; | |
1035 | |
1036 if (!CONSP (tem)) | |
1037 tem = wrong_type_argument (Qlistp, tem); | |
1038 | |
1039 while (CONSP (tem)) | |
1040 { | |
1041 tail = tem; | |
1042 tem = Fcdr (tail); | |
1043 QUIT; | |
1044 } | |
1045 | |
1046 tem = args[argnum + 1]; | |
1047 Fsetcdr (tail, tem); | |
485 | 1048 if (NILP (tem)) |
211 | 1049 args[argnum + 1] = tail; |
1050 } | |
1051 | |
1052 return val; | |
1053 } | |
1054 | |
1055 /* This is the guts of all mapping functions. | |
1056 Apply fn to each element of seq, one by one, | |
1057 storing the results into elements of vals, a C vector of Lisp_Objects. | |
1058 leni is the length of vals, which should also be the length of seq. */ | |
1059 | |
1060 static void | |
1061 mapcar1 (leni, vals, fn, seq) | |
1062 int leni; | |
1063 Lisp_Object *vals; | |
1064 Lisp_Object fn, seq; | |
1065 { | |
1066 register Lisp_Object tail; | |
1067 Lisp_Object dummy; | |
1068 register int i; | |
1069 struct gcpro gcpro1, gcpro2, gcpro3; | |
1070 | |
1071 /* Don't let vals contain any garbage when GC happens. */ | |
1072 for (i = 0; i < leni; i++) | |
1073 vals[i] = Qnil; | |
1074 | |
1075 GCPRO3 (dummy, fn, seq); | |
1076 gcpro1.var = vals; | |
1077 gcpro1.nvars = leni; | |
1078 /* We need not explicitly protect `tail' because it is used only on lists, and | |
1079 1) lists are not relocated and 2) the list is marked via `seq' so will not be freed */ | |
1080 | |
9128
04a702d7f662
(Frandom, Flength, Fstring_equal, Fstring_lessp, Fcopy_sequence, concat, Felt,
Karl Heuer <kwzh@gnu.org>
parents:
8966
diff
changeset
|
1081 if (VECTORP (seq)) |
211 | 1082 { |
1083 for (i = 0; i < leni; i++) | |
1084 { | |
1085 dummy = XVECTOR (seq)->contents[i]; | |
1086 vals[i] = call1 (fn, dummy); | |
1087 } | |
1088 } | |
9128
04a702d7f662
(Frandom, Flength, Fstring_equal, Fstring_lessp, Fcopy_sequence, concat, Felt,
Karl Heuer <kwzh@gnu.org>
parents:
8966
diff
changeset
|
1089 else if (STRINGP (seq)) |
211 | 1090 { |
1091 for (i = 0; i < leni; i++) | |
1092 { | |
9308
2c594629baaa
(Flength, concat, mapcar1): Don't use XFASTINT as an lvalue.
Karl Heuer <kwzh@gnu.org>
parents:
9289
diff
changeset
|
1093 XSETFASTINT (dummy, XSTRING (seq)->data[i]); |
211 | 1094 vals[i] = call1 (fn, dummy); |
1095 } | |
1096 } | |
1097 else /* Must be a list, since Flength did not get an error */ | |
1098 { | |
1099 tail = seq; | |
1100 for (i = 0; i < leni; i++) | |
1101 { | |
1102 vals[i] = call1 (fn, Fcar (tail)); | |
1103 tail = Fcdr (tail); | |
1104 } | |
1105 } | |
1106 | |
1107 UNGCPRO; | |
1108 } | |
1109 | |
1110 DEFUN ("mapconcat", Fmapconcat, Smapconcat, 3, 3, 0, | |
1111 "Apply FN to each element of SEQ, and concat the results as strings.\n\ | |
1112 In between each pair of results, stick in SEP.\n\ | |
5437 | 1113 Thus, \" \" as SEP results in spaces between the values returned by FN.") |
211 | 1114 (fn, seq, sep) |
1115 Lisp_Object fn, seq, sep; | |
1116 { | |
1117 Lisp_Object len; | |
1118 register int leni; | |
1119 int nargs; | |
1120 register Lisp_Object *args; | |
1121 register int i; | |
1122 struct gcpro gcpro1; | |
1123 | |
1124 len = Flength (seq); | |
1125 leni = XINT (len); | |
1126 nargs = leni + leni - 1; | |
1127 if (nargs < 0) return build_string (""); | |
1128 | |
1129 args = (Lisp_Object *) alloca (nargs * sizeof (Lisp_Object)); | |
1130 | |
1131 GCPRO1 (sep); | |
1132 mapcar1 (leni, args, fn, seq); | |
1133 UNGCPRO; | |
1134 | |
1135 for (i = leni - 1; i >= 0; i--) | |
1136 args[i + i] = args[i]; | |
1137 | |
1138 for (i = 1; i < nargs; i += 2) | |
1139 args[i] = sep; | |
1140 | |
1141 return Fconcat (nargs, args); | |
1142 } | |
1143 | |
1144 DEFUN ("mapcar", Fmapcar, Smapcar, 2, 2, 0, | |
1145 "Apply FUNCTION to each element of SEQUENCE, and make a list of the results.\n\ | |
1146 The result is a list just as long as SEQUENCE.\n\ | |
1147 SEQUENCE may be a list, a vector or a string.") | |
1148 (fn, seq) | |
1149 Lisp_Object fn, seq; | |
1150 { | |
1151 register Lisp_Object len; | |
1152 register int leni; | |
1153 register Lisp_Object *args; | |
1154 | |
1155 len = Flength (seq); | |
1156 leni = XFASTINT (len); | |
1157 args = (Lisp_Object *) alloca (leni * sizeof (Lisp_Object)); | |
1158 | |
1159 mapcar1 (leni, args, fn, seq); | |
1160 | |
1161 return Flist (leni, args); | |
1162 } | |
1163 | |
1164 /* Anything that calls this function must protect from GC! */ | |
1165 | |
1166 DEFUN ("y-or-n-p", Fy_or_n_p, Sy_or_n_p, 1, 1, 0, | |
1167 "Ask user a \"y or n\" question. Return t if answer is \"y\".\n\ | |
759
58b7fc91b74a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
727
diff
changeset
|
1168 Takes one argument, which is the string to display to ask the question.\n\ |
58b7fc91b74a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
727
diff
changeset
|
1169 It should end in a space; `y-or-n-p' adds `(y or n) ' to it.\n\ |
211 | 1170 No confirmation of the answer is requested; a single character is enough.\n\ |
1171 Also accepts Space to mean yes, or Delete to mean no.") | |
1172 (prompt) | |
1173 Lisp_Object prompt; | |
1174 { | |
2091
eedbad26e34c
(Fy_or_n_p): Use query-replace-map.
Richard M. Stallman <rms@gnu.org>
parents:
1919
diff
changeset
|
1175 register Lisp_Object obj, key, def, answer_string, map; |
eedbad26e34c
(Fy_or_n_p): Use query-replace-map.
Richard M. Stallman <rms@gnu.org>
parents:
1919
diff
changeset
|
1176 register int answer; |
211 | 1177 Lisp_Object xprompt; |
1178 Lisp_Object args[2]; | |
1179 int ocech = cursor_in_echo_area; | |
1180 struct gcpro gcpro1, gcpro2; | |
1181 | |
2091
eedbad26e34c
(Fy_or_n_p): Use query-replace-map.
Richard M. Stallman <rms@gnu.org>
parents:
1919
diff
changeset
|
1182 map = Fsymbol_value (intern ("query-replace-map")); |
eedbad26e34c
(Fy_or_n_p): Use query-replace-map.
Richard M. Stallman <rms@gnu.org>
parents:
1919
diff
changeset
|
1183 |
211 | 1184 CHECK_STRING (prompt, 0); |
1185 xprompt = prompt; | |
1186 GCPRO2 (prompt, xprompt); | |
1187 | |
1188 while (1) | |
1189 { | |
6850
d2d8b40fb599
(Fy_or_n_p, Fyes_or_no_p): Test HAVE_X_MENU.
Karl Heuer <kwzh@gnu.org>
parents:
6478
diff
changeset
|
1190 #ifdef HAVE_X_MENU |
7790
75153e2d5d85
(Fy_or_n_p): Don't use dialog box if not an X frame.
Richard M. Stallman <rms@gnu.org>
parents:
7307
diff
changeset
|
1191 if ((NILP (last_nonmenu_event) || CONSP (last_nonmenu_event)) |
75153e2d5d85
(Fy_or_n_p): Don't use dialog box if not an X frame.
Richard M. Stallman <rms@gnu.org>
parents:
7307
diff
changeset
|
1192 && using_x_p ()) |
6057
b2cc63a56415
(Fy_or_n_p): Use a popup menu if reached via mouse command.
Richard M. Stallman <rms@gnu.org>
parents:
5664
diff
changeset
|
1193 { |
b2cc63a56415
(Fy_or_n_p): Use a popup menu if reached via mouse command.
Richard M. Stallman <rms@gnu.org>
parents:
5664
diff
changeset
|
1194 Lisp_Object pane, menu; |
7815
5d167db8ce8a
(Fy_or_n_p, Fyes_or_no_p) [HAVE_X_MENU]: Redisplay before popping up a menu.
Karl Heuer <kwzh@gnu.org>
parents:
7790
diff
changeset
|
1195 redisplay_preserve_echo_area (); |
6057
b2cc63a56415
(Fy_or_n_p): Use a popup menu if reached via mouse command.
Richard M. Stallman <rms@gnu.org>
parents:
5664
diff
changeset
|
1196 pane = Fcons (Fcons (build_string ("Yes"), Qt), |
b2cc63a56415
(Fy_or_n_p): Use a popup menu if reached via mouse command.
Richard M. Stallman <rms@gnu.org>
parents:
5664
diff
changeset
|
1197 Fcons (Fcons (build_string ("No"), Qnil), |
b2cc63a56415
(Fy_or_n_p): Use a popup menu if reached via mouse command.
Richard M. Stallman <rms@gnu.org>
parents:
5664
diff
changeset
|
1198 Qnil)); |
6478
65c2e184b5d9
(Fy_or_n_p, Fyes_or_no_p): Call Fx_popup_dialog the new way.
Richard M. Stallman <rms@gnu.org>
parents:
6427
diff
changeset
|
1199 menu = Fcons (prompt, pane); |
6303
1571be153f56
(Fyes_or_no_p): Call Fx_popup_dialog instead of Fx_popup_menu.
Fred Pierresteguy <F.Pierresteguy@frcl.bull.fr>
parents:
6057
diff
changeset
|
1200 obj = Fx_popup_dialog (Qt, menu); |
6057
b2cc63a56415
(Fy_or_n_p): Use a popup menu if reached via mouse command.
Richard M. Stallman <rms@gnu.org>
parents:
5664
diff
changeset
|
1201 answer = !NILP (obj); |
b2cc63a56415
(Fy_or_n_p): Use a popup menu if reached via mouse command.
Richard M. Stallman <rms@gnu.org>
parents:
5664
diff
changeset
|
1202 break; |
b2cc63a56415
(Fy_or_n_p): Use a popup menu if reached via mouse command.
Richard M. Stallman <rms@gnu.org>
parents:
5664
diff
changeset
|
1203 } |
6850
d2d8b40fb599
(Fy_or_n_p, Fyes_or_no_p): Test HAVE_X_MENU.
Karl Heuer <kwzh@gnu.org>
parents:
6478
diff
changeset
|
1204 #endif |
d2d8b40fb599
(Fy_or_n_p, Fyes_or_no_p): Test HAVE_X_MENU.
Karl Heuer <kwzh@gnu.org>
parents:
6478
diff
changeset
|
1205 cursor_in_echo_area = 1; |
d2d8b40fb599
(Fy_or_n_p, Fyes_or_no_p): Test HAVE_X_MENU.
Karl Heuer <kwzh@gnu.org>
parents:
6478
diff
changeset
|
1206 message ("%s(y or n) ", XSTRING (xprompt)->data); |
211 | 1207 |
6850
d2d8b40fb599
(Fy_or_n_p, Fyes_or_no_p): Test HAVE_X_MENU.
Karl Heuer <kwzh@gnu.org>
parents:
6478
diff
changeset
|
1208 obj = read_filtered_event (1, 0, 0); |
d2d8b40fb599
(Fy_or_n_p, Fyes_or_no_p): Test HAVE_X_MENU.
Karl Heuer <kwzh@gnu.org>
parents:
6478
diff
changeset
|
1209 cursor_in_echo_area = 0; |
d2d8b40fb599
(Fy_or_n_p, Fyes_or_no_p): Test HAVE_X_MENU.
Karl Heuer <kwzh@gnu.org>
parents:
6478
diff
changeset
|
1210 /* If we need to quit, quit with cursor_in_echo_area = 0. */ |
d2d8b40fb599
(Fy_or_n_p, Fyes_or_no_p): Test HAVE_X_MENU.
Karl Heuer <kwzh@gnu.org>
parents:
6478
diff
changeset
|
1211 QUIT; |
2369
8ce8541f393a
(Fy_or_n_p): Ensure cursor_in_echo_area = 0 when quit.
Richard M. Stallman <rms@gnu.org>
parents:
2311
diff
changeset
|
1212 |
2091
eedbad26e34c
(Fy_or_n_p): Use query-replace-map.
Richard M. Stallman <rms@gnu.org>
parents:
1919
diff
changeset
|
1213 key = Fmake_vector (make_number (1), obj); |
eedbad26e34c
(Fy_or_n_p): Use query-replace-map.
Richard M. Stallman <rms@gnu.org>
parents:
1919
diff
changeset
|
1214 def = Flookup_key (map, key); |
eedbad26e34c
(Fy_or_n_p): Use query-replace-map.
Richard M. Stallman <rms@gnu.org>
parents:
1919
diff
changeset
|
1215 answer_string = Fsingle_key_description (obj); |
211 | 1216 |
2091
eedbad26e34c
(Fy_or_n_p): Use query-replace-map.
Richard M. Stallman <rms@gnu.org>
parents:
1919
diff
changeset
|
1217 if (EQ (def, intern ("skip"))) |
eedbad26e34c
(Fy_or_n_p): Use query-replace-map.
Richard M. Stallman <rms@gnu.org>
parents:
1919
diff
changeset
|
1218 { |
eedbad26e34c
(Fy_or_n_p): Use query-replace-map.
Richard M. Stallman <rms@gnu.org>
parents:
1919
diff
changeset
|
1219 answer = 0; |
eedbad26e34c
(Fy_or_n_p): Use query-replace-map.
Richard M. Stallman <rms@gnu.org>
parents:
1919
diff
changeset
|
1220 break; |
eedbad26e34c
(Fy_or_n_p): Use query-replace-map.
Richard M. Stallman <rms@gnu.org>
parents:
1919
diff
changeset
|
1221 } |
eedbad26e34c
(Fy_or_n_p): Use query-replace-map.
Richard M. Stallman <rms@gnu.org>
parents:
1919
diff
changeset
|
1222 else if (EQ (def, intern ("act"))) |
eedbad26e34c
(Fy_or_n_p): Use query-replace-map.
Richard M. Stallman <rms@gnu.org>
parents:
1919
diff
changeset
|
1223 { |
eedbad26e34c
(Fy_or_n_p): Use query-replace-map.
Richard M. Stallman <rms@gnu.org>
parents:
1919
diff
changeset
|
1224 answer = 1; |
eedbad26e34c
(Fy_or_n_p): Use query-replace-map.
Richard M. Stallman <rms@gnu.org>
parents:
1919
diff
changeset
|
1225 break; |
eedbad26e34c
(Fy_or_n_p): Use query-replace-map.
Richard M. Stallman <rms@gnu.org>
parents:
1919
diff
changeset
|
1226 } |
2311
98b714786ad0
(Fy_or_n_p): Handle `recenter' response type.
Richard M. Stallman <rms@gnu.org>
parents:
2171
diff
changeset
|
1227 else if (EQ (def, intern ("recenter"))) |
98b714786ad0
(Fy_or_n_p): Handle `recenter' response type.
Richard M. Stallman <rms@gnu.org>
parents:
2171
diff
changeset
|
1228 { |
98b714786ad0
(Fy_or_n_p): Handle `recenter' response type.
Richard M. Stallman <rms@gnu.org>
parents:
2171
diff
changeset
|
1229 Frecenter (Qnil); |
98b714786ad0
(Fy_or_n_p): Handle `recenter' response type.
Richard M. Stallman <rms@gnu.org>
parents:
2171
diff
changeset
|
1230 xprompt = prompt; |
98b714786ad0
(Fy_or_n_p): Handle `recenter' response type.
Richard M. Stallman <rms@gnu.org>
parents:
2171
diff
changeset
|
1231 continue; |
98b714786ad0
(Fy_or_n_p): Handle `recenter' response type.
Richard M. Stallman <rms@gnu.org>
parents:
2171
diff
changeset
|
1232 } |
2091
eedbad26e34c
(Fy_or_n_p): Use query-replace-map.
Richard M. Stallman <rms@gnu.org>
parents:
1919
diff
changeset
|
1233 else if (EQ (def, intern ("quit"))) |
211 | 1234 Vquit_flag = Qt; |
10059
c1b138be512e
(Fy_or_n_p): Handle exit-prefix in query-replace-map.
Richard M. Stallman <rms@gnu.org>
parents:
10006
diff
changeset
|
1235 /* We want to exit this command for exit-prefix, |
c1b138be512e
(Fy_or_n_p): Handle exit-prefix in query-replace-map.
Richard M. Stallman <rms@gnu.org>
parents:
10006
diff
changeset
|
1236 and this is the only way to do it. */ |
c1b138be512e
(Fy_or_n_p): Handle exit-prefix in query-replace-map.
Richard M. Stallman <rms@gnu.org>
parents:
10006
diff
changeset
|
1237 else if (EQ (def, intern ("exit-prefix"))) |
c1b138be512e
(Fy_or_n_p): Handle exit-prefix in query-replace-map.
Richard M. Stallman <rms@gnu.org>
parents:
10006
diff
changeset
|
1238 Vquit_flag = Qt; |
2091
eedbad26e34c
(Fy_or_n_p): Use query-replace-map.
Richard M. Stallman <rms@gnu.org>
parents:
1919
diff
changeset
|
1239 |
211 | 1240 QUIT; |
1194 | 1241 |
1242 /* If we don't clear this, then the next call to read_char will | |
1243 return quit_char again, and we'll enter an infinite loop. */ | |
1193
e1329d41271d
* fns.c (Fy_or_n_p): After testing for a QUIT, clear Vquit_flag.
Jim Blandy <jimb@redhat.com>
parents:
1093
diff
changeset
|
1244 Vquit_flag = Qnil; |
211 | 1245 |
1246 Fding (Qnil); | |
1247 Fdiscard_input (); | |
1248 if (EQ (xprompt, prompt)) | |
1249 { | |
1250 args[0] = build_string ("Please answer y or n. "); | |
1251 args[1] = prompt; | |
1252 xprompt = Fconcat (2, args); | |
1253 } | |
1254 } | |
1255 UNGCPRO; | |
2171
4fbceca13b22
* fns.c (Fy_or_n_p): Display the answer.
Jim Blandy <jimb@redhat.com>
parents:
2091
diff
changeset
|
1256 |
2525
6cf2344e6e7e
(Fy_or_n_p): Echo the answer just once, at exit.
Richard M. Stallman <rms@gnu.org>
parents:
2429
diff
changeset
|
1257 if (! noninteractive) |
6cf2344e6e7e
(Fy_or_n_p): Echo the answer just once, at exit.
Richard M. Stallman <rms@gnu.org>
parents:
2429
diff
changeset
|
1258 { |
6cf2344e6e7e
(Fy_or_n_p): Echo the answer just once, at exit.
Richard M. Stallman <rms@gnu.org>
parents:
2429
diff
changeset
|
1259 cursor_in_echo_area = -1; |
6cf2344e6e7e
(Fy_or_n_p): Echo the answer just once, at exit.
Richard M. Stallman <rms@gnu.org>
parents:
2429
diff
changeset
|
1260 message ("%s(y or n) %c", XSTRING (xprompt)->data, answer ? 'y' : 'n'); |
6cf2344e6e7e
(Fy_or_n_p): Echo the answer just once, at exit.
Richard M. Stallman <rms@gnu.org>
parents:
2429
diff
changeset
|
1261 cursor_in_echo_area = ocech; |
6cf2344e6e7e
(Fy_or_n_p): Echo the answer just once, at exit.
Richard M. Stallman <rms@gnu.org>
parents:
2429
diff
changeset
|
1262 } |
2171
4fbceca13b22
* fns.c (Fy_or_n_p): Display the answer.
Jim Blandy <jimb@redhat.com>
parents:
2091
diff
changeset
|
1263 |
2091
eedbad26e34c
(Fy_or_n_p): Use query-replace-map.
Richard M. Stallman <rms@gnu.org>
parents:
1919
diff
changeset
|
1264 return answer ? Qt : Qnil; |
211 | 1265 } |
1266 | |
1267 /* This is how C code calls `yes-or-no-p' and allows the user | |
1268 to redefined it. | |
1269 | |
1270 Anything that calls this function must protect from GC! */ | |
1271 | |
1272 Lisp_Object | |
1273 do_yes_or_no_p (prompt) | |
1274 Lisp_Object prompt; | |
1275 { | |
1276 return call1 (intern ("yes-or-no-p"), prompt); | |
1277 } | |
1278 | |
1279 /* Anything that calls this function must protect from GC! */ | |
1280 | |
1281 DEFUN ("yes-or-no-p", Fyes_or_no_p, Syes_or_no_p, 1, 1, 0, | |
759
58b7fc91b74a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
727
diff
changeset
|
1282 "Ask user a yes-or-no question. Return t if answer is yes.\n\ |
58b7fc91b74a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
727
diff
changeset
|
1283 Takes one argument, which is the string to display to ask the question.\n\ |
58b7fc91b74a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
727
diff
changeset
|
1284 It should end in a space; `yes-or-no-p' adds `(yes or no) ' to it.\n\ |
58b7fc91b74a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
727
diff
changeset
|
1285 The user must confirm the answer with RET,\n\ |
58b7fc91b74a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
727
diff
changeset
|
1286 and can edit it until it as been confirmed.") |
211 | 1287 (prompt) |
1288 Lisp_Object prompt; | |
1289 { | |
1290 register Lisp_Object ans; | |
1291 Lisp_Object args[2]; | |
1292 struct gcpro gcpro1; | |
6057
b2cc63a56415
(Fy_or_n_p): Use a popup menu if reached via mouse command.
Richard M. Stallman <rms@gnu.org>
parents:
5664
diff
changeset
|
1293 Lisp_Object menu; |
211 | 1294 |
1295 CHECK_STRING (prompt, 0); | |
1296 | |
6850
d2d8b40fb599
(Fy_or_n_p, Fyes_or_no_p): Test HAVE_X_MENU.
Karl Heuer <kwzh@gnu.org>
parents:
6478
diff
changeset
|
1297 #ifdef HAVE_X_MENU |
7790
75153e2d5d85
(Fy_or_n_p): Don't use dialog box if not an X frame.
Richard M. Stallman <rms@gnu.org>
parents:
7307
diff
changeset
|
1298 if ((NILP (last_nonmenu_event) || CONSP (last_nonmenu_event)) |
75153e2d5d85
(Fy_or_n_p): Don't use dialog box if not an X frame.
Richard M. Stallman <rms@gnu.org>
parents:
7307
diff
changeset
|
1299 && using_x_p ()) |
6057
b2cc63a56415
(Fy_or_n_p): Use a popup menu if reached via mouse command.
Richard M. Stallman <rms@gnu.org>
parents:
5664
diff
changeset
|
1300 { |
b2cc63a56415
(Fy_or_n_p): Use a popup menu if reached via mouse command.
Richard M. Stallman <rms@gnu.org>
parents:
5664
diff
changeset
|
1301 Lisp_Object pane, menu, obj; |
7815
5d167db8ce8a
(Fy_or_n_p, Fyes_or_no_p) [HAVE_X_MENU]: Redisplay before popping up a menu.
Karl Heuer <kwzh@gnu.org>
parents:
7790
diff
changeset
|
1302 redisplay_preserve_echo_area (); |
6057
b2cc63a56415
(Fy_or_n_p): Use a popup menu if reached via mouse command.
Richard M. Stallman <rms@gnu.org>
parents:
5664
diff
changeset
|
1303 pane = Fcons (Fcons (build_string ("Yes"), Qt), |
b2cc63a56415
(Fy_or_n_p): Use a popup menu if reached via mouse command.
Richard M. Stallman <rms@gnu.org>
parents:
5664
diff
changeset
|
1304 Fcons (Fcons (build_string ("No"), Qnil), |
b2cc63a56415
(Fy_or_n_p): Use a popup menu if reached via mouse command.
Richard M. Stallman <rms@gnu.org>
parents:
5664
diff
changeset
|
1305 Qnil)); |
b2cc63a56415
(Fy_or_n_p): Use a popup menu if reached via mouse command.
Richard M. Stallman <rms@gnu.org>
parents:
5664
diff
changeset
|
1306 GCPRO1 (pane); |
6478
65c2e184b5d9
(Fy_or_n_p, Fyes_or_no_p): Call Fx_popup_dialog the new way.
Richard M. Stallman <rms@gnu.org>
parents:
6427
diff
changeset
|
1307 menu = Fcons (prompt, pane); |
6344 | 1308 obj = Fx_popup_dialog (Qt, menu); |
6057
b2cc63a56415
(Fy_or_n_p): Use a popup menu if reached via mouse command.
Richard M. Stallman <rms@gnu.org>
parents:
5664
diff
changeset
|
1309 UNGCPRO; |
b2cc63a56415
(Fy_or_n_p): Use a popup menu if reached via mouse command.
Richard M. Stallman <rms@gnu.org>
parents:
5664
diff
changeset
|
1310 return obj; |
b2cc63a56415
(Fy_or_n_p): Use a popup menu if reached via mouse command.
Richard M. Stallman <rms@gnu.org>
parents:
5664
diff
changeset
|
1311 } |
6850
d2d8b40fb599
(Fy_or_n_p, Fyes_or_no_p): Test HAVE_X_MENU.
Karl Heuer <kwzh@gnu.org>
parents:
6478
diff
changeset
|
1312 #endif |
6057
b2cc63a56415
(Fy_or_n_p): Use a popup menu if reached via mouse command.
Richard M. Stallman <rms@gnu.org>
parents:
5664
diff
changeset
|
1313 |
211 | 1314 args[0] = prompt; |
1315 args[1] = build_string ("(yes or no) "); | |
1316 prompt = Fconcat (2, args); | |
1317 | |
1318 GCPRO1 (prompt); | |
6057
b2cc63a56415
(Fy_or_n_p): Use a popup menu if reached via mouse command.
Richard M. Stallman <rms@gnu.org>
parents:
5664
diff
changeset
|
1319 |
211 | 1320 while (1) |
1321 { | |
4456
cbfcf187b5da
(Fyes_or_no_p): Use Qyes_or_no_p_history.
Richard M. Stallman <rms@gnu.org>
parents:
4004
diff
changeset
|
1322 ans = Fdowncase (Fread_from_minibuffer (prompt, Qnil, Qnil, Qnil, |
cbfcf187b5da
(Fyes_or_no_p): Use Qyes_or_no_p_history.
Richard M. Stallman <rms@gnu.org>
parents:
4004
diff
changeset
|
1323 Qyes_or_no_p_history)); |
211 | 1324 if (XSTRING (ans)->size == 3 && !strcmp (XSTRING (ans)->data, "yes")) |
1325 { | |
1326 UNGCPRO; | |
1327 return Qt; | |
1328 } | |
1329 if (XSTRING (ans)->size == 2 && !strcmp (XSTRING (ans)->data, "no")) | |
1330 { | |
1331 UNGCPRO; | |
1332 return Qnil; | |
1333 } | |
1334 | |
1335 Fding (Qnil); | |
1336 Fdiscard_input (); | |
1337 message ("Please answer yes or no."); | |
1045
2ac1c701fced
* fns.c (Fyes_or_no_p): Call Fsleep_for with the appropriate
Jim Blandy <jimb@redhat.com>
parents:
1037
diff
changeset
|
1338 Fsleep_for (make_number (2), Qnil); |
211 | 1339 } |
1340 } | |
1341 | |
1342 DEFUN ("load-average", Fload_average, Sload_average, 0, 0, 0, | |
1343 "Return list of 1 minute, 5 minute and 15 minute load averages.\n\ | |
1344 Each of the three load averages is multiplied by 100,\n\ | |
727 | 1345 then converted to integer.\n\ |
1346 If the 5-minute or 15-minute load averages are not available, return a\n\ | |
1347 shortened list, containing only those averages which are available.") | |
211 | 1348 () |
1349 { | |
727 | 1350 double load_ave[3]; |
1351 int loads = getloadavg (load_ave, 3); | |
1352 Lisp_Object ret; | |
211 | 1353 |
727 | 1354 if (loads < 0) |
1355 error ("load-average not implemented for this operating system"); | |
211 | 1356 |
727 | 1357 ret = Qnil; |
1358 while (loads > 0) | |
1359 ret = Fcons (make_number ((int) (load_ave[--loads] * 100.0)), ret); | |
211 | 1360 |
727 | 1361 return ret; |
211 | 1362 } |
1363 | |
1364 Lisp_Object Vfeatures; | |
1365 | |
1366 DEFUN ("featurep", Ffeaturep, Sfeaturep, 1, 1, 0, | |
1367 "Returns t if FEATURE is present in this Emacs.\n\ | |
1368 Use this to conditionalize execution of lisp code based on the presence or\n\ | |
1369 absence of emacs or environment extensions.\n\ | |
1370 Use `provide' to declare that a feature is available.\n\ | |
1371 This function looks at the value of the variable `features'.") | |
1372 (feature) | |
1373 Lisp_Object feature; | |
1374 { | |
1375 register Lisp_Object tem; | |
1376 CHECK_SYMBOL (feature, 0); | |
1377 tem = Fmemq (feature, Vfeatures); | |
485 | 1378 return (NILP (tem)) ? Qnil : Qt; |
211 | 1379 } |
1380 | |
1381 DEFUN ("provide", Fprovide, Sprovide, 1, 1, 0, | |
1382 "Announce that FEATURE is a feature of the current Emacs.") | |
1383 (feature) | |
1384 Lisp_Object feature; | |
1385 { | |
1386 register Lisp_Object tem; | |
1387 CHECK_SYMBOL (feature, 0); | |
485 | 1388 if (!NILP (Vautoload_queue)) |
211 | 1389 Vautoload_queue = Fcons (Fcons (Vfeatures, Qnil), Vautoload_queue); |
1390 tem = Fmemq (feature, Vfeatures); | |
485 | 1391 if (NILP (tem)) |
211 | 1392 Vfeatures = Fcons (feature, Vfeatures); |
2546
c8cd694d70eb
(provide, require): Put appropriately-marked
Richard M. Stallman <rms@gnu.org>
parents:
2525
diff
changeset
|
1393 LOADHIST_ATTACH (Fcons (Qprovide, feature)); |
211 | 1394 return feature; |
1395 } | |
1396 | |
1397 DEFUN ("require", Frequire, Srequire, 1, 2, 0, | |
1398 "If feature FEATURE is not loaded, load it from FILENAME.\n\ | |
1399 If FEATURE is not a member of the list `features', then the feature\n\ | |
1400 is not loaded; so load the file FILENAME.\n\ | |
1401 If FILENAME is omitted, the printname of FEATURE is used as the file name.") | |
1402 (feature, file_name) | |
1403 Lisp_Object feature, file_name; | |
1404 { | |
1405 register Lisp_Object tem; | |
1406 CHECK_SYMBOL (feature, 0); | |
1407 tem = Fmemq (feature, Vfeatures); | |
2546
c8cd694d70eb
(provide, require): Put appropriately-marked
Richard M. Stallman <rms@gnu.org>
parents:
2525
diff
changeset
|
1408 LOADHIST_ATTACH (Fcons (Qrequire, feature)); |
485 | 1409 if (NILP (tem)) |
211 | 1410 { |
1411 int count = specpdl_ptr - specpdl; | |
1412 | |
1413 /* Value saved here is to be restored into Vautoload_queue */ | |
1414 record_unwind_protect (un_autoload, Vautoload_queue); | |
1415 Vautoload_queue = Qt; | |
1416 | |
485 | 1417 Fload (NILP (file_name) ? Fsymbol_name (feature) : file_name, |
211 | 1418 Qnil, Qt, Qnil); |
1419 | |
1420 tem = Fmemq (feature, Vfeatures); | |
485 | 1421 if (NILP (tem)) |
211 | 1422 error ("Required feature %s was not provided", |
1423 XSYMBOL (feature)->name->data ); | |
1424 | |
1425 /* Once loading finishes, don't undo it. */ | |
1426 Vautoload_queue = Qt; | |
1427 feature = unbind_to (count, feature); | |
1428 } | |
1429 return feature; | |
1430 } | |
1431 | |
1432 syms_of_fns () | |
1433 { | |
1434 Qstring_lessp = intern ("string-lessp"); | |
1435 staticpro (&Qstring_lessp); | |
2546
c8cd694d70eb
(provide, require): Put appropriately-marked
Richard M. Stallman <rms@gnu.org>
parents:
2525
diff
changeset
|
1436 Qprovide = intern ("provide"); |
c8cd694d70eb
(provide, require): Put appropriately-marked
Richard M. Stallman <rms@gnu.org>
parents:
2525
diff
changeset
|
1437 staticpro (&Qprovide); |
c8cd694d70eb
(provide, require): Put appropriately-marked
Richard M. Stallman <rms@gnu.org>
parents:
2525
diff
changeset
|
1438 Qrequire = intern ("require"); |
c8cd694d70eb
(provide, require): Put appropriately-marked
Richard M. Stallman <rms@gnu.org>
parents:
2525
diff
changeset
|
1439 staticpro (&Qrequire); |
4456
cbfcf187b5da
(Fyes_or_no_p): Use Qyes_or_no_p_history.
Richard M. Stallman <rms@gnu.org>
parents:
4004
diff
changeset
|
1440 Qyes_or_no_p_history = intern ("yes-or-no-p-history"); |
cbfcf187b5da
(Fyes_or_no_p): Use Qyes_or_no_p_history.
Richard M. Stallman <rms@gnu.org>
parents:
4004
diff
changeset
|
1441 staticpro (&Qyes_or_no_p_history); |
211 | 1442 |
1443 DEFVAR_LISP ("features", &Vfeatures, | |
1444 "A list of symbols which are the features of the executing emacs.\n\ | |
1445 Used by `featurep' and `require', and altered by `provide'."); | |
1446 Vfeatures = Qnil; | |
1447 | |
1448 defsubr (&Sidentity); | |
1449 defsubr (&Srandom); | |
1450 defsubr (&Slength); | |
1451 defsubr (&Sstring_equal); | |
1452 defsubr (&Sstring_lessp); | |
1453 defsubr (&Sappend); | |
1454 defsubr (&Sconcat); | |
1455 defsubr (&Svconcat); | |
1456 defsubr (&Scopy_sequence); | |
1457 defsubr (&Scopy_alist); | |
1458 defsubr (&Ssubstring); | |
1459 defsubr (&Snthcdr); | |
1460 defsubr (&Snth); | |
1461 defsubr (&Selt); | |
1462 defsubr (&Smember); | |
1463 defsubr (&Smemq); | |
1464 defsubr (&Sassq); | |
1465 defsubr (&Sassoc); | |
1466 defsubr (&Srassq); | |
1467 defsubr (&Sdelq); | |
414 | 1468 defsubr (&Sdelete); |
211 | 1469 defsubr (&Snreverse); |
1470 defsubr (&Sreverse); | |
1471 defsubr (&Ssort); | |
1472 defsubr (&Sget); | |
1473 defsubr (&Sput); | |
1474 defsubr (&Sequal); | |
1475 defsubr (&Sfillarray); | |
1476 defsubr (&Snconc); | |
1477 defsubr (&Smapcar); | |
1478 defsubr (&Smapconcat); | |
1479 defsubr (&Sy_or_n_p); | |
1480 defsubr (&Syes_or_no_p); | |
1481 defsubr (&Sload_average); | |
1482 defsubr (&Sfeaturep); | |
1483 defsubr (&Srequire); | |
1484 defsubr (&Sprovide); | |
1485 } |