Commit | Line | Data |
---|---|---|
7921925c | 1 | /* Primitive operations on Lisp data types for GNU Emacs Lisp interpreter. |
0b5538bd | 2 | Copyright (C) 1985, 1986, 1988, 1993, 1994, 1995, 1997, 1998, 1999, 2000, |
aaef169d | 3 | 2001, 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc. |
7921925c JB |
4 | |
5 | This file is part of GNU Emacs. | |
6 | ||
7 | GNU Emacs is free software; you can redistribute it and/or modify | |
8 | it under the terms of the GNU General Public License as published by | |
7c938215 | 9 | the Free Software Foundation; either version 2, or (at your option) |
7921925c JB |
10 | any later version. |
11 | ||
12 | GNU Emacs is distributed in the hope that it will be useful, | |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
18 | along with GNU Emacs; see the file COPYING. If not, write to | |
4fc5845f LK |
19 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
20 | Boston, MA 02110-1301, USA. */ | |
7921925c JB |
21 | |
22 | ||
18160b98 | 23 | #include <config.h> |
68c45bf0 | 24 | #include <signal.h> |
dd8daec5 | 25 | #include <stdio.h> |
7921925c | 26 | #include "lisp.h" |
29eab336 | 27 | #include "puresize.h" |
8313c4e7 | 28 | #include "charset.h" |
7921925c | 29 | #include "buffer.h" |
077d751f | 30 | #include "keyboard.h" |
b0c2d1c6 | 31 | #include "frame.h" |
a44804c2 | 32 | #include "syssignal.h" |
fb8e9847 | 33 | |
93b91208 | 34 | #ifdef STDC_HEADERS |
2f261542 | 35 | #include <float.h> |
93b91208 | 36 | #endif |
defa77b5 | 37 | |
ad8d56b9 PE |
38 | /* If IEEE_FLOATING_POINT isn't defined, default it from FLT_*. */ |
39 | #ifndef IEEE_FLOATING_POINT | |
40 | #if (FLT_RADIX == 2 && FLT_MANT_DIG == 24 \ | |
41 | && FLT_MIN_EXP == -125 && FLT_MAX_EXP == 128) | |
42 | #define IEEE_FLOATING_POINT 1 | |
43 | #else | |
44 | #define IEEE_FLOATING_POINT 0 | |
45 | #endif | |
46 | #endif | |
47 | ||
defa77b5 RS |
48 | /* Work around a problem that happens because math.h on hpux 7 |
49 | defines two static variables--which, in Emacs, are not really static, | |
50 | because `static' is defined as nothing. The problem is that they are | |
51 | here, in floatfns.c, and in lread.c. | |
52 | These macros prevent the name conflict. */ | |
53 | #if defined (HPUX) && !defined (HPUX8) | |
54 | #define _MAXLDBL data_c_maxldbl | |
55 | #define _NMAXLDBL data_c_nmaxldbl | |
56 | #endif | |
57 | ||
7921925c | 58 | #include <math.h> |
7921925c | 59 | |
024ec58f BF |
60 | #if !defined (atof) |
61 | extern double atof (); | |
62 | #endif /* !atof */ | |
63 | ||
7921925c JB |
64 | Lisp_Object Qnil, Qt, Qquote, Qlambda, Qsubr, Qunbound; |
65 | Lisp_Object Qerror_conditions, Qerror_message, Qtop_level; | |
66 | Lisp_Object Qerror, Qquit, Qwrong_type_argument, Qargs_out_of_range; | |
ffd56f97 | 67 | Lisp_Object Qvoid_variable, Qvoid_function, Qcyclic_function_indirection; |
13d95cc0 | 68 | Lisp_Object Qcyclic_variable_indirection, Qcircular_list; |
7921925c JB |
69 | Lisp_Object Qsetting_constant, Qinvalid_read_syntax; |
70 | Lisp_Object Qinvalid_function, Qwrong_number_of_arguments, Qno_catch; | |
3b8819d6 | 71 | Lisp_Object Qend_of_file, Qarith_error, Qmark_inactive; |
7921925c | 72 | Lisp_Object Qbeginning_of_buffer, Qend_of_buffer, Qbuffer_read_only; |
8f9f49d7 | 73 | Lisp_Object Qtext_read_only; |
aae13d36 | 74 | |
8e86942b | 75 | Lisp_Object Qintegerp, Qnatnump, Qwholenump, Qsymbolp, Qlistp, Qconsp; |
7921925c JB |
76 | Lisp_Object Qstringp, Qarrayp, Qsequencep, Qbufferp; |
77 | Lisp_Object Qchar_or_string_p, Qmarkerp, Qinteger_or_marker_p, Qvectorp; | |
cda9b832 | 78 | Lisp_Object Qbuffer_or_string_p, Qkeywordp; |
7921925c | 79 | Lisp_Object Qboundp, Qfboundp; |
7f0edce7 | 80 | Lisp_Object Qchar_table_p, Qvector_or_char_table_p; |
39bcc759 | 81 | |
7921925c | 82 | Lisp_Object Qcdr; |
c1307a23 | 83 | Lisp_Object Qad_advice_info, Qad_activate_internal; |
7921925c | 84 | |
6315e761 RS |
85 | Lisp_Object Qrange_error, Qdomain_error, Qsingularity_error; |
86 | Lisp_Object Qoverflow_error, Qunderflow_error; | |
87 | ||
464f8898 | 88 | Lisp_Object Qfloatp; |
7921925c | 89 | Lisp_Object Qnumberp, Qnumber_or_marker_p; |
7921925c | 90 | |
aae13d36 LH |
91 | Lisp_Object Qinteger; |
92 | static Lisp_Object Qsymbol, Qstring, Qcons, Qmarker, Qoverlay; | |
8313c4e7 KH |
93 | static Lisp_Object Qfloat, Qwindow_configuration, Qwindow; |
94 | Lisp_Object Qprocess; | |
39bcc759 | 95 | static Lisp_Object Qcompiled_function, Qbuffer, Qframe, Qvector; |
81dc5de5 | 96 | static Lisp_Object Qchar_table, Qbool_vector, Qhash_table; |
6f0e897f | 97 | static Lisp_Object Qsubrp, Qmany, Qunevalled; |
39bcc759 | 98 | |
7a283f36 | 99 | static Lisp_Object swap_in_symval_forwarding P_ ((Lisp_Object, Lisp_Object)); |
d02eeab3 | 100 | |
9d113d9d | 101 | Lisp_Object Vmost_positive_fixnum, Vmost_negative_fixnum; |
e6190b11 | 102 | |
13d95cc0 GM |
103 | |
104 | void | |
105 | circular_list_error (list) | |
106 | Lisp_Object list; | |
107 | { | |
108 | Fsignal (Qcircular_list, list); | |
109 | } | |
110 | ||
111 | ||
7921925c JB |
112 | Lisp_Object |
113 | wrong_type_argument (predicate, value) | |
114 | register Lisp_Object predicate, value; | |
115 | { | |
116 | register Lisp_Object tem; | |
117 | do | |
118 | { | |
e1351ff7 RS |
119 | /* If VALUE is not even a valid Lisp object, abort here |
120 | where we can get a backtrace showing where it came from. */ | |
04be3993 | 121 | if ((unsigned int) XGCTYPE (value) >= Lisp_Type_Limit) |
e1351ff7 RS |
122 | abort (); |
123 | ||
7921925c JB |
124 | value = Fsignal (Qwrong_type_argument, Fcons (predicate, Fcons (value, Qnil))); |
125 | tem = call1 (predicate, value); | |
126 | } | |
a33ef3ab | 127 | while (NILP (tem)); |
db926d80 DN |
128 | /* This function is marked as NO_RETURN, gcc would warn if it has a |
129 | return statement or if falls off the function. Other compilers | |
130 | warn if no return statement is present. */ | |
131 | #ifndef __GNUC__ | |
7921925c | 132 | return value; |
db926d80 DN |
133 | #else |
134 | abort (); | |
135 | #endif | |
7921925c JB |
136 | } |
137 | ||
dfcf069d | 138 | void |
7921925c JB |
139 | pure_write_error () |
140 | { | |
141 | error ("Attempt to modify read-only object"); | |
142 | } | |
143 | ||
144 | void | |
145 | args_out_of_range (a1, a2) | |
146 | Lisp_Object a1, a2; | |
147 | { | |
148 | while (1) | |
149 | Fsignal (Qargs_out_of_range, Fcons (a1, Fcons (a2, Qnil))); | |
150 | } | |
151 | ||
152 | void | |
153 | args_out_of_range_3 (a1, a2, a3) | |
154 | Lisp_Object a1, a2, a3; | |
155 | { | |
156 | while (1) | |
157 | Fsignal (Qargs_out_of_range, Fcons (a1, Fcons (a2, Fcons (a3, Qnil)))); | |
158 | } | |
159 | ||
7921925c JB |
160 | /* On some machines, XINT needs a temporary location. |
161 | Here it is, in case it is needed. */ | |
162 | ||
163 | int sign_extend_temp; | |
164 | ||
165 | /* On a few machines, XINT can only be done by calling this. */ | |
166 | ||
167 | int | |
168 | sign_extend_lisp_int (num) | |
a0ed95ea | 169 | EMACS_INT num; |
7921925c | 170 | { |
a0ed95ea RS |
171 | if (num & (((EMACS_INT) 1) << (VALBITS - 1))) |
172 | return num | (((EMACS_INT) (-1)) << VALBITS); | |
7921925c | 173 | else |
a0ed95ea | 174 | return num & ((((EMACS_INT) 1) << VALBITS) - 1); |
7921925c JB |
175 | } |
176 | \f | |
177 | /* Data type predicates */ | |
178 | ||
179 | DEFUN ("eq", Feq, Seq, 2, 2, 0, | |
8c1a1077 PJ |
180 | doc: /* Return t if the two args are the same Lisp object. */) |
181 | (obj1, obj2) | |
7921925c JB |
182 | Lisp_Object obj1, obj2; |
183 | { | |
184 | if (EQ (obj1, obj2)) | |
185 | return Qt; | |
186 | return Qnil; | |
187 | } | |
188 | ||
8c1a1077 PJ |
189 | DEFUN ("null", Fnull, Snull, 1, 1, 0, |
190 | doc: /* Return t if OBJECT is nil. */) | |
191 | (object) | |
39bcc759 | 192 | Lisp_Object object; |
7921925c | 193 | { |
39bcc759 | 194 | if (NILP (object)) |
7921925c JB |
195 | return Qt; |
196 | return Qnil; | |
197 | } | |
198 | ||
39bcc759 | 199 | DEFUN ("type-of", Ftype_of, Stype_of, 1, 1, 0, |
8c1a1077 PJ |
200 | doc: /* Return a symbol representing the type of OBJECT. |
201 | The symbol returned names the object's basic type; | |
202 | for example, (type-of 1) returns `integer'. */) | |
203 | (object) | |
39bcc759 RS |
204 | Lisp_Object object; |
205 | { | |
206 | switch (XGCTYPE (object)) | |
207 | { | |
208 | case Lisp_Int: | |
209 | return Qinteger; | |
210 | ||
211 | case Lisp_Symbol: | |
212 | return Qsymbol; | |
213 | ||
214 | case Lisp_String: | |
215 | return Qstring; | |
216 | ||
217 | case Lisp_Cons: | |
218 | return Qcons; | |
219 | ||
220 | case Lisp_Misc: | |
324a6eef | 221 | switch (XMISCTYPE (object)) |
39bcc759 RS |
222 | { |
223 | case Lisp_Misc_Marker: | |
224 | return Qmarker; | |
225 | case Lisp_Misc_Overlay: | |
226 | return Qoverlay; | |
227 | case Lisp_Misc_Float: | |
228 | return Qfloat; | |
229 | } | |
230 | abort (); | |
231 | ||
232 | case Lisp_Vectorlike: | |
233 | if (GC_WINDOW_CONFIGURATIONP (object)) | |
234 | return Qwindow_configuration; | |
235 | if (GC_PROCESSP (object)) | |
236 | return Qprocess; | |
237 | if (GC_WINDOWP (object)) | |
238 | return Qwindow; | |
239 | if (GC_SUBRP (object)) | |
240 | return Qsubr; | |
241 | if (GC_COMPILEDP (object)) | |
242 | return Qcompiled_function; | |
243 | if (GC_BUFFERP (object)) | |
244 | return Qbuffer; | |
fc67d5be KH |
245 | if (GC_CHAR_TABLE_P (object)) |
246 | return Qchar_table; | |
247 | if (GC_BOOL_VECTOR_P (object)) | |
248 | return Qbool_vector; | |
39bcc759 RS |
249 | if (GC_FRAMEP (object)) |
250 | return Qframe; | |
81dc5de5 GM |
251 | if (GC_HASH_TABLE_P (object)) |
252 | return Qhash_table; | |
39bcc759 RS |
253 | return Qvector; |
254 | ||
39bcc759 RS |
255 | case Lisp_Float: |
256 | return Qfloat; | |
39bcc759 RS |
257 | |
258 | default: | |
259 | abort (); | |
260 | } | |
261 | } | |
262 | ||
8c1a1077 PJ |
263 | DEFUN ("consp", Fconsp, Sconsp, 1, 1, 0, |
264 | doc: /* Return t if OBJECT is a cons cell. */) | |
265 | (object) | |
39bcc759 | 266 | Lisp_Object object; |
7921925c | 267 | { |
39bcc759 | 268 | if (CONSP (object)) |
7921925c JB |
269 | return Qt; |
270 | return Qnil; | |
271 | } | |
272 | ||
25638b07 | 273 | DEFUN ("atom", Fatom, Satom, 1, 1, 0, |
8c1a1077 PJ |
274 | doc: /* Return t if OBJECT is not a cons cell. This includes nil. */) |
275 | (object) | |
39bcc759 | 276 | Lisp_Object object; |
7921925c | 277 | { |
39bcc759 | 278 | if (CONSP (object)) |
7921925c JB |
279 | return Qnil; |
280 | return Qt; | |
281 | } | |
282 | ||
25638b07 | 283 | DEFUN ("listp", Flistp, Slistp, 1, 1, 0, |
4cdcdcc9 LT |
284 | doc: /* Return t if OBJECT is a list, that is, a cons cell or nil. |
285 | Otherwise, return nil. */) | |
8c1a1077 | 286 | (object) |
39bcc759 | 287 | Lisp_Object object; |
7921925c | 288 | { |
39bcc759 | 289 | if (CONSP (object) || NILP (object)) |
7921925c JB |
290 | return Qt; |
291 | return Qnil; | |
292 | } | |
293 | ||
25638b07 | 294 | DEFUN ("nlistp", Fnlistp, Snlistp, 1, 1, 0, |
8c1a1077 PJ |
295 | doc: /* Return t if OBJECT is not a list. Lists include nil. */) |
296 | (object) | |
39bcc759 | 297 | Lisp_Object object; |
7921925c | 298 | { |
39bcc759 | 299 | if (CONSP (object) || NILP (object)) |
7921925c JB |
300 | return Qnil; |
301 | return Qt; | |
302 | } | |
303 | \f | |
25638b07 | 304 | DEFUN ("symbolp", Fsymbolp, Ssymbolp, 1, 1, 0, |
8c1a1077 PJ |
305 | doc: /* Return t if OBJECT is a symbol. */) |
306 | (object) | |
39bcc759 | 307 | Lisp_Object object; |
7921925c | 308 | { |
39bcc759 | 309 | if (SYMBOLP (object)) |
7921925c JB |
310 | return Qt; |
311 | return Qnil; | |
312 | } | |
313 | ||
cda9b832 DL |
314 | /* Define this in C to avoid unnecessarily consing up the symbol |
315 | name. */ | |
316 | DEFUN ("keywordp", Fkeywordp, Skeywordp, 1, 1, 0, | |
8c1a1077 PJ |
317 | doc: /* Return t if OBJECT is a keyword. |
318 | This means that it is a symbol with a print name beginning with `:' | |
319 | interned in the initial obarray. */) | |
320 | (object) | |
cda9b832 DL |
321 | Lisp_Object object; |
322 | { | |
323 | if (SYMBOLP (object) | |
d5db4077 | 324 | && SREF (SYMBOL_NAME (object), 0) == ':' |
f35d5bad | 325 | && SYMBOL_INTERNED_IN_INITIAL_OBARRAY_P (object)) |
cda9b832 DL |
326 | return Qt; |
327 | return Qnil; | |
328 | } | |
329 | ||
25638b07 | 330 | DEFUN ("vectorp", Fvectorp, Svectorp, 1, 1, 0, |
8c1a1077 PJ |
331 | doc: /* Return t if OBJECT is a vector. */) |
332 | (object) | |
39bcc759 | 333 | Lisp_Object object; |
7921925c | 334 | { |
39bcc759 | 335 | if (VECTORP (object)) |
7921925c JB |
336 | return Qt; |
337 | return Qnil; | |
338 | } | |
339 | ||
25638b07 | 340 | DEFUN ("stringp", Fstringp, Sstringp, 1, 1, 0, |
8c1a1077 PJ |
341 | doc: /* Return t if OBJECT is a string. */) |
342 | (object) | |
39bcc759 | 343 | Lisp_Object object; |
7921925c | 344 | { |
39bcc759 | 345 | if (STRINGP (object)) |
7921925c JB |
346 | return Qt; |
347 | return Qnil; | |
348 | } | |
349 | ||
25638b07 | 350 | DEFUN ("multibyte-string-p", Fmultibyte_string_p, Smultibyte_string_p, |
8c1a1077 PJ |
351 | 1, 1, 0, |
352 | doc: /* Return t if OBJECT is a multibyte string. */) | |
353 | (object) | |
25638b07 RS |
354 | Lisp_Object object; |
355 | { | |
356 | if (STRINGP (object) && STRING_MULTIBYTE (object)) | |
357 | return Qt; | |
358 | return Qnil; | |
359 | } | |
360 | ||
361 | DEFUN ("char-table-p", Fchar_table_p, Schar_table_p, 1, 1, 0, | |
8c1a1077 PJ |
362 | doc: /* Return t if OBJECT is a char-table. */) |
363 | (object) | |
4d276982 RS |
364 | Lisp_Object object; |
365 | { | |
366 | if (CHAR_TABLE_P (object)) | |
367 | return Qt; | |
368 | return Qnil; | |
369 | } | |
370 | ||
7f0edce7 RS |
371 | DEFUN ("vector-or-char-table-p", Fvector_or_char_table_p, |
372 | Svector_or_char_table_p, 1, 1, 0, | |
8c1a1077 PJ |
373 | doc: /* Return t if OBJECT is a char-table or vector. */) |
374 | (object) | |
7f0edce7 RS |
375 | Lisp_Object object; |
376 | { | |
377 | if (VECTORP (object) || CHAR_TABLE_P (object)) | |
378 | return Qt; | |
379 | return Qnil; | |
380 | } | |
381 | ||
8c1a1077 PJ |
382 | DEFUN ("bool-vector-p", Fbool_vector_p, Sbool_vector_p, 1, 1, 0, |
383 | doc: /* Return t if OBJECT is a bool-vector. */) | |
384 | (object) | |
4d276982 RS |
385 | Lisp_Object object; |
386 | { | |
387 | if (BOOL_VECTOR_P (object)) | |
388 | return Qt; | |
389 | return Qnil; | |
390 | } | |
391 | ||
8c1a1077 PJ |
392 | DEFUN ("arrayp", Farrayp, Sarrayp, 1, 1, 0, |
393 | doc: /* Return t if OBJECT is an array (string or vector). */) | |
394 | (object) | |
39bcc759 | 395 | Lisp_Object object; |
7921925c | 396 | { |
a9729926 RS |
397 | if (VECTORP (object) || STRINGP (object) |
398 | || CHAR_TABLE_P (object) || BOOL_VECTOR_P (object)) | |
7921925c JB |
399 | return Qt; |
400 | return Qnil; | |
401 | } | |
402 | ||
403 | DEFUN ("sequencep", Fsequencep, Ssequencep, 1, 1, 0, | |
8c1a1077 PJ |
404 | doc: /* Return t if OBJECT is a sequence (list or array). */) |
405 | (object) | |
39bcc759 | 406 | register Lisp_Object object; |
7921925c | 407 | { |
4d276982 RS |
408 | if (CONSP (object) || NILP (object) || VECTORP (object) || STRINGP (object) |
409 | || CHAR_TABLE_P (object) || BOOL_VECTOR_P (object)) | |
7921925c JB |
410 | return Qt; |
411 | return Qnil; | |
412 | } | |
413 | ||
8c1a1077 PJ |
414 | DEFUN ("bufferp", Fbufferp, Sbufferp, 1, 1, 0, |
415 | doc: /* Return t if OBJECT is an editor buffer. */) | |
416 | (object) | |
39bcc759 | 417 | Lisp_Object object; |
7921925c | 418 | { |
39bcc759 | 419 | if (BUFFERP (object)) |
7921925c JB |
420 | return Qt; |
421 | return Qnil; | |
422 | } | |
423 | ||
8c1a1077 PJ |
424 | DEFUN ("markerp", Fmarkerp, Smarkerp, 1, 1, 0, |
425 | doc: /* Return t if OBJECT is a marker (editor pointer). */) | |
426 | (object) | |
39bcc759 | 427 | Lisp_Object object; |
7921925c | 428 | { |
39bcc759 | 429 | if (MARKERP (object)) |
7921925c JB |
430 | return Qt; |
431 | return Qnil; | |
432 | } | |
433 | ||
8c1a1077 PJ |
434 | DEFUN ("subrp", Fsubrp, Ssubrp, 1, 1, 0, |
435 | doc: /* Return t if OBJECT is a built-in function. */) | |
436 | (object) | |
39bcc759 | 437 | Lisp_Object object; |
7921925c | 438 | { |
39bcc759 | 439 | if (SUBRP (object)) |
7921925c JB |
440 | return Qt; |
441 | return Qnil; | |
442 | } | |
443 | ||
dbc4e1c1 | 444 | DEFUN ("byte-code-function-p", Fbyte_code_function_p, Sbyte_code_function_p, |
8c1a1077 PJ |
445 | 1, 1, 0, |
446 | doc: /* Return t if OBJECT is a byte-compiled function object. */) | |
447 | (object) | |
39bcc759 | 448 | Lisp_Object object; |
7921925c | 449 | { |
39bcc759 | 450 | if (COMPILEDP (object)) |
7921925c JB |
451 | return Qt; |
452 | return Qnil; | |
453 | } | |
454 | ||
0321d75c | 455 | DEFUN ("char-or-string-p", Fchar_or_string_p, Schar_or_string_p, 1, 1, 0, |
8c1a1077 PJ |
456 | doc: /* Return t if OBJECT is a character (an integer) or a string. */) |
457 | (object) | |
39bcc759 | 458 | register Lisp_Object object; |
7921925c | 459 | { |
39bcc759 | 460 | if (INTEGERP (object) || STRINGP (object)) |
7921925c JB |
461 | return Qt; |
462 | return Qnil; | |
463 | } | |
464 | \f | |
8c1a1077 PJ |
465 | DEFUN ("integerp", Fintegerp, Sintegerp, 1, 1, 0, |
466 | doc: /* Return t if OBJECT is an integer. */) | |
467 | (object) | |
39bcc759 | 468 | Lisp_Object object; |
7921925c | 469 | { |
39bcc759 | 470 | if (INTEGERP (object)) |
7921925c JB |
471 | return Qt; |
472 | return Qnil; | |
473 | } | |
474 | ||
464f8898 | 475 | DEFUN ("integer-or-marker-p", Finteger_or_marker_p, Sinteger_or_marker_p, 1, 1, 0, |
8c1a1077 PJ |
476 | doc: /* Return t if OBJECT is an integer or a marker (editor pointer). */) |
477 | (object) | |
39bcc759 | 478 | register Lisp_Object object; |
7921925c | 479 | { |
39bcc759 | 480 | if (MARKERP (object) || INTEGERP (object)) |
7921925c JB |
481 | return Qt; |
482 | return Qnil; | |
483 | } | |
484 | ||
0321d75c | 485 | DEFUN ("natnump", Fnatnump, Snatnump, 1, 1, 0, |
8c1a1077 PJ |
486 | doc: /* Return t if OBJECT is a nonnegative integer. */) |
487 | (object) | |
39bcc759 | 488 | Lisp_Object object; |
7921925c | 489 | { |
39bcc759 | 490 | if (NATNUMP (object)) |
7921925c JB |
491 | return Qt; |
492 | return Qnil; | |
493 | } | |
494 | ||
495 | DEFUN ("numberp", Fnumberp, Snumberp, 1, 1, 0, | |
8c1a1077 PJ |
496 | doc: /* Return t if OBJECT is a number (floating point or integer). */) |
497 | (object) | |
39bcc759 | 498 | Lisp_Object object; |
7921925c | 499 | { |
39bcc759 | 500 | if (NUMBERP (object)) |
7921925c | 501 | return Qt; |
dbc4e1c1 JB |
502 | else |
503 | return Qnil; | |
7921925c JB |
504 | } |
505 | ||
506 | DEFUN ("number-or-marker-p", Fnumber_or_marker_p, | |
507 | Snumber_or_marker_p, 1, 1, 0, | |
8c1a1077 PJ |
508 | doc: /* Return t if OBJECT is a number or a marker. */) |
509 | (object) | |
39bcc759 | 510 | Lisp_Object object; |
7921925c | 511 | { |
39bcc759 | 512 | if (NUMBERP (object) || MARKERP (object)) |
7921925c JB |
513 | return Qt; |
514 | return Qnil; | |
515 | } | |
464f8898 | 516 | |
464f8898 | 517 | DEFUN ("floatp", Ffloatp, Sfloatp, 1, 1, 0, |
8c1a1077 PJ |
518 | doc: /* Return t if OBJECT is a floating point number. */) |
519 | (object) | |
39bcc759 | 520 | Lisp_Object object; |
464f8898 | 521 | { |
39bcc759 | 522 | if (FLOATP (object)) |
464f8898 RS |
523 | return Qt; |
524 | return Qnil; | |
525 | } | |
cc94f3b2 | 526 | |
7921925c JB |
527 | \f |
528 | /* Extract and set components of lists */ | |
529 | ||
530 | DEFUN ("car", Fcar, Scar, 1, 1, 0, | |
8c1a1077 | 531 | doc: /* Return the car of LIST. If arg is nil, return nil. |
9701c742 LT |
532 | Error if arg is not nil and not a cons cell. See also `car-safe'. |
533 | ||
da46c5be LT |
534 | See Info node `(elisp)Cons Cells' for a discussion of related basic |
535 | Lisp concepts such as car, cdr, cons cell and list. */) | |
8c1a1077 | 536 | (list) |
7921925c JB |
537 | register Lisp_Object list; |
538 | { | |
539 | while (1) | |
540 | { | |
e9ebc175 | 541 | if (CONSP (list)) |
7539e11f | 542 | return XCAR (list); |
7921925c JB |
543 | else if (EQ (list, Qnil)) |
544 | return Qnil; | |
545 | else | |
546 | list = wrong_type_argument (Qlistp, list); | |
547 | } | |
548 | } | |
549 | ||
550 | DEFUN ("car-safe", Fcar_safe, Scar_safe, 1, 1, 0, | |
8c1a1077 PJ |
551 | doc: /* Return the car of OBJECT if it is a cons cell, or else nil. */) |
552 | (object) | |
7921925c JB |
553 | Lisp_Object object; |
554 | { | |
e9ebc175 | 555 | if (CONSP (object)) |
7539e11f | 556 | return XCAR (object); |
7921925c JB |
557 | else |
558 | return Qnil; | |
559 | } | |
560 | ||
561 | DEFUN ("cdr", Fcdr, Scdr, 1, 1, 0, | |
8c1a1077 | 562 | doc: /* Return the cdr of LIST. If arg is nil, return nil. |
9701c742 LT |
563 | Error if arg is not nil and not a cons cell. See also `cdr-safe'. |
564 | ||
da46c5be LT |
565 | See Info node `(elisp)Cons Cells' for a discussion of related basic |
566 | Lisp concepts such as cdr, car, cons cell and list. */) | |
8c1a1077 | 567 | (list) |
7921925c JB |
568 | register Lisp_Object list; |
569 | { | |
570 | while (1) | |
571 | { | |
e9ebc175 | 572 | if (CONSP (list)) |
7539e11f | 573 | return XCDR (list); |
7921925c JB |
574 | else if (EQ (list, Qnil)) |
575 | return Qnil; | |
576 | else | |
577 | list = wrong_type_argument (Qlistp, list); | |
578 | } | |
579 | } | |
580 | ||
581 | DEFUN ("cdr-safe", Fcdr_safe, Scdr_safe, 1, 1, 0, | |
8c1a1077 PJ |
582 | doc: /* Return the cdr of OBJECT if it is a cons cell, or else nil. */) |
583 | (object) | |
7921925c JB |
584 | Lisp_Object object; |
585 | { | |
e9ebc175 | 586 | if (CONSP (object)) |
7539e11f | 587 | return XCDR (object); |
7921925c JB |
588 | else |
589 | return Qnil; | |
590 | } | |
591 | ||
592 | DEFUN ("setcar", Fsetcar, Ssetcar, 2, 2, 0, | |
8c1a1077 PJ |
593 | doc: /* Set the car of CELL to be NEWCAR. Returns NEWCAR. */) |
594 | (cell, newcar) | |
7921925c JB |
595 | register Lisp_Object cell, newcar; |
596 | { | |
e9ebc175 | 597 | if (!CONSP (cell)) |
7921925c JB |
598 | cell = wrong_type_argument (Qconsp, cell); |
599 | ||
600 | CHECK_IMPURE (cell); | |
f3fbd155 | 601 | XSETCAR (cell, newcar); |
7921925c JB |
602 | return newcar; |
603 | } | |
604 | ||
605 | DEFUN ("setcdr", Fsetcdr, Ssetcdr, 2, 2, 0, | |
8c1a1077 PJ |
606 | doc: /* Set the cdr of CELL to be NEWCDR. Returns NEWCDR. */) |
607 | (cell, newcdr) | |
7921925c JB |
608 | register Lisp_Object cell, newcdr; |
609 | { | |
e9ebc175 | 610 | if (!CONSP (cell)) |
7921925c JB |
611 | cell = wrong_type_argument (Qconsp, cell); |
612 | ||
613 | CHECK_IMPURE (cell); | |
f3fbd155 | 614 | XSETCDR (cell, newcdr); |
7921925c JB |
615 | return newcdr; |
616 | } | |
617 | \f | |
618 | /* Extract and set components of symbols */ | |
619 | ||
8c1a1077 PJ |
620 | DEFUN ("boundp", Fboundp, Sboundp, 1, 1, 0, |
621 | doc: /* Return t if SYMBOL's value is not void. */) | |
622 | (symbol) | |
d9c2a0f2 | 623 | register Lisp_Object symbol; |
7921925c JB |
624 | { |
625 | Lisp_Object valcontents; | |
b7826503 | 626 | CHECK_SYMBOL (symbol); |
7921925c | 627 | |
f35d5bad | 628 | valcontents = SYMBOL_VALUE (symbol); |
7921925c | 629 | |
aabf6bec KH |
630 | if (BUFFER_LOCAL_VALUEP (valcontents) |
631 | || SOME_BUFFER_LOCAL_VALUEP (valcontents)) | |
d9c2a0f2 | 632 | valcontents = swap_in_symval_forwarding (symbol, valcontents); |
7921925c | 633 | |
1bfcade3 | 634 | return (EQ (valcontents, Qunbound) ? Qnil : Qt); |
7921925c JB |
635 | } |
636 | ||
8c1a1077 PJ |
637 | DEFUN ("fboundp", Ffboundp, Sfboundp, 1, 1, 0, |
638 | doc: /* Return t if SYMBOL's function definition is not void. */) | |
639 | (symbol) | |
d9c2a0f2 | 640 | register Lisp_Object symbol; |
7921925c | 641 | { |
b7826503 | 642 | CHECK_SYMBOL (symbol); |
d9c2a0f2 | 643 | return (EQ (XSYMBOL (symbol)->function, Qunbound) ? Qnil : Qt); |
7921925c JB |
644 | } |
645 | ||
8c1a1077 | 646 | DEFUN ("makunbound", Fmakunbound, Smakunbound, 1, 1, 0, |
bfb96cb7 FP |
647 | doc: /* Make SYMBOL's value be void. |
648 | Return SYMBOL. */) | |
8c1a1077 | 649 | (symbol) |
d9c2a0f2 | 650 | register Lisp_Object symbol; |
7921925c | 651 | { |
b7826503 | 652 | CHECK_SYMBOL (symbol); |
f35d5bad | 653 | if (XSYMBOL (symbol)->constant) |
d9c2a0f2 EN |
654 | return Fsignal (Qsetting_constant, Fcons (symbol, Qnil)); |
655 | Fset (symbol, Qunbound); | |
656 | return symbol; | |
7921925c JB |
657 | } |
658 | ||
8c1a1077 | 659 | DEFUN ("fmakunbound", Ffmakunbound, Sfmakunbound, 1, 1, 0, |
bfb96cb7 FP |
660 | doc: /* Make SYMBOL's function definition be void. |
661 | Return SYMBOL. */) | |
8c1a1077 | 662 | (symbol) |
d9c2a0f2 | 663 | register Lisp_Object symbol; |
7921925c | 664 | { |
b7826503 | 665 | CHECK_SYMBOL (symbol); |
d9c2a0f2 EN |
666 | if (NILP (symbol) || EQ (symbol, Qt)) |
667 | return Fsignal (Qsetting_constant, Fcons (symbol, Qnil)); | |
668 | XSYMBOL (symbol)->function = Qunbound; | |
669 | return symbol; | |
7921925c JB |
670 | } |
671 | ||
672 | DEFUN ("symbol-function", Fsymbol_function, Ssymbol_function, 1, 1, 0, | |
8c1a1077 PJ |
673 | doc: /* Return SYMBOL's function definition. Error if that is void. */) |
674 | (symbol) | |
ffd56f97 | 675 | register Lisp_Object symbol; |
7921925c | 676 | { |
b7826503 | 677 | CHECK_SYMBOL (symbol); |
ffd56f97 JB |
678 | if (EQ (XSYMBOL (symbol)->function, Qunbound)) |
679 | return Fsignal (Qvoid_function, Fcons (symbol, Qnil)); | |
680 | return XSYMBOL (symbol)->function; | |
7921925c JB |
681 | } |
682 | ||
8c1a1077 PJ |
683 | DEFUN ("symbol-plist", Fsymbol_plist, Ssymbol_plist, 1, 1, 0, |
684 | doc: /* Return SYMBOL's property list. */) | |
685 | (symbol) | |
d9c2a0f2 | 686 | register Lisp_Object symbol; |
7921925c | 687 | { |
b7826503 | 688 | CHECK_SYMBOL (symbol); |
d9c2a0f2 | 689 | return XSYMBOL (symbol)->plist; |
7921925c JB |
690 | } |
691 | ||
8c1a1077 PJ |
692 | DEFUN ("symbol-name", Fsymbol_name, Ssymbol_name, 1, 1, 0, |
693 | doc: /* Return SYMBOL's name, a string. */) | |
694 | (symbol) | |
d9c2a0f2 | 695 | register Lisp_Object symbol; |
7921925c JB |
696 | { |
697 | register Lisp_Object name; | |
698 | ||
b7826503 | 699 | CHECK_SYMBOL (symbol); |
84023177 | 700 | name = SYMBOL_NAME (symbol); |
7921925c JB |
701 | return name; |
702 | } | |
703 | ||
704 | DEFUN ("fset", Ffset, Sfset, 2, 2, 0, | |
8c1a1077 PJ |
705 | doc: /* Set SYMBOL's function definition to DEFINITION, and return DEFINITION. */) |
706 | (symbol, definition) | |
8c0b5540 | 707 | register Lisp_Object symbol, definition; |
d9c2a0f2 | 708 | { |
b7826503 | 709 | CHECK_SYMBOL (symbol); |
d9c2a0f2 EN |
710 | if (NILP (symbol) || EQ (symbol, Qt)) |
711 | return Fsignal (Qsetting_constant, Fcons (symbol, Qnil)); | |
712 | if (!NILP (Vautoload_queue) && !EQ (XSYMBOL (symbol)->function, Qunbound)) | |
713 | Vautoload_queue = Fcons (Fcons (symbol, XSYMBOL (symbol)->function), | |
7921925c | 714 | Vautoload_queue); |
8c0b5540 | 715 | XSYMBOL (symbol)->function = definition; |
f845f2c9 | 716 | /* Handle automatic advice activation */ |
d9c2a0f2 | 717 | if (CONSP (XSYMBOL (symbol)->plist) && !NILP (Fget (symbol, Qad_advice_info))) |
f845f2c9 | 718 | { |
c1307a23 | 719 | call2 (Qad_activate_internal, symbol, Qnil); |
8c0b5540 | 720 | definition = XSYMBOL (symbol)->function; |
f845f2c9 | 721 | } |
8c0b5540 | 722 | return definition; |
7921925c JB |
723 | } |
724 | ||
d2fde41d SM |
725 | extern Lisp_Object Qfunction_documentation; |
726 | ||
727 | DEFUN ("defalias", Fdefalias, Sdefalias, 2, 3, 0, | |
8c1a1077 | 728 | doc: /* Set SYMBOL's function definition to DEFINITION, and return DEFINITION. |
96143227 RS |
729 | Associates the function with the current load file, if any. |
730 | The optional third argument DOCSTRING specifies the documentation string | |
731 | for SYMBOL; if it is omitted or nil, SYMBOL uses the documentation string | |
732 | determined by DEFINITION. */) | |
d2fde41d SM |
733 | (symbol, definition, docstring) |
734 | register Lisp_Object symbol, definition, docstring; | |
fc08c367 | 735 | { |
8a658a52 | 736 | CHECK_SYMBOL (symbol); |
894f6538 RS |
737 | if (CONSP (XSYMBOL (symbol)->function) |
738 | && EQ (XCAR (XSYMBOL (symbol)->function), Qautoload)) | |
739 | LOADHIST_ATTACH (Fcons (Qt, symbol)); | |
32f532b7 | 740 | definition = Ffset (symbol, definition); |
62a29071 | 741 | LOADHIST_ATTACH (Fcons (Qdefun, symbol)); |
d2fde41d SM |
742 | if (!NILP (docstring)) |
743 | Fput (symbol, Qfunction_documentation, docstring); | |
73e0d965 | 744 | return definition; |
fc08c367 RS |
745 | } |
746 | ||
7921925c | 747 | DEFUN ("setplist", Fsetplist, Ssetplist, 2, 2, 0, |
29802b85 | 748 | doc: /* Set SYMBOL's property list to NEWPLIST, and return NEWPLIST. */) |
8c1a1077 | 749 | (symbol, newplist) |
d9c2a0f2 | 750 | register Lisp_Object symbol, newplist; |
7921925c | 751 | { |
b7826503 | 752 | CHECK_SYMBOL (symbol); |
d9c2a0f2 | 753 | XSYMBOL (symbol)->plist = newplist; |
7921925c JB |
754 | return newplist; |
755 | } | |
ffd56f97 | 756 | |
6f0e897f | 757 | DEFUN ("subr-arity", Fsubr_arity, Ssubr_arity, 1, 1, 0, |
8c1a1077 PJ |
758 | doc: /* Return minimum and maximum number of args allowed for SUBR. |
759 | SUBR must be a built-in function. | |
760 | The returned value is a pair (MIN . MAX). MIN is the minimum number | |
761 | of args. MAX is the maximum number or the symbol `many', for a | |
762 | function with `&rest' args, or `unevalled' for a special form. */) | |
763 | (subr) | |
6f0e897f DL |
764 | Lisp_Object subr; |
765 | { | |
766 | short minargs, maxargs; | |
767 | if (!SUBRP (subr)) | |
768 | wrong_type_argument (Qsubrp, subr); | |
769 | minargs = XSUBR (subr)->min_args; | |
770 | maxargs = XSUBR (subr)->max_args; | |
771 | if (maxargs == MANY) | |
772 | return Fcons (make_number (minargs), Qmany); | |
773 | else if (maxargs == UNEVALLED) | |
774 | return Fcons (make_number (minargs), Qunevalled); | |
775 | else | |
776 | return Fcons (make_number (minargs), make_number (maxargs)); | |
777 | } | |
778 | ||
0fddae66 SM |
779 | DEFUN ("subr-name", Fsubr_name, Ssubr_name, 1, 1, 0, |
780 | doc: /* Return name of subroutine SUBR. | |
781 | SUBR must be a built-in function. */) | |
782 | (subr) | |
783 | Lisp_Object subr; | |
784 | { | |
785 | const char *name; | |
786 | if (!SUBRP (subr)) | |
787 | wrong_type_argument (Qsubrp, subr); | |
788 | name = XSUBR (subr)->symbol_name; | |
789 | return make_string (name, strlen (name)); | |
790 | } | |
791 | ||
f52a3ca3 SM |
792 | DEFUN ("interactive-form", Finteractive_form, Sinteractive_form, 1, 1, 0, |
793 | doc: /* Return the interactive form of CMD or nil if none. | |
df133612 LT |
794 | If CMD is not a command, the return value is nil. |
795 | Value, if non-nil, is a list \(interactive SPEC). */) | |
f52a3ca3 SM |
796 | (cmd) |
797 | Lisp_Object cmd; | |
cc515226 | 798 | { |
f52a3ca3 SM |
799 | Lisp_Object fun = indirect_function (cmd); |
800 | ||
801 | if (SUBRP (fun)) | |
802 | { | |
803 | if (XSUBR (fun)->prompt) | |
804 | return list2 (Qinteractive, build_string (XSUBR (fun)->prompt)); | |
805 | } | |
806 | else if (COMPILEDP (fun)) | |
807 | { | |
808 | if ((ASIZE (fun) & PSEUDOVECTOR_SIZE_MASK) > COMPILED_INTERACTIVE) | |
809 | return list2 (Qinteractive, AREF (fun, COMPILED_INTERACTIVE)); | |
810 | } | |
811 | else if (CONSP (fun)) | |
812 | { | |
813 | Lisp_Object funcar = XCAR (fun); | |
814 | if (EQ (funcar, Qlambda)) | |
815 | return Fassq (Qinteractive, Fcdr (XCDR (fun))); | |
816 | else if (EQ (funcar, Qautoload)) | |
817 | { | |
818 | struct gcpro gcpro1; | |
819 | GCPRO1 (cmd); | |
820 | do_autoload (fun, cmd); | |
821 | UNGCPRO; | |
822 | return Finteractive_form (cmd); | |
823 | } | |
824 | } | |
cc515226 GM |
825 | return Qnil; |
826 | } | |
827 | ||
7921925c | 828 | \f |
f35d5bad GM |
829 | /*********************************************************************** |
830 | Getting and Setting Values of Symbols | |
831 | ***********************************************************************/ | |
832 | ||
833 | /* Return the symbol holding SYMBOL's value. Signal | |
834 | `cyclic-variable-indirection' if SYMBOL's chain of variable | |
835 | indirections contains a loop. */ | |
836 | ||
837 | Lisp_Object | |
838 | indirect_variable (symbol) | |
839 | Lisp_Object symbol; | |
840 | { | |
841 | Lisp_Object tortoise, hare; | |
842 | ||
843 | hare = tortoise = symbol; | |
844 | ||
845 | while (XSYMBOL (hare)->indirect_variable) | |
846 | { | |
847 | hare = XSYMBOL (hare)->value; | |
848 | if (!XSYMBOL (hare)->indirect_variable) | |
849 | break; | |
bfb96cb7 | 850 | |
f35d5bad GM |
851 | hare = XSYMBOL (hare)->value; |
852 | tortoise = XSYMBOL (tortoise)->value; | |
853 | ||
854 | if (EQ (hare, tortoise)) | |
855 | Fsignal (Qcyclic_variable_indirection, Fcons (symbol, Qnil)); | |
856 | } | |
857 | ||
858 | return hare; | |
859 | } | |
860 | ||
861 | ||
862 | DEFUN ("indirect-variable", Findirect_variable, Sindirect_variable, 1, 1, 0, | |
8c1a1077 PJ |
863 | doc: /* Return the variable at the end of OBJECT's variable chain. |
864 | If OBJECT is a symbol, follow all variable indirections and return the final | |
865 | variable. If OBJECT is not a symbol, just return it. | |
866 | Signal a cyclic-variable-indirection error if there is a loop in the | |
867 | variable chain of symbols. */) | |
868 | (object) | |
f35d5bad GM |
869 | Lisp_Object object; |
870 | { | |
871 | if (SYMBOLP (object)) | |
872 | object = indirect_variable (object); | |
873 | return object; | |
874 | } | |
875 | ||
7921925c JB |
876 | |
877 | /* Given the raw contents of a symbol value cell, | |
878 | return the Lisp value of the symbol. | |
879 | This does not handle buffer-local variables; use | |
880 | swap_in_symval_forwarding for that. */ | |
881 | ||
882 | Lisp_Object | |
883 | do_symval_forwarding (valcontents) | |
884 | register Lisp_Object valcontents; | |
885 | { | |
886 | register Lisp_Object val; | |
46b2ac21 KH |
887 | int offset; |
888 | if (MISCP (valcontents)) | |
324a6eef | 889 | switch (XMISCTYPE (valcontents)) |
46b2ac21 KH |
890 | { |
891 | case Lisp_Misc_Intfwd: | |
892 | XSETINT (val, *XINTFWD (valcontents)->intvar); | |
893 | return val; | |
7921925c | 894 | |
46b2ac21 KH |
895 | case Lisp_Misc_Boolfwd: |
896 | return (*XBOOLFWD (valcontents)->boolvar ? Qt : Qnil); | |
7921925c | 897 | |
46b2ac21 KH |
898 | case Lisp_Misc_Objfwd: |
899 | return *XOBJFWD (valcontents)->objvar; | |
7921925c | 900 | |
46b2ac21 KH |
901 | case Lisp_Misc_Buffer_Objfwd: |
902 | offset = XBUFFER_OBJFWD (valcontents)->offset; | |
f6cd0527 | 903 | return PER_BUFFER_VALUE (current_buffer, offset); |
7403b5c8 | 904 | |
e5f8af9e KH |
905 | case Lisp_Misc_Kboard_Objfwd: |
906 | offset = XKBOARD_OBJFWD (valcontents)->offset; | |
907 | return *(Lisp_Object *)(offset + (char *)current_kboard); | |
46b2ac21 | 908 | } |
7921925c JB |
909 | return valcontents; |
910 | } | |
911 | ||
d9c2a0f2 EN |
912 | /* Store NEWVAL into SYMBOL, where VALCONTENTS is found in the value cell |
913 | of SYMBOL. If SYMBOL is buffer-local, VALCONTENTS should be the | |
7921925c | 914 | buffer-independent contents of the value cell: forwarded just one |
7a283f36 GM |
915 | step past the buffer-localness. |
916 | ||
917 | BUF non-zero means set the value in buffer BUF instead of the | |
918 | current buffer. This only plays a role for per-buffer variables. */ | |
7921925c JB |
919 | |
920 | void | |
7a283f36 | 921 | store_symval_forwarding (symbol, valcontents, newval, buf) |
d9c2a0f2 | 922 | Lisp_Object symbol; |
7921925c | 923 | register Lisp_Object valcontents, newval; |
7a283f36 | 924 | struct buffer *buf; |
7921925c | 925 | { |
0220c518 | 926 | switch (SWITCH_ENUM_CAST (XTYPE (valcontents))) |
7921925c | 927 | { |
46b2ac21 | 928 | case Lisp_Misc: |
324a6eef | 929 | switch (XMISCTYPE (valcontents)) |
46b2ac21 KH |
930 | { |
931 | case Lisp_Misc_Intfwd: | |
b7826503 | 932 | CHECK_NUMBER (newval); |
46b2ac21 | 933 | *XINTFWD (valcontents)->intvar = XINT (newval); |
e6c82a8d RS |
934 | if (*XINTFWD (valcontents)->intvar != XINT (newval)) |
935 | error ("Value out of range for variable `%s'", | |
d5db4077 | 936 | SDATA (SYMBOL_NAME (symbol))); |
46b2ac21 KH |
937 | break; |
938 | ||
939 | case Lisp_Misc_Boolfwd: | |
940 | *XBOOLFWD (valcontents)->boolvar = NILP (newval) ? 0 : 1; | |
941 | break; | |
942 | ||
943 | case Lisp_Misc_Objfwd: | |
944 | *XOBJFWD (valcontents)->objvar = newval; | |
7abd90ea RS |
945 | |
946 | /* If this variable is a default for something stored | |
947 | in the buffer itself, such as default-fill-column, | |
948 | find the buffers that don't have local values for it | |
949 | and update them. */ | |
950 | if (XOBJFWD (valcontents)->objvar > (Lisp_Object *) &buffer_defaults | |
951 | && XOBJFWD (valcontents)->objvar < (Lisp_Object *) (&buffer_defaults + 1)) | |
952 | { | |
953 | int offset = ((char *) XOBJFWD (valcontents)->objvar | |
954 | - (char *) &buffer_defaults); | |
955 | int idx = PER_BUFFER_IDX (offset); | |
956 | ||
43e50e40 | 957 | Lisp_Object tail; |
7abd90ea RS |
958 | |
959 | if (idx <= 0) | |
960 | break; | |
961 | ||
962 | for (tail = Vbuffer_alist; CONSP (tail); tail = XCDR (tail)) | |
963 | { | |
964 | Lisp_Object buf; | |
965 | struct buffer *b; | |
966 | ||
967 | buf = Fcdr (XCAR (tail)); | |
968 | if (!BUFFERP (buf)) continue; | |
969 | b = XBUFFER (buf); | |
970 | ||
971 | if (! PER_BUFFER_VALUE_P (b, idx)) | |
972 | PER_BUFFER_VALUE (b, offset) = newval; | |
973 | } | |
974 | } | |
46b2ac21 KH |
975 | break; |
976 | ||
977 | case Lisp_Misc_Buffer_Objfwd: | |
978 | { | |
979 | int offset = XBUFFER_OBJFWD (valcontents)->offset; | |
980 | Lisp_Object type; | |
981 | ||
d9b36d19 | 982 | type = PER_BUFFER_TYPE (offset); |
46b2ac21 KH |
983 | if (! NILP (type) && ! NILP (newval) |
984 | && XTYPE (newval) != XINT (type)) | |
985 | buffer_slot_type_mismatch (offset); | |
986 | ||
7a283f36 GM |
987 | if (buf == NULL) |
988 | buf = current_buffer; | |
989 | PER_BUFFER_VALUE (buf, offset) = newval; | |
46b2ac21 | 990 | } |
7403b5c8 KH |
991 | break; |
992 | ||
e5f8af9e | 993 | case Lisp_Misc_Kboard_Objfwd: |
7a283f36 GM |
994 | { |
995 | char *base = (char *) current_kboard; | |
996 | char *p = base + XKBOARD_OBJFWD (valcontents)->offset; | |
997 | *(Lisp_Object *) p = newval; | |
998 | } | |
7403b5c8 KH |
999 | break; |
1000 | ||
46b2ac21 KH |
1001 | default: |
1002 | goto def; | |
1003 | } | |
7921925c JB |
1004 | break; |
1005 | ||
7921925c | 1006 | default: |
46b2ac21 | 1007 | def: |
f35d5bad | 1008 | valcontents = SYMBOL_VALUE (symbol); |
e9ebc175 KH |
1009 | if (BUFFER_LOCAL_VALUEP (valcontents) |
1010 | || SOME_BUFFER_LOCAL_VALUEP (valcontents)) | |
b0c2d1c6 | 1011 | XBUFFER_LOCAL_VALUE (valcontents)->realvalue = newval; |
7921925c | 1012 | else |
f35d5bad | 1013 | SET_SYMBOL_VALUE (symbol, newval); |
7921925c JB |
1014 | } |
1015 | } | |
1016 | ||
b0d53add GM |
1017 | /* Set up SYMBOL to refer to its global binding. |
1018 | This makes it safe to alter the status of other bindings. */ | |
1019 | ||
1020 | void | |
1021 | swap_in_global_binding (symbol) | |
1022 | Lisp_Object symbol; | |
1023 | { | |
1024 | Lisp_Object valcontents, cdr; | |
bfb96cb7 | 1025 | |
f35d5bad | 1026 | valcontents = SYMBOL_VALUE (symbol); |
b0d53add GM |
1027 | if (!BUFFER_LOCAL_VALUEP (valcontents) |
1028 | && !SOME_BUFFER_LOCAL_VALUEP (valcontents)) | |
1029 | abort (); | |
1030 | cdr = XBUFFER_LOCAL_VALUE (valcontents)->cdr; | |
1031 | ||
1032 | /* Unload the previously loaded binding. */ | |
1033 | Fsetcdr (XCAR (cdr), | |
1034 | do_symval_forwarding (XBUFFER_LOCAL_VALUE (valcontents)->realvalue)); | |
bfb96cb7 | 1035 | |
b0d53add | 1036 | /* Select the global binding in the symbol. */ |
f3fbd155 | 1037 | XSETCAR (cdr, cdr); |
7a283f36 | 1038 | store_symval_forwarding (symbol, valcontents, XCDR (cdr), NULL); |
b0d53add GM |
1039 | |
1040 | /* Indicate that the global binding is set up now. */ | |
1041 | XBUFFER_LOCAL_VALUE (valcontents)->frame = Qnil; | |
1042 | XBUFFER_LOCAL_VALUE (valcontents)->buffer = Qnil; | |
1043 | XBUFFER_LOCAL_VALUE (valcontents)->found_for_frame = 0; | |
1044 | XBUFFER_LOCAL_VALUE (valcontents)->found_for_buffer = 0; | |
1045 | } | |
1046 | ||
2829d05f | 1047 | /* Set up the buffer-local symbol SYMBOL for validity in the current buffer. |
42e975f0 RS |
1048 | VALCONTENTS is the contents of its value cell, |
1049 | which points to a struct Lisp_Buffer_Local_Value. | |
1050 | ||
1051 | Return the value forwarded one step past the buffer-local stage. | |
1052 | This could be another forwarding pointer. */ | |
7921925c JB |
1053 | |
1054 | static Lisp_Object | |
d9c2a0f2 EN |
1055 | swap_in_symval_forwarding (symbol, valcontents) |
1056 | Lisp_Object symbol, valcontents; | |
7921925c | 1057 | { |
7921925c | 1058 | register Lisp_Object tem1; |
bfb96cb7 | 1059 | |
b0c2d1c6 | 1060 | tem1 = XBUFFER_LOCAL_VALUE (valcontents)->buffer; |
7921925c | 1061 | |
42e975f0 RS |
1062 | if (NILP (tem1) |
1063 | || current_buffer != XBUFFER (tem1) | |
1064 | || (XBUFFER_LOCAL_VALUE (valcontents)->check_frame | |
1065 | && ! EQ (selected_frame, XBUFFER_LOCAL_VALUE (valcontents)->frame))) | |
7921925c | 1066 | { |
f35d5bad GM |
1067 | if (XSYMBOL (symbol)->indirect_variable) |
1068 | symbol = indirect_variable (symbol); | |
bfb96cb7 | 1069 | |
42e975f0 | 1070 | /* Unload the previously loaded binding. */ |
7539e11f | 1071 | tem1 = XCAR (XBUFFER_LOCAL_VALUE (valcontents)->cdr); |
8d4afcac | 1072 | Fsetcdr (tem1, |
b0c2d1c6 | 1073 | do_symval_forwarding (XBUFFER_LOCAL_VALUE (valcontents)->realvalue)); |
42e975f0 | 1074 | /* Choose the new binding. */ |
d9c2a0f2 | 1075 | tem1 = assq_no_quit (symbol, current_buffer->local_var_alist); |
b0c2d1c6 RS |
1076 | XBUFFER_LOCAL_VALUE (valcontents)->found_for_frame = 0; |
1077 | XBUFFER_LOCAL_VALUE (valcontents)->found_for_buffer = 0; | |
a33ef3ab | 1078 | if (NILP (tem1)) |
b0c2d1c6 RS |
1079 | { |
1080 | if (XBUFFER_LOCAL_VALUE (valcontents)->check_frame) | |
1cc04aed | 1081 | tem1 = assq_no_quit (symbol, XFRAME (selected_frame)->param_alist); |
b0c2d1c6 RS |
1082 | if (! NILP (tem1)) |
1083 | XBUFFER_LOCAL_VALUE (valcontents)->found_for_frame = 1; | |
1084 | else | |
1085 | tem1 = XBUFFER_LOCAL_VALUE (valcontents)->cdr; | |
1086 | } | |
1087 | else | |
1088 | XBUFFER_LOCAL_VALUE (valcontents)->found_for_buffer = 1; | |
1089 | ||
42e975f0 | 1090 | /* Load the new binding. */ |
f3fbd155 | 1091 | XSETCAR (XBUFFER_LOCAL_VALUE (valcontents)->cdr, tem1); |
b0c2d1c6 | 1092 | XSETBUFFER (XBUFFER_LOCAL_VALUE (valcontents)->buffer, current_buffer); |
1cc04aed | 1093 | XBUFFER_LOCAL_VALUE (valcontents)->frame = selected_frame; |
b0c2d1c6 RS |
1094 | store_symval_forwarding (symbol, |
1095 | XBUFFER_LOCAL_VALUE (valcontents)->realvalue, | |
7a283f36 | 1096 | Fcdr (tem1), NULL); |
7921925c | 1097 | } |
b0c2d1c6 | 1098 | return XBUFFER_LOCAL_VALUE (valcontents)->realvalue; |
7921925c JB |
1099 | } |
1100 | \f | |
14e76af9 JB |
1101 | /* Find the value of a symbol, returning Qunbound if it's not bound. |
1102 | This is helpful for code which just wants to get a variable's value | |
8e6208c5 | 1103 | if it has one, without signaling an error. |
14e76af9 JB |
1104 | Note that it must not be possible to quit |
1105 | within this function. Great care is required for this. */ | |
7921925c | 1106 | |
14e76af9 | 1107 | Lisp_Object |
d9c2a0f2 EN |
1108 | find_symbol_value (symbol) |
1109 | Lisp_Object symbol; | |
7921925c | 1110 | { |
dd8daec5 | 1111 | register Lisp_Object valcontents; |
7921925c | 1112 | register Lisp_Object val; |
bfb96cb7 | 1113 | |
b7826503 | 1114 | CHECK_SYMBOL (symbol); |
f35d5bad | 1115 | valcontents = SYMBOL_VALUE (symbol); |
7921925c | 1116 | |
aabf6bec KH |
1117 | if (BUFFER_LOCAL_VALUEP (valcontents) |
1118 | || SOME_BUFFER_LOCAL_VALUEP (valcontents)) | |
2a359158 | 1119 | valcontents = swap_in_symval_forwarding (symbol, valcontents); |
7921925c | 1120 | |
536b772a KH |
1121 | if (MISCP (valcontents)) |
1122 | { | |
324a6eef | 1123 | switch (XMISCTYPE (valcontents)) |
46b2ac21 KH |
1124 | { |
1125 | case Lisp_Misc_Intfwd: | |
1126 | XSETINT (val, *XINTFWD (valcontents)->intvar); | |
1127 | return val; | |
7921925c | 1128 | |
46b2ac21 KH |
1129 | case Lisp_Misc_Boolfwd: |
1130 | return (*XBOOLFWD (valcontents)->boolvar ? Qt : Qnil); | |
7921925c | 1131 | |
46b2ac21 KH |
1132 | case Lisp_Misc_Objfwd: |
1133 | return *XOBJFWD (valcontents)->objvar; | |
7921925c | 1134 | |
46b2ac21 | 1135 | case Lisp_Misc_Buffer_Objfwd: |
f6cd0527 | 1136 | return PER_BUFFER_VALUE (current_buffer, |
999b32fd | 1137 | XBUFFER_OBJFWD (valcontents)->offset); |
7403b5c8 | 1138 | |
e5f8af9e KH |
1139 | case Lisp_Misc_Kboard_Objfwd: |
1140 | return *(Lisp_Object *)(XKBOARD_OBJFWD (valcontents)->offset | |
1141 | + (char *)current_kboard); | |
46b2ac21 | 1142 | } |
7921925c JB |
1143 | } |
1144 | ||
1145 | return valcontents; | |
1146 | } | |
1147 | ||
14e76af9 | 1148 | DEFUN ("symbol-value", Fsymbol_value, Ssymbol_value, 1, 1, 0, |
8c1a1077 PJ |
1149 | doc: /* Return SYMBOL's value. Error if that is void. */) |
1150 | (symbol) | |
d9c2a0f2 | 1151 | Lisp_Object symbol; |
14e76af9 | 1152 | { |
0671d7c0 | 1153 | Lisp_Object val; |
14e76af9 | 1154 | |
d9c2a0f2 | 1155 | val = find_symbol_value (symbol); |
14e76af9 | 1156 | if (EQ (val, Qunbound)) |
d9c2a0f2 | 1157 | return Fsignal (Qvoid_variable, Fcons (symbol, Qnil)); |
14e76af9 JB |
1158 | else |
1159 | return val; | |
1160 | } | |
1161 | ||
7921925c | 1162 | DEFUN ("set", Fset, Sset, 2, 2, 0, |
8c1a1077 PJ |
1163 | doc: /* Set SYMBOL's value to NEWVAL, and return NEWVAL. */) |
1164 | (symbol, newval) | |
d9c2a0f2 | 1165 | register Lisp_Object symbol, newval; |
05ef7169 | 1166 | { |
2829d05f | 1167 | return set_internal (symbol, newval, current_buffer, 0); |
05ef7169 RS |
1168 | } |
1169 | ||
1f35ce36 RS |
1170 | /* Return 1 if SYMBOL currently has a let-binding |
1171 | which was made in the buffer that is now current. */ | |
1172 | ||
1173 | static int | |
1174 | let_shadows_buffer_binding_p (symbol) | |
1175 | Lisp_Object symbol; | |
1176 | { | |
92426155 | 1177 | volatile struct specbinding *p; |
1f35ce36 RS |
1178 | |
1179 | for (p = specpdl_ptr - 1; p >= specpdl; p--) | |
f35d5bad GM |
1180 | if (p->func == NULL |
1181 | && CONSP (p->symbol)) | |
1182 | { | |
1183 | Lisp_Object let_bound_symbol = XCAR (p->symbol); | |
1184 | if ((EQ (symbol, let_bound_symbol) | |
1185 | || (XSYMBOL (let_bound_symbol)->indirect_variable | |
1186 | && EQ (symbol, indirect_variable (let_bound_symbol)))) | |
1187 | && XBUFFER (XCDR (XCDR (p->symbol))) == current_buffer) | |
1188 | break; | |
1189 | } | |
1f35ce36 | 1190 | |
f35d5bad | 1191 | return p >= specpdl; |
1f35ce36 RS |
1192 | } |
1193 | ||
25638b07 | 1194 | /* Store the value NEWVAL into SYMBOL. |
2829d05f RS |
1195 | If buffer-locality is an issue, BUF specifies which buffer to use. |
1196 | (0 stands for the current buffer.) | |
1197 | ||
05ef7169 RS |
1198 | If BINDFLAG is zero, then if this symbol is supposed to become |
1199 | local in every buffer where it is set, then we make it local. | |
1200 | If BINDFLAG is nonzero, we don't do that. */ | |
1201 | ||
1202 | Lisp_Object | |
2829d05f | 1203 | set_internal (symbol, newval, buf, bindflag) |
05ef7169 | 1204 | register Lisp_Object symbol, newval; |
2829d05f | 1205 | struct buffer *buf; |
05ef7169 | 1206 | int bindflag; |
7921925c | 1207 | { |
1bfcade3 | 1208 | int voide = EQ (newval, Qunbound); |
7921925c | 1209 | |
4c47c973 | 1210 | register Lisp_Object valcontents, innercontents, tem1, current_alist_element; |
7921925c | 1211 | |
2829d05f RS |
1212 | if (buf == 0) |
1213 | buf = current_buffer; | |
1214 | ||
1215 | /* If restoring in a dead buffer, do nothing. */ | |
1216 | if (NILP (buf->name)) | |
1217 | return newval; | |
1218 | ||
b7826503 | 1219 | CHECK_SYMBOL (symbol); |
f35d5bad GM |
1220 | if (SYMBOL_CONSTANT_P (symbol) |
1221 | && (NILP (Fkeywordp (symbol)) | |
1222 | || !EQ (newval, SYMBOL_VALUE (symbol)))) | |
d9c2a0f2 | 1223 | return Fsignal (Qsetting_constant, Fcons (symbol, Qnil)); |
4c47c973 | 1224 | |
f35d5bad | 1225 | innercontents = valcontents = SYMBOL_VALUE (symbol); |
bfb96cb7 | 1226 | |
e9ebc175 | 1227 | if (BUFFER_OBJFWDP (valcontents)) |
7921925c | 1228 | { |
999b32fd | 1229 | int offset = XBUFFER_OBJFWD (valcontents)->offset; |
f6cd0527 | 1230 | int idx = PER_BUFFER_IDX (offset); |
999b32fd GM |
1231 | if (idx > 0 |
1232 | && !bindflag | |
1233 | && !let_shadows_buffer_binding_p (symbol)) | |
f6cd0527 | 1234 | SET_PER_BUFFER_VALUE_P (buf, idx, 1); |
7921925c | 1235 | } |
e9ebc175 KH |
1236 | else if (BUFFER_LOCAL_VALUEP (valcontents) |
1237 | || SOME_BUFFER_LOCAL_VALUEP (valcontents)) | |
7921925c | 1238 | { |
42e975f0 | 1239 | /* valcontents is a struct Lisp_Buffer_Local_Value. */ |
f35d5bad GM |
1240 | if (XSYMBOL (symbol)->indirect_variable) |
1241 | symbol = indirect_variable (symbol); | |
42e975f0 RS |
1242 | |
1243 | /* What binding is loaded right now? */ | |
b0c2d1c6 | 1244 | current_alist_element |
7539e11f | 1245 | = XCAR (XBUFFER_LOCAL_VALUE (valcontents)->cdr); |
d8cafeb5 JB |
1246 | |
1247 | /* If the current buffer is not the buffer whose binding is | |
42e975f0 RS |
1248 | loaded, or if there may be frame-local bindings and the frame |
1249 | isn't the right one, or if it's a Lisp_Buffer_Local_Value and | |
1250 | the default binding is loaded, the loaded binding may be the | |
1251 | wrong one. */ | |
8801a864 KR |
1252 | if (!BUFFERP (XBUFFER_LOCAL_VALUE (valcontents)->buffer) |
1253 | || buf != XBUFFER (XBUFFER_LOCAL_VALUE (valcontents)->buffer) | |
42e975f0 RS |
1254 | || (XBUFFER_LOCAL_VALUE (valcontents)->check_frame |
1255 | && !EQ (selected_frame, XBUFFER_LOCAL_VALUE (valcontents)->frame)) | |
1256 | || (BUFFER_LOCAL_VALUEP (valcontents) | |
1257 | && EQ (XCAR (current_alist_element), | |
1258 | current_alist_element))) | |
7921925c | 1259 | { |
42e975f0 RS |
1260 | /* The currently loaded binding is not necessarily valid. |
1261 | We need to unload it, and choose a new binding. */ | |
1262 | ||
1263 | /* Write out `realvalue' to the old loaded binding. */ | |
d8cafeb5 | 1264 | Fsetcdr (current_alist_element, |
b0c2d1c6 | 1265 | do_symval_forwarding (XBUFFER_LOCAL_VALUE (valcontents)->realvalue)); |
7921925c | 1266 | |
42e975f0 | 1267 | /* Find the new binding. */ |
2829d05f | 1268 | tem1 = Fassq (symbol, buf->local_var_alist); |
b0c2d1c6 RS |
1269 | XBUFFER_LOCAL_VALUE (valcontents)->found_for_buffer = 1; |
1270 | XBUFFER_LOCAL_VALUE (valcontents)->found_for_frame = 0; | |
1271 | ||
a33ef3ab | 1272 | if (NILP (tem1)) |
d8cafeb5 JB |
1273 | { |
1274 | /* This buffer still sees the default value. */ | |
1275 | ||
1276 | /* If the variable is a Lisp_Some_Buffer_Local_Value, | |
05ef7169 | 1277 | or if this is `let' rather than `set', |
d8cafeb5 | 1278 | make CURRENT-ALIST-ELEMENT point to itself, |
1f35ce36 RS |
1279 | indicating that we're seeing the default value. |
1280 | Likewise if the variable has been let-bound | |
1281 | in the current buffer. */ | |
1282 | if (bindflag || SOME_BUFFER_LOCAL_VALUEP (valcontents) | |
1283 | || let_shadows_buffer_binding_p (symbol)) | |
b0c2d1c6 RS |
1284 | { |
1285 | XBUFFER_LOCAL_VALUE (valcontents)->found_for_buffer = 0; | |
1286 | ||
1287 | if (XBUFFER_LOCAL_VALUE (valcontents)->check_frame) | |
1cc04aed GM |
1288 | tem1 = Fassq (symbol, |
1289 | XFRAME (selected_frame)->param_alist); | |
d8cafeb5 | 1290 | |
b0c2d1c6 RS |
1291 | if (! NILP (tem1)) |
1292 | XBUFFER_LOCAL_VALUE (valcontents)->found_for_frame = 1; | |
1293 | else | |
1294 | tem1 = XBUFFER_LOCAL_VALUE (valcontents)->cdr; | |
1295 | } | |
05ef7169 | 1296 | /* If it's a Lisp_Buffer_Local_Value, being set not bound, |
1f35ce36 RS |
1297 | and we're not within a let that was made for this buffer, |
1298 | create a new buffer-local binding for the variable. | |
1299 | That means, give this buffer a new assoc for a local value | |
42e975f0 | 1300 | and load that binding. */ |
d8cafeb5 JB |
1301 | else |
1302 | { | |
d2fde41d | 1303 | tem1 = Fcons (symbol, XCDR (current_alist_element)); |
2829d05f RS |
1304 | buf->local_var_alist |
1305 | = Fcons (tem1, buf->local_var_alist); | |
d8cafeb5 JB |
1306 | } |
1307 | } | |
b0c2d1c6 | 1308 | |
42e975f0 | 1309 | /* Record which binding is now loaded. */ |
f3fbd155 KR |
1310 | XSETCAR (XBUFFER_LOCAL_VALUE (valcontents)->cdr, |
1311 | tem1); | |
d8cafeb5 | 1312 | |
42e975f0 | 1313 | /* Set `buffer' and `frame' slots for thebinding now loaded. */ |
2829d05f | 1314 | XSETBUFFER (XBUFFER_LOCAL_VALUE (valcontents)->buffer, buf); |
1cc04aed | 1315 | XBUFFER_LOCAL_VALUE (valcontents)->frame = selected_frame; |
7921925c | 1316 | } |
4c47c973 | 1317 | innercontents = XBUFFER_LOCAL_VALUE (valcontents)->realvalue; |
7921925c | 1318 | } |
d8cafeb5 | 1319 | |
7921925c JB |
1320 | /* If storing void (making the symbol void), forward only through |
1321 | buffer-local indicator, not through Lisp_Objfwd, etc. */ | |
1322 | if (voide) | |
7a283f36 | 1323 | store_symval_forwarding (symbol, Qnil, newval, buf); |
7921925c | 1324 | else |
7a283f36 | 1325 | store_symval_forwarding (symbol, innercontents, newval, buf); |
4c47c973 GM |
1326 | |
1327 | /* If we just set a variable whose current binding is frame-local, | |
1328 | store the new value in the frame parameter too. */ | |
1329 | ||
1330 | if (BUFFER_LOCAL_VALUEP (valcontents) | |
1331 | || SOME_BUFFER_LOCAL_VALUEP (valcontents)) | |
1332 | { | |
1333 | /* What binding is loaded right now? */ | |
1334 | current_alist_element | |
1335 | = XCAR (XBUFFER_LOCAL_VALUE (valcontents)->cdr); | |
1336 | ||
1337 | /* If the current buffer is not the buffer whose binding is | |
1338 | loaded, or if there may be frame-local bindings and the frame | |
1339 | isn't the right one, or if it's a Lisp_Buffer_Local_Value and | |
1340 | the default binding is loaded, the loaded binding may be the | |
1341 | wrong one. */ | |
1342 | if (XBUFFER_LOCAL_VALUE (valcontents)->found_for_frame) | |
f3fbd155 | 1343 | XSETCDR (current_alist_element, newval); |
4c47c973 | 1344 | } |
d8cafeb5 | 1345 | |
7921925c JB |
1346 | return newval; |
1347 | } | |
1348 | \f | |
1349 | /* Access or set a buffer-local symbol's default value. */ | |
1350 | ||
d9c2a0f2 | 1351 | /* Return the default value of SYMBOL, but don't check for voidness. |
1bfcade3 | 1352 | Return Qunbound if it is void. */ |
7921925c JB |
1353 | |
1354 | Lisp_Object | |
d9c2a0f2 EN |
1355 | default_value (symbol) |
1356 | Lisp_Object symbol; | |
7921925c JB |
1357 | { |
1358 | register Lisp_Object valcontents; | |
1359 | ||
b7826503 | 1360 | CHECK_SYMBOL (symbol); |
f35d5bad | 1361 | valcontents = SYMBOL_VALUE (symbol); |
7921925c JB |
1362 | |
1363 | /* For a built-in buffer-local variable, get the default value | |
1364 | rather than letting do_symval_forwarding get the current value. */ | |
e9ebc175 | 1365 | if (BUFFER_OBJFWDP (valcontents)) |
7921925c | 1366 | { |
999b32fd | 1367 | int offset = XBUFFER_OBJFWD (valcontents)->offset; |
f6cd0527 GM |
1368 | if (PER_BUFFER_IDX (offset) != 0) |
1369 | return PER_BUFFER_DEFAULT (offset); | |
7921925c JB |
1370 | } |
1371 | ||
1372 | /* Handle user-created local variables. */ | |
e9ebc175 KH |
1373 | if (BUFFER_LOCAL_VALUEP (valcontents) |
1374 | || SOME_BUFFER_LOCAL_VALUEP (valcontents)) | |
7921925c JB |
1375 | { |
1376 | /* If var is set up for a buffer that lacks a local value for it, | |
1377 | the current value is nominally the default value. | |
42e975f0 | 1378 | But the `realvalue' slot may be more up to date, since |
7921925c JB |
1379 | ordinary setq stores just that slot. So use that. */ |
1380 | Lisp_Object current_alist_element, alist_element_car; | |
1381 | current_alist_element | |
7539e11f KR |
1382 | = XCAR (XBUFFER_LOCAL_VALUE (valcontents)->cdr); |
1383 | alist_element_car = XCAR (current_alist_element); | |
7921925c | 1384 | if (EQ (alist_element_car, current_alist_element)) |
b0c2d1c6 | 1385 | return do_symval_forwarding (XBUFFER_LOCAL_VALUE (valcontents)->realvalue); |
7921925c | 1386 | else |
7539e11f | 1387 | return XCDR (XBUFFER_LOCAL_VALUE (valcontents)->cdr); |
7921925c JB |
1388 | } |
1389 | /* For other variables, get the current value. */ | |
1390 | return do_symval_forwarding (valcontents); | |
1391 | } | |
1392 | ||
1393 | DEFUN ("default-boundp", Fdefault_boundp, Sdefault_boundp, 1, 1, 0, | |
8c1a1077 PJ |
1394 | doc: /* Return t if SYMBOL has a non-void default value. |
1395 | This is the value that is seen in buffers that do not have their own values | |
1396 | for this variable. */) | |
1397 | (symbol) | |
d9c2a0f2 | 1398 | Lisp_Object symbol; |
7921925c JB |
1399 | { |
1400 | register Lisp_Object value; | |
1401 | ||
d9c2a0f2 | 1402 | value = default_value (symbol); |
1bfcade3 | 1403 | return (EQ (value, Qunbound) ? Qnil : Qt); |
7921925c JB |
1404 | } |
1405 | ||
1406 | DEFUN ("default-value", Fdefault_value, Sdefault_value, 1, 1, 0, | |
8c1a1077 PJ |
1407 | doc: /* Return SYMBOL's default value. |
1408 | This is the value that is seen in buffers that do not have their own values | |
1409 | for this variable. The default value is meaningful for variables with | |
1410 | local bindings in certain buffers. */) | |
1411 | (symbol) | |
d9c2a0f2 | 1412 | Lisp_Object symbol; |
7921925c JB |
1413 | { |
1414 | register Lisp_Object value; | |
1415 | ||
d9c2a0f2 | 1416 | value = default_value (symbol); |
1bfcade3 | 1417 | if (EQ (value, Qunbound)) |
d9c2a0f2 | 1418 | return Fsignal (Qvoid_variable, Fcons (symbol, Qnil)); |
7921925c JB |
1419 | return value; |
1420 | } | |
1421 | ||
1422 | DEFUN ("set-default", Fset_default, Sset_default, 2, 2, 0, | |
6e86a75d | 1423 | doc: /* Set SYMBOL's default value to VALUE. SYMBOL and VALUE are evaluated. |
8c1a1077 PJ |
1424 | The default value is seen in buffers that do not have their own values |
1425 | for this variable. */) | |
1426 | (symbol, value) | |
d9c2a0f2 | 1427 | Lisp_Object symbol, value; |
7921925c JB |
1428 | { |
1429 | register Lisp_Object valcontents, current_alist_element, alist_element_buffer; | |
1430 | ||
b7826503 | 1431 | CHECK_SYMBOL (symbol); |
f35d5bad | 1432 | valcontents = SYMBOL_VALUE (symbol); |
7921925c JB |
1433 | |
1434 | /* Handle variables like case-fold-search that have special slots | |
1435 | in the buffer. Make them work apparently like Lisp_Buffer_Local_Value | |
1436 | variables. */ | |
e9ebc175 | 1437 | if (BUFFER_OBJFWDP (valcontents)) |
7921925c | 1438 | { |
999b32fd | 1439 | int offset = XBUFFER_OBJFWD (valcontents)->offset; |
f6cd0527 | 1440 | int idx = PER_BUFFER_IDX (offset); |
7921925c | 1441 | |
f6cd0527 | 1442 | PER_BUFFER_DEFAULT (offset) = value; |
984ef137 KH |
1443 | |
1444 | /* If this variable is not always local in all buffers, | |
1445 | set it in the buffers that don't nominally have a local value. */ | |
999b32fd | 1446 | if (idx > 0) |
7921925c | 1447 | { |
999b32fd | 1448 | struct buffer *b; |
bfb96cb7 | 1449 | |
7921925c | 1450 | for (b = all_buffers; b; b = b->next) |
f6cd0527 GM |
1451 | if (!PER_BUFFER_VALUE_P (b, idx)) |
1452 | PER_BUFFER_VALUE (b, offset) = value; | |
7921925c JB |
1453 | } |
1454 | return value; | |
1455 | } | |
1456 | ||
e9ebc175 KH |
1457 | if (!BUFFER_LOCAL_VALUEP (valcontents) |
1458 | && !SOME_BUFFER_LOCAL_VALUEP (valcontents)) | |
d9c2a0f2 | 1459 | return Fset (symbol, value); |
7921925c | 1460 | |
42e975f0 | 1461 | /* Store new value into the DEFAULT-VALUE slot. */ |
f3fbd155 | 1462 | XSETCDR (XBUFFER_LOCAL_VALUE (valcontents)->cdr, value); |
7921925c | 1463 | |
42e975f0 | 1464 | /* If the default binding is now loaded, set the REALVALUE slot too. */ |
8d4afcac | 1465 | current_alist_element |
7539e11f | 1466 | = XCAR (XBUFFER_LOCAL_VALUE (valcontents)->cdr); |
7921925c JB |
1467 | alist_element_buffer = Fcar (current_alist_element); |
1468 | if (EQ (alist_element_buffer, current_alist_element)) | |
7a283f36 GM |
1469 | store_symval_forwarding (symbol, |
1470 | XBUFFER_LOCAL_VALUE (valcontents)->realvalue, | |
1471 | value, NULL); | |
7921925c JB |
1472 | |
1473 | return value; | |
1474 | } | |
1475 | ||
7a7df7ac | 1476 | DEFUN ("setq-default", Fsetq_default, Ssetq_default, 0, UNEVALLED, 0, |
8c1a1077 PJ |
1477 | doc: /* Set the default value of variable VAR to VALUE. |
1478 | VAR, the variable name, is literal (not evaluated); | |
bfb96cb7 | 1479 | VALUE is an expression: it is evaluated and its value returned. |
8c1a1077 PJ |
1480 | The default value of a variable is seen in buffers |
1481 | that do not have their own values for the variable. | |
1482 | ||
1483 | More generally, you can use multiple variables and values, as in | |
948d2995 JB |
1484 | (setq-default VAR VALUE VAR VALUE...) |
1485 | This sets each VAR's default value to the corresponding VALUE. | |
1486 | The VALUE for the Nth VAR can refer to the new default values | |
1487 | of previous VARs. | |
7a7df7ac | 1488 | usage: (setq-default [VAR VALUE...]) */) |
8c1a1077 | 1489 | (args) |
7921925c JB |
1490 | Lisp_Object args; |
1491 | { | |
1492 | register Lisp_Object args_left; | |
d9c2a0f2 | 1493 | register Lisp_Object val, symbol; |
7921925c JB |
1494 | struct gcpro gcpro1; |
1495 | ||
a33ef3ab | 1496 | if (NILP (args)) |
7921925c JB |
1497 | return Qnil; |
1498 | ||
1499 | args_left = args; | |
1500 | GCPRO1 (args); | |
1501 | ||
1502 | do | |
1503 | { | |
1504 | val = Feval (Fcar (Fcdr (args_left))); | |
d2fde41d | 1505 | symbol = XCAR (args_left); |
d9c2a0f2 | 1506 | Fset_default (symbol, val); |
d2fde41d | 1507 | args_left = Fcdr (XCDR (args_left)); |
7921925c | 1508 | } |
a33ef3ab | 1509 | while (!NILP (args_left)); |
7921925c JB |
1510 | |
1511 | UNGCPRO; | |
1512 | return val; | |
1513 | } | |
1514 | \f | |
a5ca2b75 JB |
1515 | /* Lisp functions for creating and removing buffer-local variables. */ |
1516 | ||
7921925c | 1517 | DEFUN ("make-variable-buffer-local", Fmake_variable_buffer_local, Smake_variable_buffer_local, |
8c1a1077 PJ |
1518 | 1, 1, "vMake Variable Buffer Local: ", |
1519 | doc: /* Make VARIABLE become buffer-local whenever it is set. | |
1520 | At any time, the value for the current buffer is in effect, | |
1521 | unless the variable has never been set in this buffer, | |
1522 | in which case the default value is in effect. | |
1523 | Note that binding the variable with `let', or setting it while | |
1524 | a `let'-style binding made in this buffer is in effect, | |
bfb96cb7 | 1525 | does not make the variable buffer-local. Return VARIABLE. |
8c1a1077 | 1526 | |
a9908653 RS |
1527 | In most cases it is better to use `make-local-variable', |
1528 | which makes a variable local in just one buffer. | |
1529 | ||
8c1a1077 PJ |
1530 | The function `default-value' gets the default value and `set-default' sets it. */) |
1531 | (variable) | |
d9c2a0f2 | 1532 | register Lisp_Object variable; |
7921925c | 1533 | { |
8d4afcac | 1534 | register Lisp_Object tem, valcontents, newval; |
7921925c | 1535 | |
b7826503 | 1536 | CHECK_SYMBOL (variable); |
14970b45 | 1537 | variable = indirect_variable (variable); |
7921925c | 1538 | |
f35d5bad | 1539 | valcontents = SYMBOL_VALUE (variable); |
d9c2a0f2 | 1540 | if (EQ (variable, Qnil) || EQ (variable, Qt) || KBOARD_OBJFWDP (valcontents)) |
d5db4077 | 1541 | error ("Symbol %s may not be buffer-local", SDATA (SYMBOL_NAME (variable))); |
7921925c | 1542 | |
e9ebc175 | 1543 | if (BUFFER_LOCAL_VALUEP (valcontents) || BUFFER_OBJFWDP (valcontents)) |
d9c2a0f2 | 1544 | return variable; |
e9ebc175 | 1545 | if (SOME_BUFFER_LOCAL_VALUEP (valcontents)) |
7921925c | 1546 | { |
f35d5bad | 1547 | XMISCTYPE (SYMBOL_VALUE (variable)) = Lisp_Misc_Buffer_Local_Value; |
d9c2a0f2 | 1548 | return variable; |
7921925c JB |
1549 | } |
1550 | if (EQ (valcontents, Qunbound)) | |
f35d5bad | 1551 | SET_SYMBOL_VALUE (variable, Qnil); |
d9c2a0f2 | 1552 | tem = Fcons (Qnil, Fsymbol_value (variable)); |
f3fbd155 | 1553 | XSETCAR (tem, tem); |
8d4afcac | 1554 | newval = allocate_misc (); |
324a6eef | 1555 | XMISCTYPE (newval) = Lisp_Misc_Buffer_Local_Value; |
f35d5bad | 1556 | XBUFFER_LOCAL_VALUE (newval)->realvalue = SYMBOL_VALUE (variable); |
b0c2d1c6 RS |
1557 | XBUFFER_LOCAL_VALUE (newval)->buffer = Fcurrent_buffer (); |
1558 | XBUFFER_LOCAL_VALUE (newval)->frame = Qnil; | |
42e975f0 | 1559 | XBUFFER_LOCAL_VALUE (newval)->found_for_buffer = 0; |
b0c2d1c6 RS |
1560 | XBUFFER_LOCAL_VALUE (newval)->found_for_frame = 0; |
1561 | XBUFFER_LOCAL_VALUE (newval)->check_frame = 0; | |
1562 | XBUFFER_LOCAL_VALUE (newval)->cdr = tem; | |
f35d5bad | 1563 | SET_SYMBOL_VALUE (variable, newval); |
d9c2a0f2 | 1564 | return variable; |
7921925c JB |
1565 | } |
1566 | ||
1567 | DEFUN ("make-local-variable", Fmake_local_variable, Smake_local_variable, | |
8c1a1077 PJ |
1568 | 1, 1, "vMake Local Variable: ", |
1569 | doc: /* Make VARIABLE have a separate value in the current buffer. | |
1570 | Other buffers will continue to share a common default value. | |
1571 | \(The buffer-local value of VARIABLE starts out as the same value | |
1572 | VARIABLE previously had. If VARIABLE was void, it remains void.\) | |
a9908653 | 1573 | Return VARIABLE. |
8c1a1077 PJ |
1574 | |
1575 | If the variable is already arranged to become local when set, | |
1576 | this function causes a local value to exist for this buffer, | |
1577 | just as setting the variable would do. | |
1578 | ||
1579 | This function returns VARIABLE, and therefore | |
1580 | (set (make-local-variable 'VARIABLE) VALUE-EXP) | |
1581 | works. | |
1582 | ||
a9908653 RS |
1583 | See also `make-variable-buffer-local'. |
1584 | ||
8c1a1077 | 1585 | Do not use `make-local-variable' to make a hook variable buffer-local. |
515f3f25 | 1586 | Instead, use `add-hook' and specify t for the LOCAL argument. */) |
8c1a1077 | 1587 | (variable) |
d9c2a0f2 | 1588 | register Lisp_Object variable; |
7921925c JB |
1589 | { |
1590 | register Lisp_Object tem, valcontents; | |
1591 | ||
b7826503 | 1592 | CHECK_SYMBOL (variable); |
14970b45 | 1593 | variable = indirect_variable (variable); |
7921925c | 1594 | |
f35d5bad | 1595 | valcontents = SYMBOL_VALUE (variable); |
d9c2a0f2 | 1596 | if (EQ (variable, Qnil) || EQ (variable, Qt) || KBOARD_OBJFWDP (valcontents)) |
d5db4077 | 1597 | error ("Symbol %s may not be buffer-local", SDATA (SYMBOL_NAME (variable))); |
7921925c | 1598 | |
e9ebc175 | 1599 | if (BUFFER_LOCAL_VALUEP (valcontents) || BUFFER_OBJFWDP (valcontents)) |
7921925c | 1600 | { |
d9c2a0f2 | 1601 | tem = Fboundp (variable); |
7403b5c8 | 1602 | |
7921925c JB |
1603 | /* Make sure the symbol has a local value in this particular buffer, |
1604 | by setting it to the same value it already has. */ | |
d9c2a0f2 EN |
1605 | Fset (variable, (EQ (tem, Qt) ? Fsymbol_value (variable) : Qunbound)); |
1606 | return variable; | |
7921925c | 1607 | } |
42e975f0 | 1608 | /* Make sure symbol is set up to hold per-buffer values. */ |
e9ebc175 | 1609 | if (!SOME_BUFFER_LOCAL_VALUEP (valcontents)) |
7921925c | 1610 | { |
8d4afcac | 1611 | Lisp_Object newval; |
7921925c | 1612 | tem = Fcons (Qnil, do_symval_forwarding (valcontents)); |
f3fbd155 | 1613 | XSETCAR (tem, tem); |
8d4afcac | 1614 | newval = allocate_misc (); |
324a6eef | 1615 | XMISCTYPE (newval) = Lisp_Misc_Some_Buffer_Local_Value; |
f35d5bad | 1616 | XBUFFER_LOCAL_VALUE (newval)->realvalue = SYMBOL_VALUE (variable); |
b0c2d1c6 RS |
1617 | XBUFFER_LOCAL_VALUE (newval)->buffer = Qnil; |
1618 | XBUFFER_LOCAL_VALUE (newval)->frame = Qnil; | |
1619 | XBUFFER_LOCAL_VALUE (newval)->found_for_buffer = 0; | |
1620 | XBUFFER_LOCAL_VALUE (newval)->found_for_frame = 0; | |
1621 | XBUFFER_LOCAL_VALUE (newval)->check_frame = 0; | |
1622 | XBUFFER_LOCAL_VALUE (newval)->cdr = tem; | |
f35d5bad | 1623 | SET_SYMBOL_VALUE (variable, newval);; |
7921925c | 1624 | } |
42e975f0 | 1625 | /* Make sure this buffer has its own value of symbol. */ |
d9c2a0f2 | 1626 | tem = Fassq (variable, current_buffer->local_var_alist); |
a33ef3ab | 1627 | if (NILP (tem)) |
7921925c | 1628 | { |
a5d004a1 RS |
1629 | /* Swap out any local binding for some other buffer, and make |
1630 | sure the current value is permanently recorded, if it's the | |
1631 | default value. */ | |
d9c2a0f2 | 1632 | find_symbol_value (variable); |
a5d004a1 | 1633 | |
7921925c | 1634 | current_buffer->local_var_alist |
f35d5bad | 1635 | = Fcons (Fcons (variable, XCDR (XBUFFER_LOCAL_VALUE (SYMBOL_VALUE (variable))->cdr)), |
7921925c JB |
1636 | current_buffer->local_var_alist); |
1637 | ||
1638 | /* Make sure symbol does not think it is set up for this buffer; | |
42e975f0 | 1639 | force it to look once again for this buffer's value. */ |
7921925c | 1640 | { |
8d4afcac | 1641 | Lisp_Object *pvalbuf; |
a5d004a1 | 1642 | |
f35d5bad | 1643 | valcontents = SYMBOL_VALUE (variable); |
a5d004a1 | 1644 | |
b0c2d1c6 | 1645 | pvalbuf = &XBUFFER_LOCAL_VALUE (valcontents)->buffer; |
8d4afcac KH |
1646 | if (current_buffer == XBUFFER (*pvalbuf)) |
1647 | *pvalbuf = Qnil; | |
b0c2d1c6 | 1648 | XBUFFER_LOCAL_VALUE (valcontents)->found_for_buffer = 0; |
7921925c | 1649 | } |
7921925c | 1650 | } |
a5ca2b75 | 1651 | |
42e975f0 RS |
1652 | /* If the symbol forwards into a C variable, then load the binding |
1653 | for this buffer now. If C code modifies the variable before we | |
1654 | load the binding in, then that new value will clobber the default | |
1655 | binding the next time we unload it. */ | |
f35d5bad | 1656 | valcontents = XBUFFER_LOCAL_VALUE (SYMBOL_VALUE (variable))->realvalue; |
e9ebc175 | 1657 | if (INTFWDP (valcontents) || BOOLFWDP (valcontents) || OBJFWDP (valcontents)) |
f35d5bad | 1658 | swap_in_symval_forwarding (variable, SYMBOL_VALUE (variable)); |
a5ca2b75 | 1659 | |
d9c2a0f2 | 1660 | return variable; |
7921925c JB |
1661 | } |
1662 | ||
1663 | DEFUN ("kill-local-variable", Fkill_local_variable, Skill_local_variable, | |
8c1a1077 PJ |
1664 | 1, 1, "vKill Local Variable: ", |
1665 | doc: /* Make VARIABLE no longer have a separate value in the current buffer. | |
bfb96cb7 | 1666 | From now on the default value will apply in this buffer. Return VARIABLE. */) |
8c1a1077 | 1667 | (variable) |
d9c2a0f2 | 1668 | register Lisp_Object variable; |
7921925c JB |
1669 | { |
1670 | register Lisp_Object tem, valcontents; | |
1671 | ||
b7826503 | 1672 | CHECK_SYMBOL (variable); |
14970b45 | 1673 | variable = indirect_variable (variable); |
7921925c | 1674 | |
f35d5bad | 1675 | valcontents = SYMBOL_VALUE (variable); |
7921925c | 1676 | |
e9ebc175 | 1677 | if (BUFFER_OBJFWDP (valcontents)) |
7921925c | 1678 | { |
999b32fd | 1679 | int offset = XBUFFER_OBJFWD (valcontents)->offset; |
f6cd0527 | 1680 | int idx = PER_BUFFER_IDX (offset); |
7921925c | 1681 | |
999b32fd | 1682 | if (idx > 0) |
7921925c | 1683 | { |
f6cd0527 GM |
1684 | SET_PER_BUFFER_VALUE_P (current_buffer, idx, 0); |
1685 | PER_BUFFER_VALUE (current_buffer, offset) | |
1686 | = PER_BUFFER_DEFAULT (offset); | |
7921925c | 1687 | } |
d9c2a0f2 | 1688 | return variable; |
7921925c JB |
1689 | } |
1690 | ||
e9ebc175 KH |
1691 | if (!BUFFER_LOCAL_VALUEP (valcontents) |
1692 | && !SOME_BUFFER_LOCAL_VALUEP (valcontents)) | |
d9c2a0f2 | 1693 | return variable; |
7921925c | 1694 | |
42e975f0 | 1695 | /* Get rid of this buffer's alist element, if any. */ |
7921925c | 1696 | |
d9c2a0f2 | 1697 | tem = Fassq (variable, current_buffer->local_var_alist); |
a33ef3ab | 1698 | if (!NILP (tem)) |
8d4afcac KH |
1699 | current_buffer->local_var_alist |
1700 | = Fdelq (tem, current_buffer->local_var_alist); | |
7921925c | 1701 | |
42e975f0 RS |
1702 | /* If the symbol is set up with the current buffer's binding |
1703 | loaded, recompute its value. We have to do it now, or else | |
1704 | forwarded objects won't work right. */ | |
7921925c | 1705 | { |
999e6484 | 1706 | Lisp_Object *pvalbuf, buf; |
f35d5bad | 1707 | valcontents = SYMBOL_VALUE (variable); |
b0c2d1c6 | 1708 | pvalbuf = &XBUFFER_LOCAL_VALUE (valcontents)->buffer; |
999e6484 SM |
1709 | XSETBUFFER (buf, current_buffer); |
1710 | if (EQ (buf, *pvalbuf)) | |
79c83e03 KH |
1711 | { |
1712 | *pvalbuf = Qnil; | |
b0c2d1c6 | 1713 | XBUFFER_LOCAL_VALUE (valcontents)->found_for_buffer = 0; |
978dd578 | 1714 | find_symbol_value (variable); |
79c83e03 | 1715 | } |
7921925c JB |
1716 | } |
1717 | ||
d9c2a0f2 | 1718 | return variable; |
7921925c | 1719 | } |
62476adc | 1720 | |
b0c2d1c6 RS |
1721 | /* Lisp functions for creating and removing buffer-local variables. */ |
1722 | ||
1723 | DEFUN ("make-variable-frame-local", Fmake_variable_frame_local, Smake_variable_frame_local, | |
8c1a1077 PJ |
1724 | 1, 1, "vMake Variable Frame Local: ", |
1725 | doc: /* Enable VARIABLE to have frame-local bindings. | |
4d4d36b1 RS |
1726 | This does not create any frame-local bindings for VARIABLE, |
1727 | it just makes them possible. | |
1728 | ||
1729 | A frame-local binding is actually a frame parameter value. | |
1730 | If a frame F has a value for the frame parameter named VARIABLE, | |
1731 | that also acts as a frame-local binding for VARIABLE in F-- | |
1732 | provided this function has been called to enable VARIABLE | |
1733 | to have frame-local bindings at all. | |
1734 | ||
1735 | The only way to create a frame-local binding for VARIABLE in a frame | |
1736 | is to set the VARIABLE frame parameter of that frame. See | |
1737 | `modify-frame-parameters' for how to set frame parameters. | |
1738 | ||
1739 | Buffer-local bindings take precedence over frame-local bindings. */) | |
8c1a1077 | 1740 | (variable) |
b0c2d1c6 RS |
1741 | register Lisp_Object variable; |
1742 | { | |
1743 | register Lisp_Object tem, valcontents, newval; | |
1744 | ||
b7826503 | 1745 | CHECK_SYMBOL (variable); |
14970b45 | 1746 | variable = indirect_variable (variable); |
b0c2d1c6 | 1747 | |
f35d5bad | 1748 | valcontents = SYMBOL_VALUE (variable); |
b0c2d1c6 RS |
1749 | if (EQ (variable, Qnil) || EQ (variable, Qt) || KBOARD_OBJFWDP (valcontents) |
1750 | || BUFFER_OBJFWDP (valcontents)) | |
d5db4077 | 1751 | error ("Symbol %s may not be frame-local", SDATA (SYMBOL_NAME (variable))); |
b0c2d1c6 RS |
1752 | |
1753 | if (BUFFER_LOCAL_VALUEP (valcontents) | |
1754 | || SOME_BUFFER_LOCAL_VALUEP (valcontents)) | |
42e975f0 RS |
1755 | { |
1756 | XBUFFER_LOCAL_VALUE (valcontents)->check_frame = 1; | |
1757 | return variable; | |
1758 | } | |
b0c2d1c6 RS |
1759 | |
1760 | if (EQ (valcontents, Qunbound)) | |
f35d5bad | 1761 | SET_SYMBOL_VALUE (variable, Qnil); |
b0c2d1c6 | 1762 | tem = Fcons (Qnil, Fsymbol_value (variable)); |
f3fbd155 | 1763 | XSETCAR (tem, tem); |
b0c2d1c6 RS |
1764 | newval = allocate_misc (); |
1765 | XMISCTYPE (newval) = Lisp_Misc_Some_Buffer_Local_Value; | |
f35d5bad | 1766 | XBUFFER_LOCAL_VALUE (newval)->realvalue = SYMBOL_VALUE (variable); |
b0c2d1c6 RS |
1767 | XBUFFER_LOCAL_VALUE (newval)->buffer = Qnil; |
1768 | XBUFFER_LOCAL_VALUE (newval)->frame = Qnil; | |
1769 | XBUFFER_LOCAL_VALUE (newval)->found_for_buffer = 0; | |
1770 | XBUFFER_LOCAL_VALUE (newval)->found_for_frame = 0; | |
1771 | XBUFFER_LOCAL_VALUE (newval)->check_frame = 1; | |
1772 | XBUFFER_LOCAL_VALUE (newval)->cdr = tem; | |
f35d5bad | 1773 | SET_SYMBOL_VALUE (variable, newval); |
b0c2d1c6 RS |
1774 | return variable; |
1775 | } | |
1776 | ||
62476adc | 1777 | DEFUN ("local-variable-p", Flocal_variable_p, Slocal_variable_p, |
8c1a1077 PJ |
1778 | 1, 2, 0, |
1779 | doc: /* Non-nil if VARIABLE has a local binding in buffer BUFFER. | |
1780 | BUFFER defaults to the current buffer. */) | |
1781 | (variable, buffer) | |
d9c2a0f2 | 1782 | register Lisp_Object variable, buffer; |
62476adc RS |
1783 | { |
1784 | Lisp_Object valcontents; | |
c48ead86 KH |
1785 | register struct buffer *buf; |
1786 | ||
1787 | if (NILP (buffer)) | |
1788 | buf = current_buffer; | |
1789 | else | |
1790 | { | |
b7826503 | 1791 | CHECK_BUFFER (buffer); |
c48ead86 KH |
1792 | buf = XBUFFER (buffer); |
1793 | } | |
62476adc | 1794 | |
b7826503 | 1795 | CHECK_SYMBOL (variable); |
14970b45 | 1796 | variable = indirect_variable (variable); |
62476adc | 1797 | |
f35d5bad | 1798 | valcontents = SYMBOL_VALUE (variable); |
c48ead86 | 1799 | if (BUFFER_LOCAL_VALUEP (valcontents) |
1e5f16fa | 1800 | || SOME_BUFFER_LOCAL_VALUEP (valcontents)) |
c48ead86 KH |
1801 | { |
1802 | Lisp_Object tail, elt; | |
f35d5bad | 1803 | |
7539e11f | 1804 | for (tail = buf->local_var_alist; CONSP (tail); tail = XCDR (tail)) |
c48ead86 | 1805 | { |
7539e11f KR |
1806 | elt = XCAR (tail); |
1807 | if (EQ (variable, XCAR (elt))) | |
c48ead86 KH |
1808 | return Qt; |
1809 | } | |
1810 | } | |
1811 | if (BUFFER_OBJFWDP (valcontents)) | |
1812 | { | |
1813 | int offset = XBUFFER_OBJFWD (valcontents)->offset; | |
f6cd0527 GM |
1814 | int idx = PER_BUFFER_IDX (offset); |
1815 | if (idx == -1 || PER_BUFFER_VALUE_P (buf, idx)) | |
c48ead86 KH |
1816 | return Qt; |
1817 | } | |
1818 | return Qnil; | |
62476adc | 1819 | } |
f4f04cee RS |
1820 | |
1821 | DEFUN ("local-variable-if-set-p", Flocal_variable_if_set_p, Slocal_variable_if_set_p, | |
8c1a1077 | 1822 | 1, 2, 0, |
1dc5ba01 LT |
1823 | doc: /* Non-nil if VARIABLE will be local in buffer BUFFER when set there. |
1824 | More precisely, this means that setting the variable \(with `set' or`setq'), | |
1825 | while it does not have a `let'-style binding that was made in BUFFER, | |
1826 | will produce a buffer local binding. See Info node | |
1827 | `(elisp)Creating Buffer-Local'. | |
8c1a1077 PJ |
1828 | BUFFER defaults to the current buffer. */) |
1829 | (variable, buffer) | |
d9c2a0f2 | 1830 | register Lisp_Object variable, buffer; |
f4f04cee RS |
1831 | { |
1832 | Lisp_Object valcontents; | |
1833 | register struct buffer *buf; | |
1834 | ||
1835 | if (NILP (buffer)) | |
1836 | buf = current_buffer; | |
1837 | else | |
1838 | { | |
b7826503 | 1839 | CHECK_BUFFER (buffer); |
f4f04cee RS |
1840 | buf = XBUFFER (buffer); |
1841 | } | |
1842 | ||
b7826503 | 1843 | CHECK_SYMBOL (variable); |
14970b45 | 1844 | variable = indirect_variable (variable); |
f4f04cee | 1845 | |
f35d5bad | 1846 | valcontents = SYMBOL_VALUE (variable); |
f4f04cee RS |
1847 | |
1848 | /* This means that make-variable-buffer-local was done. */ | |
1849 | if (BUFFER_LOCAL_VALUEP (valcontents)) | |
1850 | return Qt; | |
1851 | /* All these slots become local if they are set. */ | |
1852 | if (BUFFER_OBJFWDP (valcontents)) | |
1853 | return Qt; | |
1854 | if (SOME_BUFFER_LOCAL_VALUEP (valcontents)) | |
1855 | { | |
1856 | Lisp_Object tail, elt; | |
7539e11f | 1857 | for (tail = buf->local_var_alist; CONSP (tail); tail = XCDR (tail)) |
f4f04cee | 1858 | { |
7539e11f KR |
1859 | elt = XCAR (tail); |
1860 | if (EQ (variable, XCAR (elt))) | |
f4f04cee RS |
1861 | return Qt; |
1862 | } | |
1863 | } | |
1864 | return Qnil; | |
1865 | } | |
0a2546d4 RS |
1866 | |
1867 | DEFUN ("variable-binding-locus", Fvariable_binding_locus, Svariable_binding_locus, | |
1868 | 1, 1, 0, | |
1869 | doc: /* Return a value indicating where VARIABLE's current binding comes from. | |
1870 | If the current binding is buffer-local, the value is the current buffer. | |
1871 | If the current binding is frame-local, the value is the selected frame. | |
1872 | If the current binding is global (the default), the value is nil. */) | |
1873 | (variable) | |
1874 | register Lisp_Object variable; | |
1875 | { | |
1876 | Lisp_Object valcontents; | |
1877 | ||
1878 | CHECK_SYMBOL (variable); | |
1879 | variable = indirect_variable (variable); | |
1880 | ||
1881 | /* Make sure the current binding is actually swapped in. */ | |
1882 | find_symbol_value (variable); | |
1883 | ||
1884 | valcontents = XSYMBOL (variable)->value; | |
1885 | ||
1886 | if (BUFFER_LOCAL_VALUEP (valcontents) | |
1887 | || SOME_BUFFER_LOCAL_VALUEP (valcontents) | |
1888 | || BUFFER_OBJFWDP (valcontents)) | |
1889 | { | |
1890 | /* For a local variable, record both the symbol and which | |
1891 | buffer's or frame's value we are saving. */ | |
1892 | if (!NILP (Flocal_variable_p (variable, Qnil))) | |
1893 | return Fcurrent_buffer (); | |
1894 | else if (!BUFFER_OBJFWDP (valcontents) | |
1895 | && XBUFFER_LOCAL_VALUE (valcontents)->found_for_frame) | |
1896 | return XBUFFER_LOCAL_VALUE (valcontents)->frame; | |
1897 | } | |
1898 | ||
1899 | return Qnil; | |
1900 | } | |
7921925c | 1901 | \f |
ffd56f97 JB |
1902 | /* Find the function at the end of a chain of symbol function indirections. */ |
1903 | ||
1904 | /* If OBJECT is a symbol, find the end of its function chain and | |
1905 | return the value found there. If OBJECT is not a symbol, just | |
1906 | return it. If there is a cycle in the function chain, signal a | |
1907 | cyclic-function-indirection error. | |
1908 | ||
1909 | This is like Findirect_function, except that it doesn't signal an | |
1910 | error if the chain ends up unbound. */ | |
1911 | Lisp_Object | |
a2932990 | 1912 | indirect_function (object) |
62476adc | 1913 | register Lisp_Object object; |
ffd56f97 | 1914 | { |
eb8c3be9 | 1915 | Lisp_Object tortoise, hare; |
ffd56f97 | 1916 | |
eb8c3be9 | 1917 | hare = tortoise = object; |
ffd56f97 JB |
1918 | |
1919 | for (;;) | |
1920 | { | |
e9ebc175 | 1921 | if (!SYMBOLP (hare) || EQ (hare, Qunbound)) |
ffd56f97 JB |
1922 | break; |
1923 | hare = XSYMBOL (hare)->function; | |
e9ebc175 | 1924 | if (!SYMBOLP (hare) || EQ (hare, Qunbound)) |
ffd56f97 JB |
1925 | break; |
1926 | hare = XSYMBOL (hare)->function; | |
1927 | ||
eb8c3be9 | 1928 | tortoise = XSYMBOL (tortoise)->function; |
ffd56f97 | 1929 | |
eb8c3be9 | 1930 | if (EQ (hare, tortoise)) |
ffd56f97 JB |
1931 | Fsignal (Qcyclic_function_indirection, Fcons (object, Qnil)); |
1932 | } | |
1933 | ||
1934 | return hare; | |
1935 | } | |
1936 | ||
a7f96a35 | 1937 | DEFUN ("indirect-function", Findirect_function, Sindirect_function, 1, 2, 0, |
8c1a1077 | 1938 | doc: /* Return the function at the end of OBJECT's function chain. |
0ddb0ae8 TTN |
1939 | If OBJECT is not a symbol, just return it. Otherwise, follow all |
1940 | function indirections to find the final function binding and return it. | |
1941 | If the final symbol in the chain is unbound, signal a void-function error. | |
1942 | Optional arg NOERROR non-nil means to return nil instead of signalling. | |
8c1a1077 PJ |
1943 | Signal a cyclic-function-indirection error if there is a loop in the |
1944 | function chain of symbols. */) | |
0ddb0ae8 | 1945 | (object, noerror) |
8c1a1077 | 1946 | register Lisp_Object object; |
0ddb0ae8 | 1947 | Lisp_Object noerror; |
ffd56f97 JB |
1948 | { |
1949 | Lisp_Object result; | |
1950 | ||
1951 | result = indirect_function (object); | |
1952 | ||
1953 | if (EQ (result, Qunbound)) | |
a7f96a35 KS |
1954 | return (NILP (noerror) |
1955 | ? Fsignal (Qvoid_function, Fcons (object, Qnil)) | |
1956 | : Qnil); | |
ffd56f97 JB |
1957 | return result; |
1958 | } | |
1959 | \f | |
7921925c JB |
1960 | /* Extract and set vector and string elements */ |
1961 | ||
1962 | DEFUN ("aref", Faref, Saref, 2, 2, 0, | |
8c1a1077 PJ |
1963 | doc: /* Return the element of ARRAY at index IDX. |
1964 | ARRAY may be a vector, a string, a char-table, a bool-vector, | |
1965 | or a byte-code object. IDX starts at 0. */) | |
1966 | (array, idx) | |
7921925c JB |
1967 | register Lisp_Object array; |
1968 | Lisp_Object idx; | |
1969 | { | |
1970 | register int idxval; | |
1971 | ||
b7826503 | 1972 | CHECK_NUMBER (idx); |
7921925c | 1973 | idxval = XINT (idx); |
e9ebc175 | 1974 | if (STRINGP (array)) |
7921925c | 1975 | { |
25638b07 RS |
1976 | int c, idxval_byte; |
1977 | ||
d5db4077 | 1978 | if (idxval < 0 || idxval >= SCHARS (array)) |
c24e4efe | 1979 | args_out_of_range (array, idx); |
25638b07 | 1980 | if (! STRING_MULTIBYTE (array)) |
d5db4077 | 1981 | return make_number ((unsigned char) SREF (array, idxval)); |
25638b07 RS |
1982 | idxval_byte = string_char_to_byte (array, idxval); |
1983 | ||
29f44a37 | 1984 | c = STRING_CHAR (SDATA (array) + idxval_byte, |
d5db4077 | 1985 | SBYTES (array) - idxval_byte); |
25638b07 | 1986 | return make_number (c); |
7921925c | 1987 | } |
4d276982 RS |
1988 | else if (BOOL_VECTOR_P (array)) |
1989 | { | |
1990 | int val; | |
4d276982 RS |
1991 | |
1992 | if (idxval < 0 || idxval >= XBOOL_VECTOR (array)->size) | |
1993 | args_out_of_range (array, idx); | |
1994 | ||
b9ed2177 AS |
1995 | val = (unsigned char) XBOOL_VECTOR (array)->data[idxval / BOOL_VECTOR_BITS_PER_CHAR]; |
1996 | return (val & (1 << (idxval % BOOL_VECTOR_BITS_PER_CHAR)) ? Qt : Qnil); | |
4d276982 RS |
1997 | } |
1998 | else if (CHAR_TABLE_P (array)) | |
1999 | { | |
2000 | Lisp_Object val; | |
2001 | ||
6bbd7a29 GM |
2002 | val = Qnil; |
2003 | ||
4d276982 RS |
2004 | if (idxval < 0) |
2005 | args_out_of_range (array, idx); | |
ab5c3f93 | 2006 | if (idxval < CHAR_TABLE_ORDINARY_SLOTS) |
8313c4e7 | 2007 | { |
256d566c KH |
2008 | if (! SINGLE_BYTE_CHAR_P (idxval)) |
2009 | args_out_of_range (array, idx); | |
39e16e51 | 2010 | /* For ASCII and 8-bit European characters, the element is |
3a6cf6bd | 2011 | stored in the top table. */ |
8313c4e7 | 2012 | val = XCHAR_TABLE (array)->contents[idxval]; |
256d566c KH |
2013 | if (NILP (val)) |
2014 | { | |
2015 | int default_slot | |
2016 | = (idxval < 0x80 ? CHAR_TABLE_DEFAULT_SLOT_ASCII | |
2017 | : idxval < 0xA0 ? CHAR_TABLE_DEFAULT_SLOT_8_BIT_CONTROL | |
2018 | : CHAR_TABLE_DEFAULT_SLOT_8_BIT_GRAPHIC); | |
2019 | val = XCHAR_TABLE (array)->contents[default_slot]; | |
2020 | } | |
8313c4e7 KH |
2021 | if (NILP (val)) |
2022 | val = XCHAR_TABLE (array)->defalt; | |
2023 | while (NILP (val)) /* Follow parents until we find some value. */ | |
2024 | { | |
2025 | array = XCHAR_TABLE (array)->parent; | |
2026 | if (NILP (array)) | |
2027 | return Qnil; | |
2028 | val = XCHAR_TABLE (array)->contents[idxval]; | |
2029 | if (NILP (val)) | |
2030 | val = XCHAR_TABLE (array)->defalt; | |
2031 | } | |
2032 | return val; | |
2033 | } | |
4d276982 RS |
2034 | else |
2035 | { | |
39e16e51 KH |
2036 | int code[4], i; |
2037 | Lisp_Object sub_table; | |
256d566c | 2038 | Lisp_Object current_default; |
8313c4e7 | 2039 | |
37309c9d | 2040 | SPLIT_CHAR (idxval, code[0], code[1], code[2]); |
e19c1eb4 KH |
2041 | if (code[1] < 32) code[1] = -1; |
2042 | else if (code[2] < 32) code[2] = -1; | |
2043 | ||
39e16e51 KH |
2044 | /* Here, the possible range of CODE[0] (== charset ID) is |
2045 | 128..MAX_CHARSET. Since the top level char table contains | |
2046 | data for multibyte characters after 256th element, we must | |
2047 | increment CODE[0] by 128 to get a correct index. */ | |
2048 | code[0] += 128; | |
2049 | code[3] = -1; /* anchor */ | |
4d276982 RS |
2050 | |
2051 | try_parent_char_table: | |
256d566c | 2052 | current_default = XCHAR_TABLE (array)->defalt; |
39e16e51 KH |
2053 | sub_table = array; |
2054 | for (i = 0; code[i] >= 0; i++) | |
4d276982 | 2055 | { |
39e16e51 KH |
2056 | val = XCHAR_TABLE (sub_table)->contents[code[i]]; |
2057 | if (SUB_CHAR_TABLE_P (val)) | |
256d566c KH |
2058 | { |
2059 | sub_table = val; | |
2060 | if (! NILP (XCHAR_TABLE (sub_table)->defalt)) | |
2061 | current_default = XCHAR_TABLE (sub_table)->defalt; | |
2062 | } | |
39e16e51 | 2063 | else |
8313c4e7 | 2064 | { |
39e16e51 | 2065 | if (NILP (val)) |
256d566c | 2066 | val = current_default; |
39e16e51 KH |
2067 | if (NILP (val)) |
2068 | { | |
2069 | array = XCHAR_TABLE (array)->parent; | |
2070 | if (!NILP (array)) | |
2071 | goto try_parent_char_table; | |
2072 | } | |
2073 | return val; | |
8313c4e7 | 2074 | } |
4d276982 | 2075 | } |
256d566c KH |
2076 | /* Reaching here means IDXVAL is a generic character in |
2077 | which each character or a group has independent value. | |
2078 | Essentially it's nonsense to get a value for such a | |
2079 | generic character, but for backward compatibility, we try | |
2080 | the default value and parent. */ | |
2081 | val = current_default; | |
8313c4e7 | 2082 | if (NILP (val)) |
4d276982 RS |
2083 | { |
2084 | array = XCHAR_TABLE (array)->parent; | |
39e16e51 KH |
2085 | if (!NILP (array)) |
2086 | goto try_parent_char_table; | |
4d276982 | 2087 | } |
4d276982 RS |
2088 | return val; |
2089 | } | |
4d276982 | 2090 | } |
7921925c | 2091 | else |
c24e4efe | 2092 | { |
6bbd7a29 | 2093 | int size = 0; |
7f358972 RS |
2094 | if (VECTORP (array)) |
2095 | size = XVECTOR (array)->size; | |
2096 | else if (COMPILEDP (array)) | |
2097 | size = XVECTOR (array)->size & PSEUDOVECTOR_SIZE_MASK; | |
2098 | else | |
2099 | wrong_type_argument (Qarrayp, array); | |
2100 | ||
2101 | if (idxval < 0 || idxval >= size) | |
c24e4efe KH |
2102 | args_out_of_range (array, idx); |
2103 | return XVECTOR (array)->contents[idxval]; | |
2104 | } | |
7921925c JB |
2105 | } |
2106 | ||
2107 | DEFUN ("aset", Faset, Saset, 3, 3, 0, | |
8c1a1077 | 2108 | doc: /* Store into the element of ARRAY at index IDX the value NEWELT. |
bfb96cb7 FP |
2109 | Return NEWELT. ARRAY may be a vector, a string, a char-table or a |
2110 | bool-vector. IDX starts at 0. */) | |
8c1a1077 | 2111 | (array, idx, newelt) |
7921925c JB |
2112 | register Lisp_Object array; |
2113 | Lisp_Object idx, newelt; | |
2114 | { | |
2115 | register int idxval; | |
2116 | ||
b7826503 | 2117 | CHECK_NUMBER (idx); |
7921925c | 2118 | idxval = XINT (idx); |
4d276982 RS |
2119 | if (!VECTORP (array) && !STRINGP (array) && !BOOL_VECTOR_P (array) |
2120 | && ! CHAR_TABLE_P (array)) | |
7921925c | 2121 | array = wrong_type_argument (Qarrayp, array); |
7921925c JB |
2122 | CHECK_IMPURE (array); |
2123 | ||
e9ebc175 | 2124 | if (VECTORP (array)) |
c24e4efe KH |
2125 | { |
2126 | if (idxval < 0 || idxval >= XVECTOR (array)->size) | |
2127 | args_out_of_range (array, idx); | |
2128 | XVECTOR (array)->contents[idxval] = newelt; | |
2129 | } | |
4d276982 RS |
2130 | else if (BOOL_VECTOR_P (array)) |
2131 | { | |
2132 | int val; | |
4d276982 RS |
2133 | |
2134 | if (idxval < 0 || idxval >= XBOOL_VECTOR (array)->size) | |
2135 | args_out_of_range (array, idx); | |
2136 | ||
b9ed2177 | 2137 | val = (unsigned char) XBOOL_VECTOR (array)->data[idxval / BOOL_VECTOR_BITS_PER_CHAR]; |
4d276982 RS |
2138 | |
2139 | if (! NILP (newelt)) | |
b9ed2177 | 2140 | val |= 1 << (idxval % BOOL_VECTOR_BITS_PER_CHAR); |
4d276982 | 2141 | else |
b9ed2177 AS |
2142 | val &= ~(1 << (idxval % BOOL_VECTOR_BITS_PER_CHAR)); |
2143 | XBOOL_VECTOR (array)->data[idxval / BOOL_VECTOR_BITS_PER_CHAR] = val; | |
4d276982 RS |
2144 | } |
2145 | else if (CHAR_TABLE_P (array)) | |
2146 | { | |
4d276982 RS |
2147 | if (idxval < 0) |
2148 | args_out_of_range (array, idx); | |
ab5c3f93 | 2149 | if (idxval < CHAR_TABLE_ORDINARY_SLOTS) |
256d566c KH |
2150 | { |
2151 | if (! SINGLE_BYTE_CHAR_P (idxval)) | |
2152 | args_out_of_range (array, idx); | |
2153 | XCHAR_TABLE (array)->contents[idxval] = newelt; | |
2154 | } | |
4d276982 RS |
2155 | else |
2156 | { | |
39e16e51 | 2157 | int code[4], i; |
8313c4e7 | 2158 | Lisp_Object val; |
4d276982 | 2159 | |
37309c9d | 2160 | SPLIT_CHAR (idxval, code[0], code[1], code[2]); |
e19c1eb4 KH |
2161 | if (code[1] < 32) code[1] = -1; |
2162 | else if (code[2] < 32) code[2] = -1; | |
2163 | ||
39e16e51 KH |
2164 | /* See the comment of the corresponding part in Faref. */ |
2165 | code[0] += 128; | |
2166 | code[3] = -1; /* anchor */ | |
2167 | for (i = 0; code[i + 1] >= 0; i++) | |
8313c4e7 | 2168 | { |
39e16e51 KH |
2169 | val = XCHAR_TABLE (array)->contents[code[i]]; |
2170 | if (SUB_CHAR_TABLE_P (val)) | |
8313c4e7 KH |
2171 | array = val; |
2172 | else | |
3c8fccc3 RS |
2173 | { |
2174 | Lisp_Object temp; | |
2175 | ||
2176 | /* VAL is a leaf. Create a sub char table with the | |
256d566c | 2177 | initial value VAL and look into it. */ |
3c8fccc3 | 2178 | |
256d566c | 2179 | temp = make_sub_char_table (val); |
3c8fccc3 RS |
2180 | XCHAR_TABLE (array)->contents[code[i]] = temp; |
2181 | array = temp; | |
2182 | } | |
8313c4e7 | 2183 | } |
39e16e51 | 2184 | XCHAR_TABLE (array)->contents[code[i]] = newelt; |
4d276982 | 2185 | } |
4d276982 | 2186 | } |
25638b07 RS |
2187 | else if (STRING_MULTIBYTE (array)) |
2188 | { | |
c6464167 | 2189 | int idxval_byte, prev_bytes, new_bytes, nbytes; |
3c9de1af | 2190 | unsigned char workbuf[MAX_MULTIBYTE_LENGTH], *p0 = workbuf, *p1; |
25638b07 | 2191 | |
d5db4077 | 2192 | if (idxval < 0 || idxval >= SCHARS (array)) |
25638b07 | 2193 | args_out_of_range (array, idx); |
b7826503 | 2194 | CHECK_NUMBER (newelt); |
25638b07 | 2195 | |
c6464167 MB |
2196 | nbytes = SBYTES (array); |
2197 | ||
25638b07 | 2198 | idxval_byte = string_char_to_byte (array, idxval); |
29f44a37 | 2199 | p1 = SDATA (array) + idxval_byte; |
3c9de1af KH |
2200 | PARSE_MULTIBYTE_SEQ (p1, nbytes - idxval_byte, prev_bytes); |
2201 | new_bytes = CHAR_STRING (XINT (newelt), p0); | |
2202 | if (prev_bytes != new_bytes) | |
2203 | { | |
2204 | /* We must relocate the string data. */ | |
d5db4077 | 2205 | int nchars = SCHARS (array); |
3c9de1af | 2206 | unsigned char *str; |
f1a87317 | 2207 | USE_SAFE_ALLOCA; |
3c9de1af | 2208 | |
f1a87317 | 2209 | SAFE_ALLOCA (str, unsigned char *, nbytes); |
d5db4077 | 2210 | bcopy (SDATA (array), str, nbytes); |
3c9de1af KH |
2211 | allocate_string_data (XSTRING (array), nchars, |
2212 | nbytes + new_bytes - prev_bytes); | |
d5db4077 KR |
2213 | bcopy (str, SDATA (array), idxval_byte); |
2214 | p1 = SDATA (array) + idxval_byte; | |
3c9de1af KH |
2215 | bcopy (str + idxval_byte + prev_bytes, p1 + new_bytes, |
2216 | nbytes - (idxval_byte + prev_bytes)); | |
233f3db6 | 2217 | SAFE_FREE (); |
3c9de1af KH |
2218 | clear_string_char_byte_cache (); |
2219 | } | |
2220 | while (new_bytes--) | |
2221 | *p1++ = *p0++; | |
25638b07 | 2222 | } |
7921925c JB |
2223 | else |
2224 | { | |
d5db4077 | 2225 | if (idxval < 0 || idxval >= SCHARS (array)) |
c24e4efe | 2226 | args_out_of_range (array, idx); |
b7826503 | 2227 | CHECK_NUMBER (newelt); |
3c9de1af KH |
2228 | |
2229 | if (XINT (newelt) < 0 || SINGLE_BYTE_CHAR_P (XINT (newelt))) | |
29f44a37 | 2230 | SSET (array, idxval, XINT (newelt)); |
3c9de1af KH |
2231 | else |
2232 | { | |
2233 | /* We must relocate the string data while converting it to | |
2234 | multibyte. */ | |
2235 | int idxval_byte, prev_bytes, new_bytes; | |
2236 | unsigned char workbuf[MAX_MULTIBYTE_LENGTH], *p0 = workbuf, *p1; | |
d5db4077 | 2237 | unsigned char *origstr = SDATA (array), *str; |
3c9de1af | 2238 | int nchars, nbytes; |
f1a87317 | 2239 | USE_SAFE_ALLOCA; |
3c9de1af | 2240 | |
d5db4077 | 2241 | nchars = SCHARS (array); |
3c9de1af KH |
2242 | nbytes = idxval_byte = count_size_as_multibyte (origstr, idxval); |
2243 | nbytes += count_size_as_multibyte (origstr + idxval, | |
2244 | nchars - idxval); | |
f1a87317 | 2245 | SAFE_ALLOCA (str, unsigned char *, nbytes); |
d5db4077 | 2246 | copy_text (SDATA (array), str, nchars, 0, 1); |
3c9de1af KH |
2247 | PARSE_MULTIBYTE_SEQ (str + idxval_byte, nbytes - idxval_byte, |
2248 | prev_bytes); | |
2249 | new_bytes = CHAR_STRING (XINT (newelt), p0); | |
2250 | allocate_string_data (XSTRING (array), nchars, | |
2251 | nbytes + new_bytes - prev_bytes); | |
d5db4077 KR |
2252 | bcopy (str, SDATA (array), idxval_byte); |
2253 | p1 = SDATA (array) + idxval_byte; | |
3c9de1af KH |
2254 | while (new_bytes--) |
2255 | *p1++ = *p0++; | |
2256 | bcopy (str + idxval_byte + prev_bytes, p1, | |
2257 | nbytes - (idxval_byte + prev_bytes)); | |
233f3db6 | 2258 | SAFE_FREE (); |
3c9de1af KH |
2259 | clear_string_char_byte_cache (); |
2260 | } | |
7921925c JB |
2261 | } |
2262 | ||
2263 | return newelt; | |
2264 | } | |
7921925c JB |
2265 | \f |
2266 | /* Arithmetic functions */ | |
2267 | ||
2268 | enum comparison { equal, notequal, less, grtr, less_or_equal, grtr_or_equal }; | |
2269 | ||
2270 | Lisp_Object | |
2271 | arithcompare (num1, num2, comparison) | |
2272 | Lisp_Object num1, num2; | |
2273 | enum comparison comparison; | |
2274 | { | |
6bbd7a29 | 2275 | double f1 = 0, f2 = 0; |
7921925c JB |
2276 | int floatp = 0; |
2277 | ||
b7826503 PJ |
2278 | CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (num1); |
2279 | CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (num2); | |
7921925c | 2280 | |
e9ebc175 | 2281 | if (FLOATP (num1) || FLOATP (num2)) |
7921925c JB |
2282 | { |
2283 | floatp = 1; | |
7539e11f KR |
2284 | f1 = (FLOATP (num1)) ? XFLOAT_DATA (num1) : XINT (num1); |
2285 | f2 = (FLOATP (num2)) ? XFLOAT_DATA (num2) : XINT (num2); | |
7921925c | 2286 | } |
7921925c JB |
2287 | |
2288 | switch (comparison) | |
2289 | { | |
2290 | case equal: | |
2291 | if (floatp ? f1 == f2 : XINT (num1) == XINT (num2)) | |
2292 | return Qt; | |
2293 | return Qnil; | |
2294 | ||
2295 | case notequal: | |
2296 | if (floatp ? f1 != f2 : XINT (num1) != XINT (num2)) | |
2297 | return Qt; | |
2298 | return Qnil; | |
2299 | ||
2300 | case less: | |
2301 | if (floatp ? f1 < f2 : XINT (num1) < XINT (num2)) | |
2302 | return Qt; | |
2303 | return Qnil; | |
2304 | ||
2305 | case less_or_equal: | |
2306 | if (floatp ? f1 <= f2 : XINT (num1) <= XINT (num2)) | |
2307 | return Qt; | |
2308 | return Qnil; | |
2309 | ||
2310 | case grtr: | |
2311 | if (floatp ? f1 > f2 : XINT (num1) > XINT (num2)) | |
2312 | return Qt; | |
2313 | return Qnil; | |
2314 | ||
2315 | case grtr_or_equal: | |
2316 | if (floatp ? f1 >= f2 : XINT (num1) >= XINT (num2)) | |
2317 | return Qt; | |
2318 | return Qnil; | |
25e40a4b JB |
2319 | |
2320 | default: | |
2321 | abort (); | |
7921925c JB |
2322 | } |
2323 | } | |
2324 | ||
2325 | DEFUN ("=", Feqlsign, Seqlsign, 2, 2, 0, | |
8c1a1077 PJ |
2326 | doc: /* Return t if two args, both numbers or markers, are equal. */) |
2327 | (num1, num2) | |
7921925c JB |
2328 | register Lisp_Object num1, num2; |
2329 | { | |
2330 | return arithcompare (num1, num2, equal); | |
2331 | } | |
2332 | ||
2333 | DEFUN ("<", Flss, Slss, 2, 2, 0, | |
8c1a1077 PJ |
2334 | doc: /* Return t if first arg is less than second arg. Both must be numbers or markers. */) |
2335 | (num1, num2) | |
7921925c JB |
2336 | register Lisp_Object num1, num2; |
2337 | { | |
2338 | return arithcompare (num1, num2, less); | |
2339 | } | |
2340 | ||
2341 | DEFUN (">", Fgtr, Sgtr, 2, 2, 0, | |
8c1a1077 PJ |
2342 | doc: /* Return t if first arg is greater than second arg. Both must be numbers or markers. */) |
2343 | (num1, num2) | |
7921925c JB |
2344 | register Lisp_Object num1, num2; |
2345 | { | |
2346 | return arithcompare (num1, num2, grtr); | |
2347 | } | |
2348 | ||
2349 | DEFUN ("<=", Fleq, Sleq, 2, 2, 0, | |
8c1a1077 PJ |
2350 | doc: /* Return t if first arg is less than or equal to second arg. |
2351 | Both must be numbers or markers. */) | |
2352 | (num1, num2) | |
7921925c JB |
2353 | register Lisp_Object num1, num2; |
2354 | { | |
2355 | return arithcompare (num1, num2, less_or_equal); | |
2356 | } | |
2357 | ||
2358 | DEFUN (">=", Fgeq, Sgeq, 2, 2, 0, | |
8c1a1077 PJ |
2359 | doc: /* Return t if first arg is greater than or equal to second arg. |
2360 | Both must be numbers or markers. */) | |
2361 | (num1, num2) | |
7921925c JB |
2362 | register Lisp_Object num1, num2; |
2363 | { | |
2364 | return arithcompare (num1, num2, grtr_or_equal); | |
2365 | } | |
2366 | ||
2367 | DEFUN ("/=", Fneq, Sneq, 2, 2, 0, | |
8c1a1077 PJ |
2368 | doc: /* Return t if first arg is not equal to second arg. Both must be numbers or markers. */) |
2369 | (num1, num2) | |
7921925c JB |
2370 | register Lisp_Object num1, num2; |
2371 | { | |
2372 | return arithcompare (num1, num2, notequal); | |
2373 | } | |
2374 | ||
8c1a1077 PJ |
2375 | DEFUN ("zerop", Fzerop, Szerop, 1, 1, 0, |
2376 | doc: /* Return t if NUMBER is zero. */) | |
2377 | (number) | |
d9c2a0f2 | 2378 | register Lisp_Object number; |
7921925c | 2379 | { |
b7826503 | 2380 | CHECK_NUMBER_OR_FLOAT (number); |
7921925c | 2381 | |
d9c2a0f2 | 2382 | if (FLOATP (number)) |
7921925c | 2383 | { |
7539e11f | 2384 | if (XFLOAT_DATA (number) == 0.0) |
7921925c JB |
2385 | return Qt; |
2386 | return Qnil; | |
2387 | } | |
7921925c | 2388 | |
d9c2a0f2 | 2389 | if (!XINT (number)) |
7921925c JB |
2390 | return Qt; |
2391 | return Qnil; | |
2392 | } | |
2393 | \f | |
34f4f6c6 | 2394 | /* Convert between long values and pairs of Lisp integers. */ |
51cf3e31 JB |
2395 | |
2396 | Lisp_Object | |
2397 | long_to_cons (i) | |
2398 | unsigned long i; | |
2399 | { | |
9bc7166b | 2400 | unsigned long top = i >> 16; |
51cf3e31 JB |
2401 | unsigned int bot = i & 0xFFFF; |
2402 | if (top == 0) | |
2403 | return make_number (bot); | |
b42cfa11 | 2404 | if (top == (unsigned long)-1 >> 16) |
51cf3e31 JB |
2405 | return Fcons (make_number (-1), make_number (bot)); |
2406 | return Fcons (make_number (top), make_number (bot)); | |
2407 | } | |
2408 | ||
2409 | unsigned long | |
2410 | cons_to_long (c) | |
2411 | Lisp_Object c; | |
2412 | { | |
878a80cc | 2413 | Lisp_Object top, bot; |
51cf3e31 JB |
2414 | if (INTEGERP (c)) |
2415 | return XINT (c); | |
7539e11f KR |
2416 | top = XCAR (c); |
2417 | bot = XCDR (c); | |
51cf3e31 | 2418 | if (CONSP (bot)) |
7539e11f | 2419 | bot = XCAR (bot); |
51cf3e31 JB |
2420 | return ((XINT (top) << 16) | XINT (bot)); |
2421 | } | |
2422 | \f | |
f2980264 | 2423 | DEFUN ("number-to-string", Fnumber_to_string, Snumber_to_string, 1, 1, 0, |
bfb96cb7 | 2424 | doc: /* Return the decimal representation of NUMBER as a string. |
8c1a1077 PJ |
2425 | Uses a minus sign if negative. |
2426 | NUMBER may be an integer or a floating point number. */) | |
2427 | (number) | |
d9c2a0f2 | 2428 | Lisp_Object number; |
7921925c | 2429 | { |
6030ce64 | 2430 | char buffer[VALBITS]; |
7921925c | 2431 | |
b7826503 | 2432 | CHECK_NUMBER_OR_FLOAT (number); |
7921925c | 2433 | |
d9c2a0f2 | 2434 | if (FLOATP (number)) |
7921925c JB |
2435 | { |
2436 | char pigbuf[350]; /* see comments in float_to_string */ | |
2437 | ||
7539e11f | 2438 | float_to_string (pigbuf, XFLOAT_DATA (number)); |
7403b5c8 | 2439 | return build_string (pigbuf); |
7921925c | 2440 | } |
7921925c | 2441 | |
e6c82a8d | 2442 | if (sizeof (int) == sizeof (EMACS_INT)) |
d9c2a0f2 | 2443 | sprintf (buffer, "%d", XINT (number)); |
e6c82a8d | 2444 | else if (sizeof (long) == sizeof (EMACS_INT)) |
dd8daec5 | 2445 | sprintf (buffer, "%ld", (long) XINT (number)); |
e6c82a8d RS |
2446 | else |
2447 | abort (); | |
7921925c JB |
2448 | return build_string (buffer); |
2449 | } | |
2450 | ||
3883fbeb RS |
2451 | INLINE static int |
2452 | digit_to_number (character, base) | |
2453 | int character, base; | |
2454 | { | |
2455 | int digit; | |
2456 | ||
2457 | if (character >= '0' && character <= '9') | |
2458 | digit = character - '0'; | |
2459 | else if (character >= 'a' && character <= 'z') | |
2460 | digit = character - 'a' + 10; | |
2461 | else if (character >= 'A' && character <= 'Z') | |
2462 | digit = character - 'A' + 10; | |
2463 | else | |
2464 | return -1; | |
2465 | ||
2466 | if (digit >= base) | |
2467 | return -1; | |
2468 | else | |
2469 | return digit; | |
bfb96cb7 | 2470 | } |
3883fbeb RS |
2471 | |
2472 | DEFUN ("string-to-number", Fstring_to_number, Sstring_to_number, 1, 2, 0, | |
558ee900 | 2473 | doc: /* Parse STRING as a decimal number and return the number. |
8c1a1077 PJ |
2474 | This parses both integers and floating point numbers. |
2475 | It ignores leading spaces and tabs. | |
2476 | ||
2477 | If BASE, interpret STRING as a number in that base. If BASE isn't | |
2478 | present, base 10 is used. BASE must be between 2 and 16 (inclusive). | |
2479 | If the base used is not 10, floating point is not recognized. */) | |
2480 | (string, base) | |
3883fbeb | 2481 | register Lisp_Object string, base; |
7921925c | 2482 | { |
3883fbeb | 2483 | register unsigned char *p; |
342858a5 GM |
2484 | register int b; |
2485 | int sign = 1; | |
2486 | Lisp_Object val; | |
25e40a4b | 2487 | |
b7826503 | 2488 | CHECK_STRING (string); |
7921925c | 2489 | |
3883fbeb RS |
2490 | if (NILP (base)) |
2491 | b = 10; | |
2492 | else | |
2493 | { | |
b7826503 | 2494 | CHECK_NUMBER (base); |
3883fbeb RS |
2495 | b = XINT (base); |
2496 | if (b < 2 || b > 16) | |
2497 | Fsignal (Qargs_out_of_range, Fcons (base, Qnil)); | |
2498 | } | |
2499 | ||
25e40a4b JB |
2500 | /* Skip any whitespace at the front of the number. Some versions of |
2501 | atoi do this anyway, so we might as well make Emacs lisp consistent. */ | |
d5db4077 | 2502 | p = SDATA (string); |
0a3e4d65 | 2503 | while (*p == ' ' || *p == '\t') |
25e40a4b JB |
2504 | p++; |
2505 | ||
3883fbeb RS |
2506 | if (*p == '-') |
2507 | { | |
342858a5 | 2508 | sign = -1; |
3883fbeb RS |
2509 | p++; |
2510 | } | |
2511 | else if (*p == '+') | |
2512 | p++; | |
bfb96cb7 | 2513 | |
8e36ae7f | 2514 | if (isfloat_string (p) && b == 10) |
342858a5 GM |
2515 | val = make_float (sign * atof (p)); |
2516 | else | |
3883fbeb | 2517 | { |
342858a5 GM |
2518 | double v = 0; |
2519 | ||
2520 | while (1) | |
2521 | { | |
2522 | int digit = digit_to_number (*p++, b); | |
2523 | if (digit < 0) | |
2524 | break; | |
2525 | v = v * b + digit; | |
2526 | } | |
2527 | ||
cb938d46 | 2528 | val = make_fixnum_or_float (sign * v); |
3883fbeb | 2529 | } |
342858a5 GM |
2530 | |
2531 | return val; | |
7921925c | 2532 | } |
3883fbeb | 2533 | |
7403b5c8 | 2534 | \f |
7921925c | 2535 | enum arithop |
7a283f36 GM |
2536 | { |
2537 | Aadd, | |
2538 | Asub, | |
2539 | Amult, | |
2540 | Adiv, | |
2541 | Alogand, | |
2542 | Alogior, | |
2543 | Alogxor, | |
2544 | Amax, | |
2545 | Amin | |
2546 | }; | |
2547 | ||
2548 | static Lisp_Object float_arith_driver P_ ((double, int, enum arithop, | |
2549 | int, Lisp_Object *)); | |
ad8d56b9 | 2550 | extern Lisp_Object fmod_float (); |
b06faa91 | 2551 | |
7921925c | 2552 | Lisp_Object |
87fbf902 | 2553 | arith_driver (code, nargs, args) |
7921925c JB |
2554 | enum arithop code; |
2555 | int nargs; | |
2556 | register Lisp_Object *args; | |
2557 | { | |
2558 | register Lisp_Object val; | |
2559 | register int argnum; | |
7a283f36 | 2560 | register EMACS_INT accum = 0; |
5260234d | 2561 | register EMACS_INT next; |
7921925c | 2562 | |
0220c518 | 2563 | switch (SWITCH_ENUM_CAST (code)) |
7921925c JB |
2564 | { |
2565 | case Alogior: | |
2566 | case Alogxor: | |
2567 | case Aadd: | |
2568 | case Asub: | |
7a283f36 GM |
2569 | accum = 0; |
2570 | break; | |
7921925c | 2571 | case Amult: |
7a283f36 GM |
2572 | accum = 1; |
2573 | break; | |
7921925c | 2574 | case Alogand: |
7a283f36 GM |
2575 | accum = -1; |
2576 | break; | |
2577 | default: | |
2578 | break; | |
7921925c JB |
2579 | } |
2580 | ||
2581 | for (argnum = 0; argnum < nargs; argnum++) | |
2582 | { | |
7a283f36 GM |
2583 | /* Using args[argnum] as argument to CHECK_NUMBER_... */ |
2584 | val = args[argnum]; | |
b7826503 | 2585 | CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (val); |
7921925c | 2586 | |
7a283f36 GM |
2587 | if (FLOATP (val)) |
2588 | return float_arith_driver ((double) accum, argnum, code, | |
2589 | nargs, args); | |
2590 | args[argnum] = val; | |
7921925c | 2591 | next = XINT (args[argnum]); |
0220c518 | 2592 | switch (SWITCH_ENUM_CAST (code)) |
7921925c | 2593 | { |
7a283f36 GM |
2594 | case Aadd: |
2595 | accum += next; | |
2596 | break; | |
7921925c | 2597 | case Asub: |
e64981da | 2598 | accum = argnum ? accum - next : nargs == 1 ? - next : next; |
7921925c | 2599 | break; |
7a283f36 GM |
2600 | case Amult: |
2601 | accum *= next; | |
2602 | break; | |
7921925c | 2603 | case Adiv: |
7a283f36 GM |
2604 | if (!argnum) |
2605 | accum = next; | |
87fbf902 RS |
2606 | else |
2607 | { | |
2608 | if (next == 0) | |
2609 | Fsignal (Qarith_error, Qnil); | |
2610 | accum /= next; | |
2611 | } | |
7921925c | 2612 | break; |
7a283f36 GM |
2613 | case Alogand: |
2614 | accum &= next; | |
2615 | break; | |
2616 | case Alogior: | |
2617 | accum |= next; | |
2618 | break; | |
2619 | case Alogxor: | |
2620 | accum ^= next; | |
2621 | break; | |
2622 | case Amax: | |
2623 | if (!argnum || next > accum) | |
2624 | accum = next; | |
2625 | break; | |
2626 | case Amin: | |
2627 | if (!argnum || next < accum) | |
2628 | accum = next; | |
2629 | break; | |
7921925c JB |
2630 | } |
2631 | } | |
2632 | ||
f187f1f7 | 2633 | XSETINT (val, accum); |
7921925c JB |
2634 | return val; |
2635 | } | |
2636 | ||
1a2f2d33 KH |
2637 | #undef isnan |
2638 | #define isnan(x) ((x) != (x)) | |
2639 | ||
7a283f36 | 2640 | static Lisp_Object |
7921925c JB |
2641 | float_arith_driver (accum, argnum, code, nargs, args) |
2642 | double accum; | |
2643 | register int argnum; | |
2644 | enum arithop code; | |
2645 | int nargs; | |
2646 | register Lisp_Object *args; | |
2647 | { | |
2648 | register Lisp_Object val; | |
2649 | double next; | |
7403b5c8 | 2650 | |
7921925c JB |
2651 | for (; argnum < nargs; argnum++) |
2652 | { | |
2653 | val = args[argnum]; /* using args[argnum] as argument to CHECK_NUMBER_... */ | |
b7826503 | 2654 | CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (val); |
7921925c | 2655 | |
e9ebc175 | 2656 | if (FLOATP (val)) |
7921925c | 2657 | { |
7539e11f | 2658 | next = XFLOAT_DATA (val); |
7921925c JB |
2659 | } |
2660 | else | |
2661 | { | |
2662 | args[argnum] = val; /* runs into a compiler bug. */ | |
2663 | next = XINT (args[argnum]); | |
2664 | } | |
0220c518 | 2665 | switch (SWITCH_ENUM_CAST (code)) |
7921925c JB |
2666 | { |
2667 | case Aadd: | |
2668 | accum += next; | |
2669 | break; | |
2670 | case Asub: | |
e64981da | 2671 | accum = argnum ? accum - next : nargs == 1 ? - next : next; |
7921925c JB |
2672 | break; |
2673 | case Amult: | |
2674 | accum *= next; | |
2675 | break; | |
2676 | case Adiv: | |
2677 | if (!argnum) | |
2678 | accum = next; | |
2679 | else | |
87fbf902 | 2680 | { |
ad8d56b9 | 2681 | if (! IEEE_FLOATING_POINT && next == 0) |
87fbf902 RS |
2682 | Fsignal (Qarith_error, Qnil); |
2683 | accum /= next; | |
2684 | } | |
7921925c JB |
2685 | break; |
2686 | case Alogand: | |
2687 | case Alogior: | |
2688 | case Alogxor: | |
2689 | return wrong_type_argument (Qinteger_or_marker_p, val); | |
2690 | case Amax: | |
1a2f2d33 | 2691 | if (!argnum || isnan (next) || next > accum) |
7921925c JB |
2692 | accum = next; |
2693 | break; | |
2694 | case Amin: | |
1a2f2d33 | 2695 | if (!argnum || isnan (next) || next < accum) |
7921925c JB |
2696 | accum = next; |
2697 | break; | |
2698 | } | |
2699 | } | |
2700 | ||
2701 | return make_float (accum); | |
2702 | } | |
cc94f3b2 | 2703 | |
7921925c JB |
2704 | |
2705 | DEFUN ("+", Fplus, Splus, 0, MANY, 0, | |
8c1a1077 PJ |
2706 | doc: /* Return sum of any number of arguments, which are numbers or markers. |
2707 | usage: (+ &rest NUMBERS-OR-MARKERS) */) | |
2708 | (nargs, args) | |
7921925c JB |
2709 | int nargs; |
2710 | Lisp_Object *args; | |
2711 | { | |
2712 | return arith_driver (Aadd, nargs, args); | |
2713 | } | |
2714 | ||
2715 | DEFUN ("-", Fminus, Sminus, 0, MANY, 0, | |
558ee900 | 2716 | doc: /* Negate number or subtract numbers or markers and return the result. |
8c1a1077 | 2717 | With one arg, negates it. With more than one arg, |
f44fba9e | 2718 | subtracts all but the first from the first. |
8c1a1077 PJ |
2719 | usage: (- &optional NUMBER-OR-MARKER &rest MORE-NUMBERS-OR-MARKERS) */) |
2720 | (nargs, args) | |
7921925c JB |
2721 | int nargs; |
2722 | Lisp_Object *args; | |
2723 | { | |
2724 | return arith_driver (Asub, nargs, args); | |
2725 | } | |
2726 | ||
2727 | DEFUN ("*", Ftimes, Stimes, 0, MANY, 0, | |
be24eadf | 2728 | doc: /* Return product of any number of arguments, which are numbers or markers. |
8c1a1077 PJ |
2729 | usage: (* &rest NUMBERS-OR-MARKERS) */) |
2730 | (nargs, args) | |
7921925c JB |
2731 | int nargs; |
2732 | Lisp_Object *args; | |
2733 | { | |
2734 | return arith_driver (Amult, nargs, args); | |
2735 | } | |
2736 | ||
2737 | DEFUN ("/", Fquo, Squo, 2, MANY, 0, | |
be24eadf | 2738 | doc: /* Return first argument divided by all the remaining arguments. |
f44fba9e | 2739 | The arguments must be numbers or markers. |
8c1a1077 PJ |
2740 | usage: (/ DIVIDEND DIVISOR &rest DIVISORS) */) |
2741 | (nargs, args) | |
7921925c JB |
2742 | int nargs; |
2743 | Lisp_Object *args; | |
2744 | { | |
28712a21 | 2745 | int argnum; |
7ef98053 | 2746 | for (argnum = 2; argnum < nargs; argnum++) |
28712a21 JB |
2747 | if (FLOATP (args[argnum])) |
2748 | return float_arith_driver (0, 0, Adiv, nargs, args); | |
7921925c JB |
2749 | return arith_driver (Adiv, nargs, args); |
2750 | } | |
2751 | ||
2752 | DEFUN ("%", Frem, Srem, 2, 2, 0, | |
be24eadf | 2753 | doc: /* Return remainder of X divided by Y. |
8c1a1077 PJ |
2754 | Both must be integers or markers. */) |
2755 | (x, y) | |
d9c2a0f2 | 2756 | register Lisp_Object x, y; |
7921925c JB |
2757 | { |
2758 | Lisp_Object val; | |
2759 | ||
b7826503 PJ |
2760 | CHECK_NUMBER_COERCE_MARKER (x); |
2761 | CHECK_NUMBER_COERCE_MARKER (y); | |
7921925c | 2762 | |
d9c2a0f2 | 2763 | if (XFASTINT (y) == 0) |
87fbf902 RS |
2764 | Fsignal (Qarith_error, Qnil); |
2765 | ||
d9c2a0f2 | 2766 | XSETINT (val, XINT (x) % XINT (y)); |
7921925c JB |
2767 | return val; |
2768 | } | |
2769 | ||
1d66a5fa KH |
2770 | #ifndef HAVE_FMOD |
2771 | double | |
2772 | fmod (f1, f2) | |
2773 | double f1, f2; | |
2774 | { | |
bc1c9d7e PE |
2775 | double r = f1; |
2776 | ||
fa43b1e8 KH |
2777 | if (f2 < 0.0) |
2778 | f2 = -f2; | |
bc1c9d7e PE |
2779 | |
2780 | /* If the magnitude of the result exceeds that of the divisor, or | |
2781 | the sign of the result does not agree with that of the dividend, | |
2782 | iterate with the reduced value. This does not yield a | |
2783 | particularly accurate result, but at least it will be in the | |
2784 | range promised by fmod. */ | |
2785 | do | |
2786 | r -= f2 * floor (r / f2); | |
2787 | while (f2 <= (r < 0 ? -r : r) || ((r < 0) != (f1 < 0) && ! isnan (r))); | |
2788 | ||
2789 | return r; | |
1d66a5fa KH |
2790 | } |
2791 | #endif /* ! HAVE_FMOD */ | |
2792 | ||
44fa9da5 | 2793 | DEFUN ("mod", Fmod, Smod, 2, 2, 0, |
be24eadf | 2794 | doc: /* Return X modulo Y. |
8c1a1077 PJ |
2795 | The result falls between zero (inclusive) and Y (exclusive). |
2796 | Both X and Y must be numbers or markers. */) | |
2797 | (x, y) | |
d9c2a0f2 | 2798 | register Lisp_Object x, y; |
44fa9da5 PE |
2799 | { |
2800 | Lisp_Object val; | |
5260234d | 2801 | EMACS_INT i1, i2; |
44fa9da5 | 2802 | |
b7826503 PJ |
2803 | CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (x); |
2804 | CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (y); | |
44fa9da5 | 2805 | |
d9c2a0f2 | 2806 | if (FLOATP (x) || FLOATP (y)) |
ad8d56b9 PE |
2807 | return fmod_float (x, y); |
2808 | ||
d9c2a0f2 EN |
2809 | i1 = XINT (x); |
2810 | i2 = XINT (y); | |
44fa9da5 PE |
2811 | |
2812 | if (i2 == 0) | |
2813 | Fsignal (Qarith_error, Qnil); | |
7403b5c8 | 2814 | |
44fa9da5 PE |
2815 | i1 %= i2; |
2816 | ||
2817 | /* If the "remainder" comes out with the wrong sign, fix it. */ | |
04f7ec69 | 2818 | if (i2 < 0 ? i1 > 0 : i1 < 0) |
44fa9da5 PE |
2819 | i1 += i2; |
2820 | ||
f187f1f7 | 2821 | XSETINT (val, i1); |
44fa9da5 PE |
2822 | return val; |
2823 | } | |
2824 | ||
7921925c | 2825 | DEFUN ("max", Fmax, Smax, 1, MANY, 0, |
8c1a1077 | 2826 | doc: /* Return largest of all the arguments (which must be numbers or markers). |
f44fba9e | 2827 | The value is always a number; markers are converted to numbers. |
8c1a1077 PJ |
2828 | usage: (max NUMBER-OR-MARKER &rest NUMBERS-OR-MARKERS) */) |
2829 | (nargs, args) | |
7921925c JB |
2830 | int nargs; |
2831 | Lisp_Object *args; | |
2832 | { | |
2833 | return arith_driver (Amax, nargs, args); | |
2834 | } | |
2835 | ||
2836 | DEFUN ("min", Fmin, Smin, 1, MANY, 0, | |
8c1a1077 | 2837 | doc: /* Return smallest of all the arguments (which must be numbers or markers). |
f44fba9e | 2838 | The value is always a number; markers are converted to numbers. |
8c1a1077 PJ |
2839 | usage: (min NUMBER-OR-MARKER &rest NUMBERS-OR-MARKERS) */) |
2840 | (nargs, args) | |
7921925c JB |
2841 | int nargs; |
2842 | Lisp_Object *args; | |
2843 | { | |
2844 | return arith_driver (Amin, nargs, args); | |
2845 | } | |
2846 | ||
2847 | DEFUN ("logand", Flogand, Slogand, 0, MANY, 0, | |
8c1a1077 | 2848 | doc: /* Return bitwise-and of all the arguments. |
f44fba9e | 2849 | Arguments may be integers, or markers converted to integers. |
8c1a1077 PJ |
2850 | usage: (logand &rest INTS-OR-MARKERS) */) |
2851 | (nargs, args) | |
7921925c JB |
2852 | int nargs; |
2853 | Lisp_Object *args; | |
2854 | { | |
2855 | return arith_driver (Alogand, nargs, args); | |
2856 | } | |
2857 | ||
2858 | DEFUN ("logior", Flogior, Slogior, 0, MANY, 0, | |
8c1a1077 | 2859 | doc: /* Return bitwise-or of all the arguments. |
f44fba9e | 2860 | Arguments may be integers, or markers converted to integers. |
8c1a1077 PJ |
2861 | usage: (logior &rest INTS-OR-MARKERS) */) |
2862 | (nargs, args) | |
7921925c JB |
2863 | int nargs; |
2864 | Lisp_Object *args; | |
2865 | { | |
2866 | return arith_driver (Alogior, nargs, args); | |
2867 | } | |
2868 | ||
2869 | DEFUN ("logxor", Flogxor, Slogxor, 0, MANY, 0, | |
8c1a1077 | 2870 | doc: /* Return bitwise-exclusive-or of all the arguments. |
f44fba9e | 2871 | Arguments may be integers, or markers converted to integers. |
8c1a1077 PJ |
2872 | usage: (logxor &rest INTS-OR-MARKERS) */) |
2873 | (nargs, args) | |
7921925c JB |
2874 | int nargs; |
2875 | Lisp_Object *args; | |
2876 | { | |
2877 | return arith_driver (Alogxor, nargs, args); | |
2878 | } | |
2879 | ||
2880 | DEFUN ("ash", Fash, Sash, 2, 2, 0, | |
8c1a1077 PJ |
2881 | doc: /* Return VALUE with its bits shifted left by COUNT. |
2882 | If COUNT is negative, shifting is actually to the right. | |
2883 | In this case, the sign bit is duplicated. */) | |
2884 | (value, count) | |
3b9f7964 | 2885 | register Lisp_Object value, count; |
7921925c JB |
2886 | { |
2887 | register Lisp_Object val; | |
2888 | ||
b7826503 PJ |
2889 | CHECK_NUMBER (value); |
2890 | CHECK_NUMBER (count); | |
7921925c | 2891 | |
81d70626 RS |
2892 | if (XINT (count) >= BITS_PER_EMACS_INT) |
2893 | XSETINT (val, 0); | |
2894 | else if (XINT (count) > 0) | |
3d9652eb | 2895 | XSETINT (val, XINT (value) << XFASTINT (count)); |
81d70626 RS |
2896 | else if (XINT (count) <= -BITS_PER_EMACS_INT) |
2897 | XSETINT (val, XINT (value) < 0 ? -1 : 0); | |
7921925c | 2898 | else |
3d9652eb | 2899 | XSETINT (val, XINT (value) >> -XINT (count)); |
7921925c JB |
2900 | return val; |
2901 | } | |
2902 | ||
2903 | DEFUN ("lsh", Flsh, Slsh, 2, 2, 0, | |
8c1a1077 PJ |
2904 | doc: /* Return VALUE with its bits shifted left by COUNT. |
2905 | If COUNT is negative, shifting is actually to the right. | |
3a9b1297 | 2906 | In this case, zeros are shifted in on the left. */) |
8c1a1077 | 2907 | (value, count) |
3d9652eb | 2908 | register Lisp_Object value, count; |
7921925c JB |
2909 | { |
2910 | register Lisp_Object val; | |
2911 | ||
b7826503 PJ |
2912 | CHECK_NUMBER (value); |
2913 | CHECK_NUMBER (count); | |
7921925c | 2914 | |
81d70626 RS |
2915 | if (XINT (count) >= BITS_PER_EMACS_INT) |
2916 | XSETINT (val, 0); | |
2917 | else if (XINT (count) > 0) | |
3d9652eb | 2918 | XSETINT (val, (EMACS_UINT) XUINT (value) << XFASTINT (count)); |
81d70626 RS |
2919 | else if (XINT (count) <= -BITS_PER_EMACS_INT) |
2920 | XSETINT (val, 0); | |
7921925c | 2921 | else |
3d9652eb | 2922 | XSETINT (val, (EMACS_UINT) XUINT (value) >> -XINT (count)); |
7921925c JB |
2923 | return val; |
2924 | } | |
2925 | ||
2926 | DEFUN ("1+", Fadd1, Sadd1, 1, 1, 0, | |
8c1a1077 PJ |
2927 | doc: /* Return NUMBER plus one. NUMBER may be a number or a marker. |
2928 | Markers are converted to integers. */) | |
2929 | (number) | |
d9c2a0f2 | 2930 | register Lisp_Object number; |
7921925c | 2931 | { |
b7826503 | 2932 | CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (number); |
7921925c | 2933 | |
d9c2a0f2 | 2934 | if (FLOATP (number)) |
7539e11f | 2935 | return (make_float (1.0 + XFLOAT_DATA (number))); |
7921925c | 2936 | |
d9c2a0f2 EN |
2937 | XSETINT (number, XINT (number) + 1); |
2938 | return number; | |
7921925c JB |
2939 | } |
2940 | ||
2941 | DEFUN ("1-", Fsub1, Ssub1, 1, 1, 0, | |
8c1a1077 PJ |
2942 | doc: /* Return NUMBER minus one. NUMBER may be a number or a marker. |
2943 | Markers are converted to integers. */) | |
2944 | (number) | |
d9c2a0f2 | 2945 | register Lisp_Object number; |
7921925c | 2946 | { |
b7826503 | 2947 | CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (number); |
7921925c | 2948 | |
d9c2a0f2 | 2949 | if (FLOATP (number)) |
7539e11f | 2950 | return (make_float (-1.0 + XFLOAT_DATA (number))); |
7921925c | 2951 | |
d9c2a0f2 EN |
2952 | XSETINT (number, XINT (number) - 1); |
2953 | return number; | |
7921925c JB |
2954 | } |
2955 | ||
2956 | DEFUN ("lognot", Flognot, Slognot, 1, 1, 0, | |
8c1a1077 PJ |
2957 | doc: /* Return the bitwise complement of NUMBER. NUMBER must be an integer. */) |
2958 | (number) | |
d9c2a0f2 | 2959 | register Lisp_Object number; |
7921925c | 2960 | { |
b7826503 | 2961 | CHECK_NUMBER (number); |
53924017 | 2962 | XSETINT (number, ~XINT (number)); |
d9c2a0f2 | 2963 | return number; |
7921925c | 2964 | } |
d4be0d31 JD |
2965 | |
2966 | DEFUN ("byteorder", Fbyteorder, Sbyteorder, 0, 0, 0, | |
2967 | doc: /* Return the byteorder for the machine. | |
2968 | Returns 66 (ASCII uppercase B) for big endian machines or 108 (ASCII | |
2969 | lowercase l) for small endian machines. */) | |
2970 | () | |
2971 | { | |
2972 | unsigned i = 0x04030201; | |
7a8560d7 | 2973 | int order = *(char *)&i == 1 ? 108 : 66; |
d4be0d31 | 2974 | |
d2f14999 | 2975 | return make_number (order); |
d4be0d31 JD |
2976 | } |
2977 | ||
2978 | ||
7921925c JB |
2979 | \f |
2980 | void | |
2981 | syms_of_data () | |
2982 | { | |
6315e761 RS |
2983 | Lisp_Object error_tail, arith_tail; |
2984 | ||
7921925c JB |
2985 | Qquote = intern ("quote"); |
2986 | Qlambda = intern ("lambda"); | |
2987 | Qsubr = intern ("subr"); | |
2988 | Qerror_conditions = intern ("error-conditions"); | |
2989 | Qerror_message = intern ("error-message"); | |
2990 | Qtop_level = intern ("top-level"); | |
2991 | ||
2992 | Qerror = intern ("error"); | |
2993 | Qquit = intern ("quit"); | |
2994 | Qwrong_type_argument = intern ("wrong-type-argument"); | |
2995 | Qargs_out_of_range = intern ("args-out-of-range"); | |
2996 | Qvoid_function = intern ("void-function"); | |
ffd56f97 | 2997 | Qcyclic_function_indirection = intern ("cyclic-function-indirection"); |
f35d5bad | 2998 | Qcyclic_variable_indirection = intern ("cyclic-variable-indirection"); |
7921925c JB |
2999 | Qvoid_variable = intern ("void-variable"); |
3000 | Qsetting_constant = intern ("setting-constant"); | |
3001 | Qinvalid_read_syntax = intern ("invalid-read-syntax"); | |
3002 | ||
3003 | Qinvalid_function = intern ("invalid-function"); | |
3004 | Qwrong_number_of_arguments = intern ("wrong-number-of-arguments"); | |
3005 | Qno_catch = intern ("no-catch"); | |
3006 | Qend_of_file = intern ("end-of-file"); | |
3007 | Qarith_error = intern ("arith-error"); | |
3008 | Qbeginning_of_buffer = intern ("beginning-of-buffer"); | |
3009 | Qend_of_buffer = intern ("end-of-buffer"); | |
3010 | Qbuffer_read_only = intern ("buffer-read-only"); | |
8f9f49d7 | 3011 | Qtext_read_only = intern ("text-read-only"); |
3b8819d6 | 3012 | Qmark_inactive = intern ("mark-inactive"); |
7921925c JB |
3013 | |
3014 | Qlistp = intern ("listp"); | |
3015 | Qconsp = intern ("consp"); | |
3016 | Qsymbolp = intern ("symbolp"); | |
cda9b832 | 3017 | Qkeywordp = intern ("keywordp"); |
7921925c JB |
3018 | Qintegerp = intern ("integerp"); |
3019 | Qnatnump = intern ("natnump"); | |
8e86942b | 3020 | Qwholenump = intern ("wholenump"); |
7921925c JB |
3021 | Qstringp = intern ("stringp"); |
3022 | Qarrayp = intern ("arrayp"); | |
3023 | Qsequencep = intern ("sequencep"); | |
3024 | Qbufferp = intern ("bufferp"); | |
3025 | Qvectorp = intern ("vectorp"); | |
3026 | Qchar_or_string_p = intern ("char-or-string-p"); | |
3027 | Qmarkerp = intern ("markerp"); | |
07bd8472 | 3028 | Qbuffer_or_string_p = intern ("buffer-or-string-p"); |
7921925c JB |
3029 | Qinteger_or_marker_p = intern ("integer-or-marker-p"); |
3030 | Qboundp = intern ("boundp"); | |
3031 | Qfboundp = intern ("fboundp"); | |
3032 | ||
7921925c JB |
3033 | Qfloatp = intern ("floatp"); |
3034 | Qnumberp = intern ("numberp"); | |
3035 | Qnumber_or_marker_p = intern ("number-or-marker-p"); | |
7921925c | 3036 | |
4d276982 | 3037 | Qchar_table_p = intern ("char-table-p"); |
7f0edce7 | 3038 | Qvector_or_char_table_p = intern ("vector-or-char-table-p"); |
4d276982 | 3039 | |
6f0e897f DL |
3040 | Qsubrp = intern ("subrp"); |
3041 | Qunevalled = intern ("unevalled"); | |
3042 | Qmany = intern ("many"); | |
3043 | ||
7921925c JB |
3044 | Qcdr = intern ("cdr"); |
3045 | ||
f845f2c9 | 3046 | /* Handle automatic advice activation */ |
ab297811 | 3047 | Qad_advice_info = intern ("ad-advice-info"); |
c1307a23 | 3048 | Qad_activate_internal = intern ("ad-activate-internal"); |
f845f2c9 | 3049 | |
6315e761 RS |
3050 | error_tail = Fcons (Qerror, Qnil); |
3051 | ||
7921925c JB |
3052 | /* ERROR is used as a signaler for random errors for which nothing else is right */ |
3053 | ||
3054 | Fput (Qerror, Qerror_conditions, | |
6315e761 | 3055 | error_tail); |
7921925c JB |
3056 | Fput (Qerror, Qerror_message, |
3057 | build_string ("error")); | |
3058 | ||
3059 | Fput (Qquit, Qerror_conditions, | |
3060 | Fcons (Qquit, Qnil)); | |
3061 | Fput (Qquit, Qerror_message, | |
3062 | build_string ("Quit")); | |
3063 | ||
3064 | Fput (Qwrong_type_argument, Qerror_conditions, | |
6315e761 | 3065 | Fcons (Qwrong_type_argument, error_tail)); |
7921925c JB |
3066 | Fput (Qwrong_type_argument, Qerror_message, |
3067 | build_string ("Wrong type argument")); | |
3068 | ||
3069 | Fput (Qargs_out_of_range, Qerror_conditions, | |
6315e761 | 3070 | Fcons (Qargs_out_of_range, error_tail)); |
7921925c JB |
3071 | Fput (Qargs_out_of_range, Qerror_message, |
3072 | build_string ("Args out of range")); | |
3073 | ||
3074 | Fput (Qvoid_function, Qerror_conditions, | |
6315e761 | 3075 | Fcons (Qvoid_function, error_tail)); |
7921925c JB |
3076 | Fput (Qvoid_function, Qerror_message, |
3077 | build_string ("Symbol's function definition is void")); | |
3078 | ||
ffd56f97 | 3079 | Fput (Qcyclic_function_indirection, Qerror_conditions, |
6315e761 | 3080 | Fcons (Qcyclic_function_indirection, error_tail)); |
ffd56f97 JB |
3081 | Fput (Qcyclic_function_indirection, Qerror_message, |
3082 | build_string ("Symbol's chain of function indirections contains a loop")); | |
3083 | ||
f35d5bad GM |
3084 | Fput (Qcyclic_variable_indirection, Qerror_conditions, |
3085 | Fcons (Qcyclic_variable_indirection, error_tail)); | |
3086 | Fput (Qcyclic_variable_indirection, Qerror_message, | |
3087 | build_string ("Symbol's chain of variable indirections contains a loop")); | |
3088 | ||
13d95cc0 GM |
3089 | Qcircular_list = intern ("circular-list"); |
3090 | staticpro (&Qcircular_list); | |
3091 | Fput (Qcircular_list, Qerror_conditions, | |
3092 | Fcons (Qcircular_list, error_tail)); | |
3093 | Fput (Qcircular_list, Qerror_message, | |
3094 | build_string ("List contains a loop")); | |
3095 | ||
7921925c | 3096 | Fput (Qvoid_variable, Qerror_conditions, |
6315e761 | 3097 | Fcons (Qvoid_variable, error_tail)); |
7921925c JB |
3098 | Fput (Qvoid_variable, Qerror_message, |
3099 | build_string ("Symbol's value as variable is void")); | |
3100 | ||
3101 | Fput (Qsetting_constant, Qerror_conditions, | |
6315e761 | 3102 | Fcons (Qsetting_constant, error_tail)); |
7921925c JB |
3103 | Fput (Qsetting_constant, Qerror_message, |
3104 | build_string ("Attempt to set a constant symbol")); | |
3105 | ||
3106 | Fput (Qinvalid_read_syntax, Qerror_conditions, | |
6315e761 | 3107 | Fcons (Qinvalid_read_syntax, error_tail)); |
7921925c JB |
3108 | Fput (Qinvalid_read_syntax, Qerror_message, |
3109 | build_string ("Invalid read syntax")); | |
3110 | ||
3111 | Fput (Qinvalid_function, Qerror_conditions, | |
6315e761 | 3112 | Fcons (Qinvalid_function, error_tail)); |
7921925c JB |
3113 | Fput (Qinvalid_function, Qerror_message, |
3114 | build_string ("Invalid function")); | |
3115 | ||
3116 | Fput (Qwrong_number_of_arguments, Qerror_conditions, | |
6315e761 | 3117 | Fcons (Qwrong_number_of_arguments, error_tail)); |
7921925c JB |
3118 | Fput (Qwrong_number_of_arguments, Qerror_message, |
3119 | build_string ("Wrong number of arguments")); | |
3120 | ||
3121 | Fput (Qno_catch, Qerror_conditions, | |
6315e761 | 3122 | Fcons (Qno_catch, error_tail)); |
7921925c JB |
3123 | Fput (Qno_catch, Qerror_message, |
3124 | build_string ("No catch for tag")); | |
3125 | ||
3126 | Fput (Qend_of_file, Qerror_conditions, | |
6315e761 | 3127 | Fcons (Qend_of_file, error_tail)); |
7921925c JB |
3128 | Fput (Qend_of_file, Qerror_message, |
3129 | build_string ("End of file during parsing")); | |
3130 | ||
6315e761 | 3131 | arith_tail = Fcons (Qarith_error, error_tail); |
7921925c | 3132 | Fput (Qarith_error, Qerror_conditions, |
6315e761 | 3133 | arith_tail); |
7921925c JB |
3134 | Fput (Qarith_error, Qerror_message, |
3135 | build_string ("Arithmetic error")); | |
3136 | ||
3137 | Fput (Qbeginning_of_buffer, Qerror_conditions, | |
6315e761 | 3138 | Fcons (Qbeginning_of_buffer, error_tail)); |
7921925c JB |
3139 | Fput (Qbeginning_of_buffer, Qerror_message, |
3140 | build_string ("Beginning of buffer")); | |
3141 | ||
3142 | Fput (Qend_of_buffer, Qerror_conditions, | |
6315e761 | 3143 | Fcons (Qend_of_buffer, error_tail)); |
7921925c JB |
3144 | Fput (Qend_of_buffer, Qerror_message, |
3145 | build_string ("End of buffer")); | |
3146 | ||
3147 | Fput (Qbuffer_read_only, Qerror_conditions, | |
6315e761 | 3148 | Fcons (Qbuffer_read_only, error_tail)); |
7921925c JB |
3149 | Fput (Qbuffer_read_only, Qerror_message, |
3150 | build_string ("Buffer is read-only")); | |
3151 | ||
8f9f49d7 GM |
3152 | Fput (Qtext_read_only, Qerror_conditions, |
3153 | Fcons (Qtext_read_only, error_tail)); | |
3154 | Fput (Qtext_read_only, Qerror_message, | |
3155 | build_string ("Text is read-only")); | |
3156 | ||
6315e761 RS |
3157 | Qrange_error = intern ("range-error"); |
3158 | Qdomain_error = intern ("domain-error"); | |
3159 | Qsingularity_error = intern ("singularity-error"); | |
3160 | Qoverflow_error = intern ("overflow-error"); | |
3161 | Qunderflow_error = intern ("underflow-error"); | |
3162 | ||
3163 | Fput (Qdomain_error, Qerror_conditions, | |
3164 | Fcons (Qdomain_error, arith_tail)); | |
3165 | Fput (Qdomain_error, Qerror_message, | |
3166 | build_string ("Arithmetic domain error")); | |
3167 | ||
3168 | Fput (Qrange_error, Qerror_conditions, | |
3169 | Fcons (Qrange_error, arith_tail)); | |
3170 | Fput (Qrange_error, Qerror_message, | |
3171 | build_string ("Arithmetic range error")); | |
3172 | ||
3173 | Fput (Qsingularity_error, Qerror_conditions, | |
3174 | Fcons (Qsingularity_error, Fcons (Qdomain_error, arith_tail))); | |
3175 | Fput (Qsingularity_error, Qerror_message, | |
3176 | build_string ("Arithmetic singularity error")); | |
3177 | ||
3178 | Fput (Qoverflow_error, Qerror_conditions, | |
3179 | Fcons (Qoverflow_error, Fcons (Qdomain_error, arith_tail))); | |
3180 | Fput (Qoverflow_error, Qerror_message, | |
3181 | build_string ("Arithmetic overflow error")); | |
3182 | ||
3183 | Fput (Qunderflow_error, Qerror_conditions, | |
3184 | Fcons (Qunderflow_error, Fcons (Qdomain_error, arith_tail))); | |
3185 | Fput (Qunderflow_error, Qerror_message, | |
3186 | build_string ("Arithmetic underflow error")); | |
3187 | ||
3188 | staticpro (&Qrange_error); | |
3189 | staticpro (&Qdomain_error); | |
3190 | staticpro (&Qsingularity_error); | |
3191 | staticpro (&Qoverflow_error); | |
3192 | staticpro (&Qunderflow_error); | |
6315e761 | 3193 | |
7921925c JB |
3194 | staticpro (&Qnil); |
3195 | staticpro (&Qt); | |
3196 | staticpro (&Qquote); | |
3197 | staticpro (&Qlambda); | |
3198 | staticpro (&Qsubr); | |
3199 | staticpro (&Qunbound); | |
3200 | staticpro (&Qerror_conditions); | |
3201 | staticpro (&Qerror_message); | |
3202 | staticpro (&Qtop_level); | |
3203 | ||
3204 | staticpro (&Qerror); | |
3205 | staticpro (&Qquit); | |
3206 | staticpro (&Qwrong_type_argument); | |
3207 | staticpro (&Qargs_out_of_range); | |
3208 | staticpro (&Qvoid_function); | |
ffd56f97 | 3209 | staticpro (&Qcyclic_function_indirection); |
dfad0b34 | 3210 | staticpro (&Qcyclic_variable_indirection); |
7921925c JB |
3211 | staticpro (&Qvoid_variable); |
3212 | staticpro (&Qsetting_constant); | |
3213 | staticpro (&Qinvalid_read_syntax); | |
3214 | staticpro (&Qwrong_number_of_arguments); | |
3215 | staticpro (&Qinvalid_function); | |
3216 | staticpro (&Qno_catch); | |
3217 | staticpro (&Qend_of_file); | |
3218 | staticpro (&Qarith_error); | |
3219 | staticpro (&Qbeginning_of_buffer); | |
3220 | staticpro (&Qend_of_buffer); | |
3221 | staticpro (&Qbuffer_read_only); | |
8f9f49d7 | 3222 | staticpro (&Qtext_read_only); |
638b77e6 | 3223 | staticpro (&Qmark_inactive); |
7921925c JB |
3224 | |
3225 | staticpro (&Qlistp); | |
3226 | staticpro (&Qconsp); | |
3227 | staticpro (&Qsymbolp); | |
cda9b832 | 3228 | staticpro (&Qkeywordp); |
7921925c JB |
3229 | staticpro (&Qintegerp); |
3230 | staticpro (&Qnatnump); | |
8e86942b | 3231 | staticpro (&Qwholenump); |
7921925c JB |
3232 | staticpro (&Qstringp); |
3233 | staticpro (&Qarrayp); | |
3234 | staticpro (&Qsequencep); | |
3235 | staticpro (&Qbufferp); | |
3236 | staticpro (&Qvectorp); | |
3237 | staticpro (&Qchar_or_string_p); | |
3238 | staticpro (&Qmarkerp); | |
07bd8472 | 3239 | staticpro (&Qbuffer_or_string_p); |
7921925c | 3240 | staticpro (&Qinteger_or_marker_p); |
7921925c | 3241 | staticpro (&Qfloatp); |
464f8898 RS |
3242 | staticpro (&Qnumberp); |
3243 | staticpro (&Qnumber_or_marker_p); | |
4d276982 | 3244 | staticpro (&Qchar_table_p); |
7f0edce7 | 3245 | staticpro (&Qvector_or_char_table_p); |
6f0e897f DL |
3246 | staticpro (&Qsubrp); |
3247 | staticpro (&Qmany); | |
3248 | staticpro (&Qunevalled); | |
7921925c JB |
3249 | |
3250 | staticpro (&Qboundp); | |
3251 | staticpro (&Qfboundp); | |
3252 | staticpro (&Qcdr); | |
ab297811 | 3253 | staticpro (&Qad_advice_info); |
c1307a23 | 3254 | staticpro (&Qad_activate_internal); |
7921925c | 3255 | |
39bcc759 RS |
3256 | /* Types that type-of returns. */ |
3257 | Qinteger = intern ("integer"); | |
3258 | Qsymbol = intern ("symbol"); | |
3259 | Qstring = intern ("string"); | |
3260 | Qcons = intern ("cons"); | |
3261 | Qmarker = intern ("marker"); | |
3262 | Qoverlay = intern ("overlay"); | |
3263 | Qfloat = intern ("float"); | |
3264 | Qwindow_configuration = intern ("window-configuration"); | |
3265 | Qprocess = intern ("process"); | |
3266 | Qwindow = intern ("window"); | |
3267 | /* Qsubr = intern ("subr"); */ | |
3268 | Qcompiled_function = intern ("compiled-function"); | |
3269 | Qbuffer = intern ("buffer"); | |
3270 | Qframe = intern ("frame"); | |
3271 | Qvector = intern ("vector"); | |
fc67d5be KH |
3272 | Qchar_table = intern ("char-table"); |
3273 | Qbool_vector = intern ("bool-vector"); | |
81dc5de5 | 3274 | Qhash_table = intern ("hash-table"); |
39bcc759 RS |
3275 | |
3276 | staticpro (&Qinteger); | |
3277 | staticpro (&Qsymbol); | |
3278 | staticpro (&Qstring); | |
3279 | staticpro (&Qcons); | |
3280 | staticpro (&Qmarker); | |
3281 | staticpro (&Qoverlay); | |
3282 | staticpro (&Qfloat); | |
3283 | staticpro (&Qwindow_configuration); | |
3284 | staticpro (&Qprocess); | |
3285 | staticpro (&Qwindow); | |
3286 | /* staticpro (&Qsubr); */ | |
3287 | staticpro (&Qcompiled_function); | |
3288 | staticpro (&Qbuffer); | |
3289 | staticpro (&Qframe); | |
3290 | staticpro (&Qvector); | |
fc67d5be KH |
3291 | staticpro (&Qchar_table); |
3292 | staticpro (&Qbool_vector); | |
81dc5de5 | 3293 | staticpro (&Qhash_table); |
39bcc759 | 3294 | |
f35d5bad | 3295 | defsubr (&Sindirect_variable); |
f52a3ca3 | 3296 | defsubr (&Sinteractive_form); |
7921925c JB |
3297 | defsubr (&Seq); |
3298 | defsubr (&Snull); | |
39bcc759 | 3299 | defsubr (&Stype_of); |
7921925c JB |
3300 | defsubr (&Slistp); |
3301 | defsubr (&Snlistp); | |
3302 | defsubr (&Sconsp); | |
3303 | defsubr (&Satom); | |
3304 | defsubr (&Sintegerp); | |
464f8898 | 3305 | defsubr (&Sinteger_or_marker_p); |
7921925c JB |
3306 | defsubr (&Snumberp); |
3307 | defsubr (&Snumber_or_marker_p); | |
464f8898 | 3308 | defsubr (&Sfloatp); |
7921925c JB |
3309 | defsubr (&Snatnump); |
3310 | defsubr (&Ssymbolp); | |
cda9b832 | 3311 | defsubr (&Skeywordp); |
7921925c | 3312 | defsubr (&Sstringp); |
0f56470d | 3313 | defsubr (&Smultibyte_string_p); |
7921925c | 3314 | defsubr (&Svectorp); |
4d276982 | 3315 | defsubr (&Schar_table_p); |
7f0edce7 | 3316 | defsubr (&Svector_or_char_table_p); |
4d276982 | 3317 | defsubr (&Sbool_vector_p); |
7921925c JB |
3318 | defsubr (&Sarrayp); |
3319 | defsubr (&Ssequencep); | |
3320 | defsubr (&Sbufferp); | |
3321 | defsubr (&Smarkerp); | |
7921925c | 3322 | defsubr (&Ssubrp); |
dbc4e1c1 | 3323 | defsubr (&Sbyte_code_function_p); |
7921925c JB |
3324 | defsubr (&Schar_or_string_p); |
3325 | defsubr (&Scar); | |
3326 | defsubr (&Scdr); | |
3327 | defsubr (&Scar_safe); | |
3328 | defsubr (&Scdr_safe); | |
3329 | defsubr (&Ssetcar); | |
3330 | defsubr (&Ssetcdr); | |
3331 | defsubr (&Ssymbol_function); | |
ffd56f97 | 3332 | defsubr (&Sindirect_function); |
7921925c JB |
3333 | defsubr (&Ssymbol_plist); |
3334 | defsubr (&Ssymbol_name); | |
3335 | defsubr (&Smakunbound); | |
3336 | defsubr (&Sfmakunbound); | |
3337 | defsubr (&Sboundp); | |
3338 | defsubr (&Sfboundp); | |
3339 | defsubr (&Sfset); | |
80df38a2 | 3340 | defsubr (&Sdefalias); |
7921925c JB |
3341 | defsubr (&Ssetplist); |
3342 | defsubr (&Ssymbol_value); | |
3343 | defsubr (&Sset); | |
3344 | defsubr (&Sdefault_boundp); | |
3345 | defsubr (&Sdefault_value); | |
3346 | defsubr (&Sset_default); | |
3347 | defsubr (&Ssetq_default); | |
3348 | defsubr (&Smake_variable_buffer_local); | |
3349 | defsubr (&Smake_local_variable); | |
3350 | defsubr (&Skill_local_variable); | |
b0c2d1c6 | 3351 | defsubr (&Smake_variable_frame_local); |
62476adc | 3352 | defsubr (&Slocal_variable_p); |
f4f04cee | 3353 | defsubr (&Slocal_variable_if_set_p); |
0a2546d4 | 3354 | defsubr (&Svariable_binding_locus); |
7921925c JB |
3355 | defsubr (&Saref); |
3356 | defsubr (&Saset); | |
f2980264 | 3357 | defsubr (&Snumber_to_string); |
25e40a4b | 3358 | defsubr (&Sstring_to_number); |
7921925c JB |
3359 | defsubr (&Seqlsign); |
3360 | defsubr (&Slss); | |
3361 | defsubr (&Sgtr); | |
3362 | defsubr (&Sleq); | |
3363 | defsubr (&Sgeq); | |
3364 | defsubr (&Sneq); | |
3365 | defsubr (&Szerop); | |
3366 | defsubr (&Splus); | |
3367 | defsubr (&Sminus); | |
3368 | defsubr (&Stimes); | |
3369 | defsubr (&Squo); | |
3370 | defsubr (&Srem); | |
44fa9da5 | 3371 | defsubr (&Smod); |
7921925c JB |
3372 | defsubr (&Smax); |
3373 | defsubr (&Smin); | |
3374 | defsubr (&Slogand); | |
3375 | defsubr (&Slogior); | |
3376 | defsubr (&Slogxor); | |
3377 | defsubr (&Slsh); | |
3378 | defsubr (&Sash); | |
3379 | defsubr (&Sadd1); | |
3380 | defsubr (&Ssub1); | |
3381 | defsubr (&Slognot); | |
d4be0d31 | 3382 | defsubr (&Sbyteorder); |
6f0e897f | 3383 | defsubr (&Ssubr_arity); |
0fddae66 | 3384 | defsubr (&Ssubr_name); |
8e86942b | 3385 | |
c80bd143 | 3386 | XSYMBOL (Qwholenump)->function = XSYMBOL (Qnatnump)->function; |
e6190b11 | 3387 | |
9d113d9d AS |
3388 | DEFVAR_LISP ("most-positive-fixnum", &Vmost_positive_fixnum, |
3389 | doc: /* The largest value that is representable in a Lisp integer. */); | |
3390 | Vmost_positive_fixnum = make_number (MOST_POSITIVE_FIXNUM); | |
bfb96cb7 | 3391 | |
9d113d9d AS |
3392 | DEFVAR_LISP ("most-negative-fixnum", &Vmost_negative_fixnum, |
3393 | doc: /* The smallest value that is representable in a Lisp integer. */); | |
3394 | Vmost_negative_fixnum = make_number (MOST_NEGATIVE_FIXNUM); | |
7921925c JB |
3395 | } |
3396 | ||
a33ef3ab | 3397 | SIGTYPE |
7921925c JB |
3398 | arith_error (signo) |
3399 | int signo; | |
3400 | { | |
fe42a920 | 3401 | #if defined(USG) && !defined(POSIX_SIGNALS) |
7921925c JB |
3402 | /* USG systems forget handlers when they are used; |
3403 | must reestablish each time */ | |
3404 | signal (signo, arith_error); | |
3405 | #endif /* USG */ | |
3406 | #ifdef VMS | |
3407 | /* VMS systems are like USG. */ | |
3408 | signal (signo, arith_error); | |
3409 | #endif /* VMS */ | |
3410 | #ifdef BSD4_1 | |
3411 | sigrelse (SIGFPE); | |
3412 | #else /* not BSD4_1 */ | |
e065a56e | 3413 | sigsetmask (SIGEMPTYMASK); |
7921925c JB |
3414 | #endif /* not BSD4_1 */ |
3415 | ||
333f1b6f | 3416 | SIGNAL_THREAD_CHECK (signo); |
7921925c JB |
3417 | Fsignal (Qarith_error, Qnil); |
3418 | } | |
3419 | ||
dfcf069d | 3420 | void |
7921925c JB |
3421 | init_data () |
3422 | { | |
3423 | /* Don't do this if just dumping out. | |
3424 | We don't want to call `signal' in this case | |
3425 | so that we don't have trouble with dumping | |
3426 | signal-delivering routines in an inconsistent state. */ | |
3427 | #ifndef CANNOT_DUMP | |
3428 | if (!initialized) | |
3429 | return; | |
3430 | #endif /* CANNOT_DUMP */ | |
3431 | signal (SIGFPE, arith_error); | |
7403b5c8 | 3432 | |
7921925c JB |
3433 | #ifdef uts |
3434 | signal (SIGEMT, arith_error); | |
3435 | #endif /* uts */ | |
3436 | } | |
ab5796a9 MB |
3437 | |
3438 | /* arch-tag: 25879798-b84d-479a-9c89-7d148e2109f7 | |
3439 | (do not change this comment) */ |