changeset 21677:f42b78e033db

(readevalloop): New arg UNIBYTE. Callers changed. Use it to bind load_convert_to_unibyte. (Feval_buffer): New arg UNIBYTE. Pass it to readevalloop. (readevalloop_1): New unwind-protect subroutine. (load_convert_to_unibyte): New variable. (syms_of_lread): Set up Lisp var. (read1): If load_convert_to_unibyte, convert strings to unibyte.
author Richard M. Stallman <rms@gnu.org>
date Mon, 20 Apr 1998 07:09:58 +0000
parents 81bbd2c2724a
children acaff8b34667
files src/lread.c
diffstat 1 files changed, 47 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/src/lread.c	Mon Apr 20 07:08:40 1998 +0000
+++ b/src/lread.c	Mon Apr 20 07:09:58 1998 +0000
@@ -113,6 +113,9 @@
 /* Nonzero means load should forcibly load all dynamic doc strings.  */
 static int load_force_doc_strings;
 
+/* Nonzero means read should convert strings to unibyte.  */
+static int load_convert_to_unibyte;
+
 /* Function to use for loading an Emacs lisp source file (not
    compiled) instead of readevalloop.  */
 Lisp_Object Vload_source_file_function;
@@ -616,7 +619,7 @@
   load_descriptor_list
     = Fcons (make_number (fileno (stream)), load_descriptor_list);
   load_in_progress++;
-  readevalloop (Qget_file_char, stream, file, Feval, 0);
+  readevalloop (Qget_file_char, stream, file, Feval, 0, Qnil);
   unbind_to (count, Qnil);
 
   /* Run any load-hooks for this file.  */
@@ -924,13 +927,25 @@
   return Qnil;
 }
 
+static Lisp_Object
+readevalloop_1 (old)
+     Lisp_Object old;
+{
+  load_convert_to_unibyte = ! NILP (old);
+  return Qnil;
+}
+
+/* UNIBYTE specifies how to set load_convert_to_unibyte
+   for this invocation.  */
+
 static void
-readevalloop (readcharfun, stream, sourcename, evalfun, printflag)
+readevalloop (readcharfun, stream, sourcename, evalfun, printflag, unibyte)
      Lisp_Object readcharfun;
      FILE *stream;
      Lisp_Object sourcename;
      Lisp_Object (*evalfun) ();
      int printflag;
+     int unibyte;
 {
   register int c;
   register Lisp_Object val;
@@ -945,6 +960,8 @@
 
   specbind (Qstandard_input, readcharfun);
   specbind (Qcurrent_load_list, Qnil);
+  record_unwind_protect (readevalloop_1, load_convert_to_unibyte ? Qt : Qnil);
+  load_convert_to_unibyte = !NILP (unibyte);
 
   readchar_backlog = 0;
 
@@ -1006,7 +1023,7 @@
 
 #ifndef standalone
 
-DEFUN ("eval-buffer", Feval_buffer, Seval_buffer, 0, 3, "",
+DEFUN ("eval-buffer", Feval_buffer, Seval_buffer, 0, 4, "",
   "Execute the current buffer as Lisp code.\n\
 Programs can pass two arguments, BUFFER and PRINTFLAG.\n\
 BUFFER is the buffer to evaluate (nil means use current buffer).\n\
@@ -1017,8 +1034,8 @@
 it specifies the file name to use for `load-history'.\n\
 \n\
 This function preserves the position of point.")
-  (buffer, printflag, filename)
-     Lisp_Object buffer, printflag, filename;
+  (buffer, printflag, filename, unibyte)
+     Lisp_Object buffer, printflag, filename, unibyte;
 {
   int count = specpdl_ptr - specpdl;
   Lisp_Object tem, buf;
@@ -1041,7 +1058,7 @@
   specbind (Qstandard_output, tem);
   record_unwind_protect (save_excursion_restore, save_excursion_save ());
   BUF_SET_PT (XBUFFER (buf), BUF_BEGV (XBUFFER (buf)));
-  readevalloop (buf, 0, filename, Feval, !NILP (printflag));
+  readevalloop (buf, 0, filename, Feval, !NILP (printflag), unibyte);
   unbind_to (count, Qnil);
 
   return Qnil;
@@ -1070,7 +1087,8 @@
   specbind (Qstandard_output, tem);
   record_unwind_protect (save_excursion_restore, save_excursion_save ());
   SET_PT (BEGV);
-  readevalloop (cbuf, 0, XBUFFER (cbuf)->filename, Feval, !NILP (printflag));
+  readevalloop (cbuf, 0, XBUFFER (cbuf)->filename, Feval,
+		!NILP (printflag), Qnil);
   return unbind_to (count, Qnil);
 }
 #endif
@@ -1105,7 +1123,8 @@
   /* This both uses start and checks its type.  */
   Fgoto_char (start);
   Fnarrow_to_region (make_number (BEGV), end);
-  readevalloop (cbuf, 0, XBUFFER (cbuf)->filename, Feval, !NILP (printflag));
+  readevalloop (cbuf, 0, XBUFFER (cbuf)->filename, Feval,
+		!NILP (printflag), Qnil);
 
   return unbind_to (count, Qnil);
 }
@@ -1757,6 +1776,8 @@
 		    p += length;
 		    continue;
 		  }
+		/* If an escape specifies a non-ASCII single-byte character,
+		   this must be a unibyte string.  */
 		else if (! ASCII_BYTE_P (c))
 		  force_singlebyte = 1;
 	      }
@@ -1797,9 +1818,19 @@
 
 	if (force_singlebyte)
 	  nchars = p - read_buffer;
-	else if (! NILP (buffer_defaults.enable_multibyte_characters)
-		 || force_multibyte)
+	else if (force_multibyte)
 	  nchars = multibyte_chars_in_text (read_buffer, p - read_buffer);
+	else if (load_convert_to_unibyte)
+	  {
+	    Lisp_Object string;
+	    nchars = multibyte_chars_in_text (read_buffer, p - read_buffer);
+	    if (p - read_buffer != nchars)
+	      {
+		string = make_multibyte_string (read_buffer, nchars,
+						p - read_buffer);
+		return Fstring_make_unibyte (string);
+	      }
+	  }
 	else
 	  nchars = p - read_buffer;
 
@@ -2936,6 +2967,12 @@
 This is useful when the file being loaded is a temporary copy.");
   load_force_doc_strings = 0;
 
+  DEFVAR_BOOL ("load-convert-to-unibyte", &load_convert_to_unibyte,
+     "Non-nil means `load' converts strings to unibyte whenever possible.\n\
+This is normally used in `load-with-code-conversion'\n\
+for loading non-compiled files.");
+  load_convert_to_unibyte = 0;
+
   DEFVAR_LISP ("source-directory", &Vsource_directory,
      "Directory in which Emacs sources were found when Emacs was built.\n\
 You cannot count on them to still be there!");