comparison src/lread.c @ 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 edecd7c1824e
children 02c939955b7a 02f1dbc4a199
comparison
equal deleted inserted replaced
61402:b2be03118df9 61403:008bb0675c5b
204 static Lisp_Object Vbytecomp_version_regexp; 204 static Lisp_Object Vbytecomp_version_regexp;
205 205
206 static void to_multibyte P_ ((char **, char **, int *)); 206 static void to_multibyte P_ ((char **, char **, int *));
207 static void readevalloop P_ ((Lisp_Object, FILE*, Lisp_Object, 207 static void readevalloop P_ ((Lisp_Object, FILE*, Lisp_Object,
208 Lisp_Object (*) (), int, 208 Lisp_Object (*) (), int,
209 Lisp_Object, Lisp_Object,
209 Lisp_Object, Lisp_Object)); 210 Lisp_Object, Lisp_Object));
210 static Lisp_Object load_unwind P_ ((Lisp_Object)); 211 static Lisp_Object load_unwind P_ ((Lisp_Object));
211 static Lisp_Object load_descriptor_unwind P_ ((Lisp_Object)); 212 static Lisp_Object load_descriptor_unwind P_ ((Lisp_Object));
212 213
213 214
910 specbind (Qload_file_name, found); 911 specbind (Qload_file_name, found);
911 specbind (Qinhibit_file_name_operation, Qnil); 912 specbind (Qinhibit_file_name_operation, Qnil);
912 load_descriptor_list 913 load_descriptor_list
913 = Fcons (make_number (fileno (stream)), load_descriptor_list); 914 = Fcons (make_number (fileno (stream)), load_descriptor_list);
914 load_in_progress++; 915 load_in_progress++;
915 readevalloop (Qget_file_char, stream, file, Feval, 0, Qnil, Qnil); 916 readevalloop (Qget_file_char, stream, file, Feval,
917 0, Qnil, Qnil, Qnil, Qnil);
916 unbind_to (count, Qnil); 918 unbind_to (count, Qnil);
917 919
918 /* Run any load-hooks for this file. */ 920 /* Run any load-hooks for this file. */
919 temp = Fassoc (file, Vafter_load_alist); 921 temp = Fassoc (file, Vafter_load_alist);
920 if (!NILP (temp)) 922 if (!NILP (temp))
1288 Fsignal (Qend_of_file, data); 1290 Fsignal (Qend_of_file, data);
1289 } 1291 }
1290 1292
1291 /* UNIBYTE specifies how to set load_convert_to_unibyte 1293 /* UNIBYTE specifies how to set load_convert_to_unibyte
1292 for this invocation. 1294 for this invocation.
1293 READFUN, if non-nil, is used instead of `read'. */ 1295 READFUN, if non-nil, is used instead of `read'.
1296 START, END is region in current buffer (from eval-region). */
1294 1297
1295 static void 1298 static void
1296 readevalloop (readcharfun, stream, sourcename, evalfun, printflag, unibyte, readfun) 1299 readevalloop (readcharfun, stream, sourcename, evalfun,
1300 printflag, unibyte, readfun, start, end)
1297 Lisp_Object readcharfun; 1301 Lisp_Object readcharfun;
1298 FILE *stream; 1302 FILE *stream;
1299 Lisp_Object sourcename; 1303 Lisp_Object sourcename;
1300 Lisp_Object (*evalfun) (); 1304 Lisp_Object (*evalfun) ();
1301 int printflag; 1305 int printflag;
1302 Lisp_Object unibyte, readfun; 1306 Lisp_Object unibyte, readfun;
1307 Lisp_Object start, end;
1303 { 1308 {
1304 register int c; 1309 register int c;
1305 register Lisp_Object val; 1310 register Lisp_Object val;
1306 int count = SPECPDL_INDEX (); 1311 int count = SPECPDL_INDEX ();
1307 struct gcpro gcpro1; 1312 struct gcpro gcpro1;
1325 LOADHIST_ATTACH (sourcename); 1330 LOADHIST_ATTACH (sourcename);
1326 1331
1327 continue_reading_p = 1; 1332 continue_reading_p = 1;
1328 while (continue_reading_p) 1333 while (continue_reading_p)
1329 { 1334 {
1335 int count1 = SPECPDL_INDEX ();
1336
1330 if (b != 0 && NILP (b->name)) 1337 if (b != 0 && NILP (b->name))
1331 error ("Reading from killed buffer"); 1338 error ("Reading from killed buffer");
1332 1339
1340 if (!NILP (start))
1341 {
1342 record_unwind_protect (save_excursion_restore, save_excursion_save ());
1343 record_unwind_protect (save_restriction_restore, save_restriction_save ());
1344 Fgoto_char (start);
1345 Fnarrow_to_region (make_number (BEGV), end);
1346 }
1347
1333 instream = stream; 1348 instream = stream;
1349 read_next:
1334 c = READCHAR; 1350 c = READCHAR;
1335 if (c == ';') 1351 if (c == ';')
1336 { 1352 {
1337 while ((c = READCHAR) != '\n' && c != -1); 1353 while ((c = READCHAR) != '\n' && c != -1);
1338 continue; 1354 goto read_next;
1339 } 1355 }
1340 if (c < 0) break; 1356 if (c < 0)
1357 {
1358 unbind_to (count1, Qnil);
1359 break;
1360 }
1341 1361
1342 /* Ignore whitespace here, so we can detect eof. */ 1362 /* Ignore whitespace here, so we can detect eof. */
1343 if (c == ' ' || c == '\t' || c == '\n' || c == '\f' || c == '\r') 1363 if (c == ' ' || c == '\t' || c == '\n' || c == '\f' || c == '\r')
1344 continue; 1364 goto read_next;
1345 1365
1346 if (!NILP (Vpurify_flag) && c == '(') 1366 if (!NILP (Vpurify_flag) && c == '(')
1347 { 1367 {
1348 int count1 = SPECPDL_INDEX ();
1349 record_unwind_protect (unreadpure, Qnil); 1368 record_unwind_protect (unreadpure, Qnil);
1350 val = read_list (-1, readcharfun); 1369 val = read_list (-1, readcharfun);
1351 unbind_to (count1, Qnil);
1352 } 1370 }
1353 else 1371 else
1354 { 1372 {
1355 UNREAD (c); 1373 UNREAD (c);
1356 read_objects = Qnil; 1374 read_objects = Qnil;
1372 val = call1 (Vload_read_function, readcharfun); 1390 val = call1 (Vload_read_function, readcharfun);
1373 else 1391 else
1374 val = read_internal_start (readcharfun, Qnil, Qnil); 1392 val = read_internal_start (readcharfun, Qnil, Qnil);
1375 } 1393 }
1376 1394
1395 if (!NILP (start) && continue_reading_p)
1396 start = Fpoint_marker ();
1397 unbind_to (count1, Qnil);
1398
1377 val = (*evalfun) (val); 1399 val = (*evalfun) (val);
1378 1400
1379 if (printflag) 1401 if (printflag)
1380 { 1402 {
1381 Vvalues = Fcons (val, Vvalues); 1403 Vvalues = Fcons (val, Vvalues);
1430 filename = XBUFFER (buf)->filename; 1452 filename = XBUFFER (buf)->filename;
1431 1453
1432 specbind (Qstandard_output, tem); 1454 specbind (Qstandard_output, tem);
1433 record_unwind_protect (save_excursion_restore, save_excursion_save ()); 1455 record_unwind_protect (save_excursion_restore, save_excursion_save ());
1434 BUF_SET_PT (XBUFFER (buf), BUF_BEGV (XBUFFER (buf))); 1456 BUF_SET_PT (XBUFFER (buf), BUF_BEGV (XBUFFER (buf)));
1435 readevalloop (buf, 0, filename, Feval, !NILP (printflag), unibyte, Qnil); 1457 readevalloop (buf, 0, filename, Feval,
1458 !NILP (printflag), unibyte, Qnil, Qnil, Qnil);
1436 unbind_to (count, Qnil); 1459 unbind_to (count, Qnil);
1437 1460
1438 return Qnil; 1461 return Qnil;
1439 } 1462 }
1440 1463
1462 tem = Qsymbolp; 1485 tem = Qsymbolp;
1463 else 1486 else
1464 tem = printflag; 1487 tem = printflag;
1465 specbind (Qstandard_output, tem); 1488 specbind (Qstandard_output, tem);
1466 1489
1467 if (NILP (printflag)) 1490 /* readevalloop calls functions which check the type of start and end. */
1468 record_unwind_protect (save_excursion_restore, save_excursion_save ());
1469 record_unwind_protect (save_restriction_restore, save_restriction_save ());
1470
1471 /* This both uses start and checks its type. */
1472 Fgoto_char (start);
1473 Fnarrow_to_region (make_number (BEGV), end);
1474 readevalloop (cbuf, 0, XBUFFER (cbuf)->filename, Feval, 1491 readevalloop (cbuf, 0, XBUFFER (cbuf)->filename, Feval,
1475 !NILP (printflag), Qnil, read_function); 1492 !NILP (printflag), Qnil, read_function,
1493 start, end);
1476 1494
1477 return unbind_to (count, Qnil); 1495 return unbind_to (count, Qnil);
1478 } 1496 }
1479 1497
1480 1498