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 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 2, or (at your option)
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; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA. */
32 #include "syssignal.h"
38 /* If IEEE_FLOATING_POINT isn't defined, default it from FLT_*. */
39 #ifndef IEEE_FLOATING_POINT
40 #if (FLT_RADIX == 2 && FLT_MANT_DIG == 24 \
41 && FLT_MIN_EXP == -125 && FLT_MAX_EXP == 128)
42 #define IEEE_FLOATING_POINT 1
44 #define IEEE_FLOATING_POINT 0
48 /* Work around a problem that happens because math.h on hpux 7
49 defines two static variables--which, in Emacs, are not really static,
50 because `static' is defined as nothing. The problem is that they are
51 here, in floatfns.c, and in lread.c.
52 These macros prevent the name conflict. */
53 #if defined (HPUX) && !defined (HPUX8)
54 #define _MAXLDBL data_c_maxldbl
55 #define _NMAXLDBL data_c_nmaxldbl
61 extern double atof ();
64 Lisp_Object Qnil
, Qt
, Qquote
, Qlambda
, Qsubr
, Qunbound
;
65 Lisp_Object Qerror_conditions
, Qerror_message
, Qtop_level
;
66 Lisp_Object Qerror
, Qquit
, Qwrong_type_argument
, Qargs_out_of_range
;
67 Lisp_Object Qvoid_variable
, Qvoid_function
, Qcyclic_function_indirection
;
68 Lisp_Object Qcyclic_variable_indirection
, Qcircular_list
;
69 Lisp_Object Qsetting_constant
, Qinvalid_read_syntax
;
70 Lisp_Object Qinvalid_function
, Qwrong_number_of_arguments
, Qno_catch
;
71 Lisp_Object Qend_of_file
, Qarith_error
, Qmark_inactive
;
72 Lisp_Object Qbeginning_of_buffer
, Qend_of_buffer
, Qbuffer_read_only
;
73 Lisp_Object Qtext_read_only
;
75 Lisp_Object Qintegerp
, Qnatnump
, Qwholenump
, Qsymbolp
, Qlistp
, Qconsp
;
76 Lisp_Object Qstringp
, Qarrayp
, Qsequencep
, Qbufferp
;
77 Lisp_Object Qchar_or_string_p
, Qmarkerp
, Qinteger_or_marker_p
, Qvectorp
;
78 Lisp_Object Qbuffer_or_string_p
, Qkeywordp
;
79 Lisp_Object Qboundp
, Qfboundp
;
80 Lisp_Object Qchar_table_p
, Qvector_or_char_table_p
;
83 Lisp_Object Qad_advice_info
, Qad_activate_internal
;
85 Lisp_Object Qrange_error
, Qdomain_error
, Qsingularity_error
;
86 Lisp_Object Qoverflow_error
, Qunderflow_error
;
89 Lisp_Object Qnumberp
, Qnumber_or_marker_p
;
92 static Lisp_Object Qsymbol
, Qstring
, Qcons
, Qmarker
, Qoverlay
;
93 static Lisp_Object Qfloat
, Qwindow_configuration
, Qwindow
;
95 static Lisp_Object Qcompiled_function
, Qbuffer
, Qframe
, Qvector
;
96 static Lisp_Object Qchar_table
, Qbool_vector
, Qhash_table
;
97 static Lisp_Object Qsubrp
, Qmany
, Qunevalled
;
99 static Lisp_Object swap_in_symval_forwarding
P_ ((Lisp_Object
, Lisp_Object
));
101 Lisp_Object Vmost_positive_fixnum
, Vmost_negative_fixnum
;
105 circular_list_error (list
)
108 Fsignal (Qcircular_list
, list
);
113 wrong_type_argument (predicate
, value
)
114 register Lisp_Object predicate
, value
;
116 register Lisp_Object tem
;
119 /* If VALUE is not even a valid Lisp object, abort here
120 where we can get a backtrace showing where it came from. */
121 if ((unsigned int) XGCTYPE (value
) >= Lisp_Type_Limit
)
124 value
= Fsignal (Qwrong_type_argument
, Fcons (predicate
, Fcons (value
, Qnil
)));
125 tem
= call1 (predicate
, value
);
128 /* This function is marked as NO_RETURN, gcc would warn if it has a
129 return statement or if falls off the function. Other compilers
130 warn if no return statement is present. */
141 error ("Attempt to modify read-only object");
145 args_out_of_range (a1
, a2
)
149 Fsignal (Qargs_out_of_range
, Fcons (a1
, Fcons (a2
, Qnil
)));
153 args_out_of_range_3 (a1
, a2
, a3
)
154 Lisp_Object a1
, a2
, a3
;
157 Fsignal (Qargs_out_of_range
, Fcons (a1
, Fcons (a2
, Fcons (a3
, Qnil
))));
160 /* On some machines, XINT needs a temporary location.
161 Here it is, in case it is needed. */
163 int sign_extend_temp
;
165 /* On a few machines, XINT can only be done by calling this. */
168 sign_extend_lisp_int (num
)
171 if (num
& (((EMACS_INT
) 1) << (VALBITS
- 1)))
172 return num
| (((EMACS_INT
) (-1)) << VALBITS
);
174 return num
& ((((EMACS_INT
) 1) << VALBITS
) - 1);
177 /* Data type predicates */
179 DEFUN ("eq", Feq
, Seq
, 2, 2, 0,
180 doc
: /* Return t if the two args are the same Lisp object. */)
182 Lisp_Object obj1
, obj2
;
189 DEFUN ("null", Fnull
, Snull
, 1, 1, 0,
190 doc
: /* Return t if OBJECT is nil. */)
199 DEFUN ("type-of", Ftype_of
, Stype_of
, 1, 1, 0,
200 doc
: /* Return a symbol representing the type of OBJECT.
201 The symbol returned names the object's basic type;
202 for example, (type-of 1) returns `integer'. */)
206 switch (XGCTYPE (object
))
221 switch (XMISCTYPE (object
))
223 case Lisp_Misc_Marker
:
225 case Lisp_Misc_Overlay
:
227 case Lisp_Misc_Float
:
232 case Lisp_Vectorlike
:
233 if (GC_WINDOW_CONFIGURATIONP (object
))
234 return Qwindow_configuration
;
235 if (GC_PROCESSP (object
))
237 if (GC_WINDOWP (object
))
239 if (GC_SUBRP (object
))
241 if (GC_COMPILEDP (object
))
242 return Qcompiled_function
;
243 if (GC_BUFFERP (object
))
245 if (GC_CHAR_TABLE_P (object
))
247 if (GC_BOOL_VECTOR_P (object
))
249 if (GC_FRAMEP (object
))
251 if (GC_HASH_TABLE_P (object
))
263 DEFUN ("consp", Fconsp
, Sconsp
, 1, 1, 0,
264 doc
: /* Return t if OBJECT is a cons cell. */)
273 DEFUN ("atom", Fatom
, Satom
, 1, 1, 0,
274 doc
: /* Return t if OBJECT is not a cons cell. This includes nil. */)
283 DEFUN ("listp", Flistp
, Slistp
, 1, 1, 0,
284 doc
: /* Return t if OBJECT is a list, that is, a cons cell or nil.
285 Otherwise, return nil. */)
289 if (CONSP (object
) || NILP (object
))
294 DEFUN ("nlistp", Fnlistp
, Snlistp
, 1, 1, 0,
295 doc
: /* Return t if OBJECT is not a list. Lists include nil. */)
299 if (CONSP (object
) || NILP (object
))
304 DEFUN ("symbolp", Fsymbolp
, Ssymbolp
, 1, 1, 0,
305 doc
: /* Return t if OBJECT is a symbol. */)
309 if (SYMBOLP (object
))
314 /* Define this in C to avoid unnecessarily consing up the symbol
316 DEFUN ("keywordp", Fkeywordp
, Skeywordp
, 1, 1, 0,
317 doc
: /* Return t if OBJECT is a keyword.
318 This means that it is a symbol with a print name beginning with `:'
319 interned in the initial obarray. */)
324 && SREF (SYMBOL_NAME (object
), 0) == ':'
325 && SYMBOL_INTERNED_IN_INITIAL_OBARRAY_P (object
))
330 DEFUN ("vectorp", Fvectorp
, Svectorp
, 1, 1, 0,
331 doc
: /* Return t if OBJECT is a vector. */)
335 if (VECTORP (object
))
340 DEFUN ("stringp", Fstringp
, Sstringp
, 1, 1, 0,
341 doc
: /* Return t if OBJECT is a string. */)
345 if (STRINGP (object
))
350 DEFUN ("multibyte-string-p", Fmultibyte_string_p
, Smultibyte_string_p
,
352 doc
: /* Return t if OBJECT is a multibyte string. */)
356 if (STRINGP (object
) && STRING_MULTIBYTE (object
))
361 DEFUN ("char-table-p", Fchar_table_p
, Schar_table_p
, 1, 1, 0,
362 doc
: /* Return t if OBJECT is a char-table. */)
366 if (CHAR_TABLE_P (object
))
371 DEFUN ("vector-or-char-table-p", Fvector_or_char_table_p
,
372 Svector_or_char_table_p
, 1, 1, 0,
373 doc
: /* Return t if OBJECT is a char-table or vector. */)
377 if (VECTORP (object
) || CHAR_TABLE_P (object
))
382 DEFUN ("bool-vector-p", Fbool_vector_p
, Sbool_vector_p
, 1, 1, 0,
383 doc
: /* Return t if OBJECT is a bool-vector. */)
387 if (BOOL_VECTOR_P (object
))
392 DEFUN ("arrayp", Farrayp
, Sarrayp
, 1, 1, 0,
393 doc
: /* Return t if OBJECT is an array (string or vector). */)
397 if (VECTORP (object
) || STRINGP (object
)
398 || CHAR_TABLE_P (object
) || BOOL_VECTOR_P (object
))
403 DEFUN ("sequencep", Fsequencep
, Ssequencep
, 1, 1, 0,
404 doc
: /* Return t if OBJECT is a sequence (list or array). */)
406 register Lisp_Object object
;
408 if (CONSP (object
) || NILP (object
) || VECTORP (object
) || STRINGP (object
)
409 || CHAR_TABLE_P (object
) || BOOL_VECTOR_P (object
))
414 DEFUN ("bufferp", Fbufferp
, Sbufferp
, 1, 1, 0,
415 doc
: /* Return t if OBJECT is an editor buffer. */)
419 if (BUFFERP (object
))
424 DEFUN ("markerp", Fmarkerp
, Smarkerp
, 1, 1, 0,
425 doc
: /* Return t if OBJECT is a marker (editor pointer). */)
429 if (MARKERP (object
))
434 DEFUN ("subrp", Fsubrp
, Ssubrp
, 1, 1, 0,
435 doc
: /* Return t if OBJECT is a built-in function. */)
444 DEFUN ("byte-code-function-p", Fbyte_code_function_p
, Sbyte_code_function_p
,
446 doc
: /* Return t if OBJECT is a byte-compiled function object. */)
450 if (COMPILEDP (object
))
455 DEFUN ("char-or-string-p", Fchar_or_string_p
, Schar_or_string_p
, 1, 1, 0,
456 doc
: /* Return t if OBJECT is a character (an integer) or a string. */)
458 register Lisp_Object object
;
460 if (INTEGERP (object
) || STRINGP (object
))
465 DEFUN ("integerp", Fintegerp
, Sintegerp
, 1, 1, 0,
466 doc
: /* Return t if OBJECT is an integer. */)
470 if (INTEGERP (object
))
475 DEFUN ("integer-or-marker-p", Finteger_or_marker_p
, Sinteger_or_marker_p
, 1, 1, 0,
476 doc
: /* Return t if OBJECT is an integer or a marker (editor pointer). */)
478 register Lisp_Object object
;
480 if (MARKERP (object
) || INTEGERP (object
))
485 DEFUN ("natnump", Fnatnump
, Snatnump
, 1, 1, 0,
486 doc
: /* Return t if OBJECT is a nonnegative integer. */)
490 if (NATNUMP (object
))
495 DEFUN ("numberp", Fnumberp
, Snumberp
, 1, 1, 0,
496 doc
: /* Return t if OBJECT is a number (floating point or integer). */)
500 if (NUMBERP (object
))
506 DEFUN ("number-or-marker-p", Fnumber_or_marker_p
,
507 Snumber_or_marker_p
, 1, 1, 0,
508 doc
: /* Return t if OBJECT is a number or a marker. */)
512 if (NUMBERP (object
) || MARKERP (object
))
517 DEFUN ("floatp", Ffloatp
, Sfloatp
, 1, 1, 0,
518 doc
: /* Return t if OBJECT is a floating point number. */)
528 /* Extract and set components of lists */
530 DEFUN ("car", Fcar
, Scar
, 1, 1, 0,
531 doc
: /* Return the car of LIST. If arg is nil, return nil.
532 Error if arg is not nil and not a cons cell. See also `car-safe'.
534 See Info node `(elisp)Cons Cells' for a discussion of related basic
535 Lisp concepts such as car, cdr, cons cell and list. */)
537 register Lisp_Object list
;
543 else if (EQ (list
, Qnil
))
546 list
= wrong_type_argument (Qlistp
, list
);
550 DEFUN ("car-safe", Fcar_safe
, Scar_safe
, 1, 1, 0,
551 doc
: /* Return the car of OBJECT if it is a cons cell, or else nil. */)
556 return XCAR (object
);
561 DEFUN ("cdr", Fcdr
, Scdr
, 1, 1, 0,
562 doc
: /* Return the cdr of LIST. If arg is nil, return nil.
563 Error if arg is not nil and not a cons cell. See also `cdr-safe'.
565 See Info node `(elisp)Cons Cells' for a discussion of related basic
566 Lisp concepts such as cdr, car, cons cell and list. */)
568 register Lisp_Object list
;
574 else if (EQ (list
, Qnil
))
577 list
= wrong_type_argument (Qlistp
, list
);
581 DEFUN ("cdr-safe", Fcdr_safe
, Scdr_safe
, 1, 1, 0,
582 doc
: /* Return the cdr of OBJECT if it is a cons cell, or else nil. */)
587 return XCDR (object
);
592 DEFUN ("setcar", Fsetcar
, Ssetcar
, 2, 2, 0,
593 doc
: /* Set the car of CELL to be NEWCAR. Returns NEWCAR. */)
595 register Lisp_Object cell
, newcar
;
598 cell
= wrong_type_argument (Qconsp
, cell
);
601 XSETCAR (cell
, newcar
);
605 DEFUN ("setcdr", Fsetcdr
, Ssetcdr
, 2, 2, 0,
606 doc
: /* Set the cdr of CELL to be NEWCDR. Returns NEWCDR. */)
608 register Lisp_Object cell
, newcdr
;
611 cell
= wrong_type_argument (Qconsp
, cell
);
614 XSETCDR (cell
, newcdr
);
618 /* Extract and set components of symbols */
620 DEFUN ("boundp", Fboundp
, Sboundp
, 1, 1, 0,
621 doc
: /* Return t if SYMBOL's value is not void. */)
623 register Lisp_Object symbol
;
625 Lisp_Object valcontents
;
626 CHECK_SYMBOL (symbol
);
628 valcontents
= SYMBOL_VALUE (symbol
);
630 if (BUFFER_LOCAL_VALUEP (valcontents
)
631 || SOME_BUFFER_LOCAL_VALUEP (valcontents
))
632 valcontents
= swap_in_symval_forwarding (symbol
, valcontents
);
634 return (EQ (valcontents
, Qunbound
) ? Qnil
: Qt
);
637 DEFUN ("fboundp", Ffboundp
, Sfboundp
, 1, 1, 0,
638 doc
: /* Return t if SYMBOL's function definition is not void. */)
640 register Lisp_Object symbol
;
642 CHECK_SYMBOL (symbol
);
643 return (EQ (XSYMBOL (symbol
)->function
, Qunbound
) ? Qnil
: Qt
);
646 DEFUN ("makunbound", Fmakunbound
, Smakunbound
, 1, 1, 0,
647 doc
: /* Make SYMBOL's value be void.
650 register Lisp_Object symbol
;
652 CHECK_SYMBOL (symbol
);
653 if (XSYMBOL (symbol
)->constant
)
654 return Fsignal (Qsetting_constant
, Fcons (symbol
, Qnil
));
655 Fset (symbol
, Qunbound
);
659 DEFUN ("fmakunbound", Ffmakunbound
, Sfmakunbound
, 1, 1, 0,
660 doc
: /* Make SYMBOL's function definition be void.
663 register Lisp_Object symbol
;
665 CHECK_SYMBOL (symbol
);
666 if (NILP (symbol
) || EQ (symbol
, Qt
))
667 return Fsignal (Qsetting_constant
, Fcons (symbol
, Qnil
));
668 XSYMBOL (symbol
)->function
= Qunbound
;
672 DEFUN ("symbol-function", Fsymbol_function
, Ssymbol_function
, 1, 1, 0,
673 doc
: /* Return SYMBOL's function definition. Error if that is void. */)
675 register Lisp_Object symbol
;
677 CHECK_SYMBOL (symbol
);
678 if (EQ (XSYMBOL (symbol
)->function
, Qunbound
))
679 return Fsignal (Qvoid_function
, Fcons (symbol
, Qnil
));
680 return XSYMBOL (symbol
)->function
;
683 DEFUN ("symbol-plist", Fsymbol_plist
, Ssymbol_plist
, 1, 1, 0,
684 doc
: /* Return SYMBOL's property list. */)
686 register Lisp_Object symbol
;
688 CHECK_SYMBOL (symbol
);
689 return XSYMBOL (symbol
)->plist
;
692 DEFUN ("symbol-name", Fsymbol_name
, Ssymbol_name
, 1, 1, 0,
693 doc
: /* Return SYMBOL's name, a string. */)
695 register Lisp_Object symbol
;
697 register Lisp_Object name
;
699 CHECK_SYMBOL (symbol
);
700 name
= SYMBOL_NAME (symbol
);
704 DEFUN ("fset", Ffset
, Sfset
, 2, 2, 0,
705 doc
: /* Set SYMBOL's function definition to DEFINITION, and return DEFINITION. */)
707 register Lisp_Object symbol
, definition
;
709 CHECK_SYMBOL (symbol
);
710 if (NILP (symbol
) || EQ (symbol
, Qt
))
711 return Fsignal (Qsetting_constant
, Fcons (symbol
, Qnil
));
712 if (!NILP (Vautoload_queue
) && !EQ (XSYMBOL (symbol
)->function
, Qunbound
))
713 Vautoload_queue
= Fcons (Fcons (symbol
, XSYMBOL (symbol
)->function
),
715 XSYMBOL (symbol
)->function
= definition
;
716 /* Handle automatic advice activation */
717 if (CONSP (XSYMBOL (symbol
)->plist
) && !NILP (Fget (symbol
, Qad_advice_info
)))
719 call2 (Qad_activate_internal
, symbol
, Qnil
);
720 definition
= XSYMBOL (symbol
)->function
;
725 extern Lisp_Object Qfunction_documentation
;
727 DEFUN ("defalias", Fdefalias
, Sdefalias
, 2, 3, 0,
728 doc
: /* Set SYMBOL's function definition to DEFINITION, and return DEFINITION.
729 Associates the function with the current load file, if any.
730 The optional third argument DOCSTRING specifies the documentation string
731 for SYMBOL; if it is omitted or nil, SYMBOL uses the documentation string
732 determined by DEFINITION. */)
733 (symbol
, definition
, docstring
)
734 register Lisp_Object symbol
, definition
, docstring
;
736 CHECK_SYMBOL (symbol
);
737 if (CONSP (XSYMBOL (symbol
)->function
)
738 && EQ (XCAR (XSYMBOL (symbol
)->function
), Qautoload
))
739 LOADHIST_ATTACH (Fcons (Qt
, symbol
));
740 definition
= Ffset (symbol
, definition
);
741 LOADHIST_ATTACH (Fcons (Qdefun
, symbol
));
742 if (!NILP (docstring
))
743 Fput (symbol
, Qfunction_documentation
, docstring
);
747 DEFUN ("setplist", Fsetplist
, Ssetplist
, 2, 2, 0,
748 doc
: /* Set SYMBOL's property list to NEWPLIST, and return NEWPLIST. */)
750 register Lisp_Object symbol
, newplist
;
752 CHECK_SYMBOL (symbol
);
753 XSYMBOL (symbol
)->plist
= newplist
;
757 DEFUN ("subr-arity", Fsubr_arity
, Ssubr_arity
, 1, 1, 0,
758 doc
: /* Return minimum and maximum number of args allowed for SUBR.
759 SUBR must be a built-in function.
760 The returned value is a pair (MIN . MAX). MIN is the minimum number
761 of args. MAX is the maximum number or the symbol `many', for a
762 function with `&rest' args, or `unevalled' for a special form. */)
766 short minargs
, maxargs
;
768 wrong_type_argument (Qsubrp
, subr
);
769 minargs
= XSUBR (subr
)->min_args
;
770 maxargs
= XSUBR (subr
)->max_args
;
772 return Fcons (make_number (minargs
), Qmany
);
773 else if (maxargs
== UNEVALLED
)
774 return Fcons (make_number (minargs
), Qunevalled
);
776 return Fcons (make_number (minargs
), make_number (maxargs
));
779 DEFUN ("subr-name", Fsubr_name
, Ssubr_name
, 1, 1, 0,
780 doc
: /* Return name of subroutine SUBR.
781 SUBR must be a built-in function. */)
787 wrong_type_argument (Qsubrp
, subr
);
788 name
= XSUBR (subr
)->symbol_name
;
789 return make_string (name
, strlen (name
));
792 DEFUN ("interactive-form", Finteractive_form
, Sinteractive_form
, 1, 1, 0,
793 doc
: /* Return the interactive form of CMD or nil if none.
794 If CMD is not a command, the return value is nil.
795 Value, if non-nil, is a list \(interactive SPEC). */)
799 Lisp_Object fun
= indirect_function (cmd
);
803 if (XSUBR (fun
)->prompt
)
804 return list2 (Qinteractive
, build_string (XSUBR (fun
)->prompt
));
806 else if (COMPILEDP (fun
))
808 if ((ASIZE (fun
) & PSEUDOVECTOR_SIZE_MASK
) > COMPILED_INTERACTIVE
)
809 return list2 (Qinteractive
, AREF (fun
, COMPILED_INTERACTIVE
));
811 else if (CONSP (fun
))
813 Lisp_Object funcar
= XCAR (fun
);
814 if (EQ (funcar
, Qlambda
))
815 return Fassq (Qinteractive
, Fcdr (XCDR (fun
)));
816 else if (EQ (funcar
, Qautoload
))
820 do_autoload (fun
, cmd
);
822 return Finteractive_form (cmd
);
829 /***********************************************************************
830 Getting and Setting Values of Symbols
831 ***********************************************************************/
833 /* Return the symbol holding SYMBOL's value. Signal
834 `cyclic-variable-indirection' if SYMBOL's chain of variable
835 indirections contains a loop. */
838 indirect_variable (symbol
)
841 Lisp_Object tortoise
, hare
;
843 hare
= tortoise
= symbol
;
845 while (XSYMBOL (hare
)->indirect_variable
)
847 hare
= XSYMBOL (hare
)->value
;
848 if (!XSYMBOL (hare
)->indirect_variable
)
851 hare
= XSYMBOL (hare
)->value
;
852 tortoise
= XSYMBOL (tortoise
)->value
;
854 if (EQ (hare
, tortoise
))
855 Fsignal (Qcyclic_variable_indirection
, Fcons (symbol
, Qnil
));
862 DEFUN ("indirect-variable", Findirect_variable
, Sindirect_variable
, 1, 1, 0,
863 doc
: /* Return the variable at the end of OBJECT's variable chain.
864 If OBJECT is a symbol, follow all variable indirections and return the final
865 variable. If OBJECT is not a symbol, just return it.
866 Signal a cyclic-variable-indirection error if there is a loop in the
867 variable chain of symbols. */)
871 if (SYMBOLP (object
))
872 object
= indirect_variable (object
);
877 /* Given the raw contents of a symbol value cell,
878 return the Lisp value of the symbol.
879 This does not handle buffer-local variables; use
880 swap_in_symval_forwarding for that. */
883 do_symval_forwarding (valcontents
)
884 register Lisp_Object valcontents
;
886 register Lisp_Object val
;
888 if (MISCP (valcontents
))
889 switch (XMISCTYPE (valcontents
))
891 case Lisp_Misc_Intfwd
:
892 XSETINT (val
, *XINTFWD (valcontents
)->intvar
);
895 case Lisp_Misc_Boolfwd
:
896 return (*XBOOLFWD (valcontents
)->boolvar
? Qt
: Qnil
);
898 case Lisp_Misc_Objfwd
:
899 return *XOBJFWD (valcontents
)->objvar
;
901 case Lisp_Misc_Buffer_Objfwd
:
902 offset
= XBUFFER_OBJFWD (valcontents
)->offset
;
903 return PER_BUFFER_VALUE (current_buffer
, offset
);
905 case Lisp_Misc_Kboard_Objfwd
:
906 offset
= XKBOARD_OBJFWD (valcontents
)->offset
;
907 return *(Lisp_Object
*)(offset
+ (char *)current_kboard
);
912 /* Store NEWVAL into SYMBOL, where VALCONTENTS is found in the value cell
913 of SYMBOL. If SYMBOL is buffer-local, VALCONTENTS should be the
914 buffer-independent contents of the value cell: forwarded just one
915 step past the buffer-localness.
917 BUF non-zero means set the value in buffer BUF instead of the
918 current buffer. This only plays a role for per-buffer variables. */
921 store_symval_forwarding (symbol
, valcontents
, newval
, buf
)
923 register Lisp_Object valcontents
, newval
;
926 switch (SWITCH_ENUM_CAST (XTYPE (valcontents
)))
929 switch (XMISCTYPE (valcontents
))
931 case Lisp_Misc_Intfwd
:
932 CHECK_NUMBER (newval
);
933 *XINTFWD (valcontents
)->intvar
= XINT (newval
);
934 if (*XINTFWD (valcontents
)->intvar
!= XINT (newval
))
935 error ("Value out of range for variable `%s'",
936 SDATA (SYMBOL_NAME (symbol
)));
939 case Lisp_Misc_Boolfwd
:
940 *XBOOLFWD (valcontents
)->boolvar
= NILP (newval
) ? 0 : 1;
943 case Lisp_Misc_Objfwd
:
944 *XOBJFWD (valcontents
)->objvar
= newval
;
946 /* If this variable is a default for something stored
947 in the buffer itself, such as default-fill-column,
948 find the buffers that don't have local values for it
950 if (XOBJFWD (valcontents
)->objvar
> (Lisp_Object
*) &buffer_defaults
951 && XOBJFWD (valcontents
)->objvar
< (Lisp_Object
*) (&buffer_defaults
+ 1))
953 int offset
= ((char *) XOBJFWD (valcontents
)->objvar
954 - (char *) &buffer_defaults
);
955 int idx
= PER_BUFFER_IDX (offset
);
962 for (tail
= Vbuffer_alist
; CONSP (tail
); tail
= XCDR (tail
))
967 buf
= Fcdr (XCAR (tail
));
968 if (!BUFFERP (buf
)) continue;
971 if (! PER_BUFFER_VALUE_P (b
, idx
))
972 PER_BUFFER_VALUE (b
, offset
) = newval
;
977 case Lisp_Misc_Buffer_Objfwd
:
979 int offset
= XBUFFER_OBJFWD (valcontents
)->offset
;
982 type
= PER_BUFFER_TYPE (offset
);
983 if (! NILP (type
) && ! NILP (newval
)
984 && XTYPE (newval
) != XINT (type
))
985 buffer_slot_type_mismatch (offset
);
988 buf
= current_buffer
;
989 PER_BUFFER_VALUE (buf
, offset
) = newval
;
993 case Lisp_Misc_Kboard_Objfwd
:
995 char *base
= (char *) current_kboard
;
996 char *p
= base
+ XKBOARD_OBJFWD (valcontents
)->offset
;
997 *(Lisp_Object
*) p
= newval
;
1008 valcontents
= SYMBOL_VALUE (symbol
);
1009 if (BUFFER_LOCAL_VALUEP (valcontents
)
1010 || SOME_BUFFER_LOCAL_VALUEP (valcontents
))
1011 XBUFFER_LOCAL_VALUE (valcontents
)->realvalue
= newval
;
1013 SET_SYMBOL_VALUE (symbol
, newval
);
1017 /* Set up SYMBOL to refer to its global binding.
1018 This makes it safe to alter the status of other bindings. */
1021 swap_in_global_binding (symbol
)
1024 Lisp_Object valcontents
, cdr
;
1026 valcontents
= SYMBOL_VALUE (symbol
);
1027 if (!BUFFER_LOCAL_VALUEP (valcontents
)
1028 && !SOME_BUFFER_LOCAL_VALUEP (valcontents
))
1030 cdr
= XBUFFER_LOCAL_VALUE (valcontents
)->cdr
;
1032 /* Unload the previously loaded binding. */
1033 Fsetcdr (XCAR (cdr
),
1034 do_symval_forwarding (XBUFFER_LOCAL_VALUE (valcontents
)->realvalue
));
1036 /* Select the global binding in the symbol. */
1038 store_symval_forwarding (symbol
, valcontents
, XCDR (cdr
), NULL
);
1040 /* Indicate that the global binding is set up now. */
1041 XBUFFER_LOCAL_VALUE (valcontents
)->frame
= Qnil
;
1042 XBUFFER_LOCAL_VALUE (valcontents
)->buffer
= Qnil
;
1043 XBUFFER_LOCAL_VALUE (valcontents
)->found_for_frame
= 0;
1044 XBUFFER_LOCAL_VALUE (valcontents
)->found_for_buffer
= 0;
1047 /* Set up the buffer-local symbol SYMBOL for validity in the current buffer.
1048 VALCONTENTS is the contents of its value cell,
1049 which points to a struct Lisp_Buffer_Local_Value.
1051 Return the value forwarded one step past the buffer-local stage.
1052 This could be another forwarding pointer. */
1055 swap_in_symval_forwarding (symbol
, valcontents
)
1056 Lisp_Object symbol
, valcontents
;
1058 register Lisp_Object tem1
;
1060 tem1
= XBUFFER_LOCAL_VALUE (valcontents
)->buffer
;
1063 || current_buffer
!= XBUFFER (tem1
)
1064 || (XBUFFER_LOCAL_VALUE (valcontents
)->check_frame
1065 && ! EQ (selected_frame
, XBUFFER_LOCAL_VALUE (valcontents
)->frame
)))
1067 if (XSYMBOL (symbol
)->indirect_variable
)
1068 symbol
= indirect_variable (symbol
);
1070 /* Unload the previously loaded binding. */
1071 tem1
= XCAR (XBUFFER_LOCAL_VALUE (valcontents
)->cdr
);
1073 do_symval_forwarding (XBUFFER_LOCAL_VALUE (valcontents
)->realvalue
));
1074 /* Choose the new binding. */
1075 tem1
= assq_no_quit (symbol
, current_buffer
->local_var_alist
);
1076 XBUFFER_LOCAL_VALUE (valcontents
)->found_for_frame
= 0;
1077 XBUFFER_LOCAL_VALUE (valcontents
)->found_for_buffer
= 0;
1080 if (XBUFFER_LOCAL_VALUE (valcontents
)->check_frame
)
1081 tem1
= assq_no_quit (symbol
, XFRAME (selected_frame
)->param_alist
);
1083 XBUFFER_LOCAL_VALUE (valcontents
)->found_for_frame
= 1;
1085 tem1
= XBUFFER_LOCAL_VALUE (valcontents
)->cdr
;
1088 XBUFFER_LOCAL_VALUE (valcontents
)->found_for_buffer
= 1;
1090 /* Load the new binding. */
1091 XSETCAR (XBUFFER_LOCAL_VALUE (valcontents
)->cdr
, tem1
);
1092 XSETBUFFER (XBUFFER_LOCAL_VALUE (valcontents
)->buffer
, current_buffer
);
1093 XBUFFER_LOCAL_VALUE (valcontents
)->frame
= selected_frame
;
1094 store_symval_forwarding (symbol
,
1095 XBUFFER_LOCAL_VALUE (valcontents
)->realvalue
,
1098 return XBUFFER_LOCAL_VALUE (valcontents
)->realvalue
;
1101 /* Find the value of a symbol, returning Qunbound if it's not bound.
1102 This is helpful for code which just wants to get a variable's value
1103 if it has one, without signaling an error.
1104 Note that it must not be possible to quit
1105 within this function. Great care is required for this. */
1108 find_symbol_value (symbol
)
1111 register Lisp_Object valcontents
;
1112 register Lisp_Object val
;
1114 CHECK_SYMBOL (symbol
);
1115 valcontents
= SYMBOL_VALUE (symbol
);
1117 if (BUFFER_LOCAL_VALUEP (valcontents
)
1118 || SOME_BUFFER_LOCAL_VALUEP (valcontents
))
1119 valcontents
= swap_in_symval_forwarding (symbol
, valcontents
);
1121 if (MISCP (valcontents
))
1123 switch (XMISCTYPE (valcontents
))
1125 case Lisp_Misc_Intfwd
:
1126 XSETINT (val
, *XINTFWD (valcontents
)->intvar
);
1129 case Lisp_Misc_Boolfwd
:
1130 return (*XBOOLFWD (valcontents
)->boolvar
? Qt
: Qnil
);
1132 case Lisp_Misc_Objfwd
:
1133 return *XOBJFWD (valcontents
)->objvar
;
1135 case Lisp_Misc_Buffer_Objfwd
:
1136 return PER_BUFFER_VALUE (current_buffer
,
1137 XBUFFER_OBJFWD (valcontents
)->offset
);
1139 case Lisp_Misc_Kboard_Objfwd
:
1140 return *(Lisp_Object
*)(XKBOARD_OBJFWD (valcontents
)->offset
1141 + (char *)current_kboard
);
1148 DEFUN ("symbol-value", Fsymbol_value
, Ssymbol_value
, 1, 1, 0,
1149 doc
: /* Return SYMBOL's value. Error if that is void. */)
1155 val
= find_symbol_value (symbol
);
1156 if (EQ (val
, Qunbound
))
1157 return Fsignal (Qvoid_variable
, Fcons (symbol
, Qnil
));
1162 DEFUN ("set", Fset
, Sset
, 2, 2, 0,
1163 doc
: /* Set SYMBOL's value to NEWVAL, and return NEWVAL. */)
1165 register Lisp_Object symbol
, newval
;
1167 return set_internal (symbol
, newval
, current_buffer
, 0);
1170 /* Return 1 if SYMBOL currently has a let-binding
1171 which was made in the buffer that is now current. */
1174 let_shadows_buffer_binding_p (symbol
)
1177 volatile struct specbinding
*p
;
1179 for (p
= specpdl_ptr
- 1; p
>= specpdl
; p
--)
1181 && CONSP (p
->symbol
))
1183 Lisp_Object let_bound_symbol
= XCAR (p
->symbol
);
1184 if ((EQ (symbol
, let_bound_symbol
)
1185 || (XSYMBOL (let_bound_symbol
)->indirect_variable
1186 && EQ (symbol
, indirect_variable (let_bound_symbol
))))
1187 && XBUFFER (XCDR (XCDR (p
->symbol
))) == current_buffer
)
1191 return p
>= specpdl
;
1194 /* Store the value NEWVAL into SYMBOL.
1195 If buffer-locality is an issue, BUF specifies which buffer to use.
1196 (0 stands for the current buffer.)
1198 If BINDFLAG is zero, then if this symbol is supposed to become
1199 local in every buffer where it is set, then we make it local.
1200 If BINDFLAG is nonzero, we don't do that. */
1203 set_internal (symbol
, newval
, buf
, bindflag
)
1204 register Lisp_Object symbol
, newval
;
1208 int voide
= EQ (newval
, Qunbound
);
1210 register Lisp_Object valcontents
, innercontents
, tem1
, current_alist_element
;
1213 buf
= current_buffer
;
1215 /* If restoring in a dead buffer, do nothing. */
1216 if (NILP (buf
->name
))
1219 CHECK_SYMBOL (symbol
);
1220 if (SYMBOL_CONSTANT_P (symbol
)
1221 && (NILP (Fkeywordp (symbol
))
1222 || !EQ (newval
, SYMBOL_VALUE (symbol
))))
1223 return Fsignal (Qsetting_constant
, Fcons (symbol
, Qnil
));
1225 innercontents
= valcontents
= SYMBOL_VALUE (symbol
);
1227 if (BUFFER_OBJFWDP (valcontents
))
1229 int offset
= XBUFFER_OBJFWD (valcontents
)->offset
;
1230 int idx
= PER_BUFFER_IDX (offset
);
1233 && !let_shadows_buffer_binding_p (symbol
))
1234 SET_PER_BUFFER_VALUE_P (buf
, idx
, 1);
1236 else if (BUFFER_LOCAL_VALUEP (valcontents
)
1237 || SOME_BUFFER_LOCAL_VALUEP (valcontents
))
1239 /* valcontents is a struct Lisp_Buffer_Local_Value. */
1240 if (XSYMBOL (symbol
)->indirect_variable
)
1241 symbol
= indirect_variable (symbol
);
1243 /* What binding is loaded right now? */
1244 current_alist_element
1245 = XCAR (XBUFFER_LOCAL_VALUE (valcontents
)->cdr
);
1247 /* If the current buffer is not the buffer whose binding is
1248 loaded, or if there may be frame-local bindings and the frame
1249 isn't the right one, or if it's a Lisp_Buffer_Local_Value and
1250 the default binding is loaded, the loaded binding may be the
1252 if (!BUFFERP (XBUFFER_LOCAL_VALUE (valcontents
)->buffer
)
1253 || buf
!= XBUFFER (XBUFFER_LOCAL_VALUE (valcontents
)->buffer
)
1254 || (XBUFFER_LOCAL_VALUE (valcontents
)->check_frame
1255 && !EQ (selected_frame
, XBUFFER_LOCAL_VALUE (valcontents
)->frame
))
1256 || (BUFFER_LOCAL_VALUEP (valcontents
)
1257 && EQ (XCAR (current_alist_element
),
1258 current_alist_element
)))
1260 /* The currently loaded binding is not necessarily valid.
1261 We need to unload it, and choose a new binding. */
1263 /* Write out `realvalue' to the old loaded binding. */
1264 Fsetcdr (current_alist_element
,
1265 do_symval_forwarding (XBUFFER_LOCAL_VALUE (valcontents
)->realvalue
));
1267 /* Find the new binding. */
1268 tem1
= Fassq (symbol
, buf
->local_var_alist
);
1269 XBUFFER_LOCAL_VALUE (valcontents
)->found_for_buffer
= 1;
1270 XBUFFER_LOCAL_VALUE (valcontents
)->found_for_frame
= 0;
1274 /* This buffer still sees the default value. */
1276 /* If the variable is a Lisp_Some_Buffer_Local_Value,
1277 or if this is `let' rather than `set',
1278 make CURRENT-ALIST-ELEMENT point to itself,
1279 indicating that we're seeing the default value.
1280 Likewise if the variable has been let-bound
1281 in the current buffer. */
1282 if (bindflag
|| SOME_BUFFER_LOCAL_VALUEP (valcontents
)
1283 || let_shadows_buffer_binding_p (symbol
))
1285 XBUFFER_LOCAL_VALUE (valcontents
)->found_for_buffer
= 0;
1287 if (XBUFFER_LOCAL_VALUE (valcontents
)->check_frame
)
1288 tem1
= Fassq (symbol
,
1289 XFRAME (selected_frame
)->param_alist
);
1292 XBUFFER_LOCAL_VALUE (valcontents
)->found_for_frame
= 1;
1294 tem1
= XBUFFER_LOCAL_VALUE (valcontents
)->cdr
;
1296 /* If it's a Lisp_Buffer_Local_Value, being set not bound,
1297 and we're not within a let that was made for this buffer,
1298 create a new buffer-local binding for the variable.
1299 That means, give this buffer a new assoc for a local value
1300 and load that binding. */
1303 tem1
= Fcons (symbol
, XCDR (current_alist_element
));
1304 buf
->local_var_alist
1305 = Fcons (tem1
, buf
->local_var_alist
);
1309 /* Record which binding is now loaded. */
1310 XSETCAR (XBUFFER_LOCAL_VALUE (valcontents
)->cdr
,
1313 /* Set `buffer' and `frame' slots for thebinding now loaded. */
1314 XSETBUFFER (XBUFFER_LOCAL_VALUE (valcontents
)->buffer
, buf
);
1315 XBUFFER_LOCAL_VALUE (valcontents
)->frame
= selected_frame
;
1317 innercontents
= XBUFFER_LOCAL_VALUE (valcontents
)->realvalue
;
1320 /* If storing void (making the symbol void), forward only through
1321 buffer-local indicator, not through Lisp_Objfwd, etc. */
1323 store_symval_forwarding (symbol
, Qnil
, newval
, buf
);
1325 store_symval_forwarding (symbol
, innercontents
, newval
, buf
);
1327 /* If we just set a variable whose current binding is frame-local,
1328 store the new value in the frame parameter too. */
1330 if (BUFFER_LOCAL_VALUEP (valcontents
)
1331 || SOME_BUFFER_LOCAL_VALUEP (valcontents
))
1333 /* What binding is loaded right now? */
1334 current_alist_element
1335 = XCAR (XBUFFER_LOCAL_VALUE (valcontents
)->cdr
);
1337 /* If the current buffer is not the buffer whose binding is
1338 loaded, or if there may be frame-local bindings and the frame
1339 isn't the right one, or if it's a Lisp_Buffer_Local_Value and
1340 the default binding is loaded, the loaded binding may be the
1342 if (XBUFFER_LOCAL_VALUE (valcontents
)->found_for_frame
)
1343 XSETCDR (current_alist_element
, newval
);
1349 /* Access or set a buffer-local symbol's default value. */
1351 /* Return the default value of SYMBOL, but don't check for voidness.
1352 Return Qunbound if it is void. */
1355 default_value (symbol
)
1358 register Lisp_Object valcontents
;
1360 CHECK_SYMBOL (symbol
);
1361 valcontents
= SYMBOL_VALUE (symbol
);
1363 /* For a built-in buffer-local variable, get the default value
1364 rather than letting do_symval_forwarding get the current value. */
1365 if (BUFFER_OBJFWDP (valcontents
))
1367 int offset
= XBUFFER_OBJFWD (valcontents
)->offset
;
1368 if (PER_BUFFER_IDX (offset
) != 0)
1369 return PER_BUFFER_DEFAULT (offset
);
1372 /* Handle user-created local variables. */
1373 if (BUFFER_LOCAL_VALUEP (valcontents
)
1374 || SOME_BUFFER_LOCAL_VALUEP (valcontents
))
1376 /* If var is set up for a buffer that lacks a local value for it,
1377 the current value is nominally the default value.
1378 But the `realvalue' slot may be more up to date, since
1379 ordinary setq stores just that slot. So use that. */
1380 Lisp_Object current_alist_element
, alist_element_car
;
1381 current_alist_element
1382 = XCAR (XBUFFER_LOCAL_VALUE (valcontents
)->cdr
);
1383 alist_element_car
= XCAR (current_alist_element
);
1384 if (EQ (alist_element_car
, current_alist_element
))
1385 return do_symval_forwarding (XBUFFER_LOCAL_VALUE (valcontents
)->realvalue
);
1387 return XCDR (XBUFFER_LOCAL_VALUE (valcontents
)->cdr
);
1389 /* For other variables, get the current value. */
1390 return do_symval_forwarding (valcontents
);
1393 DEFUN ("default-boundp", Fdefault_boundp
, Sdefault_boundp
, 1, 1, 0,
1394 doc
: /* Return t if SYMBOL has a non-void default value.
1395 This is the value that is seen in buffers that do not have their own values
1396 for this variable. */)
1400 register Lisp_Object value
;
1402 value
= default_value (symbol
);
1403 return (EQ (value
, Qunbound
) ? Qnil
: Qt
);
1406 DEFUN ("default-value", Fdefault_value
, Sdefault_value
, 1, 1, 0,
1407 doc
: /* Return SYMBOL's default value.
1408 This is the value that is seen in buffers that do not have their own values
1409 for this variable. The default value is meaningful for variables with
1410 local bindings in certain buffers. */)
1414 register Lisp_Object value
;
1416 value
= default_value (symbol
);
1417 if (EQ (value
, Qunbound
))
1418 return Fsignal (Qvoid_variable
, Fcons (symbol
, Qnil
));
1422 DEFUN ("set-default", Fset_default
, Sset_default
, 2, 2, 0,
1423 doc
: /* Set SYMBOL's default value to VALUE. SYMBOL and VALUE are evaluated.
1424 The default value is seen in buffers that do not have their own values
1425 for this variable. */)
1427 Lisp_Object symbol
, value
;
1429 register Lisp_Object valcontents
, current_alist_element
, alist_element_buffer
;
1431 CHECK_SYMBOL (symbol
);
1432 valcontents
= SYMBOL_VALUE (symbol
);
1434 /* Handle variables like case-fold-search that have special slots
1435 in the buffer. Make them work apparently like Lisp_Buffer_Local_Value
1437 if (BUFFER_OBJFWDP (valcontents
))
1439 int offset
= XBUFFER_OBJFWD (valcontents
)->offset
;
1440 int idx
= PER_BUFFER_IDX (offset
);
1442 PER_BUFFER_DEFAULT (offset
) = value
;
1444 /* If this variable is not always local in all buffers,
1445 set it in the buffers that don't nominally have a local value. */
1450 for (b
= all_buffers
; b
; b
= b
->next
)
1451 if (!PER_BUFFER_VALUE_P (b
, idx
))
1452 PER_BUFFER_VALUE (b
, offset
) = value
;
1457 if (!BUFFER_LOCAL_VALUEP (valcontents
)
1458 && !SOME_BUFFER_LOCAL_VALUEP (valcontents
))
1459 return Fset (symbol
, value
);
1461 /* Store new value into the DEFAULT-VALUE slot. */
1462 XSETCDR (XBUFFER_LOCAL_VALUE (valcontents
)->cdr
, value
);
1464 /* If the default binding is now loaded, set the REALVALUE slot too. */
1465 current_alist_element
1466 = XCAR (XBUFFER_LOCAL_VALUE (valcontents
)->cdr
);
1467 alist_element_buffer
= Fcar (current_alist_element
);
1468 if (EQ (alist_element_buffer
, current_alist_element
))
1469 store_symval_forwarding (symbol
,
1470 XBUFFER_LOCAL_VALUE (valcontents
)->realvalue
,
1476 DEFUN ("setq-default", Fsetq_default
, Ssetq_default
, 0, UNEVALLED
, 0,
1477 doc
: /* Set the default value of variable VAR to VALUE.
1478 VAR, the variable name, is literal (not evaluated);
1479 VALUE is an expression: it is evaluated and its value returned.
1480 The default value of a variable is seen in buffers
1481 that do not have their own values for the variable.
1483 More generally, you can use multiple variables and values, as in
1484 (setq-default VAR VALUE VAR VALUE...)
1485 This sets each VAR's default value to the corresponding VALUE.
1486 The VALUE for the Nth VAR can refer to the new default values
1488 usage: (setq-default [VAR VALUE...]) */)
1492 register Lisp_Object args_left
;
1493 register Lisp_Object val
, symbol
;
1494 struct gcpro gcpro1
;
1504 val
= Feval (Fcar (Fcdr (args_left
)));
1505 symbol
= XCAR (args_left
);
1506 Fset_default (symbol
, val
);
1507 args_left
= Fcdr (XCDR (args_left
));
1509 while (!NILP (args_left
));
1515 /* Lisp functions for creating and removing buffer-local variables. */
1517 DEFUN ("make-variable-buffer-local", Fmake_variable_buffer_local
, Smake_variable_buffer_local
,
1518 1, 1, "vMake Variable Buffer Local: ",
1519 doc
: /* Make VARIABLE become buffer-local whenever it is set.
1520 At any time, the value for the current buffer is in effect,
1521 unless the variable has never been set in this buffer,
1522 in which case the default value is in effect.
1523 Note that binding the variable with `let', or setting it while
1524 a `let'-style binding made in this buffer is in effect,
1525 does not make the variable buffer-local. Return VARIABLE.
1527 In most cases it is better to use `make-local-variable',
1528 which makes a variable local in just one buffer.
1530 The function `default-value' gets the default value and `set-default' sets it. */)
1532 register Lisp_Object variable
;
1534 register Lisp_Object tem
, valcontents
, newval
;
1536 CHECK_SYMBOL (variable
);
1537 variable
= indirect_variable (variable
);
1539 valcontents
= SYMBOL_VALUE (variable
);
1540 if (EQ (variable
, Qnil
) || EQ (variable
, Qt
) || KBOARD_OBJFWDP (valcontents
))
1541 error ("Symbol %s may not be buffer-local", SDATA (SYMBOL_NAME (variable
)));
1543 if (BUFFER_LOCAL_VALUEP (valcontents
) || BUFFER_OBJFWDP (valcontents
))
1545 if (SOME_BUFFER_LOCAL_VALUEP (valcontents
))
1547 XMISCTYPE (SYMBOL_VALUE (variable
)) = Lisp_Misc_Buffer_Local_Value
;
1550 if (EQ (valcontents
, Qunbound
))
1551 SET_SYMBOL_VALUE (variable
, Qnil
);
1552 tem
= Fcons (Qnil
, Fsymbol_value (variable
));
1554 newval
= allocate_misc ();
1555 XMISCTYPE (newval
) = Lisp_Misc_Buffer_Local_Value
;
1556 XBUFFER_LOCAL_VALUE (newval
)->realvalue
= SYMBOL_VALUE (variable
);
1557 XBUFFER_LOCAL_VALUE (newval
)->buffer
= Fcurrent_buffer ();
1558 XBUFFER_LOCAL_VALUE (newval
)->frame
= Qnil
;
1559 XBUFFER_LOCAL_VALUE (newval
)->found_for_buffer
= 0;
1560 XBUFFER_LOCAL_VALUE (newval
)->found_for_frame
= 0;
1561 XBUFFER_LOCAL_VALUE (newval
)->check_frame
= 0;
1562 XBUFFER_LOCAL_VALUE (newval
)->cdr
= tem
;
1563 SET_SYMBOL_VALUE (variable
, newval
);
1567 DEFUN ("make-local-variable", Fmake_local_variable
, Smake_local_variable
,
1568 1, 1, "vMake Local Variable: ",
1569 doc
: /* Make VARIABLE have a separate value in the current buffer.
1570 Other buffers will continue to share a common default value.
1571 \(The buffer-local value of VARIABLE starts out as the same value
1572 VARIABLE previously had. If VARIABLE was void, it remains void.\)
1575 If the variable is already arranged to become local when set,
1576 this function causes a local value to exist for this buffer,
1577 just as setting the variable would do.
1579 This function returns VARIABLE, and therefore
1580 (set (make-local-variable 'VARIABLE) VALUE-EXP)
1583 See also `make-variable-buffer-local'.
1585 Do not use `make-local-variable' to make a hook variable buffer-local.
1586 Instead, use `add-hook' and specify t for the LOCAL argument. */)
1588 register Lisp_Object variable
;
1590 register Lisp_Object tem
, valcontents
;
1592 CHECK_SYMBOL (variable
);
1593 variable
= indirect_variable (variable
);
1595 valcontents
= SYMBOL_VALUE (variable
);
1596 if (EQ (variable
, Qnil
) || EQ (variable
, Qt
) || KBOARD_OBJFWDP (valcontents
))
1597 error ("Symbol %s may not be buffer-local", SDATA (SYMBOL_NAME (variable
)));
1599 if (BUFFER_LOCAL_VALUEP (valcontents
) || BUFFER_OBJFWDP (valcontents
))
1601 tem
= Fboundp (variable
);
1603 /* Make sure the symbol has a local value in this particular buffer,
1604 by setting it to the same value it already has. */
1605 Fset (variable
, (EQ (tem
, Qt
) ? Fsymbol_value (variable
) : Qunbound
));
1608 /* Make sure symbol is set up to hold per-buffer values. */
1609 if (!SOME_BUFFER_LOCAL_VALUEP (valcontents
))
1612 tem
= Fcons (Qnil
, do_symval_forwarding (valcontents
));
1614 newval
= allocate_misc ();
1615 XMISCTYPE (newval
) = Lisp_Misc_Some_Buffer_Local_Value
;
1616 XBUFFER_LOCAL_VALUE (newval
)->realvalue
= SYMBOL_VALUE (variable
);
1617 XBUFFER_LOCAL_VALUE (newval
)->buffer
= Qnil
;
1618 XBUFFER_LOCAL_VALUE (newval
)->frame
= Qnil
;
1619 XBUFFER_LOCAL_VALUE (newval
)->found_for_buffer
= 0;
1620 XBUFFER_LOCAL_VALUE (newval
)->found_for_frame
= 0;
1621 XBUFFER_LOCAL_VALUE (newval
)->check_frame
= 0;
1622 XBUFFER_LOCAL_VALUE (newval
)->cdr
= tem
;
1623 SET_SYMBOL_VALUE (variable
, newval
);;
1625 /* Make sure this buffer has its own value of symbol. */
1626 tem
= Fassq (variable
, current_buffer
->local_var_alist
);
1629 /* Swap out any local binding for some other buffer, and make
1630 sure the current value is permanently recorded, if it's the
1632 find_symbol_value (variable
);
1634 current_buffer
->local_var_alist
1635 = Fcons (Fcons (variable
, XCDR (XBUFFER_LOCAL_VALUE (SYMBOL_VALUE (variable
))->cdr
)),
1636 current_buffer
->local_var_alist
);
1638 /* Make sure symbol does not think it is set up for this buffer;
1639 force it to look once again for this buffer's value. */
1641 Lisp_Object
*pvalbuf
;
1643 valcontents
= SYMBOL_VALUE (variable
);
1645 pvalbuf
= &XBUFFER_LOCAL_VALUE (valcontents
)->buffer
;
1646 if (current_buffer
== XBUFFER (*pvalbuf
))
1648 XBUFFER_LOCAL_VALUE (valcontents
)->found_for_buffer
= 0;
1652 /* If the symbol forwards into a C variable, then load the binding
1653 for this buffer now. If C code modifies the variable before we
1654 load the binding in, then that new value will clobber the default
1655 binding the next time we unload it. */
1656 valcontents
= XBUFFER_LOCAL_VALUE (SYMBOL_VALUE (variable
))->realvalue
;
1657 if (INTFWDP (valcontents
) || BOOLFWDP (valcontents
) || OBJFWDP (valcontents
))
1658 swap_in_symval_forwarding (variable
, SYMBOL_VALUE (variable
));
1663 DEFUN ("kill-local-variable", Fkill_local_variable
, Skill_local_variable
,
1664 1, 1, "vKill Local Variable: ",
1665 doc
: /* Make VARIABLE no longer have a separate value in the current buffer.
1666 From now on the default value will apply in this buffer. Return VARIABLE. */)
1668 register Lisp_Object variable
;
1670 register Lisp_Object tem
, valcontents
;
1672 CHECK_SYMBOL (variable
);
1673 variable
= indirect_variable (variable
);
1675 valcontents
= SYMBOL_VALUE (variable
);
1677 if (BUFFER_OBJFWDP (valcontents
))
1679 int offset
= XBUFFER_OBJFWD (valcontents
)->offset
;
1680 int idx
= PER_BUFFER_IDX (offset
);
1684 SET_PER_BUFFER_VALUE_P (current_buffer
, idx
, 0);
1685 PER_BUFFER_VALUE (current_buffer
, offset
)
1686 = PER_BUFFER_DEFAULT (offset
);
1691 if (!BUFFER_LOCAL_VALUEP (valcontents
)
1692 && !SOME_BUFFER_LOCAL_VALUEP (valcontents
))
1695 /* Get rid of this buffer's alist element, if any. */
1697 tem
= Fassq (variable
, current_buffer
->local_var_alist
);
1699 current_buffer
->local_var_alist
1700 = Fdelq (tem
, current_buffer
->local_var_alist
);
1702 /* If the symbol is set up with the current buffer's binding
1703 loaded, recompute its value. We have to do it now, or else
1704 forwarded objects won't work right. */
1706 Lisp_Object
*pvalbuf
, buf
;
1707 valcontents
= SYMBOL_VALUE (variable
);
1708 pvalbuf
= &XBUFFER_LOCAL_VALUE (valcontents
)->buffer
;
1709 XSETBUFFER (buf
, current_buffer
);
1710 if (EQ (buf
, *pvalbuf
))
1713 XBUFFER_LOCAL_VALUE (valcontents
)->found_for_buffer
= 0;
1714 find_symbol_value (variable
);
1721 /* Lisp functions for creating and removing buffer-local variables. */
1723 DEFUN ("make-variable-frame-local", Fmake_variable_frame_local
, Smake_variable_frame_local
,
1724 1, 1, "vMake Variable Frame Local: ",
1725 doc
: /* Enable VARIABLE to have frame-local bindings.
1726 This does not create any frame-local bindings for VARIABLE,
1727 it just makes them possible.
1729 A frame-local binding is actually a frame parameter value.
1730 If a frame F has a value for the frame parameter named VARIABLE,
1731 that also acts as a frame-local binding for VARIABLE in F--
1732 provided this function has been called to enable VARIABLE
1733 to have frame-local bindings at all.
1735 The only way to create a frame-local binding for VARIABLE in a frame
1736 is to set the VARIABLE frame parameter of that frame. See
1737 `modify-frame-parameters' for how to set frame parameters.
1739 Buffer-local bindings take precedence over frame-local bindings. */)
1741 register Lisp_Object variable
;
1743 register Lisp_Object tem
, valcontents
, newval
;
1745 CHECK_SYMBOL (variable
);
1746 variable
= indirect_variable (variable
);
1748 valcontents
= SYMBOL_VALUE (variable
);
1749 if (EQ (variable
, Qnil
) || EQ (variable
, Qt
) || KBOARD_OBJFWDP (valcontents
)
1750 || BUFFER_OBJFWDP (valcontents
))
1751 error ("Symbol %s may not be frame-local", SDATA (SYMBOL_NAME (variable
)));
1753 if (BUFFER_LOCAL_VALUEP (valcontents
)
1754 || SOME_BUFFER_LOCAL_VALUEP (valcontents
))
1756 XBUFFER_LOCAL_VALUE (valcontents
)->check_frame
= 1;
1760 if (EQ (valcontents
, Qunbound
))
1761 SET_SYMBOL_VALUE (variable
, Qnil
);
1762 tem
= Fcons (Qnil
, Fsymbol_value (variable
));
1764 newval
= allocate_misc ();
1765 XMISCTYPE (newval
) = Lisp_Misc_Some_Buffer_Local_Value
;
1766 XBUFFER_LOCAL_VALUE (newval
)->realvalue
= SYMBOL_VALUE (variable
);
1767 XBUFFER_LOCAL_VALUE (newval
)->buffer
= Qnil
;
1768 XBUFFER_LOCAL_VALUE (newval
)->frame
= Qnil
;
1769 XBUFFER_LOCAL_VALUE (newval
)->found_for_buffer
= 0;
1770 XBUFFER_LOCAL_VALUE (newval
)->found_for_frame
= 0;
1771 XBUFFER_LOCAL_VALUE (newval
)->check_frame
= 1;
1772 XBUFFER_LOCAL_VALUE (newval
)->cdr
= tem
;
1773 SET_SYMBOL_VALUE (variable
, newval
);
1777 DEFUN ("local-variable-p", Flocal_variable_p
, Slocal_variable_p
,
1779 doc
: /* Non-nil if VARIABLE has a local binding in buffer BUFFER.
1780 BUFFER defaults to the current buffer. */)
1782 register Lisp_Object variable
, buffer
;
1784 Lisp_Object valcontents
;
1785 register struct buffer
*buf
;
1788 buf
= current_buffer
;
1791 CHECK_BUFFER (buffer
);
1792 buf
= XBUFFER (buffer
);
1795 CHECK_SYMBOL (variable
);
1796 variable
= indirect_variable (variable
);
1798 valcontents
= SYMBOL_VALUE (variable
);
1799 if (BUFFER_LOCAL_VALUEP (valcontents
)
1800 || SOME_BUFFER_LOCAL_VALUEP (valcontents
))
1802 Lisp_Object tail
, elt
;
1804 for (tail
= buf
->local_var_alist
; CONSP (tail
); tail
= XCDR (tail
))
1807 if (EQ (variable
, XCAR (elt
)))
1811 if (BUFFER_OBJFWDP (valcontents
))
1813 int offset
= XBUFFER_OBJFWD (valcontents
)->offset
;
1814 int idx
= PER_BUFFER_IDX (offset
);
1815 if (idx
== -1 || PER_BUFFER_VALUE_P (buf
, idx
))
1821 DEFUN ("local-variable-if-set-p", Flocal_variable_if_set_p
, Slocal_variable_if_set_p
,
1823 doc
: /* Non-nil if VARIABLE will be local in buffer BUFFER when set there.
1824 More precisely, this means that setting the variable \(with `set' or`setq'),
1825 while it does not have a `let'-style binding that was made in BUFFER,
1826 will produce a buffer local binding. See Info node
1827 `(elisp)Creating Buffer-Local'.
1828 BUFFER defaults to the current buffer. */)
1830 register Lisp_Object variable
, buffer
;
1832 Lisp_Object valcontents
;
1833 register struct buffer
*buf
;
1836 buf
= current_buffer
;
1839 CHECK_BUFFER (buffer
);
1840 buf
= XBUFFER (buffer
);
1843 CHECK_SYMBOL (variable
);
1844 variable
= indirect_variable (variable
);
1846 valcontents
= SYMBOL_VALUE (variable
);
1848 /* This means that make-variable-buffer-local was done. */
1849 if (BUFFER_LOCAL_VALUEP (valcontents
))
1851 /* All these slots become local if they are set. */
1852 if (BUFFER_OBJFWDP (valcontents
))
1854 if (SOME_BUFFER_LOCAL_VALUEP (valcontents
))
1856 Lisp_Object tail
, elt
;
1857 for (tail
= buf
->local_var_alist
; CONSP (tail
); tail
= XCDR (tail
))
1860 if (EQ (variable
, XCAR (elt
)))
1867 DEFUN ("variable-binding-locus", Fvariable_binding_locus
, Svariable_binding_locus
,
1869 doc
: /* Return a value indicating where VARIABLE's current binding comes from.
1870 If the current binding is buffer-local, the value is the current buffer.
1871 If the current binding is frame-local, the value is the selected frame.
1872 If the current binding is global (the default), the value is nil. */)
1874 register Lisp_Object variable
;
1876 Lisp_Object valcontents
;
1878 CHECK_SYMBOL (variable
);
1879 variable
= indirect_variable (variable
);
1881 /* Make sure the current binding is actually swapped in. */
1882 find_symbol_value (variable
);
1884 valcontents
= XSYMBOL (variable
)->value
;
1886 if (BUFFER_LOCAL_VALUEP (valcontents
)
1887 || SOME_BUFFER_LOCAL_VALUEP (valcontents
)
1888 || BUFFER_OBJFWDP (valcontents
))
1890 /* For a local variable, record both the symbol and which
1891 buffer's or frame's value we are saving. */
1892 if (!NILP (Flocal_variable_p (variable
, Qnil
)))
1893 return Fcurrent_buffer ();
1894 else if (!BUFFER_OBJFWDP (valcontents
)
1895 && XBUFFER_LOCAL_VALUE (valcontents
)->found_for_frame
)
1896 return XBUFFER_LOCAL_VALUE (valcontents
)->frame
;
1902 /* Find the function at the end of a chain of symbol function indirections. */
1904 /* If OBJECT is a symbol, find the end of its function chain and
1905 return the value found there. If OBJECT is not a symbol, just
1906 return it. If there is a cycle in the function chain, signal a
1907 cyclic-function-indirection error.
1909 This is like Findirect_function, except that it doesn't signal an
1910 error if the chain ends up unbound. */
1912 indirect_function (object
)
1913 register Lisp_Object object
;
1915 Lisp_Object tortoise
, hare
;
1917 hare
= tortoise
= object
;
1921 if (!SYMBOLP (hare
) || EQ (hare
, Qunbound
))
1923 hare
= XSYMBOL (hare
)->function
;
1924 if (!SYMBOLP (hare
) || EQ (hare
, Qunbound
))
1926 hare
= XSYMBOL (hare
)->function
;
1928 tortoise
= XSYMBOL (tortoise
)->function
;
1930 if (EQ (hare
, tortoise
))
1931 Fsignal (Qcyclic_function_indirection
, Fcons (object
, Qnil
));
1937 DEFUN ("indirect-function", Findirect_function
, Sindirect_function
, 1, 2, 0,
1938 doc
: /* Return the function at the end of OBJECT's function chain.
1939 If OBJECT is not a symbol, just return it. Otherwise, follow all
1940 function indirections to find the final function binding and return it.
1941 If the final symbol in the chain is unbound, signal a void-function error.
1942 Optional arg NOERROR non-nil means to return nil instead of signalling.
1943 Signal a cyclic-function-indirection error if there is a loop in the
1944 function chain of symbols. */)
1946 register Lisp_Object object
;
1947 Lisp_Object noerror
;
1951 result
= indirect_function (object
);
1953 if (EQ (result
, Qunbound
))
1954 return (NILP (noerror
)
1955 ? Fsignal (Qvoid_function
, Fcons (object
, Qnil
))
1960 /* Extract and set vector and string elements */
1962 DEFUN ("aref", Faref
, Saref
, 2, 2, 0,
1963 doc
: /* Return the element of ARRAY at index IDX.
1964 ARRAY may be a vector, a string, a char-table, a bool-vector,
1965 or a byte-code object. IDX starts at 0. */)
1967 register Lisp_Object array
;
1970 register int idxval
;
1973 idxval
= XINT (idx
);
1974 if (STRINGP (array
))
1978 if (idxval
< 0 || idxval
>= SCHARS (array
))
1979 args_out_of_range (array
, idx
);
1980 if (! STRING_MULTIBYTE (array
))
1981 return make_number ((unsigned char) SREF (array
, idxval
));
1982 idxval_byte
= string_char_to_byte (array
, idxval
);
1984 c
= STRING_CHAR (SDATA (array
) + idxval_byte
,
1985 SBYTES (array
) - idxval_byte
);
1986 return make_number (c
);
1988 else if (BOOL_VECTOR_P (array
))
1992 if (idxval
< 0 || idxval
>= XBOOL_VECTOR (array
)->size
)
1993 args_out_of_range (array
, idx
);
1995 val
= (unsigned char) XBOOL_VECTOR (array
)->data
[idxval
/ BOOL_VECTOR_BITS_PER_CHAR
];
1996 return (val
& (1 << (idxval
% BOOL_VECTOR_BITS_PER_CHAR
)) ? Qt
: Qnil
);
1998 else if (CHAR_TABLE_P (array
))
2005 args_out_of_range (array
, idx
);
2006 if (idxval
< CHAR_TABLE_ORDINARY_SLOTS
)
2008 if (! SINGLE_BYTE_CHAR_P (idxval
))
2009 args_out_of_range (array
, idx
);
2010 /* For ASCII and 8-bit European characters, the element is
2011 stored in the top table. */
2012 val
= XCHAR_TABLE (array
)->contents
[idxval
];
2016 = (idxval
< 0x80 ? CHAR_TABLE_DEFAULT_SLOT_ASCII
2017 : idxval
< 0xA0 ? CHAR_TABLE_DEFAULT_SLOT_8_BIT_CONTROL
2018 : CHAR_TABLE_DEFAULT_SLOT_8_BIT_GRAPHIC
);
2019 val
= XCHAR_TABLE (array
)->contents
[default_slot
];
2022 val
= XCHAR_TABLE (array
)->defalt
;
2023 while (NILP (val
)) /* Follow parents until we find some value. */
2025 array
= XCHAR_TABLE (array
)->parent
;
2028 val
= XCHAR_TABLE (array
)->contents
[idxval
];
2030 val
= XCHAR_TABLE (array
)->defalt
;
2037 Lisp_Object sub_table
;
2038 Lisp_Object current_default
;
2040 SPLIT_CHAR (idxval
, code
[0], code
[1], code
[2]);
2041 if (code
[1] < 32) code
[1] = -1;
2042 else if (code
[2] < 32) code
[2] = -1;
2044 /* Here, the possible range of CODE[0] (== charset ID) is
2045 128..MAX_CHARSET. Since the top level char table contains
2046 data for multibyte characters after 256th element, we must
2047 increment CODE[0] by 128 to get a correct index. */
2049 code
[3] = -1; /* anchor */
2051 try_parent_char_table
:
2052 current_default
= XCHAR_TABLE (array
)->defalt
;
2054 for (i
= 0; code
[i
] >= 0; i
++)
2056 val
= XCHAR_TABLE (sub_table
)->contents
[code
[i
]];
2057 if (SUB_CHAR_TABLE_P (val
))
2060 if (! NILP (XCHAR_TABLE (sub_table
)->defalt
))
2061 current_default
= XCHAR_TABLE (sub_table
)->defalt
;
2066 val
= current_default
;
2069 array
= XCHAR_TABLE (array
)->parent
;
2071 goto try_parent_char_table
;
2076 /* Reaching here means IDXVAL is a generic character in
2077 which each character or a group has independent value.
2078 Essentially it's nonsense to get a value for such a
2079 generic character, but for backward compatibility, we try
2080 the default value and parent. */
2081 val
= current_default
;
2084 array
= XCHAR_TABLE (array
)->parent
;
2086 goto try_parent_char_table
;
2094 if (VECTORP (array
))
2095 size
= XVECTOR (array
)->size
;
2096 else if (COMPILEDP (array
))
2097 size
= XVECTOR (array
)->size
& PSEUDOVECTOR_SIZE_MASK
;
2099 wrong_type_argument (Qarrayp
, array
);
2101 if (idxval
< 0 || idxval
>= size
)
2102 args_out_of_range (array
, idx
);
2103 return XVECTOR (array
)->contents
[idxval
];
2107 DEFUN ("aset", Faset
, Saset
, 3, 3, 0,
2108 doc
: /* Store into the element of ARRAY at index IDX the value NEWELT.
2109 Return NEWELT. ARRAY may be a vector, a string, a char-table or a
2110 bool-vector. IDX starts at 0. */)
2111 (array
, idx
, newelt
)
2112 register Lisp_Object array
;
2113 Lisp_Object idx
, newelt
;
2115 register int idxval
;
2118 idxval
= XINT (idx
);
2119 if (!VECTORP (array
) && !STRINGP (array
) && !BOOL_VECTOR_P (array
)
2120 && ! CHAR_TABLE_P (array
))
2121 array
= wrong_type_argument (Qarrayp
, array
);
2122 CHECK_IMPURE (array
);
2124 if (VECTORP (array
))
2126 if (idxval
< 0 || idxval
>= XVECTOR (array
)->size
)
2127 args_out_of_range (array
, idx
);
2128 XVECTOR (array
)->contents
[idxval
] = newelt
;
2130 else if (BOOL_VECTOR_P (array
))
2134 if (idxval
< 0 || idxval
>= XBOOL_VECTOR (array
)->size
)
2135 args_out_of_range (array
, idx
);
2137 val
= (unsigned char) XBOOL_VECTOR (array
)->data
[idxval
/ BOOL_VECTOR_BITS_PER_CHAR
];
2139 if (! NILP (newelt
))
2140 val
|= 1 << (idxval
% BOOL_VECTOR_BITS_PER_CHAR
);
2142 val
&= ~(1 << (idxval
% BOOL_VECTOR_BITS_PER_CHAR
));
2143 XBOOL_VECTOR (array
)->data
[idxval
/ BOOL_VECTOR_BITS_PER_CHAR
] = val
;
2145 else if (CHAR_TABLE_P (array
))
2148 args_out_of_range (array
, idx
);
2149 if (idxval
< CHAR_TABLE_ORDINARY_SLOTS
)
2151 if (! SINGLE_BYTE_CHAR_P (idxval
))
2152 args_out_of_range (array
, idx
);
2153 XCHAR_TABLE (array
)->contents
[idxval
] = newelt
;
2160 SPLIT_CHAR (idxval
, code
[0], code
[1], code
[2]);
2161 if (code
[1] < 32) code
[1] = -1;
2162 else if (code
[2] < 32) code
[2] = -1;
2164 /* See the comment of the corresponding part in Faref. */
2166 code
[3] = -1; /* anchor */
2167 for (i
= 0; code
[i
+ 1] >= 0; i
++)
2169 val
= XCHAR_TABLE (array
)->contents
[code
[i
]];
2170 if (SUB_CHAR_TABLE_P (val
))
2176 /* VAL is a leaf. Create a sub char table with the
2177 initial value VAL and look into it. */
2179 temp
= make_sub_char_table (val
);
2180 XCHAR_TABLE (array
)->contents
[code
[i
]] = temp
;
2184 XCHAR_TABLE (array
)->contents
[code
[i
]] = newelt
;
2187 else if (STRING_MULTIBYTE (array
))
2189 int idxval_byte
, prev_bytes
, new_bytes
, nbytes
;
2190 unsigned char workbuf
[MAX_MULTIBYTE_LENGTH
], *p0
= workbuf
, *p1
;
2192 if (idxval
< 0 || idxval
>= SCHARS (array
))
2193 args_out_of_range (array
, idx
);
2194 CHECK_NUMBER (newelt
);
2196 nbytes
= SBYTES (array
);
2198 idxval_byte
= string_char_to_byte (array
, idxval
);
2199 p1
= SDATA (array
) + idxval_byte
;
2200 PARSE_MULTIBYTE_SEQ (p1
, nbytes
- idxval_byte
, prev_bytes
);
2201 new_bytes
= CHAR_STRING (XINT (newelt
), p0
);
2202 if (prev_bytes
!= new_bytes
)
2204 /* We must relocate the string data. */
2205 int nchars
= SCHARS (array
);
2209 SAFE_ALLOCA (str
, unsigned char *, nbytes
);
2210 bcopy (SDATA (array
), str
, nbytes
);
2211 allocate_string_data (XSTRING (array
), nchars
,
2212 nbytes
+ new_bytes
- prev_bytes
);
2213 bcopy (str
, SDATA (array
), idxval_byte
);
2214 p1
= SDATA (array
) + idxval_byte
;
2215 bcopy (str
+ idxval_byte
+ prev_bytes
, p1
+ new_bytes
,
2216 nbytes
- (idxval_byte
+ prev_bytes
));
2218 clear_string_char_byte_cache ();
2225 if (idxval
< 0 || idxval
>= SCHARS (array
))
2226 args_out_of_range (array
, idx
);
2227 CHECK_NUMBER (newelt
);
2229 if (XINT (newelt
) < 0 || SINGLE_BYTE_CHAR_P (XINT (newelt
)))
2230 SSET (array
, idxval
, XINT (newelt
));
2233 /* We must relocate the string data while converting it to
2235 int idxval_byte
, prev_bytes
, new_bytes
;
2236 unsigned char workbuf
[MAX_MULTIBYTE_LENGTH
], *p0
= workbuf
, *p1
;
2237 unsigned char *origstr
= SDATA (array
), *str
;
2241 nchars
= SCHARS (array
);
2242 nbytes
= idxval_byte
= count_size_as_multibyte (origstr
, idxval
);
2243 nbytes
+= count_size_as_multibyte (origstr
+ idxval
,
2245 SAFE_ALLOCA (str
, unsigned char *, nbytes
);
2246 copy_text (SDATA (array
), str
, nchars
, 0, 1);
2247 PARSE_MULTIBYTE_SEQ (str
+ idxval_byte
, nbytes
- idxval_byte
,
2249 new_bytes
= CHAR_STRING (XINT (newelt
), p0
);
2250 allocate_string_data (XSTRING (array
), nchars
,
2251 nbytes
+ new_bytes
- prev_bytes
);
2252 bcopy (str
, SDATA (array
), idxval_byte
);
2253 p1
= SDATA (array
) + idxval_byte
;
2256 bcopy (str
+ idxval_byte
+ prev_bytes
, p1
,
2257 nbytes
- (idxval_byte
+ prev_bytes
));
2259 clear_string_char_byte_cache ();
2266 /* Arithmetic functions */
2268 enum comparison
{ equal
, notequal
, less
, grtr
, less_or_equal
, grtr_or_equal
};
2271 arithcompare (num1
, num2
, comparison
)
2272 Lisp_Object num1
, num2
;
2273 enum comparison comparison
;
2275 double f1
= 0, f2
= 0;
2278 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (num1
);
2279 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (num2
);
2281 if (FLOATP (num1
) || FLOATP (num2
))
2284 f1
= (FLOATP (num1
)) ? XFLOAT_DATA (num1
) : XINT (num1
);
2285 f2
= (FLOATP (num2
)) ? XFLOAT_DATA (num2
) : XINT (num2
);
2291 if (floatp
? f1
== f2
: XINT (num1
) == XINT (num2
))
2296 if (floatp
? f1
!= f2
: XINT (num1
) != XINT (num2
))
2301 if (floatp
? f1
< f2
: XINT (num1
) < XINT (num2
))
2306 if (floatp
? f1
<= f2
: XINT (num1
) <= XINT (num2
))
2311 if (floatp
? f1
> f2
: XINT (num1
) > XINT (num2
))
2316 if (floatp
? f1
>= f2
: XINT (num1
) >= XINT (num2
))
2325 DEFUN ("=", Feqlsign
, Seqlsign
, 2, 2, 0,
2326 doc
: /* Return t if two args, both numbers or markers, are equal. */)
2328 register Lisp_Object num1
, num2
;
2330 return arithcompare (num1
, num2
, equal
);
2333 DEFUN ("<", Flss
, Slss
, 2, 2, 0,
2334 doc
: /* Return t if first arg is less than second arg. Both must be numbers or markers. */)
2336 register Lisp_Object num1
, num2
;
2338 return arithcompare (num1
, num2
, less
);
2341 DEFUN (">", Fgtr
, Sgtr
, 2, 2, 0,
2342 doc
: /* Return t if first arg is greater than second arg. Both must be numbers or markers. */)
2344 register Lisp_Object num1
, num2
;
2346 return arithcompare (num1
, num2
, grtr
);
2349 DEFUN ("<=", Fleq
, Sleq
, 2, 2, 0,
2350 doc
: /* Return t if first arg is less than or equal to second arg.
2351 Both must be numbers or markers. */)
2353 register Lisp_Object num1
, num2
;
2355 return arithcompare (num1
, num2
, less_or_equal
);
2358 DEFUN (">=", Fgeq
, Sgeq
, 2, 2, 0,
2359 doc
: /* Return t if first arg is greater than or equal to second arg.
2360 Both must be numbers or markers. */)
2362 register Lisp_Object num1
, num2
;
2364 return arithcompare (num1
, num2
, grtr_or_equal
);
2367 DEFUN ("/=", Fneq
, Sneq
, 2, 2, 0,
2368 doc
: /* Return t if first arg is not equal to second arg. Both must be numbers or markers. */)
2370 register Lisp_Object num1
, num2
;
2372 return arithcompare (num1
, num2
, notequal
);
2375 DEFUN ("zerop", Fzerop
, Szerop
, 1, 1, 0,
2376 doc
: /* Return t if NUMBER is zero. */)
2378 register Lisp_Object number
;
2380 CHECK_NUMBER_OR_FLOAT (number
);
2382 if (FLOATP (number
))
2384 if (XFLOAT_DATA (number
) == 0.0)
2394 /* Convert between long values and pairs of Lisp integers. */
2400 unsigned long top
= i
>> 16;
2401 unsigned int bot
= i
& 0xFFFF;
2403 return make_number (bot
);
2404 if (top
== (unsigned long)-1 >> 16)
2405 return Fcons (make_number (-1), make_number (bot
));
2406 return Fcons (make_number (top
), make_number (bot
));
2413 Lisp_Object top
, bot
;
2420 return ((XINT (top
) << 16) | XINT (bot
));
2423 DEFUN ("number-to-string", Fnumber_to_string
, Snumber_to_string
, 1, 1, 0,
2424 doc
: /* Return the decimal representation of NUMBER as a string.
2425 Uses a minus sign if negative.
2426 NUMBER may be an integer or a floating point number. */)
2430 char buffer
[VALBITS
];
2432 CHECK_NUMBER_OR_FLOAT (number
);
2434 if (FLOATP (number
))
2436 char pigbuf
[350]; /* see comments in float_to_string */
2438 float_to_string (pigbuf
, XFLOAT_DATA (number
));
2439 return build_string (pigbuf
);
2442 if (sizeof (int) == sizeof (EMACS_INT
))
2443 sprintf (buffer
, "%d", XINT (number
));
2444 else if (sizeof (long) == sizeof (EMACS_INT
))
2445 sprintf (buffer
, "%ld", (long) XINT (number
));
2448 return build_string (buffer
);
2452 digit_to_number (character
, base
)
2453 int character
, base
;
2457 if (character
>= '0' && character
<= '9')
2458 digit
= character
- '0';
2459 else if (character
>= 'a' && character
<= 'z')
2460 digit
= character
- 'a' + 10;
2461 else if (character
>= 'A' && character
<= 'Z')
2462 digit
= character
- 'A' + 10;
2472 DEFUN ("string-to-number", Fstring_to_number
, Sstring_to_number
, 1, 2, 0,
2473 doc
: /* Parse STRING as a decimal number and return the number.
2474 This parses both integers and floating point numbers.
2475 It ignores leading spaces and tabs.
2477 If BASE, interpret STRING as a number in that base. If BASE isn't
2478 present, base 10 is used. BASE must be between 2 and 16 (inclusive).
2479 If the base used is not 10, floating point is not recognized. */)
2481 register Lisp_Object string
, base
;
2483 register unsigned char *p
;
2488 CHECK_STRING (string
);
2494 CHECK_NUMBER (base
);
2496 if (b
< 2 || b
> 16)
2497 Fsignal (Qargs_out_of_range
, Fcons (base
, Qnil
));
2500 /* Skip any whitespace at the front of the number. Some versions of
2501 atoi do this anyway, so we might as well make Emacs lisp consistent. */
2503 while (*p
== ' ' || *p
== '\t')
2514 if (isfloat_string (p
) && b
== 10)
2515 val
= make_float (sign
* atof (p
));
2522 int digit
= digit_to_number (*p
++, b
);
2528 val
= make_fixnum_or_float (sign
* v
);
2548 static Lisp_Object float_arith_driver
P_ ((double, int, enum arithop
,
2549 int, Lisp_Object
*));
2550 extern Lisp_Object
fmod_float ();
2553 arith_driver (code
, nargs
, args
)
2556 register Lisp_Object
*args
;
2558 register Lisp_Object val
;
2559 register int argnum
;
2560 register EMACS_INT accum
= 0;
2561 register EMACS_INT next
;
2563 switch (SWITCH_ENUM_CAST (code
))
2581 for (argnum
= 0; argnum
< nargs
; argnum
++)
2583 /* Using args[argnum] as argument to CHECK_NUMBER_... */
2585 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (val
);
2588 return float_arith_driver ((double) accum
, argnum
, code
,
2591 next
= XINT (args
[argnum
]);
2592 switch (SWITCH_ENUM_CAST (code
))
2598 accum
= argnum
? accum
- next
: nargs
== 1 ? - next
: next
;
2609 Fsignal (Qarith_error
, Qnil
);
2623 if (!argnum
|| next
> accum
)
2627 if (!argnum
|| next
< accum
)
2633 XSETINT (val
, accum
);
2638 #define isnan(x) ((x) != (x))
2641 float_arith_driver (accum
, argnum
, code
, nargs
, args
)
2643 register int argnum
;
2646 register Lisp_Object
*args
;
2648 register Lisp_Object val
;
2651 for (; argnum
< nargs
; argnum
++)
2653 val
= args
[argnum
]; /* using args[argnum] as argument to CHECK_NUMBER_... */
2654 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (val
);
2658 next
= XFLOAT_DATA (val
);
2662 args
[argnum
] = val
; /* runs into a compiler bug. */
2663 next
= XINT (args
[argnum
]);
2665 switch (SWITCH_ENUM_CAST (code
))
2671 accum
= argnum
? accum
- next
: nargs
== 1 ? - next
: next
;
2681 if (! IEEE_FLOATING_POINT
&& next
== 0)
2682 Fsignal (Qarith_error
, Qnil
);
2689 return wrong_type_argument (Qinteger_or_marker_p
, val
);
2691 if (!argnum
|| isnan (next
) || next
> accum
)
2695 if (!argnum
|| isnan (next
) || next
< accum
)
2701 return make_float (accum
);
2705 DEFUN ("+", Fplus
, Splus
, 0, MANY
, 0,
2706 doc
: /* Return sum of any number of arguments, which are numbers or markers.
2707 usage: (+ &rest NUMBERS-OR-MARKERS) */)
2712 return arith_driver (Aadd
, nargs
, args
);
2715 DEFUN ("-", Fminus
, Sminus
, 0, MANY
, 0,
2716 doc
: /* Negate number or subtract numbers or markers and return the result.
2717 With one arg, negates it. With more than one arg,
2718 subtracts all but the first from the first.
2719 usage: (- &optional NUMBER-OR-MARKER &rest MORE-NUMBERS-OR-MARKERS) */)
2724 return arith_driver (Asub
, nargs
, args
);
2727 DEFUN ("*", Ftimes
, Stimes
, 0, MANY
, 0,
2728 doc
: /* Return product of any number of arguments, which are numbers or markers.
2729 usage: (* &rest NUMBERS-OR-MARKERS) */)
2734 return arith_driver (Amult
, nargs
, args
);
2737 DEFUN ("/", Fquo
, Squo
, 2, MANY
, 0,
2738 doc
: /* Return first argument divided by all the remaining arguments.
2739 The arguments must be numbers or markers.
2740 usage: (/ DIVIDEND DIVISOR &rest DIVISORS) */)
2746 for (argnum
= 2; argnum
< nargs
; argnum
++)
2747 if (FLOATP (args
[argnum
]))
2748 return float_arith_driver (0, 0, Adiv
, nargs
, args
);
2749 return arith_driver (Adiv
, nargs
, args
);
2752 DEFUN ("%", Frem
, Srem
, 2, 2, 0,
2753 doc
: /* Return remainder of X divided by Y.
2754 Both must be integers or markers. */)
2756 register Lisp_Object x
, y
;
2760 CHECK_NUMBER_COERCE_MARKER (x
);
2761 CHECK_NUMBER_COERCE_MARKER (y
);
2763 if (XFASTINT (y
) == 0)
2764 Fsignal (Qarith_error
, Qnil
);
2766 XSETINT (val
, XINT (x
) % XINT (y
));
2780 /* If the magnitude of the result exceeds that of the divisor, or
2781 the sign of the result does not agree with that of the dividend,
2782 iterate with the reduced value. This does not yield a
2783 particularly accurate result, but at least it will be in the
2784 range promised by fmod. */
2786 r
-= f2
* floor (r
/ f2
);
2787 while (f2
<= (r
< 0 ? -r
: r
) || ((r
< 0) != (f1
< 0) && ! isnan (r
)));
2791 #endif /* ! HAVE_FMOD */
2793 DEFUN ("mod", Fmod
, Smod
, 2, 2, 0,
2794 doc
: /* Return X modulo Y.
2795 The result falls between zero (inclusive) and Y (exclusive).
2796 Both X and Y must be numbers or markers. */)
2798 register Lisp_Object x
, y
;
2803 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (x
);
2804 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (y
);
2806 if (FLOATP (x
) || FLOATP (y
))
2807 return fmod_float (x
, y
);
2813 Fsignal (Qarith_error
, Qnil
);
2817 /* If the "remainder" comes out with the wrong sign, fix it. */
2818 if (i2
< 0 ? i1
> 0 : i1
< 0)
2825 DEFUN ("max", Fmax
, Smax
, 1, MANY
, 0,
2826 doc
: /* Return largest of all the arguments (which must be numbers or markers).
2827 The value is always a number; markers are converted to numbers.
2828 usage: (max NUMBER-OR-MARKER &rest NUMBERS-OR-MARKERS) */)
2833 return arith_driver (Amax
, nargs
, args
);
2836 DEFUN ("min", Fmin
, Smin
, 1, MANY
, 0,
2837 doc
: /* Return smallest of all the arguments (which must be numbers or markers).
2838 The value is always a number; markers are converted to numbers.
2839 usage: (min NUMBER-OR-MARKER &rest NUMBERS-OR-MARKERS) */)
2844 return arith_driver (Amin
, nargs
, args
);
2847 DEFUN ("logand", Flogand
, Slogand
, 0, MANY
, 0,
2848 doc
: /* Return bitwise-and of all the arguments.
2849 Arguments may be integers, or markers converted to integers.
2850 usage: (logand &rest INTS-OR-MARKERS) */)
2855 return arith_driver (Alogand
, nargs
, args
);
2858 DEFUN ("logior", Flogior
, Slogior
, 0, MANY
, 0,
2859 doc
: /* Return bitwise-or of all the arguments.
2860 Arguments may be integers, or markers converted to integers.
2861 usage: (logior &rest INTS-OR-MARKERS) */)
2866 return arith_driver (Alogior
, nargs
, args
);
2869 DEFUN ("logxor", Flogxor
, Slogxor
, 0, MANY
, 0,
2870 doc
: /* Return bitwise-exclusive-or of all the arguments.
2871 Arguments may be integers, or markers converted to integers.
2872 usage: (logxor &rest INTS-OR-MARKERS) */)
2877 return arith_driver (Alogxor
, nargs
, args
);
2880 DEFUN ("ash", Fash
, Sash
, 2, 2, 0,
2881 doc
: /* Return VALUE with its bits shifted left by COUNT.
2882 If COUNT is negative, shifting is actually to the right.
2883 In this case, the sign bit is duplicated. */)
2885 register Lisp_Object value
, count
;
2887 register Lisp_Object val
;
2889 CHECK_NUMBER (value
);
2890 CHECK_NUMBER (count
);
2892 if (XINT (count
) >= BITS_PER_EMACS_INT
)
2894 else if (XINT (count
) > 0)
2895 XSETINT (val
, XINT (value
) << XFASTINT (count
));
2896 else if (XINT (count
) <= -BITS_PER_EMACS_INT
)
2897 XSETINT (val
, XINT (value
) < 0 ? -1 : 0);
2899 XSETINT (val
, XINT (value
) >> -XINT (count
));
2903 DEFUN ("lsh", Flsh
, Slsh
, 2, 2, 0,
2904 doc
: /* Return VALUE with its bits shifted left by COUNT.
2905 If COUNT is negative, shifting is actually to the right.
2906 In this case, zeros are shifted in on the left. */)
2908 register Lisp_Object value
, count
;
2910 register Lisp_Object val
;
2912 CHECK_NUMBER (value
);
2913 CHECK_NUMBER (count
);
2915 if (XINT (count
) >= BITS_PER_EMACS_INT
)
2917 else if (XINT (count
) > 0)
2918 XSETINT (val
, (EMACS_UINT
) XUINT (value
) << XFASTINT (count
));
2919 else if (XINT (count
) <= -BITS_PER_EMACS_INT
)
2922 XSETINT (val
, (EMACS_UINT
) XUINT (value
) >> -XINT (count
));
2926 DEFUN ("1+", Fadd1
, Sadd1
, 1, 1, 0,
2927 doc
: /* Return NUMBER plus one. NUMBER may be a number or a marker.
2928 Markers are converted to integers. */)
2930 register Lisp_Object number
;
2932 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (number
);
2934 if (FLOATP (number
))
2935 return (make_float (1.0 + XFLOAT_DATA (number
)));
2937 XSETINT (number
, XINT (number
) + 1);
2941 DEFUN ("1-", Fsub1
, Ssub1
, 1, 1, 0,
2942 doc
: /* Return NUMBER minus one. NUMBER may be a number or a marker.
2943 Markers are converted to integers. */)
2945 register Lisp_Object number
;
2947 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (number
);
2949 if (FLOATP (number
))
2950 return (make_float (-1.0 + XFLOAT_DATA (number
)));
2952 XSETINT (number
, XINT (number
) - 1);
2956 DEFUN ("lognot", Flognot
, Slognot
, 1, 1, 0,
2957 doc
: /* Return the bitwise complement of NUMBER. NUMBER must be an integer. */)
2959 register Lisp_Object number
;
2961 CHECK_NUMBER (number
);
2962 XSETINT (number
, ~XINT (number
));
2966 DEFUN ("byteorder", Fbyteorder
, Sbyteorder
, 0, 0, 0,
2967 doc
: /* Return the byteorder for the machine.
2968 Returns 66 (ASCII uppercase B) for big endian machines or 108 (ASCII
2969 lowercase l) for small endian machines. */)
2972 unsigned i
= 0x04030201;
2973 int order
= *(char *)&i
== 1 ? 108 : 66;
2975 return make_number (order
);
2983 Lisp_Object error_tail
, arith_tail
;
2985 Qquote
= intern ("quote");
2986 Qlambda
= intern ("lambda");
2987 Qsubr
= intern ("subr");
2988 Qerror_conditions
= intern ("error-conditions");
2989 Qerror_message
= intern ("error-message");
2990 Qtop_level
= intern ("top-level");
2992 Qerror
= intern ("error");
2993 Qquit
= intern ("quit");
2994 Qwrong_type_argument
= intern ("wrong-type-argument");
2995 Qargs_out_of_range
= intern ("args-out-of-range");
2996 Qvoid_function
= intern ("void-function");
2997 Qcyclic_function_indirection
= intern ("cyclic-function-indirection");
2998 Qcyclic_variable_indirection
= intern ("cyclic-variable-indirection");
2999 Qvoid_variable
= intern ("void-variable");
3000 Qsetting_constant
= intern ("setting-constant");
3001 Qinvalid_read_syntax
= intern ("invalid-read-syntax");
3003 Qinvalid_function
= intern ("invalid-function");
3004 Qwrong_number_of_arguments
= intern ("wrong-number-of-arguments");
3005 Qno_catch
= intern ("no-catch");
3006 Qend_of_file
= intern ("end-of-file");
3007 Qarith_error
= intern ("arith-error");
3008 Qbeginning_of_buffer
= intern ("beginning-of-buffer");
3009 Qend_of_buffer
= intern ("end-of-buffer");
3010 Qbuffer_read_only
= intern ("buffer-read-only");
3011 Qtext_read_only
= intern ("text-read-only");
3012 Qmark_inactive
= intern ("mark-inactive");
3014 Qlistp
= intern ("listp");
3015 Qconsp
= intern ("consp");
3016 Qsymbolp
= intern ("symbolp");
3017 Qkeywordp
= intern ("keywordp");
3018 Qintegerp
= intern ("integerp");
3019 Qnatnump
= intern ("natnump");
3020 Qwholenump
= intern ("wholenump");
3021 Qstringp
= intern ("stringp");
3022 Qarrayp
= intern ("arrayp");
3023 Qsequencep
= intern ("sequencep");
3024 Qbufferp
= intern ("bufferp");
3025 Qvectorp
= intern ("vectorp");
3026 Qchar_or_string_p
= intern ("char-or-string-p");
3027 Qmarkerp
= intern ("markerp");
3028 Qbuffer_or_string_p
= intern ("buffer-or-string-p");
3029 Qinteger_or_marker_p
= intern ("integer-or-marker-p");
3030 Qboundp
= intern ("boundp");
3031 Qfboundp
= intern ("fboundp");
3033 Qfloatp
= intern ("floatp");
3034 Qnumberp
= intern ("numberp");
3035 Qnumber_or_marker_p
= intern ("number-or-marker-p");
3037 Qchar_table_p
= intern ("char-table-p");
3038 Qvector_or_char_table_p
= intern ("vector-or-char-table-p");
3040 Qsubrp
= intern ("subrp");
3041 Qunevalled
= intern ("unevalled");
3042 Qmany
= intern ("many");
3044 Qcdr
= intern ("cdr");
3046 /* Handle automatic advice activation */
3047 Qad_advice_info
= intern ("ad-advice-info");
3048 Qad_activate_internal
= intern ("ad-activate-internal");
3050 error_tail
= Fcons (Qerror
, Qnil
);
3052 /* ERROR is used as a signaler for random errors for which nothing else is right */
3054 Fput (Qerror
, Qerror_conditions
,
3056 Fput (Qerror
, Qerror_message
,
3057 build_string ("error"));
3059 Fput (Qquit
, Qerror_conditions
,
3060 Fcons (Qquit
, Qnil
));
3061 Fput (Qquit
, Qerror_message
,
3062 build_string ("Quit"));
3064 Fput (Qwrong_type_argument
, Qerror_conditions
,
3065 Fcons (Qwrong_type_argument
, error_tail
));
3066 Fput (Qwrong_type_argument
, Qerror_message
,
3067 build_string ("Wrong type argument"));
3069 Fput (Qargs_out_of_range
, Qerror_conditions
,
3070 Fcons (Qargs_out_of_range
, error_tail
));
3071 Fput (Qargs_out_of_range
, Qerror_message
,
3072 build_string ("Args out of range"));
3074 Fput (Qvoid_function
, Qerror_conditions
,
3075 Fcons (Qvoid_function
, error_tail
));
3076 Fput (Qvoid_function
, Qerror_message
,
3077 build_string ("Symbol's function definition is void"));
3079 Fput (Qcyclic_function_indirection
, Qerror_conditions
,
3080 Fcons (Qcyclic_function_indirection
, error_tail
));
3081 Fput (Qcyclic_function_indirection
, Qerror_message
,
3082 build_string ("Symbol's chain of function indirections contains a loop"));
3084 Fput (Qcyclic_variable_indirection
, Qerror_conditions
,
3085 Fcons (Qcyclic_variable_indirection
, error_tail
));
3086 Fput (Qcyclic_variable_indirection
, Qerror_message
,
3087 build_string ("Symbol's chain of variable indirections contains a loop"));
3089 Qcircular_list
= intern ("circular-list");
3090 staticpro (&Qcircular_list
);
3091 Fput (Qcircular_list
, Qerror_conditions
,
3092 Fcons (Qcircular_list
, error_tail
));
3093 Fput (Qcircular_list
, Qerror_message
,
3094 build_string ("List contains a loop"));
3096 Fput (Qvoid_variable
, Qerror_conditions
,
3097 Fcons (Qvoid_variable
, error_tail
));
3098 Fput (Qvoid_variable
, Qerror_message
,
3099 build_string ("Symbol's value as variable is void"));
3101 Fput (Qsetting_constant
, Qerror_conditions
,
3102 Fcons (Qsetting_constant
, error_tail
));
3103 Fput (Qsetting_constant
, Qerror_message
,
3104 build_string ("Attempt to set a constant symbol"));
3106 Fput (Qinvalid_read_syntax
, Qerror_conditions
,
3107 Fcons (Qinvalid_read_syntax
, error_tail
));
3108 Fput (Qinvalid_read_syntax
, Qerror_message
,
3109 build_string ("Invalid read syntax"));
3111 Fput (Qinvalid_function
, Qerror_conditions
,
3112 Fcons (Qinvalid_function
, error_tail
));
3113 Fput (Qinvalid_function
, Qerror_message
,
3114 build_string ("Invalid function"));
3116 Fput (Qwrong_number_of_arguments
, Qerror_conditions
,
3117 Fcons (Qwrong_number_of_arguments
, error_tail
));
3118 Fput (Qwrong_number_of_arguments
, Qerror_message
,
3119 build_string ("Wrong number of arguments"));
3121 Fput (Qno_catch
, Qerror_conditions
,
3122 Fcons (Qno_catch
, error_tail
));
3123 Fput (Qno_catch
, Qerror_message
,
3124 build_string ("No catch for tag"));
3126 Fput (Qend_of_file
, Qerror_conditions
,
3127 Fcons (Qend_of_file
, error_tail
));
3128 Fput (Qend_of_file
, Qerror_message
,
3129 build_string ("End of file during parsing"));
3131 arith_tail
= Fcons (Qarith_error
, error_tail
);
3132 Fput (Qarith_error
, Qerror_conditions
,
3134 Fput (Qarith_error
, Qerror_message
,
3135 build_string ("Arithmetic error"));
3137 Fput (Qbeginning_of_buffer
, Qerror_conditions
,
3138 Fcons (Qbeginning_of_buffer
, error_tail
));
3139 Fput (Qbeginning_of_buffer
, Qerror_message
,
3140 build_string ("Beginning of buffer"));
3142 Fput (Qend_of_buffer
, Qerror_conditions
,
3143 Fcons (Qend_of_buffer
, error_tail
));
3144 Fput (Qend_of_buffer
, Qerror_message
,
3145 build_string ("End of buffer"));
3147 Fput (Qbuffer_read_only
, Qerror_conditions
,
3148 Fcons (Qbuffer_read_only
, error_tail
));
3149 Fput (Qbuffer_read_only
, Qerror_message
,
3150 build_string ("Buffer is read-only"));
3152 Fput (Qtext_read_only
, Qerror_conditions
,
3153 Fcons (Qtext_read_only
, error_tail
));
3154 Fput (Qtext_read_only
, Qerror_message
,
3155 build_string ("Text is read-only"));
3157 Qrange_error
= intern ("range-error");
3158 Qdomain_error
= intern ("domain-error");
3159 Qsingularity_error
= intern ("singularity-error");
3160 Qoverflow_error
= intern ("overflow-error");
3161 Qunderflow_error
= intern ("underflow-error");
3163 Fput (Qdomain_error
, Qerror_conditions
,
3164 Fcons (Qdomain_error
, arith_tail
));
3165 Fput (Qdomain_error
, Qerror_message
,
3166 build_string ("Arithmetic domain error"));
3168 Fput (Qrange_error
, Qerror_conditions
,
3169 Fcons (Qrange_error
, arith_tail
));
3170 Fput (Qrange_error
, Qerror_message
,
3171 build_string ("Arithmetic range error"));
3173 Fput (Qsingularity_error
, Qerror_conditions
,
3174 Fcons (Qsingularity_error
, Fcons (Qdomain_error
, arith_tail
)));
3175 Fput (Qsingularity_error
, Qerror_message
,
3176 build_string ("Arithmetic singularity error"));
3178 Fput (Qoverflow_error
, Qerror_conditions
,
3179 Fcons (Qoverflow_error
, Fcons (Qdomain_error
, arith_tail
)));
3180 Fput (Qoverflow_error
, Qerror_message
,
3181 build_string ("Arithmetic overflow error"));
3183 Fput (Qunderflow_error
, Qerror_conditions
,
3184 Fcons (Qunderflow_error
, Fcons (Qdomain_error
, arith_tail
)));
3185 Fput (Qunderflow_error
, Qerror_message
,
3186 build_string ("Arithmetic underflow error"));
3188 staticpro (&Qrange_error
);
3189 staticpro (&Qdomain_error
);
3190 staticpro (&Qsingularity_error
);
3191 staticpro (&Qoverflow_error
);
3192 staticpro (&Qunderflow_error
);
3196 staticpro (&Qquote
);
3197 staticpro (&Qlambda
);
3199 staticpro (&Qunbound
);
3200 staticpro (&Qerror_conditions
);
3201 staticpro (&Qerror_message
);
3202 staticpro (&Qtop_level
);
3204 staticpro (&Qerror
);
3206 staticpro (&Qwrong_type_argument
);
3207 staticpro (&Qargs_out_of_range
);
3208 staticpro (&Qvoid_function
);
3209 staticpro (&Qcyclic_function_indirection
);
3210 staticpro (&Qcyclic_variable_indirection
);
3211 staticpro (&Qvoid_variable
);
3212 staticpro (&Qsetting_constant
);
3213 staticpro (&Qinvalid_read_syntax
);
3214 staticpro (&Qwrong_number_of_arguments
);
3215 staticpro (&Qinvalid_function
);
3216 staticpro (&Qno_catch
);
3217 staticpro (&Qend_of_file
);
3218 staticpro (&Qarith_error
);
3219 staticpro (&Qbeginning_of_buffer
);
3220 staticpro (&Qend_of_buffer
);
3221 staticpro (&Qbuffer_read_only
);
3222 staticpro (&Qtext_read_only
);
3223 staticpro (&Qmark_inactive
);
3225 staticpro (&Qlistp
);
3226 staticpro (&Qconsp
);
3227 staticpro (&Qsymbolp
);
3228 staticpro (&Qkeywordp
);
3229 staticpro (&Qintegerp
);
3230 staticpro (&Qnatnump
);
3231 staticpro (&Qwholenump
);
3232 staticpro (&Qstringp
);
3233 staticpro (&Qarrayp
);
3234 staticpro (&Qsequencep
);
3235 staticpro (&Qbufferp
);
3236 staticpro (&Qvectorp
);
3237 staticpro (&Qchar_or_string_p
);
3238 staticpro (&Qmarkerp
);
3239 staticpro (&Qbuffer_or_string_p
);
3240 staticpro (&Qinteger_or_marker_p
);
3241 staticpro (&Qfloatp
);
3242 staticpro (&Qnumberp
);
3243 staticpro (&Qnumber_or_marker_p
);
3244 staticpro (&Qchar_table_p
);
3245 staticpro (&Qvector_or_char_table_p
);
3246 staticpro (&Qsubrp
);
3248 staticpro (&Qunevalled
);
3250 staticpro (&Qboundp
);
3251 staticpro (&Qfboundp
);
3253 staticpro (&Qad_advice_info
);
3254 staticpro (&Qad_activate_internal
);
3256 /* Types that type-of returns. */
3257 Qinteger
= intern ("integer");
3258 Qsymbol
= intern ("symbol");
3259 Qstring
= intern ("string");
3260 Qcons
= intern ("cons");
3261 Qmarker
= intern ("marker");
3262 Qoverlay
= intern ("overlay");
3263 Qfloat
= intern ("float");
3264 Qwindow_configuration
= intern ("window-configuration");
3265 Qprocess
= intern ("process");
3266 Qwindow
= intern ("window");
3267 /* Qsubr = intern ("subr"); */
3268 Qcompiled_function
= intern ("compiled-function");
3269 Qbuffer
= intern ("buffer");
3270 Qframe
= intern ("frame");
3271 Qvector
= intern ("vector");
3272 Qchar_table
= intern ("char-table");
3273 Qbool_vector
= intern ("bool-vector");
3274 Qhash_table
= intern ("hash-table");
3276 staticpro (&Qinteger
);
3277 staticpro (&Qsymbol
);
3278 staticpro (&Qstring
);
3280 staticpro (&Qmarker
);
3281 staticpro (&Qoverlay
);
3282 staticpro (&Qfloat
);
3283 staticpro (&Qwindow_configuration
);
3284 staticpro (&Qprocess
);
3285 staticpro (&Qwindow
);
3286 /* staticpro (&Qsubr); */
3287 staticpro (&Qcompiled_function
);
3288 staticpro (&Qbuffer
);
3289 staticpro (&Qframe
);
3290 staticpro (&Qvector
);
3291 staticpro (&Qchar_table
);
3292 staticpro (&Qbool_vector
);
3293 staticpro (&Qhash_table
);
3295 defsubr (&Sindirect_variable
);
3296 defsubr (&Sinteractive_form
);
3299 defsubr (&Stype_of
);
3304 defsubr (&Sintegerp
);
3305 defsubr (&Sinteger_or_marker_p
);
3306 defsubr (&Snumberp
);
3307 defsubr (&Snumber_or_marker_p
);
3309 defsubr (&Snatnump
);
3310 defsubr (&Ssymbolp
);
3311 defsubr (&Skeywordp
);
3312 defsubr (&Sstringp
);
3313 defsubr (&Smultibyte_string_p
);
3314 defsubr (&Svectorp
);
3315 defsubr (&Schar_table_p
);
3316 defsubr (&Svector_or_char_table_p
);
3317 defsubr (&Sbool_vector_p
);
3319 defsubr (&Ssequencep
);
3320 defsubr (&Sbufferp
);
3321 defsubr (&Smarkerp
);
3323 defsubr (&Sbyte_code_function_p
);
3324 defsubr (&Schar_or_string_p
);
3327 defsubr (&Scar_safe
);
3328 defsubr (&Scdr_safe
);
3331 defsubr (&Ssymbol_function
);
3332 defsubr (&Sindirect_function
);
3333 defsubr (&Ssymbol_plist
);
3334 defsubr (&Ssymbol_name
);
3335 defsubr (&Smakunbound
);
3336 defsubr (&Sfmakunbound
);
3338 defsubr (&Sfboundp
);
3340 defsubr (&Sdefalias
);
3341 defsubr (&Ssetplist
);
3342 defsubr (&Ssymbol_value
);
3344 defsubr (&Sdefault_boundp
);
3345 defsubr (&Sdefault_value
);
3346 defsubr (&Sset_default
);
3347 defsubr (&Ssetq_default
);
3348 defsubr (&Smake_variable_buffer_local
);
3349 defsubr (&Smake_local_variable
);
3350 defsubr (&Skill_local_variable
);
3351 defsubr (&Smake_variable_frame_local
);
3352 defsubr (&Slocal_variable_p
);
3353 defsubr (&Slocal_variable_if_set_p
);
3354 defsubr (&Svariable_binding_locus
);
3357 defsubr (&Snumber_to_string
);
3358 defsubr (&Sstring_to_number
);
3359 defsubr (&Seqlsign
);
3382 defsubr (&Sbyteorder
);
3383 defsubr (&Ssubr_arity
);
3384 defsubr (&Ssubr_name
);
3386 XSYMBOL (Qwholenump
)->function
= XSYMBOL (Qnatnump
)->function
;
3388 DEFVAR_LISP ("most-positive-fixnum", &Vmost_positive_fixnum
,
3389 doc
: /* The largest value that is representable in a Lisp integer. */);
3390 Vmost_positive_fixnum
= make_number (MOST_POSITIVE_FIXNUM
);
3392 DEFVAR_LISP ("most-negative-fixnum", &Vmost_negative_fixnum
,
3393 doc
: /* The smallest value that is representable in a Lisp integer. */);
3394 Vmost_negative_fixnum
= make_number (MOST_NEGATIVE_FIXNUM
);
3401 #if defined(USG) && !defined(POSIX_SIGNALS)
3402 /* USG systems forget handlers when they are used;
3403 must reestablish each time */
3404 signal (signo
, arith_error
);
3407 /* VMS systems are like USG. */
3408 signal (signo
, arith_error
);
3412 #else /* not BSD4_1 */
3413 sigsetmask (SIGEMPTYMASK
);
3414 #endif /* not BSD4_1 */
3416 SIGNAL_THREAD_CHECK (signo
);
3417 Fsignal (Qarith_error
, Qnil
);
3423 /* Don't do this if just dumping out.
3424 We don't want to call `signal' in this case
3425 so that we don't have trouble with dumping
3426 signal-delivering routines in an inconsistent state. */
3430 #endif /* CANNOT_DUMP */
3431 signal (SIGFPE
, arith_error
);
3434 signal (SIGEMT
, arith_error
);
3438 /* arch-tag: 25879798-b84d-479a-9c89-7d148e2109f7
3439 (do not change this comment) */