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