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