Mercurial > emacs
comparison src/buffer.c @ 2508:3aa2f3b35353
* buffer.c (Fmake_overlay, Fmove_overlay): New optional BUFFER
arguments.
(recenter_overlay_lists): New argument BUF, to use instead of the
current buffer.
(Foverlay_recenter): Pass the appropriate arguments to
recenter_overlay_lists.
* buffer.c (Fdelete_overlay): Don't assume that overlay is in the
current buffer. Don't forget to declare the argument a Lisp_Object.
| author | Jim Blandy <jimb@redhat.com> |
|---|---|
| date | Sat, 10 Apr 1993 07:57:57 +0000 |
| parents | d5d7e6996604 |
| children | f694fc6cdd33 |
comparison
equal
deleted
inserted
replaced
| 2507:7ba4316ae840 | 2508:3aa2f3b35353 |
|---|---|
| 1273 | 1273 |
| 1274 *next_ptr = next; | 1274 *next_ptr = next; |
| 1275 return idx; | 1275 return idx; |
| 1276 } | 1276 } |
| 1277 | 1277 |
| 1278 /* Shift overlays in the current buffer's overlay lists, | 1278 /* Shift overlays in BUF's overlay lists, to center the lists at POS. */ |
| 1279 to center the lists at POS. */ | |
| 1280 | 1279 |
| 1281 void | 1280 void |
| 1282 recenter_overlay_lists (pos) | 1281 recenter_overlay_lists (buf, pos) |
| 1282 struct buffer *buf; | |
| 1283 int pos; | 1283 int pos; |
| 1284 { | 1284 { |
| 1285 Lisp_Object overlay, tail, next, prev, beg, end; | 1285 Lisp_Object overlay, tail, next, prev, beg, end; |
| 1286 | 1286 |
| 1287 /* See if anything in overlays_before should move to overlays_after. */ | 1287 /* See if anything in overlays_before should move to overlays_after. */ |
| 1288 | 1288 |
| 1289 /* We don't strictly need prev in this loop; it should always be nil. | 1289 /* We don't strictly need prev in this loop; it should always be nil. |
| 1290 But we use it for symmetry and in case that should cease to be true | 1290 But we use it for symmetry and in case that should cease to be true |
| 1291 with some future change. */ | 1291 with some future change. */ |
| 1292 prev = Qnil; | 1292 prev = Qnil; |
| 1293 for (tail = current_buffer->overlays_before; | 1293 for (tail = buf->overlays_before; |
| 1294 CONSP (tail); | 1294 CONSP (tail); |
| 1295 prev = tail, tail = next) | 1295 prev = tail, tail = next) |
| 1296 { | 1296 { |
| 1297 next = XCONS (tail)->cdr; | 1297 next = XCONS (tail)->cdr; |
| 1298 overlay = XCONS (tail)->car; | 1298 overlay = XCONS (tail)->car; |
| 1302 { | 1302 { |
| 1303 /* Splice the cons cell TAIL out of overlays_before. */ | 1303 /* Splice the cons cell TAIL out of overlays_before. */ |
| 1304 if (!NILP (prev)) | 1304 if (!NILP (prev)) |
| 1305 XCONS (prev)->cdr = next; | 1305 XCONS (prev)->cdr = next; |
| 1306 else | 1306 else |
| 1307 current_buffer->overlays_before = next; | 1307 buf->overlays_before = next; |
| 1308 tail = prev; | 1308 tail = prev; |
| 1309 continue; | 1309 continue; |
| 1310 } | 1310 } |
| 1311 | 1311 |
| 1312 beg = OVERLAY_START (overlay); | 1312 beg = OVERLAY_START (overlay); |
| 1320 | 1320 |
| 1321 /* Splice the cons cell TAIL out of overlays_before. */ | 1321 /* Splice the cons cell TAIL out of overlays_before. */ |
| 1322 if (!NILP (prev)) | 1322 if (!NILP (prev)) |
| 1323 XCONS (prev)->cdr = next; | 1323 XCONS (prev)->cdr = next; |
| 1324 else | 1324 else |
| 1325 current_buffer->overlays_before = next; | 1325 buf->overlays_before = next; |
| 1326 | 1326 |
| 1327 /* Search thru overlays_after for where to put it. */ | 1327 /* Search thru overlays_after for where to put it. */ |
| 1328 other_prev = Qnil; | 1328 other_prev = Qnil; |
| 1329 for (other = current_buffer->overlays_after; | 1329 for (other = buf->overlays_after; |
| 1330 CONSP (other); | 1330 CONSP (other); |
| 1331 other_prev = other, other = XCONS (other)->cdr) | 1331 other_prev = other, other = XCONS (other)->cdr) |
| 1332 { | 1332 { |
| 1333 Lisp_Object otherbeg, otheroverlay, follower; | 1333 Lisp_Object otherbeg, otheroverlay, follower; |
| 1334 int win; | 1334 int win; |
| 1345 /* Add TAIL to overlays_after before OTHER. */ | 1345 /* Add TAIL to overlays_after before OTHER. */ |
| 1346 XCONS (tail)->cdr = other; | 1346 XCONS (tail)->cdr = other; |
| 1347 if (!NILP (other_prev)) | 1347 if (!NILP (other_prev)) |
| 1348 XCONS (other_prev)->cdr = tail; | 1348 XCONS (other_prev)->cdr = tail; |
| 1349 else | 1349 else |
| 1350 current_buffer->overlays_after = tail; | 1350 buf->overlays_after = tail; |
| 1351 tail = prev; | 1351 tail = prev; |
| 1352 } | 1352 } |
| 1353 else | 1353 else |
| 1354 /* We've reached the things that should stay in overlays_before. | 1354 /* We've reached the things that should stay in overlays_before. |
| 1355 All the rest of overlays_before must end even earlier, | 1355 All the rest of overlays_before must end even earlier, |
| 1357 break; | 1357 break; |
| 1358 } | 1358 } |
| 1359 | 1359 |
| 1360 /* See if anything in overlays_after should be in overlays_before. */ | 1360 /* See if anything in overlays_after should be in overlays_before. */ |
| 1361 prev = Qnil; | 1361 prev = Qnil; |
| 1362 for (tail = current_buffer->overlays_after; | 1362 for (tail = buf->overlays_after; |
| 1363 CONSP (tail); | 1363 CONSP (tail); |
| 1364 prev = tail, tail = next) | 1364 prev = tail, tail = next) |
| 1365 { | 1365 { |
| 1366 next = XCONS (tail)->cdr; | 1366 next = XCONS (tail)->cdr; |
| 1367 overlay = XCONS (tail)->car; | 1367 overlay = XCONS (tail)->car; |
| 1371 { | 1371 { |
| 1372 /* Splice the cons cell TAIL out of overlays_after. */ | 1372 /* Splice the cons cell TAIL out of overlays_after. */ |
| 1373 if (!NILP (prev)) | 1373 if (!NILP (prev)) |
| 1374 XCONS (prev)->cdr = next; | 1374 XCONS (prev)->cdr = next; |
| 1375 else | 1375 else |
| 1376 current_buffer->overlays_after = next; | 1376 buf->overlays_after = next; |
| 1377 tail = prev; | 1377 tail = prev; |
| 1378 continue; | 1378 continue; |
| 1379 } | 1379 } |
| 1380 | 1380 |
| 1381 beg = OVERLAY_START (overlay); | 1381 beg = OVERLAY_START (overlay); |
| 1394 | 1394 |
| 1395 /* Splice the cons cell TAIL out of overlays_after. */ | 1395 /* Splice the cons cell TAIL out of overlays_after. */ |
| 1396 if (!NILP (prev)) | 1396 if (!NILP (prev)) |
| 1397 XCONS (prev)->cdr = next; | 1397 XCONS (prev)->cdr = next; |
| 1398 else | 1398 else |
| 1399 current_buffer->overlays_after = next; | 1399 buf->overlays_after = next; |
| 1400 | 1400 |
| 1401 /* Search thru overlays_before for where to put it. */ | 1401 /* Search thru overlays_before for where to put it. */ |
| 1402 other_prev = Qnil; | 1402 other_prev = Qnil; |
| 1403 for (other = current_buffer->overlays_before; | 1403 for (other = buf->overlays_before; |
| 1404 CONSP (other); | 1404 CONSP (other); |
| 1405 other_prev = other, other = XCONS (other)->cdr) | 1405 other_prev = other, other = XCONS (other)->cdr) |
| 1406 { | 1406 { |
| 1407 Lisp_Object otherend, otheroverlay; | 1407 Lisp_Object otherend, otheroverlay; |
| 1408 int win; | 1408 int win; |
| 1419 /* Add TAIL to overlays_before before OTHER. */ | 1419 /* Add TAIL to overlays_before before OTHER. */ |
| 1420 XCONS (tail)->cdr = other; | 1420 XCONS (tail)->cdr = other; |
| 1421 if (!NILP (other_prev)) | 1421 if (!NILP (other_prev)) |
| 1422 XCONS (other_prev)->cdr = tail; | 1422 XCONS (other_prev)->cdr = tail; |
| 1423 else | 1423 else |
| 1424 current_buffer->overlays_before = tail; | 1424 buf->overlays_before = tail; |
| 1425 tail = prev; | 1425 tail = prev; |
| 1426 } | 1426 } |
| 1427 } | 1427 } |
| 1428 | 1428 |
| 1429 XFASTINT (current_buffer->overlay_center) = pos; | 1429 XFASTINT (buf->overlay_center) = pos; |
| 1430 } | 1430 } |
| 1431 | 1431 |
| 1432 DEFUN ("make-overlay", Fmake_overlay, Smake_overlay, 2, 2, 0, | 1432 DEFUN ("make-overlay", Fmake_overlay, Smake_overlay, 2, 3, 0, |
| 1433 "Create a new overlay in the current buffer, with range BEG to END.\n\ | 1433 "Create a new overlay with range BEG to END in BUFFER.\n\ |
| 1434 If omitted, BUFFER defaults to the current buffer.\n\ | |
| 1434 BEG and END may be integers or markers.") | 1435 BEG and END may be integers or markers.") |
| 1435 (beg, end) | 1436 (beg, end, buffer) |
| 1436 Lisp_Object beg, end; | 1437 Lisp_Object beg, end, buffer; |
| 1437 { | 1438 { |
| 1438 Lisp_Object overlay; | 1439 Lisp_Object overlay; |
| 1439 | 1440 struct buffer *b; |
| 1440 if (MARKERP (beg) && XBUFFER (Fmarker_buffer (beg)) != current_buffer) | 1441 |
| 1441 error ("Marker points into wrong buffer"); | 1442 if (NILP (buffer)) |
| 1442 if (MARKERP (end) && XBUFFER (Fmarker_buffer (end)) != current_buffer) | 1443 XSET (buffer, Lisp_Buffer, current_buffer); |
| 1443 error ("Marker points into wrong buffer"); | 1444 CHECK_BUFFER (buffer, 2); |
| 1444 | 1445 |
| 1445 overlay = Fcons (Fcons (Fcopy_marker (beg), Fcopy_marker (end)), Qnil); | 1446 b = XBUFFER (buffer); |
| 1447 | |
| 1448 if (MARKERP (beg)) | |
| 1449 { | |
| 1450 if (! EQ (Fmarker_buffer (beg), buffer)) | |
| 1451 error ("Marker points into wrong buffer"); | |
| 1452 else | |
| 1453 beg = Fcopy_marker (beg); | |
| 1454 } | |
| 1455 else | |
| 1456 beg = Fset_marker (Fmake_marker (), beg, buffer); | |
| 1457 if (MARKERP (end)) | |
| 1458 { | |
| 1459 if (! EQ (Fmarker_buffer (end), buffer)) | |
| 1460 error ("Marker points into wrong buffer"); | |
| 1461 else | |
| 1462 end = Fcopy_marker (end); | |
| 1463 } | |
| 1464 else | |
| 1465 end = Fset_marker (Fmake_marker (), end, buffer); | |
| 1466 | |
| 1467 overlay = Fcons (Fcons (beg, end), Qnil); | |
| 1446 | 1468 |
| 1447 /* Put the new overlay on the wrong list. */ | 1469 /* Put the new overlay on the wrong list. */ |
| 1448 end = OVERLAY_END (overlay); | 1470 end = OVERLAY_END (overlay); |
| 1449 if (OVERLAY_POSITION (end) < XINT (current_buffer->overlay_center)) | 1471 if (OVERLAY_POSITION (end) < XINT (b->overlay_center)) |
| 1450 current_buffer->overlays_after | 1472 b->overlays_after = Fcons (overlay, b->overlays_after); |
| 1451 = Fcons (overlay, current_buffer->overlays_after); | |
| 1452 else | 1473 else |
| 1453 current_buffer->overlays_before | 1474 b->overlays_before = Fcons (overlay, b->overlays_before); |
| 1454 = Fcons (overlay, current_buffer->overlays_before); | |
| 1455 | 1475 |
| 1456 /* This puts it in the right list, and in the right order. */ | 1476 /* This puts it in the right list, and in the right order. */ |
| 1457 recenter_overlay_lists (XINT (current_buffer->overlay_center)); | 1477 recenter_overlay_lists (b, XINT (b->overlay_center)); |
| 1458 | 1478 |
| 1459 return overlay; | 1479 return overlay; |
| 1460 } | 1480 } |
| 1461 | 1481 |
| 1462 DEFUN ("move-overlay", Fmove_overlay, Smove_overlay, 3, 3, 0, | 1482 DEFUN ("move-overlay", Fmove_overlay, Smove_overlay, 3, 4, 0, |
| 1463 "Set the endpoints of OVERLAY to BEG and END.") | 1483 "Set the endpoints of OVERLAY to BEG and END in BUFFER.\n\ |
| 1464 (overlay, beg, end) | 1484 If omitted, don't change OVERLAY's buffer.") |
| 1465 Lisp_Object overlay, beg, end; | 1485 (overlay, beg, end, buffer) |
| 1466 { | 1486 Lisp_Object overlay, beg, end, buffer; |
| 1487 { | |
| 1488 struct buffer *b; | |
| 1489 | |
| 1467 if (!OVERLAY_VALID (overlay)) | 1490 if (!OVERLAY_VALID (overlay)) |
| 1468 error ("Invalid overlay object"); | 1491 error ("Invalid overlay object"); |
| 1469 | 1492 |
| 1470 current_buffer->overlays_before | 1493 if (NILP (buffer)) |
| 1471 = Fdelq (overlay, current_buffer->overlays_before); | 1494 buffer = Fmarker_buffer (OVERLAY_START (overlay)); |
| 1472 current_buffer->overlays_after | 1495 CHECK_BUFFER (buffer, 3); |
| 1473 = Fdelq (overlay, current_buffer->overlays_after); | 1496 |
| 1474 | 1497 b = XBUFFER (buffer); |
| 1475 Fset_marker (OVERLAY_START (overlay), beg, Qnil); | 1498 |
| 1476 Fset_marker (OVERLAY_END (overlay), end, Qnil); | 1499 b->overlays_before = Fdelq (overlay, b->overlays_before); |
| 1500 b->overlays_after = Fdelq (overlay, b->overlays_after); | |
| 1501 | |
| 1502 Fset_marker (OVERLAY_START (overlay), beg, buffer); | |
| 1503 Fset_marker (OVERLAY_END (overlay), end, buffer); | |
| 1477 | 1504 |
| 1478 /* Put the overlay on the wrong list. */ | 1505 /* Put the overlay on the wrong list. */ |
| 1479 end = OVERLAY_END (overlay); | 1506 end = OVERLAY_END (overlay); |
| 1480 if (OVERLAY_POSITION (end) < XINT (current_buffer->overlay_center)) | 1507 if (OVERLAY_POSITION (end) < XINT (b->overlay_center)) |
| 1481 current_buffer->overlays_after | 1508 b->overlays_after = Fcons (overlay, b->overlays_after); |
| 1482 = Fcons (overlay, current_buffer->overlays_after); | |
| 1483 else | 1509 else |
| 1484 current_buffer->overlays_before | 1510 b->overlays_before = Fcons (overlay, b->overlays_before); |
| 1485 = Fcons (overlay, current_buffer->overlays_before); | |
| 1486 | 1511 |
| 1487 /* This puts it in the right list, and in the right order. */ | 1512 /* This puts it in the right list, and in the right order. */ |
| 1488 recenter_overlay_lists (XINT (current_buffer->overlay_center)); | 1513 recenter_overlay_lists (b, XINT (b->overlay_center)); |
| 1489 | 1514 |
| 1490 return overlay; | 1515 return overlay; |
| 1491 } | 1516 } |
| 1492 | 1517 |
| 1493 DEFUN ("delete-overlay", Fdelete_overlay, Sdelete_overlay, 1, 1, 0, | 1518 DEFUN ("delete-overlay", Fdelete_overlay, Sdelete_overlay, 1, 1, 0, |
| 1494 "Delete the overlay OVERLAY from the current buffer.") | 1519 "Delete the overlay OVERLAY from its buffer.") |
| 1495 (overlay) | 1520 (overlay) |
| 1496 { | 1521 Lisp_Object overlay; |
| 1497 current_buffer->overlays_before | 1522 { |
| 1498 = Fdelq (overlay, current_buffer->overlays_before); | 1523 struct buffer *b; |
| 1499 current_buffer->overlays_after | 1524 |
| 1500 = Fdelq (overlay, current_buffer->overlays_after); | 1525 if (OVERLAY_VALID (overlay)) |
| 1526 b = XBUFFER (Fmarker_buffer (OVERLAY_START (overlay))); | |
| 1527 else | |
| 1528 /* Guess! */ | |
| 1529 b = current_buffer; | |
| 1530 | |
| 1531 b->overlays_before = Fdelq (overlay, b->overlays_before); | |
| 1532 b->overlays_after = Fdelq (overlay, b->overlays_after); | |
| 1533 | |
| 1501 return Qnil; | 1534 return Qnil; |
| 1502 } | 1535 } |
| 1503 | 1536 |
| 1504 DEFUN ("overlays-at", Foverlays_at, Soverlays_at, 1, 1, 0, | 1537 DEFUN ("overlays-at", Foverlays_at, Soverlays_at, 1, 1, 0, |
| 1505 "Return a list of the overays that contain position POS.") | 1538 "Return a list of the overays that contain position POS.") |
| 1595 (pos) | 1628 (pos) |
| 1596 Lisp_Object pos; | 1629 Lisp_Object pos; |
| 1597 { | 1630 { |
| 1598 CHECK_NUMBER_COERCE_MARKER (pos, 0); | 1631 CHECK_NUMBER_COERCE_MARKER (pos, 0); |
| 1599 | 1632 |
| 1600 recenter_overlay_lists (XINT (pos)); | 1633 recenter_overlay_lists (current_buffer, XINT (pos)); |
| 1601 return Qnil; | 1634 return Qnil; |
| 1602 } | 1635 } |
| 1603 | 1636 |
| 1604 DEFUN ("overlay-get", Foverlay_get, Soverlay_get, 2, 2, 0, | 1637 DEFUN ("overlay-get", Foverlay_get, Soverlay_get, 2, 2, 0, |
| 1605 "Get the property of overlay OVERLAY with property name NAME.") | 1638 "Get the property of overlay OVERLAY with property name NAME.") |
