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