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