1 /* Lisp parsing and input streams.
2 Copyright (C) 1985, 1986, 1987, 1988, 1989, 1993, 1994, 1995,
3 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
4 2005, 2006, 2007, 2008, 2009, 2010 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 of the License, or
11 (at your option) any later version.
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. If not, see <http://www.gnu.org/licenses/>. */
24 #include <sys/types.h>
30 #include "intervals.h"
32 #include "character.h"
39 #include "termhooks.h"
41 #include "blockinput.h"
55 #endif /* HAVE_SETLOCALE */
65 #define file_offset off_t
66 #define file_tell ftello
68 #define file_offset long
69 #define file_tell ftell
72 /* hash table read constants */
73 Lisp_Object Qhash_table
, Qdata
;
74 Lisp_Object Qtest
, Qsize
;
75 Lisp_Object Qweakness
;
76 Lisp_Object Qrehash_size
;
77 Lisp_Object Qrehash_threshold
;
78 extern Lisp_Object QCtest
, QCsize
, QCrehash_size
, QCrehash_threshold
, QCweakness
;
80 Lisp_Object Qread_char
, Qget_file_char
, Qstandard_input
, Qcurrent_load_list
;
81 Lisp_Object Qvariable_documentation
, Vvalues
, Vstandard_input
, Vafter_load_alist
;
82 Lisp_Object Qascii_character
, Qload
, Qload_file_name
;
83 Lisp_Object Qbackquote
, Qcomma
, Qcomma_at
, Qcomma_dot
, Qfunction
;
84 Lisp_Object Qinhibit_file_name_operation
;
85 Lisp_Object Qeval_buffer_list
, Veval_buffer_list
;
86 Lisp_Object Qfile_truename
, Qdo_after_load_evaluation
; /* ACM 2006/5/16 */
88 /* Used instead of Qget_file_char while loading *.elc files compiled
89 by Emacs 21 or older. */
90 static Lisp_Object Qget_emacs_mule_file_char
;
92 static Lisp_Object Qload_force_doc_strings
;
94 extern Lisp_Object Qevent_symbol_element_mask
;
95 extern Lisp_Object Qfile_exists_p
;
97 /* non-zero if inside `load' */
99 static Lisp_Object Qload_in_progress
;
101 /* Directory in which the sources were found. */
102 Lisp_Object Vsource_directory
;
104 /* Search path and suffixes for files to be loaded. */
105 Lisp_Object Vload_path
, Vload_suffixes
, Vload_file_rep_suffixes
;
107 /* File name of user's init file. */
108 Lisp_Object Vuser_init_file
;
110 /* This is the user-visible association list that maps features to
111 lists of defs in their load files. */
112 Lisp_Object Vload_history
;
114 /* This is used to build the load history. */
115 Lisp_Object Vcurrent_load_list
;
117 /* List of files that were preloaded. */
118 Lisp_Object Vpreloaded_file_list
;
120 /* Name of file actually being read by `load'. */
121 Lisp_Object Vload_file_name
;
123 /* Function to use for reading, in `load' and friends. */
124 Lisp_Object Vload_read_function
;
126 /* Non-nil means read recursive structures using #n= and #n# syntax. */
127 Lisp_Object Vread_circle
;
129 /* The association list of objects read with the #n=object form.
130 Each member of the list has the form (n . object), and is used to
131 look up the object for the corresponding #n# construct.
132 It must be set to nil before all top-level calls to read0. */
133 Lisp_Object read_objects
;
135 /* Nonzero means load should forcibly load all dynamic doc strings. */
136 static int load_force_doc_strings
;
138 /* Nonzero means read should convert strings to unibyte. */
139 static int load_convert_to_unibyte
;
141 /* Nonzero means READCHAR should read bytes one by one (not character)
142 when READCHARFUN is Qget_file_char or Qget_emacs_mule_file_char.
143 This is set to 1 by read1 temporarily while handling #@NUMBER. */
144 static int load_each_byte
;
146 /* Function to use for loading an Emacs Lisp source file (not
147 compiled) instead of readevalloop. */
148 Lisp_Object Vload_source_file_function
;
150 /* List of all DEFVAR_BOOL variables. Used by the byte optimizer. */
151 Lisp_Object Vbyte_boolean_vars
;
153 /* Whether or not to add a `read-positions' property to symbols
155 Lisp_Object Vread_with_symbol_positions
;
157 /* List of (SYMBOL . POSITION) accumulated so far. */
158 Lisp_Object Vread_symbol_positions_list
;
160 /* List of descriptors now open for Fload. */
161 static Lisp_Object load_descriptor_list
;
163 /* File for get_file_char to read from. Use by load. */
164 static FILE *instream
;
166 /* When nonzero, read conses in pure space */
167 static int read_pure
;
169 /* For use within read-from-string (this reader is non-reentrant!!) */
170 static int read_from_string_index
;
171 static int read_from_string_index_byte
;
172 static int read_from_string_limit
;
174 /* Number of characters read in the current call to Fread or
175 Fread_from_string. */
176 static int readchar_count
;
178 /* This contains the last string skipped with #@. */
179 static char *saved_doc_string
;
180 /* Length of buffer allocated in saved_doc_string. */
181 static int saved_doc_string_size
;
182 /* Length of actual data in saved_doc_string. */
183 static int saved_doc_string_length
;
184 /* This is the file position that string came from. */
185 static file_offset saved_doc_string_position
;
187 /* This contains the previous string skipped with #@.
188 We copy it from saved_doc_string when a new string
189 is put in saved_doc_string. */
190 static char *prev_saved_doc_string
;
191 /* Length of buffer allocated in prev_saved_doc_string. */
192 static int prev_saved_doc_string_size
;
193 /* Length of actual data in prev_saved_doc_string. */
194 static int prev_saved_doc_string_length
;
195 /* This is the file position that string came from. */
196 static file_offset prev_saved_doc_string_position
;
198 /* Nonzero means inside a new-style backquote
199 with no surrounding parentheses.
200 Fread initializes this to zero, so we need not specbind it
201 or worry about what happens to it when there is an error. */
202 static int new_backquote_flag
;
203 static Lisp_Object Vold_style_backquotes
, Qold_style_backquotes
;
205 /* A list of file names for files being loaded in Fload. Used to
206 check for recursive loads. */
208 static Lisp_Object Vloads_in_progress
;
210 /* Non-zero means load dangerous compiled Lisp files. */
212 int load_dangerous_libraries
;
214 /* Non-zero means force printing messages when loading Lisp files. */
216 int force_load_messages
;
218 /* A regular expression used to detect files compiled with Emacs. */
220 static Lisp_Object Vbytecomp_version_regexp
;
222 static int read_emacs_mule_char (int, int (*) (int, Lisp_Object
),
225 static void readevalloop (Lisp_Object
, FILE*, Lisp_Object
,
226 Lisp_Object (*) (Lisp_Object
), int,
227 Lisp_Object
, Lisp_Object
,
228 Lisp_Object
, Lisp_Object
);
229 static Lisp_Object
load_unwind (Lisp_Object
);
230 static Lisp_Object
load_descriptor_unwind (Lisp_Object
);
232 static void invalid_syntax (const char *, int) NO_RETURN
;
233 static void end_of_file_error (void) NO_RETURN
;
236 /* Functions that read one byte from the current source READCHARFUN
237 or unreads one byte. If the integer argument C is -1, it returns
238 one read byte, or -1 when there's no more byte in the source. If C
239 is 0 or positive, it unreads C, and the return value is not
242 static int readbyte_for_lambda (int, Lisp_Object
);
243 static int readbyte_from_file (int, Lisp_Object
);
244 static int readbyte_from_string (int, Lisp_Object
);
246 /* Handle unreading and rereading of characters.
247 Write READCHAR to read a character,
248 UNREAD(c) to unread c to be read again.
250 These macros correctly read/unread multibyte characters. */
252 #define READCHAR readchar (readcharfun, NULL)
253 #define UNREAD(c) unreadchar (readcharfun, c)
255 /* Same as READCHAR but set *MULTIBYTE to the multibyteness of the source. */
256 #define READCHAR_REPORT_MULTIBYTE(multibyte) readchar (readcharfun, multibyte)
258 /* When READCHARFUN is Qget_file_char, Qget_emacs_mule_file_char,
259 Qlambda, or a cons, we use this to keep an unread character because
260 a file stream can't handle multibyte-char unreading. The value -1
261 means that there's no unread character. */
262 static int unread_char
;
265 readchar (Lisp_Object readcharfun
, int *multibyte
)
269 int (*readbyte
) (int, Lisp_Object
);
270 unsigned char buf
[MAX_MULTIBYTE_LENGTH
];
272 int emacs_mule_encoding
= 0;
279 if (BUFFERP (readcharfun
))
281 register struct buffer
*inbuffer
= XBUFFER (readcharfun
);
283 int pt_byte
= BUF_PT_BYTE (inbuffer
);
285 if (pt_byte
>= BUF_ZV_BYTE (inbuffer
))
288 if (! NILP (inbuffer
->enable_multibyte_characters
))
290 /* Fetch the character code from the buffer. */
291 unsigned char *p
= BUF_BYTE_ADDRESS (inbuffer
, pt_byte
);
292 BUF_INC_POS (inbuffer
, pt_byte
);
299 c
= BUF_FETCH_BYTE (inbuffer
, pt_byte
);
300 if (! ASCII_BYTE_P (c
))
301 c
= BYTE8_TO_CHAR (c
);
304 SET_BUF_PT_BOTH (inbuffer
, BUF_PT (inbuffer
) + 1, pt_byte
);
308 if (MARKERP (readcharfun
))
310 register struct buffer
*inbuffer
= XMARKER (readcharfun
)->buffer
;
312 int bytepos
= marker_byte_position (readcharfun
);
314 if (bytepos
>= BUF_ZV_BYTE (inbuffer
))
317 if (! NILP (inbuffer
->enable_multibyte_characters
))
319 /* Fetch the character code from the buffer. */
320 unsigned char *p
= BUF_BYTE_ADDRESS (inbuffer
, bytepos
);
321 BUF_INC_POS (inbuffer
, bytepos
);
328 c
= BUF_FETCH_BYTE (inbuffer
, bytepos
);
329 if (! ASCII_BYTE_P (c
))
330 c
= BYTE8_TO_CHAR (c
);
334 XMARKER (readcharfun
)->bytepos
= bytepos
;
335 XMARKER (readcharfun
)->charpos
++;
340 if (EQ (readcharfun
, Qlambda
))
342 readbyte
= readbyte_for_lambda
;
346 if (EQ (readcharfun
, Qget_file_char
))
348 readbyte
= readbyte_from_file
;
352 if (STRINGP (readcharfun
))
354 if (read_from_string_index
>= read_from_string_limit
)
356 else if (STRING_MULTIBYTE (readcharfun
))
360 FETCH_STRING_CHAR_ADVANCE_NO_CHECK (c
, readcharfun
,
361 read_from_string_index
,
362 read_from_string_index_byte
);
366 c
= SREF (readcharfun
, read_from_string_index_byte
);
367 read_from_string_index
++;
368 read_from_string_index_byte
++;
373 if (CONSP (readcharfun
))
375 /* This is the case that read_vector is reading from a unibyte
376 string that contains a byte sequence previously skipped
377 because of #@NUMBER. The car part of readcharfun is that
378 string, and the cdr part is a value of readcharfun given to
380 readbyte
= readbyte_from_string
;
381 if (EQ (XCDR (readcharfun
), Qget_emacs_mule_file_char
))
382 emacs_mule_encoding
= 1;
386 if (EQ (readcharfun
, Qget_emacs_mule_file_char
))
388 readbyte
= readbyte_from_file
;
389 emacs_mule_encoding
= 1;
393 tem
= call0 (readcharfun
);
400 if (unread_char
>= 0)
406 c
= (*readbyte
) (-1, readcharfun
);
407 if (c
< 0 || load_each_byte
)
411 if (ASCII_BYTE_P (c
))
413 if (emacs_mule_encoding
)
414 return read_emacs_mule_char (c
, readbyte
, readcharfun
);
417 len
= BYTES_BY_CHAR_HEAD (c
);
420 c
= (*readbyte
) (-1, readcharfun
);
421 if (c
< 0 || ! TRAILING_CODE_P (c
))
424 (*readbyte
) (buf
[i
], readcharfun
);
425 return BYTE8_TO_CHAR (buf
[0]);
429 return STRING_CHAR (buf
);
432 /* Unread the character C in the way appropriate for the stream READCHARFUN.
433 If the stream is a user function, call it with the char as argument. */
436 unreadchar (Lisp_Object readcharfun
, int c
)
440 /* Don't back up the pointer if we're unreading the end-of-input mark,
441 since readchar didn't advance it when we read it. */
443 else if (BUFFERP (readcharfun
))
445 struct buffer
*b
= XBUFFER (readcharfun
);
446 int bytepos
= BUF_PT_BYTE (b
);
449 if (! NILP (b
->enable_multibyte_characters
))
450 BUF_DEC_POS (b
, bytepos
);
454 BUF_PT_BYTE (b
) = bytepos
;
456 else if (MARKERP (readcharfun
))
458 struct buffer
*b
= XMARKER (readcharfun
)->buffer
;
459 int bytepos
= XMARKER (readcharfun
)->bytepos
;
461 XMARKER (readcharfun
)->charpos
--;
462 if (! NILP (b
->enable_multibyte_characters
))
463 BUF_DEC_POS (b
, bytepos
);
467 XMARKER (readcharfun
)->bytepos
= bytepos
;
469 else if (STRINGP (readcharfun
))
471 read_from_string_index
--;
472 read_from_string_index_byte
473 = string_char_to_byte (readcharfun
, read_from_string_index
);
475 else if (CONSP (readcharfun
))
479 else if (EQ (readcharfun
, Qlambda
))
483 else if (EQ (readcharfun
, Qget_file_char
)
484 || EQ (readcharfun
, Qget_emacs_mule_file_char
))
489 ungetc (c
, instream
);
496 call1 (readcharfun
, make_number (c
));
500 readbyte_for_lambda (int c
, Lisp_Object readcharfun
)
502 return read_bytecode_char (c
>= 0);
507 readbyte_from_file (int c
, Lisp_Object readcharfun
)
512 ungetc (c
, instream
);
521 /* Interrupted reads have been observed while reading over the network */
522 while (c
== EOF
&& ferror (instream
) && errno
== EINTR
)
534 return (c
== EOF
? -1 : c
);
538 readbyte_from_string (int c
, Lisp_Object readcharfun
)
540 Lisp_Object string
= XCAR (readcharfun
);
544 read_from_string_index
--;
545 read_from_string_index_byte
546 = string_char_to_byte (string
, read_from_string_index
);
549 if (read_from_string_index
>= read_from_string_limit
)
552 FETCH_STRING_CHAR_ADVANCE (c
, string
,
553 read_from_string_index
,
554 read_from_string_index_byte
);
559 /* Read one non-ASCII character from INSTREAM. The character is
560 encoded in `emacs-mule' and the first byte is already read in
563 extern char emacs_mule_bytes
[256];
566 read_emacs_mule_char (int c
, int (*readbyte
) (int, Lisp_Object
), Lisp_Object readcharfun
)
568 /* Emacs-mule coding uses at most 4-byte for one character. */
569 unsigned char buf
[4];
570 int len
= emacs_mule_bytes
[c
];
571 struct charset
*charset
;
576 /* C is not a valid leading-code of `emacs-mule'. */
577 return BYTE8_TO_CHAR (c
);
583 c
= (*readbyte
) (-1, readcharfun
);
587 (*readbyte
) (buf
[i
], readcharfun
);
588 return BYTE8_TO_CHAR (buf
[0]);
595 charset
= emacs_mule_charset
[buf
[0]];
596 code
= buf
[1] & 0x7F;
600 if (buf
[0] == EMACS_MULE_LEADING_CODE_PRIVATE_11
601 || buf
[0] == EMACS_MULE_LEADING_CODE_PRIVATE_12
)
603 charset
= emacs_mule_charset
[buf
[1]];
604 code
= buf
[2] & 0x7F;
608 charset
= emacs_mule_charset
[buf
[0]];
609 code
= ((buf
[1] << 8) | buf
[2]) & 0x7F7F;
614 charset
= emacs_mule_charset
[buf
[1]];
615 code
= ((buf
[2] << 8) | buf
[3]) & 0x7F7F;
617 c
= DECODE_CHAR (charset
, code
);
619 Fsignal (Qinvalid_read_syntax
,
620 Fcons (build_string ("invalid multibyte form"), Qnil
));
625 static Lisp_Object
read_internal_start (Lisp_Object
, Lisp_Object
,
627 static Lisp_Object
read0 (Lisp_Object
);
628 static Lisp_Object
read1 (Lisp_Object
, int *, int);
630 static Lisp_Object
read_list (int, Lisp_Object
);
631 static Lisp_Object
read_vector (Lisp_Object
, int);
633 static Lisp_Object
substitute_object_recurse (Lisp_Object
, Lisp_Object
,
635 static void substitute_object_in_subtree (Lisp_Object
,
637 static void substitute_in_interval (INTERVAL
, Lisp_Object
);
640 /* Get a character from the tty. */
642 /* Read input events until we get one that's acceptable for our purposes.
644 If NO_SWITCH_FRAME is non-zero, switch-frame events are stashed
645 until we get a character we like, and then stuffed into
648 If ASCII_REQUIRED is non-zero, we check function key events to see
649 if the unmodified version of the symbol has a Qascii_character
650 property, and use that character, if present.
652 If ERROR_NONASCII is non-zero, we signal an error if the input we
653 get isn't an ASCII character with modifiers. If it's zero but
654 ASCII_REQUIRED is non-zero, we just re-read until we get an ASCII
657 If INPUT_METHOD is nonzero, we invoke the current input method
658 if the character warrants that.
660 If SECONDS is a number, we wait that many seconds for input, and
661 return Qnil if no input arrives within that time. */
664 read_filtered_event (no_switch_frame
, ascii_required
, error_nonascii
,
665 input_method
, seconds
)
666 int no_switch_frame
, ascii_required
, error_nonascii
, input_method
;
669 Lisp_Object val
, delayed_switch_frame
;
672 #ifdef HAVE_WINDOW_SYSTEM
673 if (display_hourglass_p
)
677 delayed_switch_frame
= Qnil
;
679 /* Compute timeout. */
680 if (NUMBERP (seconds
))
682 EMACS_TIME wait_time
;
684 double duration
= extract_float (seconds
);
686 sec
= (int) duration
;
687 usec
= (duration
- sec
) * 1000000;
688 EMACS_GET_TIME (end_time
);
689 EMACS_SET_SECS_USECS (wait_time
, sec
, usec
);
690 EMACS_ADD_TIME (end_time
, end_time
, wait_time
);
693 /* Read until we get an acceptable event. */
696 val
= read_char (0, 0, 0, (input_method
? Qnil
: Qt
), 0,
697 NUMBERP (seconds
) ? &end_time
: NULL
);
698 while (INTEGERP (val
) && XINT (val
) == -2); /* wrong_kboard_jmpbuf */
703 /* switch-frame events are put off until after the next ASCII
704 character. This is better than signaling an error just because
705 the last characters were typed to a separate minibuffer frame,
706 for example. Eventually, some code which can deal with
707 switch-frame events will read it and process it. */
709 && EVENT_HAS_PARAMETERS (val
)
710 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (val
)), Qswitch_frame
))
712 delayed_switch_frame
= val
;
716 if (ascii_required
&& !(NUMBERP (seconds
) && NILP (val
)))
718 /* Convert certain symbols to their ASCII equivalents. */
721 Lisp_Object tem
, tem1
;
722 tem
= Fget (val
, Qevent_symbol_element_mask
);
725 tem1
= Fget (Fcar (tem
), Qascii_character
);
726 /* Merge this symbol's modifier bits
727 with the ASCII equivalent of its basic code. */
729 XSETFASTINT (val
, XINT (tem1
) | XINT (Fcar (Fcdr (tem
))));
733 /* If we don't have a character now, deal with it appropriately. */
738 Vunread_command_events
= Fcons (val
, Qnil
);
739 error ("Non-character input-event");
746 if (! NILP (delayed_switch_frame
))
747 unread_switch_frame
= delayed_switch_frame
;
751 #ifdef HAVE_WINDOW_SYSTEM
752 if (display_hourglass_p
)
761 DEFUN ("read-char", Fread_char
, Sread_char
, 0, 3, 0,
762 doc
: /* Read a character from the command input (keyboard or macro).
763 It is returned as a number.
764 If the character has modifiers, they are resolved and reflected to the
765 character code if possible (e.g. C-SPC -> 0).
767 If the user generates an event which is not a character (i.e. a mouse
768 click or function key event), `read-char' signals an error. As an
769 exception, switch-frame events are put off until non-character events
771 If you want to read non-character events, or ignore them, call
772 `read-event' or `read-char-exclusive' instead.
774 If the optional argument PROMPT is non-nil, display that as a prompt.
775 If the optional argument INHERIT-INPUT-METHOD is non-nil and some
776 input method is turned on in the current buffer, that input method
777 is used for reading a character.
778 If the optional argument SECONDS is non-nil, it should be a number
779 specifying the maximum number of seconds to wait for input. If no
780 input arrives in that time, return nil. SECONDS may be a
781 floating-point value. */)
782 (Lisp_Object prompt
, Lisp_Object inherit_input_method
, Lisp_Object seconds
)
787 message_with_string ("%s", prompt
, 0);
788 val
= read_filtered_event (1, 1, 1, ! NILP (inherit_input_method
), seconds
);
790 return (NILP (val
) ? Qnil
791 : make_number (char_resolve_modifier_mask (XINT (val
))));
794 DEFUN ("read-event", Fread_event
, Sread_event
, 0, 3, 0,
795 doc
: /* Read an event object from the input stream.
796 If the optional argument PROMPT is non-nil, display that as a prompt.
797 If the optional argument INHERIT-INPUT-METHOD is non-nil and some
798 input method is turned on in the current buffer, that input method
799 is used for reading a character.
800 If the optional argument SECONDS is non-nil, it should be a number
801 specifying the maximum number of seconds to wait for input. If no
802 input arrives in that time, return nil. SECONDS may be a
803 floating-point value. */)
804 (Lisp_Object prompt
, Lisp_Object inherit_input_method
, Lisp_Object seconds
)
807 message_with_string ("%s", prompt
, 0);
808 return read_filtered_event (0, 0, 0, ! NILP (inherit_input_method
), seconds
);
811 DEFUN ("read-char-exclusive", Fread_char_exclusive
, Sread_char_exclusive
, 0, 3, 0,
812 doc
: /* Read a character from the command input (keyboard or macro).
813 It is returned as a number. Non-character events are ignored.
814 If the character has modifiers, they are resolved and reflected to the
815 character code if possible (e.g. C-SPC -> 0).
817 If the optional argument PROMPT is non-nil, display that as a prompt.
818 If the optional argument INHERIT-INPUT-METHOD is non-nil and some
819 input method is turned on in the current buffer, that input method
820 is used for reading a character.
821 If the optional argument SECONDS is non-nil, it should be a number
822 specifying the maximum number of seconds to wait for input. If no
823 input arrives in that time, return nil. SECONDS may be a
824 floating-point value. */)
825 (Lisp_Object prompt
, Lisp_Object inherit_input_method
, Lisp_Object seconds
)
830 message_with_string ("%s", prompt
, 0);
832 val
= read_filtered_event (1, 1, 0, ! NILP (inherit_input_method
), seconds
);
834 return (NILP (val
) ? Qnil
835 : make_number (char_resolve_modifier_mask (XINT (val
))));
838 DEFUN ("get-file-char", Fget_file_char
, Sget_file_char
, 0, 0, 0,
839 doc
: /* Don't use this yourself. */)
842 register Lisp_Object val
;
844 XSETINT (val
, getc (instream
));
851 /* Value is a version number of byte compiled code if the file
852 associated with file descriptor FD is a compiled Lisp file that's
853 safe to load. Only files compiled with Emacs are safe to load.
854 Files compiled with XEmacs can lead to a crash in Fbyte_code
855 because of an incompatible change in the byte compiler. */
858 safe_to_load_p (int fd
)
865 /* Read the first few bytes from the file, and look for a line
866 specifying the byte compiler version used. */
867 nbytes
= emacs_read (fd
, buf
, sizeof buf
- 1);
872 /* Skip to the next newline, skipping over the initial `ELC'
873 with NUL bytes following it, but note the version. */
874 for (i
= 0; i
< nbytes
&& buf
[i
] != '\n'; ++i
)
879 || fast_c_string_match_ignore_case (Vbytecomp_version_regexp
,
886 lseek (fd
, 0, SEEK_SET
);
891 /* Callback for record_unwind_protect. Restore the old load list OLD,
892 after loading a file successfully. */
895 record_load_unwind (Lisp_Object old
)
897 return Vloads_in_progress
= old
;
900 /* This handler function is used via internal_condition_case_1. */
903 load_error_handler (Lisp_Object data
)
909 load_warn_old_style_backquotes (Lisp_Object file
)
911 if (!NILP (Vold_style_backquotes
))
914 args
[0] = build_string ("Loading `%s': old-style backquotes detected!");
921 DEFUN ("get-load-suffixes", Fget_load_suffixes
, Sget_load_suffixes
, 0, 0, 0,
922 doc
: /* Return the suffixes that `load' should try if a suffix is \
924 This uses the variables `load-suffixes' and `load-file-rep-suffixes'. */)
927 Lisp_Object lst
= Qnil
, suffixes
= Vload_suffixes
, suffix
, ext
;
928 while (CONSP (suffixes
))
930 Lisp_Object exts
= Vload_file_rep_suffixes
;
931 suffix
= XCAR (suffixes
);
932 suffixes
= XCDR (suffixes
);
937 lst
= Fcons (concat2 (suffix
, ext
), lst
);
940 return Fnreverse (lst
);
943 DEFUN ("load", Fload
, Sload
, 1, 5, 0,
944 doc
: /* Execute a file of Lisp code named FILE.
945 First try FILE with `.elc' appended, then try with `.el',
946 then try FILE unmodified (the exact suffixes in the exact order are
947 determined by `load-suffixes'). Environment variable references in
948 FILE are replaced with their values by calling `substitute-in-file-name'.
949 This function searches the directories in `load-path'.
951 If optional second arg NOERROR is non-nil,
952 report no error if FILE doesn't exist.
953 Print messages at start and end of loading unless
954 optional third arg NOMESSAGE is non-nil (but `force-load-messages'
956 If optional fourth arg NOSUFFIX is non-nil, don't try adding
957 suffixes `.elc' or `.el' to the specified name FILE.
958 If optional fifth arg MUST-SUFFIX is non-nil, insist on
959 the suffix `.elc' or `.el'; don't accept just FILE unless
960 it ends in one of those suffixes or includes a directory name.
962 If this function fails to find a file, it may look for different
963 representations of that file before trying another file.
964 It does so by adding the non-empty suffixes in `load-file-rep-suffixes'
965 to the file name. Emacs uses this feature mainly to find compressed
966 versions of files when Auto Compression mode is enabled.
968 The exact suffixes that this function tries out, in the exact order,
969 are given by the value of the variable `load-file-rep-suffixes' if
970 NOSUFFIX is non-nil and by the return value of the function
971 `get-load-suffixes' if MUST-SUFFIX is non-nil. If both NOSUFFIX and
972 MUST-SUFFIX are nil, this function first tries out the latter suffixes
975 Loading a file records its definitions, and its `provide' and
976 `require' calls, in an element of `load-history' whose
977 car is the file name loaded. See `load-history'.
979 Return t if the file exists and loads successfully. */)
980 (Lisp_Object file
, Lisp_Object noerror
, Lisp_Object nomessage
, Lisp_Object nosuffix
, Lisp_Object must_suffix
)
982 register FILE *stream
;
983 register int fd
= -1;
984 int count
= SPECPDL_INDEX ();
985 struct gcpro gcpro1
, gcpro2
, gcpro3
;
986 Lisp_Object found
, efound
, hist_file_name
;
987 /* 1 means we printed the ".el is newer" message. */
989 /* 1 means we are loading a compiled file. */
1001 CHECK_STRING (file
);
1003 /* If file name is magic, call the handler. */
1004 /* This shouldn't be necessary any more now that `openp' handles it right.
1005 handler = Ffind_file_name_handler (file, Qload);
1006 if (!NILP (handler))
1007 return call5 (handler, Qload, file, noerror, nomessage, nosuffix); */
1009 /* Do this after the handler to avoid
1010 the need to gcpro noerror, nomessage and nosuffix.
1011 (Below here, we care only whether they are nil or not.)
1012 The presence of this call is the result of a historical accident:
1013 it used to be in every file-operation and when it got removed
1014 everywhere, it accidentally stayed here. Since then, enough people
1015 supposedly have things like (load "$PROJECT/foo.el") in their .emacs
1016 that it seemed risky to remove. */
1017 if (! NILP (noerror
))
1019 file
= internal_condition_case_1 (Fsubstitute_in_file_name
, file
,
1020 Qt
, load_error_handler
);
1025 file
= Fsubstitute_in_file_name (file
);
1028 /* Avoid weird lossage with null string as arg,
1029 since it would try to load a directory as a Lisp file */
1030 if (SCHARS (file
) > 0)
1032 int size
= SBYTES (file
);
1035 GCPRO2 (file
, found
);
1037 if (! NILP (must_suffix
))
1039 /* Don't insist on adding a suffix if FILE already ends with one. */
1041 && !strcmp (SDATA (file
) + size
- 3, ".el"))
1044 && !strcmp (SDATA (file
) + size
- 4, ".elc"))
1046 /* Don't insist on adding a suffix
1047 if the argument includes a directory name. */
1048 else if (! NILP (Ffile_name_directory (file
)))
1052 fd
= openp (Vload_path
, file
,
1053 (!NILP (nosuffix
) ? Qnil
1054 : !NILP (must_suffix
) ? Fget_load_suffixes ()
1055 : Fappend (2, (tmp
[0] = Fget_load_suffixes (),
1056 tmp
[1] = Vload_file_rep_suffixes
,
1065 xsignal2 (Qfile_error
, build_string ("Cannot open load file"), file
);
1069 /* Tell startup.el whether or not we found the user's init file. */
1070 if (EQ (Qt
, Vuser_init_file
))
1071 Vuser_init_file
= found
;
1073 /* If FD is -2, that means openp found a magic file. */
1076 if (NILP (Fequal (found
, file
)))
1077 /* If FOUND is a different file name from FILE,
1078 find its handler even if we have already inhibited
1079 the `load' operation on FILE. */
1080 handler
= Ffind_file_name_handler (found
, Qt
);
1082 handler
= Ffind_file_name_handler (found
, Qload
);
1083 if (! NILP (handler
))
1084 return call5 (handler
, Qload
, found
, noerror
, nomessage
, Qt
);
1087 /* Check if we're stuck in a recursive load cycle.
1089 2000-09-21: It's not possible to just check for the file loaded
1090 being a member of Vloads_in_progress. This fails because of the
1091 way the byte compiler currently works; `provide's are not
1092 evaluated, see font-lock.el/jit-lock.el as an example. This
1093 leads to a certain amount of ``normal'' recursion.
1095 Also, just loading a file recursively is not always an error in
1096 the general case; the second load may do something different. */
1100 for (tem
= Vloads_in_progress
; CONSP (tem
); tem
= XCDR (tem
))
1101 if (!NILP (Fequal (found
, XCAR (tem
))) && (++count
> 3))
1105 signal_error ("Recursive load", Fcons (found
, Vloads_in_progress
));
1107 record_unwind_protect (record_load_unwind
, Vloads_in_progress
);
1108 Vloads_in_progress
= Fcons (found
, Vloads_in_progress
);
1111 /* Get the name for load-history. */
1112 hist_file_name
= (! NILP (Vpurify_flag
)
1113 ? Fconcat (2, (tmp
[0] = Ffile_name_directory (file
),
1114 tmp
[1] = Ffile_name_nondirectory (found
),
1120 /* Check for the presence of old-style quotes and warn about them. */
1121 specbind (Qold_style_backquotes
, Qnil
);
1122 record_unwind_protect (load_warn_old_style_backquotes
, file
);
1124 if (!memcmp (SDATA (found
) + SBYTES (found
) - 4, ".elc", 4)
1125 || (fd
>= 0 && (version
= safe_to_load_p (fd
)) > 0))
1126 /* Load .elc files directly, but not when they are
1127 remote and have no handler! */
1134 GCPRO3 (file
, found
, hist_file_name
);
1137 && ! (version
= safe_to_load_p (fd
)))
1140 if (!load_dangerous_libraries
)
1144 error ("File `%s' was not compiled in Emacs",
1147 else if (!NILP (nomessage
) && !force_load_messages
)
1148 message_with_string ("File `%s' not compiled in Emacs", found
, 1);
1153 efound
= ENCODE_FILE (found
);
1158 stat ((char *)SDATA (efound
), &s1
);
1159 SSET (efound
, SBYTES (efound
) - 1, 0);
1160 result
= stat ((char *)SDATA (efound
), &s2
);
1161 SSET (efound
, SBYTES (efound
) - 1, 'c');
1163 if (result
>= 0 && (unsigned) s1
.st_mtime
< (unsigned) s2
.st_mtime
)
1165 /* Make the progress messages mention that source is newer. */
1168 /* If we won't print another message, mention this anyway. */
1169 if (!NILP (nomessage
) && !force_load_messages
)
1171 Lisp_Object msg_file
;
1172 msg_file
= Fsubstring (found
, make_number (0), make_number (-1));
1173 message_with_string ("Source file `%s' newer than byte-compiled file",
1182 /* We are loading a source file (*.el). */
1183 if (!NILP (Vload_source_file_function
))
1189 val
= call4 (Vload_source_file_function
, found
, hist_file_name
,
1190 NILP (noerror
) ? Qnil
: Qt
,
1191 (NILP (nomessage
) || force_load_messages
) ? Qnil
: Qt
);
1192 return unbind_to (count
, val
);
1196 GCPRO3 (file
, found
, hist_file_name
);
1200 efound
= ENCODE_FILE (found
);
1201 stream
= fopen ((char *) SDATA (efound
), fmode
);
1202 #else /* not WINDOWSNT */
1203 stream
= fdopen (fd
, fmode
);
1204 #endif /* not WINDOWSNT */
1208 error ("Failure to create stdio stream for %s", SDATA (file
));
1211 if (! NILP (Vpurify_flag
))
1212 Vpreloaded_file_list
= Fcons (Fpurecopy(file
), Vpreloaded_file_list
);
1214 if (NILP (nomessage
) || force_load_messages
)
1217 message_with_string ("Loading %s (compiled; note unsafe, not compiled in Emacs)...",
1220 message_with_string ("Loading %s (source)...", file
, 1);
1222 message_with_string ("Loading %s (compiled; note, source file is newer)...",
1224 else /* The typical case; compiled file newer than source file. */
1225 message_with_string ("Loading %s...", file
, 1);
1228 record_unwind_protect (load_unwind
, make_save_value (stream
, 0));
1229 record_unwind_protect (load_descriptor_unwind
, load_descriptor_list
);
1230 specbind (Qload_file_name
, found
);
1231 specbind (Qinhibit_file_name_operation
, Qnil
);
1232 load_descriptor_list
1233 = Fcons (make_number (fileno (stream
)), load_descriptor_list
);
1234 specbind (Qload_in_progress
, Qt
);
1235 if (! version
|| version
>= 22)
1236 readevalloop (Qget_file_char
, stream
, hist_file_name
,
1237 Feval
, 0, Qnil
, Qnil
, Qnil
, Qnil
);
1240 /* We can't handle a file which was compiled with
1241 byte-compile-dynamic by older version of Emacs. */
1242 specbind (Qload_force_doc_strings
, Qt
);
1243 readevalloop (Qget_emacs_mule_file_char
, stream
, hist_file_name
, Feval
,
1244 0, Qnil
, Qnil
, Qnil
, Qnil
);
1246 unbind_to (count
, Qnil
);
1248 /* Run any eval-after-load forms for this file */
1249 if (!NILP (Ffboundp (Qdo_after_load_evaluation
)))
1250 call1 (Qdo_after_load_evaluation
, hist_file_name
) ;
1254 xfree (saved_doc_string
);
1255 saved_doc_string
= 0;
1256 saved_doc_string_size
= 0;
1258 xfree (prev_saved_doc_string
);
1259 prev_saved_doc_string
= 0;
1260 prev_saved_doc_string_size
= 0;
1262 if (!noninteractive
&& (NILP (nomessage
) || force_load_messages
))
1265 message_with_string ("Loading %s (compiled; note unsafe, not compiled in Emacs)...done",
1268 message_with_string ("Loading %s (source)...done", file
, 1);
1270 message_with_string ("Loading %s (compiled; note, source file is newer)...done",
1272 else /* The typical case; compiled file newer than source file. */
1273 message_with_string ("Loading %s...done", file
, 1);
1280 load_unwind (Lisp_Object arg
) /* used as unwind-protect function in load */
1283 FILE *stream
= (FILE *) XSAVE_VALUE (arg
)->pointer
;
1294 load_descriptor_unwind (Lisp_Object oldlist
)
1296 load_descriptor_list
= oldlist
;
1300 /* Close all descriptors in use for Floads.
1301 This is used when starting a subprocess. */
1304 close_load_descs (void)
1308 for (tail
= load_descriptor_list
; CONSP (tail
); tail
= XCDR (tail
))
1309 emacs_close (XFASTINT (XCAR (tail
)));
1314 complete_filename_p (Lisp_Object pathname
)
1316 register const unsigned char *s
= SDATA (pathname
);
1317 return (IS_DIRECTORY_SEP (s
[0])
1318 || (SCHARS (pathname
) > 2
1319 && IS_DEVICE_SEP (s
[1]) && IS_DIRECTORY_SEP (s
[2])));
1322 DEFUN ("locate-file-internal", Flocate_file_internal
, Slocate_file_internal
, 2, 4, 0,
1323 doc
: /* Search for FILENAME through PATH.
1324 Returns the file's name in absolute form, or nil if not found.
1325 If SUFFIXES is non-nil, it should be a list of suffixes to append to
1326 file name when searching.
1327 If non-nil, PREDICATE is used instead of `file-readable-p'.
1328 PREDICATE can also be an integer to pass to the access(2) function,
1329 in which case file-name-handlers are ignored. */)
1330 (Lisp_Object filename
, Lisp_Object path
, Lisp_Object suffixes
, Lisp_Object predicate
)
1333 int fd
= openp (path
, filename
, suffixes
, &file
, predicate
);
1334 if (NILP (predicate
) && fd
> 0)
1340 /* Search for a file whose name is STR, looking in directories
1341 in the Lisp list PATH, and trying suffixes from SUFFIX.
1342 On success, returns a file descriptor. On failure, returns -1.
1344 SUFFIXES is a list of strings containing possible suffixes.
1345 The empty suffix is automatically added if the list is empty.
1347 PREDICATE non-nil means don't open the files,
1348 just look for one that satisfies the predicate. In this case,
1349 returns 1 on success. The predicate can be a lisp function or
1350 an integer to pass to `access' (in which case file-name-handlers
1353 If STOREPTR is nonzero, it points to a slot where the name of
1354 the file actually found should be stored as a Lisp string.
1355 nil is stored there on failure.
1357 If the file we find is remote, return -2
1358 but store the found remote file name in *STOREPTR. */
1361 openp (Lisp_Object path
, Lisp_Object str
, Lisp_Object suffixes
, Lisp_Object
*storeptr
, Lisp_Object predicate
)
1366 register char *fn
= buf
;
1369 Lisp_Object filename
;
1371 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
, gcpro5
, gcpro6
;
1372 Lisp_Object string
, tail
, encoded_fn
;
1373 int max_suffix_len
= 0;
1377 for (tail
= suffixes
; CONSP (tail
); tail
= XCDR (tail
))
1379 CHECK_STRING_CAR (tail
);
1380 max_suffix_len
= max (max_suffix_len
,
1381 SBYTES (XCAR (tail
)));
1384 string
= filename
= encoded_fn
= Qnil
;
1385 GCPRO6 (str
, string
, filename
, path
, suffixes
, encoded_fn
);
1390 if (complete_filename_p (str
))
1393 for (; CONSP (path
); path
= XCDR (path
))
1395 filename
= Fexpand_file_name (str
, XCAR (path
));
1396 if (!complete_filename_p (filename
))
1397 /* If there are non-absolute elts in PATH (eg ".") */
1398 /* Of course, this could conceivably lose if luser sets
1399 default-directory to be something non-absolute... */
1401 filename
= Fexpand_file_name (filename
, current_buffer
->directory
);
1402 if (!complete_filename_p (filename
))
1403 /* Give up on this path element! */
1407 /* Calculate maximum size of any filename made from
1408 this path element/specified file name and any possible suffix. */
1409 want_size
= max_suffix_len
+ SBYTES (filename
) + 1;
1410 if (fn_size
< want_size
)
1411 fn
= (char *) alloca (fn_size
= 100 + want_size
);
1413 /* Loop over suffixes. */
1414 for (tail
= NILP (suffixes
) ? Fcons (empty_unibyte_string
, Qnil
) : suffixes
;
1415 CONSP (tail
); tail
= XCDR (tail
))
1417 int lsuffix
= SBYTES (XCAR (tail
));
1418 Lisp_Object handler
;
1421 /* Concatenate path element/specified name with the suffix.
1422 If the directory starts with /:, remove that. */
1423 if (SCHARS (filename
) > 2
1424 && SREF (filename
, 0) == '/'
1425 && SREF (filename
, 1) == ':')
1427 strncpy (fn
, SDATA (filename
) + 2,
1428 SBYTES (filename
) - 2);
1429 fn
[SBYTES (filename
) - 2] = 0;
1433 strncpy (fn
, SDATA (filename
),
1435 fn
[SBYTES (filename
)] = 0;
1438 if (lsuffix
!= 0) /* Bug happens on CCI if lsuffix is 0. */
1439 strncat (fn
, SDATA (XCAR (tail
)), lsuffix
);
1441 /* Check that the file exists and is not a directory. */
1442 /* We used to only check for handlers on non-absolute file names:
1446 handler = Ffind_file_name_handler (filename, Qfile_exists_p);
1447 It's not clear why that was the case and it breaks things like
1448 (load "/bar.el") where the file is actually "/bar.el.gz". */
1449 string
= build_string (fn
);
1450 handler
= Ffind_file_name_handler (string
, Qfile_exists_p
);
1451 if ((!NILP (handler
) || !NILP (predicate
)) && !NATNUMP (predicate
))
1453 if (NILP (predicate
))
1454 exists
= !NILP (Ffile_readable_p (string
));
1456 exists
= !NILP (call1 (predicate
, string
));
1457 if (exists
&& !NILP (Ffile_directory_p (string
)))
1462 /* We succeeded; return this descriptor and filename. */
1473 encoded_fn
= ENCODE_FILE (string
);
1474 pfn
= SDATA (encoded_fn
);
1475 exists
= (stat (pfn
, &st
) >= 0
1476 && (st
.st_mode
& S_IFMT
) != S_IFDIR
);
1479 /* Check that we can access or open it. */
1480 if (NATNUMP (predicate
))
1481 fd
= (access (pfn
, XFASTINT (predicate
)) == 0) ? 1 : -1;
1483 fd
= emacs_open (pfn
, O_RDONLY
, 0);
1487 /* We succeeded; return this descriptor and filename. */
1505 /* Merge the list we've accumulated of globals from the current input source
1506 into the load_history variable. The details depend on whether
1507 the source has an associated file name or not.
1509 FILENAME is the file name that we are loading from.
1510 ENTIRE is 1 if loading that entire file, 0 if evaluating part of it. */
1513 build_load_history (Lisp_Object filename
, int entire
)
1515 register Lisp_Object tail
, prev
, newelt
;
1516 register Lisp_Object tem
, tem2
;
1517 register int foundit
= 0;
1519 tail
= Vload_history
;
1522 while (CONSP (tail
))
1526 /* Find the feature's previous assoc list... */
1527 if (!NILP (Fequal (filename
, Fcar (tem
))))
1531 /* If we're loading the entire file, remove old data. */
1535 Vload_history
= XCDR (tail
);
1537 Fsetcdr (prev
, XCDR (tail
));
1540 /* Otherwise, cons on new symbols that are not already members. */
1543 tem2
= Vcurrent_load_list
;
1545 while (CONSP (tem2
))
1547 newelt
= XCAR (tem2
);
1549 if (NILP (Fmember (newelt
, tem
)))
1550 Fsetcar (tail
, Fcons (XCAR (tem
),
1551 Fcons (newelt
, XCDR (tem
))));
1564 /* If we're loading an entire file, cons the new assoc onto the
1565 front of load-history, the most-recently-loaded position. Also
1566 do this if we didn't find an existing member for the file. */
1567 if (entire
|| !foundit
)
1568 Vload_history
= Fcons (Fnreverse (Vcurrent_load_list
),
1573 unreadpure (Lisp_Object junk
) /* Used as unwind-protect function in readevalloop */
1581 readevalloop_1 (Lisp_Object old
)
1583 load_convert_to_unibyte
= ! NILP (old
);
1587 /* Signal an `end-of-file' error, if possible with file name
1591 end_of_file_error (void)
1593 if (STRINGP (Vload_file_name
))
1594 xsignal1 (Qend_of_file
, Vload_file_name
);
1596 xsignal0 (Qend_of_file
);
1599 /* UNIBYTE specifies how to set load_convert_to_unibyte
1600 for this invocation.
1601 READFUN, if non-nil, is used instead of `read'.
1603 START, END specify region to read in current buffer (from eval-region).
1604 If the input is not from a buffer, they must be nil. */
1607 readevalloop (Lisp_Object readcharfun
,
1609 Lisp_Object sourcename
,
1610 Lisp_Object (*evalfun
) (Lisp_Object
),
1612 Lisp_Object unibyte
, Lisp_Object readfun
,
1613 Lisp_Object start
, Lisp_Object end
)
1616 register Lisp_Object val
;
1617 int count
= SPECPDL_INDEX ();
1618 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
1619 struct buffer
*b
= 0;
1620 int continue_reading_p
;
1621 /* Nonzero if reading an entire buffer. */
1622 int whole_buffer
= 0;
1623 /* 1 on the first time around. */
1626 if (MARKERP (readcharfun
))
1629 start
= readcharfun
;
1632 if (BUFFERP (readcharfun
))
1633 b
= XBUFFER (readcharfun
);
1634 else if (MARKERP (readcharfun
))
1635 b
= XMARKER (readcharfun
)->buffer
;
1637 /* We assume START is nil when input is not from a buffer. */
1638 if (! NILP (start
) && !b
)
1641 specbind (Qstandard_input
, readcharfun
); /* GCPROs readcharfun. */
1642 specbind (Qcurrent_load_list
, Qnil
);
1643 record_unwind_protect (readevalloop_1
, load_convert_to_unibyte
? Qt
: Qnil
);
1644 load_convert_to_unibyte
= !NILP (unibyte
);
1646 GCPRO4 (sourcename
, readfun
, start
, end
);
1648 /* Try to ensure sourcename is a truename, except whilst preloading. */
1649 if (NILP (Vpurify_flag
)
1650 && !NILP (sourcename
) && !NILP (Ffile_name_absolute_p (sourcename
))
1651 && !NILP (Ffboundp (Qfile_truename
)))
1652 sourcename
= call1 (Qfile_truename
, sourcename
) ;
1654 LOADHIST_ATTACH (sourcename
);
1656 continue_reading_p
= 1;
1657 while (continue_reading_p
)
1659 int count1
= SPECPDL_INDEX ();
1661 if (b
!= 0 && NILP (b
->name
))
1662 error ("Reading from killed buffer");
1666 /* Switch to the buffer we are reading from. */
1667 record_unwind_protect (save_excursion_restore
, save_excursion_save ());
1668 set_buffer_internal (b
);
1670 /* Save point in it. */
1671 record_unwind_protect (save_excursion_restore
, save_excursion_save ());
1672 /* Save ZV in it. */
1673 record_unwind_protect (save_restriction_restore
, save_restriction_save ());
1674 /* Those get unbound after we read one expression. */
1676 /* Set point and ZV around stuff to be read. */
1679 Fnarrow_to_region (make_number (BEGV
), end
);
1681 /* Just for cleanliness, convert END to a marker
1682 if it is an integer. */
1684 end
= Fpoint_max_marker ();
1687 /* On the first cycle, we can easily test here
1688 whether we are reading the whole buffer. */
1689 if (b
&& first_sexp
)
1690 whole_buffer
= (PT
== BEG
&& ZV
== Z
);
1697 while ((c
= READCHAR
) != '\n' && c
!= -1);
1702 unbind_to (count1
, Qnil
);
1706 /* Ignore whitespace here, so we can detect eof. */
1707 if (c
== ' ' || c
== '\t' || c
== '\n' || c
== '\f' || c
== '\r'
1708 || c
== 0x8a0) /* NBSP */
1711 if (!NILP (Vpurify_flag
) && c
== '(')
1713 record_unwind_protect (unreadpure
, Qnil
);
1714 val
= read_list (-1, readcharfun
);
1719 read_objects
= Qnil
;
1720 if (!NILP (readfun
))
1722 val
= call1 (readfun
, readcharfun
);
1724 /* If READCHARFUN has set point to ZV, we should
1725 stop reading, even if the form read sets point
1726 to a different value when evaluated. */
1727 if (BUFFERP (readcharfun
))
1729 struct buffer
*b
= XBUFFER (readcharfun
);
1730 if (BUF_PT (b
) == BUF_ZV (b
))
1731 continue_reading_p
= 0;
1734 else if (! NILP (Vload_read_function
))
1735 val
= call1 (Vload_read_function
, readcharfun
);
1737 val
= read_internal_start (readcharfun
, Qnil
, Qnil
);
1740 if (!NILP (start
) && continue_reading_p
)
1741 start
= Fpoint_marker ();
1743 /* Restore saved point and BEGV. */
1744 unbind_to (count1
, Qnil
);
1746 /* Now eval what we just read. */
1747 val
= (*evalfun
) (val
);
1751 Vvalues
= Fcons (val
, Vvalues
);
1752 if (EQ (Vstandard_output
, Qt
))
1761 build_load_history (sourcename
,
1762 stream
|| whole_buffer
);
1766 unbind_to (count
, Qnil
);
1769 DEFUN ("eval-buffer", Feval_buffer
, Seval_buffer
, 0, 5, "",
1770 doc
: /* Execute the current buffer as Lisp code.
1771 When called from a Lisp program (i.e., not interactively), this
1772 function accepts up to five optional arguments:
1773 BUFFER is the buffer to evaluate (nil means use current buffer).
1774 PRINTFLAG controls printing of output:
1775 A value of nil means discard it; anything else is stream for print.
1776 FILENAME specifies the file name to use for `load-history'.
1777 UNIBYTE, if non-nil, specifies `load-convert-to-unibyte' for this
1779 DO-ALLOW-PRINT, if non-nil, specifies that `print' and related
1780 functions should work normally even if PRINTFLAG is nil.
1782 This function preserves the position of point. */)
1783 (Lisp_Object buffer
, Lisp_Object printflag
, Lisp_Object filename
, Lisp_Object unibyte
, Lisp_Object do_allow_print
)
1785 int count
= SPECPDL_INDEX ();
1786 Lisp_Object tem
, buf
;
1789 buf
= Fcurrent_buffer ();
1791 buf
= Fget_buffer (buffer
);
1793 error ("No such buffer");
1795 if (NILP (printflag
) && NILP (do_allow_print
))
1800 if (NILP (filename
))
1801 filename
= XBUFFER (buf
)->filename
;
1803 specbind (Qeval_buffer_list
, Fcons (buf
, Veval_buffer_list
));
1804 specbind (Qstandard_output
, tem
);
1805 record_unwind_protect (save_excursion_restore
, save_excursion_save ());
1806 BUF_TEMP_SET_PT (XBUFFER (buf
), BUF_BEGV (XBUFFER (buf
)));
1807 readevalloop (buf
, 0, filename
, Feval
,
1808 !NILP (printflag
), unibyte
, Qnil
, Qnil
, Qnil
);
1809 unbind_to (count
, Qnil
);
1814 DEFUN ("eval-region", Feval_region
, Seval_region
, 2, 4, "r",
1815 doc
: /* Execute the region as Lisp code.
1816 When called from programs, expects two arguments,
1817 giving starting and ending indices in the current buffer
1818 of the text to be executed.
1819 Programs can pass third argument PRINTFLAG which controls output:
1820 A value of nil means discard it; anything else is stream for printing it.
1821 Also the fourth argument READ-FUNCTION, if non-nil, is used
1822 instead of `read' to read each expression. It gets one argument
1823 which is the input stream for reading characters.
1825 This function does not move point. */)
1826 (Lisp_Object start
, Lisp_Object end
, Lisp_Object printflag
, Lisp_Object read_function
)
1828 int count
= SPECPDL_INDEX ();
1829 Lisp_Object tem
, cbuf
;
1831 cbuf
= Fcurrent_buffer ();
1833 if (NILP (printflag
))
1837 specbind (Qstandard_output
, tem
);
1838 specbind (Qeval_buffer_list
, Fcons (cbuf
, Veval_buffer_list
));
1840 /* readevalloop calls functions which check the type of start and end. */
1841 readevalloop (cbuf
, 0, XBUFFER (cbuf
)->filename
, Feval
,
1842 !NILP (printflag
), Qnil
, read_function
,
1845 return unbind_to (count
, Qnil
);
1849 DEFUN ("read", Fread
, Sread
, 0, 1, 0,
1850 doc
: /* Read one Lisp expression as text from STREAM, return as Lisp object.
1851 If STREAM is nil, use the value of `standard-input' (which see).
1852 STREAM or the value of `standard-input' may be:
1853 a buffer (read from point and advance it)
1854 a marker (read from where it points and advance it)
1855 a function (call it with no arguments for each character,
1856 call it with a char as argument to push a char back)
1857 a string (takes text from string, starting at the beginning)
1858 t (read text line using minibuffer and use it, or read from
1859 standard input in batch mode). */)
1860 (Lisp_Object stream
)
1863 stream
= Vstandard_input
;
1864 if (EQ (stream
, Qt
))
1865 stream
= Qread_char
;
1866 if (EQ (stream
, Qread_char
))
1867 return Fread_minibuffer (build_string ("Lisp expression: "), Qnil
);
1869 return read_internal_start (stream
, Qnil
, Qnil
);
1872 DEFUN ("read-from-string", Fread_from_string
, Sread_from_string
, 1, 3, 0,
1873 doc
: /* Read one Lisp expression which is represented as text by STRING.
1874 Returns a cons: (OBJECT-READ . FINAL-STRING-INDEX).
1875 START and END optionally delimit a substring of STRING from which to read;
1876 they default to 0 and (length STRING) respectively. */)
1877 (Lisp_Object string
, Lisp_Object start
, Lisp_Object end
)
1880 CHECK_STRING (string
);
1881 /* read_internal_start sets read_from_string_index. */
1882 ret
= read_internal_start (string
, start
, end
);
1883 return Fcons (ret
, make_number (read_from_string_index
));
1886 /* Function to set up the global context we need in toplevel read
1889 read_internal_start (Lisp_Object stream
, Lisp_Object start
, Lisp_Object end
)
1890 /* start, end only used when stream is a string. */
1895 new_backquote_flag
= 0;
1896 read_objects
= Qnil
;
1897 if (EQ (Vread_with_symbol_positions
, Qt
)
1898 || EQ (Vread_with_symbol_positions
, stream
))
1899 Vread_symbol_positions_list
= Qnil
;
1901 if (STRINGP (stream
)
1902 || ((CONSP (stream
) && STRINGP (XCAR (stream
)))))
1904 int startval
, endval
;
1907 if (STRINGP (stream
))
1910 string
= XCAR (stream
);
1913 endval
= SCHARS (string
);
1917 endval
= XINT (end
);
1918 if (endval
< 0 || endval
> SCHARS (string
))
1919 args_out_of_range (string
, end
);
1926 CHECK_NUMBER (start
);
1927 startval
= XINT (start
);
1928 if (startval
< 0 || startval
> endval
)
1929 args_out_of_range (string
, start
);
1931 read_from_string_index
= startval
;
1932 read_from_string_index_byte
= string_char_to_byte (string
, startval
);
1933 read_from_string_limit
= endval
;
1936 retval
= read0 (stream
);
1937 if (EQ (Vread_with_symbol_positions
, Qt
)
1938 || EQ (Vread_with_symbol_positions
, stream
))
1939 Vread_symbol_positions_list
= Fnreverse (Vread_symbol_positions_list
);
1944 /* Signal Qinvalid_read_syntax error.
1945 S is error string of length N (if > 0) */
1948 invalid_syntax (const char *s
, int n
)
1952 xsignal1 (Qinvalid_read_syntax
, make_string (s
, n
));
1956 /* Use this for recursive reads, in contexts where internal tokens
1960 read0 (Lisp_Object readcharfun
)
1962 register Lisp_Object val
;
1965 val
= read1 (readcharfun
, &c
, 0);
1969 xsignal1 (Qinvalid_read_syntax
,
1970 Fmake_string (make_number (1), make_number (c
)));
1973 static int read_buffer_size
;
1974 static char *read_buffer
;
1976 /* Read a \-escape sequence, assuming we already read the `\'.
1977 If the escape sequence forces unibyte, return eight-bit char. */
1980 read_escape (Lisp_Object readcharfun
, int stringp
)
1982 register int c
= READCHAR
;
1983 /* \u allows up to four hex digits, \U up to eight. Default to the
1984 behavior for \u, and change this value in the case that \U is seen. */
1985 int unicode_hex_count
= 4;
1990 end_of_file_error ();
2020 error ("Invalid escape character syntax");
2023 c
= read_escape (readcharfun
, 0);
2024 return c
| meta_modifier
;
2029 error ("Invalid escape character syntax");
2032 c
= read_escape (readcharfun
, 0);
2033 return c
| shift_modifier
;
2038 error ("Invalid escape character syntax");
2041 c
= read_escape (readcharfun
, 0);
2042 return c
| hyper_modifier
;
2047 error ("Invalid escape character syntax");
2050 c
= read_escape (readcharfun
, 0);
2051 return c
| alt_modifier
;
2055 if (stringp
|| c
!= '-')
2062 c
= read_escape (readcharfun
, 0);
2063 return c
| super_modifier
;
2068 error ("Invalid escape character syntax");
2072 c
= read_escape (readcharfun
, 0);
2073 if ((c
& ~CHAR_MODIFIER_MASK
) == '?')
2074 return 0177 | (c
& CHAR_MODIFIER_MASK
);
2075 else if (! SINGLE_BYTE_CHAR_P ((c
& ~CHAR_MODIFIER_MASK
)))
2076 return c
| ctrl_modifier
;
2077 /* ASCII control chars are made from letters (both cases),
2078 as well as the non-letters within 0100...0137. */
2079 else if ((c
& 0137) >= 0101 && (c
& 0137) <= 0132)
2080 return (c
& (037 | ~0177));
2081 else if ((c
& 0177) >= 0100 && (c
& 0177) <= 0137)
2082 return (c
& (037 | ~0177));
2084 return c
| ctrl_modifier
;
2094 /* An octal escape, as in ANSI C. */
2096 register int i
= c
- '0';
2097 register int count
= 0;
2100 if ((c
= READCHAR
) >= '0' && c
<= '7')
2112 if (i
>= 0x80 && i
< 0x100)
2113 i
= BYTE8_TO_CHAR (i
);
2118 /* A hex escape, as in ANSI C. */
2125 if (c
>= '0' && c
<= '9')
2130 else if ((c
>= 'a' && c
<= 'f')
2131 || (c
>= 'A' && c
<= 'F'))
2134 if (c
>= 'a' && c
<= 'f')
2147 if (count
< 3 && i
>= 0x80)
2148 return BYTE8_TO_CHAR (i
);
2153 /* Post-Unicode-2.0: Up to eight hex chars. */
2154 unicode_hex_count
= 8;
2157 /* A Unicode escape. We only permit them in strings and characters,
2158 not arbitrarily in the source code, as in some other languages. */
2163 while (++count
<= unicode_hex_count
)
2166 /* isdigit and isalpha may be locale-specific, which we don't
2168 if (c
>= '0' && c
<= '9') i
= (i
<< 4) + (c
- '0');
2169 else if (c
>= 'a' && c
<= 'f') i
= (i
<< 4) + (c
- 'a') + 10;
2170 else if (c
>= 'A' && c
<= 'F') i
= (i
<< 4) + (c
- 'A') + 10;
2173 error ("Non-hex digit used for Unicode escape");
2178 error ("Non-Unicode character: 0x%x", i
);
2187 /* Read an integer in radix RADIX using READCHARFUN to read
2188 characters. RADIX must be in the interval [2..36]; if it isn't, a
2189 read error is signaled . Value is the integer read. Signals an
2190 error if encountering invalid read syntax or if RADIX is out of
2194 read_integer (Lisp_Object readcharfun
, int radix
)
2196 int ndigits
= 0, invalid_p
, c
, sign
= 0;
2197 /* We use a floating point number because */
2200 if (radix
< 2 || radix
> 36)
2204 number
= ndigits
= invalid_p
= 0;
2220 if (c
>= '0' && c
<= '9')
2222 else if (c
>= 'a' && c
<= 'z')
2223 digit
= c
- 'a' + 10;
2224 else if (c
>= 'A' && c
<= 'Z')
2225 digit
= c
- 'A' + 10;
2232 if (digit
< 0 || digit
>= radix
)
2235 number
= radix
* number
+ digit
;
2241 if (ndigits
== 0 || invalid_p
)
2244 sprintf (buf
, "integer, radix %d", radix
);
2245 invalid_syntax (buf
, 0);
2248 return make_fixnum_or_float (sign
* number
);
2252 /* If the next token is ')' or ']' or '.', we store that character
2253 in *PCH and the return value is not interesting. Else, we store
2254 zero in *PCH and we read and return one lisp object.
2256 FIRST_IN_LIST is nonzero if this is the first element of a list. */
2259 read1 (register Lisp_Object readcharfun
, int *pch
, int first_in_list
)
2262 int uninterned_symbol
= 0;
2270 c
= READCHAR_REPORT_MULTIBYTE (&multibyte
);
2272 end_of_file_error ();
2277 return read_list (0, readcharfun
);
2280 return read_vector (readcharfun
, 0);
2296 /* Accept extended format for hashtables (extensible to
2298 #s(hash-table size 2 test equal data (k1 v1 k2 v2)) */
2299 Lisp_Object tmp
= read_list (0, readcharfun
);
2300 Lisp_Object head
= CAR_SAFE (tmp
);
2301 Lisp_Object data
= Qnil
;
2302 Lisp_Object val
= Qnil
;
2303 /* The size is 2 * number of allowed keywords to
2305 Lisp_Object params
[10];
2307 Lisp_Object key
= Qnil
;
2308 int param_count
= 0;
2310 if (!EQ (head
, Qhash_table
))
2311 error ("Invalid extended read marker at head of #s list "
2312 "(only hash-table allowed)");
2314 tmp
= CDR_SAFE (tmp
);
2316 /* This is repetitive but fast and simple. */
2317 params
[param_count
] = QCsize
;
2318 params
[param_count
+1] = Fplist_get (tmp
, Qsize
);
2319 if (!NILP (params
[param_count
+1]))
2322 params
[param_count
] = QCtest
;
2323 params
[param_count
+1] = Fplist_get (tmp
, Qtest
);
2324 if (!NILP (params
[param_count
+1]))
2327 params
[param_count
] = QCweakness
;
2328 params
[param_count
+1] = Fplist_get (tmp
, Qweakness
);
2329 if (!NILP (params
[param_count
+1]))
2332 params
[param_count
] = QCrehash_size
;
2333 params
[param_count
+1] = Fplist_get (tmp
, Qrehash_size
);
2334 if (!NILP (params
[param_count
+1]))
2337 params
[param_count
] = QCrehash_threshold
;
2338 params
[param_count
+1] = Fplist_get (tmp
, Qrehash_threshold
);
2339 if (!NILP (params
[param_count
+1]))
2342 /* This is the hashtable data. */
2343 data
= Fplist_get (tmp
, Qdata
);
2345 /* Now use params to make a new hashtable and fill it. */
2346 ht
= Fmake_hash_table (param_count
, params
);
2348 while (CONSP (data
))
2353 error ("Odd number of elements in hashtable data");
2356 Fputhash (key
, val
, ht
);
2368 tmp
= read_vector (readcharfun
, 0);
2369 if (XVECTOR (tmp
)->size
< CHAR_TABLE_STANDARD_SLOTS
)
2370 error ("Invalid size char-table");
2371 XSETPVECTYPE (XVECTOR (tmp
), PVEC_CHAR_TABLE
);
2382 tmp
= read_vector (readcharfun
, 0);
2383 if (!INTEGERP (AREF (tmp
, 0)))
2384 error ("Invalid depth in char-table");
2385 depth
= XINT (AREF (tmp
, 0));
2386 if (depth
< 1 || depth
> 3)
2387 error ("Invalid depth in char-table");
2388 size
= XVECTOR (tmp
)->size
- 2;
2389 if (chartab_size
[depth
] != size
)
2390 error ("Invalid size char-table");
2391 XSETPVECTYPE (XVECTOR (tmp
), PVEC_SUB_CHAR_TABLE
);
2394 invalid_syntax ("#^^", 3);
2396 invalid_syntax ("#^", 2);
2401 length
= read1 (readcharfun
, pch
, first_in_list
);
2405 Lisp_Object tmp
, val
;
2407 = ((XFASTINT (length
) + BOOL_VECTOR_BITS_PER_CHAR
- 1)
2408 / BOOL_VECTOR_BITS_PER_CHAR
);
2411 tmp
= read1 (readcharfun
, pch
, first_in_list
);
2412 if (STRING_MULTIBYTE (tmp
)
2413 || (size_in_chars
!= SCHARS (tmp
)
2414 /* We used to print 1 char too many
2415 when the number of bits was a multiple of 8.
2416 Accept such input in case it came from an old
2418 && ! (XFASTINT (length
)
2419 == (SCHARS (tmp
) - 1) * BOOL_VECTOR_BITS_PER_CHAR
)))
2420 invalid_syntax ("#&...", 5);
2422 val
= Fmake_bool_vector (length
, Qnil
);
2423 memcpy (XBOOL_VECTOR (val
)->data
, SDATA (tmp
), size_in_chars
);
2424 /* Clear the extraneous bits in the last byte. */
2425 if (XINT (length
) != size_in_chars
* BOOL_VECTOR_BITS_PER_CHAR
)
2426 XBOOL_VECTOR (val
)->data
[size_in_chars
- 1]
2427 &= (1 << (XINT (length
) % BOOL_VECTOR_BITS_PER_CHAR
)) - 1;
2430 invalid_syntax ("#&...", 5);
2434 /* Accept compiled functions at read-time so that we don't have to
2435 build them using function calls. */
2437 tmp
= read_vector (readcharfun
, 1);
2438 return Fmake_byte_code (XVECTOR (tmp
)->size
,
2439 XVECTOR (tmp
)->contents
);
2444 struct gcpro gcpro1
;
2447 /* Read the string itself. */
2448 tmp
= read1 (readcharfun
, &ch
, 0);
2449 if (ch
!= 0 || !STRINGP (tmp
))
2450 invalid_syntax ("#", 1);
2452 /* Read the intervals and their properties. */
2455 Lisp_Object beg
, end
, plist
;
2457 beg
= read1 (readcharfun
, &ch
, 0);
2462 end
= read1 (readcharfun
, &ch
, 0);
2464 plist
= read1 (readcharfun
, &ch
, 0);
2466 invalid_syntax ("Invalid string property list", 0);
2467 Fset_text_properties (beg
, end
, plist
, tmp
);
2473 /* #@NUMBER is used to skip NUMBER following characters.
2474 That's used in .elc files to skip over doc strings
2475 and function definitions. */
2481 /* Read a decimal integer. */
2482 while ((c
= READCHAR
) >= 0
2483 && c
>= '0' && c
<= '9')
2491 if (load_force_doc_strings
2492 && (EQ (readcharfun
, Qget_file_char
)
2493 || EQ (readcharfun
, Qget_emacs_mule_file_char
)))
2495 /* If we are supposed to force doc strings into core right now,
2496 record the last string that we skipped,
2497 and record where in the file it comes from. */
2499 /* But first exchange saved_doc_string
2500 with prev_saved_doc_string, so we save two strings. */
2502 char *temp
= saved_doc_string
;
2503 int temp_size
= saved_doc_string_size
;
2504 file_offset temp_pos
= saved_doc_string_position
;
2505 int temp_len
= saved_doc_string_length
;
2507 saved_doc_string
= prev_saved_doc_string
;
2508 saved_doc_string_size
= prev_saved_doc_string_size
;
2509 saved_doc_string_position
= prev_saved_doc_string_position
;
2510 saved_doc_string_length
= prev_saved_doc_string_length
;
2512 prev_saved_doc_string
= temp
;
2513 prev_saved_doc_string_size
= temp_size
;
2514 prev_saved_doc_string_position
= temp_pos
;
2515 prev_saved_doc_string_length
= temp_len
;
2518 if (saved_doc_string_size
== 0)
2520 saved_doc_string_size
= nskip
+ 100;
2521 saved_doc_string
= (char *) xmalloc (saved_doc_string_size
);
2523 if (nskip
> saved_doc_string_size
)
2525 saved_doc_string_size
= nskip
+ 100;
2526 saved_doc_string
= (char *) xrealloc (saved_doc_string
,
2527 saved_doc_string_size
);
2530 saved_doc_string_position
= file_tell (instream
);
2532 /* Copy that many characters into saved_doc_string. */
2533 for (i
= 0; i
< nskip
&& c
>= 0; i
++)
2534 saved_doc_string
[i
] = c
= READCHAR
;
2536 saved_doc_string_length
= i
;
2540 /* Skip that many characters. */
2541 for (i
= 0; i
< nskip
&& c
>= 0; i
++)
2550 /* #! appears at the beginning of an executable file.
2551 Skip the first line. */
2552 while (c
!= '\n' && c
>= 0)
2557 return Vload_file_name
;
2559 return Fcons (Qfunction
, Fcons (read0 (readcharfun
), Qnil
));
2560 /* #:foo is the uninterned symbol named foo. */
2563 uninterned_symbol
= 1;
2567 /* Reader forms that can reuse previously read objects. */
2568 if (c
>= '0' && c
<= '9')
2573 /* Read a non-negative integer. */
2574 while (c
>= '0' && c
<= '9')
2580 /* #n=object returns object, but associates it with n for #n#. */
2581 if (c
== '=' && !NILP (Vread_circle
))
2583 /* Make a placeholder for #n# to use temporarily */
2584 Lisp_Object placeholder
;
2587 placeholder
= Fcons (Qnil
, Qnil
);
2588 cell
= Fcons (make_number (n
), placeholder
);
2589 read_objects
= Fcons (cell
, read_objects
);
2591 /* Read the object itself. */
2592 tem
= read0 (readcharfun
);
2594 /* Now put it everywhere the placeholder was... */
2595 substitute_object_in_subtree (tem
, placeholder
);
2597 /* ...and #n# will use the real value from now on. */
2598 Fsetcdr (cell
, tem
);
2602 /* #n# returns a previously read object. */
2603 if (c
== '#' && !NILP (Vread_circle
))
2605 tem
= Fassq (make_number (n
), read_objects
);
2608 /* Fall through to error message. */
2610 else if (c
== 'r' || c
== 'R')
2611 return read_integer (readcharfun
, n
);
2613 /* Fall through to error message. */
2615 else if (c
== 'x' || c
== 'X')
2616 return read_integer (readcharfun
, 16);
2617 else if (c
== 'o' || c
== 'O')
2618 return read_integer (readcharfun
, 8);
2619 else if (c
== 'b' || c
== 'B')
2620 return read_integer (readcharfun
, 2);
2623 invalid_syntax ("#", 1);
2626 while ((c
= READCHAR
) >= 0 && c
!= '\n');
2631 return Fcons (Qquote
, Fcons (read0 (readcharfun
), Qnil
));
2636 int next_char
= READCHAR
;
2638 /* Transition from old-style to new-style:
2639 If we see "(`" it used to mean old-style, which usually works
2640 fine because ` should almost never appear in such a position
2641 for new-style. But occasionally we need "(`" to mean new
2642 style, so we try to distinguish the two by the fact that we
2643 can either write "( `foo" or "(` foo", where the first
2644 intends to use new-style whereas the second intends to use
2645 old-style. For Emacs-25, we should completely remove this
2646 first_in_list exception (old-style can still be obtained via
2648 if (first_in_list
&& next_char
== ' ')
2650 Vold_style_backquotes
= Qt
;
2657 new_backquote_flag
++;
2658 value
= read0 (readcharfun
);
2659 new_backquote_flag
--;
2661 return Fcons (Qbackquote
, Fcons (value
, Qnil
));
2665 if (new_backquote_flag
)
2667 Lisp_Object comma_type
= Qnil
;
2672 comma_type
= Qcomma_at
;
2674 comma_type
= Qcomma_dot
;
2677 if (ch
>= 0) UNREAD (ch
);
2678 comma_type
= Qcomma
;
2681 new_backquote_flag
--;
2682 value
= read0 (readcharfun
);
2683 new_backquote_flag
++;
2684 return Fcons (comma_type
, Fcons (value
, Qnil
));
2688 Vold_style_backquotes
= Qt
;
2700 end_of_file_error ();
2702 /* Accept `single space' syntax like (list ? x) where the
2703 whitespace character is SPC or TAB.
2704 Other literal whitespace like NL, CR, and FF are not accepted,
2705 as there are well-established escape sequences for these. */
2706 if (c
== ' ' || c
== '\t')
2707 return make_number (c
);
2710 c
= read_escape (readcharfun
, 0);
2711 modifiers
= c
& CHAR_MODIFIER_MASK
;
2712 c
&= ~CHAR_MODIFIER_MASK
;
2713 if (CHAR_BYTE8_P (c
))
2714 c
= CHAR_TO_BYTE8 (c
);
2717 next_char
= READCHAR
;
2718 if (next_char
== '.')
2720 /* Only a dotted-pair dot is valid after a char constant. */
2721 int next_next_char
= READCHAR
;
2722 UNREAD (next_next_char
);
2724 ok
= (next_next_char
<= 040
2725 || (next_next_char
< 0200
2726 && (index ("\"';([#?", next_next_char
)
2727 || (!first_in_list
&& next_next_char
== '`')
2728 || (new_backquote_flag
&& next_next_char
== ','))));
2732 ok
= (next_char
<= 040
2733 || (next_char
< 0200
2734 && (index ("\"';()[]#?", next_char
)
2735 || (!first_in_list
&& next_char
== '`')
2736 || (new_backquote_flag
&& next_char
== ','))));
2740 return make_number (c
);
2742 invalid_syntax ("?", 1);
2747 char *p
= read_buffer
;
2748 char *end
= read_buffer
+ read_buffer_size
;
2750 /* Nonzero if we saw an escape sequence specifying
2751 a multibyte character. */
2752 int force_multibyte
= 0;
2753 /* Nonzero if we saw an escape sequence specifying
2754 a single-byte character. */
2755 int force_singlebyte
= 0;
2759 while ((c
= READCHAR
) >= 0
2762 if (end
- p
< MAX_MULTIBYTE_LENGTH
)
2764 int offset
= p
- read_buffer
;
2765 read_buffer
= (char *) xrealloc (read_buffer
,
2766 read_buffer_size
*= 2);
2767 p
= read_buffer
+ offset
;
2768 end
= read_buffer
+ read_buffer_size
;
2775 c
= read_escape (readcharfun
, 1);
2777 /* C is -1 if \ newline has just been seen */
2780 if (p
== read_buffer
)
2785 modifiers
= c
& CHAR_MODIFIER_MASK
;
2786 c
= c
& ~CHAR_MODIFIER_MASK
;
2788 if (CHAR_BYTE8_P (c
))
2789 force_singlebyte
= 1;
2790 else if (! ASCII_CHAR_P (c
))
2791 force_multibyte
= 1;
2792 else /* i.e. ASCII_CHAR_P (c) */
2794 /* Allow `\C- ' and `\C-?'. */
2795 if (modifiers
== CHAR_CTL
)
2798 c
= 0, modifiers
= 0;
2800 c
= 127, modifiers
= 0;
2802 if (modifiers
& CHAR_SHIFT
)
2804 /* Shift modifier is valid only with [A-Za-z]. */
2805 if (c
>= 'A' && c
<= 'Z')
2806 modifiers
&= ~CHAR_SHIFT
;
2807 else if (c
>= 'a' && c
<= 'z')
2808 c
-= ('a' - 'A'), modifiers
&= ~CHAR_SHIFT
;
2811 if (modifiers
& CHAR_META
)
2813 /* Move the meta bit to the right place for a
2815 modifiers
&= ~CHAR_META
;
2816 c
= BYTE8_TO_CHAR (c
| 0x80);
2817 force_singlebyte
= 1;
2821 /* Any modifiers remaining are invalid. */
2823 error ("Invalid modifier in string");
2824 p
+= CHAR_STRING (c
, (unsigned char *) p
);
2828 p
+= CHAR_STRING (c
, (unsigned char *) p
);
2829 if (CHAR_BYTE8_P (c
))
2830 force_singlebyte
= 1;
2831 else if (! ASCII_CHAR_P (c
))
2832 force_multibyte
= 1;
2838 end_of_file_error ();
2840 /* If purifying, and string starts with \ newline,
2841 return zero instead. This is for doc strings
2842 that we are really going to find in etc/DOC.nn.nn */
2843 if (!NILP (Vpurify_flag
) && NILP (Vdoc_file_name
) && cancel
)
2844 return make_number (0);
2846 if (force_multibyte
)
2847 /* READ_BUFFER already contains valid multibyte forms. */
2849 else if (force_singlebyte
)
2851 nchars
= str_as_unibyte (read_buffer
, p
- read_buffer
);
2852 p
= read_buffer
+ nchars
;
2855 /* Otherwise, READ_BUFFER contains only ASCII. */
2858 /* We want readchar_count to be the number of characters, not
2859 bytes. Hence we adjust for multibyte characters in the
2860 string. ... But it doesn't seem to be necessary, because
2861 READCHAR *does* read multibyte characters from buffers. */
2862 /* readchar_count -= (p - read_buffer) - nchars; */
2864 return make_pure_string (read_buffer
, nchars
, p
- read_buffer
,
2866 || (p
- read_buffer
!= nchars
)));
2867 return make_specified_string (read_buffer
, nchars
, p
- read_buffer
,
2869 || (p
- read_buffer
!= nchars
)));
2874 int next_char
= READCHAR
;
2877 if (next_char
<= 040
2878 || (next_char
< 0200
2879 && (index ("\"';([#?", next_char
)
2880 || (!first_in_list
&& next_char
== '`')
2881 || (new_backquote_flag
&& next_char
== ','))))
2887 /* Otherwise, we fall through! Note that the atom-reading loop
2888 below will now loop at least once, assuring that we will not
2889 try to UNREAD two characters in a row. */
2893 if (c
<= 040) goto retry
;
2894 if (c
== 0x8a0) /* NBSP */
2897 char *p
= read_buffer
;
2901 char *end
= read_buffer
+ read_buffer_size
;
2904 && c
!= 0x8a0 /* NBSP */
2906 || (!index ("\"';()[]#", c
)
2907 && !(!first_in_list
&& c
== '`')
2908 && !(new_backquote_flag
&& c
== ','))))
2910 if (end
- p
< MAX_MULTIBYTE_LENGTH
)
2912 int offset
= p
- read_buffer
;
2913 read_buffer
= (char *) xrealloc (read_buffer
,
2914 read_buffer_size
*= 2);
2915 p
= read_buffer
+ offset
;
2916 end
= read_buffer
+ read_buffer_size
;
2923 end_of_file_error ();
2928 p
+= CHAR_STRING (c
, p
);
2936 int offset
= p
- read_buffer
;
2937 read_buffer
= (char *) xrealloc (read_buffer
,
2938 read_buffer_size
*= 2);
2939 p
= read_buffer
+ offset
;
2940 end
= read_buffer
+ read_buffer_size
;
2947 if (!quoted
&& !uninterned_symbol
)
2951 if (*p1
== '+' || *p1
== '-') p1
++;
2952 /* Is it an integer? */
2955 while (p1
!= p
&& (c
= *p1
) >= '0' && c
<= '9') p1
++;
2956 /* Integers can have trailing decimal points. */
2957 if (p1
> read_buffer
&& p1
< p
&& *p1
== '.') p1
++;
2959 /* It is an integer. */
2964 /* EMACS_INT n = atol (read_buffer); */
2965 char *endptr
= NULL
;
2966 EMACS_INT n
= (errno
= 0,
2967 strtol (read_buffer
, &endptr
, 10));
2968 if (errno
== ERANGE
&& endptr
)
2971 = Fcons (make_string (read_buffer
,
2972 endptr
- read_buffer
),
2974 xsignal (Qoverflow_error
, args
);
2976 return make_fixnum_or_float (n
);
2980 if (isfloat_string (read_buffer
, 0))
2982 /* Compute NaN and infinities using 0.0 in a variable,
2983 to cope with compilers that think they are smarter
2989 /* Negate the value ourselves. This treats 0, NaNs,
2990 and infinity properly on IEEE floating point hosts,
2991 and works around a common bug where atof ("-0.0")
2993 int negative
= read_buffer
[0] == '-';
2995 /* The only way p[-1] can be 'F' or 'N', after isfloat_string
2996 returns 1, is if the input ends in e+INF or e+NaN. */
3003 value
= zero
/ zero
;
3005 /* If that made a "negative" NaN, negate it. */
3009 union { double d
; char c
[sizeof (double)]; } u_data
, u_minus_zero
;
3012 u_minus_zero
.d
= - 0.0;
3013 for (i
= 0; i
< sizeof (double); i
++)
3014 if (u_data
.c
[i
] & u_minus_zero
.c
[i
])
3020 /* Now VALUE is a positive NaN. */
3023 value
= atof (read_buffer
+ negative
);
3027 return make_float (negative
? - value
: value
);
3031 Lisp_Object name
, result
;
3032 EMACS_INT nbytes
= p
- read_buffer
;
3034 = (multibyte
? multibyte_chars_in_text (read_buffer
, nbytes
)
3037 if (uninterned_symbol
&& ! NILP (Vpurify_flag
))
3038 name
= make_pure_string (read_buffer
, nchars
, nbytes
, multibyte
);
3040 name
= make_specified_string (read_buffer
, nchars
, nbytes
,multibyte
);
3041 result
= (uninterned_symbol
? Fmake_symbol (name
)
3042 : Fintern (name
, Qnil
));
3044 if (EQ (Vread_with_symbol_positions
, Qt
)
3045 || EQ (Vread_with_symbol_positions
, readcharfun
))
3046 Vread_symbol_positions_list
=
3047 /* Kind of a hack; this will probably fail if characters
3048 in the symbol name were escaped. Not really a big
3050 Fcons (Fcons (result
,
3051 make_number (readchar_count
3052 - XFASTINT (Flength (Fsymbol_name (result
))))),
3053 Vread_symbol_positions_list
);
3061 /* List of nodes we've seen during substitute_object_in_subtree. */
3062 static Lisp_Object seen_list
;
3065 substitute_object_in_subtree (Lisp_Object object
, Lisp_Object placeholder
)
3067 Lisp_Object check_object
;
3069 /* We haven't seen any objects when we start. */
3072 /* Make all the substitutions. */
3074 = substitute_object_recurse (object
, placeholder
, object
);
3076 /* Clear seen_list because we're done with it. */
3079 /* The returned object here is expected to always eq the
3081 if (!EQ (check_object
, object
))
3082 error ("Unexpected mutation error in reader");
3085 /* Feval doesn't get called from here, so no gc protection is needed. */
3086 #define SUBSTITUTE(get_val, set_val) \
3088 Lisp_Object old_value = get_val; \
3089 Lisp_Object true_value \
3090 = substitute_object_recurse (object, placeholder, \
3093 if (!EQ (old_value, true_value)) \
3100 substitute_object_recurse (Lisp_Object object
, Lisp_Object placeholder
, Lisp_Object subtree
)
3102 /* If we find the placeholder, return the target object. */
3103 if (EQ (placeholder
, subtree
))
3106 /* If we've been to this node before, don't explore it again. */
3107 if (!EQ (Qnil
, Fmemq (subtree
, seen_list
)))
3110 /* If this node can be the entry point to a cycle, remember that
3111 we've seen it. It can only be such an entry point if it was made
3112 by #n=, which means that we can find it as a value in
3114 if (!EQ (Qnil
, Frassq (subtree
, read_objects
)))
3115 seen_list
= Fcons (subtree
, seen_list
);
3117 /* Recurse according to subtree's type.
3118 Every branch must return a Lisp_Object. */
3119 switch (XTYPE (subtree
))
3121 case Lisp_Vectorlike
:
3124 if (BOOL_VECTOR_P (subtree
))
3125 return subtree
; /* No sub-objects anyway. */
3126 else if (CHAR_TABLE_P (subtree
) || SUB_CHAR_TABLE_P (subtree
)
3127 || COMPILEDP (subtree
))
3128 length
= ASIZE (subtree
) & PSEUDOVECTOR_SIZE_MASK
;
3129 else if (VECTORP (subtree
))
3130 length
= ASIZE (subtree
);
3132 /* An unknown pseudovector may contain non-Lisp fields, so we
3133 can't just blindly traverse all its fields. We used to call
3134 `Flength' which signaled `sequencep', so I just preserved this
3136 wrong_type_argument (Qsequencep
, subtree
);
3138 for (i
= 0; i
< length
; i
++)
3139 SUBSTITUTE (AREF (subtree
, i
),
3140 ASET (subtree
, i
, true_value
));
3146 SUBSTITUTE (XCAR (subtree
),
3147 XSETCAR (subtree
, true_value
));
3148 SUBSTITUTE (XCDR (subtree
),
3149 XSETCDR (subtree
, true_value
));
3155 /* Check for text properties in each interval.
3156 substitute_in_interval contains part of the logic. */
3158 INTERVAL root_interval
= STRING_INTERVALS (subtree
);
3159 Lisp_Object arg
= Fcons (object
, placeholder
);
3161 traverse_intervals_noorder (root_interval
,
3162 &substitute_in_interval
, arg
);
3167 /* Other types don't recurse any further. */
3173 /* Helper function for substitute_object_recurse. */
3175 substitute_in_interval (INTERVAL interval
, Lisp_Object arg
)
3177 Lisp_Object object
= Fcar (arg
);
3178 Lisp_Object placeholder
= Fcdr (arg
);
3180 SUBSTITUTE (interval
->plist
, interval
->plist
= true_value
);
3191 isfloat_string (register char *cp
, int ignore_trailing
)
3198 if (*cp
== '+' || *cp
== '-')
3201 if (*cp
>= '0' && *cp
<= '9')
3204 while (*cp
>= '0' && *cp
<= '9')
3212 if (*cp
>= '0' && *cp
<= '9')
3215 while (*cp
>= '0' && *cp
<= '9')
3218 if (*cp
== 'e' || *cp
== 'E')
3222 if (*cp
== '+' || *cp
== '-')
3226 if (*cp
>= '0' && *cp
<= '9')
3229 while (*cp
>= '0' && *cp
<= '9')
3232 else if (cp
== start
)
3234 else if (cp
[-1] == '+' && cp
[0] == 'I' && cp
[1] == 'N' && cp
[2] == 'F')
3239 else if (cp
[-1] == '+' && cp
[0] == 'N' && cp
[1] == 'a' && cp
[2] == 'N')
3245 return ((ignore_trailing
3246 || (*cp
== 0) || (*cp
== ' ') || (*cp
== '\t') || (*cp
== '\n') || (*cp
== '\r') || (*cp
== '\f'))
3247 && (state
== (LEAD_INT
|DOT_CHAR
|TRAIL_INT
)
3248 || state
== (DOT_CHAR
|TRAIL_INT
)
3249 || state
== (LEAD_INT
|E_CHAR
|EXP_INT
)
3250 || state
== (LEAD_INT
|DOT_CHAR
|TRAIL_INT
|E_CHAR
|EXP_INT
)
3251 || state
== (DOT_CHAR
|TRAIL_INT
|E_CHAR
|EXP_INT
)));
3256 read_vector (Lisp_Object readcharfun
, int bytecodeflag
)
3260 register Lisp_Object
*ptr
;
3261 register Lisp_Object tem
, item
, vector
;
3262 register struct Lisp_Cons
*otem
;
3265 tem
= read_list (1, readcharfun
);
3266 len
= Flength (tem
);
3267 vector
= (read_pure
? make_pure_vector (XINT (len
)) : Fmake_vector (len
, Qnil
));
3269 size
= XVECTOR (vector
)->size
;
3270 ptr
= XVECTOR (vector
)->contents
;
3271 for (i
= 0; i
< size
; i
++)
3274 /* If `load-force-doc-strings' is t when reading a lazily-loaded
3275 bytecode object, the docstring containing the bytecode and
3276 constants values must be treated as unibyte and passed to
3277 Fread, to get the actual bytecode string and constants vector. */
3278 if (bytecodeflag
&& load_force_doc_strings
)
3280 if (i
== COMPILED_BYTECODE
)
3282 if (!STRINGP (item
))
3283 error ("Invalid byte code");
3285 /* Delay handling the bytecode slot until we know whether
3286 it is lazily-loaded (we can tell by whether the
3287 constants slot is nil). */
3288 ptr
[COMPILED_CONSTANTS
] = item
;
3291 else if (i
== COMPILED_CONSTANTS
)
3293 Lisp_Object bytestr
= ptr
[COMPILED_CONSTANTS
];
3297 /* Coerce string to unibyte (like string-as-unibyte,
3298 but without generating extra garbage and
3299 guaranteeing no change in the contents). */
3300 STRING_SET_CHARS (bytestr
, SBYTES (bytestr
));
3301 STRING_SET_UNIBYTE (bytestr
);
3303 item
= Fread (Fcons (bytestr
, readcharfun
));
3305 error ("Invalid byte code");
3307 otem
= XCONS (item
);
3308 bytestr
= XCAR (item
);
3313 /* Now handle the bytecode slot. */
3314 ptr
[COMPILED_BYTECODE
] = read_pure
? Fpurecopy (bytestr
) : bytestr
;
3316 else if (i
== COMPILED_DOC_STRING
3318 && ! STRING_MULTIBYTE (item
))
3320 if (EQ (readcharfun
, Qget_emacs_mule_file_char
))
3321 item
= Fdecode_coding_string (item
, Qemacs_mule
, Qnil
, Qnil
);
3323 item
= Fstring_as_multibyte (item
);
3326 ptr
[i
] = read_pure
? Fpurecopy (item
) : item
;
3334 /* FLAG = 1 means check for ] to terminate rather than ) and .
3335 FLAG = -1 means check for starting with defun
3336 and make structure pure. */
3339 read_list (int flag
, register Lisp_Object readcharfun
)
3341 /* -1 means check next element for defun,
3342 0 means don't check,
3343 1 means already checked and found defun. */
3344 int defunflag
= flag
< 0 ? -1 : 0;
3345 Lisp_Object val
, tail
;
3346 register Lisp_Object elt
, tem
;
3347 struct gcpro gcpro1
, gcpro2
;
3348 /* 0 is the normal case.
3349 1 means this list is a doc reference; replace it with the number 0.
3350 2 means this list is a doc reference; replace it with the doc string. */
3351 int doc_reference
= 0;
3353 /* Initialize this to 1 if we are reading a list. */
3354 int first_in_list
= flag
<= 0;
3363 elt
= read1 (readcharfun
, &ch
, first_in_list
);
3368 /* While building, if the list starts with #$, treat it specially. */
3369 if (EQ (elt
, Vload_file_name
)
3371 && !NILP (Vpurify_flag
))
3373 if (NILP (Vdoc_file_name
))
3374 /* We have not yet called Snarf-documentation, so assume
3375 this file is described in the DOC-MM.NN file
3376 and Snarf-documentation will fill in the right value later.
3377 For now, replace the whole list with 0. */
3380 /* We have already called Snarf-documentation, so make a relative
3381 file name for this file, so it can be found properly
3382 in the installed Lisp directory.
3383 We don't use Fexpand_file_name because that would make
3384 the directory absolute now. */
3385 elt
= concat2 (build_string ("../lisp/"),
3386 Ffile_name_nondirectory (elt
));
3388 else if (EQ (elt
, Vload_file_name
)
3390 && load_force_doc_strings
)
3399 invalid_syntax (") or . in a vector", 18);
3407 XSETCDR (tail
, read0 (readcharfun
));
3409 val
= read0 (readcharfun
);
3410 read1 (readcharfun
, &ch
, 0);
3414 if (doc_reference
== 1)
3415 return make_number (0);
3416 if (doc_reference
== 2)
3418 /* Get a doc string from the file we are loading.
3419 If it's in saved_doc_string, get it from there.
3421 Here, we don't know if the string is a
3422 bytecode string or a doc string. As a
3423 bytecode string must be unibyte, we always
3424 return a unibyte string. If it is actually a
3425 doc string, caller must make it
3428 int pos
= XINT (XCDR (val
));
3429 /* Position is negative for user variables. */
3430 if (pos
< 0) pos
= -pos
;
3431 if (pos
>= saved_doc_string_position
3432 && pos
< (saved_doc_string_position
3433 + saved_doc_string_length
))
3435 int start
= pos
- saved_doc_string_position
;
3438 /* Process quoting with ^A,
3439 and find the end of the string,
3440 which is marked with ^_ (037). */
3441 for (from
= start
, to
= start
;
3442 saved_doc_string
[from
] != 037;)
3444 int c
= saved_doc_string
[from
++];
3447 c
= saved_doc_string
[from
++];
3449 saved_doc_string
[to
++] = c
;
3451 saved_doc_string
[to
++] = 0;
3453 saved_doc_string
[to
++] = 037;
3456 saved_doc_string
[to
++] = c
;
3459 return make_unibyte_string (saved_doc_string
+ start
,
3462 /* Look in prev_saved_doc_string the same way. */
3463 else if (pos
>= prev_saved_doc_string_position
3464 && pos
< (prev_saved_doc_string_position
3465 + prev_saved_doc_string_length
))
3467 int start
= pos
- prev_saved_doc_string_position
;
3470 /* Process quoting with ^A,
3471 and find the end of the string,
3472 which is marked with ^_ (037). */
3473 for (from
= start
, to
= start
;
3474 prev_saved_doc_string
[from
] != 037;)
3476 int c
= prev_saved_doc_string
[from
++];
3479 c
= prev_saved_doc_string
[from
++];
3481 prev_saved_doc_string
[to
++] = c
;
3483 prev_saved_doc_string
[to
++] = 0;
3485 prev_saved_doc_string
[to
++] = 037;
3488 prev_saved_doc_string
[to
++] = c
;
3491 return make_unibyte_string (prev_saved_doc_string
3496 return get_doc_string (val
, 1, 0);
3501 invalid_syntax (". in wrong context", 18);
3503 invalid_syntax ("] in a list", 11);
3505 tem
= (read_pure
&& flag
<= 0
3506 ? pure_cons (elt
, Qnil
)
3507 : Fcons (elt
, Qnil
));
3509 XSETCDR (tail
, tem
);
3514 defunflag
= EQ (elt
, Qdefun
);
3515 else if (defunflag
> 0)
3520 Lisp_Object Vobarray
;
3521 Lisp_Object initial_obarray
;
3523 /* oblookup stores the bucket number here, for the sake of Funintern. */
3525 int oblookup_last_bucket_number
;
3527 static int hash_string (const unsigned char *ptr
, int len
);
3529 /* Get an error if OBARRAY is not an obarray.
3530 If it is one, return it. */
3533 check_obarray (Lisp_Object obarray
)
3535 if (!VECTORP (obarray
) || XVECTOR (obarray
)->size
== 0)
3537 /* If Vobarray is now invalid, force it to be valid. */
3538 if (EQ (Vobarray
, obarray
)) Vobarray
= initial_obarray
;
3539 wrong_type_argument (Qvectorp
, obarray
);
3544 /* Intern the C string STR: return a symbol with that name,
3545 interned in the current obarray. */
3548 intern (const char *str
)
3551 int len
= strlen (str
);
3552 Lisp_Object obarray
;
3555 if (!VECTORP (obarray
) || XVECTOR (obarray
)->size
== 0)
3556 obarray
= check_obarray (obarray
);
3557 tem
= oblookup (obarray
, str
, len
, len
);
3560 return Fintern (make_string (str
, len
), obarray
);
3564 intern_c_string (const char *str
)
3567 int len
= strlen (str
);
3568 Lisp_Object obarray
;
3571 if (!VECTORP (obarray
) || XVECTOR (obarray
)->size
== 0)
3572 obarray
= check_obarray (obarray
);
3573 tem
= oblookup (obarray
, str
, len
, len
);
3577 if (NILP (Vpurify_flag
))
3578 /* Creating a non-pure string from a string literal not
3579 implemented yet. We could just use make_string here and live
3580 with the extra copy. */
3583 return Fintern (make_pure_c_string (str
), obarray
);
3586 /* Create an uninterned symbol with name STR. */
3589 make_symbol (char *str
)
3591 int len
= strlen (str
);
3593 return Fmake_symbol ((!NILP (Vpurify_flag
)
3594 ? make_pure_string (str
, len
, len
, 0)
3595 : make_string (str
, len
)));
3598 DEFUN ("intern", Fintern
, Sintern
, 1, 2, 0,
3599 doc
: /* Return the canonical symbol whose name is STRING.
3600 If there is none, one is created by this function and returned.
3601 A second optional argument specifies the obarray to use;
3602 it defaults to the value of `obarray'. */)
3603 (Lisp_Object string
, Lisp_Object obarray
)
3605 register Lisp_Object tem
, sym
, *ptr
;
3607 if (NILP (obarray
)) obarray
= Vobarray
;
3608 obarray
= check_obarray (obarray
);
3610 CHECK_STRING (string
);
3612 tem
= oblookup (obarray
, SDATA (string
),
3615 if (!INTEGERP (tem
))
3618 if (!NILP (Vpurify_flag
))
3619 string
= Fpurecopy (string
);
3620 sym
= Fmake_symbol (string
);
3622 if (EQ (obarray
, initial_obarray
))
3623 XSYMBOL (sym
)->interned
= SYMBOL_INTERNED_IN_INITIAL_OBARRAY
;
3625 XSYMBOL (sym
)->interned
= SYMBOL_INTERNED
;
3627 if ((SREF (string
, 0) == ':')
3628 && EQ (obarray
, initial_obarray
))
3630 XSYMBOL (sym
)->constant
= 1;
3631 XSYMBOL (sym
)->redirect
= SYMBOL_PLAINVAL
;
3632 SET_SYMBOL_VAL (XSYMBOL (sym
), sym
);
3635 ptr
= &XVECTOR (obarray
)->contents
[XINT (tem
)];
3637 XSYMBOL (sym
)->next
= XSYMBOL (*ptr
);
3639 XSYMBOL (sym
)->next
= 0;
3644 DEFUN ("intern-soft", Fintern_soft
, Sintern_soft
, 1, 2, 0,
3645 doc
: /* Return the canonical symbol named NAME, or nil if none exists.
3646 NAME may be a string or a symbol. If it is a symbol, that exact
3647 symbol is searched for.
3648 A second optional argument specifies the obarray to use;
3649 it defaults to the value of `obarray'. */)
3650 (Lisp_Object name
, Lisp_Object obarray
)
3652 register Lisp_Object tem
, string
;
3654 if (NILP (obarray
)) obarray
= Vobarray
;
3655 obarray
= check_obarray (obarray
);
3657 if (!SYMBOLP (name
))
3659 CHECK_STRING (name
);
3663 string
= SYMBOL_NAME (name
);
3665 tem
= oblookup (obarray
, SDATA (string
), SCHARS (string
), SBYTES (string
));
3666 if (INTEGERP (tem
) || (SYMBOLP (name
) && !EQ (name
, tem
)))
3672 DEFUN ("unintern", Funintern
, Sunintern
, 1, 2, 0,
3673 doc
: /* Delete the symbol named NAME, if any, from OBARRAY.
3674 The value is t if a symbol was found and deleted, nil otherwise.
3675 NAME may be a string or a symbol. If it is a symbol, that symbol
3676 is deleted, if it belongs to OBARRAY--no other symbol is deleted.
3677 OBARRAY defaults to the value of the variable `obarray'. */)
3678 (Lisp_Object name
, Lisp_Object obarray
)
3680 register Lisp_Object string
, tem
;
3683 if (NILP (obarray
)) obarray
= Vobarray
;
3684 obarray
= check_obarray (obarray
);
3687 string
= SYMBOL_NAME (name
);
3690 CHECK_STRING (name
);
3694 tem
= oblookup (obarray
, SDATA (string
),
3699 /* If arg was a symbol, don't delete anything but that symbol itself. */
3700 if (SYMBOLP (name
) && !EQ (name
, tem
))
3703 /* There are plenty of other symbols which will screw up the Emacs
3704 session if we unintern them, as well as even more ways to use
3705 `setq' or `fset' or whatnot to make the Emacs session
3706 unusable. Let's not go down this silly road. --Stef */
3707 /* if (EQ (tem, Qnil) || EQ (tem, Qt))
3708 error ("Attempt to unintern t or nil"); */
3710 XSYMBOL (tem
)->interned
= SYMBOL_UNINTERNED
;
3712 hash
= oblookup_last_bucket_number
;
3714 if (EQ (XVECTOR (obarray
)->contents
[hash
], tem
))
3716 if (XSYMBOL (tem
)->next
)
3717 XSETSYMBOL (XVECTOR (obarray
)->contents
[hash
], XSYMBOL (tem
)->next
);
3719 XSETINT (XVECTOR (obarray
)->contents
[hash
], 0);
3723 Lisp_Object tail
, following
;
3725 for (tail
= XVECTOR (obarray
)->contents
[hash
];
3726 XSYMBOL (tail
)->next
;
3729 XSETSYMBOL (following
, XSYMBOL (tail
)->next
);
3730 if (EQ (following
, tem
))
3732 XSYMBOL (tail
)->next
= XSYMBOL (following
)->next
;
3741 /* Return the symbol in OBARRAY whose names matches the string
3742 of SIZE characters (SIZE_BYTE bytes) at PTR.
3743 If there is no such symbol in OBARRAY, return nil.
3745 Also store the bucket number in oblookup_last_bucket_number. */
3748 oblookup (Lisp_Object obarray
, register const char *ptr
, int size
, int size_byte
)
3752 register Lisp_Object tail
;
3753 Lisp_Object bucket
, tem
;
3755 if (!VECTORP (obarray
)
3756 || (obsize
= XVECTOR (obarray
)->size
) == 0)
3758 obarray
= check_obarray (obarray
);
3759 obsize
= XVECTOR (obarray
)->size
;
3761 /* This is sometimes needed in the middle of GC. */
3762 obsize
&= ~ARRAY_MARK_FLAG
;
3763 hash
= hash_string (ptr
, size_byte
) % obsize
;
3764 bucket
= XVECTOR (obarray
)->contents
[hash
];
3765 oblookup_last_bucket_number
= hash
;
3766 if (EQ (bucket
, make_number (0)))
3768 else if (!SYMBOLP (bucket
))
3769 error ("Bad data in guts of obarray"); /* Like CADR error message */
3771 for (tail
= bucket
; ; XSETSYMBOL (tail
, XSYMBOL (tail
)->next
))
3773 if (SBYTES (SYMBOL_NAME (tail
)) == size_byte
3774 && SCHARS (SYMBOL_NAME (tail
)) == size
3775 && !memcmp (SDATA (SYMBOL_NAME (tail
)), ptr
, size_byte
))
3777 else if (XSYMBOL (tail
)->next
== 0)
3780 XSETINT (tem
, hash
);
3785 hash_string (const unsigned char *ptr
, int len
)
3787 register const unsigned char *p
= ptr
;
3788 register const unsigned char *end
= p
+ len
;
3789 register unsigned char c
;
3790 register int hash
= 0;
3795 if (c
>= 0140) c
-= 40;
3796 hash
= ((hash
<<3) + (hash
>>28) + c
);
3798 return hash
& 07777777777;
3802 map_obarray (Lisp_Object obarray
, void (*fn
) (Lisp_Object
, Lisp_Object
), Lisp_Object arg
)
3805 register Lisp_Object tail
;
3806 CHECK_VECTOR (obarray
);
3807 for (i
= XVECTOR (obarray
)->size
- 1; i
>= 0; i
--)
3809 tail
= XVECTOR (obarray
)->contents
[i
];
3814 if (XSYMBOL (tail
)->next
== 0)
3816 XSETSYMBOL (tail
, XSYMBOL (tail
)->next
);
3822 mapatoms_1 (Lisp_Object sym
, Lisp_Object function
)
3824 call1 (function
, sym
);
3827 DEFUN ("mapatoms", Fmapatoms
, Smapatoms
, 1, 2, 0,
3828 doc
: /* Call FUNCTION on every symbol in OBARRAY.
3829 OBARRAY defaults to the value of `obarray'. */)
3830 (Lisp_Object function
, Lisp_Object obarray
)
3832 if (NILP (obarray
)) obarray
= Vobarray
;
3833 obarray
= check_obarray (obarray
);
3835 map_obarray (obarray
, mapatoms_1
, function
);
3839 #define OBARRAY_SIZE 1511
3844 Lisp_Object oblength
;
3846 XSETFASTINT (oblength
, OBARRAY_SIZE
);
3848 Vobarray
= Fmake_vector (oblength
, make_number (0));
3849 initial_obarray
= Vobarray
;
3850 staticpro (&initial_obarray
);
3852 Qunbound
= Fmake_symbol (make_pure_c_string ("unbound"));
3853 /* Set temporary dummy values to Qnil and Vpurify_flag to satisfy the
3854 NILP (Vpurify_flag) check in intern_c_string. */
3855 Qnil
= make_number (-1); Vpurify_flag
= make_number (1);
3856 Qnil
= intern_c_string ("nil");
3858 /* Fmake_symbol inits fields of new symbols with Qunbound and Qnil,
3859 so those two need to be fixed manally. */
3860 SET_SYMBOL_VAL (XSYMBOL (Qunbound
), Qunbound
);
3861 XSYMBOL (Qunbound
)->function
= Qunbound
;
3862 XSYMBOL (Qunbound
)->plist
= Qnil
;
3863 /* XSYMBOL (Qnil)->function = Qunbound; */
3864 SET_SYMBOL_VAL (XSYMBOL (Qnil
), Qnil
);
3865 XSYMBOL (Qnil
)->constant
= 1;
3866 XSYMBOL (Qnil
)->plist
= Qnil
;
3868 Qt
= intern_c_string ("t");
3869 SET_SYMBOL_VAL (XSYMBOL (Qt
), Qt
);
3870 XSYMBOL (Qt
)->constant
= 1;
3872 /* Qt is correct even if CANNOT_DUMP. loadup.el will set to nil at end. */
3875 Qvariable_documentation
= intern_c_string ("variable-documentation");
3876 staticpro (&Qvariable_documentation
);
3878 read_buffer_size
= 100 + MAX_MULTIBYTE_LENGTH
;
3879 read_buffer
= (char *) xmalloc (read_buffer_size
);
3883 defsubr (struct Lisp_Subr
*sname
)
3886 sym
= intern_c_string (sname
->symbol_name
);
3887 XSETPVECTYPE (sname
, PVEC_SUBR
);
3888 XSETSUBR (XSYMBOL (sym
)->function
, sname
);
3891 #ifdef NOTDEF /* use fset in subr.el now */
3893 defalias (sname
, string
)
3894 struct Lisp_Subr
*sname
;
3898 sym
= intern (string
);
3899 XSETSUBR (XSYMBOL (sym
)->function
, sname
);
3903 /* Define an "integer variable"; a symbol whose value is forwarded
3904 to a C variable of type int. Sample call:
3905 DEFVAR_INT ("emacs-priority", &emacs_priority, "Documentation"); */
3907 defvar_int (struct Lisp_Intfwd
*i_fwd
,
3908 const char *namestring
, EMACS_INT
*address
)
3911 sym
= intern_c_string (namestring
);
3912 i_fwd
->type
= Lisp_Fwd_Int
;
3913 i_fwd
->intvar
= address
;
3914 XSYMBOL (sym
)->redirect
= SYMBOL_FORWARDED
;
3915 SET_SYMBOL_FWD (XSYMBOL (sym
), (union Lisp_Fwd
*)i_fwd
);
3918 /* Similar but define a variable whose value is t if address contains 1,
3919 nil if address contains 0. */
3921 defvar_bool (struct Lisp_Boolfwd
*b_fwd
,
3922 const char *namestring
, int *address
)
3925 sym
= intern_c_string (namestring
);
3926 b_fwd
->type
= Lisp_Fwd_Bool
;
3927 b_fwd
->boolvar
= address
;
3928 XSYMBOL (sym
)->redirect
= SYMBOL_FORWARDED
;
3929 SET_SYMBOL_FWD (XSYMBOL (sym
), (union Lisp_Fwd
*)b_fwd
);
3930 Vbyte_boolean_vars
= Fcons (sym
, Vbyte_boolean_vars
);
3933 /* Similar but define a variable whose value is the Lisp Object stored
3934 at address. Two versions: with and without gc-marking of the C
3935 variable. The nopro version is used when that variable will be
3936 gc-marked for some other reason, since marking the same slot twice
3937 can cause trouble with strings. */
3939 defvar_lisp_nopro (struct Lisp_Objfwd
*o_fwd
,
3940 const char *namestring
, Lisp_Object
*address
)
3943 sym
= intern_c_string (namestring
);
3944 o_fwd
->type
= Lisp_Fwd_Obj
;
3945 o_fwd
->objvar
= address
;
3946 XSYMBOL (sym
)->redirect
= SYMBOL_FORWARDED
;
3947 SET_SYMBOL_FWD (XSYMBOL (sym
), (union Lisp_Fwd
*)o_fwd
);
3951 defvar_lisp (struct Lisp_Objfwd
*o_fwd
,
3952 const char *namestring
, Lisp_Object
*address
)
3954 defvar_lisp_nopro (o_fwd
, namestring
, address
);
3955 staticpro (address
);
3958 /* Similar but define a variable whose value is the Lisp Object stored
3959 at a particular offset in the current kboard object. */
3962 defvar_kboard (struct Lisp_Kboard_Objfwd
*ko_fwd
,
3963 const char *namestring
, int offset
)
3966 sym
= intern_c_string (namestring
);
3967 ko_fwd
->type
= Lisp_Fwd_Kboard_Obj
;
3968 ko_fwd
->offset
= offset
;
3969 XSYMBOL (sym
)->redirect
= SYMBOL_FORWARDED
;
3970 SET_SYMBOL_FWD (XSYMBOL (sym
), (union Lisp_Fwd
*)ko_fwd
);
3973 /* Record the value of load-path used at the start of dumping
3974 so we can see if the site changed it later during dumping. */
3975 static Lisp_Object dump_path
;
3981 int turn_off_warning
= 0;
3983 /* Compute the default load-path. */
3985 normal
= PATH_LOADSEARCH
;
3986 Vload_path
= decode_env_path (0, normal
);
3988 if (NILP (Vpurify_flag
))
3989 normal
= PATH_LOADSEARCH
;
3991 normal
= PATH_DUMPLOADSEARCH
;
3993 /* In a dumped Emacs, we normally have to reset the value of
3994 Vload_path from PATH_LOADSEARCH, since the value that was dumped
3995 uses ../lisp, instead of the path of the installed elisp
3996 libraries. However, if it appears that Vload_path was changed
3997 from the default before dumping, don't override that value. */
4000 if (! NILP (Fequal (dump_path
, Vload_path
)))
4002 Vload_path
= decode_env_path (0, normal
);
4003 if (!NILP (Vinstallation_directory
))
4005 Lisp_Object tem
, tem1
, sitelisp
;
4007 /* Remove site-lisp dirs from path temporarily and store
4008 them in sitelisp, then conc them on at the end so
4009 they're always first in path. */
4013 tem
= Fcar (Vload_path
);
4014 tem1
= Fstring_match (build_string ("site-lisp"),
4018 Vload_path
= Fcdr (Vload_path
);
4019 sitelisp
= Fcons (tem
, sitelisp
);
4025 /* Add to the path the lisp subdir of the
4026 installation dir, if it exists. */
4027 tem
= Fexpand_file_name (build_string ("lisp"),
4028 Vinstallation_directory
);
4029 tem1
= Ffile_exists_p (tem
);
4032 if (NILP (Fmember (tem
, Vload_path
)))
4034 turn_off_warning
= 1;
4035 Vload_path
= Fcons (tem
, Vload_path
);
4039 /* That dir doesn't exist, so add the build-time
4040 Lisp dirs instead. */
4041 Vload_path
= nconc2 (Vload_path
, dump_path
);
4043 /* Add leim under the installation dir, if it exists. */
4044 tem
= Fexpand_file_name (build_string ("leim"),
4045 Vinstallation_directory
);
4046 tem1
= Ffile_exists_p (tem
);
4049 if (NILP (Fmember (tem
, Vload_path
)))
4050 Vload_path
= Fcons (tem
, Vload_path
);
4053 /* Add site-lisp under the installation dir, if it exists. */
4054 tem
= Fexpand_file_name (build_string ("site-lisp"),
4055 Vinstallation_directory
);
4056 tem1
= Ffile_exists_p (tem
);
4059 if (NILP (Fmember (tem
, Vload_path
)))
4060 Vload_path
= Fcons (tem
, Vload_path
);
4063 /* If Emacs was not built in the source directory,
4064 and it is run from where it was built, add to load-path
4065 the lisp, leim and site-lisp dirs under that directory. */
4067 if (NILP (Fequal (Vinstallation_directory
, Vsource_directory
)))
4071 tem
= Fexpand_file_name (build_string ("src/Makefile"),
4072 Vinstallation_directory
);
4073 tem1
= Ffile_exists_p (tem
);
4075 /* Don't be fooled if they moved the entire source tree
4076 AFTER dumping Emacs. If the build directory is indeed
4077 different from the source dir, src/Makefile.in and
4078 src/Makefile will not be found together. */
4079 tem
= Fexpand_file_name (build_string ("src/Makefile.in"),
4080 Vinstallation_directory
);
4081 tem2
= Ffile_exists_p (tem
);
4082 if (!NILP (tem1
) && NILP (tem2
))
4084 tem
= Fexpand_file_name (build_string ("lisp"),
4087 if (NILP (Fmember (tem
, Vload_path
)))
4088 Vload_path
= Fcons (tem
, Vload_path
);
4090 tem
= Fexpand_file_name (build_string ("leim"),
4093 if (NILP (Fmember (tem
, Vload_path
)))
4094 Vload_path
= Fcons (tem
, Vload_path
);
4096 tem
= Fexpand_file_name (build_string ("site-lisp"),
4099 if (NILP (Fmember (tem
, Vload_path
)))
4100 Vload_path
= Fcons (tem
, Vload_path
);
4103 if (!NILP (sitelisp
))
4104 Vload_path
= nconc2 (Fnreverse (sitelisp
), Vload_path
);
4110 /* NORMAL refers to the lisp dir in the source directory. */
4111 /* We used to add ../lisp at the front here, but
4112 that caused trouble because it was copied from dump_path
4113 into Vload_path, above, when Vinstallation_directory was non-nil.
4114 It should be unnecessary. */
4115 Vload_path
= decode_env_path (0, normal
);
4116 dump_path
= Vload_path
;
4120 #if (!(defined (WINDOWSNT) || (defined (HAVE_NS))))
4121 /* When Emacs is invoked over network shares on NT, PATH_LOADSEARCH is
4122 almost never correct, thereby causing a warning to be printed out that
4123 confuses users. Since PATH_LOADSEARCH is always overridden by the
4124 EMACSLOADPATH environment variable below, disable the warning on NT. */
4126 /* Warn if dirs in the *standard* path don't exist. */
4127 if (!turn_off_warning
)
4129 Lisp_Object path_tail
;
4131 for (path_tail
= Vload_path
;
4133 path_tail
= XCDR (path_tail
))
4135 Lisp_Object dirfile
;
4136 dirfile
= Fcar (path_tail
);
4137 if (STRINGP (dirfile
))
4139 dirfile
= Fdirectory_file_name (dirfile
);
4140 if (access (SDATA (dirfile
), 0) < 0)
4141 dir_warning ("Warning: Lisp directory `%s' does not exist.\n",
4146 #endif /* !(WINDOWSNT || HAVE_NS) */
4148 /* If the EMACSLOADPATH environment variable is set, use its value.
4149 This doesn't apply if we're dumping. */
4151 if (NILP (Vpurify_flag
)
4152 && egetenv ("EMACSLOADPATH"))
4154 Vload_path
= decode_env_path ("EMACSLOADPATH", normal
);
4158 load_in_progress
= 0;
4159 Vload_file_name
= Qnil
;
4161 load_descriptor_list
= Qnil
;
4163 Vstandard_input
= Qt
;
4164 Vloads_in_progress
= Qnil
;
4167 /* Print a warning, using format string FORMAT, that directory DIRNAME
4168 does not exist. Print it on stderr and put it in *Messages*. */
4171 dir_warning (char *format
, Lisp_Object dirname
)
4174 = (char *) alloca (SCHARS (dirname
) + strlen (format
) + 5);
4176 fprintf (stderr
, format
, SDATA (dirname
));
4177 sprintf (buffer
, format
, SDATA (dirname
));
4178 /* Don't log the warning before we've initialized!! */
4180 message_dolog (buffer
, strlen (buffer
), 0, STRING_MULTIBYTE (dirname
));
4184 syms_of_lread (void)
4187 defsubr (&Sread_from_string
);
4189 defsubr (&Sintern_soft
);
4190 defsubr (&Sunintern
);
4191 defsubr (&Sget_load_suffixes
);
4193 defsubr (&Seval_buffer
);
4194 defsubr (&Seval_region
);
4195 defsubr (&Sread_char
);
4196 defsubr (&Sread_char_exclusive
);
4197 defsubr (&Sread_event
);
4198 defsubr (&Sget_file_char
);
4199 defsubr (&Smapatoms
);
4200 defsubr (&Slocate_file_internal
);
4202 DEFVAR_LISP ("obarray", &Vobarray
,
4203 doc
: /* Symbol table for use by `intern' and `read'.
4204 It is a vector whose length ought to be prime for best results.
4205 The vector's contents don't make sense if examined from Lisp programs;
4206 to find all the symbols in an obarray, use `mapatoms'. */);
4208 DEFVAR_LISP ("values", &Vvalues
,
4209 doc
: /* List of values of all expressions which were read, evaluated and printed.
4210 Order is reverse chronological. */);
4212 DEFVAR_LISP ("standard-input", &Vstandard_input
,
4213 doc
: /* Stream for read to get input from.
4214 See documentation of `read' for possible values. */);
4215 Vstandard_input
= Qt
;
4217 DEFVAR_LISP ("read-with-symbol-positions", &Vread_with_symbol_positions
,
4218 doc
: /* If non-nil, add position of read symbols to `read-symbol-positions-list'.
4220 If this variable is a buffer, then only forms read from that buffer
4221 will be added to `read-symbol-positions-list'.
4222 If this variable is t, then all read forms will be added.
4223 The effect of all other values other than nil are not currently
4224 defined, although they may be in the future.
4226 The positions are relative to the last call to `read' or
4227 `read-from-string'. It is probably a bad idea to set this variable at
4228 the toplevel; bind it instead. */);
4229 Vread_with_symbol_positions
= Qnil
;
4231 DEFVAR_LISP ("read-symbol-positions-list", &Vread_symbol_positions_list
,
4232 doc
: /* A list mapping read symbols to their positions.
4233 This variable is modified during calls to `read' or
4234 `read-from-string', but only when `read-with-symbol-positions' is
4237 Each element of the list looks like (SYMBOL . CHAR-POSITION), where
4238 CHAR-POSITION is an integer giving the offset of that occurrence of the
4239 symbol from the position where `read' or `read-from-string' started.
4241 Note that a symbol will appear multiple times in this list, if it was
4242 read multiple times. The list is in the same order as the symbols
4244 Vread_symbol_positions_list
= Qnil
;
4246 DEFVAR_LISP ("read-circle", &Vread_circle
,
4247 doc
: /* Non-nil means read recursive structures using #N= and #N# syntax. */);
4250 DEFVAR_LISP ("load-path", &Vload_path
,
4251 doc
: /* *List of directories to search for files to load.
4252 Each element is a string (directory name) or nil (try default directory).
4253 Initialized based on EMACSLOADPATH environment variable, if any,
4254 otherwise to default specified by file `epaths.h' when Emacs was built. */);
4256 DEFVAR_LISP ("load-suffixes", &Vload_suffixes
,
4257 doc
: /* List of suffixes for (compiled or source) Emacs Lisp files.
4258 This list should not include the empty string.
4259 `load' and related functions try to append these suffixes, in order,
4260 to the specified file name if a Lisp suffix is allowed or required. */);
4261 Vload_suffixes
= Fcons (make_pure_c_string (".elc"),
4262 Fcons (make_pure_c_string (".el"), Qnil
));
4263 DEFVAR_LISP ("load-file-rep-suffixes", &Vload_file_rep_suffixes
,
4264 doc
: /* List of suffixes that indicate representations of \
4266 This list should normally start with the empty string.
4268 Enabling Auto Compression mode appends the suffixes in
4269 `jka-compr-load-suffixes' to this list and disabling Auto Compression
4270 mode removes them again. `load' and related functions use this list to
4271 determine whether they should look for compressed versions of a file
4272 and, if so, which suffixes they should try to append to the file name
4273 in order to do so. However, if you want to customize which suffixes
4274 the loading functions recognize as compression suffixes, you should
4275 customize `jka-compr-load-suffixes' rather than the present variable. */);
4276 Vload_file_rep_suffixes
= Fcons (empty_unibyte_string
, Qnil
);
4278 DEFVAR_BOOL ("load-in-progress", &load_in_progress
,
4279 doc
: /* Non-nil if inside of `load'. */);
4280 Qload_in_progress
= intern_c_string ("load-in-progress");
4281 staticpro (&Qload_in_progress
);
4283 DEFVAR_LISP ("after-load-alist", &Vafter_load_alist
,
4284 doc
: /* An alist of expressions to be evalled when particular files are loaded.
4285 Each element looks like (REGEXP-OR-FEATURE FORMS...).
4287 REGEXP-OR-FEATURE is either a regular expression to match file names, or
4288 a symbol \(a feature name).
4290 When `load' is run and the file-name argument matches an element's
4291 REGEXP-OR-FEATURE, or when `provide' is run and provides the symbol
4292 REGEXP-OR-FEATURE, the FORMS in the element are executed.
4294 An error in FORMS does not undo the load, but does prevent execution of
4295 the rest of the FORMS. */);
4296 Vafter_load_alist
= Qnil
;
4298 DEFVAR_LISP ("load-history", &Vload_history
,
4299 doc
: /* Alist mapping loaded file names to symbols and features.
4300 Each alist element should be a list (FILE-NAME ENTRIES...), where
4301 FILE-NAME is the name of a file that has been loaded into Emacs.
4302 The file name is absolute and true (i.e. it doesn't contain symlinks).
4303 As an exception, one of the alist elements may have FILE-NAME nil,
4304 for symbols and features not associated with any file.
4306 The remaining ENTRIES in the alist element describe the functions and
4307 variables defined in that file, the features provided, and the
4308 features required. Each entry has the form `(provide . FEATURE)',
4309 `(require . FEATURE)', `(defun . FUNCTION)', `(autoload . SYMBOL)',
4310 `(defface . SYMBOL)', or `(t . SYMBOL)'. In addition, an entry `(t
4311 . SYMBOL)' may precede an entry `(defun . FUNCTION)', and means that
4312 SYMBOL was an autoload before this file redefined it as a function.
4314 During preloading, the file name recorded is relative to the main Lisp
4315 directory. These file names are converted to absolute at startup. */);
4316 Vload_history
= Qnil
;
4318 DEFVAR_LISP ("load-file-name", &Vload_file_name
,
4319 doc
: /* Full name of file being loaded by `load'. */);
4320 Vload_file_name
= Qnil
;
4322 DEFVAR_LISP ("user-init-file", &Vuser_init_file
,
4323 doc
: /* File name, including directory, of user's initialization file.
4324 If the file loaded had extension `.elc', and the corresponding source file
4325 exists, this variable contains the name of source file, suitable for use
4326 by functions like `custom-save-all' which edit the init file.
4327 While Emacs loads and evaluates the init file, value is the real name
4328 of the file, regardless of whether or not it has the `.elc' extension. */);
4329 Vuser_init_file
= Qnil
;
4331 DEFVAR_LISP ("current-load-list", &Vcurrent_load_list
,
4332 doc
: /* Used for internal purposes by `load'. */);
4333 Vcurrent_load_list
= Qnil
;
4335 DEFVAR_LISP ("load-read-function", &Vload_read_function
,
4336 doc
: /* Function used by `load' and `eval-region' for reading expressions.
4337 The default is nil, which means use the function `read'. */);
4338 Vload_read_function
= Qnil
;
4340 DEFVAR_LISP ("load-source-file-function", &Vload_source_file_function
,
4341 doc
: /* Function called in `load' for loading an Emacs Lisp source file.
4342 This function is for doing code conversion before reading the source file.
4343 If nil, loading is done without any code conversion.
4344 Arguments are FULLNAME, FILE, NOERROR, NOMESSAGE, where
4345 FULLNAME is the full name of FILE.
4346 See `load' for the meaning of the remaining arguments. */);
4347 Vload_source_file_function
= Qnil
;
4349 DEFVAR_BOOL ("load-force-doc-strings", &load_force_doc_strings
,
4350 doc
: /* Non-nil means `load' should force-load all dynamic doc strings.
4351 This is useful when the file being loaded is a temporary copy. */);
4352 load_force_doc_strings
= 0;
4354 DEFVAR_BOOL ("load-convert-to-unibyte", &load_convert_to_unibyte
,
4355 doc
: /* Non-nil means `read' converts strings to unibyte whenever possible.
4356 This is normally bound by `load' and `eval-buffer' to control `read',
4357 and is not meant for users to change. */);
4358 load_convert_to_unibyte
= 0;
4360 DEFVAR_LISP ("source-directory", &Vsource_directory
,
4361 doc
: /* Directory in which Emacs sources were found when Emacs was built.
4362 You cannot count on them to still be there! */);
4364 = Fexpand_file_name (build_string ("../"),
4365 Fcar (decode_env_path (0, PATH_DUMPLOADSEARCH
)));
4367 DEFVAR_LISP ("preloaded-file-list", &Vpreloaded_file_list
,
4368 doc
: /* List of files that were preloaded (when dumping Emacs). */);
4369 Vpreloaded_file_list
= Qnil
;
4371 DEFVAR_LISP ("byte-boolean-vars", &Vbyte_boolean_vars
,
4372 doc
: /* List of all DEFVAR_BOOL variables, used by the byte code optimizer. */);
4373 Vbyte_boolean_vars
= Qnil
;
4375 DEFVAR_BOOL ("load-dangerous-libraries", &load_dangerous_libraries
,
4376 doc
: /* Non-nil means load dangerous compiled Lisp files.
4377 Some versions of XEmacs use different byte codes than Emacs. These
4378 incompatible byte codes can make Emacs crash when it tries to execute
4380 load_dangerous_libraries
= 0;
4382 DEFVAR_BOOL ("force-load-messages", &force_load_messages
,
4383 doc
: /* Non-nil means force printing messages when loading Lisp files.
4384 This overrides the value of the NOMESSAGE argument to `load'. */);
4385 force_load_messages
= 0;
4387 DEFVAR_LISP ("bytecomp-version-regexp", &Vbytecomp_version_regexp
,
4388 doc
: /* Regular expression matching safe to load compiled Lisp files.
4389 When Emacs loads a compiled Lisp file, it reads the first 512 bytes
4390 from the file, and matches them against this regular expression.
4391 When the regular expression matches, the file is considered to be safe
4392 to load. See also `load-dangerous-libraries'. */);
4393 Vbytecomp_version_regexp
4394 = make_pure_c_string ("^;;;.\\(in Emacs version\\|bytecomp version FSF\\)");
4396 DEFVAR_LISP ("eval-buffer-list", &Veval_buffer_list
,
4397 doc
: /* List of buffers being read from by calls to `eval-buffer' and `eval-region'. */);
4398 Veval_buffer_list
= Qnil
;
4400 DEFVAR_LISP ("old-style-backquotes", &Vold_style_backquotes
,
4401 doc
: /* Set to non-nil when `read' encounters an old-style backquote. */);
4402 Vold_style_backquotes
= Qnil
;
4403 Qold_style_backquotes
= intern_c_string ("old-style-backquotes");
4404 staticpro (&Qold_style_backquotes
);
4406 /* Vsource_directory was initialized in init_lread. */
4408 load_descriptor_list
= Qnil
;
4409 staticpro (&load_descriptor_list
);
4411 Qcurrent_load_list
= intern_c_string ("current-load-list");
4412 staticpro (&Qcurrent_load_list
);
4414 Qstandard_input
= intern_c_string ("standard-input");
4415 staticpro (&Qstandard_input
);
4417 Qread_char
= intern_c_string ("read-char");
4418 staticpro (&Qread_char
);
4420 Qget_file_char
= intern_c_string ("get-file-char");
4421 staticpro (&Qget_file_char
);
4423 Qget_emacs_mule_file_char
= intern_c_string ("get-emacs-mule-file-char");
4424 staticpro (&Qget_emacs_mule_file_char
);
4426 Qload_force_doc_strings
= intern_c_string ("load-force-doc-strings");
4427 staticpro (&Qload_force_doc_strings
);
4429 Qbackquote
= intern_c_string ("`");
4430 staticpro (&Qbackquote
);
4431 Qcomma
= intern_c_string (",");
4432 staticpro (&Qcomma
);
4433 Qcomma_at
= intern_c_string (",@");
4434 staticpro (&Qcomma_at
);
4435 Qcomma_dot
= intern_c_string (",.");
4436 staticpro (&Qcomma_dot
);
4438 Qinhibit_file_name_operation
= intern_c_string ("inhibit-file-name-operation");
4439 staticpro (&Qinhibit_file_name_operation
);
4441 Qascii_character
= intern_c_string ("ascii-character");
4442 staticpro (&Qascii_character
);
4444 Qfunction
= intern_c_string ("function");
4445 staticpro (&Qfunction
);
4447 Qload
= intern_c_string ("load");
4450 Qload_file_name
= intern_c_string ("load-file-name");
4451 staticpro (&Qload_file_name
);
4453 Qeval_buffer_list
= intern_c_string ("eval-buffer-list");
4454 staticpro (&Qeval_buffer_list
);
4456 Qfile_truename
= intern_c_string ("file-truename");
4457 staticpro (&Qfile_truename
) ;
4459 Qdo_after_load_evaluation
= intern_c_string ("do-after-load-evaluation");
4460 staticpro (&Qdo_after_load_evaluation
) ;
4462 staticpro (&dump_path
);
4464 staticpro (&read_objects
);
4465 read_objects
= Qnil
;
4466 staticpro (&seen_list
);
4469 Vloads_in_progress
= Qnil
;
4470 staticpro (&Vloads_in_progress
);
4472 Qhash_table
= intern_c_string ("hash-table");
4473 staticpro (&Qhash_table
);
4474 Qdata
= intern_c_string ("data");
4476 Qtest
= intern_c_string ("test");
4478 Qsize
= intern_c_string ("size");
4480 Qweakness
= intern_c_string ("weakness");
4481 staticpro (&Qweakness
);
4482 Qrehash_size
= intern_c_string ("rehash-size");
4483 staticpro (&Qrehash_size
);
4484 Qrehash_threshold
= intern_c_string ("rehash-threshold");
4485 staticpro (&Qrehash_threshold
);
4488 /* arch-tag: a0d02733-0f96-4844-a659-9fd53c4f414d
4489 (do not change this comment) */