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, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
25 #include <sys/types.h>
36 #include "termhooks.h"
40 #include <sys/inode.h>
45 #include <unistd.h> /* to get X_OK */
54 #ifdef LISP_FLOAT_TYPE
60 #endif /* LISP_FLOAT_TYPE */
64 #endif /* HAVE_SETLOCALE */
72 Lisp_Object Qread_char
, Qget_file_char
, Qstandard_input
, Qcurrent_load_list
;
73 Lisp_Object Qvariable_documentation
, Vvalues
, Vstandard_input
, Vafter_load_alist
;
74 Lisp_Object Qascii_character
, Qload
, Qload_file_name
;
75 Lisp_Object Qbackquote
, Qcomma
, Qcomma_at
, Qcomma_dot
, Qfunction
;
76 Lisp_Object Qinhibit_file_name_operation
;
78 extern Lisp_Object Qevent_symbol_element_mask
;
79 extern Lisp_Object Qfile_exists_p
;
81 /* non-zero if inside `load' */
84 /* Directory in which the sources were found. */
85 Lisp_Object Vsource_directory
;
87 /* Search path for files to be loaded. */
88 Lisp_Object Vload_path
;
90 /* This is the user-visible association list that maps features to
91 lists of defs in their load files. */
92 Lisp_Object Vload_history
;
94 /* This is used to build the load history. */
95 Lisp_Object Vcurrent_load_list
;
97 /* Name of file actually being read by `load'. */
98 Lisp_Object Vload_file_name
;
100 /* Function to use for reading, in `load' and friends. */
101 Lisp_Object Vload_read_function
;
103 /* The association list of objects read with the #n=object form.
104 Each member of the list has the form (n . object), and is used to
105 look up the object for the corresponding #n# construct.
106 It must be set to nil before all top-level calls to read0. */
107 Lisp_Object read_objects
;
109 /* Nonzero means load should forcibly load all dynamic doc strings. */
110 static int load_force_doc_strings
;
112 /* List of descriptors now open for Fload. */
113 static Lisp_Object load_descriptor_list
;
115 /* File for get_file_char to read from. Use by load. */
116 static FILE *instream
;
118 /* When nonzero, read conses in pure space */
119 static int read_pure
;
121 /* For use within read-from-string (this reader is non-reentrant!!) */
122 static int read_from_string_index
;
123 static int read_from_string_limit
;
125 /* This contains the last string skipped with #@. */
126 static char *saved_doc_string
;
127 /* Length of buffer allocated in saved_doc_string. */
128 static int saved_doc_string_size
;
129 /* Length of actual data in saved_doc_string. */
130 static int saved_doc_string_length
;
131 /* This is the file position that string came from. */
132 static int saved_doc_string_position
;
134 /* Nonzero means inside a new-style backquote
135 with no surrounding parentheses.
136 Fread initializes this to zero, so we need not specbind it
137 or worry about what happens to it when there is an error. */
138 static int new_backquote_flag
;
140 /* Handle unreading and rereading of characters.
141 Write READCHAR to read a character,
142 UNREAD(c) to unread c to be read again. */
144 #define READCHAR readchar (readcharfun)
145 #define UNREAD(c) unreadchar (readcharfun, c)
148 readchar (readcharfun
)
149 Lisp_Object readcharfun
;
152 register struct buffer
*inbuffer
;
153 register int c
, mpos
;
155 if (BUFFERP (readcharfun
))
157 inbuffer
= XBUFFER (readcharfun
);
159 if (BUF_PT (inbuffer
) >= BUF_ZV (inbuffer
))
161 c
= *(unsigned char *) BUF_CHAR_ADDRESS (inbuffer
, BUF_PT (inbuffer
));
162 SET_BUF_PT (inbuffer
, BUF_PT (inbuffer
) + 1);
166 if (MARKERP (readcharfun
))
168 inbuffer
= XMARKER (readcharfun
)->buffer
;
170 mpos
= marker_position (readcharfun
);
172 if (mpos
> BUF_ZV (inbuffer
) - 1)
174 c
= *(unsigned char *) BUF_CHAR_ADDRESS (inbuffer
, mpos
);
175 if (mpos
!= BUF_GPT (inbuffer
))
176 XMARKER (readcharfun
)->bufpos
++;
178 Fset_marker (readcharfun
, make_number (mpos
+ 1),
179 Fmarker_buffer (readcharfun
));
182 if (EQ (readcharfun
, Qget_file_char
))
186 /* Interrupted reads have been observed while reading over the network */
187 while (c
== EOF
&& ferror (instream
) && errno
== EINTR
)
196 if (STRINGP (readcharfun
))
199 /* This used to be return of a conditional expression,
200 but that truncated -1 to a char on VMS. */
201 if (read_from_string_index
< read_from_string_limit
)
202 c
= XSTRING (readcharfun
)->data
[read_from_string_index
++];
208 tem
= call0 (readcharfun
);
215 /* Unread the character C in the way appropriate for the stream READCHARFUN.
216 If the stream is a user function, call it with the char as argument. */
219 unreadchar (readcharfun
, c
)
220 Lisp_Object readcharfun
;
224 /* Don't back up the pointer if we're unreading the end-of-input mark,
225 since readchar didn't advance it when we read it. */
227 else if (BUFFERP (readcharfun
))
229 if (XBUFFER (readcharfun
) == current_buffer
)
232 SET_BUF_PT (XBUFFER (readcharfun
), BUF_PT (XBUFFER (readcharfun
)) - 1);
234 else if (MARKERP (readcharfun
))
235 XMARKER (readcharfun
)->bufpos
--;
236 else if (STRINGP (readcharfun
))
237 read_from_string_index
--;
238 else if (EQ (readcharfun
, Qget_file_char
))
239 ungetc (c
, instream
);
241 call1 (readcharfun
, make_number (c
));
244 static Lisp_Object
read0 (), read1 (), read_list (), read_vector ();
246 /* get a character from the tty */
248 extern Lisp_Object
read_char ();
250 /* Read input events until we get one that's acceptable for our purposes.
252 If NO_SWITCH_FRAME is non-zero, switch-frame events are stashed
253 until we get a character we like, and then stuffed into
256 If ASCII_REQUIRED is non-zero, we check function key events to see
257 if the unmodified version of the symbol has a Qascii_character
258 property, and use that character, if present.
260 If ERROR_NONASCII is non-zero, we signal an error if the input we
261 get isn't an ASCII character with modifiers. If it's zero but
262 ASCII_REQUIRED is non-zero, we just re-read until we get an ASCII
266 read_filtered_event (no_switch_frame
, ascii_required
, error_nonascii
)
267 int no_switch_frame
, ascii_required
, error_nonascii
;
270 return make_number (getchar ());
272 register Lisp_Object val
, delayed_switch_frame
;
274 delayed_switch_frame
= Qnil
;
276 /* Read until we get an acceptable event. */
278 val
= read_char (0, 0, 0, Qnil
, 0);
283 /* switch-frame events are put off until after the next ASCII
284 character. This is better than signaling an error just because
285 the last characters were typed to a separate minibuffer frame,
286 for example. Eventually, some code which can deal with
287 switch-frame events will read it and process it. */
289 && EVENT_HAS_PARAMETERS (val
)
290 && EQ (EVENT_HEAD (val
), Qswitch_frame
))
292 delayed_switch_frame
= val
;
298 /* Convert certain symbols to their ASCII equivalents. */
301 Lisp_Object tem
, tem1
, tem2
;
302 tem
= Fget (val
, Qevent_symbol_element_mask
);
305 tem1
= Fget (Fcar (tem
), Qascii_character
);
306 /* Merge this symbol's modifier bits
307 with the ASCII equivalent of its basic code. */
309 XSETFASTINT (val
, XINT (tem1
) | XINT (Fcar (Fcdr (tem
))));
313 /* If we don't have a character now, deal with it appropriately. */
318 Vunread_command_events
= Fcons (val
, Qnil
);
319 error ("Non-character input-event");
326 if (! NILP (delayed_switch_frame
))
327 unread_switch_frame
= delayed_switch_frame
;
333 DEFUN ("read-char", Fread_char
, Sread_char
, 0, 0, 0,
334 "Read a character from the command input (keyboard or macro).\n\
335 It is returned as a number.\n\
336 If the user generates an event which is not a character (i.e. a mouse\n\
337 click or function key event), `read-char' signals an error. As an\n\
338 exception, switch-frame events are put off until non-ASCII events can\n\
340 If you want to read non-character events, or ignore them, call\n\
341 `read-event' or `read-char-exclusive' instead.")
344 return read_filtered_event (1, 1, 1);
347 DEFUN ("read-event", Fread_event
, Sread_event
, 0, 0, 0,
348 "Read an event object from the input stream.")
351 return read_filtered_event (0, 0, 0);
354 DEFUN ("read-char-exclusive", Fread_char_exclusive
, Sread_char_exclusive
, 0, 0, 0,
355 "Read a character from the command input (keyboard or macro).\n\
356 It is returned as a number. Non-character events are ignored.")
359 return read_filtered_event (1, 1, 0);
362 DEFUN ("get-file-char", Fget_file_char
, Sget_file_char
, 0, 0, 0,
363 "Don't use this yourself.")
366 register Lisp_Object val
;
367 XSETINT (val
, getc (instream
));
371 static void readevalloop ();
372 static Lisp_Object
load_unwind ();
373 static Lisp_Object
load_descriptor_unwind ();
375 DEFUN ("load", Fload
, Sload
, 1, 4, 0,
376 "Execute a file of Lisp code named FILE.\n\
377 First try FILE with `.elc' appended, then try with `.el',\n\
378 then try FILE unmodified.\n\
379 This function searches the directories in `load-path'.\n\
380 If optional second arg NOERROR is non-nil,\n\
381 report no error if FILE doesn't exist.\n\
382 Print messages at start and end of loading unless\n\
383 optional third arg NOMESSAGE is non-nil.\n\
384 If optional fourth arg NOSUFFIX is non-nil, don't try adding\n\
385 suffixes `.elc' or `.el' to the specified name FILE.\n\
386 Return t if file exists.")
387 (file
, noerror
, nomessage
, nosuffix
)
388 Lisp_Object file
, noerror
, nomessage
, nosuffix
;
390 register FILE *stream
;
391 register int fd
= -1;
392 register Lisp_Object lispstream
;
393 int count
= specpdl_ptr
- specpdl
;
397 /* 1 means we printed the ".el is newer" message. */
399 /* 1 means we are loading a compiled file. */
403 char *dosmode
= "rt";
406 CHECK_STRING (file
, 0);
408 /* If file name is magic, call the handler. */
409 handler
= Ffind_file_name_handler (file
, Qload
);
411 return call5 (handler
, Qload
, file
, noerror
, nomessage
, nosuffix
);
413 /* Do this after the handler to avoid
414 the need to gcpro noerror, nomessage and nosuffix.
415 (Below here, we care only whether they are nil or not.) */
416 file
= Fsubstitute_in_file_name (file
);
418 /* Avoid weird lossage with null string as arg,
419 since it would try to load a directory as a Lisp file */
420 if (XSTRING (file
)->size
> 0)
423 fd
= openp (Vload_path
, file
, !NILP (nosuffix
) ? "" : ".elc:.el:",
432 Fsignal (Qfile_error
, Fcons (build_string ("Cannot open load file"),
433 Fcons (file
, Qnil
)));
438 /* If FD is 0, that means openp found a remote file. */
441 handler
= Ffind_file_name_handler (found
, Qload
);
442 return call5 (handler
, Qload
, found
, noerror
, nomessage
, Qt
);
445 if (!bcmp (&(XSTRING (found
)->data
[XSTRING (found
)->size
- 4]),
456 stat ((char *)XSTRING (found
)->data
, &s1
);
457 XSTRING (found
)->data
[XSTRING (found
)->size
- 1] = 0;
458 result
= stat ((char *)XSTRING (found
)->data
, &s2
);
459 if (result
>= 0 && (unsigned) s1
.st_mtime
< (unsigned) s2
.st_mtime
)
461 /* Make the progress messages mention that source is newer. */
464 /* If we won't print another message, mention this anyway. */
465 if (! NILP (nomessage
))
466 message ("Source file `%s' newer than byte-compiled file",
467 XSTRING (found
)->data
);
469 XSTRING (found
)->data
[XSTRING (found
)->size
- 1] = 'c';
474 stream
= fopen ((char *) XSTRING (found
)->data
, dosmode
);
475 #else /* not DOS_NT */
476 stream
= fdopen (fd
, "r");
477 #endif /* not DOS_NT */
481 error ("Failure to create stdio stream for %s", XSTRING (file
)->data
);
484 if (NILP (nomessage
))
487 message ("Loading %s (compiled; note, source file is newer)...",
488 XSTRING (file
)->data
);
490 message ("Loading %s (compiled)...", XSTRING (file
)->data
);
492 message ("Loading %s...", XSTRING (file
)->data
);
496 lispstream
= Fcons (Qnil
, Qnil
);
497 XSETFASTINT (XCONS (lispstream
)->car
, (EMACS_UINT
)stream
>> 16);
498 XSETFASTINT (XCONS (lispstream
)->cdr
, (EMACS_UINT
)stream
& 0xffff);
499 record_unwind_protect (load_unwind
, lispstream
);
500 record_unwind_protect (load_descriptor_unwind
, load_descriptor_list
);
501 specbind (Qload_file_name
, found
);
502 specbind (Qinhibit_file_name_operation
, Qnil
);
504 = Fcons (make_number (fileno (stream
)), load_descriptor_list
);
506 readevalloop (Qget_file_char
, stream
, file
, Feval
, 0);
507 unbind_to (count
, Qnil
);
509 /* Run any load-hooks for this file. */
510 temp
= Fassoc (file
, Vafter_load_alist
);
512 Fprogn (Fcdr (temp
));
515 if (saved_doc_string
)
516 free (saved_doc_string
);
517 saved_doc_string
= 0;
518 saved_doc_string_size
= 0;
520 if (!noninteractive
&& NILP (nomessage
))
523 message ("Loading %s (compiled; note, source file is newer)...done",
524 XSTRING (file
)->data
);
526 message ("Loading %s (compiled)...done", XSTRING (file
)->data
);
528 message ("Loading %s...done", XSTRING (file
)->data
);
534 load_unwind (stream
) /* used as unwind-protect function in load */
537 fclose ((FILE *) (XFASTINT (XCONS (stream
)->car
) << 16
538 | XFASTINT (XCONS (stream
)->cdr
)));
539 if (--load_in_progress
< 0) load_in_progress
= 0;
544 load_descriptor_unwind (oldlist
)
547 load_descriptor_list
= oldlist
;
551 /* Close all descriptors in use for Floads.
552 This is used when starting a subprocess. */
559 for (tail
= load_descriptor_list
; !NILP (tail
); tail
= XCONS (tail
)->cdr
)
560 close (XFASTINT (XCONS (tail
)->car
));
565 complete_filename_p (pathname
)
566 Lisp_Object pathname
;
568 register unsigned char *s
= XSTRING (pathname
)->data
;
569 return (IS_DIRECTORY_SEP (s
[0])
570 || (XSTRING (pathname
)->size
> 2
571 && IS_DEVICE_SEP (s
[1]) && IS_DIRECTORY_SEP (s
[2]))
581 /* Search for a file whose name is STR, looking in directories
582 in the Lisp list PATH, and trying suffixes from SUFFIX.
583 SUFFIX is a string containing possible suffixes separated by colons.
584 On success, returns a file descriptor. On failure, returns -1.
586 EXEC_ONLY nonzero means don't open the files,
587 just look for one that is executable. In this case,
588 returns 1 on success.
590 If STOREPTR is nonzero, it points to a slot where the name of
591 the file actually found should be stored as a Lisp string.
592 nil is stored there on failure.
594 If the file we find is remote, return 0
595 but store the found remote file name in *STOREPTR.
596 We do not check for remote files if EXEC_ONLY is nonzero. */
599 openp (path
, str
, suffix
, storeptr
, exec_only
)
600 Lisp_Object path
, str
;
602 Lisp_Object
*storeptr
;
608 register char *fn
= buf
;
611 Lisp_Object filename
;
619 if (complete_filename_p (str
))
622 for (; !NILP (path
); path
= Fcdr (path
))
626 filename
= Fexpand_file_name (str
, Fcar (path
));
627 if (!complete_filename_p (filename
))
628 /* If there are non-absolute elts in PATH (eg ".") */
629 /* Of course, this could conceivably lose if luser sets
630 default-directory to be something non-absolute... */
632 filename
= Fexpand_file_name (filename
, current_buffer
->directory
);
633 if (!complete_filename_p (filename
))
634 /* Give up on this path element! */
638 /* Calculate maximum size of any filename made from
639 this path element/specified file name and any possible suffix. */
640 want_size
= strlen (suffix
) + XSTRING (filename
)->size
+ 1;
641 if (fn_size
< want_size
)
642 fn
= (char *) alloca (fn_size
= 100 + want_size
);
646 /* Loop over suffixes. */
649 char *esuffix
= (char *) index (nsuffix
, ':');
650 int lsuffix
= esuffix
? esuffix
- nsuffix
: strlen (nsuffix
);
653 /* Concatenate path element/specified name with the suffix.
654 If the directory starts with /:, remove that. */
655 if (XSTRING (filename
)->size
> 2
656 && XSTRING (filename
)->data
[0] == '/'
657 && XSTRING (filename
)->data
[1] == ':')
659 strncpy (fn
, XSTRING (filename
)->data
+ 2,
660 XSTRING (filename
)->size
- 2);
661 fn
[XSTRING (filename
)->size
- 2] = 0;
665 strncpy (fn
, XSTRING (filename
)->data
, XSTRING (filename
)->size
);
666 fn
[XSTRING (filename
)->size
] = 0;
669 if (lsuffix
!= 0) /* Bug happens on CCI if lsuffix is 0. */
670 strncat (fn
, nsuffix
, lsuffix
);
672 /* Check that the file exists and is not a directory. */
676 handler
= Ffind_file_name_handler (filename
, Qfile_exists_p
);
677 if (! NILP (handler
) && ! exec_only
)
682 string
= build_string (fn
);
683 exists
= ! NILP (exec_only
? Ffile_executable_p (string
)
684 : Ffile_readable_p (string
));
686 && ! NILP (Ffile_directory_p (build_string (fn
))))
691 /* We succeeded; return this descriptor and filename. */
693 *storeptr
= build_string (fn
);
700 int exists
= (stat (fn
, &st
) >= 0
701 && (st
.st_mode
& S_IFMT
) != S_IFDIR
);
704 /* Check that we can access or open it. */
706 fd
= (access (fn
, X_OK
) == 0) ? 1 : -1;
708 fd
= open (fn
, O_RDONLY
, 0);
712 /* We succeeded; return this descriptor and filename. */
714 *storeptr
= build_string (fn
);
721 /* Advance to next suffix. */
724 nsuffix
+= lsuffix
+ 1;
735 /* Merge the list we've accumulated of globals from the current input source
736 into the load_history variable. The details depend on whether
737 the source has an associated file name or not. */
740 build_load_history (stream
, source
)
744 register Lisp_Object tail
, prev
, newelt
;
745 register Lisp_Object tem
, tem2
;
746 register int foundit
, loading
;
748 /* Don't bother recording anything for preloaded files. */
749 if (!NILP (Vpurify_flag
))
752 loading
= stream
|| !NARROWED
;
754 tail
= Vload_history
;
761 /* Find the feature's previous assoc list... */
762 if (!NILP (Fequal (source
, Fcar (tem
))))
766 /* If we're loading, remove it. */
770 Vload_history
= Fcdr (tail
);
772 Fsetcdr (prev
, Fcdr (tail
));
775 /* Otherwise, cons on new symbols that are not already members. */
778 tem2
= Vcurrent_load_list
;
782 newelt
= Fcar (tem2
);
784 if (NILP (Fmemq (newelt
, tem
)))
785 Fsetcar (tail
, Fcons (Fcar (tem
),
786 Fcons (newelt
, Fcdr (tem
))));
799 /* If we're loading, cons the new assoc onto the front of load-history,
800 the most-recently-loaded position. Also do this if we didn't find
801 an existing member for the current source. */
802 if (loading
|| !foundit
)
803 Vload_history
= Fcons (Fnreverse (Vcurrent_load_list
),
808 unreadpure () /* Used as unwind-protect function in readevalloop */
815 readevalloop (readcharfun
, stream
, sourcename
, evalfun
, printflag
)
816 Lisp_Object readcharfun
;
818 Lisp_Object sourcename
;
819 Lisp_Object (*evalfun
) ();
823 register Lisp_Object val
;
824 int count
= specpdl_ptr
- specpdl
;
826 struct buffer
*b
= 0;
828 if (BUFFERP (readcharfun
))
829 b
= XBUFFER (readcharfun
);
830 else if (MARKERP (readcharfun
))
831 b
= XMARKER (readcharfun
)->buffer
;
833 specbind (Qstandard_input
, readcharfun
);
834 specbind (Qcurrent_load_list
, Qnil
);
838 LOADHIST_ATTACH (sourcename
);
842 if (b
!= 0 && NILP (b
->name
))
843 error ("Reading from killed buffer");
849 while ((c
= READCHAR
) != '\n' && c
!= -1);
854 /* Ignore whitespace here, so we can detect eof. */
855 if (c
== ' ' || c
== '\t' || c
== '\n' || c
== '\f' || c
== '\r')
858 if (!NILP (Vpurify_flag
) && c
== '(')
860 int count1
= specpdl_ptr
- specpdl
;
861 record_unwind_protect (unreadpure
, Qnil
);
862 val
= read_list (-1, readcharfun
);
863 unbind_to (count1
, Qnil
);
869 if (NILP (Vload_read_function
))
870 val
= read0 (readcharfun
);
872 val
= call1 (Vload_read_function
, readcharfun
);
875 val
= (*evalfun
) (val
);
878 Vvalues
= Fcons (val
, Vvalues
);
879 if (EQ (Vstandard_output
, Qt
))
886 build_load_history (stream
, sourcename
);
889 unbind_to (count
, Qnil
);
894 DEFUN ("eval-buffer", Feval_buffer
, Seval_buffer
, 0, 2, "",
895 "Execute the current buffer as Lisp code.\n\
896 Programs can pass two arguments, BUFFER and PRINTFLAG.\n\
897 BUFFER is the buffer to evaluate (nil means use current buffer).\n\
898 PRINTFLAG controls printing of output:\n\
899 nil means discard it; anything else is stream for print.\n\
901 This function preserves the position of point.")
903 Lisp_Object buffer
, printflag
;
905 int count
= specpdl_ptr
- specpdl
;
906 Lisp_Object tem
, buf
;
909 buf
= Fcurrent_buffer ();
911 buf
= Fget_buffer (buffer
);
913 error ("No such buffer.");
915 if (NILP (printflag
))
919 specbind (Qstandard_output
, tem
);
920 record_unwind_protect (save_excursion_restore
, save_excursion_save ());
921 BUF_SET_PT (XBUFFER (buf
), BUF_BEGV (XBUFFER (buf
)));
922 readevalloop (buf
, 0, XBUFFER (buf
)->filename
, Feval
, !NILP (printflag
));
923 unbind_to (count
, Qnil
);
929 DEFUN ("eval-current-buffer", Feval_current_buffer
, Seval_current_buffer
, 0, 1, "",
930 "Execute the current buffer as Lisp code.\n\
931 Programs can pass argument PRINTFLAG which controls printing of output:\n\
932 nil means discard it; anything else is stream for print.\n\
934 If there is no error, point does not move. If there is an error,\n\
935 point remains at the end of the last character read from the buffer.")
937 Lisp_Object printflag
;
939 int count
= specpdl_ptr
- specpdl
;
940 Lisp_Object tem
, cbuf
;
942 cbuf
= Fcurrent_buffer ()
944 if (NILP (printflag
))
948 specbind (Qstandard_output
, tem
);
949 record_unwind_protect (save_excursion_restore
, save_excursion_save ());
951 readevalloop (cbuf
, 0, XBUFFER (cbuf
)->filename
, Feval
, !NILP (printflag
));
952 return unbind_to (count
, Qnil
);
956 DEFUN ("eval-region", Feval_region
, Seval_region
, 2, 3, "r",
957 "Execute the region as Lisp code.\n\
958 When called from programs, expects two arguments,\n\
959 giving starting and ending indices in the current buffer\n\
960 of the text to be executed.\n\
961 Programs can pass third argument PRINTFLAG which controls output:\n\
962 nil means discard it; anything else is stream for printing it.\n\
964 If there is no error, point does not move. If there is an error,\n\
965 point remains at the end of the last character read from the buffer.")
966 (start
, end
, printflag
)
967 Lisp_Object start
, end
, printflag
;
969 int count
= specpdl_ptr
- specpdl
;
970 Lisp_Object tem
, cbuf
;
972 cbuf
= Fcurrent_buffer ();
974 if (NILP (printflag
))
978 specbind (Qstandard_output
, tem
);
980 if (NILP (printflag
))
981 record_unwind_protect (save_excursion_restore
, save_excursion_save ());
982 record_unwind_protect (save_restriction_restore
, save_restriction_save ());
984 /* This both uses start and checks its type. */
986 Fnarrow_to_region (make_number (BEGV
), end
);
987 readevalloop (cbuf
, 0, XBUFFER (cbuf
)->filename
, Feval
, !NILP (printflag
));
989 return unbind_to (count
, Qnil
);
992 #endif /* standalone */
994 DEFUN ("read", Fread
, Sread
, 0, 1, 0,
995 "Read one Lisp expression as text from STREAM, return as Lisp object.\n\
996 If STREAM is nil, use the value of `standard-input' (which see).\n\
997 STREAM or the value of `standard-input' may be:\n\
998 a buffer (read from point and advance it)\n\
999 a marker (read from where it points and advance it)\n\
1000 a function (call it with no arguments for each character,\n\
1001 call it with a char as argument to push a char back)\n\
1002 a string (takes text from string, starting at the beginning)\n\
1003 t (read text line using minibuffer and use it).")
1007 extern Lisp_Object
Fread_minibuffer ();
1010 stream
= Vstandard_input
;
1011 if (EQ (stream
, Qt
))
1012 stream
= Qread_char
;
1014 new_backquote_flag
= 0;
1015 read_objects
= Qnil
;
1018 if (EQ (stream
, Qread_char
))
1019 return Fread_minibuffer (build_string ("Lisp expression: "), Qnil
);
1022 if (STRINGP (stream
))
1023 return Fcar (Fread_from_string (stream
, Qnil
, Qnil
));
1025 return read0 (stream
);
1028 DEFUN ("read-from-string", Fread_from_string
, Sread_from_string
, 1, 3, 0,
1029 "Read one Lisp expression which is represented as text by STRING.\n\
1030 Returns a cons: (OBJECT-READ . FINAL-STRING-INDEX).\n\
1031 START and END optionally delimit a substring of STRING from which to read;\n\
1032 they default to 0 and (length STRING) respectively.")
1033 (string
, start
, end
)
1034 Lisp_Object string
, start
, end
;
1036 int startval
, endval
;
1039 CHECK_STRING (string
,0);
1042 endval
= XSTRING (string
)->size
;
1044 { CHECK_NUMBER (end
,2);
1045 endval
= XINT (end
);
1046 if (endval
< 0 || endval
> XSTRING (string
)->size
)
1047 args_out_of_range (string
, end
);
1053 { CHECK_NUMBER (start
,1);
1054 startval
= XINT (start
);
1055 if (startval
< 0 || startval
> endval
)
1056 args_out_of_range (string
, start
);
1059 read_from_string_index
= startval
;
1060 read_from_string_limit
= endval
;
1062 new_backquote_flag
= 0;
1063 read_objects
= Qnil
;
1065 tem
= read0 (string
);
1066 return Fcons (tem
, make_number (read_from_string_index
));
1069 /* Use this for recursive reads, in contexts where internal tokens
1073 Lisp_Object readcharfun
;
1075 register Lisp_Object val
;
1078 val
= read1 (readcharfun
, &c
, 0);
1080 Fsignal (Qinvalid_read_syntax
, Fcons (make_string (&c
, 1), Qnil
));
1085 static int read_buffer_size
;
1086 static char *read_buffer
;
1089 read_escape (readcharfun
)
1090 Lisp_Object readcharfun
;
1092 register int c
= READCHAR
;
1096 error ("End of file");
1122 error ("Invalid escape character syntax");
1125 c
= read_escape (readcharfun
);
1126 return c
| meta_modifier
;
1131 error ("Invalid escape character syntax");
1134 c
= read_escape (readcharfun
);
1135 return c
| shift_modifier
;
1140 error ("Invalid escape character syntax");
1143 c
= read_escape (readcharfun
);
1144 return c
| hyper_modifier
;
1149 error ("Invalid escape character syntax");
1152 c
= read_escape (readcharfun
);
1153 return c
| alt_modifier
;
1158 error ("Invalid escape character syntax");
1161 c
= read_escape (readcharfun
);
1162 return c
| super_modifier
;
1167 error ("Invalid escape character syntax");
1171 c
= read_escape (readcharfun
);
1172 if ((c
& 0177) == '?')
1174 /* ASCII control chars are made from letters (both cases),
1175 as well as the non-letters within 0100...0137. */
1176 else if ((c
& 0137) >= 0101 && (c
& 0137) <= 0132)
1177 return (c
& (037 | ~0177));
1178 else if ((c
& 0177) >= 0100 && (c
& 0177) <= 0137)
1179 return (c
& (037 | ~0177));
1181 return c
| ctrl_modifier
;
1191 /* An octal escape, as in ANSI C. */
1193 register int i
= c
- '0';
1194 register int count
= 0;
1197 if ((c
= READCHAR
) >= '0' && c
<= '7')
1212 /* A hex escape, as in ANSI C. */
1218 if (c
>= '0' && c
<= '9')
1223 else if ((c
>= 'a' && c
<= 'f')
1224 || (c
>= 'A' && c
<= 'F'))
1227 if (c
>= 'a' && c
<= 'f')
1246 /* If the next token is ')' or ']' or '.', we store that character
1247 in *PCH and the return value is not interesting. Else, we store
1248 zero in *PCH and we read and return one lisp object.
1250 FIRST_IN_LIST is nonzero if this is the first element of a list. */
1253 read1 (readcharfun
, pch
, first_in_list
)
1254 register Lisp_Object readcharfun
;
1259 int uninterned_symbol
= 0;
1266 if (c
< 0) return Fsignal (Qend_of_file
, Qnil
);
1271 return read_list (0, readcharfun
);
1274 return read_vector (readcharfun
);
1291 tmp
= read_vector (readcharfun
);
1292 if (XVECTOR (tmp
)->size
< CHAR_TABLE_STANDARD_SLOTS
1293 || XVECTOR (tmp
)->size
> CHAR_TABLE_STANDARD_SLOTS
+ 10)
1294 error ("Invalid size char-table");
1295 XSETCHAR_TABLE (tmp
, XCHAR_TABLE (tmp
));
1298 Fsignal (Qinvalid_read_syntax
, Fcons (make_string ("#^", 2), Qnil
));
1303 length
= read1 (readcharfun
, pch
, first_in_list
);
1307 Lisp_Object tmp
, val
;
1308 int size_in_chars
= ((XFASTINT (length
) + BITS_PER_CHAR
- 1)
1312 tmp
= read1 (readcharfun
, pch
, first_in_list
);
1313 if (size_in_chars
!= XSTRING (tmp
)->size
1314 /* We used to print 1 char too many
1315 when the number of bits was a multiple of 8.
1316 Accept such input in case it came from an old version. */
1317 && ! (XFASTINT (length
)
1318 == (XSTRING (tmp
)->size
- 1) * BITS_PER_CHAR
))
1319 Fsignal (Qinvalid_read_syntax
,
1320 Fcons (make_string ("#&...", 5), Qnil
));
1322 val
= Fmake_bool_vector (length
, Qnil
);
1323 bcopy (XSTRING (tmp
)->data
, XBOOL_VECTOR (val
)->data
,
1327 Fsignal (Qinvalid_read_syntax
, Fcons (make_string ("#&...", 5),
1332 /* Accept compiled functions at read-time so that we don't have to
1333 build them using function calls. */
1335 tmp
= read_vector (readcharfun
);
1336 return Fmake_byte_code (XVECTOR (tmp
)->size
,
1337 XVECTOR (tmp
)->contents
);
1339 #ifdef USE_TEXT_PROPERTIES
1343 struct gcpro gcpro1
;
1346 /* Read the string itself. */
1347 tmp
= read1 (readcharfun
, &ch
, 0);
1348 if (ch
!= 0 || !STRINGP (tmp
))
1349 Fsignal (Qinvalid_read_syntax
, Fcons (make_string ("#", 1), Qnil
));
1351 /* Read the intervals and their properties. */
1354 Lisp_Object beg
, end
, plist
;
1356 beg
= read1 (readcharfun
, &ch
, 0);
1360 end
= read1 (readcharfun
, &ch
, 0);
1362 plist
= read1 (readcharfun
, &ch
, 0);
1364 Fsignal (Qinvalid_read_syntax
,
1365 Fcons (build_string ("invalid string property list"),
1367 Fset_text_properties (beg
, end
, plist
, tmp
);
1373 /* #@NUMBER is used to skip NUMBER following characters.
1374 That's used in .elc files to skip over doc strings
1375 and function definitions. */
1380 /* Read a decimal integer. */
1381 while ((c
= READCHAR
) >= 0
1382 && c
>= '0' && c
<= '9')
1390 #ifndef DOS_NT /* I don't know if filepos works right on MSDOS and Windoze. */
1391 if (load_force_doc_strings
&& EQ (readcharfun
, Qget_file_char
))
1393 /* If we are supposed to force doc strings into core right now,
1394 record the last string that we skipped,
1395 and record where in the file it comes from. */
1396 if (saved_doc_string_size
== 0)
1398 saved_doc_string_size
= nskip
+ 100;
1399 saved_doc_string
= (char *) xmalloc (saved_doc_string_size
);
1401 if (nskip
> saved_doc_string_size
)
1403 saved_doc_string_size
= nskip
+ 100;
1404 saved_doc_string
= (char *) xrealloc (saved_doc_string
,
1405 saved_doc_string_size
);
1408 saved_doc_string_position
= ftell (instream
);
1410 /* Copy that many characters into saved_doc_string. */
1411 for (i
= 0; i
< nskip
&& c
>= 0; i
++)
1412 saved_doc_string
[i
] = c
= READCHAR
;
1414 saved_doc_string_length
= i
;
1417 #endif /* not DOS_NT */
1419 /* Skip that many characters. */
1420 for (i
= 0; i
< nskip
&& c
>= 0; i
++)
1426 return Vload_file_name
;
1428 return Fcons (Qfunction
, Fcons (read0 (readcharfun
), Qnil
));
1429 /* #:foo is the uninterned symbol named foo. */
1432 uninterned_symbol
= 1;
1436 /* Reader forms that can reuse previously read objects. */
1437 if (c
>= '0' && c
<= '9')
1442 /* Read a non-negative integer. */
1443 while (c
>= '0' && c
<= '9')
1449 /* #n=object returns object, but associates it with n for #n#. */
1452 tem
= read0 (readcharfun
);
1453 read_objects
= Fcons (Fcons (make_number (n
), tem
), read_objects
);
1456 /* #n# returns a previously read object. */
1459 tem
= Fassq (make_number (n
), read_objects
);
1462 /* Fall through to error message. */
1464 /* Fall through to error message. */
1468 Fsignal (Qinvalid_read_syntax
, Fcons (make_string ("#", 1), Qnil
));
1471 while ((c
= READCHAR
) >= 0 && c
!= '\n');
1476 return Fcons (Qquote
, Fcons (read0 (readcharfun
), Qnil
));
1486 new_backquote_flag
= 1;
1487 value
= read0 (readcharfun
);
1488 new_backquote_flag
= 0;
1490 return Fcons (Qbackquote
, Fcons (value
, Qnil
));
1494 if (new_backquote_flag
)
1496 Lisp_Object comma_type
= Qnil
;
1501 comma_type
= Qcomma_at
;
1503 comma_type
= Qcomma_dot
;
1506 if (ch
>= 0) UNREAD (ch
);
1507 comma_type
= Qcomma
;
1510 new_backquote_flag
= 0;
1511 value
= read0 (readcharfun
);
1512 new_backquote_flag
= 1;
1513 return Fcons (comma_type
, Fcons (value
, Qnil
));
1520 register Lisp_Object val
;
1523 if (c
< 0) return Fsignal (Qend_of_file
, Qnil
);
1526 XSETINT (val
, read_escape (readcharfun
));
1535 register char *p
= read_buffer
;
1536 register char *end
= read_buffer
+ read_buffer_size
;
1540 while ((c
= READCHAR
) >= 0
1545 char *new = (char *) xrealloc (read_buffer
, read_buffer_size
*= 2);
1546 p
+= new - read_buffer
;
1547 read_buffer
+= new - read_buffer
;
1548 end
= read_buffer
+ read_buffer_size
;
1551 c
= read_escape (readcharfun
);
1552 /* c is -1 if \ newline has just been seen */
1555 if (p
== read_buffer
)
1560 /* Allow `\C- ' and `\C-?'. */
1561 if (c
== (CHAR_CTL
| ' '))
1563 else if (c
== (CHAR_CTL
| '?'))
1567 /* Move the meta bit to the right place for a string. */
1568 c
= (c
& ~CHAR_META
) | 0x80;
1570 error ("Invalid modifier in string");
1574 if (c
< 0) return Fsignal (Qend_of_file
, Qnil
);
1576 /* If purifying, and string starts with \ newline,
1577 return zero instead. This is for doc strings
1578 that we are really going to find in etc/DOC.nn.nn */
1579 if (!NILP (Vpurify_flag
) && NILP (Vdoc_file_name
) && cancel
)
1580 return make_number (0);
1583 return make_pure_string (read_buffer
, p
- read_buffer
);
1585 return make_string (read_buffer
, p
- read_buffer
);
1590 #ifdef LISP_FLOAT_TYPE
1591 /* If a period is followed by a number, then we should read it
1592 as a floating point number. Otherwise, it denotes a dotted
1594 int next_char
= READCHAR
;
1597 if (! (next_char
>= '0' && next_char
<= '9'))
1604 /* Otherwise, we fall through! Note that the atom-reading loop
1605 below will now loop at least once, assuring that we will not
1606 try to UNREAD two characters in a row. */
1610 if (c
<= 040) goto retry
;
1612 register char *p
= read_buffer
;
1616 register char *end
= read_buffer
+ read_buffer_size
;
1619 !(c
== '\"' || c
== '\'' || c
== ';' || c
== '?'
1620 || c
== '(' || c
== ')'
1621 #ifndef LISP_FLOAT_TYPE
1622 /* If we have floating-point support, then we need
1623 to allow <digits><dot><digits>. */
1625 #endif /* not LISP_FLOAT_TYPE */
1626 || c
== '[' || c
== ']' || c
== '#'
1631 register char *new = (char *) xrealloc (read_buffer
, read_buffer_size
*= 2);
1632 p
+= new - read_buffer
;
1633 read_buffer
+= new - read_buffer
;
1634 end
= read_buffer
+ read_buffer_size
;
1647 char *new = (char *) xrealloc (read_buffer
, read_buffer_size
*= 2);
1648 p
+= new - read_buffer
;
1649 read_buffer
+= new - read_buffer
;
1650 /* end = read_buffer + read_buffer_size; */
1657 if (!quoted
&& !uninterned_symbol
)
1660 register Lisp_Object val
;
1662 if (*p1
== '+' || *p1
== '-') p1
++;
1663 /* Is it an integer? */
1666 while (p1
!= p
&& (c
= *p1
) >= '0' && c
<= '9') p1
++;
1667 #ifdef LISP_FLOAT_TYPE
1668 /* Integers can have trailing decimal points. */
1669 if (p1
> read_buffer
&& p1
< p
&& *p1
== '.') p1
++;
1672 /* It is an integer. */
1674 #ifdef LISP_FLOAT_TYPE
1678 if (sizeof (int) == sizeof (EMACS_INT
))
1679 XSETINT (val
, atoi (read_buffer
));
1680 else if (sizeof (long) == sizeof (EMACS_INT
))
1681 XSETINT (val
, atol (read_buffer
));
1687 #ifdef LISP_FLOAT_TYPE
1688 if (isfloat_string (read_buffer
))
1689 return make_float (atof (read_buffer
));
1693 if (uninterned_symbol
)
1694 return make_symbol (read_buffer
);
1696 return intern (read_buffer
);
1701 #ifdef LISP_FLOAT_TYPE
1716 if (*cp
== '+' || *cp
== '-')
1719 if (*cp
>= '0' && *cp
<= '9')
1722 while (*cp
>= '0' && *cp
<= '9')
1730 if (*cp
>= '0' && *cp
<= '9')
1733 while (*cp
>= '0' && *cp
<= '9')
1736 if (*cp
== 'e' || *cp
== 'E')
1740 if (*cp
== '+' || *cp
== '-')
1744 if (*cp
>= '0' && *cp
<= '9')
1747 while (*cp
>= '0' && *cp
<= '9')
1750 return (((*cp
== 0) || (*cp
== ' ') || (*cp
== '\t') || (*cp
== '\n') || (*cp
== '\r') || (*cp
== '\f'))
1751 && (state
== (LEAD_INT
|DOT_CHAR
|TRAIL_INT
)
1752 || state
== (DOT_CHAR
|TRAIL_INT
)
1753 || state
== (LEAD_INT
|E_CHAR
|EXP_INT
)
1754 || state
== (LEAD_INT
|DOT_CHAR
|TRAIL_INT
|E_CHAR
|EXP_INT
)
1755 || state
== (DOT_CHAR
|TRAIL_INT
|E_CHAR
|EXP_INT
)));
1757 #endif /* LISP_FLOAT_TYPE */
1760 read_vector (readcharfun
)
1761 Lisp_Object readcharfun
;
1765 register Lisp_Object
*ptr
;
1766 register Lisp_Object tem
, vector
;
1767 register struct Lisp_Cons
*otem
;
1770 tem
= read_list (1, readcharfun
);
1771 len
= Flength (tem
);
1772 vector
= (read_pure
? make_pure_vector (XINT (len
)) : Fmake_vector (len
, Qnil
));
1775 size
= XVECTOR (vector
)->size
;
1776 ptr
= XVECTOR (vector
)->contents
;
1777 for (i
= 0; i
< size
; i
++)
1779 ptr
[i
] = read_pure
? Fpurecopy (Fcar (tem
)) : Fcar (tem
);
1787 /* flag = 1 means check for ] to terminate rather than ) and .
1788 flag = -1 means check for starting with defun
1789 and make structure pure. */
1792 read_list (flag
, readcharfun
)
1794 register Lisp_Object readcharfun
;
1796 /* -1 means check next element for defun,
1797 0 means don't check,
1798 1 means already checked and found defun. */
1799 int defunflag
= flag
< 0 ? -1 : 0;
1800 Lisp_Object val
, tail
;
1801 register Lisp_Object elt
, tem
;
1802 struct gcpro gcpro1
, gcpro2
;
1803 /* 0 is the normal case.
1804 1 means this list is a doc reference; replace it with the number 0.
1805 2 means this list is a doc reference; replace it with the doc string. */
1806 int doc_reference
= 0;
1808 /* Initialize this to 1 if we are reading a list. */
1809 int first_in_list
= flag
<= 0;
1818 elt
= read1 (readcharfun
, &ch
, first_in_list
);
1823 /* While building, if the list starts with #$, treat it specially. */
1824 if (EQ (elt
, Vload_file_name
)
1825 && !NILP (Vpurify_flag
))
1827 if (NILP (Vdoc_file_name
))
1828 /* We have not yet called Snarf-documentation, so assume
1829 this file is described in the DOC-MM.NN file
1830 and Snarf-documentation will fill in the right value later.
1831 For now, replace the whole list with 0. */
1834 /* We have already called Snarf-documentation, so make a relative
1835 file name for this file, so it can be found properly
1836 in the installed Lisp directory.
1837 We don't use Fexpand_file_name because that would make
1838 the directory absolute now. */
1839 elt
= concat2 (build_string ("../lisp/"),
1840 Ffile_name_nondirectory (elt
));
1842 else if (EQ (elt
, Vload_file_name
)
1843 && load_force_doc_strings
)
1852 Fsignal (Qinvalid_read_syntax
,
1853 Fcons (make_string (") or . in a vector", 18), Qnil
));
1861 XCONS (tail
)->cdr
= read0 (readcharfun
);
1863 val
= read0 (readcharfun
);
1864 read1 (readcharfun
, &ch
, 0);
1868 if (doc_reference
== 1)
1869 return make_number (0);
1870 if (doc_reference
== 2)
1872 /* Get a doc string from the file we are loading.
1873 If it's in saved_doc_string, get it from there. */
1874 int pos
= XINT (XCONS (val
)->cdr
);
1875 if (pos
>= saved_doc_string_position
1876 && pos
< (saved_doc_string_position
1877 + saved_doc_string_length
))
1879 int start
= pos
- saved_doc_string_position
;
1882 /* Process quoting with ^A,
1883 and find the end of the string,
1884 which is marked with ^_ (037). */
1885 for (from
= start
, to
= start
;
1886 saved_doc_string
[from
] != 037;)
1888 int c
= saved_doc_string
[from
++];
1891 c
= saved_doc_string
[from
++];
1893 saved_doc_string
[to
++] = c
;
1895 saved_doc_string
[to
++] = 0;
1897 saved_doc_string
[to
++] = 037;
1900 saved_doc_string
[to
++] = c
;
1903 return make_string (saved_doc_string
+ start
,
1907 return read_doc_string (val
);
1912 return Fsignal (Qinvalid_read_syntax
, Fcons (make_string (". in wrong context", 18), Qnil
));
1914 return Fsignal (Qinvalid_read_syntax
, Fcons (make_string ("] in a list", 11), Qnil
));
1916 tem
= (read_pure
&& flag
<= 0
1917 ? pure_cons (elt
, Qnil
)
1918 : Fcons (elt
, Qnil
));
1920 XCONS (tail
)->cdr
= tem
;
1925 defunflag
= EQ (elt
, Qdefun
);
1926 else if (defunflag
> 0)
1931 Lisp_Object Vobarray
;
1932 Lisp_Object initial_obarray
;
1934 /* oblookup stores the bucket number here, for the sake of Funintern. */
1936 int oblookup_last_bucket_number
;
1938 static int hash_string ();
1939 Lisp_Object
oblookup ();
1941 /* Get an error if OBARRAY is not an obarray.
1942 If it is one, return it. */
1945 check_obarray (obarray
)
1946 Lisp_Object obarray
;
1948 while (!VECTORP (obarray
) || XVECTOR (obarray
)->size
== 0)
1950 /* If Vobarray is now invalid, force it to be valid. */
1951 if (EQ (Vobarray
, obarray
)) Vobarray
= initial_obarray
;
1953 obarray
= wrong_type_argument (Qvectorp
, obarray
);
1958 /* Intern the C string STR: return a symbol with that name,
1959 interned in the current obarray. */
1966 int len
= strlen (str
);
1967 Lisp_Object obarray
;
1970 if (!VECTORP (obarray
) || XVECTOR (obarray
)->size
== 0)
1971 obarray
= check_obarray (obarray
);
1972 tem
= oblookup (obarray
, str
, len
);
1975 return Fintern ((!NILP (Vpurify_flag
)
1976 ? make_pure_string (str
, len
)
1977 : make_string (str
, len
)),
1981 /* Create an uninterned symbol with name STR. */
1987 int len
= strlen (str
);
1989 return Fmake_symbol ((!NILP (Vpurify_flag
)
1990 ? make_pure_string (str
, len
)
1991 : make_string (str
, len
)));
1994 DEFUN ("intern", Fintern
, Sintern
, 1, 2, 0,
1995 "Return the canonical symbol whose name is STRING.\n\
1996 If there is none, one is created by this function and returned.\n\
1997 A second optional argument specifies the obarray to use;\n\
1998 it defaults to the value of `obarray'.")
2000 Lisp_Object string
, obarray
;
2002 register Lisp_Object tem
, sym
, *ptr
;
2004 if (NILP (obarray
)) obarray
= Vobarray
;
2005 obarray
= check_obarray (obarray
);
2007 CHECK_STRING (string
, 0);
2009 tem
= oblookup (obarray
, XSTRING (string
)->data
, XSTRING (string
)->size
);
2010 if (!INTEGERP (tem
))
2013 if (!NILP (Vpurify_flag
))
2014 string
= Fpurecopy (string
);
2015 sym
= Fmake_symbol (string
);
2016 XSYMBOL (sym
)->obarray
= obarray
;
2018 ptr
= &XVECTOR (obarray
)->contents
[XINT (tem
)];
2020 XSYMBOL (sym
)->next
= XSYMBOL (*ptr
);
2022 XSYMBOL (sym
)->next
= 0;
2027 DEFUN ("intern-soft", Fintern_soft
, Sintern_soft
, 1, 2, 0,
2028 "Return the canonical symbol whose name is STRING, or nil if none exists.\n\
2029 A second optional argument specifies the obarray to use;\n\
2030 it defaults to the value of `obarray'.")
2032 Lisp_Object string
, obarray
;
2034 register Lisp_Object tem
;
2036 if (NILP (obarray
)) obarray
= Vobarray
;
2037 obarray
= check_obarray (obarray
);
2039 CHECK_STRING (string
, 0);
2041 tem
= oblookup (obarray
, XSTRING (string
)->data
, XSTRING (string
)->size
);
2042 if (!INTEGERP (tem
))
2047 DEFUN ("unintern", Funintern
, Sunintern
, 1, 2, 0,
2048 "Delete the symbol named NAME, if any, from OBARRAY.\n\
2049 The value is t if a symbol was found and deleted, nil otherwise.\n\
2050 NAME may be a string or a symbol. If it is a symbol, that symbol\n\
2051 is deleted, if it belongs to OBARRAY--no other symbol is deleted.\n\
2052 OBARRAY defaults to the value of the variable `obarray'.")
2054 Lisp_Object name
, obarray
;
2056 register Lisp_Object string
, tem
;
2059 if (NILP (obarray
)) obarray
= Vobarray
;
2060 obarray
= check_obarray (obarray
);
2063 XSETSTRING (string
, XSYMBOL (name
)->name
);
2066 CHECK_STRING (name
, 0);
2070 tem
= oblookup (obarray
, XSTRING (string
)->data
, XSTRING (string
)->size
);
2073 /* If arg was a symbol, don't delete anything but that symbol itself. */
2074 if (SYMBOLP (name
) && !EQ (name
, tem
))
2077 hash
= oblookup_last_bucket_number
;
2079 if (EQ (XVECTOR (obarray
)->contents
[hash
], tem
))
2081 if (XSYMBOL (tem
)->next
)
2082 XSETSYMBOL (XVECTOR (obarray
)->contents
[hash
], XSYMBOL (tem
)->next
);
2084 XSETINT (XVECTOR (obarray
)->contents
[hash
], 0);
2088 Lisp_Object tail
, following
;
2090 for (tail
= XVECTOR (obarray
)->contents
[hash
];
2091 XSYMBOL (tail
)->next
;
2094 XSETSYMBOL (following
, XSYMBOL (tail
)->next
);
2095 if (EQ (following
, tem
))
2097 XSYMBOL (tail
)->next
= XSYMBOL (following
)->next
;
2106 /* Return the symbol in OBARRAY whose names matches the string
2107 of SIZE characters at PTR. If there is no such symbol in OBARRAY,
2110 Also store the bucket number in oblookup_last_bucket_number. */
2113 oblookup (obarray
, ptr
, size
)
2114 Lisp_Object obarray
;
2120 register Lisp_Object tail
;
2121 Lisp_Object bucket
, tem
;
2123 if (!VECTORP (obarray
)
2124 || (obsize
= XVECTOR (obarray
)->size
) == 0)
2126 obarray
= check_obarray (obarray
);
2127 obsize
= XVECTOR (obarray
)->size
;
2129 /* This is sometimes needed in the middle of GC. */
2130 obsize
&= ~ARRAY_MARK_FLAG
;
2131 /* Combining next two lines breaks VMS C 2.3. */
2132 hash
= hash_string (ptr
, size
);
2134 bucket
= XVECTOR (obarray
)->contents
[hash
];
2135 oblookup_last_bucket_number
= hash
;
2136 if (XFASTINT (bucket
) == 0)
2138 else if (!SYMBOLP (bucket
))
2139 error ("Bad data in guts of obarray"); /* Like CADR error message */
2141 for (tail
= bucket
; ; XSETSYMBOL (tail
, XSYMBOL (tail
)->next
))
2143 if (XSYMBOL (tail
)->name
->size
== size
2144 && !bcmp (XSYMBOL (tail
)->name
->data
, ptr
, size
))
2146 else if (XSYMBOL (tail
)->next
== 0)
2149 XSETINT (tem
, hash
);
2154 hash_string (ptr
, len
)
2158 register unsigned char *p
= ptr
;
2159 register unsigned char *end
= p
+ len
;
2160 register unsigned char c
;
2161 register int hash
= 0;
2166 if (c
>= 0140) c
-= 40;
2167 hash
= ((hash
<<3) + (hash
>>28) + c
);
2169 return hash
& 07777777777;
2173 map_obarray (obarray
, fn
, arg
)
2174 Lisp_Object obarray
;
2179 register Lisp_Object tail
;
2180 CHECK_VECTOR (obarray
, 1);
2181 for (i
= XVECTOR (obarray
)->size
- 1; i
>= 0; i
--)
2183 tail
= XVECTOR (obarray
)->contents
[i
];
2184 if (XFASTINT (tail
) != 0)
2188 if (XSYMBOL (tail
)->next
== 0)
2190 XSETSYMBOL (tail
, XSYMBOL (tail
)->next
);
2195 mapatoms_1 (sym
, function
)
2196 Lisp_Object sym
, function
;
2198 call1 (function
, sym
);
2201 DEFUN ("mapatoms", Fmapatoms
, Smapatoms
, 1, 2, 0,
2202 "Call FUNCTION on every symbol in OBARRAY.\n\
2203 OBARRAY defaults to the value of `obarray'.")
2205 Lisp_Object function
, obarray
;
2209 if (NILP (obarray
)) obarray
= Vobarray
;
2210 obarray
= check_obarray (obarray
);
2212 map_obarray (obarray
, mapatoms_1
, function
);
2216 #define OBARRAY_SIZE 1511
2221 Lisp_Object oblength
;
2225 XSETFASTINT (oblength
, OBARRAY_SIZE
);
2227 Qnil
= Fmake_symbol (make_pure_string ("nil", 3));
2228 Vobarray
= Fmake_vector (oblength
, make_number (0));
2229 initial_obarray
= Vobarray
;
2230 staticpro (&initial_obarray
);
2231 /* Intern nil in the obarray */
2232 XSYMBOL (Qnil
)->obarray
= Vobarray
;
2233 /* These locals are to kludge around a pyramid compiler bug. */
2234 hash
= hash_string ("nil", 3);
2235 /* Separate statement here to avoid VAXC bug. */
2236 hash
%= OBARRAY_SIZE
;
2237 tem
= &XVECTOR (Vobarray
)->contents
[hash
];
2240 Qunbound
= Fmake_symbol (make_pure_string ("unbound", 7));
2241 XSYMBOL (Qnil
)->function
= Qunbound
;
2242 XSYMBOL (Qunbound
)->value
= Qunbound
;
2243 XSYMBOL (Qunbound
)->function
= Qunbound
;
2246 XSYMBOL (Qnil
)->value
= Qnil
;
2247 XSYMBOL (Qnil
)->plist
= Qnil
;
2248 XSYMBOL (Qt
)->value
= Qt
;
2250 /* Qt is correct even if CANNOT_DUMP. loadup.el will set to nil at end. */
2253 Qvariable_documentation
= intern ("variable-documentation");
2254 staticpro (&Qvariable_documentation
);
2256 read_buffer_size
= 100;
2257 read_buffer
= (char *) malloc (read_buffer_size
);
2262 struct Lisp_Subr
*sname
;
2265 sym
= intern (sname
->symbol_name
);
2266 XSETSUBR (XSYMBOL (sym
)->function
, sname
);
2269 #ifdef NOTDEF /* use fset in subr.el now */
2271 defalias (sname
, string
)
2272 struct Lisp_Subr
*sname
;
2276 sym
= intern (string
);
2277 XSETSUBR (XSYMBOL (sym
)->function
, sname
);
2281 /* Define an "integer variable"; a symbol whose value is forwarded
2282 to a C variable of type int. Sample call: */
2283 /* DEFVAR_INT ("indent-tabs-mode", &indent_tabs_mode, "Documentation"); */
2285 defvar_int (namestring
, address
)
2289 Lisp_Object sym
, val
;
2290 sym
= intern (namestring
);
2291 val
= allocate_misc ();
2292 XMISCTYPE (val
) = Lisp_Misc_Intfwd
;
2293 XINTFWD (val
)->intvar
= address
;
2294 XSYMBOL (sym
)->value
= val
;
2297 /* Similar but define a variable whose value is T if address contains 1,
2298 NIL if address contains 0 */
2300 defvar_bool (namestring
, address
)
2304 Lisp_Object sym
, val
;
2305 sym
= intern (namestring
);
2306 val
= allocate_misc ();
2307 XMISCTYPE (val
) = Lisp_Misc_Boolfwd
;
2308 XBOOLFWD (val
)->boolvar
= address
;
2309 XSYMBOL (sym
)->value
= val
;
2312 /* Similar but define a variable whose value is the Lisp Object stored
2313 at address. Two versions: with and without gc-marking of the C
2314 variable. The nopro version is used when that variable will be
2315 gc-marked for some other reason, since marking the same slot twice
2316 can cause trouble with strings. */
2318 defvar_lisp_nopro (namestring
, address
)
2320 Lisp_Object
*address
;
2322 Lisp_Object sym
, val
;
2323 sym
= intern (namestring
);
2324 val
= allocate_misc ();
2325 XMISCTYPE (val
) = Lisp_Misc_Objfwd
;
2326 XOBJFWD (val
)->objvar
= address
;
2327 XSYMBOL (sym
)->value
= val
;
2331 defvar_lisp (namestring
, address
)
2333 Lisp_Object
*address
;
2335 defvar_lisp_nopro (namestring
, address
);
2336 staticpro (address
);
2341 /* Similar but define a variable whose value is the Lisp Object stored in
2342 the current buffer. address is the address of the slot in the buffer
2343 that is current now. */
2346 defvar_per_buffer (namestring
, address
, type
, doc
)
2348 Lisp_Object
*address
;
2352 Lisp_Object sym
, val
;
2354 extern struct buffer buffer_local_symbols
;
2356 sym
= intern (namestring
);
2357 val
= allocate_misc ();
2358 offset
= (char *)address
- (char *)current_buffer
;
2360 XMISCTYPE (val
) = Lisp_Misc_Buffer_Objfwd
;
2361 XBUFFER_OBJFWD (val
)->offset
= offset
;
2362 XSYMBOL (sym
)->value
= val
;
2363 *(Lisp_Object
*)(offset
+ (char *)&buffer_local_symbols
) = sym
;
2364 *(Lisp_Object
*)(offset
+ (char *)&buffer_local_types
) = type
;
2365 if (XINT (*(Lisp_Object
*)(offset
+ (char *)&buffer_local_flags
)) == 0)
2366 /* Did a DEFVAR_PER_BUFFER without initializing the corresponding
2367 slot of buffer_local_flags */
2371 #endif /* standalone */
2373 /* Similar but define a variable whose value is the Lisp Object stored
2374 at a particular offset in the current kboard object. */
2377 defvar_kboard (namestring
, offset
)
2381 Lisp_Object sym
, val
;
2382 sym
= intern (namestring
);
2383 val
= allocate_misc ();
2384 XMISCTYPE (val
) = Lisp_Misc_Kboard_Objfwd
;
2385 XKBOARD_OBJFWD (val
)->offset
= offset
;
2386 XSYMBOL (sym
)->value
= val
;
2389 /* Record the value of load-path used at the start of dumping
2390 so we can see if the site changed it later during dumping. */
2391 static Lisp_Object dump_path
;
2396 int turn_off_warning
= 0;
2398 #ifdef HAVE_SETLOCALE
2399 /* Make sure numbers are parsed as we expect. */
2400 setlocale (LC_NUMERIC
, "C");
2401 #endif /* HAVE_SETLOCALE */
2403 /* Compute the default load-path. */
2405 normal
= PATH_LOADSEARCH
;
2406 Vload_path
= decode_env_path (0, normal
);
2408 if (NILP (Vpurify_flag
))
2409 normal
= PATH_LOADSEARCH
;
2411 normal
= PATH_DUMPLOADSEARCH
;
2413 /* In a dumped Emacs, we normally have to reset the value of
2414 Vload_path from PATH_LOADSEARCH, since the value that was dumped
2415 uses ../lisp, instead of the path of the installed elisp
2416 libraries. However, if it appears that Vload_path was changed
2417 from the default before dumping, don't override that value. */
2420 if (! NILP (Fequal (dump_path
, Vload_path
)))
2422 Vload_path
= decode_env_path (0, normal
);
2423 if (!NILP (Vinstallation_directory
))
2425 /* Add to the path the lisp subdir of the
2426 installation dir, if it exists. */
2427 Lisp_Object tem
, tem1
;
2428 tem
= Fexpand_file_name (build_string ("lisp"),
2429 Vinstallation_directory
);
2430 tem1
= Ffile_exists_p (tem
);
2433 if (NILP (Fmember (tem
, Vload_path
)))
2435 turn_off_warning
= 1;
2436 Vload_path
= nconc2 (Vload_path
, Fcons (tem
, Qnil
));
2440 /* That dir doesn't exist, so add the build-time
2441 Lisp dirs instead. */
2442 Vload_path
= nconc2 (Vload_path
, dump_path
);
2444 /* Add site-list under the installation dir, if it exists. */
2445 tem
= Fexpand_file_name (build_string ("site-lisp"),
2446 Vinstallation_directory
);
2447 tem1
= Ffile_exists_p (tem
);
2450 if (NILP (Fmember (tem
, Vload_path
)))
2451 Vload_path
= nconc2 (Vload_path
, Fcons (tem
, Qnil
));
2458 /* ../lisp refers to the build directory.
2459 NORMAL refers to the lisp dir in the source directory. */
2460 Vload_path
= Fcons (build_string ("../lisp"),
2461 decode_env_path (0, normal
));
2462 dump_path
= Vload_path
;
2467 /* When Emacs is invoked over network shares on NT, PATH_LOADSEARCH is
2468 almost never correct, thereby causing a warning to be printed out that
2469 confuses users. Since PATH_LOADSEARCH is always overridden by the
2470 EMACSLOADPATH environment variable below, disable the warning on NT. */
2472 /* Warn if dirs in the *standard* path don't exist. */
2473 if (!turn_off_warning
)
2475 Lisp_Object path_tail
;
2477 for (path_tail
= Vload_path
;
2479 path_tail
= XCONS (path_tail
)->cdr
)
2481 Lisp_Object dirfile
;
2482 dirfile
= Fcar (path_tail
);
2483 if (STRINGP (dirfile
))
2485 dirfile
= Fdirectory_file_name (dirfile
);
2486 if (access (XSTRING (dirfile
)->data
, 0) < 0)
2487 dir_warning ("Warning: Lisp directory `%s' does not exist.\n",
2488 XCONS (path_tail
)->car
);
2492 #endif /* WINDOWSNT */
2494 /* If the EMACSLOADPATH environment variable is set, use its value.
2495 This doesn't apply if we're dumping. */
2497 if (NILP (Vpurify_flag
)
2498 && egetenv ("EMACSLOADPATH"))
2500 Vload_path
= decode_env_path ("EMACSLOADPATH", normal
);
2504 load_in_progress
= 0;
2505 Vload_file_name
= Qnil
;
2507 load_descriptor_list
= Qnil
;
2510 /* Print a warning, using format string FORMAT, that directory DIRNAME
2511 does not exist. Print it on stderr and put it in *Message*. */
2513 dir_warning (format
, dirname
)
2515 Lisp_Object dirname
;
2518 = (char *) alloca (XSTRING (dirname
)->size
+ strlen (format
) + 5);
2520 fprintf (stderr
, format
, XSTRING (dirname
)->data
);
2521 sprintf (buffer
, format
, XSTRING (dirname
)->data
);
2522 message_dolog (buffer
, strlen (buffer
), 0);
2529 defsubr (&Sread_from_string
);
2531 defsubr (&Sintern_soft
);
2532 defsubr (&Sunintern
);
2534 defsubr (&Seval_buffer
);
2535 defsubr (&Seval_region
);
2536 defsubr (&Sread_char
);
2537 defsubr (&Sread_char_exclusive
);
2538 defsubr (&Sread_event
);
2539 defsubr (&Sget_file_char
);
2540 defsubr (&Smapatoms
);
2542 DEFVAR_LISP ("obarray", &Vobarray
,
2543 "Symbol table for use by `intern' and `read'.\n\
2544 It is a vector whose length ought to be prime for best results.\n\
2545 The vector's contents don't make sense if examined from Lisp programs;\n\
2546 to find all the symbols in an obarray, use `mapatoms'.");
2548 DEFVAR_LISP ("values", &Vvalues
,
2549 "List of values of all expressions which were read, evaluated and printed.\n\
2550 Order is reverse chronological.");
2552 DEFVAR_LISP ("standard-input", &Vstandard_input
,
2553 "Stream for read to get input from.\n\
2554 See documentation of `read' for possible values.");
2555 Vstandard_input
= Qt
;
2557 DEFVAR_LISP ("load-path", &Vload_path
,
2558 "*List of directories to search for files to load.\n\
2559 Each element is a string (directory name) or nil (try default directory).\n\
2560 Initialized based on EMACSLOADPATH environment variable, if any,\n\
2561 otherwise to default specified by file `paths.h' when Emacs was built.");
2563 DEFVAR_BOOL ("load-in-progress", &load_in_progress
,
2564 "Non-nil iff inside of `load'.");
2566 DEFVAR_LISP ("after-load-alist", &Vafter_load_alist
,
2567 "An alist of expressions to be evalled when particular files are loaded.\n\
2568 Each element looks like (FILENAME FORMS...).\n\
2569 When `load' is run and the file-name argument is FILENAME,\n\
2570 the FORMS in the corresponding element are executed at the end of loading.\n\n\
2571 FILENAME must match exactly! Normally FILENAME is the name of a library,\n\
2572 with no directory specified, since that is how `load' is normally called.\n\
2573 An error in FORMS does not undo the load,\n\
2574 but does prevent execution of the rest of the FORMS.");
2575 Vafter_load_alist
= Qnil
;
2577 DEFVAR_LISP ("load-history", &Vload_history
,
2578 "Alist mapping source file names to symbols and features.\n\
2579 Each alist element is a list that starts with a file name,\n\
2580 except for one element (optional) that starts with nil and describes\n\
2581 definitions evaluated from buffers not visiting files.\n\
2582 The remaining elements of each list are symbols defined as functions\n\
2583 or variables, and cons cells `(provide . FEATURE)' and `(require . FEATURE)'.");
2584 Vload_history
= Qnil
;
2586 DEFVAR_LISP ("load-file-name", &Vload_file_name
,
2587 "Full name of file being loaded by `load'.");
2588 Vload_file_name
= Qnil
;
2590 DEFVAR_LISP ("current-load-list", &Vcurrent_load_list
,
2591 "Used for internal purposes by `load'.");
2592 Vcurrent_load_list
= Qnil
;
2594 DEFVAR_LISP ("load-read-function", &Vload_read_function
,
2595 "Function used by `load' and `eval-region' for reading expressions.\n\
2596 The default is nil, which means use the function `read'.");
2597 Vload_read_function
= Qnil
;
2599 DEFVAR_BOOL ("load-force-doc-strings", &load_force_doc_strings
,
2600 "Non-nil means `load' should force-load all dynamic doc strings.\n\
2601 This is useful when the file being loaded is a temporary copy.");
2602 load_force_doc_strings
= 0;
2604 DEFVAR_LISP ("source-directory", &Vsource_directory
,
2605 "Directory in which Emacs sources were found when Emacs was built.\n\
2606 You cannot count on them to still be there!");
2608 = Fexpand_file_name (build_string ("../"),
2609 Fcar (decode_env_path (0, PATH_DUMPLOADSEARCH
)));
2611 /* Vsource_directory was initialized in init_lread. */
2613 load_descriptor_list
= Qnil
;
2614 staticpro (&load_descriptor_list
);
2616 Qcurrent_load_list
= intern ("current-load-list");
2617 staticpro (&Qcurrent_load_list
);
2619 Qstandard_input
= intern ("standard-input");
2620 staticpro (&Qstandard_input
);
2622 Qread_char
= intern ("read-char");
2623 staticpro (&Qread_char
);
2625 Qget_file_char
= intern ("get-file-char");
2626 staticpro (&Qget_file_char
);
2628 Qbackquote
= intern ("`");
2629 staticpro (&Qbackquote
);
2630 Qcomma
= intern (",");
2631 staticpro (&Qcomma
);
2632 Qcomma_at
= intern (",@");
2633 staticpro (&Qcomma_at
);
2634 Qcomma_dot
= intern (",.");
2635 staticpro (&Qcomma_dot
);
2637 Qinhibit_file_name_operation
= intern ("inhibit-file-name-operation");
2638 staticpro (&Qinhibit_file_name_operation
);
2640 Qascii_character
= intern ("ascii-character");
2641 staticpro (&Qascii_character
);
2643 Qfunction
= intern ("function");
2644 staticpro (&Qfunction
);
2646 Qload
= intern ("load");
2649 Qload_file_name
= intern ("load-file-name");
2650 staticpro (&Qload_file_name
);
2652 staticpro (&dump_path
);
2654 staticpro (&read_objects
);
2655 read_objects
= Qnil
;