1 /* Lisp parsing and input streams.
2 Copyright (C) 1985, 1986, 1987, 1988, 1989,
3 1993, 1994, 1995 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs; see the file COPYING. If not, write to
19 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
24 #include <sys/types.h>
35 #include "termhooks.h"
39 #include <sys/inode.h>
46 #ifdef LISP_FLOAT_TYPE
53 /* These are redefined (correctly, but differently) in values.h. */
60 #endif /* LISP_FLOAT_TYPE */
68 Lisp_Object Qread_char
, Qget_file_char
, Qstandard_input
, Qcurrent_load_list
;
69 Lisp_Object Qvariable_documentation
, Vvalues
, Vstandard_input
, Vafter_load_alist
;
70 Lisp_Object Qascii_character
, Qload
, Qload_file_name
;
72 extern Lisp_Object Qevent_symbol_element_mask
;
74 /* non-zero if inside `load' */
77 /* Search path for files to be loaded. */
78 Lisp_Object Vload_path
;
80 /* This is the user-visible association list that maps features to
81 lists of defs in their load files. */
82 Lisp_Object Vload_history
;
84 /* This is used to build the load history. */
85 Lisp_Object Vcurrent_load_list
;
87 /* Name of file actually being read by `load'. */
88 Lisp_Object Vload_file_name
;
90 /* Function to use for reading, in `load' and friends. */
91 Lisp_Object Vload_read_function
;
93 /* List of descriptors now open for Fload. */
94 static Lisp_Object load_descriptor_list
;
96 /* File for get_file_char to read from. Use by load */
97 static FILE *instream
;
99 /* When nonzero, read conses in pure space */
100 static int read_pure
;
102 /* For use within read-from-string (this reader is non-reentrant!!) */
103 static int read_from_string_index
;
104 static int read_from_string_limit
;
106 /* Handle unreading and rereading of characters.
107 Write READCHAR to read a character,
108 UNREAD(c) to unread c to be read again. */
110 #define READCHAR readchar (readcharfun)
111 #define UNREAD(c) unreadchar (readcharfun, c)
114 readchar (readcharfun
)
115 Lisp_Object readcharfun
;
118 register struct buffer
*inbuffer
;
119 register int c
, mpos
;
121 if (BUFFERP (readcharfun
))
123 inbuffer
= XBUFFER (readcharfun
);
125 if (BUF_PT (inbuffer
) >= BUF_ZV (inbuffer
))
127 c
= *(unsigned char *) BUF_CHAR_ADDRESS (inbuffer
, BUF_PT (inbuffer
));
128 SET_BUF_PT (inbuffer
, BUF_PT (inbuffer
) + 1);
132 if (MARKERP (readcharfun
))
134 inbuffer
= XMARKER (readcharfun
)->buffer
;
136 mpos
= marker_position (readcharfun
);
138 if (mpos
> BUF_ZV (inbuffer
) - 1)
140 c
= *(unsigned char *) BUF_CHAR_ADDRESS (inbuffer
, mpos
);
141 if (mpos
!= BUF_GPT (inbuffer
))
142 XMARKER (readcharfun
)->bufpos
++;
144 Fset_marker (readcharfun
, make_number (mpos
+ 1),
145 Fmarker_buffer (readcharfun
));
148 if (EQ (readcharfun
, Qget_file_char
))
152 /* Interrupted reads have been observed while reading over the network */
153 while (c
== EOF
&& ferror (instream
) && errno
== EINTR
)
162 if (STRINGP (readcharfun
))
165 /* This used to be return of a conditional expression,
166 but that truncated -1 to a char on VMS. */
167 if (read_from_string_index
< read_from_string_limit
)
168 c
= XSTRING (readcharfun
)->data
[read_from_string_index
++];
174 tem
= call0 (readcharfun
);
181 /* Unread the character C in the way appropriate for the stream READCHARFUN.
182 If the stream is a user function, call it with the char as argument. */
185 unreadchar (readcharfun
, c
)
186 Lisp_Object readcharfun
;
190 /* Don't back up the pointer if we're unreading the end-of-input mark,
191 since readchar didn't advance it when we read it. */
193 else if (BUFFERP (readcharfun
))
195 if (XBUFFER (readcharfun
) == current_buffer
)
198 SET_BUF_PT (XBUFFER (readcharfun
), BUF_PT (XBUFFER (readcharfun
)) - 1);
200 else if (MARKERP (readcharfun
))
201 XMARKER (readcharfun
)->bufpos
--;
202 else if (STRINGP (readcharfun
))
203 read_from_string_index
--;
204 else if (EQ (readcharfun
, Qget_file_char
))
205 ungetc (c
, instream
);
207 call1 (readcharfun
, make_number (c
));
210 static Lisp_Object
read0 (), read1 (), read_list (), read_vector ();
212 /* get a character from the tty */
214 extern Lisp_Object
read_char ();
216 /* Read input events until we get one that's acceptable for our purposes.
218 If NO_SWITCH_FRAME is non-zero, switch-frame events are stashed
219 until we get a character we like, and then stuffed into
222 If ASCII_REQUIRED is non-zero, we check function key events to see
223 if the unmodified version of the symbol has a Qascii_character
224 property, and use that character, if present.
226 If ERROR_NONASCII is non-zero, we signal an error if the input we
227 get isn't an ASCII character with modifiers. If it's zero but
228 ASCII_REQUIRED is non-zero, we just re-read until we get an ASCII
231 read_filtered_event (no_switch_frame
, ascii_required
, error_nonascii
)
232 int no_switch_frame
, ascii_required
, error_nonascii
;
235 return make_number (getchar ());
237 register Lisp_Object val
, delayed_switch_frame
;
239 delayed_switch_frame
= Qnil
;
241 /* Read until we get an acceptable event. */
243 val
= read_char (0, 0, 0, Qnil
, 0);
248 /* switch-frame events are put off until after the next ASCII
249 character. This is better than signalling an error just because
250 the last characters were typed to a separate minibuffer frame,
251 for example. Eventually, some code which can deal with
252 switch-frame events will read it and process it. */
254 && EVENT_HAS_PARAMETERS (val
)
255 && EQ (EVENT_HEAD (val
), Qswitch_frame
))
257 delayed_switch_frame
= val
;
263 /* Convert certain symbols to their ASCII equivalents. */
266 Lisp_Object tem
, tem1
, tem2
;
267 tem
= Fget (val
, Qevent_symbol_element_mask
);
270 tem1
= Fget (Fcar (tem
), Qascii_character
);
271 /* Merge this symbol's modifier bits
272 with the ASCII equivalent of its basic code. */
274 XSETFASTINT (val
, XINT (tem1
) | XINT (Fcar (Fcdr (tem
))));
278 /* If we don't have a character now, deal with it appropriately. */
283 Vunread_command_events
= Fcons (val
, Qnil
);
284 error ("Non-character input-event");
291 if (! NILP (delayed_switch_frame
))
292 unread_switch_frame
= delayed_switch_frame
;
298 DEFUN ("read-char", Fread_char
, Sread_char
, 0, 0, 0,
299 "Read a character from the command input (keyboard or macro).\n\
300 It is returned as a number.\n\
301 If the user generates an event which is not a character (i.e. a mouse\n\
302 click or function key event), `read-char' signals an error. As an\n\
303 exception, switch-frame events are put off until non-ASCII events can\n\
305 If you want to read non-character events, or ignore them, call\n\
306 `read-event' or `read-char-exclusive' instead.")
309 return read_filtered_event (1, 1, 1);
312 DEFUN ("read-event", Fread_event
, Sread_event
, 0, 0, 0,
313 "Read an event object from the input stream.")
316 return read_filtered_event (0, 0, 0);
319 DEFUN ("read-char-exclusive", Fread_char_exclusive
, Sread_char_exclusive
, 0, 0, 0,
320 "Read a character from the command input (keyboard or macro).\n\
321 It is returned as a number. Non character events are ignored.")
324 return read_filtered_event (1, 1, 0);
327 DEFUN ("get-file-char", Fget_file_char
, Sget_file_char
, 0, 0, 0,
328 "Don't use this yourself.")
331 register Lisp_Object val
;
332 XSETINT (val
, getc (instream
));
336 static void readevalloop ();
337 static Lisp_Object
load_unwind ();
338 static Lisp_Object
load_descriptor_unwind ();
340 DEFUN ("load", Fload
, Sload
, 1, 4, 0,
341 "Execute a file of Lisp code named FILE.\n\
342 First try FILE with `.elc' appended, then try with `.el',\n\
343 then try FILE unmodified.\n\
344 This function searches the directories in `load-path'.\n\
345 If optional second arg NOERROR is non-nil,\n\
346 report no error if FILE doesn't exist.\n\
347 Print messages at start and end of loading unless\n\
348 optional third arg NOMESSAGE is non-nil.\n\
349 If optional fourth arg NOSUFFIX is non-nil, don't try adding\n\
350 suffixes `.elc' or `.el' to the specified name FILE.\n\
351 Return t if file exists.")
352 (str
, noerror
, nomessage
, nosuffix
)
353 Lisp_Object str
, noerror
, nomessage
, nosuffix
;
355 register FILE *stream
;
356 register int fd
= -1;
357 register Lisp_Object lispstream
;
358 int count
= specpdl_ptr
- specpdl
;
362 /* 1 means inhibit the message at the beginning. */
366 char *dosmode
= "rt";
369 CHECK_STRING (str
, 0);
371 /* If file name is magic, call the handler. */
372 handler
= Ffind_file_name_handler (str
, Qload
);
374 return call5 (handler
, Qload
, str
, noerror
, nomessage
, nosuffix
);
376 /* Do this after the handler to avoid
377 the need to gcpro noerror, nomessage and nosuffix.
378 (Below here, we care only whether they are nil or not.) */
379 str
= Fsubstitute_in_file_name (str
);
381 /* Avoid weird lossage with null string as arg,
382 since it would try to load a directory as a Lisp file */
383 if (XSTRING (str
)->size
> 0)
386 fd
= openp (Vload_path
, str
, !NILP (nosuffix
) ? "" : ".elc:.el:",
395 Fsignal (Qfile_error
, Fcons (build_string ("Cannot open load file"),
401 if (!bcmp (&(XSTRING (found
)->data
[XSTRING (found
)->size
- 4]),
410 stat ((char *)XSTRING (found
)->data
, &s1
);
411 XSTRING (found
)->data
[XSTRING (found
)->size
- 1] = 0;
412 result
= stat ((char *)XSTRING (found
)->data
, &s2
);
413 if (result
>= 0 && (unsigned) s1
.st_mtime
< (unsigned) s2
.st_mtime
)
415 message ("Source file `%s' newer than byte-compiled file",
416 XSTRING (found
)->data
);
417 /* Don't immediately overwrite this message. */
421 XSTRING (found
)->data
[XSTRING (found
)->size
- 1] = 'c';
426 stream
= fopen ((char *) XSTRING (found
)->data
, dosmode
);
427 #else /* not DOS_NT */
428 stream
= fdopen (fd
, "r");
429 #endif /* not DOS_NT */
433 error ("Failure to create stdio stream for %s", XSTRING (str
)->data
);
436 if (NILP (nomessage
) && !nomessage1
)
437 message ("Loading %s...", XSTRING (str
)->data
);
440 lispstream
= Fcons (Qnil
, Qnil
);
441 XSETFASTINT (XCONS (lispstream
)->car
, (EMACS_UINT
)stream
>> 16);
442 XSETFASTINT (XCONS (lispstream
)->cdr
, (EMACS_UINT
)stream
& 0xffff);
443 record_unwind_protect (load_unwind
, lispstream
);
444 record_unwind_protect (load_descriptor_unwind
, load_descriptor_list
);
445 specbind (Qload_file_name
, found
);
447 = Fcons (make_number (fileno (stream
)), load_descriptor_list
);
449 readevalloop (Qget_file_char
, stream
, str
, Feval
, 0);
450 unbind_to (count
, Qnil
);
452 /* Run any load-hooks for this file. */
453 temp
= Fassoc (str
, Vafter_load_alist
);
455 Fprogn (Fcdr (temp
));
458 if (!noninteractive
&& NILP (nomessage
))
459 message ("Loading %s...done", XSTRING (str
)->data
);
464 load_unwind (stream
) /* used as unwind-protect function in load */
467 fclose ((FILE *) (XFASTINT (XCONS (stream
)->car
) << 16
468 | XFASTINT (XCONS (stream
)->cdr
)));
469 if (--load_in_progress
< 0) load_in_progress
= 0;
474 load_descriptor_unwind (oldlist
)
477 load_descriptor_list
= oldlist
;
481 /* Close all descriptors in use for Floads.
482 This is used when starting a subprocess. */
488 for (tail
= load_descriptor_list
; !NILP (tail
); tail
= XCONS (tail
)->cdr
)
489 close (XFASTINT (XCONS (tail
)->car
));
493 complete_filename_p (pathname
)
494 Lisp_Object pathname
;
496 register unsigned char *s
= XSTRING (pathname
)->data
;
497 return (IS_DIRECTORY_SEP (s
[0])
498 || (XSTRING (pathname
)->size
> 2
499 && IS_DEVICE_SEP (s
[1]) && IS_DIRECTORY_SEP (s
[2]))
509 /* Search for a file whose name is STR, looking in directories
510 in the Lisp list PATH, and trying suffixes from SUFFIX.
511 SUFFIX is a string containing possible suffixes separated by colons.
512 On success, returns a file descriptor. On failure, returns -1.
514 EXEC_ONLY nonzero means don't open the files,
515 just look for one that is executable. In this case,
516 returns 1 on success.
518 If STOREPTR is nonzero, it points to a slot where the name of
519 the file actually found should be stored as a Lisp string.
520 Nil is stored there on failure. */
523 openp (path
, str
, suffix
, storeptr
, exec_only
)
524 Lisp_Object path
, str
;
526 Lisp_Object
*storeptr
;
532 register char *fn
= buf
;
535 register Lisp_Object filename
;
543 if (complete_filename_p (str
))
546 for (; !NILP (path
); path
= Fcdr (path
))
550 filename
= Fexpand_file_name (str
, Fcar (path
));
551 if (!complete_filename_p (filename
))
552 /* If there are non-absolute elts in PATH (eg ".") */
553 /* Of course, this could conceivably lose if luser sets
554 default-directory to be something non-absolute... */
556 filename
= Fexpand_file_name (filename
, current_buffer
->directory
);
557 if (!complete_filename_p (filename
))
558 /* Give up on this path element! */
562 /* Calculate maximum size of any filename made from
563 this path element/specified file name and any possible suffix. */
564 want_size
= strlen (suffix
) + XSTRING (filename
)->size
+ 1;
565 if (fn_size
< want_size
)
566 fn
= (char *) alloca (fn_size
= 100 + want_size
);
570 /* Loop over suffixes. */
573 char *esuffix
= (char *) index (nsuffix
, ':');
574 int lsuffix
= esuffix
? esuffix
- nsuffix
: strlen (nsuffix
);
576 /* Concatenate path element/specified name with the suffix. */
577 strncpy (fn
, XSTRING (filename
)->data
, XSTRING (filename
)->size
);
578 fn
[XSTRING (filename
)->size
] = 0;
579 if (lsuffix
!= 0) /* Bug happens on CCI if lsuffix is 0. */
580 strncat (fn
, nsuffix
, lsuffix
);
582 /* Ignore file if it's a directory. */
583 if (stat (fn
, &st
) >= 0
584 && (st
.st_mode
& S_IFMT
) != S_IFDIR
)
586 /* Check that we can access or open it. */
588 fd
= (access (fn
, X_OK
) == 0) ? 1 : -1;
590 fd
= open (fn
, O_RDONLY
, 0);
594 /* We succeeded; return this descriptor and filename. */
596 *storeptr
= build_string (fn
);
602 /* Advance to next suffix. */
605 nsuffix
+= lsuffix
+ 1;
616 /* Merge the list we've accumulated of globals from the current input source
617 into the load_history variable. The details depend on whether
618 the source has an associated file name or not. */
621 build_load_history (stream
, source
)
625 register Lisp_Object tail
, prev
, newelt
;
626 register Lisp_Object tem
, tem2
;
627 register int foundit
, loading
;
629 /* Don't bother recording anything for preloaded files. */
630 if (!NILP (Vpurify_flag
))
633 loading
= stream
|| !NARROWED
;
635 tail
= Vload_history
;
642 /* Find the feature's previous assoc list... */
643 if (!NILP (Fequal (source
, Fcar (tem
))))
647 /* If we're loading, remove it. */
651 Vload_history
= Fcdr (tail
);
653 Fsetcdr (prev
, Fcdr (tail
));
656 /* Otherwise, cons on new symbols that are not already members. */
659 tem2
= Vcurrent_load_list
;
663 newelt
= Fcar (tem2
);
665 if (NILP (Fmemq (newelt
, tem
)))
666 Fsetcar (tail
, Fcons (Fcar (tem
),
667 Fcons (newelt
, Fcdr (tem
))));
680 /* If we're loading, cons the new assoc onto the front of load-history,
681 the most-recently-loaded position. Also do this if we didn't find
682 an existing member for the current source. */
683 if (loading
|| !foundit
)
684 Vload_history
= Fcons (Fnreverse (Vcurrent_load_list
),
689 unreadpure () /* Used as unwind-protect function in readevalloop */
696 readevalloop (readcharfun
, stream
, sourcename
, evalfun
, printflag
)
697 Lisp_Object readcharfun
;
699 Lisp_Object sourcename
;
700 Lisp_Object (*evalfun
) ();
704 register Lisp_Object val
;
705 int count
= specpdl_ptr
- specpdl
;
707 struct buffer
*b
= 0;
709 if (BUFFERP (readcharfun
))
710 b
= XBUFFER (readcharfun
);
711 else if (MARKERP (readcharfun
))
712 b
= XMARKER (readcharfun
)->buffer
;
714 specbind (Qstandard_input
, readcharfun
);
715 specbind (Qcurrent_load_list
, Qnil
);
719 LOADHIST_ATTACH (sourcename
);
723 if (b
!= 0 && NILP (b
->name
))
724 error ("Reading from killed buffer");
730 while ((c
= READCHAR
) != '\n' && c
!= -1);
735 /* Ignore whitespace here, so we can detect eof. */
736 if (c
== ' ' || c
== '\t' || c
== '\n' || c
== '\f' || c
== '\r')
739 if (!NILP (Vpurify_flag
) && c
== '(')
741 int count1
= specpdl_ptr
- specpdl
;
742 record_unwind_protect (unreadpure
, Qnil
);
743 val
= read_list (-1, readcharfun
);
744 unbind_to (count1
, Qnil
);
749 if (NILP (Vload_read_function
))
750 val
= read0 (readcharfun
);
752 val
= call1 (Vload_read_function
, readcharfun
);
755 val
= (*evalfun
) (val
);
758 Vvalues
= Fcons (val
, Vvalues
);
759 if (EQ (Vstandard_output
, Qt
))
766 build_load_history (stream
, sourcename
);
769 unbind_to (count
, Qnil
);
774 DEFUN ("eval-buffer", Feval_buffer
, Seval_buffer
, 0, 2, "",
775 "Execute the current buffer as Lisp code.\n\
776 Programs can pass two arguments, BUFFER and PRINTFLAG.\n\
777 BUFFER is the buffer to evaluate (nil means use current buffer).\n\
778 PRINTFLAG controls printing of output:\n\
779 nil means discard it; anything else is stream for print.\n\
781 If there is no error, point does not move. If there is an error,\n\
782 point remains at the end of the last character read from the buffer.")
784 Lisp_Object bufname
, printflag
;
786 int count
= specpdl_ptr
- specpdl
;
787 Lisp_Object tem
, buf
;
790 buf
= Fcurrent_buffer ();
792 buf
= Fget_buffer (bufname
);
794 error ("No such buffer.");
796 if (NILP (printflag
))
800 specbind (Qstandard_output
, tem
);
801 record_unwind_protect (save_excursion_restore
, save_excursion_save ());
802 BUF_SET_PT (XBUFFER (buf
), BUF_BEGV (XBUFFER (buf
)));
803 readevalloop (buf
, 0, XBUFFER (buf
)->filename
, Feval
, !NILP (printflag
));
804 unbind_to (count
, Qnil
);
810 DEFUN ("eval-current-buffer", Feval_current_buffer
, Seval_current_buffer
, 0, 1, "",
811 "Execute the current buffer as Lisp code.\n\
812 Programs can pass argument PRINTFLAG which controls printing of output:\n\
813 nil means discard it; anything else is stream for print.\n\
815 If there is no error, point does not move. If there is an error,\n\
816 point remains at the end of the last character read from the buffer.")
818 Lisp_Object printflag
;
820 int count
= specpdl_ptr
- specpdl
;
821 Lisp_Object tem
, cbuf
;
823 cbuf
= Fcurrent_buffer ()
825 if (NILP (printflag
))
829 specbind (Qstandard_output
, tem
);
830 record_unwind_protect (save_excursion_restore
, save_excursion_save ());
832 readevalloop (cbuf
, 0, XBUFFER (cbuf
)->filename
, Feval
, !NILP (printflag
));
833 return unbind_to (count
, Qnil
);
837 DEFUN ("eval-region", Feval_region
, Seval_region
, 2, 3, "r",
838 "Execute the region as Lisp code.\n\
839 When called from programs, expects two arguments,\n\
840 giving starting and ending indices in the current buffer\n\
841 of the text to be executed.\n\
842 Programs can pass third argument PRINTFLAG which controls output:\n\
843 nil means discard it; anything else is stream for printing it.\n\
845 If there is no error, point does not move. If there is an error,\n\
846 point remains at the end of the last character read from the buffer.")
848 Lisp_Object b
, e
, printflag
;
850 int count
= specpdl_ptr
- specpdl
;
851 Lisp_Object tem
, cbuf
;
853 cbuf
= Fcurrent_buffer ();
855 if (NILP (printflag
))
859 specbind (Qstandard_output
, tem
);
861 if (NILP (printflag
))
862 record_unwind_protect (save_excursion_restore
, save_excursion_save ());
863 record_unwind_protect (save_restriction_restore
, save_restriction_save ());
865 /* This both uses b and checks its type. */
867 Fnarrow_to_region (make_number (BEGV
), e
);
868 readevalloop (cbuf
, 0, XBUFFER (cbuf
)->filename
, Feval
, !NILP (printflag
));
870 return unbind_to (count
, Qnil
);
873 #endif /* standalone */
875 DEFUN ("read", Fread
, Sread
, 0, 1, 0,
876 "Read one Lisp expression as text from STREAM, return as Lisp object.\n\
877 If STREAM is nil, use the value of `standard-input' (which see).\n\
878 STREAM or the value of `standard-input' may be:\n\
879 a buffer (read from point and advance it)\n\
880 a marker (read from where it points and advance it)\n\
881 a function (call it with no arguments for each character,\n\
882 call it with a char as argument to push a char back)\n\
883 a string (takes text from string, starting at the beginning)\n\
884 t (read text line using minibuffer and use it).")
886 Lisp_Object readcharfun
;
888 extern Lisp_Object
Fread_minibuffer ();
890 if (NILP (readcharfun
))
891 readcharfun
= Vstandard_input
;
892 if (EQ (readcharfun
, Qt
))
893 readcharfun
= Qread_char
;
896 if (EQ (readcharfun
, Qread_char
))
897 return Fread_minibuffer (build_string ("Lisp expression: "), Qnil
);
900 if (STRINGP (readcharfun
))
901 return Fcar (Fread_from_string (readcharfun
, Qnil
, Qnil
));
903 return read0 (readcharfun
);
906 DEFUN ("read-from-string", Fread_from_string
, Sread_from_string
, 1, 3, 0,
907 "Read one Lisp expression which is represented as text by STRING.\n\
908 Returns a cons: (OBJECT-READ . FINAL-STRING-INDEX).\n\
909 START and END optionally delimit a substring of STRING from which to read;\n\
910 they default to 0 and (length STRING) respectively.")
912 Lisp_Object string
, start
, end
;
914 int startval
, endval
;
917 CHECK_STRING (string
,0);
920 endval
= XSTRING (string
)->size
;
922 { CHECK_NUMBER (end
,2);
924 if (endval
< 0 || endval
> XSTRING (string
)->size
)
925 args_out_of_range (string
, end
);
931 { CHECK_NUMBER (start
,1);
932 startval
= XINT (start
);
933 if (startval
< 0 || startval
> endval
)
934 args_out_of_range (string
, start
);
937 read_from_string_index
= startval
;
938 read_from_string_limit
= endval
;
940 tem
= read0 (string
);
941 return Fcons (tem
, make_number (read_from_string_index
));
944 /* Use this for recursive reads, in contexts where internal tokens
948 Lisp_Object readcharfun
;
950 register Lisp_Object val
;
953 val
= read1 (readcharfun
, &c
);
955 Fsignal (Qinvalid_read_syntax
, Fcons (make_string (&c
, 1), Qnil
));
960 static int read_buffer_size
;
961 static char *read_buffer
;
964 read_escape (readcharfun
)
965 Lisp_Object readcharfun
;
967 register int c
= READCHAR
;
994 error ("Invalid escape character syntax");
997 c
= read_escape (readcharfun
);
998 return c
| meta_modifier
;
1003 error ("Invalid escape character syntax");
1006 c
= read_escape (readcharfun
);
1007 return c
| shift_modifier
;
1012 error ("Invalid escape character syntax");
1015 c
= read_escape (readcharfun
);
1016 return c
| hyper_modifier
;
1021 error ("Invalid escape character syntax");
1024 c
= read_escape (readcharfun
);
1025 return c
| alt_modifier
;
1030 error ("Invalid escape character syntax");
1033 c
= read_escape (readcharfun
);
1034 return c
| super_modifier
;
1039 error ("Invalid escape character syntax");
1043 c
= read_escape (readcharfun
);
1044 if ((c
& 0177) == '?')
1046 /* ASCII control chars are made from letters (both cases),
1047 as well as the non-letters within 0100...0137. */
1048 else if ((c
& 0137) >= 0101 && (c
& 0137) <= 0132)
1049 return (c
& (037 | ~0177));
1050 else if ((c
& 0177) >= 0100 && (c
& 0177) <= 0137)
1051 return (c
& (037 | ~0177));
1053 return c
| ctrl_modifier
;
1063 /* An octal escape, as in ANSI C. */
1065 register int i
= c
- '0';
1066 register int count
= 0;
1069 if ((c
= READCHAR
) >= '0' && c
<= '7')
1084 /* A hex escape, as in ANSI C. */
1090 if (c
>= '0' && c
<= '9')
1095 else if ((c
>= 'a' && c
<= 'f')
1096 || (c
>= 'A' && c
<= 'F'))
1099 if (c
>= 'a' && c
<= 'f')
1118 /* If the next token is ')' or ']' or '.', we store that character
1119 in *PCH and the return value is not interesting. Else, we store
1120 zero in *PCH and we read and return one lisp object. */
1122 read1 (readcharfun
, pch
)
1123 register Lisp_Object readcharfun
;
1132 if (c
< 0) return Fsignal (Qend_of_file
, Qnil
);
1137 return read_list (0, readcharfun
);
1140 return read_vector (readcharfun
);
1153 /* Accept compiled functions at read-time so that we don't have to
1154 build them using function calls. */
1156 tmp
= read_vector (readcharfun
);
1157 return Fmake_byte_code (XVECTOR (tmp
)->size
,
1158 XVECTOR (tmp
)->contents
);
1160 #ifdef USE_TEXT_PROPERTIES
1164 struct gcpro gcpro1
;
1167 /* Read the string itself. */
1168 tmp
= read1 (readcharfun
, &ch
);
1169 if (ch
!= 0 || !STRINGP (tmp
))
1170 Fsignal (Qinvalid_read_syntax
, Fcons (make_string ("#", 1), Qnil
));
1172 /* Read the intervals and their properties. */
1175 Lisp_Object beg
, end
, plist
;
1177 beg
= read1 (readcharfun
, &ch
);
1181 end
= read1 (readcharfun
, &ch
);
1183 plist
= read1 (readcharfun
, &ch
);
1185 Fsignal (Qinvalid_read_syntax
,
1186 Fcons (build_string ("invalid string property list"),
1188 Fset_text_properties (beg
, end
, plist
, tmp
);
1194 /* #@NUMBER is used to skip NUMBER following characters.
1195 That's used in .elc files to skip over doc strings
1196 and function definitions. */
1201 /* Read a decimal integer. */
1202 while ((c
= READCHAR
) >= 0
1203 && c
>= '0' && c
<= '9')
1211 /* Skip that many characters. */
1212 for (i
= 0; i
< nskip
&& c
>= 0; i
++)
1217 return Vload_file_name
;
1220 Fsignal (Qinvalid_read_syntax
, Fcons (make_string ("#", 1), Qnil
));
1223 while ((c
= READCHAR
) >= 0 && c
!= '\n');
1228 return Fcons (Qquote
, Fcons (read0 (readcharfun
), Qnil
));
1233 register Lisp_Object val
;
1236 if (c
< 0) return Fsignal (Qend_of_file
, Qnil
);
1239 XSETINT (val
, read_escape (readcharfun
));
1248 register char *p
= read_buffer
;
1249 register char *end
= read_buffer
+ read_buffer_size
;
1253 while ((c
= READCHAR
) >= 0
1258 char *new = (char *) xrealloc (read_buffer
, read_buffer_size
*= 2);
1259 p
+= new - read_buffer
;
1260 read_buffer
+= new - read_buffer
;
1261 end
= read_buffer
+ read_buffer_size
;
1264 c
= read_escape (readcharfun
);
1265 /* c is -1 if \ newline has just been seen */
1268 if (p
== read_buffer
)
1273 /* Allow `\C- ' and `\C-?'. */
1274 if (c
== (CHAR_CTL
| ' '))
1276 else if (c
== (CHAR_CTL
| '?'))
1280 /* Move the meta bit to the right place for a string. */
1281 c
= (c
& ~CHAR_META
) | 0x80;
1283 error ("Invalid modifier in string");
1287 if (c
< 0) return Fsignal (Qend_of_file
, Qnil
);
1289 /* If purifying, and string starts with \ newline,
1290 return zero instead. This is for doc strings
1291 that we are really going to find in etc/DOC.nn.nn */
1292 if (!NILP (Vpurify_flag
) && NILP (Vdoc_file_name
) && cancel
)
1293 return make_number (0);
1296 return make_pure_string (read_buffer
, p
- read_buffer
);
1298 return make_string (read_buffer
, p
- read_buffer
);
1303 #ifdef LISP_FLOAT_TYPE
1304 /* If a period is followed by a number, then we should read it
1305 as a floating point number. Otherwise, it denotes a dotted
1307 int next_char
= READCHAR
;
1310 if (! (next_char
>= '0' && next_char
<= '9'))
1317 /* Otherwise, we fall through! Note that the atom-reading loop
1318 below will now loop at least once, assuring that we will not
1319 try to UNREAD two characters in a row. */
1322 if (c
<= 040) goto retry
;
1324 register char *p
= read_buffer
;
1328 register char *end
= read_buffer
+ read_buffer_size
;
1331 !(c
== '\"' || c
== '\'' || c
== ';' || c
== '?'
1332 || c
== '(' || c
== ')'
1333 #ifndef LISP_FLOAT_TYPE
1334 /* If we have floating-point support, then we need
1335 to allow <digits><dot><digits>. */
1337 #endif /* not LISP_FLOAT_TYPE */
1338 || c
== '[' || c
== ']' || c
== '#'
1343 register char *new = (char *) xrealloc (read_buffer
, read_buffer_size
*= 2);
1344 p
+= new - read_buffer
;
1345 read_buffer
+= new - read_buffer
;
1346 end
= read_buffer
+ read_buffer_size
;
1359 char *new = (char *) xrealloc (read_buffer
, read_buffer_size
*= 2);
1360 p
+= new - read_buffer
;
1361 read_buffer
+= new - read_buffer
;
1362 /* end = read_buffer + read_buffer_size; */
1372 register Lisp_Object val
;
1374 if (*p1
== '+' || *p1
== '-') p1
++;
1375 /* Is it an integer? */
1378 while (p1
!= p
&& (c
= *p1
) >= '0' && c
<= '9') p1
++;
1379 #ifdef LISP_FLOAT_TYPE
1380 /* Integers can have trailing decimal points. */
1381 if (p1
> read_buffer
&& p1
< p
&& *p1
== '.') p1
++;
1384 /* It is an integer. */
1386 #ifdef LISP_FLOAT_TYPE
1390 XSETINT (val
, atoi (read_buffer
));
1394 #ifdef LISP_FLOAT_TYPE
1395 if (isfloat_string (read_buffer
))
1396 return make_float (atof (read_buffer
));
1400 return intern (read_buffer
);
1405 #ifdef LISP_FLOAT_TYPE
1420 if (*cp
== '+' || *cp
== '-')
1423 if (*cp
>= '0' && *cp
<= '9')
1426 while (*cp
>= '0' && *cp
<= '9')
1434 if (*cp
>= '0' && *cp
<= '9')
1437 while (*cp
>= '0' && *cp
<= '9')
1445 if ((*cp
== '+') || (*cp
== '-'))
1448 if (*cp
>= '0' && *cp
<= '9')
1451 while (*cp
>= '0' && *cp
<= '9')
1454 return (((*cp
== 0) || (*cp
== ' ') || (*cp
== '\t') || (*cp
== '\n') || (*cp
== '\r') || (*cp
== '\f'))
1455 && (state
== (LEAD_INT
|DOT_CHAR
|TRAIL_INT
)
1456 || state
== (DOT_CHAR
|TRAIL_INT
)
1457 || state
== (LEAD_INT
|E_CHAR
|EXP_INT
)
1458 || state
== (LEAD_INT
|DOT_CHAR
|TRAIL_INT
|E_CHAR
|EXP_INT
)
1459 || state
== (DOT_CHAR
|TRAIL_INT
|E_CHAR
|EXP_INT
)));
1461 #endif /* LISP_FLOAT_TYPE */
1464 read_vector (readcharfun
)
1465 Lisp_Object readcharfun
;
1469 register Lisp_Object
*ptr
;
1470 register Lisp_Object tem
, vector
;
1471 register struct Lisp_Cons
*otem
;
1474 tem
= read_list (1, readcharfun
);
1475 len
= Flength (tem
);
1476 vector
= (read_pure
? make_pure_vector (XINT (len
)) : Fmake_vector (len
, Qnil
));
1479 size
= XVECTOR (vector
)->size
;
1480 ptr
= XVECTOR (vector
)->contents
;
1481 for (i
= 0; i
< size
; i
++)
1483 ptr
[i
] = read_pure
? Fpurecopy (Fcar (tem
)) : Fcar (tem
);
1491 /* flag = 1 means check for ] to terminate rather than ) and .
1492 flag = -1 means check for starting with defun
1493 and make structure pure. */
1496 read_list (flag
, readcharfun
)
1498 register Lisp_Object readcharfun
;
1500 /* -1 means check next element for defun,
1501 0 means don't check,
1502 1 means already checked and found defun. */
1503 int defunflag
= flag
< 0 ? -1 : 0;
1504 Lisp_Object val
, tail
;
1505 register Lisp_Object elt
, tem
;
1506 struct gcpro gcpro1
, gcpro2
;
1516 elt
= read1 (readcharfun
, &ch
);
1519 /* If purifying, and the list starts with #$,
1520 return 0 instead. This is a doc string reference
1521 and it will be replaced anyway by Snarf-documentation,
1522 so don't waste pure space with it. */
1523 if (EQ (elt
, Vload_file_name
)
1524 && !NILP (Vpurify_flag
) && NILP (Vdoc_file_name
))
1533 Fsignal (Qinvalid_read_syntax
, Fcons (make_string (") or . in a vector", 18), Qnil
));
1541 XCONS (tail
)->cdr
= read0 (readcharfun
);
1543 val
= read0 (readcharfun
);
1544 read1 (readcharfun
, &ch
);
1547 return (cancel
? make_number (0) : val
);
1548 return Fsignal (Qinvalid_read_syntax
, Fcons (make_string (". in wrong context", 18), Qnil
));
1550 return Fsignal (Qinvalid_read_syntax
, Fcons (make_string ("] in a list", 11), Qnil
));
1552 tem
= (read_pure
&& flag
<= 0
1553 ? pure_cons (elt
, Qnil
)
1554 : Fcons (elt
, Qnil
));
1556 XCONS (tail
)->cdr
= tem
;
1561 defunflag
= EQ (elt
, Qdefun
);
1562 else if (defunflag
> 0)
1567 Lisp_Object Vobarray
;
1568 Lisp_Object initial_obarray
;
1570 /* oblookup stores the bucket number here, for the sake of Funintern. */
1572 int oblookup_last_bucket_number
;
1574 static int hash_string ();
1575 Lisp_Object
oblookup ();
1577 /* Get an error if OBARRAY is not an obarray.
1578 If it is one, return it. */
1581 check_obarray (obarray
)
1582 Lisp_Object obarray
;
1584 while (!VECTORP (obarray
) || XVECTOR (obarray
)->size
== 0)
1586 /* If Vobarray is now invalid, force it to be valid. */
1587 if (EQ (Vobarray
, obarray
)) Vobarray
= initial_obarray
;
1589 obarray
= wrong_type_argument (Qvectorp
, obarray
);
1594 /* Intern the C string STR: return a symbol with that name,
1595 interned in the current obarray. */
1602 int len
= strlen (str
);
1603 Lisp_Object obarray
;
1606 if (!VECTORP (obarray
) || XVECTOR (obarray
)->size
== 0)
1607 obarray
= check_obarray (obarray
);
1608 tem
= oblookup (obarray
, str
, len
);
1611 return Fintern ((!NILP (Vpurify_flag
)
1612 ? make_pure_string (str
, len
)
1613 : make_string (str
, len
)),
1617 DEFUN ("intern", Fintern
, Sintern
, 1, 2, 0,
1618 "Return the canonical symbol whose name is STRING.\n\
1619 If there is none, one is created by this function and returned.\n\
1620 A second optional argument specifies the obarray to use;\n\
1621 it defaults to the value of `obarray'.")
1623 Lisp_Object str
, obarray
;
1625 register Lisp_Object tem
, sym
, *ptr
;
1627 if (NILP (obarray
)) obarray
= Vobarray
;
1628 obarray
= check_obarray (obarray
);
1630 CHECK_STRING (str
, 0);
1632 tem
= oblookup (obarray
, XSTRING (str
)->data
, XSTRING (str
)->size
);
1633 if (!INTEGERP (tem
))
1636 if (!NILP (Vpurify_flag
))
1637 str
= Fpurecopy (str
);
1638 sym
= Fmake_symbol (str
);
1640 ptr
= &XVECTOR (obarray
)->contents
[XINT (tem
)];
1642 XSYMBOL (sym
)->next
= XSYMBOL (*ptr
);
1644 XSYMBOL (sym
)->next
= 0;
1649 DEFUN ("intern-soft", Fintern_soft
, Sintern_soft
, 1, 2, 0,
1650 "Return the canonical symbol whose name is STRING, or nil if none exists.\n\
1651 A second optional argument specifies the obarray to use;\n\
1652 it defaults to the value of `obarray'.")
1654 Lisp_Object str
, obarray
;
1656 register Lisp_Object tem
;
1658 if (NILP (obarray
)) obarray
= Vobarray
;
1659 obarray
= check_obarray (obarray
);
1661 CHECK_STRING (str
, 0);
1663 tem
= oblookup (obarray
, XSTRING (str
)->data
, XSTRING (str
)->size
);
1664 if (!INTEGERP (tem
))
1669 DEFUN ("unintern", Funintern
, Sunintern
, 1, 2, 0,
1670 "Delete the symbol named NAME, if any, from OBARRAY.\n\
1671 The value is t if a symbol was found and deleted, nil otherwise.\n\
1672 NAME may be a string or a symbol. If it is a symbol, that symbol\n\
1673 is deleted, if it belongs to OBARRAY--no other symbol is deleted.\n\
1674 OBARRAY defaults to the value of the variable `obarray'.")
1676 Lisp_Object name
, obarray
;
1678 register Lisp_Object string
, tem
;
1681 if (NILP (obarray
)) obarray
= Vobarray
;
1682 obarray
= check_obarray (obarray
);
1685 XSETSTRING (string
, XSYMBOL (name
)->name
);
1688 CHECK_STRING (name
, 0);
1692 tem
= oblookup (obarray
, XSTRING (string
)->data
, XSTRING (string
)->size
);
1695 /* If arg was a symbol, don't delete anything but that symbol itself. */
1696 if (SYMBOLP (name
) && !EQ (name
, tem
))
1699 hash
= oblookup_last_bucket_number
;
1701 if (EQ (XVECTOR (obarray
)->contents
[hash
], tem
))
1702 XSETSYMBOL (XVECTOR (obarray
)->contents
[hash
], XSYMBOL (tem
)->next
);
1705 Lisp_Object tail
, following
;
1707 for (tail
= XVECTOR (obarray
)->contents
[hash
];
1708 XSYMBOL (tail
)->next
;
1711 XSETSYMBOL (following
, XSYMBOL (tail
)->next
);
1712 if (EQ (following
, tem
))
1714 XSYMBOL (tail
)->next
= XSYMBOL (following
)->next
;
1723 /* Return the symbol in OBARRAY whose names matches the string
1724 of SIZE characters at PTR. If there is no such symbol in OBARRAY,
1727 Also store the bucket number in oblookup_last_bucket_number. */
1730 oblookup (obarray
, ptr
, size
, hashp
)
1731 Lisp_Object obarray
;
1738 register Lisp_Object tail
;
1739 Lisp_Object bucket
, tem
;
1741 if (!VECTORP (obarray
)
1742 || (obsize
= XVECTOR (obarray
)->size
) == 0)
1744 obarray
= check_obarray (obarray
);
1745 obsize
= XVECTOR (obarray
)->size
;
1747 /* Combining next two lines breaks VMS C 2.3. */
1748 hash
= hash_string (ptr
, size
);
1750 bucket
= XVECTOR (obarray
)->contents
[hash
];
1751 oblookup_last_bucket_number
= hash
;
1752 if (XFASTINT (bucket
) == 0)
1754 else if (!SYMBOLP (bucket
))
1755 error ("Bad data in guts of obarray"); /* Like CADR error message */
1757 for (tail
= bucket
; ; XSETSYMBOL (tail
, XSYMBOL (tail
)->next
))
1759 if (XSYMBOL (tail
)->name
->size
== size
1760 && !bcmp (XSYMBOL (tail
)->name
->data
, ptr
, size
))
1762 else if (XSYMBOL (tail
)->next
== 0)
1765 XSETINT (tem
, hash
);
1770 hash_string (ptr
, len
)
1774 register unsigned char *p
= ptr
;
1775 register unsigned char *end
= p
+ len
;
1776 register unsigned char c
;
1777 register int hash
= 0;
1782 if (c
>= 0140) c
-= 40;
1783 hash
= ((hash
<<3) + (hash
>>28) + c
);
1785 return hash
& 07777777777;
1789 map_obarray (obarray
, fn
, arg
)
1790 Lisp_Object obarray
;
1795 register Lisp_Object tail
;
1796 CHECK_VECTOR (obarray
, 1);
1797 for (i
= XVECTOR (obarray
)->size
- 1; i
>= 0; i
--)
1799 tail
= XVECTOR (obarray
)->contents
[i
];
1800 if (XFASTINT (tail
) != 0)
1804 if (XSYMBOL (tail
)->next
== 0)
1806 XSETSYMBOL (tail
, XSYMBOL (tail
)->next
);
1811 mapatoms_1 (sym
, function
)
1812 Lisp_Object sym
, function
;
1814 call1 (function
, sym
);
1817 DEFUN ("mapatoms", Fmapatoms
, Smapatoms
, 1, 2, 0,
1818 "Call FUNCTION on every symbol in OBARRAY.\n\
1819 OBARRAY defaults to the value of `obarray'.")
1821 Lisp_Object function
, obarray
;
1825 if (NILP (obarray
)) obarray
= Vobarray
;
1826 obarray
= check_obarray (obarray
);
1828 map_obarray (obarray
, mapatoms_1
, function
);
1832 #define OBARRAY_SIZE 1511
1837 Lisp_Object oblength
;
1841 XSETFASTINT (oblength
, OBARRAY_SIZE
);
1843 Qnil
= Fmake_symbol (make_pure_string ("nil", 3));
1844 Vobarray
= Fmake_vector (oblength
, make_number (0));
1845 initial_obarray
= Vobarray
;
1846 staticpro (&initial_obarray
);
1847 /* Intern nil in the obarray */
1848 /* These locals are to kludge around a pyramid compiler bug. */
1849 hash
= hash_string ("nil", 3);
1850 /* Separate statement here to avoid VAXC bug. */
1851 hash
%= OBARRAY_SIZE
;
1852 tem
= &XVECTOR (Vobarray
)->contents
[hash
];
1855 Qunbound
= Fmake_symbol (make_pure_string ("unbound", 7));
1856 XSYMBOL (Qnil
)->function
= Qunbound
;
1857 XSYMBOL (Qunbound
)->value
= Qunbound
;
1858 XSYMBOL (Qunbound
)->function
= Qunbound
;
1861 XSYMBOL (Qnil
)->value
= Qnil
;
1862 XSYMBOL (Qnil
)->plist
= Qnil
;
1863 XSYMBOL (Qt
)->value
= Qt
;
1865 /* Qt is correct even if CANNOT_DUMP. loadup.el will set to nil at end. */
1868 Qvariable_documentation
= intern ("variable-documentation");
1870 read_buffer_size
= 100;
1871 read_buffer
= (char *) malloc (read_buffer_size
);
1876 struct Lisp_Subr
*sname
;
1879 sym
= intern (sname
->symbol_name
);
1880 XSETSUBR (XSYMBOL (sym
)->function
, sname
);
1883 #ifdef NOTDEF /* use fset in subr.el now */
1885 defalias (sname
, string
)
1886 struct Lisp_Subr
*sname
;
1890 sym
= intern (string
);
1891 XSETSUBR (XSYMBOL (sym
)->function
, sname
);
1895 /* Define an "integer variable"; a symbol whose value is forwarded
1896 to a C variable of type int. Sample call: */
1897 /* DEFVAR_INT ("indent-tabs-mode", &indent_tabs_mode, "Documentation"); */
1899 defvar_int (namestring
, address
)
1903 Lisp_Object sym
, val
;
1904 sym
= intern (namestring
);
1905 val
= allocate_misc ();
1906 XMISCTYPE (val
) = Lisp_Misc_Intfwd
;
1907 XINTFWD (val
)->intvar
= address
;
1908 XSYMBOL (sym
)->value
= val
;
1911 /* Similar but define a variable whose value is T if address contains 1,
1912 NIL if address contains 0 */
1914 defvar_bool (namestring
, address
)
1918 Lisp_Object sym
, val
;
1919 sym
= intern (namestring
);
1920 val
= allocate_misc ();
1921 XMISCTYPE (val
) = Lisp_Misc_Boolfwd
;
1922 XBOOLFWD (val
)->boolvar
= address
;
1923 XSYMBOL (sym
)->value
= val
;
1926 /* Similar but define a variable whose value is the Lisp Object stored
1927 at address. Two versions: with and without gc-marking of the C
1928 variable. The nopro version is used when that variable will be
1929 gc-marked for some other reason, since marking the same slot twice
1930 can cause trouble with strings. */
1932 defvar_lisp_nopro (namestring
, address
)
1934 Lisp_Object
*address
;
1936 Lisp_Object sym
, val
;
1937 sym
= intern (namestring
);
1938 val
= allocate_misc ();
1939 XMISCTYPE (val
) = Lisp_Misc_Objfwd
;
1940 XOBJFWD (val
)->objvar
= address
;
1941 XSYMBOL (sym
)->value
= val
;
1945 defvar_lisp (namestring
, address
)
1947 Lisp_Object
*address
;
1949 defvar_lisp_nopro (namestring
, address
);
1950 staticpro (address
);
1955 /* Similar but define a variable whose value is the Lisp Object stored in
1956 the current buffer. address is the address of the slot in the buffer
1957 that is current now. */
1960 defvar_per_buffer (namestring
, address
, type
, doc
)
1962 Lisp_Object
*address
;
1966 Lisp_Object sym
, val
;
1968 extern struct buffer buffer_local_symbols
;
1970 sym
= intern (namestring
);
1971 val
= allocate_misc ();
1972 offset
= (char *)address
- (char *)current_buffer
;
1974 XMISCTYPE (val
) = Lisp_Misc_Buffer_Objfwd
;
1975 XBUFFER_OBJFWD (val
)->offset
= offset
;
1976 XSYMBOL (sym
)->value
= val
;
1977 *(Lisp_Object
*)(offset
+ (char *)&buffer_local_symbols
) = sym
;
1978 *(Lisp_Object
*)(offset
+ (char *)&buffer_local_types
) = type
;
1979 if (XINT (*(Lisp_Object
*)(offset
+ (char *)&buffer_local_flags
)) == 0)
1980 /* Did a DEFVAR_PER_BUFFER without initializing the corresponding
1981 slot of buffer_local_flags */
1985 #endif /* standalone */
1987 /* Similar but define a variable whose value is the Lisp Object stored
1988 at a particular offset in the current kboard object. */
1991 defvar_kboard (namestring
, offset
)
1995 Lisp_Object sym
, val
;
1996 sym
= intern (namestring
);
1997 val
= allocate_misc ();
1998 XMISCTYPE (val
) = Lisp_Misc_Kboard_Objfwd
;
1999 XKBOARD_OBJFWD (val
)->offset
= offset
;
2000 XSYMBOL (sym
)->value
= val
;
2007 /* Compute the default load-path. */
2009 normal
= PATH_LOADSEARCH
;
2010 Vload_path
= decode_env_path (0, normal
);
2012 if (NILP (Vpurify_flag
))
2013 normal
= PATH_LOADSEARCH
;
2015 normal
= PATH_DUMPLOADSEARCH
;
2017 /* In a dumped Emacs, we normally have to reset the value of
2018 Vload_path from PATH_LOADSEARCH, since the value that was dumped
2019 uses ../lisp, instead of the path of the installed elisp
2020 libraries. However, if it appears that Vload_path was changed
2021 from the default before dumping, don't override that value. */
2024 Lisp_Object dump_path
;
2026 dump_path
= decode_env_path (0, PATH_DUMPLOADSEARCH
);
2027 if (! NILP (Fequal (dump_path
, Vload_path
)))
2029 Vload_path
= decode_env_path (0, normal
);
2030 if (!NILP (Vinstallation_directory
))
2032 /* Add to the path the lisp subdir of the
2033 installation dir, if it exists. */
2034 Lisp_Object tem
, tem1
;
2035 tem
= Fexpand_file_name (build_string ("lisp"),
2036 Vinstallation_directory
);
2037 tem1
= Ffile_exists_p (tem
);
2040 if (NILP (Fmember (tem
, Vload_path
)))
2041 Vload_path
= nconc2 (Vload_path
, Fcons (tem
, Qnil
));
2044 /* That dir doesn't exist, so add the build-time
2045 Lisp dirs instead. */
2046 Vload_path
= nconc2 (Vload_path
, dump_path
);
2048 /* Add site-list under the installation dir, if it exists. */
2049 tem
= Fexpand_file_name (build_string ("site-lisp"),
2050 Vinstallation_directory
);
2051 tem1
= Ffile_exists_p (tem
);
2054 if (NILP (Fmember (tem
, Vload_path
)))
2055 Vload_path
= nconc2 (Vload_path
, Fcons (tem
, Qnil
));
2061 Vload_path
= decode_env_path (0, normal
);
2065 /* When Emacs is invoked over network shares on NT, PATH_LOADSEARCH is
2066 almost never correct, thereby causing a warning to be printed out that
2067 confuses users. Since PATH_LOADSEARCH is always overriden by the
2068 EMACSLOADPATH environment variable below, disable the warning on NT. */
2070 /* Warn if dirs in the *standard* path don't exist. */
2072 Lisp_Object path_tail
;
2074 for (path_tail
= Vload_path
;
2076 path_tail
= XCONS (path_tail
)->cdr
)
2078 Lisp_Object dirfile
;
2079 dirfile
= Fcar (path_tail
);
2080 if (STRINGP (dirfile
))
2082 dirfile
= Fdirectory_file_name (dirfile
);
2083 if (access (XSTRING (dirfile
)->data
, 0) < 0)
2085 "Warning: Lisp directory `%s' does not exist.\n",
2086 XSTRING (Fcar (path_tail
))->data
);
2090 #endif /* WINDOWSNT */
2092 /* If the EMACSLOADPATH environment variable is set, use its value.
2093 This doesn't apply if we're dumping. */
2094 if (NILP (Vpurify_flag
)
2095 && egetenv ("EMACSLOADPATH"))
2096 Vload_path
= decode_env_path ("EMACSLOADPATH", normal
);
2100 load_in_progress
= 0;
2102 load_descriptor_list
= Qnil
;
2109 defsubr (&Sread_from_string
);
2111 defsubr (&Sintern_soft
);
2112 defsubr (&Sunintern
);
2114 defsubr (&Seval_buffer
);
2115 defsubr (&Seval_region
);
2116 defsubr (&Sread_char
);
2117 defsubr (&Sread_char_exclusive
);
2118 defsubr (&Sread_event
);
2119 defsubr (&Sget_file_char
);
2120 defsubr (&Smapatoms
);
2122 DEFVAR_LISP ("obarray", &Vobarray
,
2123 "Symbol table for use by `intern' and `read'.\n\
2124 It is a vector whose length ought to be prime for best results.\n\
2125 The vector's contents don't make sense if examined from Lisp programs;\n\
2126 to find all the symbols in an obarray, use `mapatoms'.");
2128 DEFVAR_LISP ("values", &Vvalues
,
2129 "List of values of all expressions which were read, evaluated and printed.\n\
2130 Order is reverse chronological.");
2132 DEFVAR_LISP ("standard-input", &Vstandard_input
,
2133 "Stream for read to get input from.\n\
2134 See documentation of `read' for possible values.");
2135 Vstandard_input
= Qt
;
2137 DEFVAR_LISP ("load-path", &Vload_path
,
2138 "*List of directories to search for files to load.\n\
2139 Each element is a string (directory name) or nil (try default directory).\n\
2140 Initialized based on EMACSLOADPATH environment variable, if any,\n\
2141 otherwise to default specified by file `paths.h' when Emacs was built.");
2143 DEFVAR_BOOL ("load-in-progress", &load_in_progress
,
2144 "Non-nil iff inside of `load'.");
2146 DEFVAR_LISP ("after-load-alist", &Vafter_load_alist
,
2147 "An alist of expressions to be evalled when particular files are loaded.\n\
2148 Each element looks like (FILENAME FORMS...).\n\
2149 When `load' is run and the file-name argument is FILENAME,\n\
2150 the FORMS in the corresponding element are executed at the end of loading.\n\n\
2151 FILENAME must match exactly! Normally FILENAME is the name of a library,\n\
2152 with no directory specified, since that is how `load' is normally called.\n\
2153 An error in FORMS does not undo the load,\n\
2154 but does prevent execution of the rest of the FORMS.");
2155 Vafter_load_alist
= Qnil
;
2157 DEFVAR_LISP ("load-history", &Vload_history
,
2158 "Alist mapping source file names to symbols and features.\n\
2159 Each alist element is a list that starts with a file name,\n\
2160 except for one element (optional) that starts with nil and describes\n\
2161 definitions evaluated from buffers not visiting files.\n\
2162 The remaining elements of each list are symbols defined as functions\n\
2163 or variables, and cons cells `(provide . FEATURE)' and `(require . FEATURE)'.");
2164 Vload_history
= Qnil
;
2166 DEFVAR_LISP ("load-file-name", &Vload_file_name
,
2167 "Full name of file being loaded by `load'.");
2168 Vload_file_name
= Qnil
;
2170 DEFVAR_LISP ("current-load-list", &Vcurrent_load_list
,
2171 "Used for internal purposes by `load'.");
2172 Vcurrent_load_list
= Qnil
;
2174 DEFVAR_LISP ("load-read-function", &Vload_read_function
,
2175 "Function used by `load' and `eval-region' for reading expressions.\n\
2176 The default is nil, which means use the function `read'.");
2177 Vload_read_function
= Qnil
;
2179 load_descriptor_list
= Qnil
;
2180 staticpro (&load_descriptor_list
);
2182 Qcurrent_load_list
= intern ("current-load-list");
2183 staticpro (&Qcurrent_load_list
);
2185 Qstandard_input
= intern ("standard-input");
2186 staticpro (&Qstandard_input
);
2188 Qread_char
= intern ("read-char");
2189 staticpro (&Qread_char
);
2191 Qget_file_char
= intern ("get-file-char");
2192 staticpro (&Qget_file_char
);
2194 Qascii_character
= intern ("ascii-character");
2195 staticpro (&Qascii_character
);
2197 Qload
= intern ("load");
2200 Qload_file_name
= intern ("load-file-name");
2201 staticpro (&Qload_file_name
);