1 /* Primitive operations on Lisp data types for GNU Emacs Lisp interpreter.
2 Copyright (C) 1985, 1986, 1988, 1993, 1994, 1995, 1997, 1998, 1999, 2000,
3 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
4 Free Software Foundation, Inc.
6 This file is part of GNU Emacs.
8 GNU Emacs is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3, or (at your option)
13 GNU Emacs is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU Emacs; see the file COPYING. If not, write to
20 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 Boston, MA 02110-1301, USA. */
33 #include "syssignal.h"
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
49 /* Work around a problem that happens because math.h on hpux 7
50 defines two static variables--which, in Emacs, are not really static,
51 because `static' is defined as nothing. The problem is that they are
52 here, in floatfns.c, and in lread.c.
53 These macros prevent the name conflict. */
54 #if defined (HPUX) && !defined (HPUX8)
55 #define _MAXLDBL data_c_maxldbl
56 #define _NMAXLDBL data_c_nmaxldbl
62 extern double atof ();
65 Lisp_Object Qnil
, Qt
, Qquote
, Qlambda
, Qsubr
, Qunbound
;
66 Lisp_Object Qerror_conditions
, Qerror_message
, Qtop_level
;
67 Lisp_Object Qerror
, Qquit
, Qwrong_type_argument
, Qargs_out_of_range
;
68 Lisp_Object Qvoid_variable
, Qvoid_function
, Qcyclic_function_indirection
;
69 Lisp_Object Qcyclic_variable_indirection
, Qcircular_list
;
70 Lisp_Object Qsetting_constant
, Qinvalid_read_syntax
;
71 Lisp_Object Qinvalid_function
, Qwrong_number_of_arguments
, Qno_catch
;
72 Lisp_Object Qend_of_file
, Qarith_error
, Qmark_inactive
;
73 Lisp_Object Qbeginning_of_buffer
, Qend_of_buffer
, Qbuffer_read_only
;
74 Lisp_Object Qtext_read_only
;
76 Lisp_Object Qintegerp
, Qnatnump
, Qwholenump
, Qsymbolp
, Qlistp
, Qconsp
;
77 Lisp_Object Qstringp
, Qarrayp
, Qsequencep
, Qbufferp
;
78 Lisp_Object Qchar_or_string_p
, Qmarkerp
, Qinteger_or_marker_p
, Qvectorp
;
79 Lisp_Object Qbuffer_or_string_p
, Qkeywordp
;
80 Lisp_Object Qboundp
, Qfboundp
;
81 Lisp_Object Qchar_table_p
, Qvector_or_char_table_p
;
84 Lisp_Object Qad_advice_info
, Qad_activate_internal
;
86 Lisp_Object Qrange_error
, Qdomain_error
, Qsingularity_error
;
87 Lisp_Object Qoverflow_error
, Qunderflow_error
;
90 Lisp_Object Qnumberp
, Qnumber_or_marker_p
;
93 static Lisp_Object Qsymbol
, Qstring
, Qcons
, Qmarker
, Qoverlay
;
94 static Lisp_Object Qfloat
, Qwindow_configuration
, Qwindow
;
96 static Lisp_Object Qcompiled_function
, Qbuffer
, Qframe
, Qvector
;
97 static Lisp_Object Qchar_table
, Qbool_vector
, Qhash_table
;
98 static Lisp_Object Qsubrp
, Qmany
, Qunevalled
;
100 static Lisp_Object swap_in_symval_forwarding
P_ ((Lisp_Object
, Lisp_Object
));
102 Lisp_Object Vmost_positive_fixnum
, Vmost_negative_fixnum
;
106 circular_list_error (list
)
109 xsignal (Qcircular_list
, list
);
114 wrong_type_argument (predicate
, value
)
115 register Lisp_Object predicate
, value
;
117 /* If VALUE is not even a valid Lisp object, abort here
118 where we can get a backtrace showing where it came from. */
119 if ((unsigned int) XGCTYPE (value
) >= Lisp_Type_Limit
)
122 xsignal2 (Qwrong_type_argument
, predicate
, value
);
128 error ("Attempt to modify read-only object");
132 args_out_of_range (a1
, a2
)
135 xsignal2 (Qargs_out_of_range
, a1
, a2
);
139 args_out_of_range_3 (a1
, a2
, a3
)
140 Lisp_Object a1
, a2
, a3
;
142 xsignal3 (Qargs_out_of_range
, a1
, a2
, a3
);
145 /* On some machines, XINT needs a temporary location.
146 Here it is, in case it is needed. */
148 int sign_extend_temp
;
150 /* On a few machines, XINT can only be done by calling this. */
153 sign_extend_lisp_int (num
)
156 if (num
& (((EMACS_INT
) 1) << (VALBITS
- 1)))
157 return num
| (((EMACS_INT
) (-1)) << VALBITS
);
159 return num
& ((((EMACS_INT
) 1) << VALBITS
) - 1);
162 /* Data type predicates */
164 DEFUN ("eq", Feq
, Seq
, 2, 2, 0,
165 doc
: /* Return t if the two args are the same Lisp object. */)
167 Lisp_Object obj1
, obj2
;
174 DEFUN ("null", Fnull
, Snull
, 1, 1, 0,
175 doc
: /* Return t if OBJECT is nil. */)
184 DEFUN ("type-of", Ftype_of
, Stype_of
, 1, 1, 0,
185 doc
: /* Return a symbol representing the type of OBJECT.
186 The symbol returned names the object's basic type;
187 for example, (type-of 1) returns `integer'. */)
191 switch (XGCTYPE (object
))
206 switch (XMISCTYPE (object
))
208 case Lisp_Misc_Marker
:
210 case Lisp_Misc_Overlay
:
212 case Lisp_Misc_Float
:
217 case Lisp_Vectorlike
:
218 if (GC_WINDOW_CONFIGURATIONP (object
))
219 return Qwindow_configuration
;
220 if (GC_PROCESSP (object
))
222 if (GC_WINDOWP (object
))
224 if (GC_SUBRP (object
))
226 if (GC_COMPILEDP (object
))
227 return Qcompiled_function
;
228 if (GC_BUFFERP (object
))
230 if (GC_CHAR_TABLE_P (object
))
232 if (GC_BOOL_VECTOR_P (object
))
234 if (GC_FRAMEP (object
))
236 if (GC_HASH_TABLE_P (object
))
248 DEFUN ("consp", Fconsp
, Sconsp
, 1, 1, 0,
249 doc
: /* Return t if OBJECT is a cons cell. */)
258 DEFUN ("atom", Fatom
, Satom
, 1, 1, 0,
259 doc
: /* Return t if OBJECT is not a cons cell. This includes nil. */)
268 DEFUN ("listp", Flistp
, Slistp
, 1, 1, 0,
269 doc
: /* Return t if OBJECT is a list, that is, a cons cell or nil.
270 Otherwise, return nil. */)
274 if (CONSP (object
) || NILP (object
))
279 DEFUN ("nlistp", Fnlistp
, Snlistp
, 1, 1, 0,
280 doc
: /* Return t if OBJECT is not a list. Lists include nil. */)
284 if (CONSP (object
) || NILP (object
))
289 DEFUN ("symbolp", Fsymbolp
, Ssymbolp
, 1, 1, 0,
290 doc
: /* Return t if OBJECT is a symbol. */)
294 if (SYMBOLP (object
))
299 /* Define this in C to avoid unnecessarily consing up the symbol
301 DEFUN ("keywordp", Fkeywordp
, Skeywordp
, 1, 1, 0,
302 doc
: /* Return t if OBJECT is a keyword.
303 This means that it is a symbol with a print name beginning with `:'
304 interned in the initial obarray. */)
309 && SREF (SYMBOL_NAME (object
), 0) == ':'
310 && SYMBOL_INTERNED_IN_INITIAL_OBARRAY_P (object
))
315 DEFUN ("vectorp", Fvectorp
, Svectorp
, 1, 1, 0,
316 doc
: /* Return t if OBJECT is a vector. */)
320 if (VECTORP (object
))
325 DEFUN ("stringp", Fstringp
, Sstringp
, 1, 1, 0,
326 doc
: /* Return t if OBJECT is a string. */)
330 if (STRINGP (object
))
335 DEFUN ("multibyte-string-p", Fmultibyte_string_p
, Smultibyte_string_p
,
337 doc
: /* Return t if OBJECT is a multibyte string. */)
341 if (STRINGP (object
) && STRING_MULTIBYTE (object
))
346 DEFUN ("char-table-p", Fchar_table_p
, Schar_table_p
, 1, 1, 0,
347 doc
: /* Return t if OBJECT is a char-table. */)
351 if (CHAR_TABLE_P (object
))
356 DEFUN ("vector-or-char-table-p", Fvector_or_char_table_p
,
357 Svector_or_char_table_p
, 1, 1, 0,
358 doc
: /* Return t if OBJECT is a char-table or vector. */)
362 if (VECTORP (object
) || CHAR_TABLE_P (object
))
367 DEFUN ("bool-vector-p", Fbool_vector_p
, Sbool_vector_p
, 1, 1, 0,
368 doc
: /* Return t if OBJECT is a bool-vector. */)
372 if (BOOL_VECTOR_P (object
))
377 DEFUN ("arrayp", Farrayp
, Sarrayp
, 1, 1, 0,
378 doc
: /* Return t if OBJECT is an array (string or vector). */)
387 DEFUN ("sequencep", Fsequencep
, Ssequencep
, 1, 1, 0,
388 doc
: /* Return t if OBJECT is a sequence (list or array). */)
390 register Lisp_Object object
;
392 if (CONSP (object
) || NILP (object
) || ARRAYP (object
))
397 DEFUN ("bufferp", Fbufferp
, Sbufferp
, 1, 1, 0,
398 doc
: /* Return t if OBJECT is an editor buffer. */)
402 if (BUFFERP (object
))
407 DEFUN ("markerp", Fmarkerp
, Smarkerp
, 1, 1, 0,
408 doc
: /* Return t if OBJECT is a marker (editor pointer). */)
412 if (MARKERP (object
))
417 DEFUN ("subrp", Fsubrp
, Ssubrp
, 1, 1, 0,
418 doc
: /* Return t if OBJECT is a built-in function. */)
427 DEFUN ("byte-code-function-p", Fbyte_code_function_p
, Sbyte_code_function_p
,
429 doc
: /* Return t if OBJECT is a byte-compiled function object. */)
433 if (COMPILEDP (object
))
438 DEFUN ("char-or-string-p", Fchar_or_string_p
, Schar_or_string_p
, 1, 1, 0,
439 doc
: /* Return t if OBJECT is a character (an integer) or a string. */)
441 register Lisp_Object object
;
443 if (INTEGERP (object
) || STRINGP (object
))
448 DEFUN ("integerp", Fintegerp
, Sintegerp
, 1, 1, 0,
449 doc
: /* Return t if OBJECT is an integer. */)
453 if (INTEGERP (object
))
458 DEFUN ("integer-or-marker-p", Finteger_or_marker_p
, Sinteger_or_marker_p
, 1, 1, 0,
459 doc
: /* Return t if OBJECT is an integer or a marker (editor pointer). */)
461 register Lisp_Object object
;
463 if (MARKERP (object
) || INTEGERP (object
))
468 DEFUN ("natnump", Fnatnump
, Snatnump
, 1, 1, 0,
469 doc
: /* Return t if OBJECT is a nonnegative integer. */)
473 if (NATNUMP (object
))
478 DEFUN ("numberp", Fnumberp
, Snumberp
, 1, 1, 0,
479 doc
: /* Return t if OBJECT is a number (floating point or integer). */)
483 if (NUMBERP (object
))
489 DEFUN ("number-or-marker-p", Fnumber_or_marker_p
,
490 Snumber_or_marker_p
, 1, 1, 0,
491 doc
: /* Return t if OBJECT is a number or a marker. */)
495 if (NUMBERP (object
) || MARKERP (object
))
500 DEFUN ("floatp", Ffloatp
, Sfloatp
, 1, 1, 0,
501 doc
: /* Return t if OBJECT is a floating point number. */)
511 /* Extract and set components of lists */
513 DEFUN ("car", Fcar
, Scar
, 1, 1, 0,
514 doc
: /* Return the car of LIST. If arg is nil, return nil.
515 Error if arg is not nil and not a cons cell. See also `car-safe'.
517 See Info node `(elisp)Cons Cells' for a discussion of related basic
518 Lisp concepts such as car, cdr, cons cell and list. */)
520 register Lisp_Object list
;
525 DEFUN ("car-safe", Fcar_safe
, Scar_safe
, 1, 1, 0,
526 doc
: /* Return the car of OBJECT if it is a cons cell, or else nil. */)
530 return CAR_SAFE (object
);
533 DEFUN ("cdr", Fcdr
, Scdr
, 1, 1, 0,
534 doc
: /* Return the cdr of LIST. If arg is nil, return nil.
535 Error if arg is not nil and not a cons cell. See also `cdr-safe'.
537 See Info node `(elisp)Cons Cells' for a discussion of related basic
538 Lisp concepts such as cdr, car, cons cell and list. */)
540 register Lisp_Object list
;
545 DEFUN ("cdr-safe", Fcdr_safe
, Scdr_safe
, 1, 1, 0,
546 doc
: /* Return the cdr of OBJECT if it is a cons cell, or else nil. */)
550 return CDR_SAFE (object
);
553 DEFUN ("setcar", Fsetcar
, Ssetcar
, 2, 2, 0,
554 doc
: /* Set the car of CELL to be NEWCAR. Returns NEWCAR. */)
556 register Lisp_Object cell
, newcar
;
560 XSETCAR (cell
, newcar
);
564 DEFUN ("setcdr", Fsetcdr
, Ssetcdr
, 2, 2, 0,
565 doc
: /* Set the cdr of CELL to be NEWCDR. Returns NEWCDR. */)
567 register Lisp_Object cell
, newcdr
;
571 XSETCDR (cell
, newcdr
);
575 /* Extract and set components of symbols */
577 DEFUN ("boundp", Fboundp
, Sboundp
, 1, 1, 0,
578 doc
: /* Return t if SYMBOL's value is not void. */)
580 register Lisp_Object symbol
;
582 Lisp_Object valcontents
;
583 CHECK_SYMBOL (symbol
);
585 valcontents
= SYMBOL_VALUE (symbol
);
587 if (BUFFER_LOCAL_VALUEP (valcontents
)
588 || SOME_BUFFER_LOCAL_VALUEP (valcontents
))
589 valcontents
= swap_in_symval_forwarding (symbol
, valcontents
);
591 return (EQ (valcontents
, Qunbound
) ? Qnil
: Qt
);
594 DEFUN ("fboundp", Ffboundp
, Sfboundp
, 1, 1, 0,
595 doc
: /* Return t if SYMBOL's function definition is not void. */)
597 register Lisp_Object symbol
;
599 CHECK_SYMBOL (symbol
);
600 return (EQ (XSYMBOL (symbol
)->function
, Qunbound
) ? Qnil
: Qt
);
603 DEFUN ("makunbound", Fmakunbound
, Smakunbound
, 1, 1, 0,
604 doc
: /* Make SYMBOL's value be void.
607 register Lisp_Object symbol
;
609 CHECK_SYMBOL (symbol
);
610 if (SYMBOL_CONSTANT_P (symbol
))
611 xsignal1 (Qsetting_constant
, symbol
);
612 Fset (symbol
, Qunbound
);
616 DEFUN ("fmakunbound", Ffmakunbound
, Sfmakunbound
, 1, 1, 0,
617 doc
: /* Make SYMBOL's function definition be void.
620 register Lisp_Object symbol
;
622 CHECK_SYMBOL (symbol
);
623 if (NILP (symbol
) || EQ (symbol
, Qt
))
624 xsignal1 (Qsetting_constant
, symbol
);
625 XSYMBOL (symbol
)->function
= Qunbound
;
629 DEFUN ("symbol-function", Fsymbol_function
, Ssymbol_function
, 1, 1, 0,
630 doc
: /* Return SYMBOL's function definition. Error if that is void. */)
632 register Lisp_Object symbol
;
634 CHECK_SYMBOL (symbol
);
635 if (!EQ (XSYMBOL (symbol
)->function
, Qunbound
))
636 return XSYMBOL (symbol
)->function
;
637 xsignal1 (Qvoid_function
, symbol
);
640 DEFUN ("symbol-plist", Fsymbol_plist
, Ssymbol_plist
, 1, 1, 0,
641 doc
: /* Return SYMBOL's property list. */)
643 register Lisp_Object symbol
;
645 CHECK_SYMBOL (symbol
);
646 return XSYMBOL (symbol
)->plist
;
649 DEFUN ("symbol-name", Fsymbol_name
, Ssymbol_name
, 1, 1, 0,
650 doc
: /* Return SYMBOL's name, a string. */)
652 register Lisp_Object symbol
;
654 register Lisp_Object name
;
656 CHECK_SYMBOL (symbol
);
657 name
= SYMBOL_NAME (symbol
);
661 DEFUN ("fset", Ffset
, Sfset
, 2, 2, 0,
662 doc
: /* Set SYMBOL's function definition to DEFINITION, and return DEFINITION. */)
664 register Lisp_Object symbol
, definition
;
666 register Lisp_Object function
;
668 CHECK_SYMBOL (symbol
);
669 if (NILP (symbol
) || EQ (symbol
, Qt
))
670 xsignal1 (Qsetting_constant
, symbol
);
672 function
= XSYMBOL (symbol
)->function
;
674 if (!NILP (Vautoload_queue
) && !EQ (function
, Qunbound
))
675 Vautoload_queue
= Fcons (Fcons (symbol
, function
), Vautoload_queue
);
677 if (CONSP (function
) && EQ (XCAR (function
), Qautoload
))
678 Fput (symbol
, Qautoload
, XCDR (function
));
680 XSYMBOL (symbol
)->function
= definition
;
681 /* Handle automatic advice activation */
682 if (CONSP (XSYMBOL (symbol
)->plist
) && !NILP (Fget (symbol
, Qad_advice_info
)))
684 call2 (Qad_activate_internal
, symbol
, Qnil
);
685 definition
= XSYMBOL (symbol
)->function
;
690 extern Lisp_Object Qfunction_documentation
;
692 DEFUN ("defalias", Fdefalias
, Sdefalias
, 2, 3, 0,
693 doc
: /* Set SYMBOL's function definition to DEFINITION, and return DEFINITION.
694 Associates the function with the current load file, if any.
695 The optional third argument DOCSTRING specifies the documentation string
696 for SYMBOL; if it is omitted or nil, SYMBOL uses the documentation string
697 determined by DEFINITION. */)
698 (symbol
, definition
, docstring
)
699 register Lisp_Object symbol
, definition
, docstring
;
701 CHECK_SYMBOL (symbol
);
702 if (CONSP (XSYMBOL (symbol
)->function
)
703 && EQ (XCAR (XSYMBOL (symbol
)->function
), Qautoload
))
704 LOADHIST_ATTACH (Fcons (Qt
, symbol
));
705 definition
= Ffset (symbol
, definition
);
706 LOADHIST_ATTACH (Fcons (Qdefun
, symbol
));
707 if (!NILP (docstring
))
708 Fput (symbol
, Qfunction_documentation
, docstring
);
712 DEFUN ("setplist", Fsetplist
, Ssetplist
, 2, 2, 0,
713 doc
: /* Set SYMBOL's property list to NEWPLIST, and return NEWPLIST. */)
715 register Lisp_Object symbol
, newplist
;
717 CHECK_SYMBOL (symbol
);
718 XSYMBOL (symbol
)->plist
= newplist
;
722 DEFUN ("subr-arity", Fsubr_arity
, Ssubr_arity
, 1, 1, 0,
723 doc
: /* Return minimum and maximum number of args allowed for SUBR.
724 SUBR must be a built-in function.
725 The returned value is a pair (MIN . MAX). MIN is the minimum number
726 of args. MAX is the maximum number or the symbol `many', for a
727 function with `&rest' args, or `unevalled' for a special form. */)
731 short minargs
, maxargs
;
733 minargs
= XSUBR (subr
)->min_args
;
734 maxargs
= XSUBR (subr
)->max_args
;
736 return Fcons (make_number (minargs
), Qmany
);
737 else if (maxargs
== UNEVALLED
)
738 return Fcons (make_number (minargs
), Qunevalled
);
740 return Fcons (make_number (minargs
), make_number (maxargs
));
743 DEFUN ("subr-name", Fsubr_name
, Ssubr_name
, 1, 1, 0,
744 doc
: /* Return name of subroutine SUBR.
745 SUBR must be a built-in function. */)
751 name
= XSUBR (subr
)->symbol_name
;
752 return make_string (name
, strlen (name
));
755 DEFUN ("interactive-form", Finteractive_form
, Sinteractive_form
, 1, 1, 0,
756 doc
: /* Return the interactive form of CMD or nil if none.
757 If CMD is not a command, the return value is nil.
758 Value, if non-nil, is a list \(interactive SPEC). */)
762 Lisp_Object fun
= indirect_function (cmd
);
766 if (XSUBR (fun
)->prompt
)
767 return list2 (Qinteractive
, build_string (XSUBR (fun
)->prompt
));
769 else if (COMPILEDP (fun
))
771 if ((ASIZE (fun
) & PSEUDOVECTOR_SIZE_MASK
) > COMPILED_INTERACTIVE
)
772 return list2 (Qinteractive
, AREF (fun
, COMPILED_INTERACTIVE
));
774 else if (CONSP (fun
))
776 Lisp_Object funcar
= XCAR (fun
);
777 if (EQ (funcar
, Qlambda
))
778 return Fassq (Qinteractive
, Fcdr (XCDR (fun
)));
779 else if (EQ (funcar
, Qautoload
))
783 do_autoload (fun
, cmd
);
785 return Finteractive_form (cmd
);
792 /***********************************************************************
793 Getting and Setting Values of Symbols
794 ***********************************************************************/
796 /* Return the symbol holding SYMBOL's value. Signal
797 `cyclic-variable-indirection' if SYMBOL's chain of variable
798 indirections contains a loop. */
801 indirect_variable (symbol
)
804 Lisp_Object tortoise
, hare
;
806 hare
= tortoise
= symbol
;
808 while (XSYMBOL (hare
)->indirect_variable
)
810 hare
= XSYMBOL (hare
)->value
;
811 if (!XSYMBOL (hare
)->indirect_variable
)
814 hare
= XSYMBOL (hare
)->value
;
815 tortoise
= XSYMBOL (tortoise
)->value
;
817 if (EQ (hare
, tortoise
))
818 xsignal1 (Qcyclic_variable_indirection
, symbol
);
825 DEFUN ("indirect-variable", Findirect_variable
, Sindirect_variable
, 1, 1, 0,
826 doc
: /* Return the variable at the end of OBJECT's variable chain.
827 If OBJECT is a symbol, follow all variable indirections and return the final
828 variable. If OBJECT is not a symbol, just return it.
829 Signal a cyclic-variable-indirection error if there is a loop in the
830 variable chain of symbols. */)
834 if (SYMBOLP (object
))
835 object
= indirect_variable (object
);
840 /* Given the raw contents of a symbol value cell,
841 return the Lisp value of the symbol.
842 This does not handle buffer-local variables; use
843 swap_in_symval_forwarding for that. */
846 do_symval_forwarding (valcontents
)
847 register Lisp_Object valcontents
;
849 register Lisp_Object val
;
851 if (MISCP (valcontents
))
852 switch (XMISCTYPE (valcontents
))
854 case Lisp_Misc_Intfwd
:
855 XSETINT (val
, *XINTFWD (valcontents
)->intvar
);
858 case Lisp_Misc_Boolfwd
:
859 return (*XBOOLFWD (valcontents
)->boolvar
? Qt
: Qnil
);
861 case Lisp_Misc_Objfwd
:
862 return *XOBJFWD (valcontents
)->objvar
;
864 case Lisp_Misc_Buffer_Objfwd
:
865 offset
= XBUFFER_OBJFWD (valcontents
)->offset
;
866 return PER_BUFFER_VALUE (current_buffer
, offset
);
868 case Lisp_Misc_Kboard_Objfwd
:
869 offset
= XKBOARD_OBJFWD (valcontents
)->offset
;
870 return *(Lisp_Object
*)(offset
+ (char *)current_kboard
);
875 /* Store NEWVAL into SYMBOL, where VALCONTENTS is found in the value cell
876 of SYMBOL. If SYMBOL is buffer-local, VALCONTENTS should be the
877 buffer-independent contents of the value cell: forwarded just one
878 step past the buffer-localness.
880 BUF non-zero means set the value in buffer BUF instead of the
881 current buffer. This only plays a role for per-buffer variables. */
884 store_symval_forwarding (symbol
, valcontents
, newval
, buf
)
886 register Lisp_Object valcontents
, newval
;
889 switch (SWITCH_ENUM_CAST (XTYPE (valcontents
)))
892 switch (XMISCTYPE (valcontents
))
894 case Lisp_Misc_Intfwd
:
895 CHECK_NUMBER (newval
);
896 *XINTFWD (valcontents
)->intvar
= XINT (newval
);
897 if (*XINTFWD (valcontents
)->intvar
!= XINT (newval
))
898 error ("Value out of range for variable `%s'",
899 SDATA (SYMBOL_NAME (symbol
)));
902 case Lisp_Misc_Boolfwd
:
903 *XBOOLFWD (valcontents
)->boolvar
= NILP (newval
) ? 0 : 1;
906 case Lisp_Misc_Objfwd
:
907 *XOBJFWD (valcontents
)->objvar
= newval
;
909 /* If this variable is a default for something stored
910 in the buffer itself, such as default-fill-column,
911 find the buffers that don't have local values for it
913 if (XOBJFWD (valcontents
)->objvar
> (Lisp_Object
*) &buffer_defaults
914 && XOBJFWD (valcontents
)->objvar
< (Lisp_Object
*) (&buffer_defaults
+ 1))
916 int offset
= ((char *) XOBJFWD (valcontents
)->objvar
917 - (char *) &buffer_defaults
);
918 int idx
= PER_BUFFER_IDX (offset
);
925 for (tail
= Vbuffer_alist
; CONSP (tail
); tail
= XCDR (tail
))
930 buf
= Fcdr (XCAR (tail
));
931 if (!BUFFERP (buf
)) continue;
934 if (! PER_BUFFER_VALUE_P (b
, idx
))
935 PER_BUFFER_VALUE (b
, offset
) = newval
;
940 case Lisp_Misc_Buffer_Objfwd
:
942 int offset
= XBUFFER_OBJFWD (valcontents
)->offset
;
945 type
= PER_BUFFER_TYPE (offset
);
946 if (! NILP (type
) && ! NILP (newval
)
947 && XTYPE (newval
) != XINT (type
))
948 buffer_slot_type_mismatch (offset
);
951 buf
= current_buffer
;
952 PER_BUFFER_VALUE (buf
, offset
) = newval
;
956 case Lisp_Misc_Kboard_Objfwd
:
958 char *base
= (char *) current_kboard
;
959 char *p
= base
+ XKBOARD_OBJFWD (valcontents
)->offset
;
960 *(Lisp_Object
*) p
= newval
;
971 valcontents
= SYMBOL_VALUE (symbol
);
972 if (BUFFER_LOCAL_VALUEP (valcontents
)
973 || SOME_BUFFER_LOCAL_VALUEP (valcontents
))
974 XBUFFER_LOCAL_VALUE (valcontents
)->realvalue
= newval
;
976 SET_SYMBOL_VALUE (symbol
, newval
);
980 /* Set up SYMBOL to refer to its global binding.
981 This makes it safe to alter the status of other bindings. */
984 swap_in_global_binding (symbol
)
987 Lisp_Object valcontents
, cdr
;
989 valcontents
= SYMBOL_VALUE (symbol
);
990 if (!BUFFER_LOCAL_VALUEP (valcontents
)
991 && !SOME_BUFFER_LOCAL_VALUEP (valcontents
))
993 cdr
= XBUFFER_LOCAL_VALUE (valcontents
)->cdr
;
995 /* Unload the previously loaded binding. */
997 do_symval_forwarding (XBUFFER_LOCAL_VALUE (valcontents
)->realvalue
));
999 /* Select the global binding in the symbol. */
1001 store_symval_forwarding (symbol
, valcontents
, XCDR (cdr
), NULL
);
1003 /* Indicate that the global binding is set up now. */
1004 XBUFFER_LOCAL_VALUE (valcontents
)->frame
= Qnil
;
1005 XBUFFER_LOCAL_VALUE (valcontents
)->buffer
= Qnil
;
1006 XBUFFER_LOCAL_VALUE (valcontents
)->found_for_frame
= 0;
1007 XBUFFER_LOCAL_VALUE (valcontents
)->found_for_buffer
= 0;
1010 /* Set up the buffer-local symbol SYMBOL for validity in the current buffer.
1011 VALCONTENTS is the contents of its value cell,
1012 which points to a struct Lisp_Buffer_Local_Value.
1014 Return the value forwarded one step past the buffer-local stage.
1015 This could be another forwarding pointer. */
1018 swap_in_symval_forwarding (symbol
, valcontents
)
1019 Lisp_Object symbol
, valcontents
;
1021 register Lisp_Object tem1
;
1023 tem1
= XBUFFER_LOCAL_VALUE (valcontents
)->buffer
;
1026 || current_buffer
!= XBUFFER (tem1
)
1027 || (XBUFFER_LOCAL_VALUE (valcontents
)->check_frame
1028 && ! EQ (selected_frame
, XBUFFER_LOCAL_VALUE (valcontents
)->frame
)))
1030 if (XSYMBOL (symbol
)->indirect_variable
)
1031 symbol
= indirect_variable (symbol
);
1033 /* Unload the previously loaded binding. */
1034 tem1
= XCAR (XBUFFER_LOCAL_VALUE (valcontents
)->cdr
);
1036 do_symval_forwarding (XBUFFER_LOCAL_VALUE (valcontents
)->realvalue
));
1037 /* Choose the new binding. */
1038 tem1
= assq_no_quit (symbol
, current_buffer
->local_var_alist
);
1039 XBUFFER_LOCAL_VALUE (valcontents
)->found_for_frame
= 0;
1040 XBUFFER_LOCAL_VALUE (valcontents
)->found_for_buffer
= 0;
1043 if (XBUFFER_LOCAL_VALUE (valcontents
)->check_frame
)
1044 tem1
= assq_no_quit (symbol
, XFRAME (selected_frame
)->param_alist
);
1046 XBUFFER_LOCAL_VALUE (valcontents
)->found_for_frame
= 1;
1048 tem1
= XBUFFER_LOCAL_VALUE (valcontents
)->cdr
;
1051 XBUFFER_LOCAL_VALUE (valcontents
)->found_for_buffer
= 1;
1053 /* Load the new binding. */
1054 XSETCAR (XBUFFER_LOCAL_VALUE (valcontents
)->cdr
, tem1
);
1055 XSETBUFFER (XBUFFER_LOCAL_VALUE (valcontents
)->buffer
, current_buffer
);
1056 XBUFFER_LOCAL_VALUE (valcontents
)->frame
= selected_frame
;
1057 store_symval_forwarding (symbol
,
1058 XBUFFER_LOCAL_VALUE (valcontents
)->realvalue
,
1061 return XBUFFER_LOCAL_VALUE (valcontents
)->realvalue
;
1064 /* Find the value of a symbol, returning Qunbound if it's not bound.
1065 This is helpful for code which just wants to get a variable's value
1066 if it has one, without signaling an error.
1067 Note that it must not be possible to quit
1068 within this function. Great care is required for this. */
1071 find_symbol_value (symbol
)
1074 register Lisp_Object valcontents
;
1075 register Lisp_Object val
;
1077 CHECK_SYMBOL (symbol
);
1078 valcontents
= SYMBOL_VALUE (symbol
);
1080 if (BUFFER_LOCAL_VALUEP (valcontents
)
1081 || SOME_BUFFER_LOCAL_VALUEP (valcontents
))
1082 valcontents
= swap_in_symval_forwarding (symbol
, valcontents
);
1084 if (MISCP (valcontents
))
1086 switch (XMISCTYPE (valcontents
))
1088 case Lisp_Misc_Intfwd
:
1089 XSETINT (val
, *XINTFWD (valcontents
)->intvar
);
1092 case Lisp_Misc_Boolfwd
:
1093 return (*XBOOLFWD (valcontents
)->boolvar
? Qt
: Qnil
);
1095 case Lisp_Misc_Objfwd
:
1096 return *XOBJFWD (valcontents
)->objvar
;
1098 case Lisp_Misc_Buffer_Objfwd
:
1099 return PER_BUFFER_VALUE (current_buffer
,
1100 XBUFFER_OBJFWD (valcontents
)->offset
);
1102 case Lisp_Misc_Kboard_Objfwd
:
1103 return *(Lisp_Object
*)(XKBOARD_OBJFWD (valcontents
)->offset
1104 + (char *)current_kboard
);
1111 DEFUN ("symbol-value", Fsymbol_value
, Ssymbol_value
, 1, 1, 0,
1112 doc
: /* Return SYMBOL's value. Error if that is void. */)
1118 val
= find_symbol_value (symbol
);
1119 if (!EQ (val
, Qunbound
))
1122 xsignal1 (Qvoid_variable
, symbol
);
1125 DEFUN ("set", Fset
, Sset
, 2, 2, 0,
1126 doc
: /* Set SYMBOL's value to NEWVAL, and return NEWVAL. */)
1128 register Lisp_Object symbol
, newval
;
1130 return set_internal (symbol
, newval
, current_buffer
, 0);
1133 /* Return 1 if SYMBOL currently has a let-binding
1134 which was made in the buffer that is now current. */
1137 let_shadows_buffer_binding_p (symbol
)
1140 volatile struct specbinding
*p
;
1142 for (p
= specpdl_ptr
- 1; p
>= specpdl
; p
--)
1144 && CONSP (p
->symbol
))
1146 Lisp_Object let_bound_symbol
= XCAR (p
->symbol
);
1147 if ((EQ (symbol
, let_bound_symbol
)
1148 || (XSYMBOL (let_bound_symbol
)->indirect_variable
1149 && EQ (symbol
, indirect_variable (let_bound_symbol
))))
1150 && XBUFFER (XCDR (XCDR (p
->symbol
))) == current_buffer
)
1154 return p
>= specpdl
;
1157 /* Store the value NEWVAL into SYMBOL.
1158 If buffer-locality is an issue, BUF specifies which buffer to use.
1159 (0 stands for the current buffer.)
1161 If BINDFLAG is zero, then if this symbol is supposed to become
1162 local in every buffer where it is set, then we make it local.
1163 If BINDFLAG is nonzero, we don't do that. */
1166 set_internal (symbol
, newval
, buf
, bindflag
)
1167 register Lisp_Object symbol
, newval
;
1171 int voide
= EQ (newval
, Qunbound
);
1173 register Lisp_Object valcontents
, innercontents
, tem1
, current_alist_element
;
1176 buf
= current_buffer
;
1178 /* If restoring in a dead buffer, do nothing. */
1179 if (NILP (buf
->name
))
1182 CHECK_SYMBOL (symbol
);
1183 if (SYMBOL_CONSTANT_P (symbol
)
1184 && (NILP (Fkeywordp (symbol
))
1185 || !EQ (newval
, SYMBOL_VALUE (symbol
))))
1186 xsignal1 (Qsetting_constant
, symbol
);
1188 innercontents
= valcontents
= SYMBOL_VALUE (symbol
);
1190 if (BUFFER_OBJFWDP (valcontents
))
1192 int offset
= XBUFFER_OBJFWD (valcontents
)->offset
;
1193 int idx
= PER_BUFFER_IDX (offset
);
1196 && !let_shadows_buffer_binding_p (symbol
))
1197 SET_PER_BUFFER_VALUE_P (buf
, idx
, 1);
1199 else if (BUFFER_LOCAL_VALUEP (valcontents
)
1200 || SOME_BUFFER_LOCAL_VALUEP (valcontents
))
1202 /* valcontents is a struct Lisp_Buffer_Local_Value. */
1203 if (XSYMBOL (symbol
)->indirect_variable
)
1204 symbol
= indirect_variable (symbol
);
1206 /* What binding is loaded right now? */
1207 current_alist_element
1208 = XCAR (XBUFFER_LOCAL_VALUE (valcontents
)->cdr
);
1210 /* If the current buffer is not the buffer whose binding is
1211 loaded, or if there may be frame-local bindings and the frame
1212 isn't the right one, or if it's a Lisp_Buffer_Local_Value and
1213 the default binding is loaded, the loaded binding may be the
1215 if (!BUFFERP (XBUFFER_LOCAL_VALUE (valcontents
)->buffer
)
1216 || buf
!= XBUFFER (XBUFFER_LOCAL_VALUE (valcontents
)->buffer
)
1217 || (XBUFFER_LOCAL_VALUE (valcontents
)->check_frame
1218 && !EQ (selected_frame
, XBUFFER_LOCAL_VALUE (valcontents
)->frame
))
1219 || (BUFFER_LOCAL_VALUEP (valcontents
)
1220 && EQ (XCAR (current_alist_element
),
1221 current_alist_element
)))
1223 /* The currently loaded binding is not necessarily valid.
1224 We need to unload it, and choose a new binding. */
1226 /* Write out `realvalue' to the old loaded binding. */
1227 Fsetcdr (current_alist_element
,
1228 do_symval_forwarding (XBUFFER_LOCAL_VALUE (valcontents
)->realvalue
));
1230 /* Find the new binding. */
1231 tem1
= Fassq (symbol
, buf
->local_var_alist
);
1232 XBUFFER_LOCAL_VALUE (valcontents
)->found_for_buffer
= 1;
1233 XBUFFER_LOCAL_VALUE (valcontents
)->found_for_frame
= 0;
1237 /* This buffer still sees the default value. */
1239 /* If the variable is a Lisp_Some_Buffer_Local_Value,
1240 or if this is `let' rather than `set',
1241 make CURRENT-ALIST-ELEMENT point to itself,
1242 indicating that we're seeing the default value.
1243 Likewise if the variable has been let-bound
1244 in the current buffer. */
1245 if (bindflag
|| SOME_BUFFER_LOCAL_VALUEP (valcontents
)
1246 || let_shadows_buffer_binding_p (symbol
))
1248 XBUFFER_LOCAL_VALUE (valcontents
)->found_for_buffer
= 0;
1250 if (XBUFFER_LOCAL_VALUE (valcontents
)->check_frame
)
1251 tem1
= Fassq (symbol
,
1252 XFRAME (selected_frame
)->param_alist
);
1255 XBUFFER_LOCAL_VALUE (valcontents
)->found_for_frame
= 1;
1257 tem1
= XBUFFER_LOCAL_VALUE (valcontents
)->cdr
;
1259 /* If it's a Lisp_Buffer_Local_Value, being set not bound,
1260 and we're not within a let that was made for this buffer,
1261 create a new buffer-local binding for the variable.
1262 That means, give this buffer a new assoc for a local value
1263 and load that binding. */
1266 tem1
= Fcons (symbol
, XCDR (current_alist_element
));
1267 buf
->local_var_alist
1268 = Fcons (tem1
, buf
->local_var_alist
);
1272 /* Record which binding is now loaded. */
1273 XSETCAR (XBUFFER_LOCAL_VALUE (valcontents
)->cdr
,
1276 /* Set `buffer' and `frame' slots for the binding now loaded. */
1277 XSETBUFFER (XBUFFER_LOCAL_VALUE (valcontents
)->buffer
, buf
);
1278 XBUFFER_LOCAL_VALUE (valcontents
)->frame
= selected_frame
;
1280 innercontents
= XBUFFER_LOCAL_VALUE (valcontents
)->realvalue
;
1283 /* If storing void (making the symbol void), forward only through
1284 buffer-local indicator, not through Lisp_Objfwd, etc. */
1286 store_symval_forwarding (symbol
, Qnil
, newval
, buf
);
1288 store_symval_forwarding (symbol
, innercontents
, newval
, buf
);
1290 /* If we just set a variable whose current binding is frame-local,
1291 store the new value in the frame parameter too. */
1293 if (BUFFER_LOCAL_VALUEP (valcontents
)
1294 || SOME_BUFFER_LOCAL_VALUEP (valcontents
))
1296 /* What binding is loaded right now? */
1297 current_alist_element
1298 = XCAR (XBUFFER_LOCAL_VALUE (valcontents
)->cdr
);
1300 /* If the current buffer is not the buffer whose binding is
1301 loaded, or if there may be frame-local bindings and the frame
1302 isn't the right one, or if it's a Lisp_Buffer_Local_Value and
1303 the default binding is loaded, the loaded binding may be the
1305 if (XBUFFER_LOCAL_VALUE (valcontents
)->found_for_frame
)
1306 XSETCDR (current_alist_element
, newval
);
1312 /* Access or set a buffer-local symbol's default value. */
1314 /* Return the default value of SYMBOL, but don't check for voidness.
1315 Return Qunbound if it is void. */
1318 default_value (symbol
)
1321 register Lisp_Object valcontents
;
1323 CHECK_SYMBOL (symbol
);
1324 valcontents
= SYMBOL_VALUE (symbol
);
1326 /* For a built-in buffer-local variable, get the default value
1327 rather than letting do_symval_forwarding get the current value. */
1328 if (BUFFER_OBJFWDP (valcontents
))
1330 int offset
= XBUFFER_OBJFWD (valcontents
)->offset
;
1331 if (PER_BUFFER_IDX (offset
) != 0)
1332 return PER_BUFFER_DEFAULT (offset
);
1335 /* Handle user-created local variables. */
1336 if (BUFFER_LOCAL_VALUEP (valcontents
)
1337 || SOME_BUFFER_LOCAL_VALUEP (valcontents
))
1339 /* If var is set up for a buffer that lacks a local value for it,
1340 the current value is nominally the default value.
1341 But the `realvalue' slot may be more up to date, since
1342 ordinary setq stores just that slot. So use that. */
1343 Lisp_Object current_alist_element
, alist_element_car
;
1344 current_alist_element
1345 = XCAR (XBUFFER_LOCAL_VALUE (valcontents
)->cdr
);
1346 alist_element_car
= XCAR (current_alist_element
);
1347 if (EQ (alist_element_car
, current_alist_element
))
1348 return do_symval_forwarding (XBUFFER_LOCAL_VALUE (valcontents
)->realvalue
);
1350 return XCDR (XBUFFER_LOCAL_VALUE (valcontents
)->cdr
);
1352 /* For other variables, get the current value. */
1353 return do_symval_forwarding (valcontents
);
1356 DEFUN ("default-boundp", Fdefault_boundp
, Sdefault_boundp
, 1, 1, 0,
1357 doc
: /* Return t if SYMBOL has a non-void default value.
1358 This is the value that is seen in buffers that do not have their own values
1359 for this variable. */)
1363 register Lisp_Object value
;
1365 value
= default_value (symbol
);
1366 return (EQ (value
, Qunbound
) ? Qnil
: Qt
);
1369 DEFUN ("default-value", Fdefault_value
, Sdefault_value
, 1, 1, 0,
1370 doc
: /* Return SYMBOL's default value.
1371 This is the value that is seen in buffers that do not have their own values
1372 for this variable. The default value is meaningful for variables with
1373 local bindings in certain buffers. */)
1377 register Lisp_Object value
;
1379 value
= default_value (symbol
);
1380 if (!EQ (value
, Qunbound
))
1383 xsignal1 (Qvoid_variable
, symbol
);
1386 DEFUN ("set-default", Fset_default
, Sset_default
, 2, 2, 0,
1387 doc
: /* Set SYMBOL's default value to VALUE. SYMBOL and VALUE are evaluated.
1388 The default value is seen in buffers that do not have their own values
1389 for this variable. */)
1391 Lisp_Object symbol
, value
;
1393 register Lisp_Object valcontents
, current_alist_element
, alist_element_buffer
;
1395 CHECK_SYMBOL (symbol
);
1396 valcontents
= SYMBOL_VALUE (symbol
);
1398 /* Handle variables like case-fold-search that have special slots
1399 in the buffer. Make them work apparently like Lisp_Buffer_Local_Value
1401 if (BUFFER_OBJFWDP (valcontents
))
1403 int offset
= XBUFFER_OBJFWD (valcontents
)->offset
;
1404 int idx
= PER_BUFFER_IDX (offset
);
1406 PER_BUFFER_DEFAULT (offset
) = value
;
1408 /* If this variable is not always local in all buffers,
1409 set it in the buffers that don't nominally have a local value. */
1414 for (b
= all_buffers
; b
; b
= b
->next
)
1415 if (!PER_BUFFER_VALUE_P (b
, idx
))
1416 PER_BUFFER_VALUE (b
, offset
) = value
;
1421 if (!BUFFER_LOCAL_VALUEP (valcontents
)
1422 && !SOME_BUFFER_LOCAL_VALUEP (valcontents
))
1423 return Fset (symbol
, value
);
1425 /* Store new value into the DEFAULT-VALUE slot. */
1426 XSETCDR (XBUFFER_LOCAL_VALUE (valcontents
)->cdr
, value
);
1428 /* If the default binding is now loaded, set the REALVALUE slot too. */
1429 current_alist_element
1430 = XCAR (XBUFFER_LOCAL_VALUE (valcontents
)->cdr
);
1431 alist_element_buffer
= Fcar (current_alist_element
);
1432 if (EQ (alist_element_buffer
, current_alist_element
))
1433 store_symval_forwarding (symbol
,
1434 XBUFFER_LOCAL_VALUE (valcontents
)->realvalue
,
1440 DEFUN ("setq-default", Fsetq_default
, Ssetq_default
, 0, UNEVALLED
, 0,
1441 doc
: /* Set the default value of variable VAR to VALUE.
1442 VAR, the variable name, is literal (not evaluated);
1443 VALUE is an expression: it is evaluated and its value returned.
1444 The default value of a variable is seen in buffers
1445 that do not have their own values for the variable.
1447 More generally, you can use multiple variables and values, as in
1448 (setq-default VAR VALUE VAR VALUE...)
1449 This sets each VAR's default value to the corresponding VALUE.
1450 The VALUE for the Nth VAR can refer to the new default values
1452 usage: (setq-default [VAR VALUE]...) */)
1456 register Lisp_Object args_left
;
1457 register Lisp_Object val
, symbol
;
1458 struct gcpro gcpro1
;
1468 val
= Feval (Fcar (Fcdr (args_left
)));
1469 symbol
= XCAR (args_left
);
1470 Fset_default (symbol
, val
);
1471 args_left
= Fcdr (XCDR (args_left
));
1473 while (!NILP (args_left
));
1479 /* Lisp functions for creating and removing buffer-local variables. */
1481 DEFUN ("make-variable-buffer-local", Fmake_variable_buffer_local
, Smake_variable_buffer_local
,
1482 1, 1, "vMake Variable Buffer Local: ",
1483 doc
: /* Make VARIABLE become buffer-local whenever it is set.
1484 At any time, the value for the current buffer is in effect,
1485 unless the variable has never been set in this buffer,
1486 in which case the default value is in effect.
1487 Note that binding the variable with `let', or setting it while
1488 a `let'-style binding made in this buffer is in effect,
1489 does not make the variable buffer-local. Return VARIABLE.
1491 In most cases it is better to use `make-local-variable',
1492 which makes a variable local in just one buffer.
1494 The function `default-value' gets the default value and `set-default' sets it. */)
1496 register Lisp_Object variable
;
1498 register Lisp_Object tem
, valcontents
, newval
;
1500 CHECK_SYMBOL (variable
);
1501 variable
= indirect_variable (variable
);
1503 valcontents
= SYMBOL_VALUE (variable
);
1504 if (EQ (variable
, Qnil
) || EQ (variable
, Qt
) || KBOARD_OBJFWDP (valcontents
))
1505 error ("Symbol %s may not be buffer-local", SDATA (SYMBOL_NAME (variable
)));
1507 if (BUFFER_LOCAL_VALUEP (valcontents
) || BUFFER_OBJFWDP (valcontents
))
1509 if (SOME_BUFFER_LOCAL_VALUEP (valcontents
))
1511 XMISCTYPE (SYMBOL_VALUE (variable
)) = Lisp_Misc_Buffer_Local_Value
;
1514 if (EQ (valcontents
, Qunbound
))
1515 SET_SYMBOL_VALUE (variable
, Qnil
);
1516 tem
= Fcons (Qnil
, Fsymbol_value (variable
));
1518 newval
= allocate_misc ();
1519 XMISCTYPE (newval
) = Lisp_Misc_Buffer_Local_Value
;
1520 XBUFFER_LOCAL_VALUE (newval
)->realvalue
= SYMBOL_VALUE (variable
);
1521 XBUFFER_LOCAL_VALUE (newval
)->buffer
= Fcurrent_buffer ();
1522 XBUFFER_LOCAL_VALUE (newval
)->frame
= Qnil
;
1523 XBUFFER_LOCAL_VALUE (newval
)->found_for_buffer
= 0;
1524 XBUFFER_LOCAL_VALUE (newval
)->found_for_frame
= 0;
1525 XBUFFER_LOCAL_VALUE (newval
)->check_frame
= 0;
1526 XBUFFER_LOCAL_VALUE (newval
)->cdr
= tem
;
1527 SET_SYMBOL_VALUE (variable
, newval
);
1531 DEFUN ("make-local-variable", Fmake_local_variable
, Smake_local_variable
,
1532 1, 1, "vMake Local Variable: ",
1533 doc
: /* Make VARIABLE have a separate value in the current buffer.
1534 Other buffers will continue to share a common default value.
1535 \(The buffer-local value of VARIABLE starts out as the same value
1536 VARIABLE previously had. If VARIABLE was void, it remains void.\)
1539 If the variable is already arranged to become local when set,
1540 this function causes a local value to exist for this buffer,
1541 just as setting the variable would do.
1543 This function returns VARIABLE, and therefore
1544 (set (make-local-variable 'VARIABLE) VALUE-EXP)
1547 See also `make-variable-buffer-local'.
1549 Do not use `make-local-variable' to make a hook variable buffer-local.
1550 Instead, use `add-hook' and specify t for the LOCAL argument. */)
1552 register Lisp_Object variable
;
1554 register Lisp_Object tem
, valcontents
;
1556 CHECK_SYMBOL (variable
);
1557 variable
= indirect_variable (variable
);
1559 valcontents
= SYMBOL_VALUE (variable
);
1560 if (EQ (variable
, Qnil
) || EQ (variable
, Qt
) || KBOARD_OBJFWDP (valcontents
))
1561 error ("Symbol %s may not be buffer-local", SDATA (SYMBOL_NAME (variable
)));
1563 if (BUFFER_LOCAL_VALUEP (valcontents
) || BUFFER_OBJFWDP (valcontents
))
1565 tem
= Fboundp (variable
);
1567 /* Make sure the symbol has a local value in this particular buffer,
1568 by setting it to the same value it already has. */
1569 Fset (variable
, (EQ (tem
, Qt
) ? Fsymbol_value (variable
) : Qunbound
));
1572 /* Make sure symbol is set up to hold per-buffer values. */
1573 if (!SOME_BUFFER_LOCAL_VALUEP (valcontents
))
1576 tem
= Fcons (Qnil
, do_symval_forwarding (valcontents
));
1578 newval
= allocate_misc ();
1579 XMISCTYPE (newval
) = Lisp_Misc_Some_Buffer_Local_Value
;
1580 XBUFFER_LOCAL_VALUE (newval
)->realvalue
= SYMBOL_VALUE (variable
);
1581 XBUFFER_LOCAL_VALUE (newval
)->buffer
= Qnil
;
1582 XBUFFER_LOCAL_VALUE (newval
)->frame
= Qnil
;
1583 XBUFFER_LOCAL_VALUE (newval
)->found_for_buffer
= 0;
1584 XBUFFER_LOCAL_VALUE (newval
)->found_for_frame
= 0;
1585 XBUFFER_LOCAL_VALUE (newval
)->check_frame
= 0;
1586 XBUFFER_LOCAL_VALUE (newval
)->cdr
= tem
;
1587 SET_SYMBOL_VALUE (variable
, newval
);
1589 /* Make sure this buffer has its own value of symbol. */
1590 tem
= Fassq (variable
, current_buffer
->local_var_alist
);
1593 /* Swap out any local binding for some other buffer, and make
1594 sure the current value is permanently recorded, if it's the
1596 find_symbol_value (variable
);
1598 current_buffer
->local_var_alist
1599 = Fcons (Fcons (variable
, XCDR (XBUFFER_LOCAL_VALUE (SYMBOL_VALUE (variable
))->cdr
)),
1600 current_buffer
->local_var_alist
);
1602 /* Make sure symbol does not think it is set up for this buffer;
1603 force it to look once again for this buffer's value. */
1605 Lisp_Object
*pvalbuf
;
1607 valcontents
= SYMBOL_VALUE (variable
);
1609 pvalbuf
= &XBUFFER_LOCAL_VALUE (valcontents
)->buffer
;
1610 if (current_buffer
== XBUFFER (*pvalbuf
))
1612 XBUFFER_LOCAL_VALUE (valcontents
)->found_for_buffer
= 0;
1616 /* If the symbol forwards into a C variable, then load the binding
1617 for this buffer now. If C code modifies the variable before we
1618 load the binding in, then that new value will clobber the default
1619 binding the next time we unload it. */
1620 valcontents
= XBUFFER_LOCAL_VALUE (SYMBOL_VALUE (variable
))->realvalue
;
1621 if (INTFWDP (valcontents
) || BOOLFWDP (valcontents
) || OBJFWDP (valcontents
))
1622 swap_in_symval_forwarding (variable
, SYMBOL_VALUE (variable
));
1627 DEFUN ("kill-local-variable", Fkill_local_variable
, Skill_local_variable
,
1628 1, 1, "vKill Local Variable: ",
1629 doc
: /* Make VARIABLE no longer have a separate value in the current buffer.
1630 From now on the default value will apply in this buffer. Return VARIABLE. */)
1632 register Lisp_Object variable
;
1634 register Lisp_Object tem
, valcontents
;
1636 CHECK_SYMBOL (variable
);
1637 variable
= indirect_variable (variable
);
1639 valcontents
= SYMBOL_VALUE (variable
);
1641 if (BUFFER_OBJFWDP (valcontents
))
1643 int offset
= XBUFFER_OBJFWD (valcontents
)->offset
;
1644 int idx
= PER_BUFFER_IDX (offset
);
1648 SET_PER_BUFFER_VALUE_P (current_buffer
, idx
, 0);
1649 PER_BUFFER_VALUE (current_buffer
, offset
)
1650 = PER_BUFFER_DEFAULT (offset
);
1655 if (!BUFFER_LOCAL_VALUEP (valcontents
)
1656 && !SOME_BUFFER_LOCAL_VALUEP (valcontents
))
1659 /* Get rid of this buffer's alist element, if any. */
1661 tem
= Fassq (variable
, current_buffer
->local_var_alist
);
1663 current_buffer
->local_var_alist
1664 = Fdelq (tem
, current_buffer
->local_var_alist
);
1666 /* If the symbol is set up with the current buffer's binding
1667 loaded, recompute its value. We have to do it now, or else
1668 forwarded objects won't work right. */
1670 Lisp_Object
*pvalbuf
, buf
;
1671 valcontents
= SYMBOL_VALUE (variable
);
1672 pvalbuf
= &XBUFFER_LOCAL_VALUE (valcontents
)->buffer
;
1673 XSETBUFFER (buf
, current_buffer
);
1674 if (EQ (buf
, *pvalbuf
))
1677 XBUFFER_LOCAL_VALUE (valcontents
)->found_for_buffer
= 0;
1678 find_symbol_value (variable
);
1685 /* Lisp functions for creating and removing buffer-local variables. */
1687 DEFUN ("make-variable-frame-local", Fmake_variable_frame_local
, Smake_variable_frame_local
,
1688 1, 1, "vMake Variable Frame Local: ",
1689 doc
: /* Enable VARIABLE to have frame-local bindings.
1690 This does not create any frame-local bindings for VARIABLE,
1691 it just makes them possible.
1693 A frame-local binding is actually a frame parameter value.
1694 If a frame F has a value for the frame parameter named VARIABLE,
1695 that also acts as a frame-local binding for VARIABLE in F--
1696 provided this function has been called to enable VARIABLE
1697 to have frame-local bindings at all.
1699 The only way to create a frame-local binding for VARIABLE in a frame
1700 is to set the VARIABLE frame parameter of that frame. See
1701 `modify-frame-parameters' for how to set frame parameters.
1703 Buffer-local bindings take precedence over frame-local bindings. */)
1705 register Lisp_Object variable
;
1707 register Lisp_Object tem
, valcontents
, newval
;
1709 CHECK_SYMBOL (variable
);
1710 variable
= indirect_variable (variable
);
1712 valcontents
= SYMBOL_VALUE (variable
);
1713 if (EQ (variable
, Qnil
) || EQ (variable
, Qt
) || KBOARD_OBJFWDP (valcontents
)
1714 || BUFFER_OBJFWDP (valcontents
))
1715 error ("Symbol %s may not be frame-local", SDATA (SYMBOL_NAME (variable
)));
1717 if (BUFFER_LOCAL_VALUEP (valcontents
)
1718 || SOME_BUFFER_LOCAL_VALUEP (valcontents
))
1720 XBUFFER_LOCAL_VALUE (valcontents
)->check_frame
= 1;
1724 if (EQ (valcontents
, Qunbound
))
1725 SET_SYMBOL_VALUE (variable
, Qnil
);
1726 tem
= Fcons (Qnil
, Fsymbol_value (variable
));
1728 newval
= allocate_misc ();
1729 XMISCTYPE (newval
) = Lisp_Misc_Some_Buffer_Local_Value
;
1730 XBUFFER_LOCAL_VALUE (newval
)->realvalue
= SYMBOL_VALUE (variable
);
1731 XBUFFER_LOCAL_VALUE (newval
)->buffer
= Qnil
;
1732 XBUFFER_LOCAL_VALUE (newval
)->frame
= Qnil
;
1733 XBUFFER_LOCAL_VALUE (newval
)->found_for_buffer
= 0;
1734 XBUFFER_LOCAL_VALUE (newval
)->found_for_frame
= 0;
1735 XBUFFER_LOCAL_VALUE (newval
)->check_frame
= 1;
1736 XBUFFER_LOCAL_VALUE (newval
)->cdr
= tem
;
1737 SET_SYMBOL_VALUE (variable
, newval
);
1741 DEFUN ("local-variable-p", Flocal_variable_p
, Slocal_variable_p
,
1743 doc
: /* Non-nil if VARIABLE has a local binding in buffer BUFFER.
1744 BUFFER defaults to the current buffer. */)
1746 register Lisp_Object variable
, buffer
;
1748 Lisp_Object valcontents
;
1749 register struct buffer
*buf
;
1752 buf
= current_buffer
;
1755 CHECK_BUFFER (buffer
);
1756 buf
= XBUFFER (buffer
);
1759 CHECK_SYMBOL (variable
);
1760 variable
= indirect_variable (variable
);
1762 valcontents
= SYMBOL_VALUE (variable
);
1763 if (BUFFER_LOCAL_VALUEP (valcontents
)
1764 || SOME_BUFFER_LOCAL_VALUEP (valcontents
))
1766 Lisp_Object tail
, elt
;
1768 for (tail
= buf
->local_var_alist
; CONSP (tail
); tail
= XCDR (tail
))
1771 if (EQ (variable
, XCAR (elt
)))
1775 if (BUFFER_OBJFWDP (valcontents
))
1777 int offset
= XBUFFER_OBJFWD (valcontents
)->offset
;
1778 int idx
= PER_BUFFER_IDX (offset
);
1779 if (idx
== -1 || PER_BUFFER_VALUE_P (buf
, idx
))
1785 DEFUN ("local-variable-if-set-p", Flocal_variable_if_set_p
, Slocal_variable_if_set_p
,
1787 doc
: /* Non-nil if VARIABLE will be local in buffer BUFFER when set there.
1788 More precisely, this means that setting the variable \(with `set' or`setq'),
1789 while it does not have a `let'-style binding that was made in BUFFER,
1790 will produce a buffer local binding. See Info node
1791 `(elisp)Creating Buffer-Local'.
1792 BUFFER defaults to the current buffer. */)
1794 register Lisp_Object variable
, buffer
;
1796 Lisp_Object valcontents
;
1797 register struct buffer
*buf
;
1800 buf
= current_buffer
;
1803 CHECK_BUFFER (buffer
);
1804 buf
= XBUFFER (buffer
);
1807 CHECK_SYMBOL (variable
);
1808 variable
= indirect_variable (variable
);
1810 valcontents
= SYMBOL_VALUE (variable
);
1812 /* This means that make-variable-buffer-local was done. */
1813 if (BUFFER_LOCAL_VALUEP (valcontents
))
1815 /* All these slots become local if they are set. */
1816 if (BUFFER_OBJFWDP (valcontents
))
1818 if (SOME_BUFFER_LOCAL_VALUEP (valcontents
))
1820 Lisp_Object tail
, elt
;
1821 for (tail
= buf
->local_var_alist
; CONSP (tail
); tail
= XCDR (tail
))
1824 if (EQ (variable
, XCAR (elt
)))
1831 DEFUN ("variable-binding-locus", Fvariable_binding_locus
, Svariable_binding_locus
,
1833 doc
: /* Return a value indicating where VARIABLE's current binding comes from.
1834 If the current binding is buffer-local, the value is the current buffer.
1835 If the current binding is frame-local, the value is the selected frame.
1836 If the current binding is global (the default), the value is nil. */)
1838 register Lisp_Object variable
;
1840 Lisp_Object valcontents
;
1842 CHECK_SYMBOL (variable
);
1843 variable
= indirect_variable (variable
);
1845 /* Make sure the current binding is actually swapped in. */
1846 find_symbol_value (variable
);
1848 valcontents
= XSYMBOL (variable
)->value
;
1850 if (BUFFER_LOCAL_VALUEP (valcontents
)
1851 || SOME_BUFFER_LOCAL_VALUEP (valcontents
)
1852 || BUFFER_OBJFWDP (valcontents
))
1854 /* For a local variable, record both the symbol and which
1855 buffer's or frame's value we are saving. */
1856 if (!NILP (Flocal_variable_p (variable
, Qnil
)))
1857 return Fcurrent_buffer ();
1858 else if (!BUFFER_OBJFWDP (valcontents
)
1859 && XBUFFER_LOCAL_VALUE (valcontents
)->found_for_frame
)
1860 return XBUFFER_LOCAL_VALUE (valcontents
)->frame
;
1866 /* Find the function at the end of a chain of symbol function indirections. */
1868 /* If OBJECT is a symbol, find the end of its function chain and
1869 return the value found there. If OBJECT is not a symbol, just
1870 return it. If there is a cycle in the function chain, signal a
1871 cyclic-function-indirection error.
1873 This is like Findirect_function, except that it doesn't signal an
1874 error if the chain ends up unbound. */
1876 indirect_function (object
)
1877 register Lisp_Object object
;
1879 Lisp_Object tortoise
, hare
;
1881 hare
= tortoise
= object
;
1885 if (!SYMBOLP (hare
) || EQ (hare
, Qunbound
))
1887 hare
= XSYMBOL (hare
)->function
;
1888 if (!SYMBOLP (hare
) || EQ (hare
, Qunbound
))
1890 hare
= XSYMBOL (hare
)->function
;
1892 tortoise
= XSYMBOL (tortoise
)->function
;
1894 if (EQ (hare
, tortoise
))
1895 xsignal1 (Qcyclic_function_indirection
, object
);
1901 DEFUN ("indirect-function", Findirect_function
, Sindirect_function
, 1, 2, 0,
1902 doc
: /* Return the function at the end of OBJECT's function chain.
1903 If OBJECT is not a symbol, just return it. Otherwise, follow all
1904 function indirections to find the final function binding and return it.
1905 If the final symbol in the chain is unbound, signal a void-function error.
1906 Optional arg NOERROR non-nil means to return nil instead of signalling.
1907 Signal a cyclic-function-indirection error if there is a loop in the
1908 function chain of symbols. */)
1910 register Lisp_Object object
;
1911 Lisp_Object noerror
;
1915 /* Optimize for no indirection. */
1917 if (SYMBOLP (result
) && !EQ (result
, Qunbound
)
1918 && (result
= XSYMBOL (result
)->function
, SYMBOLP (result
)))
1919 result
= indirect_function (result
);
1920 if (!EQ (result
, Qunbound
))
1924 xsignal1 (Qvoid_function
, object
);
1929 /* Extract and set vector and string elements */
1931 DEFUN ("aref", Faref
, Saref
, 2, 2, 0,
1932 doc
: /* Return the element of ARRAY at index IDX.
1933 ARRAY may be a vector, a string, a char-table, a bool-vector,
1934 or a byte-code object. IDX starts at 0. */)
1936 register Lisp_Object array
;
1939 register int idxval
;
1942 idxval
= XINT (idx
);
1943 if (STRINGP (array
))
1947 if (idxval
< 0 || idxval
>= SCHARS (array
))
1948 args_out_of_range (array
, idx
);
1949 if (! STRING_MULTIBYTE (array
))
1950 return make_number ((unsigned char) SREF (array
, idxval
));
1951 idxval_byte
= string_char_to_byte (array
, idxval
);
1953 c
= STRING_CHAR (SDATA (array
) + idxval_byte
,
1954 SBYTES (array
) - idxval_byte
);
1955 return make_number (c
);
1957 else if (BOOL_VECTOR_P (array
))
1961 if (idxval
< 0 || idxval
>= XBOOL_VECTOR (array
)->size
)
1962 args_out_of_range (array
, idx
);
1964 val
= (unsigned char) XBOOL_VECTOR (array
)->data
[idxval
/ BOOL_VECTOR_BITS_PER_CHAR
];
1965 return (val
& (1 << (idxval
% BOOL_VECTOR_BITS_PER_CHAR
)) ? Qt
: Qnil
);
1967 else if (CHAR_TABLE_P (array
))
1974 args_out_of_range (array
, idx
);
1975 if (idxval
< CHAR_TABLE_ORDINARY_SLOTS
)
1977 if (! SINGLE_BYTE_CHAR_P (idxval
))
1978 args_out_of_range (array
, idx
);
1979 /* For ASCII and 8-bit European characters, the element is
1980 stored in the top table. */
1981 val
= XCHAR_TABLE (array
)->contents
[idxval
];
1985 = (idxval
< 0x80 ? CHAR_TABLE_DEFAULT_SLOT_ASCII
1986 : idxval
< 0xA0 ? CHAR_TABLE_DEFAULT_SLOT_8_BIT_CONTROL
1987 : CHAR_TABLE_DEFAULT_SLOT_8_BIT_GRAPHIC
);
1988 val
= XCHAR_TABLE (array
)->contents
[default_slot
];
1991 val
= XCHAR_TABLE (array
)->defalt
;
1992 while (NILP (val
)) /* Follow parents until we find some value. */
1994 array
= XCHAR_TABLE (array
)->parent
;
1997 val
= XCHAR_TABLE (array
)->contents
[idxval
];
1999 val
= XCHAR_TABLE (array
)->defalt
;
2006 Lisp_Object sub_table
;
2007 Lisp_Object current_default
;
2009 SPLIT_CHAR (idxval
, code
[0], code
[1], code
[2]);
2010 if (code
[1] < 32) code
[1] = -1;
2011 else if (code
[2] < 32) code
[2] = -1;
2013 /* Here, the possible range of CODE[0] (== charset ID) is
2014 128..MAX_CHARSET. Since the top level char table contains
2015 data for multibyte characters after 256th element, we must
2016 increment CODE[0] by 128 to get a correct index. */
2018 code
[3] = -1; /* anchor */
2020 try_parent_char_table
:
2021 current_default
= XCHAR_TABLE (array
)->defalt
;
2023 for (i
= 0; code
[i
] >= 0; i
++)
2025 val
= XCHAR_TABLE (sub_table
)->contents
[code
[i
]];
2026 if (SUB_CHAR_TABLE_P (val
))
2029 if (! NILP (XCHAR_TABLE (sub_table
)->defalt
))
2030 current_default
= XCHAR_TABLE (sub_table
)->defalt
;
2035 val
= current_default
;
2038 array
= XCHAR_TABLE (array
)->parent
;
2040 goto try_parent_char_table
;
2045 /* Reaching here means IDXVAL is a generic character in
2046 which each character or a group has independent value.
2047 Essentially it's nonsense to get a value for such a
2048 generic character, but for backward compatibility, we try
2049 the default value and parent. */
2050 val
= current_default
;
2053 array
= XCHAR_TABLE (array
)->parent
;
2055 goto try_parent_char_table
;
2063 if (VECTORP (array
))
2064 size
= XVECTOR (array
)->size
;
2065 else if (COMPILEDP (array
))
2066 size
= XVECTOR (array
)->size
& PSEUDOVECTOR_SIZE_MASK
;
2068 wrong_type_argument (Qarrayp
, array
);
2070 if (idxval
< 0 || idxval
>= size
)
2071 args_out_of_range (array
, idx
);
2072 return XVECTOR (array
)->contents
[idxval
];
2076 DEFUN ("aset", Faset
, Saset
, 3, 3, 0,
2077 doc
: /* Store into the element of ARRAY at index IDX the value NEWELT.
2078 Return NEWELT. ARRAY may be a vector, a string, a char-table or a
2079 bool-vector. IDX starts at 0. */)
2080 (array
, idx
, newelt
)
2081 register Lisp_Object array
;
2082 Lisp_Object idx
, newelt
;
2084 register int idxval
;
2087 idxval
= XINT (idx
);
2088 CHECK_ARRAY (array
, Qarrayp
);
2089 CHECK_IMPURE (array
);
2091 if (VECTORP (array
))
2093 if (idxval
< 0 || idxval
>= XVECTOR (array
)->size
)
2094 args_out_of_range (array
, idx
);
2095 XVECTOR (array
)->contents
[idxval
] = newelt
;
2097 else if (BOOL_VECTOR_P (array
))
2101 if (idxval
< 0 || idxval
>= XBOOL_VECTOR (array
)->size
)
2102 args_out_of_range (array
, idx
);
2104 val
= (unsigned char) XBOOL_VECTOR (array
)->data
[idxval
/ BOOL_VECTOR_BITS_PER_CHAR
];
2106 if (! NILP (newelt
))
2107 val
|= 1 << (idxval
% BOOL_VECTOR_BITS_PER_CHAR
);
2109 val
&= ~(1 << (idxval
% BOOL_VECTOR_BITS_PER_CHAR
));
2110 XBOOL_VECTOR (array
)->data
[idxval
/ BOOL_VECTOR_BITS_PER_CHAR
] = val
;
2112 else if (CHAR_TABLE_P (array
))
2115 args_out_of_range (array
, idx
);
2116 if (idxval
< CHAR_TABLE_ORDINARY_SLOTS
)
2118 if (! SINGLE_BYTE_CHAR_P (idxval
))
2119 args_out_of_range (array
, idx
);
2120 XCHAR_TABLE (array
)->contents
[idxval
] = newelt
;
2127 SPLIT_CHAR (idxval
, code
[0], code
[1], code
[2]);
2128 if (code
[1] < 32) code
[1] = -1;
2129 else if (code
[2] < 32) code
[2] = -1;
2131 /* See the comment of the corresponding part in Faref. */
2133 code
[3] = -1; /* anchor */
2134 for (i
= 0; code
[i
+ 1] >= 0; i
++)
2136 val
= XCHAR_TABLE (array
)->contents
[code
[i
]];
2137 if (SUB_CHAR_TABLE_P (val
))
2143 /* VAL is a leaf. Create a sub char table with the
2144 initial value VAL and look into it. */
2146 temp
= make_sub_char_table (val
);
2147 XCHAR_TABLE (array
)->contents
[code
[i
]] = temp
;
2151 XCHAR_TABLE (array
)->contents
[code
[i
]] = newelt
;
2154 else if (STRING_MULTIBYTE (array
))
2156 int idxval_byte
, prev_bytes
, new_bytes
, nbytes
;
2157 unsigned char workbuf
[MAX_MULTIBYTE_LENGTH
], *p0
= workbuf
, *p1
;
2159 if (idxval
< 0 || idxval
>= SCHARS (array
))
2160 args_out_of_range (array
, idx
);
2161 CHECK_NUMBER (newelt
);
2163 nbytes
= SBYTES (array
);
2165 idxval_byte
= string_char_to_byte (array
, idxval
);
2166 p1
= SDATA (array
) + idxval_byte
;
2167 PARSE_MULTIBYTE_SEQ (p1
, nbytes
- idxval_byte
, prev_bytes
);
2168 new_bytes
= CHAR_STRING (XINT (newelt
), p0
);
2169 if (prev_bytes
!= new_bytes
)
2171 /* We must relocate the string data. */
2172 int nchars
= SCHARS (array
);
2176 SAFE_ALLOCA (str
, unsigned char *, nbytes
);
2177 bcopy (SDATA (array
), str
, nbytes
);
2178 allocate_string_data (XSTRING (array
), nchars
,
2179 nbytes
+ new_bytes
- prev_bytes
);
2180 bcopy (str
, SDATA (array
), idxval_byte
);
2181 p1
= SDATA (array
) + idxval_byte
;
2182 bcopy (str
+ idxval_byte
+ prev_bytes
, p1
+ new_bytes
,
2183 nbytes
- (idxval_byte
+ prev_bytes
));
2185 clear_string_char_byte_cache ();
2192 if (idxval
< 0 || idxval
>= SCHARS (array
))
2193 args_out_of_range (array
, idx
);
2194 CHECK_NUMBER (newelt
);
2196 if (XINT (newelt
) < 0 || SINGLE_BYTE_CHAR_P (XINT (newelt
)))
2197 SSET (array
, idxval
, XINT (newelt
));
2200 /* We must relocate the string data while converting it to
2202 int idxval_byte
, prev_bytes
, new_bytes
;
2203 unsigned char workbuf
[MAX_MULTIBYTE_LENGTH
], *p0
= workbuf
, *p1
;
2204 unsigned char *origstr
= SDATA (array
), *str
;
2208 nchars
= SCHARS (array
);
2209 nbytes
= idxval_byte
= count_size_as_multibyte (origstr
, idxval
);
2210 nbytes
+= count_size_as_multibyte (origstr
+ idxval
,
2212 SAFE_ALLOCA (str
, unsigned char *, nbytes
);
2213 copy_text (SDATA (array
), str
, nchars
, 0, 1);
2214 PARSE_MULTIBYTE_SEQ (str
+ idxval_byte
, nbytes
- idxval_byte
,
2216 new_bytes
= CHAR_STRING (XINT (newelt
), p0
);
2217 allocate_string_data (XSTRING (array
), nchars
,
2218 nbytes
+ new_bytes
- prev_bytes
);
2219 bcopy (str
, SDATA (array
), idxval_byte
);
2220 p1
= SDATA (array
) + idxval_byte
;
2223 bcopy (str
+ idxval_byte
+ prev_bytes
, p1
,
2224 nbytes
- (idxval_byte
+ prev_bytes
));
2226 clear_string_char_byte_cache ();
2233 /* Arithmetic functions */
2235 enum comparison
{ equal
, notequal
, less
, grtr
, less_or_equal
, grtr_or_equal
};
2238 arithcompare (num1
, num2
, comparison
)
2239 Lisp_Object num1
, num2
;
2240 enum comparison comparison
;
2242 double f1
= 0, f2
= 0;
2245 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (num1
);
2246 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (num2
);
2248 if (FLOATP (num1
) || FLOATP (num2
))
2251 f1
= (FLOATP (num1
)) ? XFLOAT_DATA (num1
) : XINT (num1
);
2252 f2
= (FLOATP (num2
)) ? XFLOAT_DATA (num2
) : XINT (num2
);
2258 if (floatp
? f1
== f2
: XINT (num1
) == XINT (num2
))
2263 if (floatp
? f1
!= f2
: XINT (num1
) != XINT (num2
))
2268 if (floatp
? f1
< f2
: XINT (num1
) < XINT (num2
))
2273 if (floatp
? f1
<= f2
: XINT (num1
) <= XINT (num2
))
2278 if (floatp
? f1
> f2
: XINT (num1
) > XINT (num2
))
2283 if (floatp
? f1
>= f2
: XINT (num1
) >= XINT (num2
))
2292 DEFUN ("=", Feqlsign
, Seqlsign
, 2, 2, 0,
2293 doc
: /* Return t if two args, both numbers or markers, are equal. */)
2295 register Lisp_Object num1
, num2
;
2297 return arithcompare (num1
, num2
, equal
);
2300 DEFUN ("<", Flss
, Slss
, 2, 2, 0,
2301 doc
: /* Return t if first arg is less than second arg. Both must be numbers or markers. */)
2303 register Lisp_Object num1
, num2
;
2305 return arithcompare (num1
, num2
, less
);
2308 DEFUN (">", Fgtr
, Sgtr
, 2, 2, 0,
2309 doc
: /* Return t if first arg is greater than second arg. Both must be numbers or markers. */)
2311 register Lisp_Object num1
, num2
;
2313 return arithcompare (num1
, num2
, grtr
);
2316 DEFUN ("<=", Fleq
, Sleq
, 2, 2, 0,
2317 doc
: /* Return t if first arg is less than or equal to second arg.
2318 Both must be numbers or markers. */)
2320 register Lisp_Object num1
, num2
;
2322 return arithcompare (num1
, num2
, less_or_equal
);
2325 DEFUN (">=", Fgeq
, Sgeq
, 2, 2, 0,
2326 doc
: /* Return t if first arg is greater than or equal to second arg.
2327 Both must be numbers or markers. */)
2329 register Lisp_Object num1
, num2
;
2331 return arithcompare (num1
, num2
, grtr_or_equal
);
2334 DEFUN ("/=", Fneq
, Sneq
, 2, 2, 0,
2335 doc
: /* Return t if first arg is not equal to second arg. Both must be numbers or markers. */)
2337 register Lisp_Object num1
, num2
;
2339 return arithcompare (num1
, num2
, notequal
);
2342 DEFUN ("zerop", Fzerop
, Szerop
, 1, 1, 0,
2343 doc
: /* Return t if NUMBER is zero. */)
2345 register Lisp_Object number
;
2347 CHECK_NUMBER_OR_FLOAT (number
);
2349 if (FLOATP (number
))
2351 if (XFLOAT_DATA (number
) == 0.0)
2361 /* Convert between long values and pairs of Lisp integers.
2362 Note that long_to_cons returns a single Lisp integer
2363 when the value fits in one. */
2369 unsigned long top
= i
>> 16;
2370 unsigned int bot
= i
& 0xFFFF;
2372 return make_number (bot
);
2373 if (top
== (unsigned long)-1 >> 16)
2374 return Fcons (make_number (-1), make_number (bot
));
2375 return Fcons (make_number (top
), make_number (bot
));
2382 Lisp_Object top
, bot
;
2389 return ((XINT (top
) << 16) | XINT (bot
));
2392 DEFUN ("number-to-string", Fnumber_to_string
, Snumber_to_string
, 1, 1, 0,
2393 doc
: /* Return the decimal representation of NUMBER as a string.
2394 Uses a minus sign if negative.
2395 NUMBER may be an integer or a floating point number. */)
2399 char buffer
[VALBITS
];
2401 CHECK_NUMBER_OR_FLOAT (number
);
2403 if (FLOATP (number
))
2405 char pigbuf
[350]; /* see comments in float_to_string */
2407 float_to_string (pigbuf
, XFLOAT_DATA (number
));
2408 return build_string (pigbuf
);
2411 if (sizeof (int) == sizeof (EMACS_INT
))
2412 sprintf (buffer
, "%d", XINT (number
));
2413 else if (sizeof (long) == sizeof (EMACS_INT
))
2414 sprintf (buffer
, "%ld", (long) XINT (number
));
2417 return build_string (buffer
);
2421 digit_to_number (character
, base
)
2422 int character
, base
;
2426 if (character
>= '0' && character
<= '9')
2427 digit
= character
- '0';
2428 else if (character
>= 'a' && character
<= 'z')
2429 digit
= character
- 'a' + 10;
2430 else if (character
>= 'A' && character
<= 'Z')
2431 digit
= character
- 'A' + 10;
2441 DEFUN ("string-to-number", Fstring_to_number
, Sstring_to_number
, 1, 2, 0,
2442 doc
: /* Parse STRING as a decimal number and return the number.
2443 This parses both integers and floating point numbers.
2444 It ignores leading spaces and tabs.
2446 If BASE, interpret STRING as a number in that base. If BASE isn't
2447 present, base 10 is used. BASE must be between 2 and 16 (inclusive).
2448 If the base used is not 10, floating point is not recognized. */)
2450 register Lisp_Object string
, base
;
2452 register unsigned char *p
;
2457 CHECK_STRING (string
);
2463 CHECK_NUMBER (base
);
2465 if (b
< 2 || b
> 16)
2466 xsignal1 (Qargs_out_of_range
, base
);
2469 /* Skip any whitespace at the front of the number. Some versions of
2470 atoi do this anyway, so we might as well make Emacs lisp consistent. */
2472 while (*p
== ' ' || *p
== '\t')
2483 if (isfloat_string (p
) && b
== 10)
2484 val
= make_float (sign
* atof (p
));
2491 int digit
= digit_to_number (*p
++, b
);
2497 val
= make_fixnum_or_float (sign
* v
);
2517 static Lisp_Object float_arith_driver
P_ ((double, int, enum arithop
,
2518 int, Lisp_Object
*));
2519 extern Lisp_Object
fmod_float ();
2522 arith_driver (code
, nargs
, args
)
2525 register Lisp_Object
*args
;
2527 register Lisp_Object val
;
2528 register int argnum
;
2529 register EMACS_INT accum
= 0;
2530 register EMACS_INT next
;
2532 switch (SWITCH_ENUM_CAST (code
))
2550 for (argnum
= 0; argnum
< nargs
; argnum
++)
2552 /* Using args[argnum] as argument to CHECK_NUMBER_... */
2554 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (val
);
2557 return float_arith_driver ((double) accum
, argnum
, code
,
2560 next
= XINT (args
[argnum
]);
2561 switch (SWITCH_ENUM_CAST (code
))
2567 accum
= argnum
? accum
- next
: nargs
== 1 ? - next
: next
;
2578 xsignal0 (Qarith_error
);
2592 if (!argnum
|| next
> accum
)
2596 if (!argnum
|| next
< accum
)
2602 XSETINT (val
, accum
);
2607 #define isnan(x) ((x) != (x))
2610 float_arith_driver (accum
, argnum
, code
, nargs
, args
)
2612 register int argnum
;
2615 register Lisp_Object
*args
;
2617 register Lisp_Object val
;
2620 for (; argnum
< nargs
; argnum
++)
2622 val
= args
[argnum
]; /* using args[argnum] as argument to CHECK_NUMBER_... */
2623 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (val
);
2627 next
= XFLOAT_DATA (val
);
2631 args
[argnum
] = val
; /* runs into a compiler bug. */
2632 next
= XINT (args
[argnum
]);
2634 switch (SWITCH_ENUM_CAST (code
))
2640 accum
= argnum
? accum
- next
: nargs
== 1 ? - next
: next
;
2650 if (! IEEE_FLOATING_POINT
&& next
== 0)
2651 xsignal0 (Qarith_error
);
2658 return wrong_type_argument (Qinteger_or_marker_p
, val
);
2660 if (!argnum
|| isnan (next
) || next
> accum
)
2664 if (!argnum
|| isnan (next
) || next
< accum
)
2670 return make_float (accum
);
2674 DEFUN ("+", Fplus
, Splus
, 0, MANY
, 0,
2675 doc
: /* Return sum of any number of arguments, which are numbers or markers.
2676 usage: (+ &rest NUMBERS-OR-MARKERS) */)
2681 return arith_driver (Aadd
, nargs
, args
);
2684 DEFUN ("-", Fminus
, Sminus
, 0, MANY
, 0,
2685 doc
: /* Negate number or subtract numbers or markers and return the result.
2686 With one arg, negates it. With more than one arg,
2687 subtracts all but the first from the first.
2688 usage: (- &optional NUMBER-OR-MARKER &rest MORE-NUMBERS-OR-MARKERS) */)
2693 return arith_driver (Asub
, nargs
, args
);
2696 DEFUN ("*", Ftimes
, Stimes
, 0, MANY
, 0,
2697 doc
: /* Return product of any number of arguments, which are numbers or markers.
2698 usage: (* &rest NUMBERS-OR-MARKERS) */)
2703 return arith_driver (Amult
, nargs
, args
);
2706 DEFUN ("/", Fquo
, Squo
, 2, MANY
, 0,
2707 doc
: /* Return first argument divided by all the remaining arguments.
2708 The arguments must be numbers or markers.
2709 usage: (/ DIVIDEND DIVISOR &rest DIVISORS) */)
2715 for (argnum
= 2; argnum
< nargs
; argnum
++)
2716 if (FLOATP (args
[argnum
]))
2717 return float_arith_driver (0, 0, Adiv
, nargs
, args
);
2718 return arith_driver (Adiv
, nargs
, args
);
2721 DEFUN ("%", Frem
, Srem
, 2, 2, 0,
2722 doc
: /* Return remainder of X divided by Y.
2723 Both must be integers or markers. */)
2725 register Lisp_Object x
, y
;
2729 CHECK_NUMBER_COERCE_MARKER (x
);
2730 CHECK_NUMBER_COERCE_MARKER (y
);
2732 if (XFASTINT (y
) == 0)
2733 xsignal0 (Qarith_error
);
2735 XSETINT (val
, XINT (x
) % XINT (y
));
2749 /* If the magnitude of the result exceeds that of the divisor, or
2750 the sign of the result does not agree with that of the dividend,
2751 iterate with the reduced value. This does not yield a
2752 particularly accurate result, but at least it will be in the
2753 range promised by fmod. */
2755 r
-= f2
* floor (r
/ f2
);
2756 while (f2
<= (r
< 0 ? -r
: r
) || ((r
< 0) != (f1
< 0) && ! isnan (r
)));
2760 #endif /* ! HAVE_FMOD */
2762 DEFUN ("mod", Fmod
, Smod
, 2, 2, 0,
2763 doc
: /* Return X modulo Y.
2764 The result falls between zero (inclusive) and Y (exclusive).
2765 Both X and Y must be numbers or markers. */)
2767 register Lisp_Object x
, y
;
2772 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (x
);
2773 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (y
);
2775 if (FLOATP (x
) || FLOATP (y
))
2776 return fmod_float (x
, y
);
2782 xsignal0 (Qarith_error
);
2786 /* If the "remainder" comes out with the wrong sign, fix it. */
2787 if (i2
< 0 ? i1
> 0 : i1
< 0)
2794 DEFUN ("max", Fmax
, Smax
, 1, MANY
, 0,
2795 doc
: /* Return largest of all the arguments (which must be numbers or markers).
2796 The value is always a number; markers are converted to numbers.
2797 usage: (max NUMBER-OR-MARKER &rest NUMBERS-OR-MARKERS) */)
2802 return arith_driver (Amax
, nargs
, args
);
2805 DEFUN ("min", Fmin
, Smin
, 1, MANY
, 0,
2806 doc
: /* Return smallest of all the arguments (which must be numbers or markers).
2807 The value is always a number; markers are converted to numbers.
2808 usage: (min NUMBER-OR-MARKER &rest NUMBERS-OR-MARKERS) */)
2813 return arith_driver (Amin
, nargs
, args
);
2816 DEFUN ("logand", Flogand
, Slogand
, 0, MANY
, 0,
2817 doc
: /* Return bitwise-and of all the arguments.
2818 Arguments may be integers, or markers converted to integers.
2819 usage: (logand &rest INTS-OR-MARKERS) */)
2824 return arith_driver (Alogand
, nargs
, args
);
2827 DEFUN ("logior", Flogior
, Slogior
, 0, MANY
, 0,
2828 doc
: /* Return bitwise-or of all the arguments.
2829 Arguments may be integers, or markers converted to integers.
2830 usage: (logior &rest INTS-OR-MARKERS) */)
2835 return arith_driver (Alogior
, nargs
, args
);
2838 DEFUN ("logxor", Flogxor
, Slogxor
, 0, MANY
, 0,
2839 doc
: /* Return bitwise-exclusive-or of all the arguments.
2840 Arguments may be integers, or markers converted to integers.
2841 usage: (logxor &rest INTS-OR-MARKERS) */)
2846 return arith_driver (Alogxor
, nargs
, args
);
2849 DEFUN ("ash", Fash
, Sash
, 2, 2, 0,
2850 doc
: /* Return VALUE with its bits shifted left by COUNT.
2851 If COUNT is negative, shifting is actually to the right.
2852 In this case, the sign bit is duplicated. */)
2854 register Lisp_Object value
, count
;
2856 register Lisp_Object val
;
2858 CHECK_NUMBER (value
);
2859 CHECK_NUMBER (count
);
2861 if (XINT (count
) >= BITS_PER_EMACS_INT
)
2863 else if (XINT (count
) > 0)
2864 XSETINT (val
, XINT (value
) << XFASTINT (count
));
2865 else if (XINT (count
) <= -BITS_PER_EMACS_INT
)
2866 XSETINT (val
, XINT (value
) < 0 ? -1 : 0);
2868 XSETINT (val
, XINT (value
) >> -XINT (count
));
2872 DEFUN ("lsh", Flsh
, Slsh
, 2, 2, 0,
2873 doc
: /* Return VALUE with its bits shifted left by COUNT.
2874 If COUNT is negative, shifting is actually to the right.
2875 In this case, zeros are shifted in on the left. */)
2877 register Lisp_Object value
, count
;
2879 register Lisp_Object val
;
2881 CHECK_NUMBER (value
);
2882 CHECK_NUMBER (count
);
2884 if (XINT (count
) >= BITS_PER_EMACS_INT
)
2886 else if (XINT (count
) > 0)
2887 XSETINT (val
, (EMACS_UINT
) XUINT (value
) << XFASTINT (count
));
2888 else if (XINT (count
) <= -BITS_PER_EMACS_INT
)
2891 XSETINT (val
, (EMACS_UINT
) XUINT (value
) >> -XINT (count
));
2895 DEFUN ("1+", Fadd1
, Sadd1
, 1, 1, 0,
2896 doc
: /* Return NUMBER plus one. NUMBER may be a number or a marker.
2897 Markers are converted to integers. */)
2899 register Lisp_Object number
;
2901 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (number
);
2903 if (FLOATP (number
))
2904 return (make_float (1.0 + XFLOAT_DATA (number
)));
2906 XSETINT (number
, XINT (number
) + 1);
2910 DEFUN ("1-", Fsub1
, Ssub1
, 1, 1, 0,
2911 doc
: /* Return NUMBER minus one. NUMBER may be a number or a marker.
2912 Markers are converted to integers. */)
2914 register Lisp_Object number
;
2916 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (number
);
2918 if (FLOATP (number
))
2919 return (make_float (-1.0 + XFLOAT_DATA (number
)));
2921 XSETINT (number
, XINT (number
) - 1);
2925 DEFUN ("lognot", Flognot
, Slognot
, 1, 1, 0,
2926 doc
: /* Return the bitwise complement of NUMBER. NUMBER must be an integer. */)
2928 register Lisp_Object number
;
2930 CHECK_NUMBER (number
);
2931 XSETINT (number
, ~XINT (number
));
2935 DEFUN ("byteorder", Fbyteorder
, Sbyteorder
, 0, 0, 0,
2936 doc
: /* Return the byteorder for the machine.
2937 Returns 66 (ASCII uppercase B) for big endian machines or 108 (ASCII
2938 lowercase l) for small endian machines. */)
2941 unsigned i
= 0x04030201;
2942 int order
= *(char *)&i
== 1 ? 108 : 66;
2944 return make_number (order
);
2952 Lisp_Object error_tail
, arith_tail
;
2954 Qquote
= intern ("quote");
2955 Qlambda
= intern ("lambda");
2956 Qsubr
= intern ("subr");
2957 Qerror_conditions
= intern ("error-conditions");
2958 Qerror_message
= intern ("error-message");
2959 Qtop_level
= intern ("top-level");
2961 Qerror
= intern ("error");
2962 Qquit
= intern ("quit");
2963 Qwrong_type_argument
= intern ("wrong-type-argument");
2964 Qargs_out_of_range
= intern ("args-out-of-range");
2965 Qvoid_function
= intern ("void-function");
2966 Qcyclic_function_indirection
= intern ("cyclic-function-indirection");
2967 Qcyclic_variable_indirection
= intern ("cyclic-variable-indirection");
2968 Qvoid_variable
= intern ("void-variable");
2969 Qsetting_constant
= intern ("setting-constant");
2970 Qinvalid_read_syntax
= intern ("invalid-read-syntax");
2972 Qinvalid_function
= intern ("invalid-function");
2973 Qwrong_number_of_arguments
= intern ("wrong-number-of-arguments");
2974 Qno_catch
= intern ("no-catch");
2975 Qend_of_file
= intern ("end-of-file");
2976 Qarith_error
= intern ("arith-error");
2977 Qbeginning_of_buffer
= intern ("beginning-of-buffer");
2978 Qend_of_buffer
= intern ("end-of-buffer");
2979 Qbuffer_read_only
= intern ("buffer-read-only");
2980 Qtext_read_only
= intern ("text-read-only");
2981 Qmark_inactive
= intern ("mark-inactive");
2983 Qlistp
= intern ("listp");
2984 Qconsp
= intern ("consp");
2985 Qsymbolp
= intern ("symbolp");
2986 Qkeywordp
= intern ("keywordp");
2987 Qintegerp
= intern ("integerp");
2988 Qnatnump
= intern ("natnump");
2989 Qwholenump
= intern ("wholenump");
2990 Qstringp
= intern ("stringp");
2991 Qarrayp
= intern ("arrayp");
2992 Qsequencep
= intern ("sequencep");
2993 Qbufferp
= intern ("bufferp");
2994 Qvectorp
= intern ("vectorp");
2995 Qchar_or_string_p
= intern ("char-or-string-p");
2996 Qmarkerp
= intern ("markerp");
2997 Qbuffer_or_string_p
= intern ("buffer-or-string-p");
2998 Qinteger_or_marker_p
= intern ("integer-or-marker-p");
2999 Qboundp
= intern ("boundp");
3000 Qfboundp
= intern ("fboundp");
3002 Qfloatp
= intern ("floatp");
3003 Qnumberp
= intern ("numberp");
3004 Qnumber_or_marker_p
= intern ("number-or-marker-p");
3006 Qchar_table_p
= intern ("char-table-p");
3007 Qvector_or_char_table_p
= intern ("vector-or-char-table-p");
3009 Qsubrp
= intern ("subrp");
3010 Qunevalled
= intern ("unevalled");
3011 Qmany
= intern ("many");
3013 Qcdr
= intern ("cdr");
3015 /* Handle automatic advice activation */
3016 Qad_advice_info
= intern ("ad-advice-info");
3017 Qad_activate_internal
= intern ("ad-activate-internal");
3019 error_tail
= Fcons (Qerror
, Qnil
);
3021 /* ERROR is used as a signaler for random errors for which nothing else is right */
3023 Fput (Qerror
, Qerror_conditions
,
3025 Fput (Qerror
, Qerror_message
,
3026 build_string ("error"));
3028 Fput (Qquit
, Qerror_conditions
,
3029 Fcons (Qquit
, Qnil
));
3030 Fput (Qquit
, Qerror_message
,
3031 build_string ("Quit"));
3033 Fput (Qwrong_type_argument
, Qerror_conditions
,
3034 Fcons (Qwrong_type_argument
, error_tail
));
3035 Fput (Qwrong_type_argument
, Qerror_message
,
3036 build_string ("Wrong type argument"));
3038 Fput (Qargs_out_of_range
, Qerror_conditions
,
3039 Fcons (Qargs_out_of_range
, error_tail
));
3040 Fput (Qargs_out_of_range
, Qerror_message
,
3041 build_string ("Args out of range"));
3043 Fput (Qvoid_function
, Qerror_conditions
,
3044 Fcons (Qvoid_function
, error_tail
));
3045 Fput (Qvoid_function
, Qerror_message
,
3046 build_string ("Symbol's function definition is void"));
3048 Fput (Qcyclic_function_indirection
, Qerror_conditions
,
3049 Fcons (Qcyclic_function_indirection
, error_tail
));
3050 Fput (Qcyclic_function_indirection
, Qerror_message
,
3051 build_string ("Symbol's chain of function indirections contains a loop"));
3053 Fput (Qcyclic_variable_indirection
, Qerror_conditions
,
3054 Fcons (Qcyclic_variable_indirection
, error_tail
));
3055 Fput (Qcyclic_variable_indirection
, Qerror_message
,
3056 build_string ("Symbol's chain of variable indirections contains a loop"));
3058 Qcircular_list
= intern ("circular-list");
3059 staticpro (&Qcircular_list
);
3060 Fput (Qcircular_list
, Qerror_conditions
,
3061 Fcons (Qcircular_list
, error_tail
));
3062 Fput (Qcircular_list
, Qerror_message
,
3063 build_string ("List contains a loop"));
3065 Fput (Qvoid_variable
, Qerror_conditions
,
3066 Fcons (Qvoid_variable
, error_tail
));
3067 Fput (Qvoid_variable
, Qerror_message
,
3068 build_string ("Symbol's value as variable is void"));
3070 Fput (Qsetting_constant
, Qerror_conditions
,
3071 Fcons (Qsetting_constant
, error_tail
));
3072 Fput (Qsetting_constant
, Qerror_message
,
3073 build_string ("Attempt to set a constant symbol"));
3075 Fput (Qinvalid_read_syntax
, Qerror_conditions
,
3076 Fcons (Qinvalid_read_syntax
, error_tail
));
3077 Fput (Qinvalid_read_syntax
, Qerror_message
,
3078 build_string ("Invalid read syntax"));
3080 Fput (Qinvalid_function
, Qerror_conditions
,
3081 Fcons (Qinvalid_function
, error_tail
));
3082 Fput (Qinvalid_function
, Qerror_message
,
3083 build_string ("Invalid function"));
3085 Fput (Qwrong_number_of_arguments
, Qerror_conditions
,
3086 Fcons (Qwrong_number_of_arguments
, error_tail
));
3087 Fput (Qwrong_number_of_arguments
, Qerror_message
,
3088 build_string ("Wrong number of arguments"));
3090 Fput (Qno_catch
, Qerror_conditions
,
3091 Fcons (Qno_catch
, error_tail
));
3092 Fput (Qno_catch
, Qerror_message
,
3093 build_string ("No catch for tag"));
3095 Fput (Qend_of_file
, Qerror_conditions
,
3096 Fcons (Qend_of_file
, error_tail
));
3097 Fput (Qend_of_file
, Qerror_message
,
3098 build_string ("End of file during parsing"));
3100 arith_tail
= Fcons (Qarith_error
, error_tail
);
3101 Fput (Qarith_error
, Qerror_conditions
,
3103 Fput (Qarith_error
, Qerror_message
,
3104 build_string ("Arithmetic error"));
3106 Fput (Qbeginning_of_buffer
, Qerror_conditions
,
3107 Fcons (Qbeginning_of_buffer
, error_tail
));
3108 Fput (Qbeginning_of_buffer
, Qerror_message
,
3109 build_string ("Beginning of buffer"));
3111 Fput (Qend_of_buffer
, Qerror_conditions
,
3112 Fcons (Qend_of_buffer
, error_tail
));
3113 Fput (Qend_of_buffer
, Qerror_message
,
3114 build_string ("End of buffer"));
3116 Fput (Qbuffer_read_only
, Qerror_conditions
,
3117 Fcons (Qbuffer_read_only
, error_tail
));
3118 Fput (Qbuffer_read_only
, Qerror_message
,
3119 build_string ("Buffer is read-only"));
3121 Fput (Qtext_read_only
, Qerror_conditions
,
3122 Fcons (Qtext_read_only
, error_tail
));
3123 Fput (Qtext_read_only
, Qerror_message
,
3124 build_string ("Text is read-only"));
3126 Qrange_error
= intern ("range-error");
3127 Qdomain_error
= intern ("domain-error");
3128 Qsingularity_error
= intern ("singularity-error");
3129 Qoverflow_error
= intern ("overflow-error");
3130 Qunderflow_error
= intern ("underflow-error");
3132 Fput (Qdomain_error
, Qerror_conditions
,
3133 Fcons (Qdomain_error
, arith_tail
));
3134 Fput (Qdomain_error
, Qerror_message
,
3135 build_string ("Arithmetic domain error"));
3137 Fput (Qrange_error
, Qerror_conditions
,
3138 Fcons (Qrange_error
, arith_tail
));
3139 Fput (Qrange_error
, Qerror_message
,
3140 build_string ("Arithmetic range error"));
3142 Fput (Qsingularity_error
, Qerror_conditions
,
3143 Fcons (Qsingularity_error
, Fcons (Qdomain_error
, arith_tail
)));
3144 Fput (Qsingularity_error
, Qerror_message
,
3145 build_string ("Arithmetic singularity error"));
3147 Fput (Qoverflow_error
, Qerror_conditions
,
3148 Fcons (Qoverflow_error
, Fcons (Qdomain_error
, arith_tail
)));
3149 Fput (Qoverflow_error
, Qerror_message
,
3150 build_string ("Arithmetic overflow error"));
3152 Fput (Qunderflow_error
, Qerror_conditions
,
3153 Fcons (Qunderflow_error
, Fcons (Qdomain_error
, arith_tail
)));
3154 Fput (Qunderflow_error
, Qerror_message
,
3155 build_string ("Arithmetic underflow error"));
3157 staticpro (&Qrange_error
);
3158 staticpro (&Qdomain_error
);
3159 staticpro (&Qsingularity_error
);
3160 staticpro (&Qoverflow_error
);
3161 staticpro (&Qunderflow_error
);
3165 staticpro (&Qquote
);
3166 staticpro (&Qlambda
);
3168 staticpro (&Qunbound
);
3169 staticpro (&Qerror_conditions
);
3170 staticpro (&Qerror_message
);
3171 staticpro (&Qtop_level
);
3173 staticpro (&Qerror
);
3175 staticpro (&Qwrong_type_argument
);
3176 staticpro (&Qargs_out_of_range
);
3177 staticpro (&Qvoid_function
);
3178 staticpro (&Qcyclic_function_indirection
);
3179 staticpro (&Qcyclic_variable_indirection
);
3180 staticpro (&Qvoid_variable
);
3181 staticpro (&Qsetting_constant
);
3182 staticpro (&Qinvalid_read_syntax
);
3183 staticpro (&Qwrong_number_of_arguments
);
3184 staticpro (&Qinvalid_function
);
3185 staticpro (&Qno_catch
);
3186 staticpro (&Qend_of_file
);
3187 staticpro (&Qarith_error
);
3188 staticpro (&Qbeginning_of_buffer
);
3189 staticpro (&Qend_of_buffer
);
3190 staticpro (&Qbuffer_read_only
);
3191 staticpro (&Qtext_read_only
);
3192 staticpro (&Qmark_inactive
);
3194 staticpro (&Qlistp
);
3195 staticpro (&Qconsp
);
3196 staticpro (&Qsymbolp
);
3197 staticpro (&Qkeywordp
);
3198 staticpro (&Qintegerp
);
3199 staticpro (&Qnatnump
);
3200 staticpro (&Qwholenump
);
3201 staticpro (&Qstringp
);
3202 staticpro (&Qarrayp
);
3203 staticpro (&Qsequencep
);
3204 staticpro (&Qbufferp
);
3205 staticpro (&Qvectorp
);
3206 staticpro (&Qchar_or_string_p
);
3207 staticpro (&Qmarkerp
);
3208 staticpro (&Qbuffer_or_string_p
);
3209 staticpro (&Qinteger_or_marker_p
);
3210 staticpro (&Qfloatp
);
3211 staticpro (&Qnumberp
);
3212 staticpro (&Qnumber_or_marker_p
);
3213 staticpro (&Qchar_table_p
);
3214 staticpro (&Qvector_or_char_table_p
);
3215 staticpro (&Qsubrp
);
3217 staticpro (&Qunevalled
);
3219 staticpro (&Qboundp
);
3220 staticpro (&Qfboundp
);
3222 staticpro (&Qad_advice_info
);
3223 staticpro (&Qad_activate_internal
);
3225 /* Types that type-of returns. */
3226 Qinteger
= intern ("integer");
3227 Qsymbol
= intern ("symbol");
3228 Qstring
= intern ("string");
3229 Qcons
= intern ("cons");
3230 Qmarker
= intern ("marker");
3231 Qoverlay
= intern ("overlay");
3232 Qfloat
= intern ("float");
3233 Qwindow_configuration
= intern ("window-configuration");
3234 Qprocess
= intern ("process");
3235 Qwindow
= intern ("window");
3236 /* Qsubr = intern ("subr"); */
3237 Qcompiled_function
= intern ("compiled-function");
3238 Qbuffer
= intern ("buffer");
3239 Qframe
= intern ("frame");
3240 Qvector
= intern ("vector");
3241 Qchar_table
= intern ("char-table");
3242 Qbool_vector
= intern ("bool-vector");
3243 Qhash_table
= intern ("hash-table");
3245 staticpro (&Qinteger
);
3246 staticpro (&Qsymbol
);
3247 staticpro (&Qstring
);
3249 staticpro (&Qmarker
);
3250 staticpro (&Qoverlay
);
3251 staticpro (&Qfloat
);
3252 staticpro (&Qwindow_configuration
);
3253 staticpro (&Qprocess
);
3254 staticpro (&Qwindow
);
3255 /* staticpro (&Qsubr); */
3256 staticpro (&Qcompiled_function
);
3257 staticpro (&Qbuffer
);
3258 staticpro (&Qframe
);
3259 staticpro (&Qvector
);
3260 staticpro (&Qchar_table
);
3261 staticpro (&Qbool_vector
);
3262 staticpro (&Qhash_table
);
3264 defsubr (&Sindirect_variable
);
3265 defsubr (&Sinteractive_form
);
3268 defsubr (&Stype_of
);
3273 defsubr (&Sintegerp
);
3274 defsubr (&Sinteger_or_marker_p
);
3275 defsubr (&Snumberp
);
3276 defsubr (&Snumber_or_marker_p
);
3278 defsubr (&Snatnump
);
3279 defsubr (&Ssymbolp
);
3280 defsubr (&Skeywordp
);
3281 defsubr (&Sstringp
);
3282 defsubr (&Smultibyte_string_p
);
3283 defsubr (&Svectorp
);
3284 defsubr (&Schar_table_p
);
3285 defsubr (&Svector_or_char_table_p
);
3286 defsubr (&Sbool_vector_p
);
3288 defsubr (&Ssequencep
);
3289 defsubr (&Sbufferp
);
3290 defsubr (&Smarkerp
);
3292 defsubr (&Sbyte_code_function_p
);
3293 defsubr (&Schar_or_string_p
);
3296 defsubr (&Scar_safe
);
3297 defsubr (&Scdr_safe
);
3300 defsubr (&Ssymbol_function
);
3301 defsubr (&Sindirect_function
);
3302 defsubr (&Ssymbol_plist
);
3303 defsubr (&Ssymbol_name
);
3304 defsubr (&Smakunbound
);
3305 defsubr (&Sfmakunbound
);
3307 defsubr (&Sfboundp
);
3309 defsubr (&Sdefalias
);
3310 defsubr (&Ssetplist
);
3311 defsubr (&Ssymbol_value
);
3313 defsubr (&Sdefault_boundp
);
3314 defsubr (&Sdefault_value
);
3315 defsubr (&Sset_default
);
3316 defsubr (&Ssetq_default
);
3317 defsubr (&Smake_variable_buffer_local
);
3318 defsubr (&Smake_local_variable
);
3319 defsubr (&Skill_local_variable
);
3320 defsubr (&Smake_variable_frame_local
);
3321 defsubr (&Slocal_variable_p
);
3322 defsubr (&Slocal_variable_if_set_p
);
3323 defsubr (&Svariable_binding_locus
);
3326 defsubr (&Snumber_to_string
);
3327 defsubr (&Sstring_to_number
);
3328 defsubr (&Seqlsign
);
3351 defsubr (&Sbyteorder
);
3352 defsubr (&Ssubr_arity
);
3353 defsubr (&Ssubr_name
);
3355 XSYMBOL (Qwholenump
)->function
= XSYMBOL (Qnatnump
)->function
;
3357 DEFVAR_LISP ("most-positive-fixnum", &Vmost_positive_fixnum
,
3358 doc
: /* The largest value that is representable in a Lisp integer. */);
3359 Vmost_positive_fixnum
= make_number (MOST_POSITIVE_FIXNUM
);
3361 DEFVAR_LISP ("most-negative-fixnum", &Vmost_negative_fixnum
,
3362 doc
: /* The smallest value that is representable in a Lisp integer. */);
3363 Vmost_negative_fixnum
= make_number (MOST_NEGATIVE_FIXNUM
);
3370 #if defined(USG) && !defined(POSIX_SIGNALS)
3371 /* USG systems forget handlers when they are used;
3372 must reestablish each time */
3373 signal (signo
, arith_error
);
3376 /* VMS systems are like USG. */
3377 signal (signo
, arith_error
);
3381 #else /* not BSD4_1 */
3382 sigsetmask (SIGEMPTYMASK
);
3383 #endif /* not BSD4_1 */
3385 SIGNAL_THREAD_CHECK (signo
);
3386 xsignal0 (Qarith_error
);
3392 /* Don't do this if just dumping out.
3393 We don't want to call `signal' in this case
3394 so that we don't have trouble with dumping
3395 signal-delivering routines in an inconsistent state. */
3399 #endif /* CANNOT_DUMP */
3400 signal (SIGFPE
, arith_error
);
3403 signal (SIGEMT
, arith_error
);
3407 /* arch-tag: 25879798-b84d-479a-9c89-7d148e2109f7
3408 (do not change this comment) */