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