From fbff6988ce1e3fc41cf046e1c9e897e6470da257 Mon Sep 17 00:00:00 2001 From: Karl Heuer Date: Thu, 20 Feb 1997 06:52:14 +0000 Subject: Include charset.h. (Vload_source_file_function): New variable. (Fload): Call Vload_source_file_function if defined while loading an Emacs Lisp source file. */ (read_multibyte): New function. (read_escape): Handle multibyte characters. (read1): Correct the value of size_in_chars of a bool vector. Handle the case `?' is followed by a multibyte character. (Vload_source_file_function): New variable. --- src/lread.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 57 insertions(+), 4 deletions(-) (limited to 'src/lread.c') diff --git a/src/lread.c b/src/lread.c index 322cb1e1c8d..4e2ed5ccd2a 100644 --- a/src/lread.c +++ b/src/lread.c @@ -30,6 +30,7 @@ Boston, MA 02111-1307, USA. */ #ifndef standalone #include "buffer.h" +#include "charset.h" #include #include "commands.h" #include "keyboard.h" @@ -109,6 +110,10 @@ Lisp_Object read_objects; /* Nonzero means load should forcibly load all dynamic doc strings. */ static int load_force_doc_strings; +/* Function to use for loading an Emacs lisp source file (not + compiled) instead of readevalloop. */ +Lisp_Object Vload_source_file_function; + /* List of descriptors now open for Fload. */ static Lisp_Object load_descriptor_list; @@ -139,7 +144,11 @@ static int new_backquote_flag; /* Handle unreading and rereading of characters. Write READCHAR to read a character, - UNREAD(c) to unread c to be read again. */ + UNREAD(c) to unread c to be read again. + + These macros actually read/unread a byte code, multibyte characters + are not handled here. The caller should manage them if necessary. + */ #define READCHAR readchar (readcharfun) #define UNREAD(c) unreadchar (readcharfun, c) @@ -468,6 +477,17 @@ Return t if file exists.") } XSTRING (found)->data[XSTRING (found)->size - 1] = 'c'; } + else + { + /* We are loading a source file (*.el). */ + if (!NILP (Vload_source_file_function)) + { + close (fd); + return call3 (Vload_source_file_function, found, file, + NILP (noerror) ? Qnil : Qt, + NILP (nomessage) ? Qnil : Qt); + } + } #ifdef DOS_NT close (fd); @@ -1085,6 +1105,27 @@ read0 (readcharfun) static int read_buffer_size; static char *read_buffer; +/* Read multibyte form and return it as a character. C is a first + byte of multibyte form, and rest of them are read from + READCHARFUN. */ +static int +read_multibyte (c, readcharfun) + register int c; + Lisp_Object readcharfun; +{ + /* We need the actual character code of this multibyte + characters. */ + unsigned char str[MAX_LENGTH_OF_MULTI_BYTE_FORM]; + int len = 0; + + str[len++] = c; + while ((c = READCHAR) >= 0xA0 + && len < MAX_LENGTH_OF_MULTI_BYTE_FORM) + str[len++] = c; + UNREAD (c); + return STRING_CHAR (str, len); +} + static int read_escape (readcharfun) Lisp_Object readcharfun; @@ -1239,6 +1280,8 @@ read_escape (readcharfun) } default: + if (BASE_LEADING_CODE_P (c)) + c = read_multibyte (c, readcharfun); return c; } } @@ -1523,9 +1566,10 @@ read1 (readcharfun, pch, first_in_list) if (c < 0) return Fsignal (Qend_of_file, Qnil); if (c == '\\') - XSETINT (val, read_escape (readcharfun)); - else - XSETINT (val, c); + c = read_escape (readcharfun); + else if (BASE_LEADING_CODE_P (c)) + c = read_multibyte (c, readcharfun); + XSETINT (val, c); return val; } @@ -2596,6 +2640,15 @@ or variables, and cons cells `(provide . FEATURE)' and `(require . FEATURE)'."); The default is nil, which means use the function `read'."); Vload_read_function = Qnil; + DEFVAR_LISP ("load-source-file-function", &Vload_source_file_function, + "Function called in `load' for loading an Emacs lisp source file.\n\ +This function is for doing code conversion before reading the source file.\n\ +If nil, loading is done without any code conversion.\n\ +Arguments are FULLNAME, FILE, NOERROR, NOMESSAGE, where\n\ + FULLNAME is the full name of FILE.\n\ +See `load' for the meaning of the remaining arguments."); + Vload_source_file_function = Qnil; + DEFVAR_BOOL ("load-force-doc-strings", &load_force_doc_strings, "Non-nil means `load' should force-load all dynamic doc strings.\n\ This is useful when the file being loaded is a temporary copy."); -- cgit v1.2.1