changeset 61403:008bb0675c5b

(readevalloop): Add args START and END as region in current buffer to read. Callers changed. When specified, narrow to this region only when reading, not during eval. Track next point to read from during eval. Also restore point to "real" buffer position before eval. (Feval_region): Don't save excursion and restriction here, and don't narrow to region. Just pass region to readevalloop. Note: Point is now preserved even when PRINTFLAG is nil.
author Kim F. Storm <storm@cua.dk>
date Fri, 08 Apr 2005 23:33:28 +0000
parents b2be03118df9
children f6ddc48bc826
files src/lread.c
diffstat 1 files changed, 35 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/src/lread.c	Fri Apr 08 23:32:54 2005 +0000
+++ b/src/lread.c	Fri Apr 08 23:33:28 2005 +0000
@@ -206,6 +206,7 @@
 static void to_multibyte P_ ((char **, char **, int *));
 static void readevalloop P_ ((Lisp_Object, FILE*, Lisp_Object,
 			      Lisp_Object (*) (), int,
+			      Lisp_Object, Lisp_Object,
 			      Lisp_Object, Lisp_Object));
 static Lisp_Object load_unwind P_ ((Lisp_Object));
 static Lisp_Object load_descriptor_unwind P_ ((Lisp_Object));
@@ -912,7 +913,8 @@
   load_descriptor_list
     = Fcons (make_number (fileno (stream)), load_descriptor_list);
   load_in_progress++;
-  readevalloop (Qget_file_char, stream, file, Feval, 0, Qnil, Qnil);
+  readevalloop (Qget_file_char, stream, file, Feval,
+		0, Qnil, Qnil, Qnil, Qnil);
   unbind_to (count, Qnil);
 
   /* Run any load-hooks for this file.  */
@@ -1290,16 +1292,19 @@
 
 /* UNIBYTE specifies how to set load_convert_to_unibyte
    for this invocation.
-   READFUN, if non-nil, is used instead of `read'.  */
+   READFUN, if non-nil, is used instead of `read'.
+   START, END is region in current buffer (from eval-region).  */
 
 static void
-readevalloop (readcharfun, stream, sourcename, evalfun, printflag, unibyte, readfun)
+readevalloop (readcharfun, stream, sourcename, evalfun,
+	      printflag, unibyte, readfun, start, end)
      Lisp_Object readcharfun;
      FILE *stream;
      Lisp_Object sourcename;
      Lisp_Object (*evalfun) ();
      int printflag;
      Lisp_Object unibyte, readfun;
+     Lisp_Object start, end;
 {
   register int c;
   register Lisp_Object val;
@@ -1327,28 +1332,41 @@
   continue_reading_p = 1;
   while (continue_reading_p)
     {
+      int count1 = SPECPDL_INDEX ();
+
       if (b != 0 && NILP (b->name))
 	error ("Reading from killed buffer");
 
+      if (!NILP (start))
+	{
+	  record_unwind_protect (save_excursion_restore, save_excursion_save ());
+	  record_unwind_protect (save_restriction_restore, save_restriction_save ());
+	  Fgoto_char (start);
+	  Fnarrow_to_region (make_number (BEGV), end);
+	}
+
       instream = stream;
+    read_next:
       c = READCHAR;
       if (c == ';')
 	{
 	  while ((c = READCHAR) != '\n' && c != -1);
-	  continue;
+	  goto read_next;
 	}
-      if (c < 0) break;
+      if (c < 0)
+	{
+	  unbind_to (count1, Qnil);
+	  break;
+	}
 
       /* Ignore whitespace here, so we can detect eof.  */
       if (c == ' ' || c == '\t' || c == '\n' || c == '\f' || c == '\r')
-	continue;
+	goto read_next;
 
       if (!NILP (Vpurify_flag) && c == '(')
 	{
-	  int count1 = SPECPDL_INDEX ();
 	  record_unwind_protect (unreadpure, Qnil);
 	  val = read_list (-1, readcharfun);
-	  unbind_to (count1, Qnil);
 	}
       else
 	{
@@ -1374,6 +1392,10 @@
 	    val = read_internal_start (readcharfun, Qnil, Qnil);
 	}
 
+      if (!NILP (start) && continue_reading_p)
+	start = Fpoint_marker ();
+      unbind_to (count1, Qnil);
+
       val = (*evalfun) (val);
 
       if (printflag)
@@ -1432,7 +1454,8 @@
   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), unibyte, Qnil);
+  readevalloop (buf, 0, filename, Feval,
+		!NILP (printflag), unibyte, Qnil, Qnil, Qnil);
   unbind_to (count, Qnil);
 
   return Qnil;
@@ -1464,15 +1487,10 @@
     tem = printflag;
   specbind (Qstandard_output, tem);
 
-  if (NILP (printflag))
-    record_unwind_protect (save_excursion_restore, save_excursion_save ());
-  record_unwind_protect (save_restriction_restore, save_restriction_save ());
-
-  /* This both uses start and checks its type.  */
-  Fgoto_char (start);
-  Fnarrow_to_region (make_number (BEGV), end);
+  /* readevalloop calls functions which check the type of start and end.  */
   readevalloop (cbuf, 0, XBUFFER (cbuf)->filename, Feval,
-		!NILP (printflag), Qnil, read_function);
+		!NILP (printflag), Qnil, read_function,
+		start, end);
 
   return unbind_to (count, Qnil);
 }