comparison src/lread.c @ 67906:28939487a2d5

(readevalloop): Test for reading a whole buffer before actually reading anything. Handle all cases, including START = END = nil and an already-narrowed buffer. Convert END to a marker if it is a number.
author Richard M. Stallman <rms@gnu.org>
date Fri, 30 Dec 2005 04:54:57 +0000
parents 998f4ca6948d
children 581e383fb47c c69d44922688 7beb78bc1f8e
comparison
equal deleted inserted replaced
67905:71ec21feb311 67906:28939487a2d5
1316 register int c; 1316 register int c;
1317 register Lisp_Object val; 1317 register Lisp_Object val;
1318 int count = SPECPDL_INDEX (); 1318 int count = SPECPDL_INDEX ();
1319 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4; 1319 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
1320 struct buffer *b = 0; 1320 struct buffer *b = 0;
1321 int bpos;
1321 int continue_reading_p; 1322 int continue_reading_p;
1323 /* Nonzero if reading an entire buffer. */
1324 int whole_buffer = 0;
1325 /* 1 on the first time around. */
1326 int first_sexp = 1;
1327
1328 if (MARKERP (readcharfun))
1329 {
1330 if (NILP (start))
1331 start = readcharfun;
1332 }
1322 1333
1323 if (BUFFERP (readcharfun)) 1334 if (BUFFERP (readcharfun))
1324 b = XBUFFER (readcharfun); 1335 b = XBUFFER (readcharfun);
1325 else if (MARKERP (readcharfun)) 1336 else if (MARKERP (readcharfun))
1326 b = XMARKER (readcharfun)->buffer; 1337 b = XMARKER (readcharfun)->buffer;
1341 { 1352 {
1342 int count1 = SPECPDL_INDEX (); 1353 int count1 = SPECPDL_INDEX ();
1343 1354
1344 if (b != 0 && NILP (b->name)) 1355 if (b != 0 && NILP (b->name))
1345 error ("Reading from killed buffer"); 1356 error ("Reading from killed buffer");
1346
1347 1357
1348 if (!NILP (start)) 1358 if (!NILP (start))
1349 { 1359 {
1350 /* Switch to the buffer we are reading from. */ 1360 /* Switch to the buffer we are reading from. */
1351 record_unwind_protect (save_excursion_restore, save_excursion_save ()); 1361 record_unwind_protect (save_excursion_restore, save_excursion_save ());
1357 record_unwind_protect (save_restriction_restore, save_restriction_save ()); 1367 record_unwind_protect (save_restriction_restore, save_restriction_save ());
1358 /* Those get unbound after we read one expression. */ 1368 /* Those get unbound after we read one expression. */
1359 1369
1360 /* Set point and ZV around stuff to be read. */ 1370 /* Set point and ZV around stuff to be read. */
1361 Fgoto_char (start); 1371 Fgoto_char (start);
1362 Fnarrow_to_region (make_number (BEGV), end); 1372 if (!NILP (end))
1363 } 1373 Fnarrow_to_region (make_number (BEGV), end);
1374
1375 /* Just for cleanliness, convert END to a marker
1376 if it is an integer. */
1377 if (INTEGERP (end))
1378 end = Fpoint_max_marker ();
1379 }
1380
1381 /* On the first cycle, we can easily test here
1382 whether we are reading the whole buffer. */
1383 if (b && first_sexp)
1384 whole_buffer = (PT == BEG && ZV == Z);
1364 1385
1365 instream = stream; 1386 instream = stream;
1366 read_next: 1387 read_next:
1367 c = READCHAR; 1388 c = READCHAR;
1368 if (c == ';') 1389 if (c == ';')
1409 val = read_internal_start (readcharfun, Qnil, Qnil); 1430 val = read_internal_start (readcharfun, Qnil, Qnil);
1410 } 1431 }
1411 1432
1412 if (!NILP (start) && continue_reading_p) 1433 if (!NILP (start) && continue_reading_p)
1413 start = Fpoint_marker (); 1434 start = Fpoint_marker ();
1435
1436 /* Restore saved point and BEGV. */
1414 unbind_to (count1, Qnil); 1437 unbind_to (count1, Qnil);
1415 1438
1439 /* Now eval what we just read. */
1416 val = (*evalfun) (val); 1440 val = (*evalfun) (val);
1417 1441
1418 if (printflag) 1442 if (printflag)
1419 { 1443 {
1420 Vvalues = Fcons (val, Vvalues); 1444 Vvalues = Fcons (val, Vvalues);
1421 if (EQ (Vstandard_output, Qt)) 1445 if (EQ (Vstandard_output, Qt))
1422 Fprin1 (val, Qnil); 1446 Fprin1 (val, Qnil);
1423 else 1447 else
1424 Fprint (val, Qnil); 1448 Fprint (val, Qnil);
1425 } 1449 }
1450
1451 first_sexp = 0;
1426 } 1452 }
1427 1453
1428 build_load_history (sourcename, 1454 build_load_history (sourcename,
1429 stream || (INTEGERP (start) && INTEGERP (end) 1455 stream || whole_buffer);
1430 && XINT (start) == BEG && XINT (end) == Z));
1431 1456
1432 UNGCPRO; 1457 UNGCPRO;
1433 1458
1434 unbind_to (count, Qnil); 1459 unbind_to (count, Qnil);
1435 } 1460 }