1 /* Lisp parsing and input streams.
2 Copyright (C) 1985, 86, 87, 88, 89, 93, 94, 95, 97, 98, 99, 2000, 2001
3 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
25 #include <sys/types.h>
30 #include "intervals.h"
36 #include "termhooks.h"
39 #include <sys/inode.h>
44 #include <unistd.h> /* to get X_OK */
61 #endif /* HAVE_SETLOCALE */
68 #define file_offset off_t
69 #define file_tell ftello
71 #define file_offset long
72 #define file_tell ftell
79 Lisp_Object Qread_char
, Qget_file_char
, Qstandard_input
, Qcurrent_load_list
;
80 Lisp_Object Qvariable_documentation
, Vvalues
, Vstandard_input
, Vafter_load_alist
;
81 Lisp_Object Qascii_character
, Qload
, Qload_file_name
;
82 Lisp_Object Qbackquote
, Qcomma
, Qcomma_at
, Qcomma_dot
, Qfunction
;
83 Lisp_Object Qinhibit_file_name_operation
;
85 extern Lisp_Object Qevent_symbol_element_mask
;
86 extern Lisp_Object Qfile_exists_p
;
88 /* non-zero if inside `load' */
91 /* Directory in which the sources were found. */
92 Lisp_Object Vsource_directory
;
94 /* Search path for files to be loaded. */
95 Lisp_Object Vload_path
;
97 /* File name of user's init file. */
98 Lisp_Object Vuser_init_file
;
100 /* This is the user-visible association list that maps features to
101 lists of defs in their load files. */
102 Lisp_Object Vload_history
;
104 /* This is used to build the load history. */
105 Lisp_Object Vcurrent_load_list
;
107 /* List of files that were preloaded. */
108 Lisp_Object Vpreloaded_file_list
;
110 /* Name of file actually being read by `load'. */
111 Lisp_Object Vload_file_name
;
113 /* Function to use for reading, in `load' and friends. */
114 Lisp_Object Vload_read_function
;
116 /* The association list of objects read with the #n=object form.
117 Each member of the list has the form (n . object), and is used to
118 look up the object for the corresponding #n# construct.
119 It must be set to nil before all top-level calls to read0. */
120 Lisp_Object read_objects
;
122 /* Nonzero means load should forcibly load all dynamic doc strings. */
123 static int load_force_doc_strings
;
125 /* Nonzero means read should convert strings to unibyte. */
126 static int load_convert_to_unibyte
;
128 /* Function to use for loading an Emacs lisp source file (not
129 compiled) instead of readevalloop. */
130 Lisp_Object Vload_source_file_function
;
132 /* List of all DEFVAR_BOOL variables. Used by the byte optimizer. */
133 Lisp_Object Vbyte_boolean_vars
;
135 /* List of descriptors now open for Fload. */
136 static Lisp_Object load_descriptor_list
;
138 /* File for get_file_char to read from. Use by load. */
139 static FILE *instream
;
141 /* When nonzero, read conses in pure space */
142 static int read_pure
;
144 /* For use within read-from-string (this reader is non-reentrant!!) */
145 static int read_from_string_index
;
146 static int read_from_string_index_byte
;
147 static int read_from_string_limit
;
149 /* Number of bytes left to read in the buffer character
150 that `readchar' has already advanced over. */
151 static int readchar_backlog
;
153 /* This contains the last string skipped with #@. */
154 static char *saved_doc_string
;
155 /* Length of buffer allocated in saved_doc_string. */
156 static int saved_doc_string_size
;
157 /* Length of actual data in saved_doc_string. */
158 static int saved_doc_string_length
;
159 /* This is the file position that string came from. */
160 static file_offset saved_doc_string_position
;
162 /* This contains the previous string skipped with #@.
163 We copy it from saved_doc_string when a new string
164 is put in saved_doc_string. */
165 static char *prev_saved_doc_string
;
166 /* Length of buffer allocated in prev_saved_doc_string. */
167 static int prev_saved_doc_string_size
;
168 /* Length of actual data in prev_saved_doc_string. */
169 static int prev_saved_doc_string_length
;
170 /* This is the file position that string came from. */
171 static file_offset prev_saved_doc_string_position
;
173 /* Nonzero means inside a new-style backquote
174 with no surrounding parentheses.
175 Fread initializes this to zero, so we need not specbind it
176 or worry about what happens to it when there is an error. */
177 static int new_backquote_flag
;
179 /* A list of file names for files being loaded in Fload. Used to
180 check for recursive loads. */
182 static Lisp_Object Vloads_in_progress
;
184 /* Limit of the depth of recursive loads. */
186 Lisp_Object Vrecursive_load_depth_limit
;
188 /* Non-zero means load dangerous compiled Lisp files. */
190 int load_dangerous_libraries
;
192 /* A regular expression used to detect files compiled with Emacs. */
194 static Lisp_Object Vbytecomp_version_regexp
;
196 static void readevalloop
P_ ((Lisp_Object
, FILE*, Lisp_Object
,
197 Lisp_Object (*) (), int,
198 Lisp_Object
, Lisp_Object
));
199 static Lisp_Object load_unwind
P_ ((Lisp_Object
));
200 static Lisp_Object load_descriptor_unwind
P_ ((Lisp_Object
));
203 /* Handle unreading and rereading of characters.
204 Write READCHAR to read a character,
205 UNREAD(c) to unread c to be read again.
207 These macros actually read/unread a byte code, multibyte characters
208 are not handled here. The caller should manage them if necessary.
211 #define READCHAR readchar (readcharfun)
212 #define UNREAD(c) unreadchar (readcharfun, c)
215 readchar (readcharfun
)
216 Lisp_Object readcharfun
;
221 if (BUFFERP (readcharfun
))
223 register struct buffer
*inbuffer
= XBUFFER (readcharfun
);
225 int pt_byte
= BUF_PT_BYTE (inbuffer
);
226 int orig_pt_byte
= pt_byte
;
228 if (readchar_backlog
> 0)
229 /* We get the address of the byte just passed,
230 which is the last byte of the character.
231 The other bytes in this character are consecutive with it,
232 because the gap can't be in the middle of a character. */
233 return *(BUF_BYTE_ADDRESS (inbuffer
, BUF_PT_BYTE (inbuffer
) - 1)
234 - --readchar_backlog
);
236 if (pt_byte
>= BUF_ZV_BYTE (inbuffer
))
239 readchar_backlog
= -1;
241 if (! NILP (inbuffer
->enable_multibyte_characters
))
243 /* Fetch the character code from the buffer. */
244 unsigned char *p
= BUF_BYTE_ADDRESS (inbuffer
, pt_byte
);
245 BUF_INC_POS (inbuffer
, pt_byte
);
246 c
= STRING_CHAR (p
, pt_byte
- orig_pt_byte
);
250 c
= BUF_FETCH_BYTE (inbuffer
, pt_byte
);
253 SET_BUF_PT_BOTH (inbuffer
, BUF_PT (inbuffer
) + 1, pt_byte
);
257 if (MARKERP (readcharfun
))
259 register struct buffer
*inbuffer
= XMARKER (readcharfun
)->buffer
;
261 int bytepos
= marker_byte_position (readcharfun
);
262 int orig_bytepos
= bytepos
;
264 if (readchar_backlog
> 0)
265 /* We get the address of the byte just passed,
266 which is the last byte of the character.
267 The other bytes in this character are consecutive with it,
268 because the gap can't be in the middle of a character. */
269 return *(BUF_BYTE_ADDRESS (inbuffer
, XMARKER (readcharfun
)->bytepos
- 1)
270 - --readchar_backlog
);
272 if (bytepos
>= BUF_ZV_BYTE (inbuffer
))
275 readchar_backlog
= -1;
277 if (! NILP (inbuffer
->enable_multibyte_characters
))
279 /* Fetch the character code from the buffer. */
280 unsigned char *p
= BUF_BYTE_ADDRESS (inbuffer
, bytepos
);
281 BUF_INC_POS (inbuffer
, bytepos
);
282 c
= STRING_CHAR (p
, bytepos
- orig_bytepos
);
286 c
= BUF_FETCH_BYTE (inbuffer
, bytepos
);
290 XMARKER (readcharfun
)->bytepos
= bytepos
;
291 XMARKER (readcharfun
)->charpos
++;
296 if (EQ (readcharfun
, Qlambda
))
297 return read_bytecode_char (0);
299 if (EQ (readcharfun
, Qget_file_char
))
303 /* Interrupted reads have been observed while reading over the network */
304 while (c
== EOF
&& ferror (instream
) && errno
== EINTR
)
313 if (STRINGP (readcharfun
))
315 if (read_from_string_index
>= read_from_string_limit
)
318 FETCH_STRING_CHAR_ADVANCE (c
, readcharfun
,
319 read_from_string_index
,
320 read_from_string_index_byte
);
325 tem
= call0 (readcharfun
);
332 /* Unread the character C in the way appropriate for the stream READCHARFUN.
333 If the stream is a user function, call it with the char as argument. */
336 unreadchar (readcharfun
, c
)
337 Lisp_Object readcharfun
;
341 /* Don't back up the pointer if we're unreading the end-of-input mark,
342 since readchar didn't advance it when we read it. */
344 else if (BUFFERP (readcharfun
))
346 struct buffer
*b
= XBUFFER (readcharfun
);
347 int bytepos
= BUF_PT_BYTE (b
);
349 if (readchar_backlog
>= 0)
354 if (! NILP (b
->enable_multibyte_characters
))
355 BUF_DEC_POS (b
, bytepos
);
359 BUF_PT_BYTE (b
) = bytepos
;
362 else if (MARKERP (readcharfun
))
364 struct buffer
*b
= XMARKER (readcharfun
)->buffer
;
365 int bytepos
= XMARKER (readcharfun
)->bytepos
;
367 if (readchar_backlog
>= 0)
371 XMARKER (readcharfun
)->charpos
--;
372 if (! NILP (b
->enable_multibyte_characters
))
373 BUF_DEC_POS (b
, bytepos
);
377 XMARKER (readcharfun
)->bytepos
= bytepos
;
380 else if (STRINGP (readcharfun
))
382 read_from_string_index
--;
383 read_from_string_index_byte
384 = string_char_to_byte (readcharfun
, read_from_string_index
);
386 else if (EQ (readcharfun
, Qlambda
))
387 read_bytecode_char (1);
388 else if (EQ (readcharfun
, Qget_file_char
))
389 ungetc (c
, instream
);
391 call1 (readcharfun
, make_number (c
));
394 static Lisp_Object
read0 (), read1 (), read_list (), read_vector ();
395 static int read_multibyte ();
396 static Lisp_Object
substitute_object_recurse ();
397 static void substitute_object_in_subtree (), substitute_in_interval ();
400 /* Get a character from the tty. */
402 extern Lisp_Object
read_char ();
404 /* Read input events until we get one that's acceptable for our purposes.
406 If NO_SWITCH_FRAME is non-zero, switch-frame events are stashed
407 until we get a character we like, and then stuffed into
410 If ASCII_REQUIRED is non-zero, we check function key events to see
411 if the unmodified version of the symbol has a Qascii_character
412 property, and use that character, if present.
414 If ERROR_NONASCII is non-zero, we signal an error if the input we
415 get isn't an ASCII character with modifiers. If it's zero but
416 ASCII_REQUIRED is non-zero, we just re-read until we get an ASCII
419 If INPUT_METHOD is nonzero, we invoke the current input method
420 if the character warrants that. */
423 read_filtered_event (no_switch_frame
, ascii_required
, error_nonascii
,
425 int no_switch_frame
, ascii_required
, error_nonascii
, input_method
;
427 register Lisp_Object val
, delayed_switch_frame
;
429 #ifdef HAVE_WINDOW_SYSTEM
430 if (display_hourglass_p
)
434 delayed_switch_frame
= Qnil
;
436 /* Read until we get an acceptable event. */
438 val
= read_char (0, 0, 0,
439 (input_method
? Qnil
: Qt
),
445 /* switch-frame events are put off until after the next ASCII
446 character. This is better than signaling an error just because
447 the last characters were typed to a separate minibuffer frame,
448 for example. Eventually, some code which can deal with
449 switch-frame events will read it and process it. */
451 && EVENT_HAS_PARAMETERS (val
)
452 && EQ (EVENT_HEAD (val
), Qswitch_frame
))
454 delayed_switch_frame
= val
;
460 /* Convert certain symbols to their ASCII equivalents. */
463 Lisp_Object tem
, tem1
;
464 tem
= Fget (val
, Qevent_symbol_element_mask
);
467 tem1
= Fget (Fcar (tem
), Qascii_character
);
468 /* Merge this symbol's modifier bits
469 with the ASCII equivalent of its basic code. */
471 XSETFASTINT (val
, XINT (tem1
) | XINT (Fcar (Fcdr (tem
))));
475 /* If we don't have a character now, deal with it appropriately. */
480 Vunread_command_events
= Fcons (val
, Qnil
);
481 error ("Non-character input-event");
488 if (! NILP (delayed_switch_frame
))
489 unread_switch_frame
= delayed_switch_frame
;
491 #ifdef HAVE_WINDOW_SYSTEM
492 if (display_hourglass_p
)
498 DEFUN ("read-char", Fread_char
, Sread_char
, 0, 2, 0,
499 "Read a character from the command input (keyboard or macro).\n\
500 It is returned as a number.\n\
501 If the user generates an event which is not a character (i.e. a mouse\n\
502 click or function key event), `read-char' signals an error. As an\n\
503 exception, switch-frame events are put off until non-ASCII events can\n\
505 If you want to read non-character events, or ignore them, call\n\
506 `read-event' or `read-char-exclusive' instead.\n\
508 If the optional argument PROMPT is non-nil, display that as a prompt.\n\
509 If the optional argument INHERIT-INPUT-METHOD is non-nil and some\n\
510 input method is turned on in the current buffer, that input method\n\
511 is used for reading a character.")
512 (prompt
, inherit_input_method
)
513 Lisp_Object prompt
, inherit_input_method
;
516 message_with_string ("%s", prompt
, 0);
517 return read_filtered_event (1, 1, 1, ! NILP (inherit_input_method
));
520 DEFUN ("read-event", Fread_event
, Sread_event
, 0, 2, 0,
521 "Read an event object from the input stream.\n\
522 If the optional argument PROMPT is non-nil, display that as a prompt.\n\
523 If the optional argument INHERIT-INPUT-METHOD is non-nil and some\n\
524 input method is turned on in the current buffer, that input method\n\
525 is used for reading a character.")
526 (prompt
, inherit_input_method
)
527 Lisp_Object prompt
, inherit_input_method
;
530 message_with_string ("%s", prompt
, 0);
531 return read_filtered_event (0, 0, 0, ! NILP (inherit_input_method
));
534 DEFUN ("read-char-exclusive", Fread_char_exclusive
, Sread_char_exclusive
, 0, 2, 0,
535 "Read a character from the command input (keyboard or macro).\n\
536 It is returned as a number. Non-character events are ignored.\n\
538 If the optional argument PROMPT is non-nil, display that as a prompt.\n\
539 If the optional argument INHERIT-INPUT-METHOD is non-nil and some\n\
540 input method is turned on in the current buffer, that input method\n\
541 is used for reading a character.")
542 (prompt
, inherit_input_method
)
543 Lisp_Object prompt
, inherit_input_method
;
546 message_with_string ("%s", prompt
, 0);
547 return read_filtered_event (1, 1, 0, ! NILP (inherit_input_method
));
550 DEFUN ("get-file-char", Fget_file_char
, Sget_file_char
, 0, 0, 0,
551 "Don't use this yourself.")
554 register Lisp_Object val
;
555 XSETINT (val
, getc (instream
));
561 /* Value is non-zero if the file asswociated with file descriptor FD
562 is a compiled Lisp file that's safe to load. Only files compiled
563 with Emacs are safe to load. Files compiled with XEmacs can lead
564 to a crash in Fbyte_code because of an incompatible change in the
575 /* Read the first few bytes from the file, and look for a line
576 specifying the byte compiler version used. */
577 nbytes
= emacs_read (fd
, buf
, sizeof buf
- 1);
582 /* Skip to the next newline, skipping over the initial `ELC'
583 with NUL bytes following it. */
584 for (i
= 0; i
< nbytes
&& buf
[i
] != '\n'; ++i
)
588 && fast_c_string_match_ignore_case (Vbytecomp_version_regexp
,
593 lseek (fd
, 0, SEEK_SET
);
598 /* Callback for record_unwind_protect. Restore the old load list OLD,
599 after loading a file successfully. */
602 record_load_unwind (old
)
605 return Vloads_in_progress
= old
;
609 DEFUN ("load", Fload
, Sload
, 1, 5, 0,
610 "Execute a file of Lisp code named FILE.\n\
611 First try FILE with `.elc' appended, then try with `.el',\n\
612 then try FILE unmodified.\n\
613 This function searches the directories in `load-path'.\n\
614 If optional second arg NOERROR is non-nil,\n\
615 report no error if FILE doesn't exist.\n\
616 Print messages at start and end of loading unless\n\
617 optional third arg NOMESSAGE is non-nil.\n\
618 If optional fourth arg NOSUFFIX is non-nil, don't try adding\n\
619 suffixes `.elc' or `.el' to the specified name FILE.\n\
620 If optional fifth arg MUST-SUFFIX is non-nil, insist on\n\
621 the suffix `.elc' or `.el'; don't accept just FILE unless\n\
622 it ends in one of those suffixes or includes a directory name.\n\
623 Return t if file exists.")
624 (file
, noerror
, nomessage
, nosuffix
, must_suffix
)
625 Lisp_Object file
, noerror
, nomessage
, nosuffix
, must_suffix
;
627 register FILE *stream
;
628 register int fd
= -1;
629 register Lisp_Object lispstream
;
630 int count
= specpdl_ptr
- specpdl
;
634 /* 1 means we printed the ".el is newer" message. */
636 /* 1 means we are loading a compiled file. */
645 CHECK_STRING (file
, 0);
647 /* If file name is magic, call the handler. */
648 handler
= Ffind_file_name_handler (file
, Qload
);
650 return call5 (handler
, Qload
, file
, noerror
, nomessage
, nosuffix
);
652 /* Do this after the handler to avoid
653 the need to gcpro noerror, nomessage and nosuffix.
654 (Below here, we care only whether they are nil or not.) */
655 file
= Fsubstitute_in_file_name (file
);
657 /* Avoid weird lossage with null string as arg,
658 since it would try to load a directory as a Lisp file */
659 if (XSTRING (file
)->size
> 0)
661 int size
= STRING_BYTES (XSTRING (file
));
665 if (! NILP (must_suffix
))
667 /* Don't insist on adding a suffix if FILE already ends with one. */
669 && !strcmp (XSTRING (file
)->data
+ size
- 3, ".el"))
672 && !strcmp (XSTRING (file
)->data
+ size
- 4, ".elc"))
674 /* Don't insist on adding a suffix
675 if the argument includes a directory name. */
676 else if (! NILP (Ffile_name_directory (file
)))
680 fd
= openp (Vload_path
, file
,
681 (!NILP (nosuffix
) ? ""
682 : ! NILP (must_suffix
) ? ".elc.gz:.elc:.el.gz:.el"
683 : ".elc:.elc.gz:.el.gz:.el:"),
692 Fsignal (Qfile_error
, Fcons (build_string ("Cannot open load file"),
693 Fcons (file
, Qnil
)));
698 /* Tell startup.el whether or not we found the user's init file. */
699 if (EQ (Qt
, Vuser_init_file
))
700 Vuser_init_file
= found
;
702 /* If FD is -2, that means openp found a magic file. */
705 if (NILP (Fequal (found
, file
)))
706 /* If FOUND is a different file name from FILE,
707 find its handler even if we have already inhibited
708 the `load' operation on FILE. */
709 handler
= Ffind_file_name_handler (found
, Qt
);
711 handler
= Ffind_file_name_handler (found
, Qload
);
712 if (! NILP (handler
))
713 return call5 (handler
, Qload
, found
, noerror
, nomessage
, Qt
);
716 /* Check if we're stuck in a recursive load cycle.
718 2000-09-21: It's not possible to just check for the file loaded
719 being a member of Vloads_in_progress. This fails because of the
720 way the byte compiler currently works; `provide's are not
721 evaluted, see font-lock.el/jit-lock.el as an example. This
722 leads to a certain amount of ``normal'' recursion.
724 Also, just loading a file recursively is not always an error in
725 the general case; the second load may do something different. */
726 if (INTEGERP (Vrecursive_load_depth_limit
)
727 && XINT (Vrecursive_load_depth_limit
) > 0)
729 Lisp_Object len
= Flength (Vloads_in_progress
);
730 if (XFASTINT (len
) > XFASTINT (Vrecursive_load_depth_limit
))
731 Fsignal (Qerror
, Fcons (build_string ("Recursive load suspected"),
732 Fcons (found
, Vloads_in_progress
)));
733 record_unwind_protect (record_load_unwind
, Vloads_in_progress
);
734 Vloads_in_progress
= Fcons (found
, Vloads_in_progress
);
737 if (!bcmp (&(XSTRING (found
)->data
[STRING_BYTES (XSTRING (found
)) - 4]),
739 /* Load .elc files directly, but not when they are
740 remote and have no handler! */
747 if (!safe_to_load_p (fd
))
750 if (!load_dangerous_libraries
)
751 error ("File `%s' was not compiled in Emacs",
752 XSTRING (found
)->data
);
753 else if (!NILP (nomessage
))
754 message_with_string ("File `%s' not compiled in Emacs", found
, 1);
762 stat ((char *)XSTRING (found
)->data
, &s1
);
763 XSTRING (found
)->data
[STRING_BYTES (XSTRING (found
)) - 1] = 0;
764 result
= stat ((char *)XSTRING (found
)->data
, &s2
);
765 if (result
>= 0 && (unsigned) s1
.st_mtime
< (unsigned) s2
.st_mtime
)
767 /* Make the progress messages mention that source is newer. */
770 /* If we won't print another message, mention this anyway. */
771 if (! NILP (nomessage
))
772 message_with_string ("Source file `%s' newer than byte-compiled file",
775 XSTRING (found
)->data
[STRING_BYTES (XSTRING (found
)) - 1] = 'c';
782 /* We are loading a source file (*.el). */
783 if (!NILP (Vload_source_file_function
))
789 val
= call4 (Vload_source_file_function
, found
, file
,
790 NILP (noerror
) ? Qnil
: Qt
,
791 NILP (nomessage
) ? Qnil
: Qt
);
792 return unbind_to (count
, val
);
798 stream
= fopen ((char *) XSTRING (found
)->data
, fmode
);
799 #else /* not WINDOWSNT */
800 stream
= fdopen (fd
, fmode
);
801 #endif /* not WINDOWSNT */
805 error ("Failure to create stdio stream for %s", XSTRING (file
)->data
);
808 if (! NILP (Vpurify_flag
))
809 Vpreloaded_file_list
= Fcons (file
, Vpreloaded_file_list
);
811 if (NILP (nomessage
))
814 message_with_string ("Loading %s (compiled; note unsafe, not compiled in Emacs)...",
817 message_with_string ("Loading %s (source)...", file
, 1);
819 message_with_string ("Loading %s (compiled; note, source file is newer)...",
821 else /* The typical case; compiled file newer than source file. */
822 message_with_string ("Loading %s...", file
, 1);
826 lispstream
= Fcons (Qnil
, Qnil
);
827 XSETFASTINT (XCAR (lispstream
), (EMACS_UINT
)stream
>> 16);
828 XSETFASTINT (XCDR (lispstream
), (EMACS_UINT
)stream
& 0xffff);
829 record_unwind_protect (load_unwind
, lispstream
);
830 record_unwind_protect (load_descriptor_unwind
, load_descriptor_list
);
831 specbind (Qload_file_name
, found
);
832 specbind (Qinhibit_file_name_operation
, Qnil
);
834 = Fcons (make_number (fileno (stream
)), load_descriptor_list
);
836 readevalloop (Qget_file_char
, stream
, file
, Feval
, 0, Qnil
, Qnil
);
837 unbind_to (count
, Qnil
);
839 /* Run any load-hooks for this file. */
840 temp
= Fassoc (file
, Vafter_load_alist
);
842 Fprogn (Fcdr (temp
));
845 if (saved_doc_string
)
846 free (saved_doc_string
);
847 saved_doc_string
= 0;
848 saved_doc_string_size
= 0;
850 if (prev_saved_doc_string
)
851 xfree (prev_saved_doc_string
);
852 prev_saved_doc_string
= 0;
853 prev_saved_doc_string_size
= 0;
855 if (!noninteractive
&& NILP (nomessage
))
858 message_with_string ("Loading %s (compiled; note unsafe, not compiled in Emacs)...done",
861 message_with_string ("Loading %s (source)...done", file
, 1);
863 message_with_string ("Loading %s (compiled; note, source file is newer)...done",
865 else /* The typical case; compiled file newer than source file. */
866 message_with_string ("Loading %s...done", file
, 1);
873 load_unwind (stream
) /* used as unwind-protect function in load */
876 fclose ((FILE *) (XFASTINT (XCAR (stream
)) << 16
877 | XFASTINT (XCDR (stream
))));
878 if (--load_in_progress
< 0) load_in_progress
= 0;
883 load_descriptor_unwind (oldlist
)
886 load_descriptor_list
= oldlist
;
890 /* Close all descriptors in use for Floads.
891 This is used when starting a subprocess. */
898 for (tail
= load_descriptor_list
; !NILP (tail
); tail
= XCDR (tail
))
899 emacs_close (XFASTINT (XCAR (tail
)));
904 complete_filename_p (pathname
)
905 Lisp_Object pathname
;
907 register unsigned char *s
= XSTRING (pathname
)->data
;
908 return (IS_DIRECTORY_SEP (s
[0])
909 || (XSTRING (pathname
)->size
> 2
910 && IS_DEVICE_SEP (s
[1]) && IS_DIRECTORY_SEP (s
[2]))
920 /* Search for a file whose name is STR, looking in directories
921 in the Lisp list PATH, and trying suffixes from SUFFIX.
922 SUFFIX is a string containing possible suffixes separated by colons.
923 On success, returns a file descriptor. On failure, returns -1.
925 EXEC_ONLY nonzero means don't open the files,
926 just look for one that is executable. In this case,
927 returns 1 on success.
929 If STOREPTR is nonzero, it points to a slot where the name of
930 the file actually found should be stored as a Lisp string.
931 nil is stored there on failure.
933 If the file we find is remote, return -2
934 but store the found remote file name in *STOREPTR.
935 We do not check for remote files if EXEC_ONLY is nonzero. */
938 openp (path
, str
, suffix
, storeptr
, exec_only
)
939 Lisp_Object path
, str
;
941 Lisp_Object
*storeptr
;
947 register char *fn
= buf
;
950 Lisp_Object filename
;
952 struct gcpro gcpro1
, gcpro2
, gcpro3
;
955 string
= filename
= Qnil
;
956 GCPRO3 (str
, string
, filename
);
961 if (complete_filename_p (str
))
964 for (; !NILP (path
); path
= Fcdr (path
))
968 filename
= Fexpand_file_name (str
, Fcar (path
));
969 if (!complete_filename_p (filename
))
970 /* If there are non-absolute elts in PATH (eg ".") */
971 /* Of course, this could conceivably lose if luser sets
972 default-directory to be something non-absolute... */
974 filename
= Fexpand_file_name (filename
, current_buffer
->directory
);
975 if (!complete_filename_p (filename
))
976 /* Give up on this path element! */
980 /* Calculate maximum size of any filename made from
981 this path element/specified file name and any possible suffix. */
982 want_size
= strlen (suffix
) + STRING_BYTES (XSTRING (filename
)) + 1;
983 if (fn_size
< want_size
)
984 fn
= (char *) alloca (fn_size
= 100 + want_size
);
988 /* Loop over suffixes. */
991 char *esuffix
= (char *) index (nsuffix
, ':');
992 int lsuffix
= esuffix
? esuffix
- nsuffix
: strlen (nsuffix
);
995 /* Concatenate path element/specified name with the suffix.
996 If the directory starts with /:, remove that. */
997 if (XSTRING (filename
)->size
> 2
998 && XSTRING (filename
)->data
[0] == '/'
999 && XSTRING (filename
)->data
[1] == ':')
1001 strncpy (fn
, XSTRING (filename
)->data
+ 2,
1002 STRING_BYTES (XSTRING (filename
)) - 2);
1003 fn
[STRING_BYTES (XSTRING (filename
)) - 2] = 0;
1007 strncpy (fn
, XSTRING (filename
)->data
,
1008 STRING_BYTES (XSTRING (filename
)));
1009 fn
[STRING_BYTES (XSTRING (filename
))] = 0;
1012 if (lsuffix
!= 0) /* Bug happens on CCI if lsuffix is 0. */
1013 strncat (fn
, nsuffix
, lsuffix
);
1015 /* Check that the file exists and is not a directory. */
1019 handler
= Ffind_file_name_handler (filename
, Qfile_exists_p
);
1020 if (! NILP (handler
) && ! exec_only
)
1024 string
= build_string (fn
);
1025 exists
= ! NILP (exec_only
? Ffile_executable_p (string
)
1026 : Ffile_readable_p (string
));
1028 && ! NILP (Ffile_directory_p (build_string (fn
))))
1033 /* We succeeded; return this descriptor and filename. */
1035 *storeptr
= build_string (fn
);
1042 int exists
= (stat (fn
, &st
) >= 0
1043 && (st
.st_mode
& S_IFMT
) != S_IFDIR
);
1046 /* Check that we can access or open it. */
1048 fd
= (access (fn
, X_OK
) == 0) ? 1 : -1;
1050 fd
= emacs_open (fn
, O_RDONLY
, 0);
1054 /* We succeeded; return this descriptor and filename. */
1056 *storeptr
= build_string (fn
);
1063 /* Advance to next suffix. */
1066 nsuffix
+= lsuffix
+ 1;
1077 /* Merge the list we've accumulated of globals from the current input source
1078 into the load_history variable. The details depend on whether
1079 the source has an associated file name or not. */
1082 build_load_history (stream
, source
)
1086 register Lisp_Object tail
, prev
, newelt
;
1087 register Lisp_Object tem
, tem2
;
1088 register int foundit
, loading
;
1090 loading
= stream
|| !NARROWED
;
1092 tail
= Vload_history
;
1095 while (!NILP (tail
))
1099 /* Find the feature's previous assoc list... */
1100 if (!NILP (Fequal (source
, Fcar (tem
))))
1104 /* If we're loading, remove it. */
1108 Vload_history
= Fcdr (tail
);
1110 Fsetcdr (prev
, Fcdr (tail
));
1113 /* Otherwise, cons on new symbols that are not already members. */
1116 tem2
= Vcurrent_load_list
;
1118 while (CONSP (tem2
))
1120 newelt
= Fcar (tem2
);
1122 if (NILP (Fmemq (newelt
, tem
)))
1123 Fsetcar (tail
, Fcons (Fcar (tem
),
1124 Fcons (newelt
, Fcdr (tem
))));
1137 /* If we're loading, cons the new assoc onto the front of load-history,
1138 the most-recently-loaded position. Also do this if we didn't find
1139 an existing member for the current source. */
1140 if (loading
|| !foundit
)
1141 Vload_history
= Fcons (Fnreverse (Vcurrent_load_list
),
1146 unreadpure (junk
) /* Used as unwind-protect function in readevalloop */
1154 readevalloop_1 (old
)
1157 load_convert_to_unibyte
= ! NILP (old
);
1161 /* Signal an `end-of-file' error, if possible with file name
1165 end_of_file_error ()
1169 if (STRINGP (Vload_file_name
))
1170 data
= Fcons (Vload_file_name
, Qnil
);
1174 Fsignal (Qend_of_file
, data
);
1177 /* UNIBYTE specifies how to set load_convert_to_unibyte
1178 for this invocation.
1179 READFUN, if non-nil, is used instead of `read'. */
1182 readevalloop (readcharfun
, stream
, sourcename
, evalfun
, printflag
, unibyte
, readfun
)
1183 Lisp_Object readcharfun
;
1185 Lisp_Object sourcename
;
1186 Lisp_Object (*evalfun
) ();
1188 Lisp_Object unibyte
, readfun
;
1191 register Lisp_Object val
;
1192 int count
= specpdl_ptr
- specpdl
;
1193 struct gcpro gcpro1
;
1194 struct buffer
*b
= 0;
1195 int continue_reading_p
;
1197 if (BUFFERP (readcharfun
))
1198 b
= XBUFFER (readcharfun
);
1199 else if (MARKERP (readcharfun
))
1200 b
= XMARKER (readcharfun
)->buffer
;
1202 specbind (Qstandard_input
, readcharfun
);
1203 specbind (Qcurrent_load_list
, Qnil
);
1204 record_unwind_protect (readevalloop_1
, load_convert_to_unibyte
? Qt
: Qnil
);
1205 load_convert_to_unibyte
= !NILP (unibyte
);
1207 readchar_backlog
= -1;
1209 GCPRO1 (sourcename
);
1211 LOADHIST_ATTACH (sourcename
);
1213 continue_reading_p
= 1;
1214 while (continue_reading_p
)
1216 if (b
!= 0 && NILP (b
->name
))
1217 error ("Reading from killed buffer");
1223 while ((c
= READCHAR
) != '\n' && c
!= -1);
1228 /* Ignore whitespace here, so we can detect eof. */
1229 if (c
== ' ' || c
== '\t' || c
== '\n' || c
== '\f' || c
== '\r')
1232 if (!NILP (Vpurify_flag
) && c
== '(')
1234 int count1
= specpdl_ptr
- specpdl
;
1235 record_unwind_protect (unreadpure
, Qnil
);
1236 val
= read_list (-1, readcharfun
);
1237 unbind_to (count1
, Qnil
);
1242 read_objects
= Qnil
;
1243 if (!NILP (readfun
))
1245 val
= call1 (readfun
, readcharfun
);
1247 /* If READCHARFUN has set point to ZV, we should
1248 stop reading, even if the form read sets point
1249 to a different value when evaluated. */
1250 if (BUFFERP (readcharfun
))
1252 struct buffer
*b
= XBUFFER (readcharfun
);
1253 if (BUF_PT (b
) == BUF_ZV (b
))
1254 continue_reading_p
= 0;
1257 else if (! NILP (Vload_read_function
))
1258 val
= call1 (Vload_read_function
, readcharfun
);
1260 val
= read0 (readcharfun
);
1263 val
= (*evalfun
) (val
);
1267 Vvalues
= Fcons (val
, Vvalues
);
1268 if (EQ (Vstandard_output
, Qt
))
1275 build_load_history (stream
, sourcename
);
1278 unbind_to (count
, Qnil
);
1281 DEFUN ("eval-buffer", Feval_buffer
, Seval_buffer
, 0, 5, "",
1282 "Execute the current buffer as Lisp code.\n\
1283 Programs can pass two arguments, BUFFER and PRINTFLAG.\n\
1284 BUFFER is the buffer to evaluate (nil means use current buffer).\n\
1285 PRINTFLAG controls printing of output:\n\
1286 nil means discard it; anything else is stream for print.\n\
1288 If the optional third argument FILENAME is non-nil,\n\
1289 it specifies the file name to use for `load-history'.\n\
1290 The optional fourth argument UNIBYTE specifies `load-convert-to-unibyte'\n\
1291 for this invocation.\n\
1293 The optional fifth argument DO-ALLOW-PRINT, if not-nil, specifies that\n\
1294 `print' and related functions should work normally even if PRINTFLAG is nil.\n\
1296 This function preserves the position of point.")
1297 (buffer
, printflag
, filename
, unibyte
, do_allow_print
)
1298 Lisp_Object buffer
, printflag
, filename
, unibyte
, do_allow_print
;
1300 int count
= specpdl_ptr
- specpdl
;
1301 Lisp_Object tem
, buf
;
1304 buf
= Fcurrent_buffer ();
1306 buf
= Fget_buffer (buffer
);
1308 error ("No such buffer");
1310 if (NILP (printflag
) && NILP (do_allow_print
))
1315 if (NILP (filename
))
1316 filename
= XBUFFER (buf
)->filename
;
1318 specbind (Qstandard_output
, tem
);
1319 record_unwind_protect (save_excursion_restore
, save_excursion_save ());
1320 BUF_SET_PT (XBUFFER (buf
), BUF_BEGV (XBUFFER (buf
)));
1321 readevalloop (buf
, 0, filename
, Feval
, !NILP (printflag
), unibyte
, Qnil
);
1322 unbind_to (count
, Qnil
);
1328 XDEFUN ("eval-current-buffer", Feval_current_buffer
, Seval_current_buffer
, 0, 1, "",
1329 "Execute the current buffer as Lisp code.\n\
1330 Programs can pass argument PRINTFLAG which controls printing of output:\n\
1331 nil means discard it; anything else is stream for print.\n\
1333 If there is no error, point does not move. If there is an error,\n\
1334 point remains at the end of the last character read from the buffer.")
1336 Lisp_Object printflag
;
1338 int count
= specpdl_ptr
- specpdl
;
1339 Lisp_Object tem
, cbuf
;
1341 cbuf
= Fcurrent_buffer ()
1343 if (NILP (printflag
))
1347 specbind (Qstandard_output
, tem
);
1348 record_unwind_protect (save_excursion_restore
, save_excursion_save ());
1350 readevalloop (cbuf
, 0, XBUFFER (cbuf
)->filename
, Feval
,
1351 !NILP (printflag
), Qnil
, Qnil
);
1352 return unbind_to (count
, Qnil
);
1356 DEFUN ("eval-region", Feval_region
, Seval_region
, 2, 4, "r",
1357 "Execute the region as Lisp code.\n\
1358 When called from programs, expects two arguments,\n\
1359 giving starting and ending indices in the current buffer\n\
1360 of the text to be executed.\n\
1361 Programs can pass third argument PRINTFLAG which controls output:\n\
1362 nil means discard it; anything else is stream for printing it.\n\
1363 Also the fourth argument READ-FUNCTION, if non-nil, is used\n\
1364 instead of `read' to read each expression. It gets one argument\n\
1365 which is the input stream for reading characters.\n\
1367 This function does not move point.")
1368 (start
, end
, printflag
, read_function
)
1369 Lisp_Object start
, end
, printflag
, read_function
;
1371 int count
= specpdl_ptr
- specpdl
;
1372 Lisp_Object tem
, cbuf
;
1374 cbuf
= Fcurrent_buffer ();
1376 if (NILP (printflag
))
1380 specbind (Qstandard_output
, tem
);
1382 if (NILP (printflag
))
1383 record_unwind_protect (save_excursion_restore
, save_excursion_save ());
1384 record_unwind_protect (save_restriction_restore
, save_restriction_save ());
1386 /* This both uses start and checks its type. */
1388 Fnarrow_to_region (make_number (BEGV
), end
);
1389 readevalloop (cbuf
, 0, XBUFFER (cbuf
)->filename
, Feval
,
1390 !NILP (printflag
), Qnil
, read_function
);
1392 return unbind_to (count
, Qnil
);
1396 DEFUN ("read", Fread
, Sread
, 0, 1, 0,
1397 "Read one Lisp expression as text from STREAM, return as Lisp object.\n\
1398 If STREAM is nil, use the value of `standard-input' (which see).\n\
1399 STREAM or the value of `standard-input' may be:\n\
1400 a buffer (read from point and advance it)\n\
1401 a marker (read from where it points and advance it)\n\
1402 a function (call it with no arguments for each character,\n\
1403 call it with a char as argument to push a char back)\n\
1404 a string (takes text from string, starting at the beginning)\n\
1405 t (read text line using minibuffer and use it, or read from\n\
1406 standard input in batch mode).")
1410 extern Lisp_Object
Fread_minibuffer ();
1413 stream
= Vstandard_input
;
1414 if (EQ (stream
, Qt
))
1415 stream
= Qread_char
;
1417 readchar_backlog
= -1;
1418 new_backquote_flag
= 0;
1419 read_objects
= Qnil
;
1421 if (EQ (stream
, Qread_char
))
1422 return Fread_minibuffer (build_string ("Lisp expression: "), Qnil
);
1424 if (STRINGP (stream
))
1425 return Fcar (Fread_from_string (stream
, Qnil
, Qnil
));
1427 return read0 (stream
);
1430 DEFUN ("read-from-string", Fread_from_string
, Sread_from_string
, 1, 3, 0,
1431 "Read one Lisp expression which is represented as text by STRING.\n\
1432 Returns a cons: (OBJECT-READ . FINAL-STRING-INDEX).\n\
1433 START and END optionally delimit a substring of STRING from which to read;\n\
1434 they default to 0 and (length STRING) respectively.")
1435 (string
, start
, end
)
1436 Lisp_Object string
, start
, end
;
1438 int startval
, endval
;
1441 CHECK_STRING (string
,0);
1444 endval
= XSTRING (string
)->size
;
1447 CHECK_NUMBER (end
, 2);
1448 endval
= XINT (end
);
1449 if (endval
< 0 || endval
> XSTRING (string
)->size
)
1450 args_out_of_range (string
, end
);
1457 CHECK_NUMBER (start
, 1);
1458 startval
= XINT (start
);
1459 if (startval
< 0 || startval
> endval
)
1460 args_out_of_range (string
, start
);
1463 read_from_string_index
= startval
;
1464 read_from_string_index_byte
= string_char_to_byte (string
, startval
);
1465 read_from_string_limit
= endval
;
1467 new_backquote_flag
= 0;
1468 read_objects
= Qnil
;
1470 tem
= read0 (string
);
1471 return Fcons (tem
, make_number (read_from_string_index
));
1474 /* Use this for recursive reads, in contexts where internal tokens
1479 Lisp_Object readcharfun
;
1481 register Lisp_Object val
;
1484 val
= read1 (readcharfun
, &c
, 0);
1486 Fsignal (Qinvalid_read_syntax
, Fcons (Fmake_string (make_number (1),
1493 static int read_buffer_size
;
1494 static char *read_buffer
;
1496 /* Read multibyte form and return it as a character. C is a first
1497 byte of multibyte form, and rest of them are read from
1501 read_multibyte (c
, readcharfun
)
1503 Lisp_Object readcharfun
;
1505 /* We need the actual character code of this multibyte
1507 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
1512 while ((c
= READCHAR
) >= 0xA0
1513 && len
< MAX_MULTIBYTE_LENGTH
)
1516 if (UNIBYTE_STR_AS_MULTIBYTE_P (str
, len
, bytes
))
1517 return STRING_CHAR (str
, len
);
1518 /* The byte sequence is not valid as multibyte. Unread all bytes
1519 but the first one, and return the first byte. */
1525 /* Read a \-escape sequence, assuming we already read the `\'. */
1528 read_escape (readcharfun
, stringp
)
1529 Lisp_Object readcharfun
;
1532 register int c
= READCHAR
;
1536 error ("End of file");
1566 error ("Invalid escape character syntax");
1569 c
= read_escape (readcharfun
, 0);
1570 return c
| meta_modifier
;
1575 error ("Invalid escape character syntax");
1578 c
= read_escape (readcharfun
, 0);
1579 return c
| shift_modifier
;
1584 error ("Invalid escape character syntax");
1587 c
= read_escape (readcharfun
, 0);
1588 return c
| hyper_modifier
;
1593 error ("Invalid escape character syntax");
1596 c
= read_escape (readcharfun
, 0);
1597 return c
| alt_modifier
;
1602 error ("Invalid escape character syntax");
1605 c
= read_escape (readcharfun
, 0);
1606 return c
| super_modifier
;
1611 error ("Invalid escape character syntax");
1615 c
= read_escape (readcharfun
, 0);
1616 if ((c
& ~CHAR_MODIFIER_MASK
) == '?')
1617 return 0177 | (c
& CHAR_MODIFIER_MASK
);
1618 else if (! SINGLE_BYTE_CHAR_P ((c
& ~CHAR_MODIFIER_MASK
)))
1619 return c
| ctrl_modifier
;
1620 /* ASCII control chars are made from letters (both cases),
1621 as well as the non-letters within 0100...0137. */
1622 else if ((c
& 0137) >= 0101 && (c
& 0137) <= 0132)
1623 return (c
& (037 | ~0177));
1624 else if ((c
& 0177) >= 0100 && (c
& 0177) <= 0137)
1625 return (c
& (037 | ~0177));
1627 return c
| ctrl_modifier
;
1637 /* An octal escape, as in ANSI C. */
1639 register int i
= c
- '0';
1640 register int count
= 0;
1643 if ((c
= READCHAR
) >= '0' && c
<= '7')
1658 /* A hex escape, as in ANSI C. */
1664 if (c
>= '0' && c
<= '9')
1669 else if ((c
>= 'a' && c
<= 'f')
1670 || (c
>= 'A' && c
<= 'F'))
1673 if (c
>= 'a' && c
<= 'f')
1688 if (BASE_LEADING_CODE_P (c
))
1689 c
= read_multibyte (c
, readcharfun
);
1695 /* Read an integer in radix RADIX using READCHARFUN to read
1696 characters. RADIX must be in the interval [2..36]; if it isn't, a
1697 read error is signaled . Value is the integer read. Signals an
1698 error if encountering invalid read syntax or if RADIX is out of
1702 read_integer (readcharfun
, radix
)
1703 Lisp_Object readcharfun
;
1706 int ndigits
= 0, invalid_p
, c
, sign
= 0;
1707 EMACS_INT number
= 0;
1709 if (radix
< 2 || radix
> 36)
1713 number
= ndigits
= invalid_p
= 0;
1729 if (c
>= '0' && c
<= '9')
1731 else if (c
>= 'a' && c
<= 'z')
1732 digit
= c
- 'a' + 10;
1733 else if (c
>= 'A' && c
<= 'Z')
1734 digit
= c
- 'A' + 10;
1741 if (digit
< 0 || digit
>= radix
)
1744 number
= radix
* number
+ digit
;
1750 if (ndigits
== 0 || invalid_p
)
1753 sprintf (buf
, "integer, radix %d", radix
);
1754 Fsignal (Qinvalid_read_syntax
, Fcons (build_string (buf
), Qnil
));
1757 return make_number (sign
* number
);
1761 /* If the next token is ')' or ']' or '.', we store that character
1762 in *PCH and the return value is not interesting. Else, we store
1763 zero in *PCH and we read and return one lisp object.
1765 FIRST_IN_LIST is nonzero if this is the first element of a list. */
1768 read1 (readcharfun
, pch
, first_in_list
)
1769 register Lisp_Object readcharfun
;
1774 int uninterned_symbol
= 0;
1782 end_of_file_error ();
1787 return read_list (0, readcharfun
);
1790 return read_vector (readcharfun
, 0);
1807 tmp
= read_vector (readcharfun
, 0);
1808 if (XVECTOR (tmp
)->size
< CHAR_TABLE_STANDARD_SLOTS
1809 || XVECTOR (tmp
)->size
> CHAR_TABLE_STANDARD_SLOTS
+ 10)
1810 error ("Invalid size char-table");
1811 XSETCHAR_TABLE (tmp
, XCHAR_TABLE (tmp
));
1812 XCHAR_TABLE (tmp
)->top
= Qt
;
1821 tmp
= read_vector (readcharfun
, 0);
1822 if (XVECTOR (tmp
)->size
!= SUB_CHAR_TABLE_STANDARD_SLOTS
)
1823 error ("Invalid size char-table");
1824 XSETCHAR_TABLE (tmp
, XCHAR_TABLE (tmp
));
1825 XCHAR_TABLE (tmp
)->top
= Qnil
;
1828 Fsignal (Qinvalid_read_syntax
,
1829 Fcons (make_string ("#^^", 3), Qnil
));
1831 Fsignal (Qinvalid_read_syntax
, Fcons (make_string ("#^", 2), Qnil
));
1836 length
= read1 (readcharfun
, pch
, first_in_list
);
1840 Lisp_Object tmp
, val
;
1841 int size_in_chars
= ((XFASTINT (length
) + BITS_PER_CHAR
- 1)
1845 tmp
= read1 (readcharfun
, pch
, first_in_list
);
1846 if (size_in_chars
!= XSTRING (tmp
)->size
1847 /* We used to print 1 char too many
1848 when the number of bits was a multiple of 8.
1849 Accept such input in case it came from an old version. */
1850 && ! (XFASTINT (length
)
1851 == (XSTRING (tmp
)->size
- 1) * BITS_PER_CHAR
))
1852 Fsignal (Qinvalid_read_syntax
,
1853 Fcons (make_string ("#&...", 5), Qnil
));
1855 val
= Fmake_bool_vector (length
, Qnil
);
1856 bcopy (XSTRING (tmp
)->data
, XBOOL_VECTOR (val
)->data
,
1858 /* Clear the extraneous bits in the last byte. */
1859 if (XINT (length
) != size_in_chars
* BITS_PER_CHAR
)
1860 XBOOL_VECTOR (val
)->data
[size_in_chars
- 1]
1861 &= (1 << (XINT (length
) % BITS_PER_CHAR
)) - 1;
1864 Fsignal (Qinvalid_read_syntax
, Fcons (make_string ("#&...", 5),
1869 /* Accept compiled functions at read-time so that we don't have to
1870 build them using function calls. */
1872 tmp
= read_vector (readcharfun
, 1);
1873 return Fmake_byte_code (XVECTOR (tmp
)->size
,
1874 XVECTOR (tmp
)->contents
);
1879 struct gcpro gcpro1
;
1882 /* Read the string itself. */
1883 tmp
= read1 (readcharfun
, &ch
, 0);
1884 if (ch
!= 0 || !STRINGP (tmp
))
1885 Fsignal (Qinvalid_read_syntax
, Fcons (make_string ("#", 1), Qnil
));
1887 /* Read the intervals and their properties. */
1890 Lisp_Object beg
, end
, plist
;
1892 beg
= read1 (readcharfun
, &ch
, 0);
1897 end
= read1 (readcharfun
, &ch
, 0);
1899 plist
= read1 (readcharfun
, &ch
, 0);
1901 Fsignal (Qinvalid_read_syntax
,
1902 Fcons (build_string ("invalid string property list"),
1904 Fset_text_properties (beg
, end
, plist
, tmp
);
1910 /* #@NUMBER is used to skip NUMBER following characters.
1911 That's used in .elc files to skip over doc strings
1912 and function definitions. */
1917 /* Read a decimal integer. */
1918 while ((c
= READCHAR
) >= 0
1919 && c
>= '0' && c
<= '9')
1927 if (load_force_doc_strings
&& EQ (readcharfun
, Qget_file_char
))
1929 /* If we are supposed to force doc strings into core right now,
1930 record the last string that we skipped,
1931 and record where in the file it comes from. */
1933 /* But first exchange saved_doc_string
1934 with prev_saved_doc_string, so we save two strings. */
1936 char *temp
= saved_doc_string
;
1937 int temp_size
= saved_doc_string_size
;
1938 file_offset temp_pos
= saved_doc_string_position
;
1939 int temp_len
= saved_doc_string_length
;
1941 saved_doc_string
= prev_saved_doc_string
;
1942 saved_doc_string_size
= prev_saved_doc_string_size
;
1943 saved_doc_string_position
= prev_saved_doc_string_position
;
1944 saved_doc_string_length
= prev_saved_doc_string_length
;
1946 prev_saved_doc_string
= temp
;
1947 prev_saved_doc_string_size
= temp_size
;
1948 prev_saved_doc_string_position
= temp_pos
;
1949 prev_saved_doc_string_length
= temp_len
;
1952 if (saved_doc_string_size
== 0)
1954 saved_doc_string_size
= nskip
+ 100;
1955 saved_doc_string
= (char *) xmalloc (saved_doc_string_size
);
1957 if (nskip
> saved_doc_string_size
)
1959 saved_doc_string_size
= nskip
+ 100;
1960 saved_doc_string
= (char *) xrealloc (saved_doc_string
,
1961 saved_doc_string_size
);
1964 saved_doc_string_position
= file_tell (instream
);
1966 /* Copy that many characters into saved_doc_string. */
1967 for (i
= 0; i
< nskip
&& c
>= 0; i
++)
1968 saved_doc_string
[i
] = c
= READCHAR
;
1970 saved_doc_string_length
= i
;
1974 /* Skip that many characters. */
1975 for (i
= 0; i
< nskip
&& c
>= 0; i
++)
1982 return Vload_file_name
;
1984 return Fcons (Qfunction
, Fcons (read0 (readcharfun
), Qnil
));
1985 /* #:foo is the uninterned symbol named foo. */
1988 uninterned_symbol
= 1;
1992 /* Reader forms that can reuse previously read objects. */
1993 if (c
>= '0' && c
<= '9')
1998 /* Read a non-negative integer. */
1999 while (c
>= '0' && c
<= '9')
2005 /* #n=object returns object, but associates it with n for #n#. */
2008 /* Make a placeholder for #n# to use temporarily */
2009 Lisp_Object placeholder
;
2012 placeholder
= Fcons(Qnil
, Qnil
);
2013 cell
= Fcons (make_number (n
), placeholder
);
2014 read_objects
= Fcons (cell
, read_objects
);
2016 /* Read the object itself. */
2017 tem
= read0 (readcharfun
);
2019 /* Now put it everywhere the placeholder was... */
2020 substitute_object_in_subtree (tem
, placeholder
);
2022 /* ...and #n# will use the real value from now on. */
2023 Fsetcdr (cell
, tem
);
2027 /* #n# returns a previously read object. */
2030 tem
= Fassq (make_number (n
), read_objects
);
2033 /* Fall through to error message. */
2035 else if (c
== 'r' || c
== 'R')
2036 return read_integer (readcharfun
, n
);
2038 /* Fall through to error message. */
2040 else if (c
== 'x' || c
== 'X')
2041 return read_integer (readcharfun
, 16);
2042 else if (c
== 'o' || c
== 'O')
2043 return read_integer (readcharfun
, 8);
2044 else if (c
== 'b' || c
== 'B')
2045 return read_integer (readcharfun
, 2);
2048 Fsignal (Qinvalid_read_syntax
, Fcons (make_string ("#", 1), Qnil
));
2051 while ((c
= READCHAR
) >= 0 && c
!= '\n');
2056 return Fcons (Qquote
, Fcons (read0 (readcharfun
), Qnil
));
2066 new_backquote_flag
= 1;
2067 value
= read0 (readcharfun
);
2068 new_backquote_flag
= 0;
2070 return Fcons (Qbackquote
, Fcons (value
, Qnil
));
2074 if (new_backquote_flag
)
2076 Lisp_Object comma_type
= Qnil
;
2081 comma_type
= Qcomma_at
;
2083 comma_type
= Qcomma_dot
;
2086 if (ch
>= 0) UNREAD (ch
);
2087 comma_type
= Qcomma
;
2090 new_backquote_flag
= 0;
2091 value
= read0 (readcharfun
);
2092 new_backquote_flag
= 1;
2093 return Fcons (comma_type
, Fcons (value
, Qnil
));
2102 end_of_file_error ();
2105 c
= read_escape (readcharfun
, 0);
2106 else if (BASE_LEADING_CODE_P (c
))
2107 c
= read_multibyte (c
, readcharfun
);
2109 return make_number (c
);
2114 register char *p
= read_buffer
;
2115 register char *end
= read_buffer
+ read_buffer_size
;
2117 /* Nonzero if we saw an escape sequence specifying
2118 a multibyte character. */
2119 int force_multibyte
= 0;
2120 /* Nonzero if we saw an escape sequence specifying
2121 a single-byte character. */
2122 int force_singlebyte
= 0;
2126 while ((c
= READCHAR
) >= 0
2129 if (end
- p
< MAX_MULTIBYTE_LENGTH
)
2131 int offset
= p
- read_buffer
;
2132 read_buffer
= (char *) xrealloc (read_buffer
,
2133 read_buffer_size
*= 2);
2134 p
= read_buffer
+ offset
;
2135 end
= read_buffer
+ read_buffer_size
;
2140 c
= read_escape (readcharfun
, 1);
2142 /* C is -1 if \ newline has just been seen */
2145 if (p
== read_buffer
)
2150 /* If an escape specifies a non-ASCII single-byte character,
2151 this must be a unibyte string. */
2152 if (SINGLE_BYTE_CHAR_P ((c
& ~CHAR_MODIFIER_MASK
))
2153 && ! ASCII_BYTE_P ((c
& ~CHAR_MODIFIER_MASK
)))
2154 force_singlebyte
= 1;
2157 if (! SINGLE_BYTE_CHAR_P ((c
& ~CHAR_MODIFIER_MASK
)))
2159 /* Any modifiers for a multibyte character are invalid. */
2160 if (c
& CHAR_MODIFIER_MASK
)
2161 error ("Invalid modifier in string");
2162 p
+= CHAR_STRING (c
, p
);
2163 force_multibyte
= 1;
2167 /* Allow `\C- ' and `\C-?'. */
2168 if (c
== (CHAR_CTL
| ' '))
2170 else if (c
== (CHAR_CTL
| '?'))
2175 /* Shift modifier is valid only with [A-Za-z]. */
2176 if ((c
& 0377) >= 'A' && (c
& 0377) <= 'Z')
2178 else if ((c
& 0377) >= 'a' && (c
& 0377) <= 'z')
2179 c
= (c
& ~CHAR_SHIFT
) - ('a' - 'A');
2183 /* Move the meta bit to the right place for a string. */
2184 c
= (c
& ~CHAR_META
) | 0x80;
2186 error ("Invalid modifier in string");
2191 end_of_file_error ();
2193 /* If purifying, and string starts with \ newline,
2194 return zero instead. This is for doc strings
2195 that we are really going to find in etc/DOC.nn.nn */
2196 if (!NILP (Vpurify_flag
) && NILP (Vdoc_file_name
) && cancel
)
2197 return make_number (0);
2199 if (force_multibyte
)
2200 p
= read_buffer
+ str_as_multibyte (read_buffer
, end
- read_buffer
,
2201 p
- read_buffer
, &nchars
);
2202 else if (force_singlebyte
)
2203 nchars
= p
- read_buffer
;
2204 else if (load_convert_to_unibyte
)
2207 p
= read_buffer
+ str_as_multibyte (read_buffer
, end
- read_buffer
,
2208 p
- read_buffer
, &nchars
);
2209 if (p
- read_buffer
!= nchars
)
2211 string
= make_multibyte_string (read_buffer
, nchars
,
2213 return Fstring_make_unibyte (string
);
2216 else if (EQ (readcharfun
, Qget_file_char
)
2217 || EQ (readcharfun
, Qlambda
))
2218 /* Nowadays, reading directly from a file is used only for
2219 compiled Emacs Lisp files, and those always use the
2220 Emacs internal encoding. Meanwhile, Qlambda is used
2221 for reading dynamic byte code (compiled with
2222 byte-compile-dynamic = t). */
2223 p
= read_buffer
+ str_as_multibyte (read_buffer
, end
- read_buffer
,
2224 p
- read_buffer
, &nchars
);
2226 /* In all other cases, if we read these bytes as
2227 separate characters, treat them as separate characters now. */
2228 nchars
= p
- read_buffer
;
2231 return make_pure_string (read_buffer
, nchars
, p
- read_buffer
,
2233 || (p
- read_buffer
!= nchars
)));
2234 return make_specified_string (read_buffer
, nchars
, p
- read_buffer
,
2236 || (p
- read_buffer
!= nchars
)));
2241 int next_char
= READCHAR
;
2244 if (next_char
<= 040
2245 || index ("\"'`,(", next_char
))
2251 /* Otherwise, we fall through! Note that the atom-reading loop
2252 below will now loop at least once, assuring that we will not
2253 try to UNREAD two characters in a row. */
2257 if (c
<= 040) goto retry
;
2259 char *p
= read_buffer
;
2263 char *end
= read_buffer
+ read_buffer_size
;
2266 && !(c
== '\"' || c
== '\'' || c
== ';'
2267 || c
== '(' || c
== ')'
2268 || c
== '[' || c
== ']' || c
== '#'))
2270 if (end
- p
< MAX_MULTIBYTE_LENGTH
)
2272 int offset
= p
- read_buffer
;
2273 read_buffer
= (char *) xrealloc (read_buffer
,
2274 read_buffer_size
*= 2);
2275 p
= read_buffer
+ offset
;
2276 end
= read_buffer
+ read_buffer_size
;
2283 end_of_file_error ();
2287 if (! SINGLE_BYTE_CHAR_P (c
))
2288 p
+= CHAR_STRING (c
, p
);
2297 int offset
= p
- read_buffer
;
2298 read_buffer
= (char *) xrealloc (read_buffer
,
2299 read_buffer_size
*= 2);
2300 p
= read_buffer
+ offset
;
2301 end
= read_buffer
+ read_buffer_size
;
2308 if (!quoted
&& !uninterned_symbol
)
2311 register Lisp_Object val
;
2313 if (*p1
== '+' || *p1
== '-') p1
++;
2314 /* Is it an integer? */
2317 while (p1
!= p
&& (c
= *p1
) >= '0' && c
<= '9') p1
++;
2318 /* Integers can have trailing decimal points. */
2319 if (p1
> read_buffer
&& p1
< p
&& *p1
== '.') p1
++;
2321 /* It is an integer. */
2325 if (sizeof (int) == sizeof (EMACS_INT
))
2326 XSETINT (val
, atoi (read_buffer
));
2327 else if (sizeof (long) == sizeof (EMACS_INT
))
2328 XSETINT (val
, atol (read_buffer
));
2334 if (isfloat_string (read_buffer
))
2336 /* Compute NaN and infinities using 0.0 in a variable,
2337 to cope with compilers that think they are smarter
2343 /* Negate the value ourselves. This treats 0, NaNs,
2344 and infinity properly on IEEE floating point hosts,
2345 and works around a common bug where atof ("-0.0")
2347 int negative
= read_buffer
[0] == '-';
2349 /* The only way p[-1] can be 'F' or 'N', after isfloat_string
2350 returns 1, is if the input ends in e+INF or e+NaN. */
2357 value
= zero
/ zero
;
2360 value
= atof (read_buffer
+ negative
);
2364 return make_float (negative
? - value
: value
);
2368 if (uninterned_symbol
)
2369 return make_symbol (read_buffer
);
2371 return intern (read_buffer
);
2377 /* List of nodes we've seen during substitute_object_in_subtree. */
2378 static Lisp_Object seen_list
;
2381 substitute_object_in_subtree (object
, placeholder
)
2383 Lisp_Object placeholder
;
2385 Lisp_Object check_object
;
2387 /* We haven't seen any objects when we start. */
2390 /* Make all the substitutions. */
2392 = substitute_object_recurse (object
, placeholder
, object
);
2394 /* Clear seen_list because we're done with it. */
2397 /* The returned object here is expected to always eq the
2399 if (!EQ (check_object
, object
))
2400 error ("Unexpected mutation error in reader");
2403 /* Feval doesn't get called from here, so no gc protection is needed. */
2404 #define SUBSTITUTE(get_val, set_val) \
2406 Lisp_Object old_value = get_val; \
2407 Lisp_Object true_value \
2408 = substitute_object_recurse (object, placeholder,\
2411 if (!EQ (old_value, true_value)) \
2418 substitute_object_recurse (object
, placeholder
, subtree
)
2420 Lisp_Object placeholder
;
2421 Lisp_Object subtree
;
2423 /* If we find the placeholder, return the target object. */
2424 if (EQ (placeholder
, subtree
))
2427 /* If we've been to this node before, don't explore it again. */
2428 if (!EQ (Qnil
, Fmemq (subtree
, seen_list
)))
2431 /* If this node can be the entry point to a cycle, remember that
2432 we've seen it. It can only be such an entry point if it was made
2433 by #n=, which means that we can find it as a value in
2435 if (!EQ (Qnil
, Frassq (subtree
, read_objects
)))
2436 seen_list
= Fcons (subtree
, seen_list
);
2438 /* Recurse according to subtree's type.
2439 Every branch must return a Lisp_Object. */
2440 switch (XTYPE (subtree
))
2442 case Lisp_Vectorlike
:
2445 int length
= XINT (Flength(subtree
));
2446 for (i
= 0; i
< length
; i
++)
2448 Lisp_Object idx
= make_number (i
);
2449 SUBSTITUTE (Faref (subtree
, idx
),
2450 Faset (subtree
, idx
, true_value
));
2457 SUBSTITUTE (Fcar_safe (subtree
),
2458 Fsetcar (subtree
, true_value
));
2459 SUBSTITUTE (Fcdr_safe (subtree
),
2460 Fsetcdr (subtree
, true_value
));
2466 /* Check for text properties in each interval.
2467 substitute_in_interval contains part of the logic. */
2469 INTERVAL root_interval
= XSTRING (subtree
)->intervals
;
2470 Lisp_Object arg
= Fcons (object
, placeholder
);
2472 traverse_intervals (root_interval
, 1, 0,
2473 &substitute_in_interval
, arg
);
2478 /* Other types don't recurse any further. */
2484 /* Helper function for substitute_object_recurse. */
2486 substitute_in_interval (interval
, arg
)
2490 Lisp_Object object
= Fcar (arg
);
2491 Lisp_Object placeholder
= Fcdr (arg
);
2493 SUBSTITUTE(interval
->plist
, interval
->plist
= true_value
);
2512 if (*cp
== '+' || *cp
== '-')
2515 if (*cp
>= '0' && *cp
<= '9')
2518 while (*cp
>= '0' && *cp
<= '9')
2526 if (*cp
>= '0' && *cp
<= '9')
2529 while (*cp
>= '0' && *cp
<= '9')
2532 if (*cp
== 'e' || *cp
== 'E')
2536 if (*cp
== '+' || *cp
== '-')
2540 if (*cp
>= '0' && *cp
<= '9')
2543 while (*cp
>= '0' && *cp
<= '9')
2546 else if (cp
== start
)
2548 else if (cp
[-1] == '+' && cp
[0] == 'I' && cp
[1] == 'N' && cp
[2] == 'F')
2553 else if (cp
[-1] == '+' && cp
[0] == 'N' && cp
[1] == 'a' && cp
[2] == 'N')
2559 return (((*cp
== 0) || (*cp
== ' ') || (*cp
== '\t') || (*cp
== '\n') || (*cp
== '\r') || (*cp
== '\f'))
2560 && (state
== (LEAD_INT
|DOT_CHAR
|TRAIL_INT
)
2561 || state
== (DOT_CHAR
|TRAIL_INT
)
2562 || state
== (LEAD_INT
|E_CHAR
|EXP_INT
)
2563 || state
== (LEAD_INT
|DOT_CHAR
|TRAIL_INT
|E_CHAR
|EXP_INT
)
2564 || state
== (DOT_CHAR
|TRAIL_INT
|E_CHAR
|EXP_INT
)));
2569 read_vector (readcharfun
, bytecodeflag
)
2570 Lisp_Object readcharfun
;
2575 register Lisp_Object
*ptr
;
2576 register Lisp_Object tem
, item
, vector
;
2577 register struct Lisp_Cons
*otem
;
2580 tem
= read_list (1, readcharfun
);
2581 len
= Flength (tem
);
2582 vector
= (read_pure
? make_pure_vector (XINT (len
)) : Fmake_vector (len
, Qnil
));
2584 size
= XVECTOR (vector
)->size
;
2585 ptr
= XVECTOR (vector
)->contents
;
2586 for (i
= 0; i
< size
; i
++)
2589 /* If `load-force-doc-strings' is t when reading a lazily-loaded
2590 bytecode object, the docstring containing the bytecode and
2591 constants values must be treated as unibyte and passed to
2592 Fread, to get the actual bytecode string and constants vector. */
2593 if (bytecodeflag
&& load_force_doc_strings
)
2595 if (i
== COMPILED_BYTECODE
)
2597 if (!STRINGP (item
))
2598 error ("invalid byte code");
2600 /* Delay handling the bytecode slot until we know whether
2601 it is lazily-loaded (we can tell by whether the
2602 constants slot is nil). */
2603 ptr
[COMPILED_CONSTANTS
] = item
;
2606 else if (i
== COMPILED_CONSTANTS
)
2608 Lisp_Object bytestr
= ptr
[COMPILED_CONSTANTS
];
2612 /* Coerce string to unibyte (like string-as-unibyte,
2613 but without generating extra garbage and
2614 guaranteeing no change in the contents). */
2615 XSTRING (bytestr
)->size
= STRING_BYTES (XSTRING (bytestr
));
2616 SET_STRING_BYTES (XSTRING (bytestr
), -1);
2618 item
= Fread (bytestr
);
2620 error ("invalid byte code");
2622 otem
= XCONS (item
);
2623 bytestr
= XCAR (item
);
2628 /* Now handle the bytecode slot. */
2629 ptr
[COMPILED_BYTECODE
] = read_pure
? Fpurecopy (bytestr
) : bytestr
;
2632 ptr
[i
] = read_pure
? Fpurecopy (item
) : item
;
2640 /* FLAG = 1 means check for ] to terminate rather than ) and .
2641 FLAG = -1 means check for starting with defun
2642 and make structure pure. */
2645 read_list (flag
, readcharfun
)
2647 register Lisp_Object readcharfun
;
2649 /* -1 means check next element for defun,
2650 0 means don't check,
2651 1 means already checked and found defun. */
2652 int defunflag
= flag
< 0 ? -1 : 0;
2653 Lisp_Object val
, tail
;
2654 register Lisp_Object elt
, tem
;
2655 struct gcpro gcpro1
, gcpro2
;
2656 /* 0 is the normal case.
2657 1 means this list is a doc reference; replace it with the number 0.
2658 2 means this list is a doc reference; replace it with the doc string. */
2659 int doc_reference
= 0;
2661 /* Initialize this to 1 if we are reading a list. */
2662 int first_in_list
= flag
<= 0;
2671 elt
= read1 (readcharfun
, &ch
, first_in_list
);
2676 /* While building, if the list starts with #$, treat it specially. */
2677 if (EQ (elt
, Vload_file_name
)
2679 && !NILP (Vpurify_flag
))
2681 if (NILP (Vdoc_file_name
))
2682 /* We have not yet called Snarf-documentation, so assume
2683 this file is described in the DOC-MM.NN file
2684 and Snarf-documentation will fill in the right value later.
2685 For now, replace the whole list with 0. */
2688 /* We have already called Snarf-documentation, so make a relative
2689 file name for this file, so it can be found properly
2690 in the installed Lisp directory.
2691 We don't use Fexpand_file_name because that would make
2692 the directory absolute now. */
2693 elt
= concat2 (build_string ("../lisp/"),
2694 Ffile_name_nondirectory (elt
));
2696 else if (EQ (elt
, Vload_file_name
)
2698 && load_force_doc_strings
)
2707 Fsignal (Qinvalid_read_syntax
,
2708 Fcons (make_string (") or . in a vector", 18), Qnil
));
2716 XCDR (tail
) = read0 (readcharfun
);
2718 val
= read0 (readcharfun
);
2719 read1 (readcharfun
, &ch
, 0);
2723 if (doc_reference
== 1)
2724 return make_number (0);
2725 if (doc_reference
== 2)
2727 /* Get a doc string from the file we are loading.
2728 If it's in saved_doc_string, get it from there. */
2729 int pos
= XINT (XCDR (val
));
2730 /* Position is negative for user variables. */
2731 if (pos
< 0) pos
= -pos
;
2732 if (pos
>= saved_doc_string_position
2733 && pos
< (saved_doc_string_position
2734 + saved_doc_string_length
))
2736 int start
= pos
- saved_doc_string_position
;
2739 /* Process quoting with ^A,
2740 and find the end of the string,
2741 which is marked with ^_ (037). */
2742 for (from
= start
, to
= start
;
2743 saved_doc_string
[from
] != 037;)
2745 int c
= saved_doc_string
[from
++];
2748 c
= saved_doc_string
[from
++];
2750 saved_doc_string
[to
++] = c
;
2752 saved_doc_string
[to
++] = 0;
2754 saved_doc_string
[to
++] = 037;
2757 saved_doc_string
[to
++] = c
;
2760 return make_string (saved_doc_string
+ start
,
2763 /* Look in prev_saved_doc_string the same way. */
2764 else if (pos
>= prev_saved_doc_string_position
2765 && pos
< (prev_saved_doc_string_position
2766 + prev_saved_doc_string_length
))
2768 int start
= pos
- prev_saved_doc_string_position
;
2771 /* Process quoting with ^A,
2772 and find the end of the string,
2773 which is marked with ^_ (037). */
2774 for (from
= start
, to
= start
;
2775 prev_saved_doc_string
[from
] != 037;)
2777 int c
= prev_saved_doc_string
[from
++];
2780 c
= prev_saved_doc_string
[from
++];
2782 prev_saved_doc_string
[to
++] = c
;
2784 prev_saved_doc_string
[to
++] = 0;
2786 prev_saved_doc_string
[to
++] = 037;
2789 prev_saved_doc_string
[to
++] = c
;
2792 return make_string (prev_saved_doc_string
+ start
,
2796 return get_doc_string (val
, 0, 0);
2801 return Fsignal (Qinvalid_read_syntax
, Fcons (make_string (". in wrong context", 18), Qnil
));
2803 return Fsignal (Qinvalid_read_syntax
, Fcons (make_string ("] in a list", 11), Qnil
));
2805 tem
= (read_pure
&& flag
<= 0
2806 ? pure_cons (elt
, Qnil
)
2807 : Fcons (elt
, Qnil
));
2814 defunflag
= EQ (elt
, Qdefun
);
2815 else if (defunflag
> 0)
2820 Lisp_Object Vobarray
;
2821 Lisp_Object initial_obarray
;
2823 /* oblookup stores the bucket number here, for the sake of Funintern. */
2825 int oblookup_last_bucket_number
;
2827 static int hash_string ();
2828 Lisp_Object
oblookup ();
2830 /* Get an error if OBARRAY is not an obarray.
2831 If it is one, return it. */
2834 check_obarray (obarray
)
2835 Lisp_Object obarray
;
2837 while (!VECTORP (obarray
) || XVECTOR (obarray
)->size
== 0)
2839 /* If Vobarray is now invalid, force it to be valid. */
2840 if (EQ (Vobarray
, obarray
)) Vobarray
= initial_obarray
;
2842 obarray
= wrong_type_argument (Qvectorp
, obarray
);
2847 /* Intern the C string STR: return a symbol with that name,
2848 interned in the current obarray. */
2855 int len
= strlen (str
);
2856 Lisp_Object obarray
;
2859 if (!VECTORP (obarray
) || XVECTOR (obarray
)->size
== 0)
2860 obarray
= check_obarray (obarray
);
2861 tem
= oblookup (obarray
, str
, len
, len
);
2864 return Fintern (make_string (str
, len
), obarray
);
2867 /* Create an uninterned symbol with name STR. */
2873 int len
= strlen (str
);
2875 return Fmake_symbol ((!NILP (Vpurify_flag
)
2876 ? make_pure_string (str
, len
, len
, 0)
2877 : make_string (str
, len
)));
2880 DEFUN ("intern", Fintern
, Sintern
, 1, 2, 0,
2881 "Return the canonical symbol whose name is STRING.\n\
2882 If there is none, one is created by this function and returned.\n\
2883 A second optional argument specifies the obarray to use;\n\
2884 it defaults to the value of `obarray'.")
2886 Lisp_Object string
, obarray
;
2888 register Lisp_Object tem
, sym
, *ptr
;
2890 if (NILP (obarray
)) obarray
= Vobarray
;
2891 obarray
= check_obarray (obarray
);
2893 CHECK_STRING (string
, 0);
2895 tem
= oblookup (obarray
, XSTRING (string
)->data
,
2896 XSTRING (string
)->size
,
2897 STRING_BYTES (XSTRING (string
)));
2898 if (!INTEGERP (tem
))
2901 if (!NILP (Vpurify_flag
))
2902 string
= Fpurecopy (string
);
2903 sym
= Fmake_symbol (string
);
2904 XSYMBOL (sym
)->obarray
= obarray
;
2906 if ((XSTRING (string
)->data
[0] == ':')
2907 && EQ (obarray
, initial_obarray
))
2908 XSYMBOL (sym
)->value
= sym
;
2910 ptr
= &XVECTOR (obarray
)->contents
[XINT (tem
)];
2912 XSYMBOL (sym
)->next
= XSYMBOL (*ptr
);
2914 XSYMBOL (sym
)->next
= 0;
2919 DEFUN ("intern-soft", Fintern_soft
, Sintern_soft
, 1, 2, 0,
2920 "Return the canonical symbol named NAME, or nil if none exists.\n\
2921 NAME may be a string or a symbol. If it is a symbol, that exact\n\
2922 symbol is searched for.\n\
2923 A second optional argument specifies the obarray to use;\n\
2924 it defaults to the value of `obarray'.")
2926 Lisp_Object name
, obarray
;
2928 register Lisp_Object tem
;
2929 struct Lisp_String
*string
;
2931 if (NILP (obarray
)) obarray
= Vobarray
;
2932 obarray
= check_obarray (obarray
);
2934 if (!SYMBOLP (name
))
2936 CHECK_STRING (name
, 0);
2937 string
= XSTRING (name
);
2940 string
= XSYMBOL (name
)->name
;
2942 tem
= oblookup (obarray
, string
->data
, string
->size
, STRING_BYTES (string
));
2943 if (INTEGERP (tem
) || (SYMBOLP (name
) && !EQ (name
, tem
)))
2949 DEFUN ("unintern", Funintern
, Sunintern
, 1, 2, 0,
2950 "Delete the symbol named NAME, if any, from OBARRAY.\n\
2951 The value is t if a symbol was found and deleted, nil otherwise.\n\
2952 NAME may be a string or a symbol. If it is a symbol, that symbol\n\
2953 is deleted, if it belongs to OBARRAY--no other symbol is deleted.\n\
2954 OBARRAY defaults to the value of the variable `obarray'.")
2956 Lisp_Object name
, obarray
;
2958 register Lisp_Object string
, tem
;
2961 if (NILP (obarray
)) obarray
= Vobarray
;
2962 obarray
= check_obarray (obarray
);
2965 XSETSTRING (string
, XSYMBOL (name
)->name
);
2968 CHECK_STRING (name
, 0);
2972 tem
= oblookup (obarray
, XSTRING (string
)->data
,
2973 XSTRING (string
)->size
,
2974 STRING_BYTES (XSTRING (string
)));
2977 /* If arg was a symbol, don't delete anything but that symbol itself. */
2978 if (SYMBOLP (name
) && !EQ (name
, tem
))
2981 XSYMBOL (tem
)->obarray
= Qnil
;
2983 hash
= oblookup_last_bucket_number
;
2985 if (EQ (XVECTOR (obarray
)->contents
[hash
], tem
))
2987 if (XSYMBOL (tem
)->next
)
2988 XSETSYMBOL (XVECTOR (obarray
)->contents
[hash
], XSYMBOL (tem
)->next
);
2990 XSETINT (XVECTOR (obarray
)->contents
[hash
], 0);
2994 Lisp_Object tail
, following
;
2996 for (tail
= XVECTOR (obarray
)->contents
[hash
];
2997 XSYMBOL (tail
)->next
;
3000 XSETSYMBOL (following
, XSYMBOL (tail
)->next
);
3001 if (EQ (following
, tem
))
3003 XSYMBOL (tail
)->next
= XSYMBOL (following
)->next
;
3012 /* Return the symbol in OBARRAY whose names matches the string
3013 of SIZE characters (SIZE_BYTE bytes) at PTR.
3014 If there is no such symbol in OBARRAY, return nil.
3016 Also store the bucket number in oblookup_last_bucket_number. */
3019 oblookup (obarray
, ptr
, size
, size_byte
)
3020 Lisp_Object obarray
;
3022 int size
, size_byte
;
3026 register Lisp_Object tail
;
3027 Lisp_Object bucket
, tem
;
3029 if (!VECTORP (obarray
)
3030 || (obsize
= XVECTOR (obarray
)->size
) == 0)
3032 obarray
= check_obarray (obarray
);
3033 obsize
= XVECTOR (obarray
)->size
;
3035 /* This is sometimes needed in the middle of GC. */
3036 obsize
&= ~ARRAY_MARK_FLAG
;
3037 /* Combining next two lines breaks VMS C 2.3. */
3038 hash
= hash_string (ptr
, size_byte
);
3040 bucket
= XVECTOR (obarray
)->contents
[hash
];
3041 oblookup_last_bucket_number
= hash
;
3042 if (XFASTINT (bucket
) == 0)
3044 else if (!SYMBOLP (bucket
))
3045 error ("Bad data in guts of obarray"); /* Like CADR error message */
3047 for (tail
= bucket
; ; XSETSYMBOL (tail
, XSYMBOL (tail
)->next
))
3049 if (STRING_BYTES (XSYMBOL (tail
)->name
) == size_byte
3050 && XSYMBOL (tail
)->name
->size
== size
3051 && !bcmp (XSYMBOL (tail
)->name
->data
, ptr
, size_byte
))
3053 else if (XSYMBOL (tail
)->next
== 0)
3056 XSETINT (tem
, hash
);
3061 hash_string (ptr
, len
)
3065 register unsigned char *p
= ptr
;
3066 register unsigned char *end
= p
+ len
;
3067 register unsigned char c
;
3068 register int hash
= 0;
3073 if (c
>= 0140) c
-= 40;
3074 hash
= ((hash
<<3) + (hash
>>28) + c
);
3076 return hash
& 07777777777;
3080 map_obarray (obarray
, fn
, arg
)
3081 Lisp_Object obarray
;
3082 void (*fn
) P_ ((Lisp_Object
, Lisp_Object
));
3086 register Lisp_Object tail
;
3087 CHECK_VECTOR (obarray
, 1);
3088 for (i
= XVECTOR (obarray
)->size
- 1; i
>= 0; i
--)
3090 tail
= XVECTOR (obarray
)->contents
[i
];
3095 if (XSYMBOL (tail
)->next
== 0)
3097 XSETSYMBOL (tail
, XSYMBOL (tail
)->next
);
3103 mapatoms_1 (sym
, function
)
3104 Lisp_Object sym
, function
;
3106 call1 (function
, sym
);
3109 DEFUN ("mapatoms", Fmapatoms
, Smapatoms
, 1, 2, 0,
3110 "Call FUNCTION on every symbol in OBARRAY.\n\
3111 OBARRAY defaults to the value of `obarray'.")
3113 Lisp_Object function
, obarray
;
3115 if (NILP (obarray
)) obarray
= Vobarray
;
3116 obarray
= check_obarray (obarray
);
3118 map_obarray (obarray
, mapatoms_1
, function
);
3122 #define OBARRAY_SIZE 1511
3127 Lisp_Object oblength
;
3131 XSETFASTINT (oblength
, OBARRAY_SIZE
);
3133 Qnil
= Fmake_symbol (make_pure_string ("nil", 3, 3, 0));
3134 Vobarray
= Fmake_vector (oblength
, make_number (0));
3135 initial_obarray
= Vobarray
;
3136 staticpro (&initial_obarray
);
3137 /* Intern nil in the obarray */
3138 XSYMBOL (Qnil
)->obarray
= Vobarray
;
3139 /* These locals are to kludge around a pyramid compiler bug. */
3140 hash
= hash_string ("nil", 3);
3141 /* Separate statement here to avoid VAXC bug. */
3142 hash
%= OBARRAY_SIZE
;
3143 tem
= &XVECTOR (Vobarray
)->contents
[hash
];
3146 Qunbound
= Fmake_symbol (make_pure_string ("unbound", 7, 7, 0));
3147 XSYMBOL (Qnil
)->function
= Qunbound
;
3148 XSYMBOL (Qunbound
)->value
= Qunbound
;
3149 XSYMBOL (Qunbound
)->function
= Qunbound
;
3152 XSYMBOL (Qnil
)->value
= Qnil
;
3153 XSYMBOL (Qnil
)->plist
= Qnil
;
3154 XSYMBOL (Qt
)->value
= Qt
;
3156 /* Qt is correct even if CANNOT_DUMP. loadup.el will set to nil at end. */
3159 Qvariable_documentation
= intern ("variable-documentation");
3160 staticpro (&Qvariable_documentation
);
3162 read_buffer_size
= 100 + MAX_MULTIBYTE_LENGTH
;
3163 read_buffer
= (char *) xmalloc (read_buffer_size
);
3168 struct Lisp_Subr
*sname
;
3171 sym
= intern (sname
->symbol_name
);
3172 XSETSUBR (XSYMBOL (sym
)->function
, sname
);
3175 #ifdef NOTDEF /* use fset in subr.el now */
3177 defalias (sname
, string
)
3178 struct Lisp_Subr
*sname
;
3182 sym
= intern (string
);
3183 XSETSUBR (XSYMBOL (sym
)->function
, sname
);
3187 /* Define an "integer variable"; a symbol whose value is forwarded
3188 to a C variable of type int. Sample call: */
3189 /* DEFVAR_INT ("indent-tabs-mode", &indent_tabs_mode, "Documentation"); */
3191 defvar_int (namestring
, address
)
3195 Lisp_Object sym
, val
;
3196 sym
= intern (namestring
);
3197 val
= allocate_misc ();
3198 XMISCTYPE (val
) = Lisp_Misc_Intfwd
;
3199 XINTFWD (val
)->intvar
= address
;
3200 XSYMBOL (sym
)->value
= val
;
3203 /* Similar but define a variable whose value is T if address contains 1,
3204 NIL if address contains 0 */
3206 defvar_bool (namestring
, address
)
3210 Lisp_Object sym
, val
;
3211 sym
= intern (namestring
);
3212 val
= allocate_misc ();
3213 XMISCTYPE (val
) = Lisp_Misc_Boolfwd
;
3214 XBOOLFWD (val
)->boolvar
= address
;
3215 XSYMBOL (sym
)->value
= val
;
3216 Vbyte_boolean_vars
= Fcons (sym
, Vbyte_boolean_vars
);
3219 /* Similar but define a variable whose value is the Lisp Object stored
3220 at address. Two versions: with and without gc-marking of the C
3221 variable. The nopro version is used when that variable will be
3222 gc-marked for some other reason, since marking the same slot twice
3223 can cause trouble with strings. */
3225 defvar_lisp_nopro (namestring
, address
)
3227 Lisp_Object
*address
;
3229 Lisp_Object sym
, val
;
3230 sym
= intern (namestring
);
3231 val
= allocate_misc ();
3232 XMISCTYPE (val
) = Lisp_Misc_Objfwd
;
3233 XOBJFWD (val
)->objvar
= address
;
3234 XSYMBOL (sym
)->value
= val
;
3238 defvar_lisp (namestring
, address
)
3240 Lisp_Object
*address
;
3242 defvar_lisp_nopro (namestring
, address
);
3243 staticpro (address
);
3246 /* Similar but define a variable whose value is the Lisp Object stored in
3247 the current buffer. address is the address of the slot in the buffer
3248 that is current now. */
3251 defvar_per_buffer (namestring
, address
, type
, doc
)
3253 Lisp_Object
*address
;
3257 Lisp_Object sym
, val
;
3259 extern struct buffer buffer_local_symbols
;
3261 sym
= intern (namestring
);
3262 val
= allocate_misc ();
3263 offset
= (char *)address
- (char *)current_buffer
;
3265 XMISCTYPE (val
) = Lisp_Misc_Buffer_Objfwd
;
3266 XBUFFER_OBJFWD (val
)->offset
= offset
;
3267 XSYMBOL (sym
)->value
= val
;
3268 PER_BUFFER_SYMBOL (offset
) = sym
;
3269 PER_BUFFER_TYPE (offset
) = type
;
3271 if (PER_BUFFER_IDX (offset
) == 0)
3272 /* Did a DEFVAR_PER_BUFFER without initializing the corresponding
3273 slot of buffer_local_flags */
3278 /* Similar but define a variable whose value is the Lisp Object stored
3279 at a particular offset in the current kboard object. */
3282 defvar_kboard (namestring
, offset
)
3286 Lisp_Object sym
, val
;
3287 sym
= intern (namestring
);
3288 val
= allocate_misc ();
3289 XMISCTYPE (val
) = Lisp_Misc_Kboard_Objfwd
;
3290 XKBOARD_OBJFWD (val
)->offset
= offset
;
3291 XSYMBOL (sym
)->value
= val
;
3294 /* Record the value of load-path used at the start of dumping
3295 so we can see if the site changed it later during dumping. */
3296 static Lisp_Object dump_path
;
3302 int turn_off_warning
= 0;
3304 /* Compute the default load-path. */
3306 normal
= PATH_LOADSEARCH
;
3307 Vload_path
= decode_env_path (0, normal
);
3309 if (NILP (Vpurify_flag
))
3310 normal
= PATH_LOADSEARCH
;
3312 normal
= PATH_DUMPLOADSEARCH
;
3314 /* In a dumped Emacs, we normally have to reset the value of
3315 Vload_path from PATH_LOADSEARCH, since the value that was dumped
3316 uses ../lisp, instead of the path of the installed elisp
3317 libraries. However, if it appears that Vload_path was changed
3318 from the default before dumping, don't override that value. */
3321 if (! NILP (Fequal (dump_path
, Vload_path
)))
3323 Vload_path
= decode_env_path (0, normal
);
3324 if (!NILP (Vinstallation_directory
))
3326 /* Add to the path the lisp subdir of the
3327 installation dir, if it exists. */
3328 Lisp_Object tem
, tem1
;
3329 tem
= Fexpand_file_name (build_string ("lisp"),
3330 Vinstallation_directory
);
3331 tem1
= Ffile_exists_p (tem
);
3334 if (NILP (Fmember (tem
, Vload_path
)))
3336 turn_off_warning
= 1;
3337 Vload_path
= nconc2 (Vload_path
, Fcons (tem
, Qnil
));
3341 /* That dir doesn't exist, so add the build-time
3342 Lisp dirs instead. */
3343 Vload_path
= nconc2 (Vload_path
, dump_path
);
3345 /* Add leim under the installation dir, if it exists. */
3346 tem
= Fexpand_file_name (build_string ("leim"),
3347 Vinstallation_directory
);
3348 tem1
= Ffile_exists_p (tem
);
3351 if (NILP (Fmember (tem
, Vload_path
)))
3352 Vload_path
= nconc2 (Vload_path
, Fcons (tem
, Qnil
));
3355 /* Add site-list under the installation dir, if it exists. */
3356 tem
= Fexpand_file_name (build_string ("site-lisp"),
3357 Vinstallation_directory
);
3358 tem1
= Ffile_exists_p (tem
);
3361 if (NILP (Fmember (tem
, Vload_path
)))
3362 Vload_path
= nconc2 (Vload_path
, Fcons (tem
, Qnil
));
3365 /* If Emacs was not built in the source directory,
3366 and it is run from where it was built, add to load-path
3367 the lisp, leim and site-lisp dirs under that directory. */
3369 if (NILP (Fequal (Vinstallation_directory
, Vsource_directory
)))
3373 tem
= Fexpand_file_name (build_string ("src/Makefile"),
3374 Vinstallation_directory
);
3375 tem1
= Ffile_exists_p (tem
);
3377 /* Don't be fooled if they moved the entire source tree
3378 AFTER dumping Emacs. If the build directory is indeed
3379 different from the source dir, src/Makefile.in and
3380 src/Makefile will not be found together. */
3381 tem
= Fexpand_file_name (build_string ("src/Makefile.in"),
3382 Vinstallation_directory
);
3383 tem2
= Ffile_exists_p (tem
);
3384 if (!NILP (tem1
) && NILP (tem2
))
3386 tem
= Fexpand_file_name (build_string ("lisp"),
3389 if (NILP (Fmember (tem
, Vload_path
)))
3390 Vload_path
= nconc2 (Vload_path
, Fcons (tem
, Qnil
));
3392 tem
= Fexpand_file_name (build_string ("leim"),
3395 if (NILP (Fmember (tem
, Vload_path
)))
3396 Vload_path
= nconc2 (Vload_path
, Fcons (tem
, Qnil
));
3398 tem
= Fexpand_file_name (build_string ("site-lisp"),
3401 if (NILP (Fmember (tem
, Vload_path
)))
3402 Vload_path
= nconc2 (Vload_path
, Fcons (tem
, Qnil
));
3410 /* NORMAL refers to the lisp dir in the source directory. */
3411 /* We used to add ../lisp at the front here, but
3412 that caused trouble because it was copied from dump_path
3413 into Vload_path, aboe, when Vinstallation_directory was non-nil.
3414 It should be unnecessary. */
3415 Vload_path
= decode_env_path (0, normal
);
3416 dump_path
= Vload_path
;
3421 /* When Emacs is invoked over network shares on NT, PATH_LOADSEARCH is
3422 almost never correct, thereby causing a warning to be printed out that
3423 confuses users. Since PATH_LOADSEARCH is always overridden by the
3424 EMACSLOADPATH environment variable below, disable the warning on NT. */
3426 /* Warn if dirs in the *standard* path don't exist. */
3427 if (!turn_off_warning
)
3429 Lisp_Object path_tail
;
3431 for (path_tail
= Vload_path
;
3433 path_tail
= XCDR (path_tail
))
3435 Lisp_Object dirfile
;
3436 dirfile
= Fcar (path_tail
);
3437 if (STRINGP (dirfile
))
3439 dirfile
= Fdirectory_file_name (dirfile
);
3440 if (access (XSTRING (dirfile
)->data
, 0) < 0)
3441 dir_warning ("Warning: Lisp directory `%s' does not exist.\n",
3446 #endif /* WINDOWSNT */
3448 /* If the EMACSLOADPATH environment variable is set, use its value.
3449 This doesn't apply if we're dumping. */
3451 if (NILP (Vpurify_flag
)
3452 && egetenv ("EMACSLOADPATH"))
3454 Vload_path
= decode_env_path ("EMACSLOADPATH", normal
);
3458 load_in_progress
= 0;
3459 Vload_file_name
= Qnil
;
3461 load_descriptor_list
= Qnil
;
3463 Vstandard_input
= Qt
;
3464 Vloads_in_progress
= Qnil
;
3467 /* Print a warning, using format string FORMAT, that directory DIRNAME
3468 does not exist. Print it on stderr and put it in *Message*. */
3471 dir_warning (format
, dirname
)
3473 Lisp_Object dirname
;
3476 = (char *) alloca (XSTRING (dirname
)->size
+ strlen (format
) + 5);
3478 fprintf (stderr
, format
, XSTRING (dirname
)->data
);
3479 sprintf (buffer
, format
, XSTRING (dirname
)->data
);
3480 /* Don't log the warning before we've initialized!! */
3482 message_dolog (buffer
, strlen (buffer
), 0, STRING_MULTIBYTE (dirname
));
3489 defsubr (&Sread_from_string
);
3491 defsubr (&Sintern_soft
);
3492 defsubr (&Sunintern
);
3494 defsubr (&Seval_buffer
);
3495 defsubr (&Seval_region
);
3496 defsubr (&Sread_char
);
3497 defsubr (&Sread_char_exclusive
);
3498 defsubr (&Sread_event
);
3499 defsubr (&Sget_file_char
);
3500 defsubr (&Smapatoms
);
3502 DEFVAR_LISP ("obarray", &Vobarray
,
3503 "Symbol table for use by `intern' and `read'.\n\
3504 It is a vector whose length ought to be prime for best results.\n\
3505 The vector's contents don't make sense if examined from Lisp programs;\n\
3506 to find all the symbols in an obarray, use `mapatoms'.");
3508 DEFVAR_LISP ("values", &Vvalues
,
3509 "List of values of all expressions which were read, evaluated and printed.\n\
3510 Order is reverse chronological.");
3512 DEFVAR_LISP ("standard-input", &Vstandard_input
,
3513 "Stream for read to get input from.\n\
3514 See documentation of `read' for possible values.");
3515 Vstandard_input
= Qt
;
3517 DEFVAR_LISP ("load-path", &Vload_path
,
3518 "*List of directories to search for files to load.\n\
3519 Each element is a string (directory name) or nil (try default directory).\n\
3520 Initialized based on EMACSLOADPATH environment variable, if any,\n\
3521 otherwise to default specified by file `epaths.h' when Emacs was built.");
3523 DEFVAR_BOOL ("load-in-progress", &load_in_progress
,
3524 "Non-nil iff inside of `load'.");
3526 DEFVAR_LISP ("after-load-alist", &Vafter_load_alist
,
3527 "An alist of expressions to be evalled when particular files are loaded.\n\
3528 Each element looks like (FILENAME FORMS...).\n\
3529 When `load' is run and the file-name argument is FILENAME,\n\
3530 the FORMS in the corresponding element are executed at the end of loading.\n\n\
3531 FILENAME must match exactly! Normally FILENAME is the name of a library,\n\
3532 with no directory specified, since that is how `load' is normally called.\n\
3533 An error in FORMS does not undo the load,\n\
3534 but does prevent execution of the rest of the FORMS.");
3535 Vafter_load_alist
= Qnil
;
3537 DEFVAR_LISP ("load-history", &Vload_history
,
3538 "Alist mapping source file names to symbols and features.\n\
3539 Each alist element is a list that starts with a file name,\n\
3540 except for one element (optional) that starts with nil and describes\n\
3541 definitions evaluated from buffers not visiting files.\n\
3542 The remaining elements of each list are symbols defined as functions\n\
3543 or variables, and cons cells `(provide . FEATURE)', `(require . FEATURE)',\n\
3544 and `(autoload . SYMBOL)'.");
3545 Vload_history
= Qnil
;
3547 DEFVAR_LISP ("load-file-name", &Vload_file_name
,
3548 "Full name of file being loaded by `load'.");
3549 Vload_file_name
= Qnil
;
3551 DEFVAR_LISP ("user-init-file", &Vuser_init_file
,
3552 "File name, including directory, of user's initialization file.\n\
3553 If the file loaded had extension `.elc' and there was a corresponding `.el'\n\
3554 file, this variable contains the name of the .el file, suitable for use\n\
3555 by functions like `custom-save-all' which edit the init file.");
3556 Vuser_init_file
= Qnil
;
3558 DEFVAR_LISP ("current-load-list", &Vcurrent_load_list
,
3559 "Used for internal purposes by `load'.");
3560 Vcurrent_load_list
= Qnil
;
3562 DEFVAR_LISP ("load-read-function", &Vload_read_function
,
3563 "Function used by `load' and `eval-region' for reading expressions.\n\
3564 The default is nil, which means use the function `read'.");
3565 Vload_read_function
= Qnil
;
3567 DEFVAR_LISP ("load-source-file-function", &Vload_source_file_function
,
3568 "Function called in `load' for loading an Emacs lisp source file.\n\
3569 This function is for doing code conversion before reading the source file.\n\
3570 If nil, loading is done without any code conversion.\n\
3571 Arguments are FULLNAME, FILE, NOERROR, NOMESSAGE, where\n\
3572 FULLNAME is the full name of FILE.\n\
3573 See `load' for the meaning of the remaining arguments.");
3574 Vload_source_file_function
= Qnil
;
3576 DEFVAR_BOOL ("load-force-doc-strings", &load_force_doc_strings
,
3577 "Non-nil means `load' should force-load all dynamic doc strings.\n\
3578 This is useful when the file being loaded is a temporary copy.");
3579 load_force_doc_strings
= 0;
3581 DEFVAR_BOOL ("load-convert-to-unibyte", &load_convert_to_unibyte
,
3582 "Non-nil means `read' converts strings to unibyte whenever possible.\n\
3583 This is normally bound by `load' and `eval-buffer' to control `read',\n\
3584 and is not meant for users to change.");
3585 load_convert_to_unibyte
= 0;
3587 DEFVAR_LISP ("source-directory", &Vsource_directory
,
3588 "Directory in which Emacs sources were found when Emacs was built.\n\
3589 You cannot count on them to still be there!");
3591 = Fexpand_file_name (build_string ("../"),
3592 Fcar (decode_env_path (0, PATH_DUMPLOADSEARCH
)));
3594 DEFVAR_LISP ("preloaded-file-list", &Vpreloaded_file_list
,
3595 "List of files that were preloaded (when dumping Emacs).");
3596 Vpreloaded_file_list
= Qnil
;
3598 DEFVAR_LISP ("byte-boolean-vars", &Vbyte_boolean_vars
,
3599 "List of all DEFVAR_BOOL variables, used by the byte code optimizer.");
3600 Vbyte_boolean_vars
= Qnil
;
3602 DEFVAR_BOOL ("load-dangerous-libraries", &load_dangerous_libraries
,
3603 "Non-nil means load dangerous compiled Lisp files.\n\
3604 Some versions of XEmacs use different byte codes than Emacs. These\n\
3605 incompatible byte codes can make Emacs crash when it tries to execute\n\
3607 load_dangerous_libraries
= 0;
3609 DEFVAR_LISP ("bytecomp-version-regexp", &Vbytecomp_version_regexp
,
3610 "Regular expression matching safe to load compiled Lisp files.\n\
3611 When Emacs loads a compiled Lisp file, it reads the first 512 bytes\n\
3612 from the file, and matches them against this regular expression.\n\
3613 When the regular expression matches, the file is considered to be safe\n\
3614 to load. See also `load-dangerous-libraries'.");
3615 Vbytecomp_version_regexp
3616 = build_string ("^;;;.\\(in Emacs version\\|bytecomp version FSF\\)");
3618 DEFVAR_LISP ("recursive-load-depth-limit", &Vrecursive_load_depth_limit
,
3619 "Limit for depth of recursive loads.\n\
3620 Value should be either an integer > 0 specifying the limit, or nil for\n\
3622 Vrecursive_load_depth_limit
= make_number (10);
3624 /* Vsource_directory was initialized in init_lread. */
3626 load_descriptor_list
= Qnil
;
3627 staticpro (&load_descriptor_list
);
3629 Qcurrent_load_list
= intern ("current-load-list");
3630 staticpro (&Qcurrent_load_list
);
3632 Qstandard_input
= intern ("standard-input");
3633 staticpro (&Qstandard_input
);
3635 Qread_char
= intern ("read-char");
3636 staticpro (&Qread_char
);
3638 Qget_file_char
= intern ("get-file-char");
3639 staticpro (&Qget_file_char
);
3641 Qbackquote
= intern ("`");
3642 staticpro (&Qbackquote
);
3643 Qcomma
= intern (",");
3644 staticpro (&Qcomma
);
3645 Qcomma_at
= intern (",@");
3646 staticpro (&Qcomma_at
);
3647 Qcomma_dot
= intern (",.");
3648 staticpro (&Qcomma_dot
);
3650 Qinhibit_file_name_operation
= intern ("inhibit-file-name-operation");
3651 staticpro (&Qinhibit_file_name_operation
);
3653 Qascii_character
= intern ("ascii-character");
3654 staticpro (&Qascii_character
);
3656 Qfunction
= intern ("function");
3657 staticpro (&Qfunction
);
3659 Qload
= intern ("load");
3662 Qload_file_name
= intern ("load-file-name");
3663 staticpro (&Qload_file_name
);
3665 staticpro (&dump_path
);
3667 staticpro (&read_objects
);
3668 read_objects
= Qnil
;
3669 staticpro (&seen_list
);
3671 Vloads_in_progress
= Qnil
;
3672 staticpro (&Vloads_in_progress
);