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 if ((c
& 0xff) >= 'a' && (c
& 0xff) <= 'z')
1008 return c
- ('a' - 'A');
1009 return c
| shift_modifier
;
1014 error ("Invalid escape character syntax");
1017 c
= read_escape (readcharfun
);
1018 return c
| hyper_modifier
;
1023 error ("Invalid escape character syntax");
1026 c
= read_escape (readcharfun
);
1027 return c
| alt_modifier
;
1032 error ("Invalid escape character syntax");
1035 c
= read_escape (readcharfun
);
1036 return c
| super_modifier
;
1041 error ("Invalid escape character syntax");
1045 c
= read_escape (readcharfun
);
1046 if ((c
& 0177) == '?')
1048 /* ASCII control chars are made from letters (both cases),
1049 as well as the non-letters within 0100...0137. */
1050 else if ((c
& 0137) >= 0101 && (c
& 0137) <= 0132)
1051 return (c
& (037 | ~0177));
1052 else if ((c
& 0177) >= 0100 && (c
& 0177) <= 0137)
1053 return (c
& (037 | ~0177));
1055 return c
| ctrl_modifier
;
1065 /* An octal escape, as in ANSI C. */
1067 register int i
= c
- '0';
1068 register int count
= 0;
1071 if ((c
= READCHAR
) >= '0' && c
<= '7')
1086 /* A hex escape, as in ANSI C. */
1092 if (c
>= '0' && c
<= '9')
1097 else if ((c
>= 'a' && c
<= 'f')
1098 || (c
>= 'A' && c
<= 'F'))
1101 if (c
>= 'a' && c
<= 'f')
1120 /* If the next token is ')' or ']' or '.', we store that character
1121 in *PCH and the return value is not interesting. Else, we store
1122 zero in *PCH and we read and return one lisp object. */
1124 read1 (readcharfun
, pch
)
1125 register Lisp_Object readcharfun
;
1134 if (c
< 0) return Fsignal (Qend_of_file
, Qnil
);
1139 return read_list (0, readcharfun
);
1142 return read_vector (readcharfun
);
1155 /* Accept compiled functions at read-time so that we don't have to
1156 build them using function calls. */
1158 tmp
= read_vector (readcharfun
);
1159 return Fmake_byte_code (XVECTOR (tmp
)->size
,
1160 XVECTOR (tmp
)->contents
);
1162 #ifdef USE_TEXT_PROPERTIES
1166 struct gcpro gcpro1
;
1169 /* Read the string itself. */
1170 tmp
= read1 (readcharfun
, &ch
);
1171 if (ch
!= 0 || !STRINGP (tmp
))
1172 Fsignal (Qinvalid_read_syntax
, Fcons (make_string ("#", 1), Qnil
));
1174 /* Read the intervals and their properties. */
1177 Lisp_Object beg
, end
, plist
;
1179 beg
= read1 (readcharfun
, &ch
);
1183 end
= read1 (readcharfun
, &ch
);
1185 plist
= read1 (readcharfun
, &ch
);
1187 Fsignal (Qinvalid_read_syntax
,
1188 Fcons (build_string ("invalid string property list"),
1190 Fset_text_properties (beg
, end
, plist
, tmp
);
1196 /* #@NUMBER is used to skip NUMBER following characters.
1197 That's used in .elc files to skip over doc strings
1198 and function definitions. */
1203 /* Read a decimal integer. */
1204 while ((c
= READCHAR
) >= 0
1205 && c
>= '0' && c
<= '9')
1213 /* Skip that many characters. */
1214 for (i
= 0; i
< nskip
&& c
>= 0; i
++)
1219 return Vload_file_name
;
1222 Fsignal (Qinvalid_read_syntax
, Fcons (make_string ("#", 1), Qnil
));
1225 while ((c
= READCHAR
) >= 0 && c
!= '\n');
1230 return Fcons (Qquote
, Fcons (read0 (readcharfun
), Qnil
));
1235 register Lisp_Object val
;
1238 if (c
< 0) return Fsignal (Qend_of_file
, Qnil
);
1241 XSETINT (val
, read_escape (readcharfun
));
1250 register char *p
= read_buffer
;
1251 register char *end
= read_buffer
+ read_buffer_size
;
1255 while ((c
= READCHAR
) >= 0
1260 char *new = (char *) xrealloc (read_buffer
, read_buffer_size
*= 2);
1261 p
+= new - read_buffer
;
1262 read_buffer
+= new - read_buffer
;
1263 end
= read_buffer
+ read_buffer_size
;
1266 c
= read_escape (readcharfun
);
1267 /* c is -1 if \ newline has just been seen */
1270 if (p
== read_buffer
)
1275 /* Allow `\C- ' and `\C-?'. */
1276 if (c
== (CHAR_CTL
| ' '))
1278 else if (c
== (CHAR_CTL
| '?'))
1282 /* Move the meta bit to the right place for a string. */
1283 c
= (c
& ~CHAR_META
) | 0x80;
1285 error ("Invalid modifier in string");
1289 if (c
< 0) return Fsignal (Qend_of_file
, Qnil
);
1291 /* If purifying, and string starts with \ newline,
1292 return zero instead. This is for doc strings
1293 that we are really going to find in etc/DOC.nn.nn */
1294 if (!NILP (Vpurify_flag
) && NILP (Vdoc_file_name
) && cancel
)
1295 return make_number (0);
1298 return make_pure_string (read_buffer
, p
- read_buffer
);
1300 return make_string (read_buffer
, p
- read_buffer
);
1305 #ifdef LISP_FLOAT_TYPE
1306 /* If a period is followed by a number, then we should read it
1307 as a floating point number. Otherwise, it denotes a dotted
1309 int next_char
= READCHAR
;
1312 if (! (next_char
>= '0' && next_char
<= '9'))
1319 /* Otherwise, we fall through! Note that the atom-reading loop
1320 below will now loop at least once, assuring that we will not
1321 try to UNREAD two characters in a row. */
1324 if (c
<= 040) goto retry
;
1326 register char *p
= read_buffer
;
1330 register char *end
= read_buffer
+ read_buffer_size
;
1333 !(c
== '\"' || c
== '\'' || c
== ';' || c
== '?'
1334 || c
== '(' || c
== ')'
1335 #ifndef LISP_FLOAT_TYPE
1336 /* If we have floating-point support, then we need
1337 to allow <digits><dot><digits>. */
1339 #endif /* not LISP_FLOAT_TYPE */
1340 || c
== '[' || c
== ']' || c
== '#'
1345 register char *new = (char *) xrealloc (read_buffer
, read_buffer_size
*= 2);
1346 p
+= new - read_buffer
;
1347 read_buffer
+= new - read_buffer
;
1348 end
= read_buffer
+ read_buffer_size
;
1361 char *new = (char *) xrealloc (read_buffer
, read_buffer_size
*= 2);
1362 p
+= new - read_buffer
;
1363 read_buffer
+= new - read_buffer
;
1364 /* end = read_buffer + read_buffer_size; */
1374 register Lisp_Object val
;
1376 if (*p1
== '+' || *p1
== '-') p1
++;
1377 /* Is it an integer? */
1380 while (p1
!= p
&& (c
= *p1
) >= '0' && c
<= '9') p1
++;
1381 #ifdef LISP_FLOAT_TYPE
1382 /* Integers can have trailing decimal points. */
1383 if (p1
> read_buffer
&& p1
< p
&& *p1
== '.') p1
++;
1386 /* It is an integer. */
1388 #ifdef LISP_FLOAT_TYPE
1392 XSETINT (val
, atoi (read_buffer
));
1396 #ifdef LISP_FLOAT_TYPE
1397 if (isfloat_string (read_buffer
))
1398 return make_float (atof (read_buffer
));
1402 return intern (read_buffer
);
1407 #ifdef LISP_FLOAT_TYPE
1422 if (*cp
== '+' || *cp
== '-')
1425 if (*cp
>= '0' && *cp
<= '9')
1428 while (*cp
>= '0' && *cp
<= '9')
1436 if (*cp
>= '0' && *cp
<= '9')
1439 while (*cp
>= '0' && *cp
<= '9')
1447 if ((*cp
== '+') || (*cp
== '-'))
1450 if (*cp
>= '0' && *cp
<= '9')
1453 while (*cp
>= '0' && *cp
<= '9')
1456 return (((*cp
== 0) || (*cp
== ' ') || (*cp
== '\t') || (*cp
== '\n') || (*cp
== '\r') || (*cp
== '\f'))
1457 && (state
== (LEAD_INT
|DOT_CHAR
|TRAIL_INT
)
1458 || state
== (DOT_CHAR
|TRAIL_INT
)
1459 || state
== (LEAD_INT
|E_CHAR
|EXP_INT
)
1460 || state
== (LEAD_INT
|DOT_CHAR
|TRAIL_INT
|E_CHAR
|EXP_INT
)
1461 || state
== (DOT_CHAR
|TRAIL_INT
|E_CHAR
|EXP_INT
)));
1463 #endif /* LISP_FLOAT_TYPE */
1466 read_vector (readcharfun
)
1467 Lisp_Object readcharfun
;
1471 register Lisp_Object
*ptr
;
1472 register Lisp_Object tem
, vector
;
1473 register struct Lisp_Cons
*otem
;
1476 tem
= read_list (1, readcharfun
);
1477 len
= Flength (tem
);
1478 vector
= (read_pure
? make_pure_vector (XINT (len
)) : Fmake_vector (len
, Qnil
));
1481 size
= XVECTOR (vector
)->size
;
1482 ptr
= XVECTOR (vector
)->contents
;
1483 for (i
= 0; i
< size
; i
++)
1485 ptr
[i
] = read_pure
? Fpurecopy (Fcar (tem
)) : Fcar (tem
);
1493 /* flag = 1 means check for ] to terminate rather than ) and .
1494 flag = -1 means check for starting with defun
1495 and make structure pure. */
1498 read_list (flag
, readcharfun
)
1500 register Lisp_Object readcharfun
;
1502 /* -1 means check next element for defun,
1503 0 means don't check,
1504 1 means already checked and found defun. */
1505 int defunflag
= flag
< 0 ? -1 : 0;
1506 Lisp_Object val
, tail
;
1507 register Lisp_Object elt
, tem
;
1508 struct gcpro gcpro1
, gcpro2
;
1518 elt
= read1 (readcharfun
, &ch
);
1521 /* If purifying, and the list starts with #$,
1522 return 0 instead. This is a doc string reference
1523 and it will be replaced anyway by Snarf-documentation,
1524 so don't waste pure space with it. */
1525 if (EQ (elt
, Vload_file_name
)
1526 && !NILP (Vpurify_flag
) && NILP (Vdoc_file_name
))
1535 Fsignal (Qinvalid_read_syntax
, Fcons (make_string (") or . in a vector", 18), Qnil
));
1543 XCONS (tail
)->cdr
= read0 (readcharfun
);
1545 val
= read0 (readcharfun
);
1546 read1 (readcharfun
, &ch
);
1549 return (cancel
? make_number (0) : val
);
1550 return Fsignal (Qinvalid_read_syntax
, Fcons (make_string (". in wrong context", 18), Qnil
));
1552 return Fsignal (Qinvalid_read_syntax
, Fcons (make_string ("] in a list", 11), Qnil
));
1554 tem
= (read_pure
&& flag
<= 0
1555 ? pure_cons (elt
, Qnil
)
1556 : Fcons (elt
, Qnil
));
1558 XCONS (tail
)->cdr
= tem
;
1563 defunflag
= EQ (elt
, Qdefun
);
1564 else if (defunflag
> 0)
1569 Lisp_Object Vobarray
;
1570 Lisp_Object initial_obarray
;
1572 /* oblookup stores the bucket number here, for the sake of Funintern. */
1574 int oblookup_last_bucket_number
;
1576 static int hash_string ();
1577 Lisp_Object
oblookup ();
1579 /* Get an error if OBARRAY is not an obarray.
1580 If it is one, return it. */
1583 check_obarray (obarray
)
1584 Lisp_Object obarray
;
1586 while (!VECTORP (obarray
) || XVECTOR (obarray
)->size
== 0)
1588 /* If Vobarray is now invalid, force it to be valid. */
1589 if (EQ (Vobarray
, obarray
)) Vobarray
= initial_obarray
;
1591 obarray
= wrong_type_argument (Qvectorp
, obarray
);
1596 /* Intern the C string STR: return a symbol with that name,
1597 interned in the current obarray. */
1604 int len
= strlen (str
);
1605 Lisp_Object obarray
;
1608 if (!VECTORP (obarray
) || XVECTOR (obarray
)->size
== 0)
1609 obarray
= check_obarray (obarray
);
1610 tem
= oblookup (obarray
, str
, len
);
1613 return Fintern ((!NILP (Vpurify_flag
)
1614 ? make_pure_string (str
, len
)
1615 : make_string (str
, len
)),
1619 DEFUN ("intern", Fintern
, Sintern
, 1, 2, 0,
1620 "Return the canonical symbol whose name is STRING.\n\
1621 If there is none, one is created by this function and returned.\n\
1622 A second optional argument specifies the obarray to use;\n\
1623 it defaults to the value of `obarray'.")
1625 Lisp_Object str
, obarray
;
1627 register Lisp_Object tem
, sym
, *ptr
;
1629 if (NILP (obarray
)) obarray
= Vobarray
;
1630 obarray
= check_obarray (obarray
);
1632 CHECK_STRING (str
, 0);
1634 tem
= oblookup (obarray
, XSTRING (str
)->data
, XSTRING (str
)->size
);
1635 if (!INTEGERP (tem
))
1638 if (!NILP (Vpurify_flag
))
1639 str
= Fpurecopy (str
);
1640 sym
= Fmake_symbol (str
);
1642 ptr
= &XVECTOR (obarray
)->contents
[XINT (tem
)];
1644 XSYMBOL (sym
)->next
= XSYMBOL (*ptr
);
1646 XSYMBOL (sym
)->next
= 0;
1651 DEFUN ("intern-soft", Fintern_soft
, Sintern_soft
, 1, 2, 0,
1652 "Return the canonical symbol whose name is STRING, or nil if none exists.\n\
1653 A second optional argument specifies the obarray to use;\n\
1654 it defaults to the value of `obarray'.")
1656 Lisp_Object str
, obarray
;
1658 register Lisp_Object tem
;
1660 if (NILP (obarray
)) obarray
= Vobarray
;
1661 obarray
= check_obarray (obarray
);
1663 CHECK_STRING (str
, 0);
1665 tem
= oblookup (obarray
, XSTRING (str
)->data
, XSTRING (str
)->size
);
1666 if (!INTEGERP (tem
))
1671 DEFUN ("unintern", Funintern
, Sunintern
, 1, 2, 0,
1672 "Delete the symbol named NAME, if any, from OBARRAY.\n\
1673 The value is t if a symbol was found and deleted, nil otherwise.\n\
1674 NAME may be a string or a symbol. If it is a symbol, that symbol\n\
1675 is deleted, if it belongs to OBARRAY--no other symbol is deleted.\n\
1676 OBARRAY defaults to the value of the variable `obarray'.")
1678 Lisp_Object name
, obarray
;
1680 register Lisp_Object string
, tem
;
1683 if (NILP (obarray
)) obarray
= Vobarray
;
1684 obarray
= check_obarray (obarray
);
1687 XSETSTRING (string
, XSYMBOL (name
)->name
);
1690 CHECK_STRING (name
, 0);
1694 tem
= oblookup (obarray
, XSTRING (string
)->data
, XSTRING (string
)->size
);
1697 /* If arg was a symbol, don't delete anything but that symbol itself. */
1698 if (SYMBOLP (name
) && !EQ (name
, tem
))
1701 hash
= oblookup_last_bucket_number
;
1703 if (EQ (XVECTOR (obarray
)->contents
[hash
], tem
))
1704 XSETSYMBOL (XVECTOR (obarray
)->contents
[hash
], XSYMBOL (tem
)->next
);
1707 Lisp_Object tail
, following
;
1709 for (tail
= XVECTOR (obarray
)->contents
[hash
];
1710 XSYMBOL (tail
)->next
;
1713 XSETSYMBOL (following
, XSYMBOL (tail
)->next
);
1714 if (EQ (following
, tem
))
1716 XSYMBOL (tail
)->next
= XSYMBOL (following
)->next
;
1725 /* Return the symbol in OBARRAY whose names matches the string
1726 of SIZE characters at PTR. If there is no such symbol in OBARRAY,
1729 Also store the bucket number in oblookup_last_bucket_number. */
1732 oblookup (obarray
, ptr
, size
, hashp
)
1733 Lisp_Object obarray
;
1740 register Lisp_Object tail
;
1741 Lisp_Object bucket
, tem
;
1743 if (!VECTORP (obarray
)
1744 || (obsize
= XVECTOR (obarray
)->size
) == 0)
1746 obarray
= check_obarray (obarray
);
1747 obsize
= XVECTOR (obarray
)->size
;
1749 /* Combining next two lines breaks VMS C 2.3. */
1750 hash
= hash_string (ptr
, size
);
1752 bucket
= XVECTOR (obarray
)->contents
[hash
];
1753 oblookup_last_bucket_number
= hash
;
1754 if (XFASTINT (bucket
) == 0)
1756 else if (!SYMBOLP (bucket
))
1757 error ("Bad data in guts of obarray"); /* Like CADR error message */
1759 for (tail
= bucket
; ; XSETSYMBOL (tail
, XSYMBOL (tail
)->next
))
1761 if (XSYMBOL (tail
)->name
->size
== size
1762 && !bcmp (XSYMBOL (tail
)->name
->data
, ptr
, size
))
1764 else if (XSYMBOL (tail
)->next
== 0)
1767 XSETINT (tem
, hash
);
1772 hash_string (ptr
, len
)
1776 register unsigned char *p
= ptr
;
1777 register unsigned char *end
= p
+ len
;
1778 register unsigned char c
;
1779 register int hash
= 0;
1784 if (c
>= 0140) c
-= 40;
1785 hash
= ((hash
<<3) + (hash
>>28) + c
);
1787 return hash
& 07777777777;
1791 map_obarray (obarray
, fn
, arg
)
1792 Lisp_Object obarray
;
1797 register Lisp_Object tail
;
1798 CHECK_VECTOR (obarray
, 1);
1799 for (i
= XVECTOR (obarray
)->size
- 1; i
>= 0; i
--)
1801 tail
= XVECTOR (obarray
)->contents
[i
];
1802 if (XFASTINT (tail
) != 0)
1806 if (XSYMBOL (tail
)->next
== 0)
1808 XSETSYMBOL (tail
, XSYMBOL (tail
)->next
);
1813 mapatoms_1 (sym
, function
)
1814 Lisp_Object sym
, function
;
1816 call1 (function
, sym
);
1819 DEFUN ("mapatoms", Fmapatoms
, Smapatoms
, 1, 2, 0,
1820 "Call FUNCTION on every symbol in OBARRAY.\n\
1821 OBARRAY defaults to the value of `obarray'.")
1823 Lisp_Object function
, obarray
;
1827 if (NILP (obarray
)) obarray
= Vobarray
;
1828 obarray
= check_obarray (obarray
);
1830 map_obarray (obarray
, mapatoms_1
, function
);
1834 #define OBARRAY_SIZE 1511
1839 Lisp_Object oblength
;
1843 XSETFASTINT (oblength
, OBARRAY_SIZE
);
1845 Qnil
= Fmake_symbol (make_pure_string ("nil", 3));
1846 Vobarray
= Fmake_vector (oblength
, make_number (0));
1847 initial_obarray
= Vobarray
;
1848 staticpro (&initial_obarray
);
1849 /* Intern nil in the obarray */
1850 /* These locals are to kludge around a pyramid compiler bug. */
1851 hash
= hash_string ("nil", 3);
1852 /* Separate statement here to avoid VAXC bug. */
1853 hash
%= OBARRAY_SIZE
;
1854 tem
= &XVECTOR (Vobarray
)->contents
[hash
];
1857 Qunbound
= Fmake_symbol (make_pure_string ("unbound", 7));
1858 XSYMBOL (Qnil
)->function
= Qunbound
;
1859 XSYMBOL (Qunbound
)->value
= Qunbound
;
1860 XSYMBOL (Qunbound
)->function
= Qunbound
;
1863 XSYMBOL (Qnil
)->value
= Qnil
;
1864 XSYMBOL (Qnil
)->plist
= Qnil
;
1865 XSYMBOL (Qt
)->value
= Qt
;
1867 /* Qt is correct even if CANNOT_DUMP. loadup.el will set to nil at end. */
1870 Qvariable_documentation
= intern ("variable-documentation");
1872 read_buffer_size
= 100;
1873 read_buffer
= (char *) malloc (read_buffer_size
);
1878 struct Lisp_Subr
*sname
;
1881 sym
= intern (sname
->symbol_name
);
1882 XSETSUBR (XSYMBOL (sym
)->function
, sname
);
1885 #ifdef NOTDEF /* use fset in subr.el now */
1887 defalias (sname
, string
)
1888 struct Lisp_Subr
*sname
;
1892 sym
= intern (string
);
1893 XSETSUBR (XSYMBOL (sym
)->function
, sname
);
1897 /* Define an "integer variable"; a symbol whose value is forwarded
1898 to a C variable of type int. Sample call: */
1899 /* DEFVAR_INT ("indent-tabs-mode", &indent_tabs_mode, "Documentation"); */
1901 defvar_int (namestring
, address
)
1905 Lisp_Object sym
, val
;
1906 sym
= intern (namestring
);
1907 val
= allocate_misc ();
1908 XMISCTYPE (val
) = Lisp_Misc_Intfwd
;
1909 XINTFWD (val
)->intvar
= address
;
1910 XSYMBOL (sym
)->value
= val
;
1913 /* Similar but define a variable whose value is T if address contains 1,
1914 NIL if address contains 0 */
1916 defvar_bool (namestring
, address
)
1920 Lisp_Object sym
, val
;
1921 sym
= intern (namestring
);
1922 val
= allocate_misc ();
1923 XMISCTYPE (val
) = Lisp_Misc_Boolfwd
;
1924 XBOOLFWD (val
)->boolvar
= address
;
1925 XSYMBOL (sym
)->value
= val
;
1928 /* Similar but define a variable whose value is the Lisp Object stored
1929 at address. Two versions: with and without gc-marking of the C
1930 variable. The nopro version is used when that variable will be
1931 gc-marked for some other reason, since marking the same slot twice
1932 can cause trouble with strings. */
1934 defvar_lisp_nopro (namestring
, address
)
1936 Lisp_Object
*address
;
1938 Lisp_Object sym
, val
;
1939 sym
= intern (namestring
);
1940 val
= allocate_misc ();
1941 XMISCTYPE (val
) = Lisp_Misc_Objfwd
;
1942 XOBJFWD (val
)->objvar
= address
;
1943 XSYMBOL (sym
)->value
= val
;
1947 defvar_lisp (namestring
, address
)
1949 Lisp_Object
*address
;
1951 defvar_lisp_nopro (namestring
, address
);
1952 staticpro (address
);
1957 /* Similar but define a variable whose value is the Lisp Object stored in
1958 the current buffer. address is the address of the slot in the buffer
1959 that is current now. */
1962 defvar_per_buffer (namestring
, address
, type
, doc
)
1964 Lisp_Object
*address
;
1968 Lisp_Object sym
, val
;
1970 extern struct buffer buffer_local_symbols
;
1972 sym
= intern (namestring
);
1973 val
= allocate_misc ();
1974 offset
= (char *)address
- (char *)current_buffer
;
1976 XMISCTYPE (val
) = Lisp_Misc_Buffer_Objfwd
;
1977 XBUFFER_OBJFWD (val
)->offset
= offset
;
1978 XSYMBOL (sym
)->value
= val
;
1979 *(Lisp_Object
*)(offset
+ (char *)&buffer_local_symbols
) = sym
;
1980 *(Lisp_Object
*)(offset
+ (char *)&buffer_local_types
) = type
;
1981 if (XINT (*(Lisp_Object
*)(offset
+ (char *)&buffer_local_flags
)) == 0)
1982 /* Did a DEFVAR_PER_BUFFER without initializing the corresponding
1983 slot of buffer_local_flags */
1987 #endif /* standalone */
1989 /* Similar but define a variable whose value is the Lisp Object stored
1990 at a particular offset in the current kboard object. */
1993 defvar_kboard (namestring
, offset
)
1997 Lisp_Object sym
, val
;
1998 sym
= intern (namestring
);
1999 val
= allocate_misc ();
2000 XMISCTYPE (val
) = Lisp_Misc_Kboard_Objfwd
;
2001 XKBOARD_OBJFWD (val
)->offset
= offset
;
2002 XSYMBOL (sym
)->value
= val
;
2009 /* Compute the default load-path. */
2011 normal
= PATH_LOADSEARCH
;
2012 Vload_path
= decode_env_path (0, normal
);
2014 if (NILP (Vpurify_flag
))
2015 normal
= PATH_LOADSEARCH
;
2017 normal
= PATH_DUMPLOADSEARCH
;
2019 /* In a dumped Emacs, we normally have to reset the value of
2020 Vload_path from PATH_LOADSEARCH, since the value that was dumped
2021 uses ../lisp, instead of the path of the installed elisp
2022 libraries. However, if it appears that Vload_path was changed
2023 from the default before dumping, don't override that value. */
2026 Lisp_Object dump_path
;
2028 dump_path
= decode_env_path (0, PATH_DUMPLOADSEARCH
);
2029 if (! NILP (Fequal (dump_path
, Vload_path
)))
2031 Vload_path
= decode_env_path (0, normal
);
2032 if (!NILP (Vinstallation_directory
))
2034 /* Add to the path the lisp subdir of the
2035 installation dir, if it exists. */
2036 Lisp_Object tem
, tem1
;
2037 tem
= Fexpand_file_name (build_string ("lisp"),
2038 Vinstallation_directory
);
2039 tem1
= Ffile_exists_p (tem
);
2042 if (NILP (Fmember (tem
, Vload_path
)))
2043 Vload_path
= nconc2 (Vload_path
, Fcons (tem
, Qnil
));
2046 /* That dir doesn't exist, so add the build-time
2047 Lisp dirs instead. */
2048 Vload_path
= nconc2 (Vload_path
, dump_path
);
2053 Vload_path
= decode_env_path (0, normal
);
2057 /* When Emacs is invoked over network shares on NT, PATH_LOADSEARCH is
2058 almost never correct, thereby causing a warning to be printed out that
2059 confuses users. Since PATH_LOADSEARCH is always overriden by the
2060 EMACSLOADPATH environment variable below, disable the warning on NT. */
2062 /* Warn if dirs in the *standard* path don't exist. */
2064 Lisp_Object path_tail
;
2066 for (path_tail
= Vload_path
;
2068 path_tail
= XCONS (path_tail
)->cdr
)
2070 Lisp_Object dirfile
;
2071 dirfile
= Fcar (path_tail
);
2072 if (STRINGP (dirfile
))
2074 dirfile
= Fdirectory_file_name (dirfile
);
2075 if (access (XSTRING (dirfile
)->data
, 0) < 0)
2077 "Warning: Lisp directory `%s' does not exist.\n",
2078 XSTRING (Fcar (path_tail
))->data
);
2082 #endif /* WINDOWSNT */
2084 /* If the EMACSLOADPATH environment variable is set, use its value.
2085 This doesn't apply if we're dumping. */
2086 if (NILP (Vpurify_flag
)
2087 && egetenv ("EMACSLOADPATH"))
2088 Vload_path
= decode_env_path ("EMACSLOADPATH", normal
);
2092 load_in_progress
= 0;
2094 load_descriptor_list
= Qnil
;
2101 defsubr (&Sread_from_string
);
2103 defsubr (&Sintern_soft
);
2104 defsubr (&Sunintern
);
2106 defsubr (&Seval_buffer
);
2107 defsubr (&Seval_region
);
2108 defsubr (&Sread_char
);
2109 defsubr (&Sread_char_exclusive
);
2110 defsubr (&Sread_event
);
2111 defsubr (&Sget_file_char
);
2112 defsubr (&Smapatoms
);
2114 DEFVAR_LISP ("obarray", &Vobarray
,
2115 "Symbol table for use by `intern' and `read'.\n\
2116 It is a vector whose length ought to be prime for best results.\n\
2117 The vector's contents don't make sense if examined from Lisp programs;\n\
2118 to find all the symbols in an obarray, use `mapatoms'.");
2120 DEFVAR_LISP ("values", &Vvalues
,
2121 "List of values of all expressions which were read, evaluated and printed.\n\
2122 Order is reverse chronological.");
2124 DEFVAR_LISP ("standard-input", &Vstandard_input
,
2125 "Stream for read to get input from.\n\
2126 See documentation of `read' for possible values.");
2127 Vstandard_input
= Qt
;
2129 DEFVAR_LISP ("load-path", &Vload_path
,
2130 "*List of directories to search for files to load.\n\
2131 Each element is a string (directory name) or nil (try default directory).\n\
2132 Initialized based on EMACSLOADPATH environment variable, if any,\n\
2133 otherwise to default specified by file `paths.h' when Emacs was built.");
2135 DEFVAR_BOOL ("load-in-progress", &load_in_progress
,
2136 "Non-nil iff inside of `load'.");
2138 DEFVAR_LISP ("after-load-alist", &Vafter_load_alist
,
2139 "An alist of expressions to be evalled when particular files are loaded.\n\
2140 Each element looks like (FILENAME FORMS...).\n\
2141 When `load' is run and the file-name argument is FILENAME,\n\
2142 the FORMS in the corresponding element are executed at the end of loading.\n\n\
2143 FILENAME must match exactly! Normally FILENAME is the name of a library,\n\
2144 with no directory specified, since that is how `load' is normally called.\n\
2145 An error in FORMS does not undo the load,\n\
2146 but does prevent execution of the rest of the FORMS.");
2147 Vafter_load_alist
= Qnil
;
2149 DEFVAR_LISP ("load-history", &Vload_history
,
2150 "Alist mapping source file names to symbols and features.\n\
2151 Each alist element is a list that starts with a file name,\n\
2152 except for one element (optional) that starts with nil and describes\n\
2153 definitions evaluated from buffers not visiting files.\n\
2154 The remaining elements of each list are symbols defined as functions\n\
2155 or variables, and cons cells `(provide . FEATURE)' and `(require . FEATURE)'.");
2156 Vload_history
= Qnil
;
2158 DEFVAR_LISP ("load-file-name", &Vload_file_name
,
2159 "Full name of file being loaded by `load'.");
2160 Vload_file_name
= Qnil
;
2162 DEFVAR_LISP ("current-load-list", &Vcurrent_load_list
,
2163 "Used for internal purposes by `load'.");
2164 Vcurrent_load_list
= Qnil
;
2166 DEFVAR_LISP ("load-read-function", &Vload_read_function
,
2167 "Function used by `load' and `eval-region' for reading expressions.\n\
2168 The default is nil, which means use the function `read'.");
2169 Vload_read_function
= Qnil
;
2171 load_descriptor_list
= Qnil
;
2172 staticpro (&load_descriptor_list
);
2174 Qcurrent_load_list
= intern ("current-load-list");
2175 staticpro (&Qcurrent_load_list
);
2177 Qstandard_input
= intern ("standard-input");
2178 staticpro (&Qstandard_input
);
2180 Qread_char
= intern ("read-char");
2181 staticpro (&Qread_char
);
2183 Qget_file_char
= intern ("get-file-char");
2184 staticpro (&Qget_file_char
);
2186 Qascii_character
= intern ("ascii-character");
2187 staticpro (&Qascii_character
);
2189 Qload
= intern ("load");
2192 Qload_file_name
= intern ("load-file-name");
2193 staticpro (&Qload_file_name
);