1 /* Lisp parsing and input streams.
3 Copyright (C) 1985-1989, 1993-1995, 1997-2012 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
23 #include <sys/types.h>
27 #include <limits.h> /* For CHAR_BIT. */
28 #include <stat-time.h>
30 #include "intervals.h"
31 #include "character.h"
39 #include "termhooks.h"
41 #include "blockinput.h"
55 #endif /* HAVE_SETLOCALE */
60 #define file_offset off_t
61 #define file_tell ftello
63 #define file_offset long
64 #define file_tell ftell
67 /* Hash table read constants. */
68 static Lisp_Object Qhash_table
, Qdata
;
69 static Lisp_Object Qtest
, Qsize
;
70 static Lisp_Object Qweakness
;
71 static Lisp_Object Qrehash_size
;
72 static Lisp_Object Qrehash_threshold
;
74 static Lisp_Object Qread_char
, Qget_file_char
, Qcurrent_load_list
;
75 Lisp_Object Qstandard_input
;
76 Lisp_Object Qvariable_documentation
;
77 static Lisp_Object Qascii_character
, Qload
, Qload_file_name
;
78 Lisp_Object Qbackquote
, Qcomma
, Qcomma_at
, Qcomma_dot
, Qfunction
;
79 static Lisp_Object Qinhibit_file_name_operation
;
80 static Lisp_Object Qeval_buffer_list
;
81 Lisp_Object Qlexical_binding
;
82 static Lisp_Object Qfile_truename
, Qdo_after_load_evaluation
; /* ACM 2006/5/16 */
84 /* Used instead of Qget_file_char while loading *.elc files compiled
85 by Emacs 21 or older. */
86 static Lisp_Object Qget_emacs_mule_file_char
;
88 static Lisp_Object Qload_force_doc_strings
;
90 static Lisp_Object Qload_in_progress
;
92 /* The association list of objects read with the #n=object form.
93 Each member of the list has the form (n . object), and is used to
94 look up the object for the corresponding #n# construct.
95 It must be set to nil before all top-level calls to read0. */
96 static Lisp_Object read_objects
;
98 /* Nonzero means READCHAR should read bytes one by one (not character)
99 when READCHARFUN is Qget_file_char or Qget_emacs_mule_file_char.
100 This is set to 1 by read1 temporarily while handling #@NUMBER. */
101 static int load_each_byte
;
103 /* List of descriptors now open for Fload. */
104 static Lisp_Object load_descriptor_list
;
106 /* File for get_file_char to read from. Use by load. */
107 static FILE *instream
;
109 /* For use within read-from-string (this reader is non-reentrant!!) */
110 static ptrdiff_t read_from_string_index
;
111 static ptrdiff_t read_from_string_index_byte
;
112 static ptrdiff_t read_from_string_limit
;
114 /* Number of characters read in the current call to Fread or
115 Fread_from_string. */
116 static EMACS_INT readchar_count
;
118 /* This contains the last string skipped with #@. */
119 static char *saved_doc_string
;
120 /* Length of buffer allocated in saved_doc_string. */
121 static ptrdiff_t saved_doc_string_size
;
122 /* Length of actual data in saved_doc_string. */
123 static ptrdiff_t saved_doc_string_length
;
124 /* This is the file position that string came from. */
125 static file_offset saved_doc_string_position
;
127 /* This contains the previous string skipped with #@.
128 We copy it from saved_doc_string when a new string
129 is put in saved_doc_string. */
130 static char *prev_saved_doc_string
;
131 /* Length of buffer allocated in prev_saved_doc_string. */
132 static ptrdiff_t prev_saved_doc_string_size
;
133 /* Length of actual data in prev_saved_doc_string. */
134 static ptrdiff_t prev_saved_doc_string_length
;
135 /* This is the file position that string came from. */
136 static file_offset prev_saved_doc_string_position
;
138 /* Nonzero means inside a new-style backquote
139 with no surrounding parentheses.
140 Fread initializes this to zero, so we need not specbind it
141 or worry about what happens to it when there is an error. */
142 static int new_backquote_flag
;
143 static Lisp_Object Qold_style_backquotes
;
145 /* A list of file names for files being loaded in Fload. Used to
146 check for recursive loads. */
148 static Lisp_Object Vloads_in_progress
;
150 static int read_emacs_mule_char (int, int (*) (int, Lisp_Object
),
153 static void readevalloop (Lisp_Object
, FILE*, Lisp_Object
, int,
154 Lisp_Object
, Lisp_Object
,
155 Lisp_Object
, Lisp_Object
);
156 static Lisp_Object
load_unwind (Lisp_Object
);
157 static Lisp_Object
load_descriptor_unwind (Lisp_Object
);
159 /* Functions that read one byte from the current source READCHARFUN
160 or unreads one byte. If the integer argument C is -1, it returns
161 one read byte, or -1 when there's no more byte in the source. If C
162 is 0 or positive, it unreads C, and the return value is not
165 static int readbyte_for_lambda (int, Lisp_Object
);
166 static int readbyte_from_file (int, Lisp_Object
);
167 static int readbyte_from_string (int, Lisp_Object
);
169 /* Handle unreading and rereading of characters.
170 Write READCHAR to read a character,
171 UNREAD(c) to unread c to be read again.
173 These macros correctly read/unread multibyte characters. */
175 #define READCHAR readchar (readcharfun, NULL)
176 #define UNREAD(c) unreadchar (readcharfun, c)
178 /* Same as READCHAR but set *MULTIBYTE to the multibyteness of the source. */
179 #define READCHAR_REPORT_MULTIBYTE(multibyte) readchar (readcharfun, multibyte)
181 /* When READCHARFUN is Qget_file_char, Qget_emacs_mule_file_char,
182 Qlambda, or a cons, we use this to keep an unread character because
183 a file stream can't handle multibyte-char unreading. The value -1
184 means that there's no unread character. */
185 static int unread_char
;
188 readchar (Lisp_Object readcharfun
, bool *multibyte
)
192 int (*readbyte
) (int, Lisp_Object
);
193 unsigned char buf
[MAX_MULTIBYTE_LENGTH
];
195 int emacs_mule_encoding
= 0;
202 if (BUFFERP (readcharfun
))
204 register struct buffer
*inbuffer
= XBUFFER (readcharfun
);
206 ptrdiff_t pt_byte
= BUF_PT_BYTE (inbuffer
);
208 if (pt_byte
>= BUF_ZV_BYTE (inbuffer
))
211 if (! NILP (BVAR (inbuffer
, enable_multibyte_characters
)))
213 /* Fetch the character code from the buffer. */
214 unsigned char *p
= BUF_BYTE_ADDRESS (inbuffer
, pt_byte
);
215 BUF_INC_POS (inbuffer
, pt_byte
);
222 c
= BUF_FETCH_BYTE (inbuffer
, pt_byte
);
223 if (! ASCII_BYTE_P (c
))
224 c
= BYTE8_TO_CHAR (c
);
227 SET_BUF_PT_BOTH (inbuffer
, BUF_PT (inbuffer
) + 1, pt_byte
);
231 if (MARKERP (readcharfun
))
233 register struct buffer
*inbuffer
= XMARKER (readcharfun
)->buffer
;
235 ptrdiff_t bytepos
= marker_byte_position (readcharfun
);
237 if (bytepos
>= BUF_ZV_BYTE (inbuffer
))
240 if (! NILP (BVAR (inbuffer
, enable_multibyte_characters
)))
242 /* Fetch the character code from the buffer. */
243 unsigned char *p
= BUF_BYTE_ADDRESS (inbuffer
, bytepos
);
244 BUF_INC_POS (inbuffer
, bytepos
);
251 c
= BUF_FETCH_BYTE (inbuffer
, bytepos
);
252 if (! ASCII_BYTE_P (c
))
253 c
= BYTE8_TO_CHAR (c
);
257 XMARKER (readcharfun
)->bytepos
= bytepos
;
258 XMARKER (readcharfun
)->charpos
++;
263 if (EQ (readcharfun
, Qlambda
))
265 readbyte
= readbyte_for_lambda
;
269 if (EQ (readcharfun
, Qget_file_char
))
271 readbyte
= readbyte_from_file
;
275 if (STRINGP (readcharfun
))
277 if (read_from_string_index
>= read_from_string_limit
)
279 else if (STRING_MULTIBYTE (readcharfun
))
283 FETCH_STRING_CHAR_ADVANCE_NO_CHECK (c
, readcharfun
,
284 read_from_string_index
,
285 read_from_string_index_byte
);
289 c
= SREF (readcharfun
, read_from_string_index_byte
);
290 read_from_string_index
++;
291 read_from_string_index_byte
++;
296 if (CONSP (readcharfun
))
298 /* This is the case that read_vector is reading from a unibyte
299 string that contains a byte sequence previously skipped
300 because of #@NUMBER. The car part of readcharfun is that
301 string, and the cdr part is a value of readcharfun given to
303 readbyte
= readbyte_from_string
;
304 if (EQ (XCDR (readcharfun
), Qget_emacs_mule_file_char
))
305 emacs_mule_encoding
= 1;
309 if (EQ (readcharfun
, Qget_emacs_mule_file_char
))
311 readbyte
= readbyte_from_file
;
312 emacs_mule_encoding
= 1;
316 tem
= call0 (readcharfun
);
323 if (unread_char
>= 0)
329 c
= (*readbyte
) (-1, readcharfun
);
330 if (c
< 0 || load_each_byte
)
334 if (ASCII_BYTE_P (c
))
336 if (emacs_mule_encoding
)
337 return read_emacs_mule_char (c
, readbyte
, readcharfun
);
340 len
= BYTES_BY_CHAR_HEAD (c
);
343 c
= (*readbyte
) (-1, readcharfun
);
344 if (c
< 0 || ! TRAILING_CODE_P (c
))
347 (*readbyte
) (buf
[i
], readcharfun
);
348 return BYTE8_TO_CHAR (buf
[0]);
352 return STRING_CHAR (buf
);
355 /* Unread the character C in the way appropriate for the stream READCHARFUN.
356 If the stream is a user function, call it with the char as argument. */
359 unreadchar (Lisp_Object readcharfun
, int c
)
363 /* Don't back up the pointer if we're unreading the end-of-input mark,
364 since readchar didn't advance it when we read it. */
366 else if (BUFFERP (readcharfun
))
368 struct buffer
*b
= XBUFFER (readcharfun
);
369 ptrdiff_t charpos
= BUF_PT (b
);
370 ptrdiff_t bytepos
= BUF_PT_BYTE (b
);
372 if (! NILP (BVAR (b
, enable_multibyte_characters
)))
373 BUF_DEC_POS (b
, bytepos
);
377 SET_BUF_PT_BOTH (b
, charpos
- 1, bytepos
);
379 else if (MARKERP (readcharfun
))
381 struct buffer
*b
= XMARKER (readcharfun
)->buffer
;
382 ptrdiff_t bytepos
= XMARKER (readcharfun
)->bytepos
;
384 XMARKER (readcharfun
)->charpos
--;
385 if (! NILP (BVAR (b
, enable_multibyte_characters
)))
386 BUF_DEC_POS (b
, bytepos
);
390 XMARKER (readcharfun
)->bytepos
= bytepos
;
392 else if (STRINGP (readcharfun
))
394 read_from_string_index
--;
395 read_from_string_index_byte
396 = string_char_to_byte (readcharfun
, read_from_string_index
);
398 else if (CONSP (readcharfun
))
402 else if (EQ (readcharfun
, Qlambda
))
406 else if (EQ (readcharfun
, Qget_file_char
)
407 || EQ (readcharfun
, Qget_emacs_mule_file_char
))
412 ungetc (c
, instream
);
419 call1 (readcharfun
, make_number (c
));
423 readbyte_for_lambda (int c
, Lisp_Object readcharfun
)
425 return read_bytecode_char (c
>= 0);
430 readbyte_from_file (int c
, Lisp_Object readcharfun
)
435 ungetc (c
, instream
);
444 /* Interrupted reads have been observed while reading over the network. */
445 while (c
== EOF
&& ferror (instream
) && errno
== EINTR
)
457 return (c
== EOF
? -1 : c
);
461 readbyte_from_string (int c
, Lisp_Object readcharfun
)
463 Lisp_Object string
= XCAR (readcharfun
);
467 read_from_string_index
--;
468 read_from_string_index_byte
469 = string_char_to_byte (string
, read_from_string_index
);
472 if (read_from_string_index
>= read_from_string_limit
)
475 FETCH_STRING_CHAR_ADVANCE (c
, string
,
476 read_from_string_index
,
477 read_from_string_index_byte
);
482 /* Read one non-ASCII character from INSTREAM. The character is
483 encoded in `emacs-mule' and the first byte is already read in
487 read_emacs_mule_char (int c
, int (*readbyte
) (int, Lisp_Object
), Lisp_Object readcharfun
)
489 /* Emacs-mule coding uses at most 4-byte for one character. */
490 unsigned char buf
[4];
491 int len
= emacs_mule_bytes
[c
];
492 struct charset
*charset
;
497 /* C is not a valid leading-code of `emacs-mule'. */
498 return BYTE8_TO_CHAR (c
);
504 c
= (*readbyte
) (-1, readcharfun
);
508 (*readbyte
) (buf
[i
], readcharfun
);
509 return BYTE8_TO_CHAR (buf
[0]);
516 charset
= CHARSET_FROM_ID (emacs_mule_charset
[buf
[0]]);
517 code
= buf
[1] & 0x7F;
521 if (buf
[0] == EMACS_MULE_LEADING_CODE_PRIVATE_11
522 || buf
[0] == EMACS_MULE_LEADING_CODE_PRIVATE_12
)
524 charset
= CHARSET_FROM_ID (emacs_mule_charset
[buf
[1]]);
525 code
= buf
[2] & 0x7F;
529 charset
= CHARSET_FROM_ID (emacs_mule_charset
[buf
[0]]);
530 code
= ((buf
[1] << 8) | buf
[2]) & 0x7F7F;
535 charset
= CHARSET_FROM_ID (emacs_mule_charset
[buf
[1]]);
536 code
= ((buf
[2] << 8) | buf
[3]) & 0x7F7F;
538 c
= DECODE_CHAR (charset
, code
);
540 Fsignal (Qinvalid_read_syntax
,
541 Fcons (build_string ("invalid multibyte form"), Qnil
));
546 static Lisp_Object
read_internal_start (Lisp_Object
, Lisp_Object
,
548 static Lisp_Object
read0 (Lisp_Object
);
549 static Lisp_Object
read1 (Lisp_Object
, int *, int);
551 static Lisp_Object
read_list (int, Lisp_Object
);
552 static Lisp_Object
read_vector (Lisp_Object
, int);
554 static Lisp_Object
substitute_object_recurse (Lisp_Object
, Lisp_Object
,
556 static void substitute_object_in_subtree (Lisp_Object
,
558 static void substitute_in_interval (INTERVAL
, Lisp_Object
);
561 /* Get a character from the tty. */
563 /* Read input events until we get one that's acceptable for our purposes.
565 If NO_SWITCH_FRAME is non-zero, switch-frame events are stashed
566 until we get a character we like, and then stuffed into
569 If ASCII_REQUIRED is non-zero, we check function key events to see
570 if the unmodified version of the symbol has a Qascii_character
571 property, and use that character, if present.
573 If ERROR_NONASCII is non-zero, we signal an error if the input we
574 get isn't an ASCII character with modifiers. If it's zero but
575 ASCII_REQUIRED is non-zero, we just re-read until we get an ASCII
578 If INPUT_METHOD is nonzero, we invoke the current input method
579 if the character warrants that.
581 If SECONDS is a number, we wait that many seconds for input, and
582 return Qnil if no input arrives within that time. */
585 read_filtered_event (int no_switch_frame
, int ascii_required
,
586 int error_nonascii
, int input_method
, Lisp_Object seconds
)
588 Lisp_Object val
, delayed_switch_frame
;
591 #ifdef HAVE_WINDOW_SYSTEM
592 if (display_hourglass_p
)
596 delayed_switch_frame
= Qnil
;
598 /* Compute timeout. */
599 if (NUMBERP (seconds
))
601 double duration
= extract_float (seconds
);
602 EMACS_TIME wait_time
= EMACS_TIME_FROM_DOUBLE (duration
);
603 end_time
= add_emacs_time (current_emacs_time (), wait_time
);
606 /* Read until we get an acceptable event. */
609 val
= read_char (0, 0, 0, (input_method
? Qnil
: Qt
), 0,
610 NUMBERP (seconds
) ? &end_time
: NULL
);
611 while (INTEGERP (val
) && XINT (val
) == -2); /* wrong_kboard_jmpbuf */
616 /* switch-frame events are put off until after the next ASCII
617 character. This is better than signaling an error just because
618 the last characters were typed to a separate minibuffer frame,
619 for example. Eventually, some code which can deal with
620 switch-frame events will read it and process it. */
622 && EVENT_HAS_PARAMETERS (val
)
623 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (val
)), Qswitch_frame
))
625 delayed_switch_frame
= val
;
629 if (ascii_required
&& !(NUMBERP (seconds
) && NILP (val
)))
631 /* Convert certain symbols to their ASCII equivalents. */
634 Lisp_Object tem
, tem1
;
635 tem
= Fget (val
, Qevent_symbol_element_mask
);
638 tem1
= Fget (Fcar (tem
), Qascii_character
);
639 /* Merge this symbol's modifier bits
640 with the ASCII equivalent of its basic code. */
642 XSETFASTINT (val
, XINT (tem1
) | XINT (Fcar (Fcdr (tem
))));
646 /* If we don't have a character now, deal with it appropriately. */
651 Vunread_command_events
= Fcons (val
, Qnil
);
652 error ("Non-character input-event");
659 if (! NILP (delayed_switch_frame
))
660 unread_switch_frame
= delayed_switch_frame
;
664 #ifdef HAVE_WINDOW_SYSTEM
665 if (display_hourglass_p
)
674 DEFUN ("read-char", Fread_char
, Sread_char
, 0, 3, 0,
675 doc
: /* Read a character from the command input (keyboard or macro).
676 It is returned as a number.
677 If the character has modifiers, they are resolved and reflected to the
678 character code if possible (e.g. C-SPC -> 0).
680 If the user generates an event which is not a character (i.e. a mouse
681 click or function key event), `read-char' signals an error. As an
682 exception, switch-frame events are put off until non-character events
684 If you want to read non-character events, or ignore them, call
685 `read-event' or `read-char-exclusive' instead.
687 If the optional argument PROMPT is non-nil, display that as a prompt.
688 If the optional argument INHERIT-INPUT-METHOD is non-nil and some
689 input method is turned on in the current buffer, that input method
690 is used for reading a character.
691 If the optional argument SECONDS is non-nil, it should be a number
692 specifying the maximum number of seconds to wait for input. If no
693 input arrives in that time, return nil. SECONDS may be a
694 floating-point value. */)
695 (Lisp_Object prompt
, Lisp_Object inherit_input_method
, Lisp_Object seconds
)
700 message_with_string ("%s", prompt
, 0);
701 val
= read_filtered_event (1, 1, 1, ! NILP (inherit_input_method
), seconds
);
703 return (NILP (val
) ? Qnil
704 : make_number (char_resolve_modifier_mask (XINT (val
))));
707 DEFUN ("read-event", Fread_event
, Sread_event
, 0, 3, 0,
708 doc
: /* Read an event object from the input stream.
709 If the optional argument PROMPT is non-nil, display that as a prompt.
710 If the optional argument INHERIT-INPUT-METHOD is non-nil and some
711 input method is turned on in the current buffer, that input method
712 is used for reading a character.
713 If the optional argument SECONDS is non-nil, it should be a number
714 specifying the maximum number of seconds to wait for input. If no
715 input arrives in that time, return nil. SECONDS may be a
716 floating-point value. */)
717 (Lisp_Object prompt
, Lisp_Object inherit_input_method
, Lisp_Object seconds
)
720 message_with_string ("%s", prompt
, 0);
721 return read_filtered_event (0, 0, 0, ! NILP (inherit_input_method
), seconds
);
724 DEFUN ("read-char-exclusive", Fread_char_exclusive
, Sread_char_exclusive
, 0, 3, 0,
725 doc
: /* Read a character from the command input (keyboard or macro).
726 It is returned as a number. Non-character events are ignored.
727 If the character has modifiers, they are resolved and reflected to the
728 character code if possible (e.g. C-SPC -> 0).
730 If the optional argument PROMPT is non-nil, display that as a prompt.
731 If the optional argument INHERIT-INPUT-METHOD is non-nil and some
732 input method is turned on in the current buffer, that input method
733 is used for reading a character.
734 If the optional argument SECONDS is non-nil, it should be a number
735 specifying the maximum number of seconds to wait for input. If no
736 input arrives in that time, return nil. SECONDS may be a
737 floating-point value. */)
738 (Lisp_Object prompt
, Lisp_Object inherit_input_method
, Lisp_Object seconds
)
743 message_with_string ("%s", prompt
, 0);
745 val
= read_filtered_event (1, 1, 0, ! NILP (inherit_input_method
), seconds
);
747 return (NILP (val
) ? Qnil
748 : make_number (char_resolve_modifier_mask (XINT (val
))));
751 DEFUN ("get-file-char", Fget_file_char
, Sget_file_char
, 0, 0, 0,
752 doc
: /* Don't use this yourself. */)
755 register Lisp_Object val
;
757 XSETINT (val
, getc (instream
));
765 /* Return true if the lisp code read using READCHARFUN defines a non-nil
766 `lexical-binding' file variable. After returning, the stream is
767 positioned following the first line, if it is a comment, otherwise
771 lisp_file_lexically_bound_p (Lisp_Object readcharfun
)
775 /* The first line isn't a comment, just give up. */
781 /* Look for an appropriate file-variable in the first line. */
785 NOMINAL
, AFTER_FIRST_DASH
, AFTER_ASTERIX
,
786 } beg_end_state
= NOMINAL
;
787 int in_file_vars
= 0;
789 #define UPDATE_BEG_END_STATE(ch) \
790 if (beg_end_state == NOMINAL) \
791 beg_end_state = (ch == '-' ? AFTER_FIRST_DASH : NOMINAL); \
792 else if (beg_end_state == AFTER_FIRST_DASH) \
793 beg_end_state = (ch == '*' ? AFTER_ASTERIX : NOMINAL); \
794 else if (beg_end_state == AFTER_ASTERIX) \
797 in_file_vars = !in_file_vars; \
798 beg_end_state = NOMINAL; \
801 /* Skip until we get to the file vars, if any. */
805 UPDATE_BEG_END_STATE (ch
);
807 while (!in_file_vars
&& ch
!= '\n' && ch
!= EOF
);
811 char var
[100], val
[100];
816 /* Read a variable name. */
817 while (ch
== ' ' || ch
== '\t')
821 while (ch
!= ':' && ch
!= '\n' && ch
!= EOF
&& in_file_vars
)
823 if (i
< sizeof var
- 1)
825 UPDATE_BEG_END_STATE (ch
);
829 /* Stop scanning if no colon was found before end marker. */
830 if (!in_file_vars
|| ch
== '\n' || ch
== EOF
)
833 while (i
> 0 && (var
[i
- 1] == ' ' || var
[i
- 1] == '\t'))
839 /* Read a variable value. */
842 while (ch
== ' ' || ch
== '\t')
846 while (ch
!= ';' && ch
!= '\n' && ch
!= EOF
&& in_file_vars
)
848 if (i
< sizeof val
- 1)
850 UPDATE_BEG_END_STATE (ch
);
854 /* The value was terminated by an end-marker, which remove. */
856 while (i
> 0 && (val
[i
- 1] == ' ' || val
[i
- 1] == '\t'))
860 if (strcmp (var
, "lexical-binding") == 0)
863 rv
= (strcmp (val
, "nil") != 0);
869 while (ch
!= '\n' && ch
!= EOF
)
876 /* Value is a version number of byte compiled code if the file
877 associated with file descriptor FD is a compiled Lisp file that's
878 safe to load. Only files compiled with Emacs are safe to load.
879 Files compiled with XEmacs can lead to a crash in Fbyte_code
880 because of an incompatible change in the byte compiler. */
883 safe_to_load_p (int fd
)
890 /* Read the first few bytes from the file, and look for a line
891 specifying the byte compiler version used. */
892 nbytes
= emacs_read (fd
, buf
, sizeof buf
- 1);
897 /* Skip to the next newline, skipping over the initial `ELC'
898 with NUL bytes following it, but note the version. */
899 for (i
= 0; i
< nbytes
&& buf
[i
] != '\n'; ++i
)
904 || fast_c_string_match_ignore_case (Vbytecomp_version_regexp
,
905 buf
+ i
, nbytes
- i
) < 0)
911 lseek (fd
, 0, SEEK_SET
);
916 /* Callback for record_unwind_protect. Restore the old load list OLD,
917 after loading a file successfully. */
920 record_load_unwind (Lisp_Object old
)
922 return Vloads_in_progress
= old
;
925 /* This handler function is used via internal_condition_case_1. */
928 load_error_handler (Lisp_Object data
)
934 load_warn_old_style_backquotes (Lisp_Object file
)
936 if (!NILP (Vold_style_backquotes
))
939 args
[0] = build_string ("Loading `%s': old-style backquotes detected!");
946 DEFUN ("get-load-suffixes", Fget_load_suffixes
, Sget_load_suffixes
, 0, 0, 0,
947 doc
: /* Return the suffixes that `load' should try if a suffix is \
949 This uses the variables `load-suffixes' and `load-file-rep-suffixes'. */)
952 Lisp_Object lst
= Qnil
, suffixes
= Vload_suffixes
, suffix
, ext
;
953 while (CONSP (suffixes
))
955 Lisp_Object exts
= Vload_file_rep_suffixes
;
956 suffix
= XCAR (suffixes
);
957 suffixes
= XCDR (suffixes
);
962 lst
= Fcons (concat2 (suffix
, ext
), lst
);
965 return Fnreverse (lst
);
968 DEFUN ("load", Fload
, Sload
, 1, 5, 0,
969 doc
: /* Execute a file of Lisp code named FILE.
970 First try FILE with `.elc' appended, then try with `.el',
971 then try FILE unmodified (the exact suffixes in the exact order are
972 determined by `load-suffixes'). Environment variable references in
973 FILE are replaced with their values by calling `substitute-in-file-name'.
974 This function searches the directories in `load-path'.
976 If optional second arg NOERROR is non-nil,
977 report no error if FILE doesn't exist.
978 Print messages at start and end of loading unless
979 optional third arg NOMESSAGE is non-nil (but `force-load-messages'
981 If optional fourth arg NOSUFFIX is non-nil, don't try adding
982 suffixes `.elc' or `.el' to the specified name FILE.
983 If optional fifth arg MUST-SUFFIX is non-nil, insist on
984 the suffix `.elc' or `.el'; don't accept just FILE unless
985 it ends in one of those suffixes or includes a directory name.
987 If this function fails to find a file, it may look for different
988 representations of that file before trying another file.
989 It does so by adding the non-empty suffixes in `load-file-rep-suffixes'
990 to the file name. Emacs uses this feature mainly to find compressed
991 versions of files when Auto Compression mode is enabled.
993 The exact suffixes that this function tries out, in the exact order,
994 are given by the value of the variable `load-file-rep-suffixes' if
995 NOSUFFIX is non-nil and by the return value of the function
996 `get-load-suffixes' if MUST-SUFFIX is non-nil. If both NOSUFFIX and
997 MUST-SUFFIX are nil, this function first tries out the latter suffixes
1000 Loading a file records its definitions, and its `provide' and
1001 `require' calls, in an element of `load-history' whose
1002 car is the file name loaded. See `load-history'.
1004 While the file is in the process of being loaded, the variable
1005 `load-in-progress' is non-nil and the variable `load-file-name'
1006 is bound to the file's name.
1008 Return t if the file exists and loads successfully. */)
1009 (Lisp_Object file
, Lisp_Object noerror
, Lisp_Object nomessage
, Lisp_Object nosuffix
, Lisp_Object must_suffix
)
1011 register FILE *stream
;
1012 register int fd
= -1;
1013 ptrdiff_t count
= SPECPDL_INDEX ();
1014 struct gcpro gcpro1
, gcpro2
, gcpro3
;
1015 Lisp_Object found
, efound
, hist_file_name
;
1016 /* 1 means we printed the ".el is newer" message. */
1018 /* 1 means we are loading a compiled file. */
1020 Lisp_Object handler
;
1022 const char *fmode
= "r";
1030 CHECK_STRING (file
);
1032 /* If file name is magic, call the handler. */
1033 /* This shouldn't be necessary any more now that `openp' handles it right.
1034 handler = Ffind_file_name_handler (file, Qload);
1035 if (!NILP (handler))
1036 return call5 (handler, Qload, file, noerror, nomessage, nosuffix); */
1038 /* Do this after the handler to avoid
1039 the need to gcpro noerror, nomessage and nosuffix.
1040 (Below here, we care only whether they are nil or not.)
1041 The presence of this call is the result of a historical accident:
1042 it used to be in every file-operation and when it got removed
1043 everywhere, it accidentally stayed here. Since then, enough people
1044 supposedly have things like (load "$PROJECT/foo.el") in their .emacs
1045 that it seemed risky to remove. */
1046 if (! NILP (noerror
))
1048 file
= internal_condition_case_1 (Fsubstitute_in_file_name
, file
,
1049 Qt
, load_error_handler
);
1054 file
= Fsubstitute_in_file_name (file
);
1057 /* Avoid weird lossage with null string as arg,
1058 since it would try to load a directory as a Lisp file. */
1059 if (SBYTES (file
) > 0)
1061 ptrdiff_t size
= SBYTES (file
);
1064 GCPRO2 (file
, found
);
1066 if (! NILP (must_suffix
))
1068 /* Don't insist on adding a suffix if FILE already ends with one. */
1070 && !strcmp (SSDATA (file
) + size
- 3, ".el"))
1073 && !strcmp (SSDATA (file
) + size
- 4, ".elc"))
1075 /* Don't insist on adding a suffix
1076 if the argument includes a directory name. */
1077 else if (! NILP (Ffile_name_directory (file
)))
1081 fd
= openp (Vload_path
, file
,
1082 (!NILP (nosuffix
) ? Qnil
1083 : !NILP (must_suffix
) ? Fget_load_suffixes ()
1084 : Fappend (2, (tmp
[0] = Fget_load_suffixes (),
1085 tmp
[1] = Vload_file_rep_suffixes
,
1094 xsignal2 (Qfile_error
, build_string ("Cannot open load file"), file
);
1098 /* Tell startup.el whether or not we found the user's init file. */
1099 if (EQ (Qt
, Vuser_init_file
))
1100 Vuser_init_file
= found
;
1102 /* If FD is -2, that means openp found a magic file. */
1105 if (NILP (Fequal (found
, file
)))
1106 /* If FOUND is a different file name from FILE,
1107 find its handler even if we have already inhibited
1108 the `load' operation on FILE. */
1109 handler
= Ffind_file_name_handler (found
, Qt
);
1111 handler
= Ffind_file_name_handler (found
, Qload
);
1112 if (! NILP (handler
))
1113 return call5 (handler
, Qload
, found
, noerror
, nomessage
, Qt
);
1115 /* Tramp has to deal with semi-broken packages that prepend
1116 drive letters to remote files. For that reason, Tramp
1117 catches file operations that test for file existence, which
1118 makes openp think X:/foo.elc files are remote. However,
1119 Tramp does not catch `load' operations for such files, so we
1120 end up with a nil as the `load' handler above. If we would
1121 continue with fd = -2, we will behave wrongly, and in
1122 particular try reading a .elc file in the "rt" mode instead
1123 of "rb". See bug #9311 for the results. To work around
1124 this, we try to open the file locally, and go with that if it
1126 fd
= emacs_open (SSDATA (ENCODE_FILE (found
)), O_RDONLY
, 0);
1132 /* Check if we're stuck in a recursive load cycle.
1134 2000-09-21: It's not possible to just check for the file loaded
1135 being a member of Vloads_in_progress. This fails because of the
1136 way the byte compiler currently works; `provide's are not
1137 evaluated, see font-lock.el/jit-lock.el as an example. This
1138 leads to a certain amount of ``normal'' recursion.
1140 Also, just loading a file recursively is not always an error in
1141 the general case; the second load may do something different. */
1145 for (tem
= Vloads_in_progress
; CONSP (tem
); tem
= XCDR (tem
))
1146 if (!NILP (Fequal (found
, XCAR (tem
))) && (++load_count
> 3))
1150 signal_error ("Recursive load", Fcons (found
, Vloads_in_progress
));
1152 record_unwind_protect (record_load_unwind
, Vloads_in_progress
);
1153 Vloads_in_progress
= Fcons (found
, Vloads_in_progress
);
1156 /* All loads are by default dynamic, unless the file itself specifies
1157 otherwise using a file-variable in the first line. This is bound here
1158 so that it takes effect whether or not we use
1159 Vload_source_file_function. */
1160 specbind (Qlexical_binding
, Qnil
);
1162 /* Get the name for load-history. */
1163 hist_file_name
= (! NILP (Vpurify_flag
)
1164 ? Fconcat (2, (tmp
[0] = Ffile_name_directory (file
),
1165 tmp
[1] = Ffile_name_nondirectory (found
),
1171 /* Check for the presence of old-style quotes and warn about them. */
1172 specbind (Qold_style_backquotes
, Qnil
);
1173 record_unwind_protect (load_warn_old_style_backquotes
, file
);
1175 if (!memcmp (SDATA (found
) + SBYTES (found
) - 4, ".elc", 4)
1176 || (fd
>= 0 && (version
= safe_to_load_p (fd
)) > 0))
1177 /* Load .elc files directly, but not when they are
1178 remote and have no handler! */
1185 GCPRO3 (file
, found
, hist_file_name
);
1188 && ! (version
= safe_to_load_p (fd
)))
1191 if (!load_dangerous_libraries
)
1195 error ("File `%s' was not compiled in Emacs",
1198 else if (!NILP (nomessage
) && !force_load_messages
)
1199 message_with_string ("File `%s' not compiled in Emacs", found
, 1);
1204 efound
= ENCODE_FILE (found
);
1209 result
= stat (SSDATA (efound
), &s1
);
1212 SSET (efound
, SBYTES (efound
) - 1, 0);
1213 result
= stat (SSDATA (efound
), &s2
);
1214 SSET (efound
, SBYTES (efound
) - 1, 'c');
1218 && EMACS_TIME_LT (get_stat_mtime (&s1
), get_stat_mtime (&s2
)))
1220 /* Make the progress messages mention that source is newer. */
1223 /* If we won't print another message, mention this anyway. */
1224 if (!NILP (nomessage
) && !force_load_messages
)
1226 Lisp_Object msg_file
;
1227 msg_file
= Fsubstring (found
, make_number (0), make_number (-1));
1228 message_with_string ("Source file `%s' newer than byte-compiled file",
1237 /* We are loading a source file (*.el). */
1238 if (!NILP (Vload_source_file_function
))
1244 val
= call4 (Vload_source_file_function
, found
, hist_file_name
,
1245 NILP (noerror
) ? Qnil
: Qt
,
1246 (NILP (nomessage
) || force_load_messages
) ? Qnil
: Qt
);
1247 return unbind_to (count
, val
);
1251 GCPRO3 (file
, found
, hist_file_name
);
1254 efound
= ENCODE_FILE (found
);
1255 /* If we somehow got here with fd == -2, meaning the file is deemed
1256 to be remote, don't even try to reopen the file locally; just
1257 force a failure instead. */
1261 stream
= fopen (SSDATA (efound
), fmode
);
1265 #else /* not WINDOWSNT */
1266 stream
= fdopen (fd
, fmode
);
1267 #endif /* not WINDOWSNT */
1271 error ("Failure to create stdio stream for %s", SDATA (file
));
1274 if (! NILP (Vpurify_flag
))
1275 Vpreloaded_file_list
= Fcons (Fpurecopy (file
), Vpreloaded_file_list
);
1277 if (NILP (nomessage
) || force_load_messages
)
1280 message_with_string ("Loading %s (compiled; note unsafe, not compiled in Emacs)...",
1283 message_with_string ("Loading %s (source)...", file
, 1);
1285 message_with_string ("Loading %s (compiled; note, source file is newer)...",
1287 else /* The typical case; compiled file newer than source file. */
1288 message_with_string ("Loading %s...", file
, 1);
1291 record_unwind_protect (load_unwind
, make_save_value (stream
, 0));
1292 record_unwind_protect (load_descriptor_unwind
, load_descriptor_list
);
1293 specbind (Qload_file_name
, found
);
1294 specbind (Qinhibit_file_name_operation
, Qnil
);
1295 load_descriptor_list
1296 = Fcons (make_number (fileno (stream
)), load_descriptor_list
);
1297 specbind (Qload_in_progress
, Qt
);
1300 if (lisp_file_lexically_bound_p (Qget_file_char
))
1301 Fset (Qlexical_binding
, Qt
);
1303 if (! version
|| version
>= 22)
1304 readevalloop (Qget_file_char
, stream
, hist_file_name
,
1305 0, Qnil
, Qnil
, Qnil
, Qnil
);
1308 /* We can't handle a file which was compiled with
1309 byte-compile-dynamic by older version of Emacs. */
1310 specbind (Qload_force_doc_strings
, Qt
);
1311 readevalloop (Qget_emacs_mule_file_char
, stream
, hist_file_name
,
1312 0, Qnil
, Qnil
, Qnil
, Qnil
);
1314 unbind_to (count
, Qnil
);
1316 /* Run any eval-after-load forms for this file. */
1317 if (!NILP (Ffboundp (Qdo_after_load_evaluation
)))
1318 call1 (Qdo_after_load_evaluation
, hist_file_name
) ;
1322 xfree (saved_doc_string
);
1323 saved_doc_string
= 0;
1324 saved_doc_string_size
= 0;
1326 xfree (prev_saved_doc_string
);
1327 prev_saved_doc_string
= 0;
1328 prev_saved_doc_string_size
= 0;
1330 if (!noninteractive
&& (NILP (nomessage
) || force_load_messages
))
1333 message_with_string ("Loading %s (compiled; note unsafe, not compiled in Emacs)...done",
1336 message_with_string ("Loading %s (source)...done", file
, 1);
1338 message_with_string ("Loading %s (compiled; note, source file is newer)...done",
1340 else /* The typical case; compiled file newer than source file. */
1341 message_with_string ("Loading %s...done", file
, 1);
1348 load_unwind (Lisp_Object arg
) /* Used as unwind-protect function in load. */
1350 FILE *stream
= (FILE *) XSAVE_VALUE (arg
)->pointer
;
1361 load_descriptor_unwind (Lisp_Object oldlist
)
1363 load_descriptor_list
= oldlist
;
1367 /* Close all descriptors in use for Floads.
1368 This is used when starting a subprocess. */
1371 close_load_descs (void)
1375 for (tail
= load_descriptor_list
; CONSP (tail
); tail
= XCDR (tail
))
1376 emacs_close (XFASTINT (XCAR (tail
)));
1381 complete_filename_p (Lisp_Object pathname
)
1383 register const unsigned char *s
= SDATA (pathname
);
1384 return (IS_DIRECTORY_SEP (s
[0])
1385 || (SCHARS (pathname
) > 2
1386 && IS_DEVICE_SEP (s
[1]) && IS_DIRECTORY_SEP (s
[2])));
1389 DEFUN ("locate-file-internal", Flocate_file_internal
, Slocate_file_internal
, 2, 4, 0,
1390 doc
: /* Search for FILENAME through PATH.
1391 Returns the file's name in absolute form, or nil if not found.
1392 If SUFFIXES is non-nil, it should be a list of suffixes to append to
1393 file name when searching.
1394 If non-nil, PREDICATE is used instead of `file-readable-p'.
1395 PREDICATE can also be an integer to pass to the access(2) function,
1396 in which case file-name-handlers are ignored.
1397 This function will normally skip directories, so if you want it to find
1398 directories, make sure the PREDICATE function returns `dir-ok' for them. */)
1399 (Lisp_Object filename
, Lisp_Object path
, Lisp_Object suffixes
, Lisp_Object predicate
)
1402 int fd
= openp (path
, filename
, suffixes
, &file
, predicate
);
1403 if (NILP (predicate
) && fd
> 0)
1408 static Lisp_Object Qdir_ok
;
1410 /* Search for a file whose name is STR, looking in directories
1411 in the Lisp list PATH, and trying suffixes from SUFFIX.
1412 On success, returns a file descriptor. On failure, returns -1.
1414 SUFFIXES is a list of strings containing possible suffixes.
1415 The empty suffix is automatically added if the list is empty.
1417 PREDICATE non-nil means don't open the files,
1418 just look for one that satisfies the predicate. In this case,
1419 returns 1 on success. The predicate can be a lisp function or
1420 an integer to pass to `access' (in which case file-name-handlers
1423 If STOREPTR is nonzero, it points to a slot where the name of
1424 the file actually found should be stored as a Lisp string.
1425 nil is stored there on failure.
1427 If the file we find is remote, return -2
1428 but store the found remote file name in *STOREPTR. */
1431 openp (Lisp_Object path
, Lisp_Object str
, Lisp_Object suffixes
, Lisp_Object
*storeptr
, Lisp_Object predicate
)
1434 ptrdiff_t fn_size
= 100;
1436 register char *fn
= buf
;
1438 ptrdiff_t want_length
;
1439 Lisp_Object filename
;
1441 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
, gcpro5
, gcpro6
;
1442 Lisp_Object string
, tail
, encoded_fn
;
1443 ptrdiff_t max_suffix_len
= 0;
1447 for (tail
= suffixes
; CONSP (tail
); tail
= XCDR (tail
))
1449 CHECK_STRING_CAR (tail
);
1450 max_suffix_len
= max (max_suffix_len
,
1451 SBYTES (XCAR (tail
)));
1454 string
= filename
= encoded_fn
= Qnil
;
1455 GCPRO6 (str
, string
, filename
, path
, suffixes
, encoded_fn
);
1460 if (complete_filename_p (str
))
1463 for (; CONSP (path
); path
= XCDR (path
))
1465 filename
= Fexpand_file_name (str
, XCAR (path
));
1466 if (!complete_filename_p (filename
))
1467 /* If there are non-absolute elts in PATH (eg "."). */
1468 /* Of course, this could conceivably lose if luser sets
1469 default-directory to be something non-absolute... */
1471 filename
= Fexpand_file_name (filename
, BVAR (current_buffer
, directory
));
1472 if (!complete_filename_p (filename
))
1473 /* Give up on this path element! */
1477 /* Calculate maximum length of any filename made from
1478 this path element/specified file name and any possible suffix. */
1479 want_length
= max_suffix_len
+ SBYTES (filename
);
1480 if (fn_size
<= want_length
)
1481 fn
= alloca (fn_size
= 100 + want_length
);
1483 /* Loop over suffixes. */
1484 for (tail
= NILP (suffixes
) ? Fcons (empty_unibyte_string
, Qnil
) : suffixes
;
1485 CONSP (tail
); tail
= XCDR (tail
))
1487 ptrdiff_t fnlen
, lsuffix
= SBYTES (XCAR (tail
));
1488 Lisp_Object handler
;
1491 /* Concatenate path element/specified name with the suffix.
1492 If the directory starts with /:, remove that. */
1493 int prefixlen
= ((SCHARS (filename
) > 2
1494 && SREF (filename
, 0) == '/'
1495 && SREF (filename
, 1) == ':')
1497 fnlen
= SBYTES (filename
) - prefixlen
;
1498 memcpy (fn
, SDATA (filename
) + prefixlen
, fnlen
);
1499 memcpy (fn
+ fnlen
, SDATA (XCAR (tail
)), lsuffix
+ 1);
1501 /* Check that the file exists and is not a directory. */
1502 /* We used to only check for handlers on non-absolute file names:
1506 handler = Ffind_file_name_handler (filename, Qfile_exists_p);
1507 It's not clear why that was the case and it breaks things like
1508 (load "/bar.el") where the file is actually "/bar.el.gz". */
1509 string
= make_string (fn
, fnlen
);
1510 handler
= Ffind_file_name_handler (string
, Qfile_exists_p
);
1511 if ((!NILP (handler
) || !NILP (predicate
)) && !NATNUMP (predicate
))
1513 if (NILP (predicate
))
1514 exists
= !NILP (Ffile_readable_p (string
));
1517 Lisp_Object tmp
= call1 (predicate
, string
);
1518 exists
= !NILP (tmp
)
1519 && (EQ (tmp
, Qdir_ok
)
1520 || NILP (Ffile_directory_p (string
)));
1525 /* We succeeded; return this descriptor and filename. */
1536 encoded_fn
= ENCODE_FILE (string
);
1537 pfn
= SSDATA (encoded_fn
);
1538 exists
= (stat (pfn
, &st
) == 0 && ! S_ISDIR (st
.st_mode
));
1541 /* Check that we can access or open it. */
1542 if (NATNUMP (predicate
))
1543 fd
= (((XFASTINT (predicate
) & ~INT_MAX
) == 0
1544 && access (pfn
, XFASTINT (predicate
)) == 0)
1547 fd
= emacs_open (pfn
, O_RDONLY
, 0);
1551 /* We succeeded; return this descriptor and filename. */
1569 /* Merge the list we've accumulated of globals from the current input source
1570 into the load_history variable. The details depend on whether
1571 the source has an associated file name or not.
1573 FILENAME is the file name that we are loading from.
1574 ENTIRE is 1 if loading that entire file, 0 if evaluating part of it. */
1577 build_load_history (Lisp_Object filename
, int entire
)
1579 register Lisp_Object tail
, prev
, newelt
;
1580 register Lisp_Object tem
, tem2
;
1581 register int foundit
= 0;
1583 tail
= Vload_history
;
1586 while (CONSP (tail
))
1590 /* Find the feature's previous assoc list... */
1591 if (!NILP (Fequal (filename
, Fcar (tem
))))
1595 /* If we're loading the entire file, remove old data. */
1599 Vload_history
= XCDR (tail
);
1601 Fsetcdr (prev
, XCDR (tail
));
1604 /* Otherwise, cons on new symbols that are not already members. */
1607 tem2
= Vcurrent_load_list
;
1609 while (CONSP (tem2
))
1611 newelt
= XCAR (tem2
);
1613 if (NILP (Fmember (newelt
, tem
)))
1614 Fsetcar (tail
, Fcons (XCAR (tem
),
1615 Fcons (newelt
, XCDR (tem
))));
1628 /* If we're loading an entire file, cons the new assoc onto the
1629 front of load-history, the most-recently-loaded position. Also
1630 do this if we didn't find an existing member for the file. */
1631 if (entire
|| !foundit
)
1632 Vload_history
= Fcons (Fnreverse (Vcurrent_load_list
),
1637 readevalloop_1 (Lisp_Object old
)
1639 load_convert_to_unibyte
= ! NILP (old
);
1643 /* Signal an `end-of-file' error, if possible with file name
1646 static _Noreturn
void
1647 end_of_file_error (void)
1649 if (STRINGP (Vload_file_name
))
1650 xsignal1 (Qend_of_file
, Vload_file_name
);
1652 xsignal0 (Qend_of_file
);
1655 /* UNIBYTE specifies how to set load_convert_to_unibyte
1656 for this invocation.
1657 READFUN, if non-nil, is used instead of `read'.
1659 START, END specify region to read in current buffer (from eval-region).
1660 If the input is not from a buffer, they must be nil. */
1663 readevalloop (Lisp_Object readcharfun
,
1665 Lisp_Object sourcename
,
1667 Lisp_Object unibyte
, Lisp_Object readfun
,
1668 Lisp_Object start
, Lisp_Object end
)
1671 register Lisp_Object val
;
1672 ptrdiff_t count
= SPECPDL_INDEX ();
1673 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
1674 struct buffer
*b
= 0;
1675 int continue_reading_p
;
1676 Lisp_Object lex_bound
;
1677 /* Nonzero if reading an entire buffer. */
1678 int whole_buffer
= 0;
1679 /* 1 on the first time around. */
1681 Lisp_Object macroexpand
= intern ("internal-macroexpand-for-load");
1683 if (NILP (Ffboundp (macroexpand
))
1684 /* Don't macroexpand in .elc files, since it should have been done
1685 already. We actually don't know whether we're in a .elc file or not,
1686 so we use circumstancial evidence: .el files normally go through
1687 Vload_source_file_function -> load-with-code-conversion
1689 || EQ (readcharfun
, Qget_file_char
)
1690 || EQ (readcharfun
, Qget_emacs_mule_file_char
))
1693 if (MARKERP (readcharfun
))
1696 start
= readcharfun
;
1699 if (BUFFERP (readcharfun
))
1700 b
= XBUFFER (readcharfun
);
1701 else if (MARKERP (readcharfun
))
1702 b
= XMARKER (readcharfun
)->buffer
;
1704 /* We assume START is nil when input is not from a buffer. */
1705 if (! NILP (start
) && !b
)
1708 specbind (Qstandard_input
, readcharfun
); /* GCPROs readcharfun. */
1709 specbind (Qcurrent_load_list
, Qnil
);
1710 record_unwind_protect (readevalloop_1
, load_convert_to_unibyte
? Qt
: Qnil
);
1711 load_convert_to_unibyte
= !NILP (unibyte
);
1713 /* If lexical binding is active (either because it was specified in
1714 the file's header, or via a buffer-local variable), create an empty
1715 lexical environment, otherwise, turn off lexical binding. */
1716 lex_bound
= find_symbol_value (Qlexical_binding
);
1717 specbind (Qinternal_interpreter_environment
,
1718 NILP (lex_bound
) || EQ (lex_bound
, Qunbound
)
1719 ? Qnil
: Fcons (Qt
, Qnil
));
1721 GCPRO4 (sourcename
, readfun
, start
, end
);
1723 /* Try to ensure sourcename is a truename, except whilst preloading. */
1724 if (NILP (Vpurify_flag
)
1725 && !NILP (sourcename
) && !NILP (Ffile_name_absolute_p (sourcename
))
1726 && !NILP (Ffboundp (Qfile_truename
)))
1727 sourcename
= call1 (Qfile_truename
, sourcename
) ;
1729 LOADHIST_ATTACH (sourcename
);
1731 continue_reading_p
= 1;
1732 while (continue_reading_p
)
1734 ptrdiff_t count1
= SPECPDL_INDEX ();
1736 if (b
!= 0 && !BUFFER_LIVE_P (b
))
1737 error ("Reading from killed buffer");
1741 /* Switch to the buffer we are reading from. */
1742 record_unwind_protect (save_excursion_restore
, save_excursion_save ());
1743 set_buffer_internal (b
);
1745 /* Save point in it. */
1746 record_unwind_protect (save_excursion_restore
, save_excursion_save ());
1747 /* Save ZV in it. */
1748 record_unwind_protect (save_restriction_restore
, save_restriction_save ());
1749 /* Those get unbound after we read one expression. */
1751 /* Set point and ZV around stuff to be read. */
1754 Fnarrow_to_region (make_number (BEGV
), end
);
1756 /* Just for cleanliness, convert END to a marker
1757 if it is an integer. */
1759 end
= Fpoint_max_marker ();
1762 /* On the first cycle, we can easily test here
1763 whether we are reading the whole buffer. */
1764 if (b
&& first_sexp
)
1765 whole_buffer
= (PT
== BEG
&& ZV
== Z
);
1772 while ((c
= READCHAR
) != '\n' && c
!= -1);
1777 unbind_to (count1
, Qnil
);
1781 /* Ignore whitespace here, so we can detect eof. */
1782 if (c
== ' ' || c
== '\t' || c
== '\n' || c
== '\f' || c
== '\r'
1783 || c
== 0xa0) /* NBSP */
1786 if (!NILP (Vpurify_flag
) && c
== '(')
1788 val
= read_list (0, readcharfun
);
1793 read_objects
= Qnil
;
1794 if (!NILP (readfun
))
1796 val
= call1 (readfun
, readcharfun
);
1798 /* If READCHARFUN has set point to ZV, we should
1799 stop reading, even if the form read sets point
1800 to a different value when evaluated. */
1801 if (BUFFERP (readcharfun
))
1803 struct buffer
*buf
= XBUFFER (readcharfun
);
1804 if (BUF_PT (buf
) == BUF_ZV (buf
))
1805 continue_reading_p
= 0;
1808 else if (! NILP (Vload_read_function
))
1809 val
= call1 (Vload_read_function
, readcharfun
);
1811 val
= read_internal_start (readcharfun
, Qnil
, Qnil
);
1814 if (!NILP (start
) && continue_reading_p
)
1815 start
= Fpoint_marker ();
1817 /* Restore saved point and BEGV. */
1818 unbind_to (count1
, Qnil
);
1820 /* Now eval what we just read. */
1821 if (!NILP (macroexpand
))
1822 val
= call1 (macroexpand
, val
);
1823 val
= eval_sub (val
);
1827 Vvalues
= Fcons (val
, Vvalues
);
1828 if (EQ (Vstandard_output
, Qt
))
1837 build_load_history (sourcename
,
1838 stream
|| whole_buffer
);
1842 unbind_to (count
, Qnil
);
1845 DEFUN ("eval-buffer", Feval_buffer
, Seval_buffer
, 0, 5, "",
1846 doc
: /* Execute the current buffer as Lisp code.
1847 When called from a Lisp program (i.e., not interactively), this
1848 function accepts up to five optional arguments:
1849 BUFFER is the buffer to evaluate (nil means use current buffer).
1850 PRINTFLAG controls printing of output:
1851 A value of nil means discard it; anything else is stream for print.
1852 FILENAME specifies the file name to use for `load-history'.
1853 UNIBYTE, if non-nil, specifies `load-convert-to-unibyte' for this
1855 DO-ALLOW-PRINT, if non-nil, specifies that `print' and related
1856 functions should work normally even if PRINTFLAG is nil.
1858 This function preserves the position of point. */)
1859 (Lisp_Object buffer
, Lisp_Object printflag
, Lisp_Object filename
, Lisp_Object unibyte
, Lisp_Object do_allow_print
)
1861 ptrdiff_t count
= SPECPDL_INDEX ();
1862 Lisp_Object tem
, buf
;
1865 buf
= Fcurrent_buffer ();
1867 buf
= Fget_buffer (buffer
);
1869 error ("No such buffer");
1871 if (NILP (printflag
) && NILP (do_allow_print
))
1876 if (NILP (filename
))
1877 filename
= BVAR (XBUFFER (buf
), filename
);
1879 specbind (Qeval_buffer_list
, Fcons (buf
, Veval_buffer_list
));
1880 specbind (Qstandard_output
, tem
);
1881 record_unwind_protect (save_excursion_restore
, save_excursion_save ());
1882 BUF_TEMP_SET_PT (XBUFFER (buf
), BUF_BEGV (XBUFFER (buf
)));
1883 specbind (Qlexical_binding
, lisp_file_lexically_bound_p (buf
) ? Qt
: Qnil
);
1884 readevalloop (buf
, 0, filename
,
1885 !NILP (printflag
), unibyte
, Qnil
, Qnil
, Qnil
);
1886 unbind_to (count
, Qnil
);
1891 DEFUN ("eval-region", Feval_region
, Seval_region
, 2, 4, "r",
1892 doc
: /* Execute the region as Lisp code.
1893 When called from programs, expects two arguments,
1894 giving starting and ending indices in the current buffer
1895 of the text to be executed.
1896 Programs can pass third argument PRINTFLAG which controls output:
1897 A value of nil means discard it; anything else is stream for printing it.
1898 Also the fourth argument READ-FUNCTION, if non-nil, is used
1899 instead of `read' to read each expression. It gets one argument
1900 which is the input stream for reading characters.
1902 This function does not move point. */)
1903 (Lisp_Object start
, Lisp_Object end
, Lisp_Object printflag
, Lisp_Object read_function
)
1905 /* FIXME: Do the eval-sexp-add-defvars dance! */
1906 ptrdiff_t count
= SPECPDL_INDEX ();
1907 Lisp_Object tem
, cbuf
;
1909 cbuf
= Fcurrent_buffer ();
1911 if (NILP (printflag
))
1915 specbind (Qstandard_output
, tem
);
1916 specbind (Qeval_buffer_list
, Fcons (cbuf
, Veval_buffer_list
));
1918 /* `readevalloop' calls functions which check the type of start and end. */
1919 readevalloop (cbuf
, 0, BVAR (XBUFFER (cbuf
), filename
),
1920 !NILP (printflag
), Qnil
, read_function
,
1923 return unbind_to (count
, Qnil
);
1927 DEFUN ("read", Fread
, Sread
, 0, 1, 0,
1928 doc
: /* Read one Lisp expression as text from STREAM, return as Lisp object.
1929 If STREAM is nil, use the value of `standard-input' (which see).
1930 STREAM or the value of `standard-input' may be:
1931 a buffer (read from point and advance it)
1932 a marker (read from where it points and advance it)
1933 a function (call it with no arguments for each character,
1934 call it with a char as argument to push a char back)
1935 a string (takes text from string, starting at the beginning)
1936 t (read text line using minibuffer and use it, or read from
1937 standard input in batch mode). */)
1938 (Lisp_Object stream
)
1941 stream
= Vstandard_input
;
1942 if (EQ (stream
, Qt
))
1943 stream
= Qread_char
;
1944 if (EQ (stream
, Qread_char
))
1945 return Fread_minibuffer (build_string ("Lisp expression: "), Qnil
);
1947 return read_internal_start (stream
, Qnil
, Qnil
);
1950 DEFUN ("read-from-string", Fread_from_string
, Sread_from_string
, 1, 3, 0,
1951 doc
: /* Read one Lisp expression which is represented as text by STRING.
1952 Returns a cons: (OBJECT-READ . FINAL-STRING-INDEX).
1953 FINAL-STRING-INDEX is an integer giving the position of the next
1954 remaining character in STRING.
1955 START and END optionally delimit a substring of STRING from which to read;
1956 they default to 0 and (length STRING) respectively. */)
1957 (Lisp_Object string
, Lisp_Object start
, Lisp_Object end
)
1960 CHECK_STRING (string
);
1961 /* `read_internal_start' sets `read_from_string_index'. */
1962 ret
= read_internal_start (string
, start
, end
);
1963 return Fcons (ret
, make_number (read_from_string_index
));
1966 /* Function to set up the global context we need in toplevel read
1969 read_internal_start (Lisp_Object stream
, Lisp_Object start
, Lisp_Object end
)
1970 /* `start', `end' only used when stream is a string. */
1975 new_backquote_flag
= 0;
1976 read_objects
= Qnil
;
1977 if (EQ (Vread_with_symbol_positions
, Qt
)
1978 || EQ (Vread_with_symbol_positions
, stream
))
1979 Vread_symbol_positions_list
= Qnil
;
1981 if (STRINGP (stream
)
1982 || ((CONSP (stream
) && STRINGP (XCAR (stream
)))))
1984 ptrdiff_t startval
, endval
;
1987 if (STRINGP (stream
))
1990 string
= XCAR (stream
);
1993 endval
= SCHARS (string
);
1997 if (! (0 <= XINT (end
) && XINT (end
) <= SCHARS (string
)))
1998 args_out_of_range (string
, end
);
1999 endval
= XINT (end
);
2006 CHECK_NUMBER (start
);
2007 if (! (0 <= XINT (start
) && XINT (start
) <= endval
))
2008 args_out_of_range (string
, start
);
2009 startval
= XINT (start
);
2011 read_from_string_index
= startval
;
2012 read_from_string_index_byte
= string_char_to_byte (string
, startval
);
2013 read_from_string_limit
= endval
;
2016 retval
= read0 (stream
);
2017 if (EQ (Vread_with_symbol_positions
, Qt
)
2018 || EQ (Vread_with_symbol_positions
, stream
))
2019 Vread_symbol_positions_list
= Fnreverse (Vread_symbol_positions_list
);
2024 /* Signal Qinvalid_read_syntax error.
2025 S is error string of length N (if > 0) */
2027 static _Noreturn
void
2028 invalid_syntax (const char *s
)
2030 xsignal1 (Qinvalid_read_syntax
, build_string (s
));
2034 /* Use this for recursive reads, in contexts where internal tokens
2038 read0 (Lisp_Object readcharfun
)
2040 register Lisp_Object val
;
2043 val
= read1 (readcharfun
, &c
, 0);
2047 xsignal1 (Qinvalid_read_syntax
,
2048 Fmake_string (make_number (1), make_number (c
)));
2051 static ptrdiff_t read_buffer_size
;
2052 static char *read_buffer
;
2054 /* Read a \-escape sequence, assuming we already read the `\'.
2055 If the escape sequence forces unibyte, return eight-bit char. */
2058 read_escape (Lisp_Object readcharfun
, int stringp
)
2060 register int c
= READCHAR
;
2061 /* \u allows up to four hex digits, \U up to eight. Default to the
2062 behavior for \u, and change this value in the case that \U is seen. */
2063 int unicode_hex_count
= 4;
2068 end_of_file_error ();
2098 error ("Invalid escape character syntax");
2101 c
= read_escape (readcharfun
, 0);
2102 return c
| meta_modifier
;
2107 error ("Invalid escape character syntax");
2110 c
= read_escape (readcharfun
, 0);
2111 return c
| shift_modifier
;
2116 error ("Invalid escape character syntax");
2119 c
= read_escape (readcharfun
, 0);
2120 return c
| hyper_modifier
;
2125 error ("Invalid escape character syntax");
2128 c
= read_escape (readcharfun
, 0);
2129 return c
| alt_modifier
;
2133 if (stringp
|| c
!= '-')
2140 c
= read_escape (readcharfun
, 0);
2141 return c
| super_modifier
;
2146 error ("Invalid escape character syntax");
2150 c
= read_escape (readcharfun
, 0);
2151 if ((c
& ~CHAR_MODIFIER_MASK
) == '?')
2152 return 0177 | (c
& CHAR_MODIFIER_MASK
);
2153 else if (! SINGLE_BYTE_CHAR_P ((c
& ~CHAR_MODIFIER_MASK
)))
2154 return c
| ctrl_modifier
;
2155 /* ASCII control chars are made from letters (both cases),
2156 as well as the non-letters within 0100...0137. */
2157 else if ((c
& 0137) >= 0101 && (c
& 0137) <= 0132)
2158 return (c
& (037 | ~0177));
2159 else if ((c
& 0177) >= 0100 && (c
& 0177) <= 0137)
2160 return (c
& (037 | ~0177));
2162 return c
| ctrl_modifier
;
2172 /* An octal escape, as in ANSI C. */
2174 register int i
= c
- '0';
2175 register int count
= 0;
2178 if ((c
= READCHAR
) >= '0' && c
<= '7')
2190 if (i
>= 0x80 && i
< 0x100)
2191 i
= BYTE8_TO_CHAR (i
);
2196 /* A hex escape, as in ANSI C. */
2203 if (c
>= '0' && c
<= '9')
2208 else if ((c
>= 'a' && c
<= 'f')
2209 || (c
>= 'A' && c
<= 'F'))
2212 if (c
>= 'a' && c
<= 'f')
2222 /* Allow hex escapes as large as ?\xfffffff, because some
2223 packages use them to denote characters with modifiers. */
2224 if ((CHAR_META
| (CHAR_META
- 1)) < i
)
2225 error ("Hex character out of range: \\x%x...", i
);
2229 if (count
< 3 && i
>= 0x80)
2230 return BYTE8_TO_CHAR (i
);
2235 /* Post-Unicode-2.0: Up to eight hex chars. */
2236 unicode_hex_count
= 8;
2239 /* A Unicode escape. We only permit them in strings and characters,
2240 not arbitrarily in the source code, as in some other languages. */
2245 while (++count
<= unicode_hex_count
)
2248 /* `isdigit' and `isalpha' may be locale-specific, which we don't
2250 if (c
>= '0' && c
<= '9') i
= (i
<< 4) + (c
- '0');
2251 else if (c
>= 'a' && c
<= 'f') i
= (i
<< 4) + (c
- 'a') + 10;
2252 else if (c
>= 'A' && c
<= 'F') i
= (i
<< 4) + (c
- 'A') + 10;
2254 error ("Non-hex digit used for Unicode escape");
2257 error ("Non-Unicode character: 0x%x", i
);
2266 /* Return the digit that CHARACTER stands for in the given BASE.
2267 Return -1 if CHARACTER is out of range for BASE,
2268 and -2 if CHARACTER is not valid for any supported BASE. */
2270 digit_to_number (int character
, int base
)
2274 if ('0' <= character
&& character
<= '9')
2275 digit
= character
- '0';
2276 else if ('a' <= character
&& character
<= 'z')
2277 digit
= character
- 'a' + 10;
2278 else if ('A' <= character
&& character
<= 'Z')
2279 digit
= character
- 'A' + 10;
2283 return digit
< base
? digit
: -1;
2286 /* Read an integer in radix RADIX using READCHARFUN to read
2287 characters. RADIX must be in the interval [2..36]; if it isn't, a
2288 read error is signaled . Value is the integer read. Signals an
2289 error if encountering invalid read syntax or if RADIX is out of
2293 read_integer (Lisp_Object readcharfun
, EMACS_INT radix
)
2295 /* Room for sign, leading 0, other digits, trailing null byte.
2296 Also, room for invalid syntax diagnostic. */
2297 char buf
[max (1 + 1 + sizeof (uintmax_t) * CHAR_BIT
+ 1,
2298 sizeof "integer, radix " + INT_STRLEN_BOUND (EMACS_INT
))];
2300 int valid
= -1; /* 1 if valid, 0 if not, -1 if incomplete. */
2302 if (radix
< 2 || radix
> 36)
2310 if (c
== '-' || c
== '+')
2321 /* Ignore redundant leading zeros, so the buffer doesn't
2322 fill up with them. */
2328 while (-1 <= (digit
= digit_to_number (c
, radix
)))
2335 if (p
< buf
+ sizeof buf
- 1)
2349 sprintf (buf
, "integer, radix %"pI
"d", radix
);
2350 invalid_syntax (buf
);
2353 return string_to_number (buf
, radix
, 0);
2357 /* If the next token is ')' or ']' or '.', we store that character
2358 in *PCH and the return value is not interesting. Else, we store
2359 zero in *PCH and we read and return one lisp object.
2361 FIRST_IN_LIST is nonzero if this is the first element of a list. */
2364 read1 (register Lisp_Object readcharfun
, int *pch
, int first_in_list
)
2367 bool uninterned_symbol
= 0;
2375 c
= READCHAR_REPORT_MULTIBYTE (&multibyte
);
2377 end_of_file_error ();
2382 return read_list (0, readcharfun
);
2385 return read_vector (readcharfun
, 0);
2401 /* Accept extended format for hashtables (extensible to
2403 #s(hash-table size 2 test equal data (k1 v1 k2 v2)) */
2404 Lisp_Object tmp
= read_list (0, readcharfun
);
2405 Lisp_Object head
= CAR_SAFE (tmp
);
2406 Lisp_Object data
= Qnil
;
2407 Lisp_Object val
= Qnil
;
2408 /* The size is 2 * number of allowed keywords to
2410 Lisp_Object params
[10];
2412 Lisp_Object key
= Qnil
;
2413 int param_count
= 0;
2415 if (!EQ (head
, Qhash_table
))
2416 error ("Invalid extended read marker at head of #s list "
2417 "(only hash-table allowed)");
2419 tmp
= CDR_SAFE (tmp
);
2421 /* This is repetitive but fast and simple. */
2422 params
[param_count
] = QCsize
;
2423 params
[param_count
+ 1] = Fplist_get (tmp
, Qsize
);
2424 if (!NILP (params
[param_count
+ 1]))
2427 params
[param_count
] = QCtest
;
2428 params
[param_count
+ 1] = Fplist_get (tmp
, Qtest
);
2429 if (!NILP (params
[param_count
+ 1]))
2432 params
[param_count
] = QCweakness
;
2433 params
[param_count
+ 1] = Fplist_get (tmp
, Qweakness
);
2434 if (!NILP (params
[param_count
+ 1]))
2437 params
[param_count
] = QCrehash_size
;
2438 params
[param_count
+ 1] = Fplist_get (tmp
, Qrehash_size
);
2439 if (!NILP (params
[param_count
+ 1]))
2442 params
[param_count
] = QCrehash_threshold
;
2443 params
[param_count
+ 1] = Fplist_get (tmp
, Qrehash_threshold
);
2444 if (!NILP (params
[param_count
+ 1]))
2447 /* This is the hashtable data. */
2448 data
= Fplist_get (tmp
, Qdata
);
2450 /* Now use params to make a new hashtable and fill it. */
2451 ht
= Fmake_hash_table (param_count
, params
);
2453 while (CONSP (data
))
2458 error ("Odd number of elements in hashtable data");
2461 Fputhash (key
, val
, ht
);
2467 invalid_syntax ("#");
2475 tmp
= read_vector (readcharfun
, 0);
2476 if (ASIZE (tmp
) < CHAR_TABLE_STANDARD_SLOTS
)
2477 error ("Invalid size char-table");
2478 XSETPVECTYPE (XVECTOR (tmp
), PVEC_CHAR_TABLE
);
2490 tmp
= read_vector (readcharfun
, 0);
2493 error ("Invalid size char-table");
2494 if (! RANGED_INTEGERP (1, AREF (tmp
, 0), 3))
2495 error ("Invalid depth in char-table");
2496 depth
= XINT (AREF (tmp
, 0));
2497 if (chartab_size
[depth
] != size
- 2)
2498 error ("Invalid size char-table");
2499 XSETPVECTYPE (XVECTOR (tmp
), PVEC_SUB_CHAR_TABLE
);
2502 invalid_syntax ("#^^");
2504 invalid_syntax ("#^");
2509 length
= read1 (readcharfun
, pch
, first_in_list
);
2513 Lisp_Object tmp
, val
;
2514 EMACS_INT size_in_chars
2515 = ((XFASTINT (length
) + BOOL_VECTOR_BITS_PER_CHAR
- 1)
2516 / BOOL_VECTOR_BITS_PER_CHAR
);
2519 tmp
= read1 (readcharfun
, pch
, first_in_list
);
2520 if (STRING_MULTIBYTE (tmp
)
2521 || (size_in_chars
!= SCHARS (tmp
)
2522 /* We used to print 1 char too many
2523 when the number of bits was a multiple of 8.
2524 Accept such input in case it came from an old
2526 && ! (XFASTINT (length
)
2527 == (SCHARS (tmp
) - 1) * BOOL_VECTOR_BITS_PER_CHAR
)))
2528 invalid_syntax ("#&...");
2530 val
= Fmake_bool_vector (length
, Qnil
);
2531 memcpy (XBOOL_VECTOR (val
)->data
, SDATA (tmp
), size_in_chars
);
2532 /* Clear the extraneous bits in the last byte. */
2533 if (XINT (length
) != size_in_chars
* BOOL_VECTOR_BITS_PER_CHAR
)
2534 XBOOL_VECTOR (val
)->data
[size_in_chars
- 1]
2535 &= (1 << (XINT (length
) % BOOL_VECTOR_BITS_PER_CHAR
)) - 1;
2538 invalid_syntax ("#&...");
2542 /* Accept compiled functions at read-time so that we don't have to
2543 build them using function calls. */
2545 tmp
= read_vector (readcharfun
, 1);
2546 make_byte_code (XVECTOR (tmp
));
2552 struct gcpro gcpro1
;
2555 /* Read the string itself. */
2556 tmp
= read1 (readcharfun
, &ch
, 0);
2557 if (ch
!= 0 || !STRINGP (tmp
))
2558 invalid_syntax ("#");
2560 /* Read the intervals and their properties. */
2563 Lisp_Object beg
, end
, plist
;
2565 beg
= read1 (readcharfun
, &ch
, 0);
2570 end
= read1 (readcharfun
, &ch
, 0);
2572 plist
= read1 (readcharfun
, &ch
, 0);
2574 invalid_syntax ("Invalid string property list");
2575 Fset_text_properties (beg
, end
, plist
, tmp
);
2581 /* #@NUMBER is used to skip NUMBER following characters.
2582 That's used in .elc files to skip over doc strings
2583 and function definitions. */
2586 enum { extra
= 100 };
2587 ptrdiff_t i
, nskip
= 0;
2590 /* Read a decimal integer. */
2591 while ((c
= READCHAR
) >= 0
2592 && c
>= '0' && c
<= '9')
2594 if ((STRING_BYTES_BOUND
- extra
) / 10 <= nskip
)
2601 if (load_force_doc_strings
2602 && (EQ (readcharfun
, Qget_file_char
)
2603 || EQ (readcharfun
, Qget_emacs_mule_file_char
)))
2605 /* If we are supposed to force doc strings into core right now,
2606 record the last string that we skipped,
2607 and record where in the file it comes from. */
2609 /* But first exchange saved_doc_string
2610 with prev_saved_doc_string, so we save two strings. */
2612 char *temp
= saved_doc_string
;
2613 ptrdiff_t temp_size
= saved_doc_string_size
;
2614 file_offset temp_pos
= saved_doc_string_position
;
2615 ptrdiff_t temp_len
= saved_doc_string_length
;
2617 saved_doc_string
= prev_saved_doc_string
;
2618 saved_doc_string_size
= prev_saved_doc_string_size
;
2619 saved_doc_string_position
= prev_saved_doc_string_position
;
2620 saved_doc_string_length
= prev_saved_doc_string_length
;
2622 prev_saved_doc_string
= temp
;
2623 prev_saved_doc_string_size
= temp_size
;
2624 prev_saved_doc_string_position
= temp_pos
;
2625 prev_saved_doc_string_length
= temp_len
;
2628 if (saved_doc_string_size
== 0)
2630 saved_doc_string
= xmalloc (nskip
+ extra
);
2631 saved_doc_string_size
= nskip
+ extra
;
2633 if (nskip
> saved_doc_string_size
)
2635 saved_doc_string
= xrealloc (saved_doc_string
, nskip
+ extra
);
2636 saved_doc_string_size
= nskip
+ extra
;
2639 saved_doc_string_position
= file_tell (instream
);
2641 /* Copy that many characters into saved_doc_string. */
2642 for (i
= 0; i
< nskip
&& c
>= 0; i
++)
2643 saved_doc_string
[i
] = c
= READCHAR
;
2645 saved_doc_string_length
= i
;
2649 /* Skip that many characters. */
2650 for (i
= 0; i
< nskip
&& c
>= 0; i
++)
2659 /* #! appears at the beginning of an executable file.
2660 Skip the first line. */
2661 while (c
!= '\n' && c
>= 0)
2666 return Vload_file_name
;
2668 return Fcons (Qfunction
, Fcons (read0 (readcharfun
), Qnil
));
2669 /* #:foo is the uninterned symbol named foo. */
2672 uninterned_symbol
= 1;
2675 && c
!= 0xa0 /* NBSP */
2677 || strchr ("\"';()[]#`,", c
) == NULL
)))
2679 /* No symbol character follows, this is the empty
2682 return Fmake_symbol (empty_unibyte_string
);
2686 /* ## is the empty symbol. */
2688 return Fintern (empty_unibyte_string
, Qnil
);
2689 /* Reader forms that can reuse previously read objects. */
2690 if (c
>= '0' && c
<= '9')
2695 /* Read a non-negative integer. */
2696 while (c
>= '0' && c
<= '9')
2698 if (MOST_POSITIVE_FIXNUM
/ 10 < n
2699 || MOST_POSITIVE_FIXNUM
< n
* 10 + c
- '0')
2700 n
= MOST_POSITIVE_FIXNUM
+ 1;
2702 n
= n
* 10 + c
- '0';
2706 if (n
<= MOST_POSITIVE_FIXNUM
)
2708 if (c
== 'r' || c
== 'R')
2709 return read_integer (readcharfun
, n
);
2711 if (! NILP (Vread_circle
))
2713 /* #n=object returns object, but associates it with
2717 /* Make a placeholder for #n# to use temporarily. */
2718 Lisp_Object placeholder
;
2721 placeholder
= Fcons (Qnil
, Qnil
);
2722 cell
= Fcons (make_number (n
), placeholder
);
2723 read_objects
= Fcons (cell
, read_objects
);
2725 /* Read the object itself. */
2726 tem
= read0 (readcharfun
);
2728 /* Now put it everywhere the placeholder was... */
2729 substitute_object_in_subtree (tem
, placeholder
);
2731 /* ...and #n# will use the real value from now on. */
2732 Fsetcdr (cell
, tem
);
2737 /* #n# returns a previously read object. */
2740 tem
= Fassq (make_number (n
), read_objects
);
2746 /* Fall through to error message. */
2748 else if (c
== 'x' || c
== 'X')
2749 return read_integer (readcharfun
, 16);
2750 else if (c
== 'o' || c
== 'O')
2751 return read_integer (readcharfun
, 8);
2752 else if (c
== 'b' || c
== 'B')
2753 return read_integer (readcharfun
, 2);
2756 invalid_syntax ("#");
2759 while ((c
= READCHAR
) >= 0 && c
!= '\n');
2764 return Fcons (Qquote
, Fcons (read0 (readcharfun
), Qnil
));
2769 int next_char
= READCHAR
;
2771 /* Transition from old-style to new-style:
2772 If we see "(`" it used to mean old-style, which usually works
2773 fine because ` should almost never appear in such a position
2774 for new-style. But occasionally we need "(`" to mean new
2775 style, so we try to distinguish the two by the fact that we
2776 can either write "( `foo" or "(` foo", where the first
2777 intends to use new-style whereas the second intends to use
2778 old-style. For Emacs-25, we should completely remove this
2779 first_in_list exception (old-style can still be obtained via
2781 if (!new_backquote_flag
&& first_in_list
&& next_char
== ' ')
2783 Vold_style_backquotes
= Qt
;
2790 new_backquote_flag
++;
2791 value
= read0 (readcharfun
);
2792 new_backquote_flag
--;
2794 return Fcons (Qbackquote
, Fcons (value
, Qnil
));
2799 int next_char
= READCHAR
;
2801 /* Transition from old-style to new-style:
2802 It used to be impossible to have a new-style , other than within
2803 a new-style `. This is sufficient when ` and , are used in the
2804 normal way, but ` and , can also appear in args to macros that
2805 will not interpret them in the usual way, in which case , may be
2806 used without any ` anywhere near.
2807 So we now use the same heuristic as for backquote: old-style
2808 unquotes are only recognized when first on a list, and when
2809 followed by a space.
2810 Because it's more difficult to peek 2 chars ahead, a new-style
2811 ,@ can still not be used outside of a `, unless it's in the middle
2813 if (new_backquote_flag
2815 || (next_char
!= ' ' && next_char
!= '@'))
2817 Lisp_Object comma_type
= Qnil
;
2822 comma_type
= Qcomma_at
;
2824 comma_type
= Qcomma_dot
;
2827 if (ch
>= 0) UNREAD (ch
);
2828 comma_type
= Qcomma
;
2831 value
= read0 (readcharfun
);
2832 return Fcons (comma_type
, Fcons (value
, Qnil
));
2836 Vold_style_backquotes
= Qt
;
2848 end_of_file_error ();
2850 /* Accept `single space' syntax like (list ? x) where the
2851 whitespace character is SPC or TAB.
2852 Other literal whitespace like NL, CR, and FF are not accepted,
2853 as there are well-established escape sequences for these. */
2854 if (c
== ' ' || c
== '\t')
2855 return make_number (c
);
2858 c
= read_escape (readcharfun
, 0);
2859 modifiers
= c
& CHAR_MODIFIER_MASK
;
2860 c
&= ~CHAR_MODIFIER_MASK
;
2861 if (CHAR_BYTE8_P (c
))
2862 c
= CHAR_TO_BYTE8 (c
);
2865 next_char
= READCHAR
;
2866 ok
= (next_char
<= 040
2867 || (next_char
< 0200
2868 && strchr ("\"';()[]#?`,.", next_char
) != NULL
));
2871 return make_number (c
);
2873 invalid_syntax ("?");
2878 char *p
= read_buffer
;
2879 char *end
= read_buffer
+ read_buffer_size
;
2881 /* Nonzero if we saw an escape sequence specifying
2882 a multibyte character. */
2883 int force_multibyte
= 0;
2884 /* Nonzero if we saw an escape sequence specifying
2885 a single-byte character. */
2886 int force_singlebyte
= 0;
2888 ptrdiff_t nchars
= 0;
2890 while ((ch
= READCHAR
) >= 0
2893 if (end
- p
< MAX_MULTIBYTE_LENGTH
)
2895 ptrdiff_t offset
= p
- read_buffer
;
2896 if (min (PTRDIFF_MAX
, SIZE_MAX
) / 2 < read_buffer_size
)
2897 memory_full (SIZE_MAX
);
2898 read_buffer
= xrealloc (read_buffer
, read_buffer_size
* 2);
2899 read_buffer_size
*= 2;
2900 p
= read_buffer
+ offset
;
2901 end
= read_buffer
+ read_buffer_size
;
2908 ch
= read_escape (readcharfun
, 1);
2910 /* CH is -1 if \ newline has just been seen. */
2913 if (p
== read_buffer
)
2918 modifiers
= ch
& CHAR_MODIFIER_MASK
;
2919 ch
= ch
& ~CHAR_MODIFIER_MASK
;
2921 if (CHAR_BYTE8_P (ch
))
2922 force_singlebyte
= 1;
2923 else if (! ASCII_CHAR_P (ch
))
2924 force_multibyte
= 1;
2925 else /* I.e. ASCII_CHAR_P (ch). */
2927 /* Allow `\C- ' and `\C-?'. */
2928 if (modifiers
== CHAR_CTL
)
2931 ch
= 0, modifiers
= 0;
2933 ch
= 127, modifiers
= 0;
2935 if (modifiers
& CHAR_SHIFT
)
2937 /* Shift modifier is valid only with [A-Za-z]. */
2938 if (ch
>= 'A' && ch
<= 'Z')
2939 modifiers
&= ~CHAR_SHIFT
;
2940 else if (ch
>= 'a' && ch
<= 'z')
2941 ch
-= ('a' - 'A'), modifiers
&= ~CHAR_SHIFT
;
2944 if (modifiers
& CHAR_META
)
2946 /* Move the meta bit to the right place for a
2948 modifiers
&= ~CHAR_META
;
2949 ch
= BYTE8_TO_CHAR (ch
| 0x80);
2950 force_singlebyte
= 1;
2954 /* Any modifiers remaining are invalid. */
2956 error ("Invalid modifier in string");
2957 p
+= CHAR_STRING (ch
, (unsigned char *) p
);
2961 p
+= CHAR_STRING (ch
, (unsigned char *) p
);
2962 if (CHAR_BYTE8_P (ch
))
2963 force_singlebyte
= 1;
2964 else if (! ASCII_CHAR_P (ch
))
2965 force_multibyte
= 1;
2971 end_of_file_error ();
2973 /* If purifying, and string starts with \ newline,
2974 return zero instead. This is for doc strings
2975 that we are really going to find in etc/DOC.nn.nn. */
2976 if (!NILP (Vpurify_flag
) && NILP (Vdoc_file_name
) && cancel
)
2977 return make_number (0);
2979 if (! force_multibyte
&& force_singlebyte
)
2981 /* READ_BUFFER contains raw 8-bit bytes and no multibyte
2982 forms. Convert it to unibyte. */
2983 nchars
= str_as_unibyte ((unsigned char *) read_buffer
,
2985 p
= read_buffer
+ nchars
;
2988 return make_specified_string (read_buffer
, nchars
, p
- read_buffer
,
2990 || (p
- read_buffer
!= nchars
)));
2995 int next_char
= READCHAR
;
2998 if (next_char
<= 040
2999 || (next_char
< 0200
3000 && strchr ("\"';([#?`,", next_char
) != NULL
))
3006 /* Otherwise, we fall through! Note that the atom-reading loop
3007 below will now loop at least once, assuring that we will not
3008 try to UNREAD two characters in a row. */
3012 if (c
<= 040) goto retry
;
3013 if (c
== 0xa0) /* NBSP */
3018 char *p
= read_buffer
;
3020 EMACS_INT start_position
= readchar_count
- 1;
3023 char *end
= read_buffer
+ read_buffer_size
;
3027 if (end
- p
< MAX_MULTIBYTE_LENGTH
)
3029 ptrdiff_t offset
= p
- read_buffer
;
3030 if (min (PTRDIFF_MAX
, SIZE_MAX
) / 2 < read_buffer_size
)
3031 memory_full (SIZE_MAX
);
3032 read_buffer
= xrealloc (read_buffer
, read_buffer_size
* 2);
3033 read_buffer_size
*= 2;
3034 p
= read_buffer
+ offset
;
3035 end
= read_buffer
+ read_buffer_size
;
3042 end_of_file_error ();
3047 p
+= CHAR_STRING (c
, (unsigned char *) p
);
3053 && c
!= 0xa0 /* NBSP */
3055 || strchr ("\"';()[]#`,", c
) == NULL
));
3059 ptrdiff_t offset
= p
- read_buffer
;
3060 if (min (PTRDIFF_MAX
, SIZE_MAX
) / 2 < read_buffer_size
)
3061 memory_full (SIZE_MAX
);
3062 read_buffer
= xrealloc (read_buffer
, read_buffer_size
* 2);
3063 read_buffer_size
*= 2;
3064 p
= read_buffer
+ offset
;
3065 end
= read_buffer
+ read_buffer_size
;
3071 if (!quoted
&& !uninterned_symbol
)
3073 Lisp_Object result
= string_to_number (read_buffer
, 10, 0);
3074 if (! NILP (result
))
3078 Lisp_Object name
, result
;
3079 ptrdiff_t nbytes
= p
- read_buffer
;
3082 ? multibyte_chars_in_text ((unsigned char *) read_buffer
,
3086 name
= ((uninterned_symbol
&& ! NILP (Vpurify_flag
)
3087 ? make_pure_string
: make_specified_string
)
3088 (read_buffer
, nchars
, nbytes
, multibyte
));
3089 result
= (uninterned_symbol
? Fmake_symbol (name
)
3090 : Fintern (name
, Qnil
));
3092 if (EQ (Vread_with_symbol_positions
, Qt
)
3093 || EQ (Vread_with_symbol_positions
, readcharfun
))
3094 Vread_symbol_positions_list
3095 = Fcons (Fcons (result
, make_number (start_position
)),
3096 Vread_symbol_positions_list
);
3104 /* List of nodes we've seen during substitute_object_in_subtree. */
3105 static Lisp_Object seen_list
;
3108 substitute_object_in_subtree (Lisp_Object object
, Lisp_Object placeholder
)
3110 Lisp_Object check_object
;
3112 /* We haven't seen any objects when we start. */
3115 /* Make all the substitutions. */
3117 = substitute_object_recurse (object
, placeholder
, object
);
3119 /* Clear seen_list because we're done with it. */
3122 /* The returned object here is expected to always eq the
3124 if (!EQ (check_object
, object
))
3125 error ("Unexpected mutation error in reader");
3128 /* Feval doesn't get called from here, so no gc protection is needed. */
3129 #define SUBSTITUTE(get_val, set_val) \
3131 Lisp_Object old_value = get_val; \
3132 Lisp_Object true_value \
3133 = substitute_object_recurse (object, placeholder, \
3136 if (!EQ (old_value, true_value)) \
3143 substitute_object_recurse (Lisp_Object object
, Lisp_Object placeholder
, Lisp_Object subtree
)
3145 /* If we find the placeholder, return the target object. */
3146 if (EQ (placeholder
, subtree
))
3149 /* If we've been to this node before, don't explore it again. */
3150 if (!EQ (Qnil
, Fmemq (subtree
, seen_list
)))
3153 /* If this node can be the entry point to a cycle, remember that
3154 we've seen it. It can only be such an entry point if it was made
3155 by #n=, which means that we can find it as a value in
3157 if (!EQ (Qnil
, Frassq (subtree
, read_objects
)))
3158 seen_list
= Fcons (subtree
, seen_list
);
3160 /* Recurse according to subtree's type.
3161 Every branch must return a Lisp_Object. */
3162 switch (XTYPE (subtree
))
3164 case Lisp_Vectorlike
:
3166 ptrdiff_t i
, length
= 0;
3167 if (BOOL_VECTOR_P (subtree
))
3168 return subtree
; /* No sub-objects anyway. */
3169 else if (CHAR_TABLE_P (subtree
) || SUB_CHAR_TABLE_P (subtree
)
3170 || COMPILEDP (subtree
))
3171 length
= ASIZE (subtree
) & PSEUDOVECTOR_SIZE_MASK
;
3172 else if (VECTORP (subtree
))
3173 length
= ASIZE (subtree
);
3175 /* An unknown pseudovector may contain non-Lisp fields, so we
3176 can't just blindly traverse all its fields. We used to call
3177 `Flength' which signaled `sequencep', so I just preserved this
3179 wrong_type_argument (Qsequencep
, subtree
);
3181 for (i
= 0; i
< length
; i
++)
3182 SUBSTITUTE (AREF (subtree
, i
),
3183 ASET (subtree
, i
, true_value
));
3189 SUBSTITUTE (XCAR (subtree
),
3190 XSETCAR (subtree
, true_value
));
3191 SUBSTITUTE (XCDR (subtree
),
3192 XSETCDR (subtree
, true_value
));
3198 /* Check for text properties in each interval.
3199 substitute_in_interval contains part of the logic. */
3201 INTERVAL root_interval
= string_intervals (subtree
);
3202 Lisp_Object arg
= Fcons (object
, placeholder
);
3204 traverse_intervals_noorder (root_interval
,
3205 &substitute_in_interval
, arg
);
3210 /* Other types don't recurse any further. */
3216 /* Helper function for substitute_object_recurse. */
3218 substitute_in_interval (INTERVAL interval
, Lisp_Object arg
)
3220 Lisp_Object object
= Fcar (arg
);
3221 Lisp_Object placeholder
= Fcdr (arg
);
3223 SUBSTITUTE (interval
->plist
, set_interval_plist (interval
, true_value
));
3233 /* Convert STRING to a number, assuming base BASE. Return a fixnum if CP has
3234 integer syntax and fits in a fixnum, else return the nearest float if CP has
3235 either floating point or integer syntax and BASE is 10, else return nil. If
3236 IGNORE_TRAILING is nonzero, consider just the longest prefix of CP that has
3237 valid floating point syntax. Signal an overflow if BASE is not 10 and the
3238 number has integer syntax but does not fit. */
3241 string_to_number (char const *string
, int base
, int ignore_trailing
)
3244 char const *cp
= string
;
3246 int float_syntax
= 0;
3249 /* Compute NaN and infinities using a variable, to cope with compilers that
3250 think they are smarter than we are. */
3253 /* Negate the value ourselves. This treats 0, NaNs, and infinity properly on
3254 IEEE floating point hosts, and works around a formerly-common bug where
3255 atof ("-0.0") drops the sign. */
3256 int negative
= *cp
== '-';
3258 int signedp
= negative
|| *cp
== '+';
3263 leading_digit
= digit_to_number (*cp
, base
);
3264 if (0 <= leading_digit
)
3269 while (0 <= digit_to_number (*cp
, base
));
3279 if ('0' <= *cp
&& *cp
<= '9')
3284 while ('0' <= *cp
&& *cp
<= '9');
3286 if (*cp
== 'e' || *cp
== 'E')
3288 char const *ecp
= cp
;
3290 if (*cp
== '+' || *cp
== '-')
3292 if ('0' <= *cp
&& *cp
<= '9')
3297 while ('0' <= *cp
&& *cp
<= '9');
3299 else if (cp
[-1] == '+'
3300 && cp
[0] == 'I' && cp
[1] == 'N' && cp
[2] == 'F')
3306 else if (cp
[-1] == '+'
3307 && cp
[0] == 'N' && cp
[1] == 'a' && cp
[2] == 'N')
3311 value
= zero
/ zero
;
3313 /* If that made a "negative" NaN, negate it. */
3316 union { double d
; char c
[sizeof (double)]; }
3317 u_data
, u_minus_zero
;
3319 u_minus_zero
.d
= -0.0;
3320 for (i
= 0; i
< sizeof (double); i
++)
3321 if (u_data
.c
[i
] & u_minus_zero
.c
[i
])
3327 /* Now VALUE is a positive NaN. */
3333 float_syntax
= ((state
& (DOT_CHAR
|TRAIL_INT
)) == (DOT_CHAR
|TRAIL_INT
)
3334 || state
== (LEAD_INT
|E_EXP
));
3337 /* Return nil if the number uses invalid syntax. If IGNORE_TRAILING, accept
3338 any prefix that matches. Otherwise, the entire string must match. */
3339 if (! (ignore_trailing
3340 ? ((state
& LEAD_INT
) != 0 || float_syntax
)
3341 : (!*cp
&& ((state
& ~DOT_CHAR
) == LEAD_INT
|| float_syntax
))))
3344 /* If the number uses integer and not float syntax, and is in C-language
3345 range, use its value, preferably as a fixnum. */
3346 if (0 <= leading_digit
&& ! float_syntax
)
3350 /* Fast special case for single-digit integers. This also avoids a
3351 glitch when BASE is 16 and IGNORE_TRAILING is nonzero, because in that
3352 case some versions of strtoumax accept numbers like "0x1" that Emacs
3354 if (digit_to_number (string
[signedp
+ 1], base
) < 0)
3355 return make_number (negative
? -leading_digit
: leading_digit
);
3358 n
= strtoumax (string
+ signedp
, NULL
, base
);
3359 if (errno
== ERANGE
)
3361 /* Unfortunately there's no simple and accurate way to convert
3362 non-base-10 numbers that are out of C-language range. */
3364 xsignal1 (Qoverflow_error
, build_string (string
));
3366 else if (n
<= (negative
? -MOST_NEGATIVE_FIXNUM
: MOST_POSITIVE_FIXNUM
))
3368 EMACS_INT signed_n
= n
;
3369 return make_number (negative
? -signed_n
: signed_n
);
3375 /* Either the number uses float syntax, or it does not fit into a fixnum.
3376 Convert it from string to floating point, unless the value is already
3377 known because it is an infinity, a NAN, or its absolute value fits in
3380 value
= atof (string
+ signedp
);
3382 return make_float (negative
? -value
: value
);
3387 read_vector (Lisp_Object readcharfun
, int bytecodeflag
)
3390 register Lisp_Object
*ptr
;
3391 register Lisp_Object tem
, item
, vector
;
3392 register struct Lisp_Cons
*otem
;
3395 tem
= read_list (1, readcharfun
);
3396 len
= Flength (tem
);
3397 vector
= Fmake_vector (len
, Qnil
);
3399 size
= ASIZE (vector
);
3400 ptr
= XVECTOR (vector
)->contents
;
3401 for (i
= 0; i
< size
; i
++)
3404 /* If `load-force-doc-strings' is t when reading a lazily-loaded
3405 bytecode object, the docstring containing the bytecode and
3406 constants values must be treated as unibyte and passed to
3407 Fread, to get the actual bytecode string and constants vector. */
3408 if (bytecodeflag
&& load_force_doc_strings
)
3410 if (i
== COMPILED_BYTECODE
)
3412 if (!STRINGP (item
))
3413 error ("Invalid byte code");
3415 /* Delay handling the bytecode slot until we know whether
3416 it is lazily-loaded (we can tell by whether the
3417 constants slot is nil). */
3418 ASET (vector
, COMPILED_CONSTANTS
, item
);
3421 else if (i
== COMPILED_CONSTANTS
)
3423 Lisp_Object bytestr
= ptr
[COMPILED_CONSTANTS
];
3427 /* Coerce string to unibyte (like string-as-unibyte,
3428 but without generating extra garbage and
3429 guaranteeing no change in the contents). */
3430 STRING_SET_CHARS (bytestr
, SBYTES (bytestr
));
3431 STRING_SET_UNIBYTE (bytestr
);
3433 item
= Fread (Fcons (bytestr
, readcharfun
));
3435 error ("Invalid byte code");
3437 otem
= XCONS (item
);
3438 bytestr
= XCAR (item
);
3443 /* Now handle the bytecode slot. */
3444 ASET (vector
, COMPILED_BYTECODE
, bytestr
);
3446 else if (i
== COMPILED_DOC_STRING
3448 && ! STRING_MULTIBYTE (item
))
3450 if (EQ (readcharfun
, Qget_emacs_mule_file_char
))
3451 item
= Fdecode_coding_string (item
, Qemacs_mule
, Qnil
, Qnil
);
3453 item
= Fstring_as_multibyte (item
);
3456 ASET (vector
, i
, item
);
3464 /* FLAG = 1 means check for ] to terminate rather than ) and . */
3467 read_list (int flag
, register Lisp_Object readcharfun
)
3469 Lisp_Object val
, tail
;
3470 register Lisp_Object elt
, tem
;
3471 struct gcpro gcpro1
, gcpro2
;
3472 /* 0 is the normal case.
3473 1 means this list is a doc reference; replace it with the number 0.
3474 2 means this list is a doc reference; replace it with the doc string. */
3475 int doc_reference
= 0;
3477 /* Initialize this to 1 if we are reading a list. */
3478 int first_in_list
= flag
<= 0;
3487 elt
= read1 (readcharfun
, &ch
, first_in_list
);
3492 /* While building, if the list starts with #$, treat it specially. */
3493 if (EQ (elt
, Vload_file_name
)
3495 && !NILP (Vpurify_flag
))
3497 if (NILP (Vdoc_file_name
))
3498 /* We have not yet called Snarf-documentation, so assume
3499 this file is described in the DOC-MM.NN file
3500 and Snarf-documentation will fill in the right value later.
3501 For now, replace the whole list with 0. */
3504 /* We have already called Snarf-documentation, so make a relative
3505 file name for this file, so it can be found properly
3506 in the installed Lisp directory.
3507 We don't use Fexpand_file_name because that would make
3508 the directory absolute now. */
3509 elt
= concat2 (build_string ("../lisp/"),
3510 Ffile_name_nondirectory (elt
));
3512 else if (EQ (elt
, Vload_file_name
)
3514 && load_force_doc_strings
)
3523 invalid_syntax (") or . in a vector");
3531 XSETCDR (tail
, read0 (readcharfun
));
3533 val
= read0 (readcharfun
);
3534 read1 (readcharfun
, &ch
, 0);
3538 if (doc_reference
== 1)
3539 return make_number (0);
3540 if (doc_reference
== 2)
3542 /* Get a doc string from the file we are loading.
3543 If it's in saved_doc_string, get it from there.
3545 Here, we don't know if the string is a
3546 bytecode string or a doc string. As a
3547 bytecode string must be unibyte, we always
3548 return a unibyte string. If it is actually a
3549 doc string, caller must make it
3552 EMACS_INT pos
= XINT (XCDR (val
));
3553 /* Position is negative for user variables. */
3554 if (pos
< 0) pos
= -pos
;
3555 if (pos
>= saved_doc_string_position
3556 && pos
< (saved_doc_string_position
3557 + saved_doc_string_length
))
3559 ptrdiff_t start
= pos
- saved_doc_string_position
;
3562 /* Process quoting with ^A,
3563 and find the end of the string,
3564 which is marked with ^_ (037). */
3565 for (from
= start
, to
= start
;
3566 saved_doc_string
[from
] != 037;)
3568 int c
= saved_doc_string
[from
++];
3571 c
= saved_doc_string
[from
++];
3573 saved_doc_string
[to
++] = c
;
3575 saved_doc_string
[to
++] = 0;
3577 saved_doc_string
[to
++] = 037;
3580 saved_doc_string
[to
++] = c
;
3583 return make_unibyte_string (saved_doc_string
+ start
,
3586 /* Look in prev_saved_doc_string the same way. */
3587 else if (pos
>= prev_saved_doc_string_position
3588 && pos
< (prev_saved_doc_string_position
3589 + prev_saved_doc_string_length
))
3592 pos
- prev_saved_doc_string_position
;
3595 /* Process quoting with ^A,
3596 and find the end of the string,
3597 which is marked with ^_ (037). */
3598 for (from
= start
, to
= start
;
3599 prev_saved_doc_string
[from
] != 037;)
3601 int c
= prev_saved_doc_string
[from
++];
3604 c
= prev_saved_doc_string
[from
++];
3606 prev_saved_doc_string
[to
++] = c
;
3608 prev_saved_doc_string
[to
++] = 0;
3610 prev_saved_doc_string
[to
++] = 037;
3613 prev_saved_doc_string
[to
++] = c
;
3616 return make_unibyte_string (prev_saved_doc_string
3621 return get_doc_string (val
, 1, 0);
3626 invalid_syntax (". in wrong context");
3628 invalid_syntax ("] in a list");
3630 tem
= Fcons (elt
, Qnil
);
3632 XSETCDR (tail
, tem
);
3639 static Lisp_Object initial_obarray
;
3641 /* `oblookup' stores the bucket number here, for the sake of Funintern. */
3643 static size_t oblookup_last_bucket_number
;
3645 /* Get an error if OBARRAY is not an obarray.
3646 If it is one, return it. */
3649 check_obarray (Lisp_Object obarray
)
3651 if (!VECTORP (obarray
) || ASIZE (obarray
) == 0)
3653 /* If Vobarray is now invalid, force it to be valid. */
3654 if (EQ (Vobarray
, obarray
)) Vobarray
= initial_obarray
;
3655 wrong_type_argument (Qvectorp
, obarray
);
3660 /* Intern the C string STR: return a symbol with that name,
3661 interned in the current obarray. */
3664 intern_1 (const char *str
, ptrdiff_t len
)
3666 Lisp_Object obarray
= check_obarray (Vobarray
);
3667 Lisp_Object tem
= oblookup (obarray
, str
, len
, len
);
3669 return SYMBOLP (tem
) ? tem
: Fintern (make_string (str
, len
), obarray
);
3673 intern_c_string_1 (const char *str
, ptrdiff_t len
)
3675 Lisp_Object obarray
= check_obarray (Vobarray
);
3676 Lisp_Object tem
= oblookup (obarray
, str
, len
, len
);
3681 if (NILP (Vpurify_flag
))
3682 /* Creating a non-pure string from a string literal not
3683 implemented yet. We could just use make_string here and live
3684 with the extra copy. */
3687 return Fintern (make_pure_c_string (str
, len
), obarray
);
3690 DEFUN ("intern", Fintern
, Sintern
, 1, 2, 0,
3691 doc
: /* Return the canonical symbol whose name is STRING.
3692 If there is none, one is created by this function and returned.
3693 A second optional argument specifies the obarray to use;
3694 it defaults to the value of `obarray'. */)
3695 (Lisp_Object string
, Lisp_Object obarray
)
3697 register Lisp_Object tem
, sym
, *ptr
;
3699 if (NILP (obarray
)) obarray
= Vobarray
;
3700 obarray
= check_obarray (obarray
);
3702 CHECK_STRING (string
);
3704 tem
= oblookup (obarray
, SSDATA (string
),
3707 if (!INTEGERP (tem
))
3710 if (!NILP (Vpurify_flag
))
3711 string
= Fpurecopy (string
);
3712 sym
= Fmake_symbol (string
);
3714 if (EQ (obarray
, initial_obarray
))
3715 XSYMBOL (sym
)->interned
= SYMBOL_INTERNED_IN_INITIAL_OBARRAY
;
3717 XSYMBOL (sym
)->interned
= SYMBOL_INTERNED
;
3719 if ((SREF (string
, 0) == ':')
3720 && EQ (obarray
, initial_obarray
))
3722 XSYMBOL (sym
)->constant
= 1;
3723 XSYMBOL (sym
)->redirect
= SYMBOL_PLAINVAL
;
3724 SET_SYMBOL_VAL (XSYMBOL (sym
), sym
);
3727 ptr
= aref_addr (obarray
, XINT(tem
));
3729 set_symbol_next (sym
, XSYMBOL (*ptr
));
3731 set_symbol_next (sym
, NULL
);
3736 DEFUN ("intern-soft", Fintern_soft
, Sintern_soft
, 1, 2, 0,
3737 doc
: /* Return the canonical symbol named NAME, or nil if none exists.
3738 NAME may be a string or a symbol. If it is a symbol, that exact
3739 symbol is searched for.
3740 A second optional argument specifies the obarray to use;
3741 it defaults to the value of `obarray'. */)
3742 (Lisp_Object name
, Lisp_Object obarray
)
3744 register Lisp_Object tem
, string
;
3746 if (NILP (obarray
)) obarray
= Vobarray
;
3747 obarray
= check_obarray (obarray
);
3749 if (!SYMBOLP (name
))
3751 CHECK_STRING (name
);
3755 string
= SYMBOL_NAME (name
);
3757 tem
= oblookup (obarray
, SSDATA (string
), SCHARS (string
), SBYTES (string
));
3758 if (INTEGERP (tem
) || (SYMBOLP (name
) && !EQ (name
, tem
)))
3764 DEFUN ("unintern", Funintern
, Sunintern
, 1, 2, 0,
3765 doc
: /* Delete the symbol named NAME, if any, from OBARRAY.
3766 The value is t if a symbol was found and deleted, nil otherwise.
3767 NAME may be a string or a symbol. If it is a symbol, that symbol
3768 is deleted, if it belongs to OBARRAY--no other symbol is deleted.
3769 OBARRAY defaults to the value of the variable `obarray'. */)
3770 (Lisp_Object name
, Lisp_Object obarray
)
3772 register Lisp_Object string
, tem
;
3775 if (NILP (obarray
)) obarray
= Vobarray
;
3776 obarray
= check_obarray (obarray
);
3779 string
= SYMBOL_NAME (name
);
3782 CHECK_STRING (name
);
3786 tem
= oblookup (obarray
, SSDATA (string
),
3791 /* If arg was a symbol, don't delete anything but that symbol itself. */
3792 if (SYMBOLP (name
) && !EQ (name
, tem
))
3795 /* There are plenty of other symbols which will screw up the Emacs
3796 session if we unintern them, as well as even more ways to use
3797 `setq' or `fset' or whatnot to make the Emacs session
3798 unusable. Let's not go down this silly road. --Stef */
3799 /* if (EQ (tem, Qnil) || EQ (tem, Qt))
3800 error ("Attempt to unintern t or nil"); */
3802 XSYMBOL (tem
)->interned
= SYMBOL_UNINTERNED
;
3804 hash
= oblookup_last_bucket_number
;
3806 if (EQ (AREF (obarray
, hash
), tem
))
3808 if (XSYMBOL (tem
)->next
)
3811 XSETSYMBOL (sym
, XSYMBOL (tem
)->next
);
3812 ASET (obarray
, hash
, sym
);
3815 ASET (obarray
, hash
, make_number (0));
3819 Lisp_Object tail
, following
;
3821 for (tail
= AREF (obarray
, hash
);
3822 XSYMBOL (tail
)->next
;
3825 XSETSYMBOL (following
, XSYMBOL (tail
)->next
);
3826 if (EQ (following
, tem
))
3828 set_symbol_next (tail
, XSYMBOL (following
)->next
);
3837 /* Return the symbol in OBARRAY whose names matches the string
3838 of SIZE characters (SIZE_BYTE bytes) at PTR.
3839 If there is no such symbol in OBARRAY, return nil.
3841 Also store the bucket number in oblookup_last_bucket_number. */
3844 oblookup (Lisp_Object obarray
, register const char *ptr
, ptrdiff_t size
, ptrdiff_t size_byte
)
3848 register Lisp_Object tail
;
3849 Lisp_Object bucket
, tem
;
3851 obarray
= check_obarray (obarray
);
3852 obsize
= ASIZE (obarray
);
3854 /* This is sometimes needed in the middle of GC. */
3855 obsize
&= ~ARRAY_MARK_FLAG
;
3856 hash
= hash_string (ptr
, size_byte
) % obsize
;
3857 bucket
= AREF (obarray
, hash
);
3858 oblookup_last_bucket_number
= hash
;
3859 if (EQ (bucket
, make_number (0)))
3861 else if (!SYMBOLP (bucket
))
3862 error ("Bad data in guts of obarray"); /* Like CADR error message. */
3864 for (tail
= bucket
; ; XSETSYMBOL (tail
, XSYMBOL (tail
)->next
))
3866 if (SBYTES (SYMBOL_NAME (tail
)) == size_byte
3867 && SCHARS (SYMBOL_NAME (tail
)) == size
3868 && !memcmp (SDATA (SYMBOL_NAME (tail
)), ptr
, size_byte
))
3870 else if (XSYMBOL (tail
)->next
== 0)
3873 XSETINT (tem
, hash
);
3878 map_obarray (Lisp_Object obarray
, void (*fn
) (Lisp_Object
, Lisp_Object
), Lisp_Object arg
)
3881 register Lisp_Object tail
;
3882 CHECK_VECTOR (obarray
);
3883 for (i
= ASIZE (obarray
) - 1; i
>= 0; i
--)
3885 tail
= AREF (obarray
, i
);
3890 if (XSYMBOL (tail
)->next
== 0)
3892 XSETSYMBOL (tail
, XSYMBOL (tail
)->next
);
3898 mapatoms_1 (Lisp_Object sym
, Lisp_Object function
)
3900 call1 (function
, sym
);
3903 DEFUN ("mapatoms", Fmapatoms
, Smapatoms
, 1, 2, 0,
3904 doc
: /* Call FUNCTION on every symbol in OBARRAY.
3905 OBARRAY defaults to the value of `obarray'. */)
3906 (Lisp_Object function
, Lisp_Object obarray
)
3908 if (NILP (obarray
)) obarray
= Vobarray
;
3909 obarray
= check_obarray (obarray
);
3911 map_obarray (obarray
, mapatoms_1
, function
);
3915 #define OBARRAY_SIZE 1511
3920 Lisp_Object oblength
;
3921 ptrdiff_t size
= 100 + MAX_MULTIBYTE_LENGTH
;
3923 XSETFASTINT (oblength
, OBARRAY_SIZE
);
3925 Vobarray
= Fmake_vector (oblength
, make_number (0));
3926 initial_obarray
= Vobarray
;
3927 staticpro (&initial_obarray
);
3929 Qunbound
= Fmake_symbol (build_pure_c_string ("unbound"));
3930 /* Set temporary dummy values to Qnil and Vpurify_flag to satisfy the
3931 NILP (Vpurify_flag) check in intern_c_string. */
3932 Qnil
= make_number (-1); Vpurify_flag
= make_number (1);
3933 Qnil
= intern_c_string ("nil");
3935 /* Fmake_symbol inits fields of new symbols with Qunbound and Qnil,
3936 so those two need to be fixed manually. */
3937 SET_SYMBOL_VAL (XSYMBOL (Qunbound
), Qunbound
);
3938 set_symbol_function (Qunbound
, Qunbound
);
3939 set_symbol_plist (Qunbound
, Qnil
);
3940 SET_SYMBOL_VAL (XSYMBOL (Qnil
), Qnil
);
3941 XSYMBOL (Qnil
)->constant
= 1;
3942 XSYMBOL (Qnil
)->declared_special
= 1;
3943 set_symbol_plist (Qnil
, Qnil
);
3945 Qt
= intern_c_string ("t");
3946 SET_SYMBOL_VAL (XSYMBOL (Qt
), Qt
);
3947 XSYMBOL (Qnil
)->declared_special
= 1;
3948 XSYMBOL (Qt
)->constant
= 1;
3950 /* Qt is correct even if CANNOT_DUMP. loadup.el will set to nil at end. */
3953 DEFSYM (Qvariable_documentation
, "variable-documentation");
3955 read_buffer
= xmalloc (size
);
3956 read_buffer_size
= size
;
3960 defsubr (struct Lisp_Subr
*sname
)
3962 Lisp_Object sym
, tem
;
3963 sym
= intern_c_string (sname
->symbol_name
);
3964 XSETTYPED_PVECTYPE (sname
, size
, PVEC_SUBR
);
3965 XSETSUBR (tem
, sname
);
3966 set_symbol_function (sym
, tem
);
3969 #ifdef NOTDEF /* Use fset in subr.el now! */
3971 defalias (struct Lisp_Subr
*sname
, char *string
)
3974 sym
= intern (string
);
3975 XSETSUBR (XSYMBOL (sym
)->function
, sname
);
3979 /* Define an "integer variable"; a symbol whose value is forwarded to a
3980 C variable of type EMACS_INT. Sample call (with "xx" to fool make-docfile):
3981 DEFxxVAR_INT ("emacs-priority", &emacs_priority, "Documentation"); */
3983 defvar_int (struct Lisp_Intfwd
*i_fwd
,
3984 const char *namestring
, EMACS_INT
*address
)
3987 sym
= intern_c_string (namestring
);
3988 i_fwd
->type
= Lisp_Fwd_Int
;
3989 i_fwd
->intvar
= address
;
3990 XSYMBOL (sym
)->declared_special
= 1;
3991 XSYMBOL (sym
)->redirect
= SYMBOL_FORWARDED
;
3992 SET_SYMBOL_FWD (XSYMBOL (sym
), (union Lisp_Fwd
*)i_fwd
);
3995 /* Similar but define a variable whose value is t if address contains 1,
3996 nil if address contains 0. */
3998 defvar_bool (struct Lisp_Boolfwd
*b_fwd
,
3999 const char *namestring
, bool *address
)
4002 sym
= intern_c_string (namestring
);
4003 b_fwd
->type
= Lisp_Fwd_Bool
;
4004 b_fwd
->boolvar
= address
;
4005 XSYMBOL (sym
)->declared_special
= 1;
4006 XSYMBOL (sym
)->redirect
= SYMBOL_FORWARDED
;
4007 SET_SYMBOL_FWD (XSYMBOL (sym
), (union Lisp_Fwd
*)b_fwd
);
4008 Vbyte_boolean_vars
= Fcons (sym
, Vbyte_boolean_vars
);
4011 /* Similar but define a variable whose value is the Lisp Object stored
4012 at address. Two versions: with and without gc-marking of the C
4013 variable. The nopro version is used when that variable will be
4014 gc-marked for some other reason, since marking the same slot twice
4015 can cause trouble with strings. */
4017 defvar_lisp_nopro (struct Lisp_Objfwd
*o_fwd
,
4018 const char *namestring
, Lisp_Object
*address
)
4021 sym
= intern_c_string (namestring
);
4022 o_fwd
->type
= Lisp_Fwd_Obj
;
4023 o_fwd
->objvar
= address
;
4024 XSYMBOL (sym
)->declared_special
= 1;
4025 XSYMBOL (sym
)->redirect
= SYMBOL_FORWARDED
;
4026 SET_SYMBOL_FWD (XSYMBOL (sym
), (union Lisp_Fwd
*)o_fwd
);
4030 defvar_lisp (struct Lisp_Objfwd
*o_fwd
,
4031 const char *namestring
, Lisp_Object
*address
)
4033 defvar_lisp_nopro (o_fwd
, namestring
, address
);
4034 staticpro (address
);
4037 /* Similar but define a variable whose value is the Lisp Object stored
4038 at a particular offset in the current kboard object. */
4041 defvar_kboard (struct Lisp_Kboard_Objfwd
*ko_fwd
,
4042 const char *namestring
, int offset
)
4045 sym
= intern_c_string (namestring
);
4046 ko_fwd
->type
= Lisp_Fwd_Kboard_Obj
;
4047 ko_fwd
->offset
= offset
;
4048 XSYMBOL (sym
)->declared_special
= 1;
4049 XSYMBOL (sym
)->redirect
= SYMBOL_FORWARDED
;
4050 SET_SYMBOL_FWD (XSYMBOL (sym
), (union Lisp_Fwd
*)ko_fwd
);
4053 /* Check that the elements of Vload_path exist. */
4056 load_path_check (void)
4058 Lisp_Object path_tail
;
4060 /* The only elements that might not exist are those from
4061 PATH_LOADSEARCH, EMACSLOADPATH. Anything else is only added if
4063 for (path_tail
= Vload_path
; !NILP (path_tail
); path_tail
= XCDR (path_tail
))
4065 Lisp_Object dirfile
;
4066 dirfile
= Fcar (path_tail
);
4067 if (STRINGP (dirfile
))
4069 dirfile
= Fdirectory_file_name (dirfile
);
4070 if (access (SSDATA (dirfile
), 0) < 0)
4071 dir_warning ("Warning: Lisp directory `%s' does not exist.\n",
4077 /* Record the value of load-path used at the start of dumping
4078 so we can see if the site changed it later during dumping. */
4079 static Lisp_Object dump_path
;
4081 /* Compute the default Vload_path, with the following logic:
4083 use EMACSLOADPATH env-var if set; otherwise use PATH_LOADSEARCH,
4084 prepending PATH_SITELOADSEARCH unless --no-site-lisp.
4085 The remainder is what happens when dumping works:
4086 If purify-flag (ie dumping) just use PATH_DUMPLOADSEARCH.
4087 Otherwise use EMACSLOADPATH if set, else PATH_LOADSEARCH.
4089 If !initialized, then just set both Vload_path and dump_path.
4090 If initialized, then if Vload_path != dump_path, do nothing.
4091 (Presumably the load-path has already been changed by something.
4092 This can only be from a site-load file during dumping,
4093 or because EMACSLOADPATH is set.)
4094 If Vinstallation_directory is not nil (ie, running uninstalled):
4095 If installation-dir/lisp exists and not already a member,
4096 we must be running uninstalled. Reset the load-path
4097 to just installation-dir/lisp. (The default PATH_LOADSEARCH
4098 refers to the eventual installation directories. Since we
4099 are not yet installed, we should not use them, even if they exist.)
4100 If installation-dir/lisp does not exist, just add dump_path at the
4102 Add installation-dir/leim (if exists and not already a member) at the front.
4103 Add installation-dir/site-lisp (if !no_site_lisp, and exists
4104 and not already a member) at the front.
4105 If installation-dir != source-dir (ie running an uninstalled,
4106 out-of-tree build) AND install-dir/src/Makefile exists BUT
4107 install-dir/src/Makefile.in does NOT exist (this is a sanity
4108 check), then repeat the above steps for source-dir/lisp,
4110 Finally, add the site-lisp directories at the front (if !no_site_lisp).
4120 const char *loadpath
= ns_load_path ();
4123 normal
= PATH_LOADSEARCH
;
4125 Vload_path
= decode_env_path ("EMACSLOADPATH", loadpath
? loadpath
: normal
);
4127 Vload_path
= decode_env_path ("EMACSLOADPATH", normal
);
4132 /* FIXME CANNOT_DUMP platforms should get source-dir/lisp etc added
4133 to their load-path too, AFAICS. I don't think we can tell the
4134 difference between initialized and !initialized in this case,
4135 so we'll have to do it unconditionally when Vinstallation_directory
4137 if (!no_site_lisp
&& !egetenv ("EMACSLOADPATH"))
4139 Lisp_Object sitelisp
;
4140 sitelisp
= decode_env_path (0, PATH_SITELOADSEARCH
);
4141 if (! NILP (sitelisp
)) Vload_path
= nconc2 (sitelisp
, Vload_path
);
4143 #else /* !CANNOT_DUMP */
4144 if (NILP (Vpurify_flag
))
4146 normal
= PATH_LOADSEARCH
;
4147 /* If the EMACSLOADPATH environment variable is set, use its value.
4148 This doesn't apply if we're dumping. */
4149 if (egetenv ("EMACSLOADPATH"))
4150 Vload_path
= decode_env_path ("EMACSLOADPATH", normal
);
4153 normal
= PATH_DUMPLOADSEARCH
;
4155 /* In a dumped Emacs, we normally reset the value of Vload_path using
4156 PATH_LOADSEARCH, since the value that was dumped uses lisp/ in
4157 the source directory, instead of the path of the installed elisp
4158 libraries. However, if it appears that Vload_path has already been
4159 changed from the default that was saved before dumping, don't
4160 change it further. Changes can only be due to EMACSLOADPATH, or
4161 site-lisp files that were processed during dumping. */
4164 if (NILP (Fequal (dump_path
, Vload_path
)))
4166 /* Do not make any changes, just check the elements exist. */
4167 /* Note: --no-site-lisp is ignored.
4168 I don't know what to do about this. */
4174 const char *loadpath
= ns_load_path ();
4175 Vload_path
= decode_env_path (0, loadpath
? loadpath
: normal
);
4177 Vload_path
= decode_env_path (0, normal
);
4179 if (!NILP (Vinstallation_directory
))
4181 Lisp_Object tem
, tem1
;
4183 /* Add to the path the lisp subdir of the installation
4184 dir, if it exists. Note: in out-of-tree builds,
4185 this directory is empty save for Makefile. */
4186 tem
= Fexpand_file_name (build_string ("lisp"),
4187 Vinstallation_directory
);
4188 tem1
= Ffile_exists_p (tem
);
4191 if (NILP (Fmember (tem
, Vload_path
)))
4193 /* We are running uninstalled. The default load-path
4194 points to the eventual installed lisp, leim
4195 directories. We should not use those now, even
4196 if they exist, so start over from a clean slate. */
4197 Vload_path
= Fcons (tem
, Qnil
);
4201 /* That dir doesn't exist, so add the build-time
4202 Lisp dirs instead. */
4203 Vload_path
= nconc2 (Vload_path
, dump_path
);
4205 /* Add leim under the installation dir, if it exists. */
4206 tem
= Fexpand_file_name (build_string ("leim"),
4207 Vinstallation_directory
);
4208 tem1
= Ffile_exists_p (tem
);
4211 if (NILP (Fmember (tem
, Vload_path
)))
4212 Vload_path
= Fcons (tem
, Vload_path
);
4215 /* Add site-lisp under the installation dir, if it exists. */
4218 tem
= Fexpand_file_name (build_string ("site-lisp"),
4219 Vinstallation_directory
);
4220 tem1
= Ffile_exists_p (tem
);
4223 if (NILP (Fmember (tem
, Vload_path
)))
4224 Vload_path
= Fcons (tem
, Vload_path
);
4228 /* If Emacs was not built in the source directory,
4229 and it is run from where it was built, add to load-path
4230 the lisp, leim and site-lisp dirs under that directory. */
4232 if (NILP (Fequal (Vinstallation_directory
, Vsource_directory
)))
4236 tem
= Fexpand_file_name (build_string ("src/Makefile"),
4237 Vinstallation_directory
);
4238 tem1
= Ffile_exists_p (tem
);
4240 /* Don't be fooled if they moved the entire source tree
4241 AFTER dumping Emacs. If the build directory is indeed
4242 different from the source dir, src/Makefile.in and
4243 src/Makefile will not be found together. */
4244 tem
= Fexpand_file_name (build_string ("src/Makefile.in"),
4245 Vinstallation_directory
);
4246 tem2
= Ffile_exists_p (tem
);
4247 if (!NILP (tem1
) && NILP (tem2
))
4249 tem
= Fexpand_file_name (build_string ("lisp"),
4252 if (NILP (Fmember (tem
, Vload_path
)))
4253 Vload_path
= Fcons (tem
, Vload_path
);
4255 tem
= Fexpand_file_name (build_string ("leim"),
4258 if (NILP (Fmember (tem
, Vload_path
)))
4259 Vload_path
= Fcons (tem
, Vload_path
);
4263 tem
= Fexpand_file_name (build_string ("site-lisp"),
4265 tem1
= Ffile_exists_p (tem
);
4268 if (NILP (Fmember (tem
, Vload_path
)))
4269 Vload_path
= Fcons (tem
, Vload_path
);
4273 } /* Vinstallation_directory != Vsource_directory */
4275 } /* if Vinstallation_directory */
4277 /* Check before adding the site-lisp directories.
4278 The install should have created them, but they are not
4279 required, so no need to warn if they are absent.
4280 Or we might be running before installation. */
4283 /* Add the site-lisp directories at the front. */
4286 Lisp_Object sitelisp
;
4287 sitelisp
= decode_env_path (0, PATH_SITELOADSEARCH
);
4288 if (! NILP (sitelisp
)) Vload_path
= nconc2 (sitelisp
, Vload_path
);
4290 } /* if dump_path == Vload_path */
4292 else /* !initialized */
4294 /* NORMAL refers to PATH_DUMPLOADSEARCH, ie the lisp dir in the
4295 source directory. We used to add ../lisp (ie the lisp dir in
4296 the build directory) at the front here, but that caused trouble
4297 because it was copied from dump_path into Vload_path, above,
4298 when Vinstallation_directory was non-nil. It should not be
4299 necessary, since in out of tree builds lisp/ is empty, save
4301 Vload_path
= decode_env_path (0, normal
);
4302 dump_path
= Vload_path
;
4303 /* No point calling load_path_check; load-path only contains essential
4304 elements from the source directory at this point. They cannot
4305 be missing unless something went extremely (and improbably)
4306 wrong, in which case the build will fail in obvious ways. */
4308 #endif /* !CANNOT_DUMP */
4312 load_in_progress
= 0;
4313 Vload_file_name
= Qnil
;
4315 load_descriptor_list
= Qnil
;
4317 Vstandard_input
= Qt
;
4318 Vloads_in_progress
= Qnil
;
4321 /* Print a warning, using format string FORMAT, that directory DIRNAME
4322 does not exist. Print it on stderr and put it in *Messages*. */
4325 dir_warning (const char *format
, Lisp_Object dirname
)
4327 fprintf (stderr
, format
, SDATA (dirname
));
4329 /* Don't log the warning before we've initialized!! */
4333 char *buffer
= SAFE_ALLOCA (SBYTES (dirname
)
4334 + strlen (format
) - (sizeof "%s" - 1) + 1);
4335 ptrdiff_t message_len
= esprintf (buffer
, format
, SDATA (dirname
));
4336 message_dolog (buffer
, message_len
, 0, STRING_MULTIBYTE (dirname
));
4342 syms_of_lread (void)
4345 defsubr (&Sread_from_string
);
4347 defsubr (&Sintern_soft
);
4348 defsubr (&Sunintern
);
4349 defsubr (&Sget_load_suffixes
);
4351 defsubr (&Seval_buffer
);
4352 defsubr (&Seval_region
);
4353 defsubr (&Sread_char
);
4354 defsubr (&Sread_char_exclusive
);
4355 defsubr (&Sread_event
);
4356 defsubr (&Sget_file_char
);
4357 defsubr (&Smapatoms
);
4358 defsubr (&Slocate_file_internal
);
4360 DEFVAR_LISP ("obarray", Vobarray
,
4361 doc
: /* Symbol table for use by `intern' and `read'.
4362 It is a vector whose length ought to be prime for best results.
4363 The vector's contents don't make sense if examined from Lisp programs;
4364 to find all the symbols in an obarray, use `mapatoms'. */);
4366 DEFVAR_LISP ("values", Vvalues
,
4367 doc
: /* List of values of all expressions which were read, evaluated and printed.
4368 Order is reverse chronological. */);
4369 XSYMBOL (intern ("values"))->declared_special
= 0;
4371 DEFVAR_LISP ("standard-input", Vstandard_input
,
4372 doc
: /* Stream for read to get input from.
4373 See documentation of `read' for possible values. */);
4374 Vstandard_input
= Qt
;
4376 DEFVAR_LISP ("read-with-symbol-positions", Vread_with_symbol_positions
,
4377 doc
: /* If non-nil, add position of read symbols to `read-symbol-positions-list'.
4379 If this variable is a buffer, then only forms read from that buffer
4380 will be added to `read-symbol-positions-list'.
4381 If this variable is t, then all read forms will be added.
4382 The effect of all other values other than nil are not currently
4383 defined, although they may be in the future.
4385 The positions are relative to the last call to `read' or
4386 `read-from-string'. It is probably a bad idea to set this variable at
4387 the toplevel; bind it instead. */);
4388 Vread_with_symbol_positions
= Qnil
;
4390 DEFVAR_LISP ("read-symbol-positions-list", Vread_symbol_positions_list
,
4391 doc
: /* A list mapping read symbols to their positions.
4392 This variable is modified during calls to `read' or
4393 `read-from-string', but only when `read-with-symbol-positions' is
4396 Each element of the list looks like (SYMBOL . CHAR-POSITION), where
4397 CHAR-POSITION is an integer giving the offset of that occurrence of the
4398 symbol from the position where `read' or `read-from-string' started.
4400 Note that a symbol will appear multiple times in this list, if it was
4401 read multiple times. The list is in the same order as the symbols
4403 Vread_symbol_positions_list
= Qnil
;
4405 DEFVAR_LISP ("read-circle", Vread_circle
,
4406 doc
: /* Non-nil means read recursive structures using #N= and #N# syntax. */);
4409 DEFVAR_LISP ("load-path", Vload_path
,
4410 doc
: /* List of directories to search for files to load.
4411 Each element is a string (directory name) or nil (try default directory).
4412 Initialized based on EMACSLOADPATH environment variable, if any,
4413 otherwise to default specified by file `epaths.h' when Emacs was built. */);
4415 DEFVAR_LISP ("load-suffixes", Vload_suffixes
,
4416 doc
: /* List of suffixes for (compiled or source) Emacs Lisp files.
4417 This list should not include the empty string.
4418 `load' and related functions try to append these suffixes, in order,
4419 to the specified file name if a Lisp suffix is allowed or required. */);
4420 Vload_suffixes
= Fcons (build_pure_c_string (".elc"),
4421 Fcons (build_pure_c_string (".el"), Qnil
));
4422 DEFVAR_LISP ("load-file-rep-suffixes", Vload_file_rep_suffixes
,
4423 doc
: /* List of suffixes that indicate representations of \
4425 This list should normally start with the empty string.
4427 Enabling Auto Compression mode appends the suffixes in
4428 `jka-compr-load-suffixes' to this list and disabling Auto Compression
4429 mode removes them again. `load' and related functions use this list to
4430 determine whether they should look for compressed versions of a file
4431 and, if so, which suffixes they should try to append to the file name
4432 in order to do so. However, if you want to customize which suffixes
4433 the loading functions recognize as compression suffixes, you should
4434 customize `jka-compr-load-suffixes' rather than the present variable. */);
4435 Vload_file_rep_suffixes
= Fcons (empty_unibyte_string
, Qnil
);
4437 DEFVAR_BOOL ("load-in-progress", load_in_progress
,
4438 doc
: /* Non-nil if inside of `load'. */);
4439 DEFSYM (Qload_in_progress
, "load-in-progress");
4441 DEFVAR_LISP ("after-load-alist", Vafter_load_alist
,
4442 doc
: /* An alist of expressions to be evalled when particular files are loaded.
4443 Each element looks like (REGEXP-OR-FEATURE FORMS...).
4445 REGEXP-OR-FEATURE is either a regular expression to match file names, or
4446 a symbol \(a feature name).
4448 When `load' is run and the file-name argument matches an element's
4449 REGEXP-OR-FEATURE, or when `provide' is run and provides the symbol
4450 REGEXP-OR-FEATURE, the FORMS in the element are executed.
4452 An error in FORMS does not undo the load, but does prevent execution of
4453 the rest of the FORMS. */);
4454 Vafter_load_alist
= Qnil
;
4456 DEFVAR_LISP ("load-history", Vload_history
,
4457 doc
: /* Alist mapping loaded file names to symbols and features.
4458 Each alist element should be a list (FILE-NAME ENTRIES...), where
4459 FILE-NAME is the name of a file that has been loaded into Emacs.
4460 The file name is absolute and true (i.e. it doesn't contain symlinks).
4461 As an exception, one of the alist elements may have FILE-NAME nil,
4462 for symbols and features not associated with any file.
4464 The remaining ENTRIES in the alist element describe the functions and
4465 variables defined in that file, the features provided, and the
4466 features required. Each entry has the form `(provide . FEATURE)',
4467 `(require . FEATURE)', `(defun . FUNCTION)', `(autoload . SYMBOL)',
4468 `(defface . SYMBOL)', or `(t . SYMBOL)'. Entries like `(t . SYMBOL)'
4469 may precede a `(defun . FUNCTION)' entry, and means that SYMBOL was an
4470 autoload before this file redefined it as a function. In addition,
4471 entries may also be single symbols, which means that SYMBOL was
4472 defined by `defvar' or `defconst'.
4474 During preloading, the file name recorded is relative to the main Lisp
4475 directory. These file names are converted to absolute at startup. */);
4476 Vload_history
= Qnil
;
4478 DEFVAR_LISP ("load-file-name", Vload_file_name
,
4479 doc
: /* Full name of file being loaded by `load'. */);
4480 Vload_file_name
= Qnil
;
4482 DEFVAR_LISP ("user-init-file", Vuser_init_file
,
4483 doc
: /* File name, including directory, of user's initialization file.
4484 If the file loaded had extension `.elc', and the corresponding source file
4485 exists, this variable contains the name of source file, suitable for use
4486 by functions like `custom-save-all' which edit the init file.
4487 While Emacs loads and evaluates the init file, value is the real name
4488 of the file, regardless of whether or not it has the `.elc' extension. */);
4489 Vuser_init_file
= Qnil
;
4491 DEFVAR_LISP ("current-load-list", Vcurrent_load_list
,
4492 doc
: /* Used for internal purposes by `load'. */);
4493 Vcurrent_load_list
= Qnil
;
4495 DEFVAR_LISP ("load-read-function", Vload_read_function
,
4496 doc
: /* Function used by `load' and `eval-region' for reading expressions.
4497 The default is nil, which means use the function `read'. */);
4498 Vload_read_function
= Qnil
;
4500 DEFVAR_LISP ("load-source-file-function", Vload_source_file_function
,
4501 doc
: /* Function called in `load' for loading an Emacs Lisp source file.
4502 This function is for doing code conversion before reading the source file.
4503 If nil, loading is done without any code conversion.
4504 Arguments are FULLNAME, FILE, NOERROR, NOMESSAGE, where
4505 FULLNAME is the full name of FILE.
4506 See `load' for the meaning of the remaining arguments. */);
4507 Vload_source_file_function
= Qnil
;
4509 DEFVAR_BOOL ("load-force-doc-strings", load_force_doc_strings
,
4510 doc
: /* Non-nil means `load' should force-load all dynamic doc strings.
4511 This is useful when the file being loaded is a temporary copy. */);
4512 load_force_doc_strings
= 0;
4514 DEFVAR_BOOL ("load-convert-to-unibyte", load_convert_to_unibyte
,
4515 doc
: /* Non-nil means `read' converts strings to unibyte whenever possible.
4516 This is normally bound by `load' and `eval-buffer' to control `read',
4517 and is not meant for users to change. */);
4518 load_convert_to_unibyte
= 0;
4520 DEFVAR_LISP ("source-directory", Vsource_directory
,
4521 doc
: /* Directory in which Emacs sources were found when Emacs was built.
4522 You cannot count on them to still be there! */);
4524 = Fexpand_file_name (build_string ("../"),
4525 Fcar (decode_env_path (0, PATH_DUMPLOADSEARCH
)));
4527 DEFVAR_LISP ("preloaded-file-list", Vpreloaded_file_list
,
4528 doc
: /* List of files that were preloaded (when dumping Emacs). */);
4529 Vpreloaded_file_list
= Qnil
;
4531 DEFVAR_LISP ("byte-boolean-vars", Vbyte_boolean_vars
,
4532 doc
: /* List of all DEFVAR_BOOL variables, used by the byte code optimizer. */);
4533 Vbyte_boolean_vars
= Qnil
;
4535 DEFVAR_BOOL ("load-dangerous-libraries", load_dangerous_libraries
,
4536 doc
: /* Non-nil means load dangerous compiled Lisp files.
4537 Some versions of XEmacs use different byte codes than Emacs. These
4538 incompatible byte codes can make Emacs crash when it tries to execute
4540 load_dangerous_libraries
= 0;
4542 DEFVAR_BOOL ("force-load-messages", force_load_messages
,
4543 doc
: /* Non-nil means force printing messages when loading Lisp files.
4544 This overrides the value of the NOMESSAGE argument to `load'. */);
4545 force_load_messages
= 0;
4547 DEFVAR_LISP ("bytecomp-version-regexp", Vbytecomp_version_regexp
,
4548 doc
: /* Regular expression matching safe to load compiled Lisp files.
4549 When Emacs loads a compiled Lisp file, it reads the first 512 bytes
4550 from the file, and matches them against this regular expression.
4551 When the regular expression matches, the file is considered to be safe
4552 to load. See also `load-dangerous-libraries'. */);
4553 Vbytecomp_version_regexp
4554 = build_pure_c_string ("^;;;.\\(in Emacs version\\|bytecomp version FSF\\)");
4556 DEFSYM (Qlexical_binding
, "lexical-binding");
4557 DEFVAR_LISP ("lexical-binding", Vlexical_binding
,
4558 doc
: /* Whether to use lexical binding when evaluating code.
4559 Non-nil means that the code in the current buffer should be evaluated
4560 with lexical binding.
4561 This variable is automatically set from the file variables of an
4562 interpreted Lisp file read using `load'. Unlike other file local
4563 variables, this must be set in the first line of a file. */);
4564 Vlexical_binding
= Qnil
;
4565 Fmake_variable_buffer_local (Qlexical_binding
);
4567 DEFVAR_LISP ("eval-buffer-list", Veval_buffer_list
,
4568 doc
: /* List of buffers being read from by calls to `eval-buffer' and `eval-region'. */);
4569 Veval_buffer_list
= Qnil
;
4571 DEFVAR_LISP ("old-style-backquotes", Vold_style_backquotes
,
4572 doc
: /* Set to non-nil when `read' encounters an old-style backquote. */);
4573 Vold_style_backquotes
= Qnil
;
4574 DEFSYM (Qold_style_backquotes
, "old-style-backquotes");
4576 /* Vsource_directory was initialized in init_lread. */
4578 load_descriptor_list
= Qnil
;
4579 staticpro (&load_descriptor_list
);
4581 DEFSYM (Qcurrent_load_list
, "current-load-list");
4582 DEFSYM (Qstandard_input
, "standard-input");
4583 DEFSYM (Qread_char
, "read-char");
4584 DEFSYM (Qget_file_char
, "get-file-char");
4585 DEFSYM (Qget_emacs_mule_file_char
, "get-emacs-mule-file-char");
4586 DEFSYM (Qload_force_doc_strings
, "load-force-doc-strings");
4588 DEFSYM (Qbackquote
, "`");
4589 DEFSYM (Qcomma
, ",");
4590 DEFSYM (Qcomma_at
, ",@");
4591 DEFSYM (Qcomma_dot
, ",.");
4593 DEFSYM (Qinhibit_file_name_operation
, "inhibit-file-name-operation");
4594 DEFSYM (Qascii_character
, "ascii-character");
4595 DEFSYM (Qfunction
, "function");
4596 DEFSYM (Qload
, "load");
4597 DEFSYM (Qload_file_name
, "load-file-name");
4598 DEFSYM (Qeval_buffer_list
, "eval-buffer-list");
4599 DEFSYM (Qfile_truename
, "file-truename");
4600 DEFSYM (Qdir_ok
, "dir-ok");
4601 DEFSYM (Qdo_after_load_evaluation
, "do-after-load-evaluation");
4603 staticpro (&dump_path
);
4605 staticpro (&read_objects
);
4606 read_objects
= Qnil
;
4607 staticpro (&seen_list
);
4610 Vloads_in_progress
= Qnil
;
4611 staticpro (&Vloads_in_progress
);
4613 DEFSYM (Qhash_table
, "hash-table");
4614 DEFSYM (Qdata
, "data");
4615 DEFSYM (Qtest
, "test");
4616 DEFSYM (Qsize
, "size");
4617 DEFSYM (Qweakness
, "weakness");
4618 DEFSYM (Qrehash_size
, "rehash-size");
4619 DEFSYM (Qrehash_threshold
, "rehash-threshold");