1 /* Primitive operations on Lisp data types for GNU Emacs Lisp interpreter.
2 Copyright (C) 1985-1986, 1988, 1993-1995, 1997-2011
3 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
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.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
27 #include "character.h"
31 #include "syssignal.h"
32 #include "termhooks.h" /* For FRAME_KBOARD reference in y-or-n-p. */
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
45 #define IEEE_FLOATING_POINT 0
51 Lisp_Object Qnil
, Qt
, Qquote
, Qlambda
, Qunbound
;
52 static Lisp_Object Qsubr
;
53 Lisp_Object Qerror_conditions
, Qerror_message
, Qtop_level
;
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
;
62 Lisp_Object Qinvalid_function
, Qwrong_number_of_arguments
, Qno_catch
;
63 Lisp_Object Qend_of_file
, Qarith_error
, Qmark_inactive
;
64 Lisp_Object Qbeginning_of_buffer
, Qend_of_buffer
, Qbuffer_read_only
;
65 Lisp_Object Qtext_read_only
;
67 Lisp_Object Qintegerp
, Qwholenump
, Qsymbolp
, Qlistp
, Qconsp
;
68 static Lisp_Object Qnatnump
;
69 Lisp_Object Qstringp
, Qarrayp
, Qsequencep
, Qbufferp
;
70 Lisp_Object Qchar_or_string_p
, Qmarkerp
, Qinteger_or_marker_p
, Qvectorp
;
71 Lisp_Object Qbuffer_or_string_p
;
72 static Lisp_Object Qkeywordp
, Qboundp
;
74 Lisp_Object Qchar_table_p
, Qvector_or_char_table_p
;
77 static Lisp_Object Qad_advice_info
, Qad_activate_internal
;
79 Lisp_Object Qrange_error
, Qdomain_error
, Qsingularity_error
;
80 Lisp_Object Qoverflow_error
, Qunderflow_error
;
83 Lisp_Object Qnumberp
, Qnumber_or_marker_p
;
86 static Lisp_Object Qsymbol
, Qstring
, Qcons
, Qmarker
, Qoverlay
;
88 static Lisp_Object Qfloat
, Qwindow_configuration
;
89 static Lisp_Object Qprocess
;
90 static Lisp_Object Qcompiled_function
, Qbuffer
, Qframe
, Qvector
;
91 static Lisp_Object Qchar_table
, Qbool_vector
, Qhash_table
;
92 static Lisp_Object Qsubrp
, Qmany
, Qunevalled
;
93 Lisp_Object Qfont_spec
, Qfont_entity
, Qfont_object
;
95 Lisp_Object Qinteractive_form
;
97 static void swap_in_symval_forwarding (struct Lisp_Symbol
*, struct Lisp_Buffer_Local_Value
*);
101 wrong_type_argument (register Lisp_Object predicate
, register Lisp_Object value
)
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)
110 xsignal2 (Qwrong_type_argument
, predicate
, value
);
114 pure_write_error (void)
116 error ("Attempt to modify read-only object");
120 args_out_of_range (Lisp_Object a1
, Lisp_Object a2
)
122 xsignal2 (Qargs_out_of_range
, a1
, a2
);
126 args_out_of_range_3 (Lisp_Object a1
, Lisp_Object a2
, Lisp_Object a3
)
128 xsignal3 (Qargs_out_of_range
, a1
, a2
, a3
);
132 /* Data type predicates */
134 DEFUN ("eq", Feq
, Seq
, 2, 2, 0,
135 doc
: /* Return t if the two args are the same Lisp object. */)
136 (Lisp_Object obj1
, Lisp_Object obj2
)
143 DEFUN ("null", Fnull
, Snull
, 1, 1, 0,
144 doc
: /* Return t if OBJECT is nil. */)
152 DEFUN ("type-of", Ftype_of
, Stype_of
, 1, 1, 0,
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'. */)
158 switch (XTYPE (object
))
173 switch (XMISCTYPE (object
))
175 case Lisp_Misc_Marker
:
177 case Lisp_Misc_Overlay
:
179 case Lisp_Misc_Float
:
184 case Lisp_Vectorlike
:
185 if (WINDOW_CONFIGURATIONP (object
))
186 return Qwindow_configuration
;
187 if (PROCESSP (object
))
189 if (WINDOWP (object
))
193 if (COMPILEDP (object
))
194 return Qcompiled_function
;
195 if (BUFFERP (object
))
197 if (CHAR_TABLE_P (object
))
199 if (BOOL_VECTOR_P (object
))
203 if (HASH_TABLE_P (object
))
205 if (FONT_SPEC_P (object
))
207 if (FONT_ENTITY_P (object
))
209 if (FONT_OBJECT_P (object
))
221 DEFUN ("consp", Fconsp
, Sconsp
, 1, 1, 0,
222 doc
: /* Return t if OBJECT is a cons cell. */)
230 DEFUN ("atom", Fatom
, Satom
, 1, 1, 0,
231 doc
: /* Return t if OBJECT is not a cons cell. This includes nil. */)
239 DEFUN ("listp", Flistp
, Slistp
, 1, 1, 0,
240 doc
: /* Return t if OBJECT is a list, that is, a cons cell or nil.
241 Otherwise, return nil. */)
244 if (CONSP (object
) || NILP (object
))
249 DEFUN ("nlistp", Fnlistp
, Snlistp
, 1, 1, 0,
250 doc
: /* Return t if OBJECT is not a list. Lists include nil. */)
253 if (CONSP (object
) || NILP (object
))
258 DEFUN ("symbolp", Fsymbolp
, Ssymbolp
, 1, 1, 0,
259 doc
: /* Return t if OBJECT is a symbol. */)
262 if (SYMBOLP (object
))
267 /* Define this in C to avoid unnecessarily consing up the symbol
269 DEFUN ("keywordp", Fkeywordp
, Skeywordp
, 1, 1, 0,
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. */)
276 && SREF (SYMBOL_NAME (object
), 0) == ':'
277 && SYMBOL_INTERNED_IN_INITIAL_OBARRAY_P (object
))
282 DEFUN ("vectorp", Fvectorp
, Svectorp
, 1, 1, 0,
283 doc
: /* Return t if OBJECT is a vector. */)
286 if (VECTORP (object
))
291 DEFUN ("stringp", Fstringp
, Sstringp
, 1, 1, 0,
292 doc
: /* Return t if OBJECT is a string. */)
295 if (STRINGP (object
))
300 DEFUN ("multibyte-string-p", Fmultibyte_string_p
, Smultibyte_string_p
,
302 doc
: /* Return t if OBJECT is a multibyte string. */)
305 if (STRINGP (object
) && STRING_MULTIBYTE (object
))
310 DEFUN ("char-table-p", Fchar_table_p
, Schar_table_p
, 1, 1, 0,
311 doc
: /* Return t if OBJECT is a char-table. */)
314 if (CHAR_TABLE_P (object
))
319 DEFUN ("vector-or-char-table-p", Fvector_or_char_table_p
,
320 Svector_or_char_table_p
, 1, 1, 0,
321 doc
: /* Return t if OBJECT is a char-table or vector. */)
324 if (VECTORP (object
) || CHAR_TABLE_P (object
))
329 DEFUN ("bool-vector-p", Fbool_vector_p
, Sbool_vector_p
, 1, 1, 0,
330 doc
: /* Return t if OBJECT is a bool-vector. */)
333 if (BOOL_VECTOR_P (object
))
338 DEFUN ("arrayp", Farrayp
, Sarrayp
, 1, 1, 0,
339 doc
: /* Return t if OBJECT is an array (string or vector). */)
347 DEFUN ("sequencep", Fsequencep
, Ssequencep
, 1, 1, 0,
348 doc
: /* Return t if OBJECT is a sequence (list or array). */)
349 (register Lisp_Object object
)
351 if (CONSP (object
) || NILP (object
) || ARRAYP (object
))
356 DEFUN ("bufferp", Fbufferp
, Sbufferp
, 1, 1, 0,
357 doc
: /* Return t if OBJECT is an editor buffer. */)
360 if (BUFFERP (object
))
365 DEFUN ("markerp", Fmarkerp
, Smarkerp
, 1, 1, 0,
366 doc
: /* Return t if OBJECT is a marker (editor pointer). */)
369 if (MARKERP (object
))
374 DEFUN ("subrp", Fsubrp
, Ssubrp
, 1, 1, 0,
375 doc
: /* Return t if OBJECT is a built-in function. */)
383 DEFUN ("byte-code-function-p", Fbyte_code_function_p
, Sbyte_code_function_p
,
385 doc
: /* Return t if OBJECT is a byte-compiled function object. */)
388 if (COMPILEDP (object
))
393 DEFUN ("char-or-string-p", Fchar_or_string_p
, Schar_or_string_p
, 1, 1, 0,
394 doc
: /* Return t if OBJECT is a character or a string. */)
395 (register Lisp_Object object
)
397 if (CHARACTERP (object
) || STRINGP (object
))
402 DEFUN ("integerp", Fintegerp
, Sintegerp
, 1, 1, 0,
403 doc
: /* Return t if OBJECT is an integer. */)
406 if (INTEGERP (object
))
411 DEFUN ("integer-or-marker-p", Finteger_or_marker_p
, Sinteger_or_marker_p
, 1, 1, 0,
412 doc
: /* Return t if OBJECT is an integer or a marker (editor pointer). */)
413 (register Lisp_Object object
)
415 if (MARKERP (object
) || INTEGERP (object
))
420 DEFUN ("natnump", Fnatnump
, Snatnump
, 1, 1, 0,
421 doc
: /* Return t if OBJECT is a nonnegative integer. */)
424 if (NATNUMP (object
))
429 DEFUN ("numberp", Fnumberp
, Snumberp
, 1, 1, 0,
430 doc
: /* Return t if OBJECT is a number (floating point or integer). */)
433 if (NUMBERP (object
))
439 DEFUN ("number-or-marker-p", Fnumber_or_marker_p
,
440 Snumber_or_marker_p
, 1, 1, 0,
441 doc
: /* Return t if OBJECT is a number or a marker. */)
444 if (NUMBERP (object
) || MARKERP (object
))
449 DEFUN ("floatp", Ffloatp
, Sfloatp
, 1, 1, 0,
450 doc
: /* Return t if OBJECT is a floating point number. */)
459 /* Extract and set components of lists */
461 DEFUN ("car", Fcar
, Scar
, 1, 1, 0,
462 doc
: /* Return the car of LIST. If arg is nil, return nil.
463 Error if arg is not nil and not a cons cell. See also `car-safe'.
465 See Info node `(elisp)Cons Cells' for a discussion of related basic
466 Lisp concepts such as car, cdr, cons cell and list. */)
467 (register Lisp_Object list
)
472 DEFUN ("car-safe", Fcar_safe
, Scar_safe
, 1, 1, 0,
473 doc
: /* Return the car of OBJECT if it is a cons cell, or else nil. */)
476 return CAR_SAFE (object
);
479 DEFUN ("cdr", Fcdr
, Scdr
, 1, 1, 0,
480 doc
: /* Return the cdr of LIST. If arg is nil, return nil.
481 Error if arg is not nil and not a cons cell. See also `cdr-safe'.
483 See Info node `(elisp)Cons Cells' for a discussion of related basic
484 Lisp concepts such as cdr, car, cons cell and list. */)
485 (register Lisp_Object list
)
490 DEFUN ("cdr-safe", Fcdr_safe
, Scdr_safe
, 1, 1, 0,
491 doc
: /* Return the cdr of OBJECT if it is a cons cell, or else nil. */)
494 return CDR_SAFE (object
);
497 DEFUN ("setcar", Fsetcar
, Ssetcar
, 2, 2, 0,
498 doc
: /* Set the car of CELL to be NEWCAR. Returns NEWCAR. */)
499 (register Lisp_Object cell
, Lisp_Object newcar
)
503 XSETCAR (cell
, newcar
);
507 DEFUN ("setcdr", Fsetcdr
, Ssetcdr
, 2, 2, 0,
508 doc
: /* Set the cdr of CELL to be NEWCDR. Returns NEWCDR. */)
509 (register Lisp_Object cell
, Lisp_Object newcdr
)
513 XSETCDR (cell
, newcdr
);
517 /* Extract and set components of symbols */
519 DEFUN ("boundp", Fboundp
, Sboundp
, 1, 1, 0,
520 doc
: /* Return t if SYMBOL's value is not void. */)
521 (register Lisp_Object symbol
)
523 Lisp_Object valcontents
;
524 struct Lisp_Symbol
*sym
;
525 CHECK_SYMBOL (symbol
);
526 sym
= XSYMBOL (symbol
);
529 switch (sym
->redirect
)
531 case SYMBOL_PLAINVAL
: valcontents
= SYMBOL_VAL (sym
); break;
532 case SYMBOL_VARALIAS
: sym
= indirect_variable (sym
); goto start
;
533 case SYMBOL_LOCALIZED
:
535 struct Lisp_Buffer_Local_Value
*blv
= SYMBOL_BLV (sym
);
537 /* In set_internal, we un-forward vars when their value is
542 swap_in_symval_forwarding (sym
, blv
);
543 valcontents
= BLV_VALUE (blv
);
547 case SYMBOL_FORWARDED
:
548 /* In set_internal, we un-forward vars when their value is
554 return (EQ (valcontents
, Qunbound
) ? Qnil
: Qt
);
557 DEFUN ("fboundp", Ffboundp
, Sfboundp
, 1, 1, 0,
558 doc
: /* Return t if SYMBOL's function definition is not void. */)
559 (register Lisp_Object symbol
)
561 CHECK_SYMBOL (symbol
);
562 return (EQ (XSYMBOL (symbol
)->function
, Qunbound
) ? Qnil
: Qt
);
565 DEFUN ("makunbound", Fmakunbound
, Smakunbound
, 1, 1, 0,
566 doc
: /* Make SYMBOL's value be void.
568 (register Lisp_Object symbol
)
570 CHECK_SYMBOL (symbol
);
571 if (SYMBOL_CONSTANT_P (symbol
))
572 xsignal1 (Qsetting_constant
, symbol
);
573 Fset (symbol
, Qunbound
);
577 DEFUN ("fmakunbound", Ffmakunbound
, Sfmakunbound
, 1, 1, 0,
578 doc
: /* Make SYMBOL's function definition be void.
580 (register Lisp_Object symbol
)
582 CHECK_SYMBOL (symbol
);
583 if (NILP (symbol
) || EQ (symbol
, Qt
))
584 xsignal1 (Qsetting_constant
, symbol
);
585 XSYMBOL (symbol
)->function
= Qunbound
;
589 DEFUN ("symbol-function", Fsymbol_function
, Ssymbol_function
, 1, 1, 0,
590 doc
: /* Return SYMBOL's function definition. Error if that is void. */)
591 (register Lisp_Object symbol
)
593 CHECK_SYMBOL (symbol
);
594 if (!EQ (XSYMBOL (symbol
)->function
, Qunbound
))
595 return XSYMBOL (symbol
)->function
;
596 xsignal1 (Qvoid_function
, symbol
);
599 DEFUN ("symbol-plist", Fsymbol_plist
, Ssymbol_plist
, 1, 1, 0,
600 doc
: /* Return SYMBOL's property list. */)
601 (register Lisp_Object symbol
)
603 CHECK_SYMBOL (symbol
);
604 return XSYMBOL (symbol
)->plist
;
607 DEFUN ("symbol-name", Fsymbol_name
, Ssymbol_name
, 1, 1, 0,
608 doc
: /* Return SYMBOL's name, a string. */)
609 (register Lisp_Object symbol
)
611 register Lisp_Object name
;
613 CHECK_SYMBOL (symbol
);
614 name
= SYMBOL_NAME (symbol
);
618 DEFUN ("fset", Ffset
, Sfset
, 2, 2, 0,
619 doc
: /* Set SYMBOL's function definition to DEFINITION, and return DEFINITION. */)
620 (register Lisp_Object symbol
, Lisp_Object definition
)
622 register Lisp_Object function
;
624 CHECK_SYMBOL (symbol
);
625 if (NILP (symbol
) || EQ (symbol
, Qt
))
626 xsignal1 (Qsetting_constant
, symbol
);
628 function
= XSYMBOL (symbol
)->function
;
630 if (!NILP (Vautoload_queue
) && !EQ (function
, Qunbound
))
631 Vautoload_queue
= Fcons (Fcons (symbol
, function
), Vautoload_queue
);
633 if (CONSP (function
) && EQ (XCAR (function
), Qautoload
))
634 Fput (symbol
, Qautoload
, XCDR (function
));
636 XSYMBOL (symbol
)->function
= definition
;
637 /* Handle automatic advice activation */
638 if (CONSP (XSYMBOL (symbol
)->plist
) && !NILP (Fget (symbol
, Qad_advice_info
)))
640 call2 (Qad_activate_internal
, symbol
, Qnil
);
641 definition
= XSYMBOL (symbol
)->function
;
646 DEFUN ("defalias", Fdefalias
, Sdefalias
, 2, 3, 0,
647 doc
: /* Set SYMBOL's function definition to DEFINITION, and return DEFINITION.
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. */)
652 (register Lisp_Object symbol
, Lisp_Object definition
, Lisp_Object docstring
)
654 CHECK_SYMBOL (symbol
);
655 if (CONSP (XSYMBOL (symbol
)->function
)
656 && EQ (XCAR (XSYMBOL (symbol
)->function
), Qautoload
))
657 LOADHIST_ATTACH (Fcons (Qt
, symbol
));
658 definition
= Ffset (symbol
, definition
);
659 LOADHIST_ATTACH (Fcons (Qdefun
, symbol
));
660 if (!NILP (docstring
))
661 Fput (symbol
, Qfunction_documentation
, docstring
);
665 DEFUN ("setplist", Fsetplist
, Ssetplist
, 2, 2, 0,
666 doc
: /* Set SYMBOL's property list to NEWPLIST, and return NEWPLIST. */)
667 (register Lisp_Object symbol
, Lisp_Object newplist
)
669 CHECK_SYMBOL (symbol
);
670 XSYMBOL (symbol
)->plist
= newplist
;
674 DEFUN ("subr-arity", Fsubr_arity
, Ssubr_arity
, 1, 1, 0,
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. */)
682 short minargs
, maxargs
;
684 minargs
= XSUBR (subr
)->min_args
;
685 maxargs
= XSUBR (subr
)->max_args
;
687 return Fcons (make_number (minargs
), Qmany
);
688 else if (maxargs
== UNEVALLED
)
689 return Fcons (make_number (minargs
), Qunevalled
);
691 return Fcons (make_number (minargs
), make_number (maxargs
));
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. */)
701 name
= XSUBR (subr
)->symbol_name
;
702 return make_string (name
, strlen (name
));
705 DEFUN ("interactive-form", Finteractive_form
, Sinteractive_form
, 1, 1, 0,
706 doc
: /* Return the interactive form of CMD or nil if none.
707 If CMD is not a command, the return value is nil.
708 Value, if non-nil, is a list \(interactive SPEC). */)
711 Lisp_Object fun
= indirect_function (cmd
); /* Check cycles. */
713 if (NILP (fun
) || EQ (fun
, Qunbound
))
716 /* Use an `interactive-form' property if present, analogous to the
717 function-documentation property. */
719 while (SYMBOLP (fun
))
721 Lisp_Object tmp
= Fget (fun
, Qinteractive_form
);
725 fun
= Fsymbol_function (fun
);
730 const char *spec
= XSUBR (fun
)->intspec
;
732 return list2 (Qinteractive
,
733 (*spec
!= '(') ? build_string (spec
) :
734 Fcar (Fread_from_string (build_string (spec
), Qnil
, Qnil
)));
736 else if (COMPILEDP (fun
))
738 if ((ASIZE (fun
) & PSEUDOVECTOR_SIZE_MASK
) > COMPILED_INTERACTIVE
)
739 return list2 (Qinteractive
, AREF (fun
, COMPILED_INTERACTIVE
));
741 else if (CONSP (fun
))
743 Lisp_Object funcar
= XCAR (fun
);
744 if (EQ (funcar
, Qclosure
))
745 return Fassq (Qinteractive
, Fcdr (Fcdr (XCDR (fun
))));
746 else if (EQ (funcar
, Qlambda
))
747 return Fassq (Qinteractive
, Fcdr (XCDR (fun
)));
748 else if (EQ (funcar
, Qautoload
))
752 do_autoload (fun
, cmd
);
754 return Finteractive_form (cmd
);
761 /***********************************************************************
762 Getting and Setting Values of Symbols
763 ***********************************************************************/
765 /* Return the symbol holding SYMBOL's value. Signal
766 `cyclic-variable-indirection' if SYMBOL's chain of variable
767 indirections contains a loop. */
770 indirect_variable (struct Lisp_Symbol
*symbol
)
772 struct Lisp_Symbol
*tortoise
, *hare
;
774 hare
= tortoise
= symbol
;
776 while (hare
->redirect
== SYMBOL_VARALIAS
)
778 hare
= SYMBOL_ALIAS (hare
);
779 if (hare
->redirect
!= SYMBOL_VARALIAS
)
782 hare
= SYMBOL_ALIAS (hare
);
783 tortoise
= SYMBOL_ALIAS (tortoise
);
785 if (hare
== tortoise
)
788 XSETSYMBOL (tem
, symbol
);
789 xsignal1 (Qcyclic_variable_indirection
, tem
);
797 DEFUN ("indirect-variable", Findirect_variable
, Sindirect_variable
, 1, 1, 0,
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. */)
805 if (SYMBOLP (object
))
807 struct Lisp_Symbol
*sym
= indirect_variable (XSYMBOL (object
));
808 XSETSYMBOL (object
, sym
);
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. */
820 do_symval_forwarding (register union Lisp_Fwd
*valcontents
)
822 register Lisp_Object val
;
823 switch (XFWDTYPE (valcontents
))
826 XSETINT (val
, *XINTFWD (valcontents
)->intvar
);
830 return (*XBOOLFWD (valcontents
)->boolvar
? Qt
: Qnil
);
833 return *XOBJFWD (valcontents
)->objvar
;
835 case Lisp_Fwd_Buffer_Obj
:
836 return PER_BUFFER_VALUE (current_buffer
,
837 XBUFFER_OBJFWD (valcontents
)->offset
);
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:
844 (with-selected-frame frame
845 (define-key local-function-map "\eOP" [f1]))
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 ()));
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
859 buffer-independent contents of the value cell: forwarded just one
860 step past the buffer-localness.
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. */
866 store_symval_forwarding (union Lisp_Fwd
*valcontents
, register Lisp_Object newval
, struct buffer
*buf
)
868 switch (XFWDTYPE (valcontents
))
871 CHECK_NUMBER (newval
);
872 *XINTFWD (valcontents
)->intvar
= XINT (newval
);
876 *XBOOLFWD (valcontents
)->boolvar
= !NILP (newval
);
880 *XOBJFWD (valcontents
)->objvar
= newval
;
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
886 if (XOBJFWD (valcontents
)->objvar
> (Lisp_Object
*) &buffer_defaults
887 && XOBJFWD (valcontents
)->objvar
< (Lisp_Object
*) (&buffer_defaults
+ 1))
889 int offset
= ((char *) XOBJFWD (valcontents
)->objvar
890 - (char *) &buffer_defaults
);
891 int idx
= PER_BUFFER_IDX (offset
);
898 for (tail
= Vbuffer_alist
; CONSP (tail
); tail
= XCDR (tail
))
903 lbuf
= Fcdr (XCAR (tail
));
904 if (!BUFFERP (lbuf
)) continue;
907 if (! PER_BUFFER_VALUE_P (b
, idx
))
908 PER_BUFFER_VALUE (b
, offset
) = newval
;
913 case Lisp_Fwd_Buffer_Obj
:
915 int offset
= XBUFFER_OBJFWD (valcontents
)->offset
;
916 Lisp_Object type
= XBUFFER_OBJFWD (valcontents
)->slottype
;
918 if (!(NILP (type
) || NILP (newval
)
919 || (XINT (type
) == LISP_INT_TAG
921 : XTYPE (newval
) == XINT (type
))))
922 buffer_slot_type_mismatch (newval
, XINT (type
));
925 buf
= current_buffer
;
926 PER_BUFFER_VALUE (buf
, offset
) = newval
;
930 case Lisp_Fwd_Kboard_Obj
:
932 char *base
= (char *) FRAME_KBOARD (SELECTED_FRAME ());
933 char *p
= base
+ XKBOARD_OBJFWD (valcontents
)->offset
;
934 *(Lisp_Object
*) p
= newval
;
939 abort (); /* goto def; */
943 /* Set up SYMBOL to refer to its global binding.
944 This makes it safe to alter the status of other bindings. */
947 swap_in_global_binding (struct Lisp_Symbol
*symbol
)
949 struct Lisp_Buffer_Local_Value
*blv
= SYMBOL_BLV (symbol
);
951 /* Unload the previously loaded binding. */
953 SET_BLV_VALUE (blv
, do_symval_forwarding (blv
->fwd
));
955 /* Select the global binding in the symbol. */
956 blv
->valcell
= blv
->defcell
;
958 store_symval_forwarding (blv
->fwd
, XCDR (blv
->defcell
), NULL
);
960 /* Indicate that the global binding is set up now. */
962 SET_BLV_FOUND (blv
, 0);
965 /* Set up the buffer-local symbol SYMBOL for validity in the current buffer.
966 VALCONTENTS is the contents of its value cell,
967 which points to a struct Lisp_Buffer_Local_Value.
969 Return the value forwarded one step past the buffer-local stage.
970 This could be another forwarding pointer. */
973 swap_in_symval_forwarding (struct Lisp_Symbol
*symbol
, struct Lisp_Buffer_Local_Value
*blv
)
975 register Lisp_Object tem1
;
977 eassert (blv
== SYMBOL_BLV (symbol
));
983 ? !EQ (selected_frame
, tem1
)
984 : current_buffer
!= XBUFFER (tem1
)))
987 /* Unload the previously loaded binding. */
990 SET_BLV_VALUE (blv
, do_symval_forwarding (blv
->fwd
));
991 /* Choose the new binding. */
994 XSETSYMBOL (var
, symbol
);
995 if (blv
->frame_local
)
997 tem1
= assq_no_quit (var
, XFRAME (selected_frame
)->param_alist
);
998 blv
->where
= selected_frame
;
1002 tem1
= assq_no_quit (var
, BVAR (current_buffer
, local_var_alist
));
1003 XSETBUFFER (blv
->where
, current_buffer
);
1006 if (!(blv
->found
= !NILP (tem1
)))
1007 tem1
= blv
->defcell
;
1009 /* Load the new binding. */
1010 blv
->valcell
= tem1
;
1012 store_symval_forwarding (blv
->fwd
, BLV_VALUE (blv
), NULL
);
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
1018 if it has one, without signaling an error.
1019 Note that it must not be possible to quit
1020 within this function. Great care is required for this. */
1023 find_symbol_value (Lisp_Object symbol
)
1025 struct Lisp_Symbol
*sym
;
1027 CHECK_SYMBOL (symbol
);
1028 sym
= XSYMBOL (symbol
);
1031 switch (sym
->redirect
)
1033 case SYMBOL_VARALIAS
: sym
= indirect_variable (sym
); goto start
;
1034 case SYMBOL_PLAINVAL
: return SYMBOL_VAL (sym
);
1035 case SYMBOL_LOCALIZED
:
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
);
1042 case SYMBOL_FORWARDED
:
1043 return do_symval_forwarding (SYMBOL_FWD (sym
));
1048 DEFUN ("symbol-value", Fsymbol_value
, Ssymbol_value
, 1, 1, 0,
1049 doc
: /* Return SYMBOL's value. Error if that is void. */)
1050 (Lisp_Object symbol
)
1054 val
= find_symbol_value (symbol
);
1055 if (!EQ (val
, Qunbound
))
1058 xsignal1 (Qvoid_variable
, symbol
);
1061 DEFUN ("set", Fset
, Sset
, 2, 2, 0,
1062 doc
: /* Set SYMBOL's value to NEWVAL, and return NEWVAL. */)
1063 (register Lisp_Object symbol
, Lisp_Object newval
)
1065 set_internal (symbol
, newval
, Qnil
, 0);
1069 /* Return 1 if SYMBOL currently has a let-binding
1070 which was made in the buffer that is now current. */
1073 let_shadows_buffer_binding_p (struct Lisp_Symbol
*symbol
)
1075 struct specbinding
*p
;
1077 for (p
= specpdl_ptr
- 1; p
>= specpdl
; p
--)
1079 && CONSP (p
->symbol
))
1081 struct Lisp_Symbol
*let_bound_symbol
= XSYMBOL (XCAR (p
->symbol
));
1082 eassert (let_bound_symbol
->redirect
!= SYMBOL_VARALIAS
);
1083 if (symbol
== let_bound_symbol
1084 && XBUFFER (XCDR (XCDR (p
->symbol
))) == current_buffer
)
1088 return p
>= specpdl
;
1092 let_shadows_global_binding_p (Lisp_Object symbol
)
1094 struct specbinding
*p
;
1096 for (p
= specpdl_ptr
- 1; p
>= specpdl
; p
--)
1097 if (p
->func
== NULL
&& EQ (p
->symbol
, symbol
))
1100 return p
>= specpdl
;
1103 /* Store the value NEWVAL into SYMBOL.
1104 If buffer/frame-locality is an issue, WHERE specifies which context to use.
1105 (nil stands for the current buffer/frame).
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. */
1112 set_internal (register Lisp_Object symbol
, register Lisp_Object newval
, register Lisp_Object where
, int bindflag
)
1114 int voide
= EQ (newval
, Qunbound
);
1115 struct Lisp_Symbol
*sym
;
1118 /* If restoring in a dead buffer, do nothing. */
1119 /* if (BUFFERP (where) && NILP (XBUFFER (where)->name))
1122 CHECK_SYMBOL (symbol
);
1123 if (SYMBOL_CONSTANT_P (symbol
))
1125 if (NILP (Fkeywordp (symbol
))
1126 || !EQ (newval
, Fsymbol_value (symbol
)))
1127 xsignal1 (Qsetting_constant
, symbol
);
1129 /* Allow setting keywords to their own value. */
1133 sym
= XSYMBOL (symbol
);
1136 switch (sym
->redirect
)
1138 case SYMBOL_VARALIAS
: sym
= indirect_variable (sym
); goto start
;
1139 case SYMBOL_PLAINVAL
: SET_SYMBOL_VAL (sym
, newval
); return;
1140 case SYMBOL_LOCALIZED
:
1142 struct Lisp_Buffer_Local_Value
*blv
= SYMBOL_BLV (sym
);
1145 if (blv
->frame_local
)
1146 where
= selected_frame
;
1148 XSETBUFFER (where
, current_buffer
);
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
1155 if (!EQ (blv
->where
, where
)
1156 /* Also unload a global binding (if the var is local_if_set). */
1157 || (EQ (blv
->valcell
, blv
->defcell
)))
1159 /* The currently loaded binding is not necessarily valid.
1160 We need to unload it, and choose a new binding. */
1162 /* Write out `realvalue' to the old loaded binding. */
1164 SET_BLV_VALUE (blv
, do_symval_forwarding (blv
->fwd
));
1166 /* Find the new binding. */
1167 XSETSYMBOL (symbol
, sym
); /* May have changed via aliasing. */
1168 tem1
= Fassq (symbol
,
1170 ? XFRAME (where
)->param_alist
1171 : BVAR (XBUFFER (where
), local_var_alist
)));
1177 /* This buffer still sees the default value. */
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
))
1189 tem1
= blv
->defcell
;
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. */
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
));
1202 BVAR (XBUFFER (where
), local_var_alist
)
1203 = Fcons (tem1
, BVAR (XBUFFER (where
), local_var_alist
));
1207 /* Record which binding is now loaded. */
1208 blv
->valcell
= tem1
;
1211 /* Store the new value in the cons cell. */
1212 SET_BLV_VALUE (blv
, newval
);
1217 /* If storing void (making the symbol void), forward only through
1218 buffer-local indicator, not through Lisp_Objfwd, etc. */
1221 store_symval_forwarding (blv
->fwd
, newval
,
1223 ? XBUFFER (where
) : current_buffer
);
1227 case SYMBOL_FORWARDED
:
1230 = BUFFERP (where
) ? XBUFFER (where
) : current_buffer
;
1231 union Lisp_Fwd
*innercontents
= SYMBOL_FWD (sym
);
1232 if (BUFFER_OBJFWDP (innercontents
))
1234 int offset
= XBUFFER_OBJFWD (innercontents
)->offset
;
1235 int idx
= PER_BUFFER_IDX (offset
);
1238 && !let_shadows_buffer_binding_p (sym
))
1239 SET_PER_BUFFER_VALUE_P (buf
, idx
, 1);
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
);
1249 store_symval_forwarding (/* sym, */ innercontents
, newval
, buf
);
1257 /* Access or set a buffer-local symbol's default value. */
1259 /* Return the default value of SYMBOL, but don't check for voidness.
1260 Return Qunbound if it is void. */
1263 default_value (Lisp_Object symbol
)
1265 struct Lisp_Symbol
*sym
;
1267 CHECK_SYMBOL (symbol
);
1268 sym
= XSYMBOL (symbol
);
1271 switch (sym
->redirect
)
1273 case SYMBOL_VARALIAS
: sym
= indirect_variable (sym
); goto start
;
1274 case SYMBOL_PLAINVAL
: return SYMBOL_VAL (sym
);
1275 case SYMBOL_LOCALIZED
:
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
);
1285 return XCDR (blv
->defcell
);
1287 case SYMBOL_FORWARDED
:
1289 union Lisp_Fwd
*valcontents
= SYMBOL_FWD (sym
);
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
))
1295 int offset
= XBUFFER_OBJFWD (valcontents
)->offset
;
1296 if (PER_BUFFER_IDX (offset
) != 0)
1297 return PER_BUFFER_DEFAULT (offset
);
1300 /* For other variables, get the current value. */
1301 return do_symval_forwarding (valcontents
);
1307 DEFUN ("default-boundp", Fdefault_boundp
, Sdefault_boundp
, 1, 1, 0,
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. */)
1311 (Lisp_Object symbol
)
1313 register Lisp_Object value
;
1315 value
= default_value (symbol
);
1316 return (EQ (value
, Qunbound
) ? Qnil
: Qt
);
1319 DEFUN ("default-value", Fdefault_value
, Sdefault_value
, 1, 1, 0,
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. */)
1324 (Lisp_Object symbol
)
1326 register Lisp_Object value
;
1328 value
= default_value (symbol
);
1329 if (!EQ (value
, Qunbound
))
1332 xsignal1 (Qvoid_variable
, symbol
);
1335 DEFUN ("set-default", Fset_default
, Sset_default
, 2, 2, 0,
1336 doc
: /* Set SYMBOL's default value to VALUE. SYMBOL and VALUE are evaluated.
1337 The default value is seen in buffers that do not have their own values
1338 for this variable. */)
1339 (Lisp_Object symbol
, Lisp_Object value
)
1341 struct Lisp_Symbol
*sym
;
1343 CHECK_SYMBOL (symbol
);
1344 if (SYMBOL_CONSTANT_P (symbol
))
1346 if (NILP (Fkeywordp (symbol
))
1347 || !EQ (value
, Fdefault_value (symbol
)))
1348 xsignal1 (Qsetting_constant
, symbol
);
1350 /* Allow setting keywords to their own value. */
1353 sym
= XSYMBOL (symbol
);
1356 switch (sym
->redirect
)
1358 case SYMBOL_VARALIAS
: sym
= indirect_variable (sym
); goto start
;
1359 case SYMBOL_PLAINVAL
: return Fset (symbol
, value
);
1360 case SYMBOL_LOCALIZED
:
1362 struct Lisp_Buffer_Local_Value
*blv
= SYMBOL_BLV (sym
);
1364 /* Store new value into the DEFAULT-VALUE slot. */
1365 XSETCDR (blv
->defcell
, value
);
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
);
1372 case SYMBOL_FORWARDED
:
1374 union Lisp_Fwd
*valcontents
= SYMBOL_FWD (sym
);
1376 /* Handle variables like case-fold-search that have special slots
1378 Make them work apparently like Lisp_Buffer_Local_Value variables. */
1379 if (BUFFER_OBJFWDP (valcontents
))
1381 int offset
= XBUFFER_OBJFWD (valcontents
)->offset
;
1382 int idx
= PER_BUFFER_IDX (offset
);
1384 PER_BUFFER_DEFAULT (offset
) = value
;
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. */
1392 for (b
= all_buffers
; b
; b
= b
->header
.next
.buffer
)
1393 if (!PER_BUFFER_VALUE_P (b
, idx
))
1394 PER_BUFFER_VALUE (b
, offset
) = value
;
1399 return Fset (symbol
, value
);
1405 DEFUN ("setq-default", Fsetq_default
, Ssetq_default
, 0, UNEVALLED
, 0,
1406 doc
: /* Set the default value of variable VAR to VALUE.
1407 VAR, the variable name, is literal (not evaluated);
1408 VALUE is an expression: it is evaluated and its value returned.
1409 The default value of a variable is seen in buffers
1410 that do not have their own values for the variable.
1412 More generally, you can use multiple variables and values, as in
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
1417 usage: (setq-default [VAR VALUE]...) */)
1420 register Lisp_Object args_left
;
1421 register Lisp_Object val
, symbol
;
1422 struct gcpro gcpro1
;
1432 val
= eval_sub (Fcar (Fcdr (args_left
)));
1433 symbol
= XCAR (args_left
);
1434 Fset_default (symbol
, val
);
1435 args_left
= Fcdr (XCDR (args_left
));
1437 while (!NILP (args_left
));
1443 /* Lisp functions for creating and removing buffer-local variables. */
1448 union Lisp_Fwd
*fwd
;
1451 static struct Lisp_Buffer_Local_Value
*
1452 make_blv (struct Lisp_Symbol
*sym
, int forwarded
, union Lisp_Val_Fwd valcontents
)
1454 struct Lisp_Buffer_Local_Value
*blv
1455 = xmalloc (sizeof (struct Lisp_Buffer_Local_Value
));
1459 XSETSYMBOL (symbol
, sym
);
1460 tem
= Fcons (symbol
, (forwarded
1461 ? do_symval_forwarding (valcontents
.fwd
)
1462 : valcontents
.value
));
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
;
1470 blv
->frame_local
= 0;
1471 blv
->local_if_set
= 0;
1474 SET_BLV_FOUND (blv
, 0);
1478 DEFUN ("make-variable-buffer-local", Fmake_variable_buffer_local
,
1479 Smake_variable_buffer_local
, 1, 1, "vMake Variable Buffer Local: ",
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,
1486 does not make the variable buffer-local. Return VARIABLE.
1488 In most cases it is better to use `make-local-variable',
1489 which makes a variable local in just one buffer.
1491 The function `default-value' gets the default value and `set-default' sets it. */)
1492 (register Lisp_Object variable
)
1494 struct Lisp_Symbol
*sym
;
1495 struct Lisp_Buffer_Local_Value
*blv
= NULL
;
1496 union Lisp_Val_Fwd valcontents
IF_LINT (= {0});
1497 int forwarded
IF_LINT (= 0);
1499 CHECK_SYMBOL (variable
);
1500 sym
= XSYMBOL (variable
);
1503 switch (sym
->redirect
)
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
;
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
)));
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
))
1529 error ("Symbol %s may not be buffer-local", SDATA (SYMBOL_NAME (variable
)));
1533 blv
= make_blv (sym
, forwarded
, valcontents
);
1534 sym
->redirect
= SYMBOL_LOCALIZED
;
1535 SET_SYMBOL_BLV (sym
, blv
);
1538 XSETSYMBOL (symbol
, sym
); /* In case `variable' is aliased. */
1539 if (let_shadows_global_binding_p (symbol
))
1540 message ("Making %s buffer-local while let-bound!",
1541 SDATA (SYMBOL_NAME (variable
)));
1545 blv
->local_if_set
= 1;
1549 DEFUN ("make-local-variable", Fmake_local_variable
, Smake_local_variable
,
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.\)
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.
1561 This function returns VARIABLE, and therefore
1562 (set (make-local-variable 'VARIABLE) VALUE-EXP)
1565 See also `make-variable-buffer-local'.
1567 Do not use `make-local-variable' to make a hook variable buffer-local.
1568 Instead, use `add-hook' and specify t for the LOCAL argument. */)
1569 (register Lisp_Object variable
)
1571 register Lisp_Object tem
;
1572 int forwarded
IF_LINT (= 0);
1573 union Lisp_Val_Fwd valcontents
IF_LINT (= {0});
1574 struct Lisp_Symbol
*sym
;
1575 struct Lisp_Buffer_Local_Value
*blv
= NULL
;
1577 CHECK_SYMBOL (variable
);
1578 sym
= XSYMBOL (variable
);
1581 switch (sym
->redirect
)
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
)));
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
)));
1602 error ("Symbol %s may not be buffer-local",
1603 SDATA (SYMBOL_NAME (variable
)));
1605 if (blv
? blv
->local_if_set
1606 : (forwarded
&& BUFFER_OBJFWDP (valcontents
.fwd
)))
1608 tem
= Fboundp (variable
);
1609 /* Make sure the symbol has a local value in this particular buffer,
1610 by setting it to the same value it already has. */
1611 Fset (variable
, (EQ (tem
, Qt
) ? Fsymbol_value (variable
) : Qunbound
));
1616 blv
= make_blv (sym
, forwarded
, valcontents
);
1617 sym
->redirect
= SYMBOL_LOCALIZED
;
1618 SET_SYMBOL_BLV (sym
, blv
);
1621 XSETSYMBOL (symbol
, sym
); /* In case `variable' is aliased. */
1622 if (let_shadows_global_binding_p (symbol
))
1623 message ("Making %s local to %s while let-bound!",
1624 SDATA (SYMBOL_NAME (variable
)),
1625 SDATA (BVAR (current_buffer
, name
)));
1629 /* Make sure this buffer has its own value of symbol. */
1630 XSETSYMBOL (variable
, sym
); /* Update in case of aliasing. */
1631 tem
= Fassq (variable
, BVAR (current_buffer
, local_var_alist
));
1634 if (let_shadows_buffer_binding_p (sym
))
1635 message ("Making %s buffer-local while locally let-bound!",
1636 SDATA (SYMBOL_NAME (variable
)));
1638 /* Swap out any local binding for some other buffer, and make
1639 sure the current value is permanently recorded, if it's the
1641 find_symbol_value (variable
);
1643 BVAR (current_buffer
, local_var_alist
)
1644 = Fcons (Fcons (variable
, XCDR (blv
->defcell
)),
1645 BVAR (current_buffer
, local_var_alist
));
1647 /* Make sure symbol does not think it is set up for this buffer;
1648 force it to look once again for this buffer's value. */
1649 if (current_buffer
== XBUFFER (blv
->where
))
1651 /* blv->valcell = blv->defcell;
1652 * SET_BLV_FOUND (blv, 0); */
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. */
1661 swap_in_symval_forwarding (sym
, blv
);
1666 DEFUN ("kill-local-variable", Fkill_local_variable
, Skill_local_variable
,
1667 1, 1, "vKill Local Variable: ",
1668 doc
: /* Make VARIABLE no longer have a separate value in the current buffer.
1669 From now on the default value will apply in this buffer. Return VARIABLE. */)
1670 (register Lisp_Object variable
)
1672 register Lisp_Object tem
;
1673 struct Lisp_Buffer_Local_Value
*blv
;
1674 struct Lisp_Symbol
*sym
;
1676 CHECK_SYMBOL (variable
);
1677 sym
= XSYMBOL (variable
);
1680 switch (sym
->redirect
)
1682 case SYMBOL_VARALIAS
: sym
= indirect_variable (sym
); goto start
;
1683 case SYMBOL_PLAINVAL
: return variable
;
1684 case SYMBOL_FORWARDED
:
1686 union Lisp_Fwd
*valcontents
= SYMBOL_FWD (sym
);
1687 if (BUFFER_OBJFWDP (valcontents
))
1689 int offset
= XBUFFER_OBJFWD (valcontents
)->offset
;
1690 int idx
= PER_BUFFER_IDX (offset
);
1694 SET_PER_BUFFER_VALUE_P (current_buffer
, idx
, 0);
1695 PER_BUFFER_VALUE (current_buffer
, offset
)
1696 = PER_BUFFER_DEFAULT (offset
);
1701 case SYMBOL_LOCALIZED
:
1702 blv
= SYMBOL_BLV (sym
);
1703 if (blv
->frame_local
)
1709 /* Get rid of this buffer's alist element, if any. */
1710 XSETSYMBOL (variable
, sym
); /* Propagate variable indirection. */
1711 tem
= Fassq (variable
, BVAR (current_buffer
, local_var_alist
));
1713 BVAR (current_buffer
, local_var_alist
)
1714 = Fdelq (tem
, BVAR (current_buffer
, local_var_alist
));
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. */
1720 Lisp_Object buf
; XSETBUFFER (buf
, current_buffer
);
1721 if (EQ (buf
, blv
->where
))
1724 /* blv->valcell = blv->defcell;
1725 * SET_BLV_FOUND (blv, 0); */
1727 find_symbol_value (variable
);
1734 /* Lisp functions for creating and removing buffer-local variables. */
1736 /* Obsolete since 22.2. NB adjust doc of modify-frame-parameters
1737 when/if this is removed. */
1739 DEFUN ("make-variable-frame-local", Fmake_variable_frame_local
, Smake_variable_frame_local
,
1740 1, 1, "vMake Variable Frame Local: ",
1741 doc
: /* Enable VARIABLE to have frame-local bindings.
1742 This does not create any frame-local bindings for VARIABLE,
1743 it just makes them possible.
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.
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.
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). */)
1758 (register Lisp_Object variable
)
1761 union Lisp_Val_Fwd valcontents
;
1762 struct Lisp_Symbol
*sym
;
1763 struct Lisp_Buffer_Local_Value
*blv
= NULL
;
1765 CHECK_SYMBOL (variable
);
1766 sym
= XSYMBOL (variable
);
1769 switch (sym
->redirect
)
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
;
1777 case SYMBOL_LOCALIZED
:
1778 if (SYMBOL_BLV (sym
)->frame_local
)
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
)));
1793 error ("Symbol %s may not be frame-local", SDATA (SYMBOL_NAME (variable
)));
1795 blv
= make_blv (sym
, forwarded
, valcontents
);
1796 blv
->frame_local
= 1;
1797 sym
->redirect
= SYMBOL_LOCALIZED
;
1798 SET_SYMBOL_BLV (sym
, blv
);
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
)));
1809 DEFUN ("local-variable-p", Flocal_variable_p
, Slocal_variable_p
,
1811 doc
: /* Non-nil if VARIABLE has a local binding in buffer BUFFER.
1812 BUFFER defaults to the current buffer. */)
1813 (register Lisp_Object variable
, Lisp_Object buffer
)
1815 register struct buffer
*buf
;
1816 struct Lisp_Symbol
*sym
;
1819 buf
= current_buffer
;
1822 CHECK_BUFFER (buffer
);
1823 buf
= XBUFFER (buffer
);
1826 CHECK_SYMBOL (variable
);
1827 sym
= XSYMBOL (variable
);
1830 switch (sym
->redirect
)
1832 case SYMBOL_VARALIAS
: sym
= indirect_variable (sym
); goto start
;
1833 case SYMBOL_PLAINVAL
: return Qnil
;
1834 case SYMBOL_LOCALIZED
:
1836 Lisp_Object tail
, elt
, tmp
;
1837 struct Lisp_Buffer_Local_Value
*blv
= SYMBOL_BLV (sym
);
1838 XSETBUFFER (tmp
, buf
);
1839 XSETSYMBOL (variable
, sym
); /* Update in case of aliasing. */
1841 for (tail
= BVAR (buf
, local_var_alist
); CONSP (tail
); tail
= XCDR (tail
))
1844 if (EQ (variable
, XCAR (elt
)))
1846 eassert (!blv
->frame_local
);
1847 eassert (BLV_FOUND (blv
) || !EQ (blv
->where
, tmp
));
1851 eassert (!BLV_FOUND (blv
) || !EQ (blv
->where
, tmp
));
1854 case SYMBOL_FORWARDED
:
1856 union Lisp_Fwd
*valcontents
= SYMBOL_FWD (sym
);
1857 if (BUFFER_OBJFWDP (valcontents
))
1859 int offset
= XBUFFER_OBJFWD (valcontents
)->offset
;
1860 int idx
= PER_BUFFER_IDX (offset
);
1861 if (idx
== -1 || PER_BUFFER_VALUE_P (buf
, idx
))
1870 DEFUN ("local-variable-if-set-p", Flocal_variable_if_set_p
, Slocal_variable_if_set_p
,
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'.
1877 BUFFER defaults to the current buffer. */)
1878 (register Lisp_Object variable
, Lisp_Object buffer
)
1880 struct Lisp_Symbol
*sym
;
1882 CHECK_SYMBOL (variable
);
1883 sym
= XSYMBOL (variable
);
1886 switch (sym
->redirect
)
1888 case SYMBOL_VARALIAS
: sym
= indirect_variable (sym
); goto start
;
1889 case SYMBOL_PLAINVAL
: return Qnil
;
1890 case SYMBOL_LOCALIZED
:
1892 struct Lisp_Buffer_Local_Value
*blv
= SYMBOL_BLV (sym
);
1893 if (blv
->local_if_set
)
1895 XSETSYMBOL (variable
, sym
); /* Update in case of aliasing. */
1896 return Flocal_variable_p (variable
, buffer
);
1898 case SYMBOL_FORWARDED
:
1899 /* All BUFFER_OBJFWD slots become local if they are set. */
1900 return (BUFFER_OBJFWDP (SYMBOL_FWD (sym
)) ? Qt
: Qnil
);
1905 DEFUN ("variable-binding-locus", Fvariable_binding_locus
, Svariable_binding_locus
,
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. */)
1911 (register Lisp_Object variable
)
1913 struct Lisp_Symbol
*sym
;
1915 CHECK_SYMBOL (variable
);
1916 sym
= XSYMBOL (variable
);
1918 /* Make sure the current binding is actually swapped in. */
1919 find_symbol_value (variable
);
1922 switch (sym
->redirect
)
1924 case SYMBOL_VARALIAS
: sym
= indirect_variable (sym
); goto start
;
1925 case SYMBOL_PLAINVAL
: return Qnil
;
1926 case SYMBOL_FORWARDED
:
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
))
1935 case SYMBOL_LOCALIZED
:
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 ();
1940 else if (sym
->redirect
== SYMBOL_LOCALIZED
1941 && BLV_FOUND (SYMBOL_BLV (sym
)))
1942 return SYMBOL_BLV (sym
)->where
;
1949 /* This code is disabled now that we use the selected frame to return
1950 keyboard-local-values. */
1952 extern struct terminal
*get_terminal (Lisp_Object display
, int);
1954 DEFUN ("terminal-local-value", Fterminal_local_value
,
1955 Sterminal_local_value
, 2, 2, 0,
1956 doc
: /* Return the terminal-local value of SYMBOL on TERMINAL.
1957 If SYMBOL is not a terminal-local variable, then return its normal
1958 value, like `symbol-value'.
1960 TERMINAL may be a terminal object, a frame, or nil (meaning the
1961 selected frame's terminal device). */)
1962 (Lisp_Object symbol
, Lisp_Object terminal
)
1965 struct terminal
*t
= get_terminal (terminal
, 1);
1966 push_kboard (t
->kboard
);
1967 result
= Fsymbol_value (symbol
);
1972 DEFUN ("set-terminal-local-value", Fset_terminal_local_value
,
1973 Sset_terminal_local_value
, 3, 3, 0,
1974 doc
: /* Set the terminal-local binding of SYMBOL on TERMINAL to VALUE.
1975 If VARIABLE is not a terminal-local variable, then set its normal
1976 binding, like `set'.
1978 TERMINAL may be a terminal object, a frame, or nil (meaning the
1979 selected frame's terminal device). */)
1980 (Lisp_Object symbol
, Lisp_Object terminal
, Lisp_Object value
)
1983 struct terminal
*t
= get_terminal (terminal
, 1);
1984 push_kboard (d
->kboard
);
1985 result
= Fset (symbol
, value
);
1991 /* Find the function at the end of a chain of symbol function indirections. */
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.
1998 This is like Findirect_function, except that it doesn't signal an
1999 error if the chain ends up unbound. */
2001 indirect_function (register Lisp_Object object
)
2003 Lisp_Object tortoise
, hare
;
2005 hare
= tortoise
= object
;
2009 if (!SYMBOLP (hare
) || EQ (hare
, Qunbound
))
2011 hare
= XSYMBOL (hare
)->function
;
2012 if (!SYMBOLP (hare
) || EQ (hare
, Qunbound
))
2014 hare
= XSYMBOL (hare
)->function
;
2016 tortoise
= XSYMBOL (tortoise
)->function
;
2018 if (EQ (hare
, tortoise
))
2019 xsignal1 (Qcyclic_function_indirection
, object
);
2025 DEFUN ("indirect-function", Findirect_function
, Sindirect_function
, 1, 2, 0,
2026 doc
: /* Return the function at the end of OBJECT's function chain.
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.
2031 Signal a cyclic-function-indirection error if there is a loop in the
2032 function chain of symbols. */)
2033 (register Lisp_Object object
, Lisp_Object noerror
)
2037 /* Optimize for no indirection. */
2039 if (SYMBOLP (result
) && !EQ (result
, Qunbound
)
2040 && (result
= XSYMBOL (result
)->function
, SYMBOLP (result
)))
2041 result
= indirect_function (result
);
2042 if (!EQ (result
, Qunbound
))
2046 xsignal1 (Qvoid_function
, object
);
2051 /* Extract and set vector and string elements */
2053 DEFUN ("aref", Faref
, Saref
, 2, 2, 0,
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. */)
2057 (register Lisp_Object array
, Lisp_Object idx
)
2059 register EMACS_INT idxval
;
2062 idxval
= XINT (idx
);
2063 if (STRINGP (array
))
2066 EMACS_INT idxval_byte
;
2068 if (idxval
< 0 || idxval
>= SCHARS (array
))
2069 args_out_of_range (array
, idx
);
2070 if (! STRING_MULTIBYTE (array
))
2071 return make_number ((unsigned char) SREF (array
, idxval
));
2072 idxval_byte
= string_char_to_byte (array
, idxval
);
2074 c
= STRING_CHAR (SDATA (array
) + idxval_byte
);
2075 return make_number (c
);
2077 else if (BOOL_VECTOR_P (array
))
2081 if (idxval
< 0 || idxval
>= XBOOL_VECTOR (array
)->size
)
2082 args_out_of_range (array
, idx
);
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
);
2087 else if (CHAR_TABLE_P (array
))
2089 CHECK_CHARACTER (idx
);
2090 return CHAR_TABLE_REF (array
, idxval
);
2095 if (VECTORP (array
))
2096 size
= ASIZE (array
);
2097 else if (COMPILEDP (array
))
2098 size
= ASIZE (array
) & PSEUDOVECTOR_SIZE_MASK
;
2100 wrong_type_argument (Qarrayp
, array
);
2102 if (idxval
< 0 || idxval
>= size
)
2103 args_out_of_range (array
, idx
);
2104 return AREF (array
, idxval
);
2108 DEFUN ("aset", Faset
, Saset
, 3, 3, 0,
2109 doc
: /* Store into the element of ARRAY at index IDX the value NEWELT.
2110 Return NEWELT. ARRAY may be a vector, a string, a char-table or a
2111 bool-vector. IDX starts at 0. */)
2112 (register Lisp_Object array
, Lisp_Object idx
, Lisp_Object newelt
)
2114 register EMACS_INT idxval
;
2117 idxval
= XINT (idx
);
2118 CHECK_ARRAY (array
, Qarrayp
);
2119 CHECK_IMPURE (array
);
2121 if (VECTORP (array
))
2123 if (idxval
< 0 || idxval
>= ASIZE (array
))
2124 args_out_of_range (array
, idx
);
2125 XVECTOR (array
)->contents
[idxval
] = newelt
;
2127 else if (BOOL_VECTOR_P (array
))
2131 if (idxval
< 0 || idxval
>= XBOOL_VECTOR (array
)->size
)
2132 args_out_of_range (array
, idx
);
2134 val
= (unsigned char) XBOOL_VECTOR (array
)->data
[idxval
/ BOOL_VECTOR_BITS_PER_CHAR
];
2136 if (! NILP (newelt
))
2137 val
|= 1 << (idxval
% BOOL_VECTOR_BITS_PER_CHAR
);
2139 val
&= ~(1 << (idxval
% BOOL_VECTOR_BITS_PER_CHAR
));
2140 XBOOL_VECTOR (array
)->data
[idxval
/ BOOL_VECTOR_BITS_PER_CHAR
] = val
;
2142 else if (CHAR_TABLE_P (array
))
2144 CHECK_CHARACTER (idx
);
2145 CHAR_TABLE_SET (array
, idxval
, newelt
);
2147 else if (STRING_MULTIBYTE (array
))
2149 EMACS_INT idxval_byte
, prev_bytes
, new_bytes
, nbytes
;
2150 unsigned char workbuf
[MAX_MULTIBYTE_LENGTH
], *p0
= workbuf
, *p1
;
2152 if (idxval
< 0 || idxval
>= SCHARS (array
))
2153 args_out_of_range (array
, idx
);
2154 CHECK_CHARACTER (newelt
);
2156 nbytes
= SBYTES (array
);
2158 idxval_byte
= string_char_to_byte (array
, idxval
);
2159 p1
= SDATA (array
) + idxval_byte
;
2160 prev_bytes
= BYTES_BY_CHAR_HEAD (*p1
);
2161 new_bytes
= CHAR_STRING (XINT (newelt
), p0
);
2162 if (prev_bytes
!= new_bytes
)
2164 /* We must relocate the string data. */
2165 EMACS_INT nchars
= SCHARS (array
);
2169 SAFE_ALLOCA (str
, unsigned char *, nbytes
);
2170 memcpy (str
, SDATA (array
), nbytes
);
2171 allocate_string_data (XSTRING (array
), nchars
,
2172 nbytes
+ new_bytes
- prev_bytes
);
2173 memcpy (SDATA (array
), str
, idxval_byte
);
2174 p1
= SDATA (array
) + idxval_byte
;
2175 memcpy (p1
+ new_bytes
, str
+ idxval_byte
+ prev_bytes
,
2176 nbytes
- (idxval_byte
+ prev_bytes
));
2178 clear_string_char_byte_cache ();
2185 if (idxval
< 0 || idxval
>= SCHARS (array
))
2186 args_out_of_range (array
, idx
);
2187 CHECK_NUMBER (newelt
);
2189 if (XINT (newelt
) >= 0 && ! SINGLE_BYTE_CHAR_P (XINT (newelt
)))
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
);
2201 SSET (array
, idxval
, XINT (newelt
));
2207 /* Arithmetic functions */
2209 enum comparison
{ equal
, notequal
, less
, grtr
, less_or_equal
, grtr_or_equal
};
2212 arithcompare (Lisp_Object num1
, Lisp_Object num2
, enum comparison comparison
)
2214 double f1
= 0, f2
= 0;
2217 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (num1
);
2218 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (num2
);
2220 if (FLOATP (num1
) || FLOATP (num2
))
2223 f1
= (FLOATP (num1
)) ? XFLOAT_DATA (num1
) : XINT (num1
);
2224 f2
= (FLOATP (num2
)) ? XFLOAT_DATA (num2
) : XINT (num2
);
2230 if (floatp
? f1
== f2
: XINT (num1
) == XINT (num2
))
2235 if (floatp
? f1
!= f2
: XINT (num1
) != XINT (num2
))
2240 if (floatp
? f1
< f2
: XINT (num1
) < XINT (num2
))
2245 if (floatp
? f1
<= f2
: XINT (num1
) <= XINT (num2
))
2250 if (floatp
? f1
> f2
: XINT (num1
) > XINT (num2
))
2255 if (floatp
? f1
>= f2
: XINT (num1
) >= XINT (num2
))
2264 DEFUN ("=", Feqlsign
, Seqlsign
, 2, 2, 0,
2265 doc
: /* Return t if two args, both numbers or markers, are equal. */)
2266 (register Lisp_Object num1
, Lisp_Object num2
)
2268 return arithcompare (num1
, num2
, equal
);
2271 DEFUN ("<", Flss
, Slss
, 2, 2, 0,
2272 doc
: /* Return t if first arg is less than second arg. Both must be numbers or markers. */)
2273 (register Lisp_Object num1
, Lisp_Object num2
)
2275 return arithcompare (num1
, num2
, less
);
2278 DEFUN (">", Fgtr
, Sgtr
, 2, 2, 0,
2279 doc
: /* Return t if first arg is greater than second arg. Both must be numbers or markers. */)
2280 (register Lisp_Object num1
, Lisp_Object num2
)
2282 return arithcompare (num1
, num2
, grtr
);
2285 DEFUN ("<=", Fleq
, Sleq
, 2, 2, 0,
2286 doc
: /* Return t if first arg is less than or equal to second arg.
2287 Both must be numbers or markers. */)
2288 (register Lisp_Object num1
, Lisp_Object num2
)
2290 return arithcompare (num1
, num2
, less_or_equal
);
2293 DEFUN (">=", Fgeq
, Sgeq
, 2, 2, 0,
2294 doc
: /* Return t if first arg is greater than or equal to second arg.
2295 Both must be numbers or markers. */)
2296 (register Lisp_Object num1
, Lisp_Object num2
)
2298 return arithcompare (num1
, num2
, grtr_or_equal
);
2301 DEFUN ("/=", Fneq
, Sneq
, 2, 2, 0,
2302 doc
: /* Return t if first arg is not equal to second arg. Both must be numbers or markers. */)
2303 (register Lisp_Object num1
, Lisp_Object num2
)
2305 return arithcompare (num1
, num2
, notequal
);
2308 DEFUN ("zerop", Fzerop
, Szerop
, 1, 1, 0,
2309 doc
: /* Return t if NUMBER is zero. */)
2310 (register Lisp_Object number
)
2312 CHECK_NUMBER_OR_FLOAT (number
);
2314 if (FLOATP (number
))
2316 if (XFLOAT_DATA (number
) == 0.0)
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. */
2331 long_to_cons (long unsigned int i
)
2333 unsigned long top
= i
>> 16;
2334 unsigned int bot
= i
& 0xFFFF;
2336 return make_number (bot
);
2337 if (top
== (unsigned long)-1 >> 16)
2338 return Fcons (make_number (-1), make_number (bot
));
2339 return Fcons (make_number (top
), make_number (bot
));
2343 cons_to_long (Lisp_Object c
)
2345 Lisp_Object top
, bot
;
2352 return ((XINT (top
) << 16) | XINT (bot
));
2355 DEFUN ("number-to-string", Fnumber_to_string
, Snumber_to_string
, 1, 1, 0,
2356 doc
: /* Return the decimal representation of NUMBER as a string.
2357 Uses a minus sign if negative.
2358 NUMBER may be an integer or a floating point number. */)
2359 (Lisp_Object number
)
2361 char buffer
[VALBITS
];
2363 CHECK_NUMBER_OR_FLOAT (number
);
2365 if (FLOATP (number
))
2367 char pigbuf
[FLOAT_TO_STRING_BUFSIZE
];
2369 float_to_string (pigbuf
, XFLOAT_DATA (number
));
2370 return build_string (pigbuf
);
2373 sprintf (buffer
, "%"pI
"d", XINT (number
));
2374 return build_string (buffer
);
2377 DEFUN ("string-to-number", Fstring_to_number
, Sstring_to_number
, 1, 2, 0,
2378 doc
: /* Parse STRING as a decimal number and return the number.
2379 This parses both integers and floating point numbers.
2380 It ignores leading spaces and tabs, and all trailing chars.
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).
2384 If the base used is not 10, STRING is always parsed as integer. */)
2385 (register Lisp_Object string
, Lisp_Object base
)
2391 CHECK_STRING (string
);
2397 CHECK_NUMBER (base
);
2399 if (b
< 2 || b
> 16)
2400 xsignal1 (Qargs_out_of_range
, base
);
2403 p
= SSDATA (string
);
2404 while (*p
== ' ' || *p
== '\t')
2407 val
= string_to_number (p
, b
, 1);
2408 return NILP (val
) ? make_number (0) : val
;
2424 static Lisp_Object
float_arith_driver (double, size_t, enum arithop
,
2425 size_t, Lisp_Object
*);
2427 arith_driver (enum arithop code
, size_t nargs
, register Lisp_Object
*args
)
2429 register Lisp_Object val
;
2430 register size_t argnum
;
2431 register EMACS_INT accum
= 0;
2432 register EMACS_INT next
;
2434 switch (SWITCH_ENUM_CAST (code
))
2452 for (argnum
= 0; argnum
< nargs
; argnum
++)
2454 /* Using args[argnum] as argument to CHECK_NUMBER_... */
2456 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (val
);
2459 return float_arith_driver ((double) accum
, argnum
, code
,
2462 next
= XINT (args
[argnum
]);
2463 switch (SWITCH_ENUM_CAST (code
))
2469 accum
= argnum
? accum
- next
: nargs
== 1 ? - next
: next
;
2480 xsignal0 (Qarith_error
);
2494 if (!argnum
|| next
> accum
)
2498 if (!argnum
|| next
< accum
)
2504 XSETINT (val
, accum
);
2509 #define isnan(x) ((x) != (x))
2512 float_arith_driver (double accum
, register size_t argnum
, enum arithop code
,
2513 size_t nargs
, register Lisp_Object
*args
)
2515 register Lisp_Object val
;
2518 for (; argnum
< nargs
; argnum
++)
2520 val
= args
[argnum
]; /* using args[argnum] as argument to CHECK_NUMBER_... */
2521 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (val
);
2525 next
= XFLOAT_DATA (val
);
2529 args
[argnum
] = val
; /* runs into a compiler bug. */
2530 next
= XINT (args
[argnum
]);
2532 switch (SWITCH_ENUM_CAST (code
))
2538 accum
= argnum
? accum
- next
: nargs
== 1 ? - next
: next
;
2548 if (! IEEE_FLOATING_POINT
&& next
== 0)
2549 xsignal0 (Qarith_error
);
2556 return wrong_type_argument (Qinteger_or_marker_p
, val
);
2558 if (!argnum
|| isnan (next
) || next
> accum
)
2562 if (!argnum
|| isnan (next
) || next
< accum
)
2568 return make_float (accum
);
2572 DEFUN ("+", Fplus
, Splus
, 0, MANY
, 0,
2573 doc
: /* Return sum of any number of arguments, which are numbers or markers.
2574 usage: (+ &rest NUMBERS-OR-MARKERS) */)
2575 (size_t nargs
, Lisp_Object
*args
)
2577 return arith_driver (Aadd
, nargs
, args
);
2580 DEFUN ("-", Fminus
, Sminus
, 0, MANY
, 0,
2581 doc
: /* Negate number or subtract numbers or markers and return the result.
2582 With one arg, negates it. With more than one arg,
2583 subtracts all but the first from the first.
2584 usage: (- &optional NUMBER-OR-MARKER &rest MORE-NUMBERS-OR-MARKERS) */)
2585 (size_t nargs
, Lisp_Object
*args
)
2587 return arith_driver (Asub
, nargs
, args
);
2590 DEFUN ("*", Ftimes
, Stimes
, 0, MANY
, 0,
2591 doc
: /* Return product of any number of arguments, which are numbers or markers.
2592 usage: (* &rest NUMBERS-OR-MARKERS) */)
2593 (size_t nargs
, Lisp_Object
*args
)
2595 return arith_driver (Amult
, nargs
, args
);
2598 DEFUN ("/", Fquo
, Squo
, 2, MANY
, 0,
2599 doc
: /* Return first argument divided by all the remaining arguments.
2600 The arguments must be numbers or markers.
2601 usage: (/ DIVIDEND DIVISOR &rest DIVISORS) */)
2602 (size_t nargs
, Lisp_Object
*args
)
2605 for (argnum
= 2; argnum
< nargs
; argnum
++)
2606 if (FLOATP (args
[argnum
]))
2607 return float_arith_driver (0, 0, Adiv
, nargs
, args
);
2608 return arith_driver (Adiv
, nargs
, args
);
2611 DEFUN ("%", Frem
, Srem
, 2, 2, 0,
2612 doc
: /* Return remainder of X divided by Y.
2613 Both must be integers or markers. */)
2614 (register Lisp_Object x
, Lisp_Object y
)
2618 CHECK_NUMBER_COERCE_MARKER (x
);
2619 CHECK_NUMBER_COERCE_MARKER (y
);
2621 if (XFASTINT (y
) == 0)
2622 xsignal0 (Qarith_error
);
2624 XSETINT (val
, XINT (x
) % XINT (y
));
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. */
2644 r
-= f2
* floor (r
/ f2
);
2645 while (f2
<= (r
< 0 ? -r
: r
) || ((r
< 0) != (f1
< 0) && ! isnan (r
)));
2649 #endif /* ! HAVE_FMOD */
2651 DEFUN ("mod", Fmod
, Smod
, 2, 2, 0,
2652 doc
: /* Return X modulo Y.
2653 The result falls between zero (inclusive) and Y (exclusive).
2654 Both X and Y must be numbers or markers. */)
2655 (register Lisp_Object x
, Lisp_Object y
)
2660 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (x
);
2661 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (y
);
2663 if (FLOATP (x
) || FLOATP (y
))
2664 return fmod_float (x
, y
);
2670 xsignal0 (Qarith_error
);
2674 /* If the "remainder" comes out with the wrong sign, fix it. */
2675 if (i2
< 0 ? i1
> 0 : i1
< 0)
2682 DEFUN ("max", Fmax
, Smax
, 1, MANY
, 0,
2683 doc
: /* Return largest of all the arguments (which must be numbers or markers).
2684 The value is always a number; markers are converted to numbers.
2685 usage: (max NUMBER-OR-MARKER &rest NUMBERS-OR-MARKERS) */)
2686 (size_t nargs
, Lisp_Object
*args
)
2688 return arith_driver (Amax
, nargs
, args
);
2691 DEFUN ("min", Fmin
, Smin
, 1, MANY
, 0,
2692 doc
: /* Return smallest of all the arguments (which must be numbers or markers).
2693 The value is always a number; markers are converted to numbers.
2694 usage: (min NUMBER-OR-MARKER &rest NUMBERS-OR-MARKERS) */)
2695 (size_t nargs
, Lisp_Object
*args
)
2697 return arith_driver (Amin
, nargs
, args
);
2700 DEFUN ("logand", Flogand
, Slogand
, 0, MANY
, 0,
2701 doc
: /* Return bitwise-and of all the arguments.
2702 Arguments may be integers, or markers converted to integers.
2703 usage: (logand &rest INTS-OR-MARKERS) */)
2704 (size_t nargs
, Lisp_Object
*args
)
2706 return arith_driver (Alogand
, nargs
, args
);
2709 DEFUN ("logior", Flogior
, Slogior
, 0, MANY
, 0,
2710 doc
: /* Return bitwise-or of all the arguments.
2711 Arguments may be integers, or markers converted to integers.
2712 usage: (logior &rest INTS-OR-MARKERS) */)
2713 (size_t nargs
, Lisp_Object
*args
)
2715 return arith_driver (Alogior
, nargs
, args
);
2718 DEFUN ("logxor", Flogxor
, Slogxor
, 0, MANY
, 0,
2719 doc
: /* Return bitwise-exclusive-or of all the arguments.
2720 Arguments may be integers, or markers converted to integers.
2721 usage: (logxor &rest INTS-OR-MARKERS) */)
2722 (size_t nargs
, Lisp_Object
*args
)
2724 return arith_driver (Alogxor
, nargs
, args
);
2727 DEFUN ("ash", Fash
, Sash
, 2, 2, 0,
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. */)
2731 (register Lisp_Object value
, Lisp_Object count
)
2733 register Lisp_Object val
;
2735 CHECK_NUMBER (value
);
2736 CHECK_NUMBER (count
);
2738 if (XINT (count
) >= BITS_PER_EMACS_INT
)
2740 else if (XINT (count
) > 0)
2741 XSETINT (val
, XINT (value
) << XFASTINT (count
));
2742 else if (XINT (count
) <= -BITS_PER_EMACS_INT
)
2743 XSETINT (val
, XINT (value
) < 0 ? -1 : 0);
2745 XSETINT (val
, XINT (value
) >> -XINT (count
));
2749 DEFUN ("lsh", Flsh
, Slsh
, 2, 2, 0,
2750 doc
: /* Return VALUE with its bits shifted left by COUNT.
2751 If COUNT is negative, shifting is actually to the right.
2752 In this case, zeros are shifted in on the left. */)
2753 (register Lisp_Object value
, Lisp_Object count
)
2755 register Lisp_Object val
;
2757 CHECK_NUMBER (value
);
2758 CHECK_NUMBER (count
);
2760 if (XINT (count
) >= BITS_PER_EMACS_INT
)
2762 else if (XINT (count
) > 0)
2763 XSETINT (val
, (EMACS_UINT
) XUINT (value
) << XFASTINT (count
));
2764 else if (XINT (count
) <= -BITS_PER_EMACS_INT
)
2767 XSETINT (val
, (EMACS_UINT
) XUINT (value
) >> -XINT (count
));
2771 DEFUN ("1+", Fadd1
, Sadd1
, 1, 1, 0,
2772 doc
: /* Return NUMBER plus one. NUMBER may be a number or a marker.
2773 Markers are converted to integers. */)
2774 (register Lisp_Object number
)
2776 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (number
);
2778 if (FLOATP (number
))
2779 return (make_float (1.0 + XFLOAT_DATA (number
)));
2781 XSETINT (number
, XINT (number
) + 1);
2785 DEFUN ("1-", Fsub1
, Ssub1
, 1, 1, 0,
2786 doc
: /* Return NUMBER minus one. NUMBER may be a number or a marker.
2787 Markers are converted to integers. */)
2788 (register Lisp_Object number
)
2790 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (number
);
2792 if (FLOATP (number
))
2793 return (make_float (-1.0 + XFLOAT_DATA (number
)));
2795 XSETINT (number
, XINT (number
) - 1);
2799 DEFUN ("lognot", Flognot
, Slognot
, 1, 1, 0,
2800 doc
: /* Return the bitwise complement of NUMBER. NUMBER must be an integer. */)
2801 (register Lisp_Object number
)
2803 CHECK_NUMBER (number
);
2804 XSETINT (number
, ~XINT (number
));
2808 DEFUN ("byteorder", Fbyteorder
, Sbyteorder
, 0, 0, 0,
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. */)
2814 unsigned i
= 0x04030201;
2815 int order
= *(char *)&i
== 1 ? 108 : 66;
2817 return make_number (order
);
2825 Lisp_Object error_tail
, arith_tail
;
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");
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");
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");
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");
2875 Qfloatp
= intern_c_string ("floatp");
2876 Qnumberp
= intern_c_string ("numberp");
2877 Qnumber_or_marker_p
= intern_c_string ("number-or-marker-p");
2879 Qchar_table_p
= intern_c_string ("char-table-p");
2880 Qvector_or_char_table_p
= intern_c_string ("vector-or-char-table-p");
2882 Qsubrp
= intern_c_string ("subrp");
2883 Qunevalled
= intern_c_string ("unevalled");
2884 Qmany
= intern_c_string ("many");
2886 Qcdr
= intern_c_string ("cdr");
2888 /* Handle automatic advice activation */
2889 Qad_advice_info
= intern_c_string ("ad-advice-info");
2890 Qad_activate_internal
= intern_c_string ("ad-activate-internal");
2892 error_tail
= pure_cons (Qerror
, Qnil
);
2894 /* ERROR is used as a signaler for random errors for which nothing else is right */
2896 Fput (Qerror
, Qerror_conditions
,
2898 Fput (Qerror
, Qerror_message
,
2899 make_pure_c_string ("error"));
2901 Fput (Qquit
, Qerror_conditions
,
2902 pure_cons (Qquit
, Qnil
));
2903 Fput (Qquit
, Qerror_message
,
2904 make_pure_c_string ("Quit"));
2906 Fput (Qwrong_type_argument
, Qerror_conditions
,
2907 pure_cons (Qwrong_type_argument
, error_tail
));
2908 Fput (Qwrong_type_argument
, Qerror_message
,
2909 make_pure_c_string ("Wrong type argument"));
2911 Fput (Qargs_out_of_range
, Qerror_conditions
,
2912 pure_cons (Qargs_out_of_range
, error_tail
));
2913 Fput (Qargs_out_of_range
, Qerror_message
,
2914 make_pure_c_string ("Args out of range"));
2916 Fput (Qvoid_function
, Qerror_conditions
,
2917 pure_cons (Qvoid_function
, error_tail
));
2918 Fput (Qvoid_function
, Qerror_message
,
2919 make_pure_c_string ("Symbol's function definition is void"));
2921 Fput (Qcyclic_function_indirection
, Qerror_conditions
,
2922 pure_cons (Qcyclic_function_indirection
, error_tail
));
2923 Fput (Qcyclic_function_indirection
, Qerror_message
,
2924 make_pure_c_string ("Symbol's chain of function indirections contains a loop"));
2926 Fput (Qcyclic_variable_indirection
, Qerror_conditions
,
2927 pure_cons (Qcyclic_variable_indirection
, error_tail
));
2928 Fput (Qcyclic_variable_indirection
, Qerror_message
,
2929 make_pure_c_string ("Symbol's chain of variable indirections contains a loop"));
2931 Qcircular_list
= intern_c_string ("circular-list");
2932 staticpro (&Qcircular_list
);
2933 Fput (Qcircular_list
, Qerror_conditions
,
2934 pure_cons (Qcircular_list
, error_tail
));
2935 Fput (Qcircular_list
, Qerror_message
,
2936 make_pure_c_string ("List contains a loop"));
2938 Fput (Qvoid_variable
, Qerror_conditions
,
2939 pure_cons (Qvoid_variable
, error_tail
));
2940 Fput (Qvoid_variable
, Qerror_message
,
2941 make_pure_c_string ("Symbol's value as variable is void"));
2943 Fput (Qsetting_constant
, Qerror_conditions
,
2944 pure_cons (Qsetting_constant
, error_tail
));
2945 Fput (Qsetting_constant
, Qerror_message
,
2946 make_pure_c_string ("Attempt to set a constant symbol"));
2948 Fput (Qinvalid_read_syntax
, Qerror_conditions
,
2949 pure_cons (Qinvalid_read_syntax
, error_tail
));
2950 Fput (Qinvalid_read_syntax
, Qerror_message
,
2951 make_pure_c_string ("Invalid read syntax"));
2953 Fput (Qinvalid_function
, Qerror_conditions
,
2954 pure_cons (Qinvalid_function
, error_tail
));
2955 Fput (Qinvalid_function
, Qerror_message
,
2956 make_pure_c_string ("Invalid function"));
2958 Fput (Qwrong_number_of_arguments
, Qerror_conditions
,
2959 pure_cons (Qwrong_number_of_arguments
, error_tail
));
2960 Fput (Qwrong_number_of_arguments
, Qerror_message
,
2961 make_pure_c_string ("Wrong number of arguments"));
2963 Fput (Qno_catch
, Qerror_conditions
,
2964 pure_cons (Qno_catch
, error_tail
));
2965 Fput (Qno_catch
, Qerror_message
,
2966 make_pure_c_string ("No catch for tag"));
2968 Fput (Qend_of_file
, Qerror_conditions
,
2969 pure_cons (Qend_of_file
, error_tail
));
2970 Fput (Qend_of_file
, Qerror_message
,
2971 make_pure_c_string ("End of file during parsing"));
2973 arith_tail
= pure_cons (Qarith_error
, error_tail
);
2974 Fput (Qarith_error
, Qerror_conditions
,
2976 Fput (Qarith_error
, Qerror_message
,
2977 make_pure_c_string ("Arithmetic error"));
2979 Fput (Qbeginning_of_buffer
, Qerror_conditions
,
2980 pure_cons (Qbeginning_of_buffer
, error_tail
));
2981 Fput (Qbeginning_of_buffer
, Qerror_message
,
2982 make_pure_c_string ("Beginning of buffer"));
2984 Fput (Qend_of_buffer
, Qerror_conditions
,
2985 pure_cons (Qend_of_buffer
, error_tail
));
2986 Fput (Qend_of_buffer
, Qerror_message
,
2987 make_pure_c_string ("End of buffer"));
2989 Fput (Qbuffer_read_only
, Qerror_conditions
,
2990 pure_cons (Qbuffer_read_only
, error_tail
));
2991 Fput (Qbuffer_read_only
, Qerror_message
,
2992 make_pure_c_string ("Buffer is read-only"));
2994 Fput (Qtext_read_only
, Qerror_conditions
,
2995 pure_cons (Qtext_read_only
, error_tail
));
2996 Fput (Qtext_read_only
, Qerror_message
,
2997 make_pure_c_string ("Text is read-only"));
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");
3005 Fput (Qdomain_error
, Qerror_conditions
,
3006 pure_cons (Qdomain_error
, arith_tail
));
3007 Fput (Qdomain_error
, Qerror_message
,
3008 make_pure_c_string ("Arithmetic domain error"));
3010 Fput (Qrange_error
, Qerror_conditions
,
3011 pure_cons (Qrange_error
, arith_tail
));
3012 Fput (Qrange_error
, Qerror_message
,
3013 make_pure_c_string ("Arithmetic range error"));
3015 Fput (Qsingularity_error
, Qerror_conditions
,
3016 pure_cons (Qsingularity_error
, Fcons (Qdomain_error
, arith_tail
)));
3017 Fput (Qsingularity_error
, Qerror_message
,
3018 make_pure_c_string ("Arithmetic singularity error"));
3020 Fput (Qoverflow_error
, Qerror_conditions
,
3021 pure_cons (Qoverflow_error
, Fcons (Qdomain_error
, arith_tail
)));
3022 Fput (Qoverflow_error
, Qerror_message
,
3023 make_pure_c_string ("Arithmetic overflow error"));
3025 Fput (Qunderflow_error
, Qerror_conditions
,
3026 pure_cons (Qunderflow_error
, Fcons (Qdomain_error
, arith_tail
)));
3027 Fput (Qunderflow_error
, Qerror_message
,
3028 make_pure_c_string ("Arithmetic underflow error"));
3030 staticpro (&Qrange_error
);
3031 staticpro (&Qdomain_error
);
3032 staticpro (&Qsingularity_error
);
3033 staticpro (&Qoverflow_error
);
3034 staticpro (&Qunderflow_error
);
3038 staticpro (&Qquote
);
3039 staticpro (&Qlambda
);
3041 staticpro (&Qunbound
);
3042 staticpro (&Qerror_conditions
);
3043 staticpro (&Qerror_message
);
3044 staticpro (&Qtop_level
);
3046 staticpro (&Qerror
);
3048 staticpro (&Qwrong_type_argument
);
3049 staticpro (&Qargs_out_of_range
);
3050 staticpro (&Qvoid_function
);
3051 staticpro (&Qcyclic_function_indirection
);
3052 staticpro (&Qcyclic_variable_indirection
);
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
);
3064 staticpro (&Qtext_read_only
);
3065 staticpro (&Qmark_inactive
);
3067 staticpro (&Qlistp
);
3068 staticpro (&Qconsp
);
3069 staticpro (&Qsymbolp
);
3070 staticpro (&Qkeywordp
);
3071 staticpro (&Qintegerp
);
3072 staticpro (&Qnatnump
);
3073 staticpro (&Qwholenump
);
3074 staticpro (&Qstringp
);
3075 staticpro (&Qarrayp
);
3076 staticpro (&Qsequencep
);
3077 staticpro (&Qbufferp
);
3078 staticpro (&Qvectorp
);
3079 staticpro (&Qchar_or_string_p
);
3080 staticpro (&Qmarkerp
);
3081 staticpro (&Qbuffer_or_string_p
);
3082 staticpro (&Qinteger_or_marker_p
);
3083 staticpro (&Qfloatp
);
3084 staticpro (&Qnumberp
);
3085 staticpro (&Qnumber_or_marker_p
);
3086 staticpro (&Qchar_table_p
);
3087 staticpro (&Qvector_or_char_table_p
);
3088 staticpro (&Qsubrp
);
3090 staticpro (&Qunevalled
);
3092 staticpro (&Qboundp
);
3093 staticpro (&Qfboundp
);
3095 staticpro (&Qad_advice_info
);
3096 staticpro (&Qad_activate_internal
);
3098 /* Types that type-of returns. */
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");
3118 DEFSYM (Qfont_spec
, "font-spec");
3119 DEFSYM (Qfont_entity
, "font-entity");
3120 DEFSYM (Qfont_object
, "font-object");
3122 DEFSYM (Qinteractive_form
, "interactive-form");
3124 staticpro (&Qinteger
);
3125 staticpro (&Qsymbol
);
3126 staticpro (&Qstring
);
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
);
3139 staticpro (&Qchar_table
);
3140 staticpro (&Qbool_vector
);
3141 staticpro (&Qhash_table
);
3143 defsubr (&Sindirect_variable
);
3144 defsubr (&Sinteractive_form
);
3147 defsubr (&Stype_of
);
3152 defsubr (&Sintegerp
);
3153 defsubr (&Sinteger_or_marker_p
);
3154 defsubr (&Snumberp
);
3155 defsubr (&Snumber_or_marker_p
);
3157 defsubr (&Snatnump
);
3158 defsubr (&Ssymbolp
);
3159 defsubr (&Skeywordp
);
3160 defsubr (&Sstringp
);
3161 defsubr (&Smultibyte_string_p
);
3162 defsubr (&Svectorp
);
3163 defsubr (&Schar_table_p
);
3164 defsubr (&Svector_or_char_table_p
);
3165 defsubr (&Sbool_vector_p
);
3167 defsubr (&Ssequencep
);
3168 defsubr (&Sbufferp
);
3169 defsubr (&Smarkerp
);
3171 defsubr (&Sbyte_code_function_p
);
3172 defsubr (&Schar_or_string_p
);
3175 defsubr (&Scar_safe
);
3176 defsubr (&Scdr_safe
);
3179 defsubr (&Ssymbol_function
);
3180 defsubr (&Sindirect_function
);
3181 defsubr (&Ssymbol_plist
);
3182 defsubr (&Ssymbol_name
);
3183 defsubr (&Smakunbound
);
3184 defsubr (&Sfmakunbound
);
3186 defsubr (&Sfboundp
);
3188 defsubr (&Sdefalias
);
3189 defsubr (&Ssetplist
);
3190 defsubr (&Ssymbol_value
);
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
);
3199 defsubr (&Smake_variable_frame_local
);
3200 defsubr (&Slocal_variable_p
);
3201 defsubr (&Slocal_variable_if_set_p
);
3202 defsubr (&Svariable_binding_locus
);
3203 #if 0 /* XXX Remove this. --lorentey */
3204 defsubr (&Sterminal_local_value
);
3205 defsubr (&Sset_terminal_local_value
);
3209 defsubr (&Snumber_to_string
);
3210 defsubr (&Sstring_to_number
);
3211 defsubr (&Seqlsign
);
3234 defsubr (&Sbyteorder
);
3235 defsubr (&Ssubr_arity
);
3236 defsubr (&Ssubr_name
);
3238 XSYMBOL (Qwholenump
)->function
= XSYMBOL (Qnatnump
)->function
;
3240 DEFVAR_LISP ("most-positive-fixnum", Vmost_positive_fixnum
,
3241 doc
: /* The largest value that is representable in a Lisp integer. */);
3242 Vmost_positive_fixnum
= make_number (MOST_POSITIVE_FIXNUM
);
3243 XSYMBOL (intern_c_string ("most-positive-fixnum"))->constant
= 1;
3245 DEFVAR_LISP ("most-negative-fixnum", Vmost_negative_fixnum
,
3246 doc
: /* The smallest value that is representable in a Lisp integer. */);
3247 Vmost_negative_fixnum
= make_number (MOST_NEGATIVE_FIXNUM
);
3248 XSYMBOL (intern_c_string ("most-negative-fixnum"))->constant
= 1;
3251 #ifndef FORWARD_SIGNAL_TO_MAIN_THREAD
3252 static void arith_error (int) NO_RETURN
;
3256 arith_error (int signo
)
3258 sigsetmask (SIGEMPTYMASK
);
3260 SIGNAL_THREAD_CHECK (signo
);
3261 xsignal0 (Qarith_error
);
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. */
3274 #endif /* CANNOT_DUMP */
3275 signal (SIGFPE
, arith_error
);
3278 signal (SIGEMT
, arith_error
);