comparison src/buffer.c @ 2776:8bf3bb4c20dd

* lisp.h (Lisp_Overlay): New tag. (OVERLAYP): New predicate. (CHECK_OVERLAY): New type-checker. (Qoverlayp): New extern declaration. * buffer.c (Foverlayp): New function. (Qoverlayp): New atom. (overlays_at, recenter_overlay_lists): Abort if we encounter an invalid overlay. (syms_of_buffer): defsubr Soverlayp; initialize Qoverlayp. (Fdelete_overlay): Set the overlay's markers to point nowhere. Use CHECK_OVERLAY instead of signalling a special error. (Fmove_overlay, Foverlay_put): Use CHECK_OVERLAY instead of signalling a special error. (Foverlay_get): Use CHECK_OVERLAY. * fns.c (internal_equal): Define this for overlays. * buffer.h (OVERLAY_VALID): Define in terms of OVERLAYP. * print.c (print): Give overlays their own print syntax. * alloc.c (mark_object): Treat overlays like conses. * buffer.c (Foverlay_get): Return Qnil if the requested property is missing from the property list.
author Jim Blandy <jimb@redhat.com>
date Fri, 14 May 1993 14:36:01 +0000
parents 16db9d1af886
children 995c6e665599
comparison
equal deleted inserted replaced
2775:72277ed7609e 2776:8bf3bb4c20dd
121 Lisp_Object Qprotected_field; 121 Lisp_Object Qprotected_field;
122 122
123 Lisp_Object QSFundamental; /* A string "Fundamental" */ 123 Lisp_Object QSFundamental; /* A string "Fundamental" */
124 124
125 Lisp_Object Qkill_buffer_hook; 125 Lisp_Object Qkill_buffer_hook;
126
127 Lisp_Object Qoverlayp;
126 128
127 /* For debugging; temporary. See set_buffer_internal. */ 129 /* For debugging; temporary. See set_buffer_internal. */
128 /* Lisp_Object Qlisp_mode, Vcheck_symbol; */ 130 /* Lisp_Object Qlisp_mode, Vcheck_symbol; */
129 131
130 nsberror (spec) 132 nsberror (spec)
1194 } 1196 }
1195 1197
1196 /* Find all the overlays in the current buffer that contain position POS. 1198 /* Find all the overlays in the current buffer that contain position POS.
1197 Return the number found, and store them in a vector in *VEC_PTR. 1199 Return the number found, and store them in a vector in *VEC_PTR.
1198 Store in *LEN_PTR the size allocated for the vector. 1200 Store in *LEN_PTR the size allocated for the vector.
1199 Store in *NEXT_PTR the next position after POS where an overlay starts. 1201 Store in *NEXT_PTR the next position after POS where an overlay starts,
1202 or ZV if there are no more overlays.
1200 1203
1201 *VEC_PTR and *LEN_PTR should contain a valid vector and size 1204 *VEC_PTR and *LEN_PTR should contain a valid vector and size
1202 when this function is called. */ 1205 when this function is called. */
1203 1206
1204 int 1207 int
1211 Lisp_Object tail, overlay, start, end, result; 1214 Lisp_Object tail, overlay, start, end, result;
1212 int idx = 0; 1215 int idx = 0;
1213 int len = *len_ptr; 1216 int len = *len_ptr;
1214 Lisp_Object *vec = *vec_ptr; 1217 Lisp_Object *vec = *vec_ptr;
1215 int next = ZV; 1218 int next = ZV;
1216 int startpos;
1217
1218 for (tail = current_buffer->overlays_before; 1219 for (tail = current_buffer->overlays_before;
1219 CONSP (tail); 1220 CONSP (tail);
1220 tail = XCONS (tail)->cdr) 1221 tail = XCONS (tail)->cdr)
1221 { 1222 {
1223 int startpos;
1224
1222 overlay = XCONS (tail)->car; 1225 overlay = XCONS (tail)->car;
1223 if (! OVERLAY_VALID (overlay)) 1226 if (! OVERLAY_VALID (overlay))
1224 continue; 1227 abort ();
1225 1228
1226 start = OVERLAY_START (overlay); 1229 start = OVERLAY_START (overlay);
1227 end = OVERLAY_END (overlay); 1230 end = OVERLAY_END (overlay);
1228 if (OVERLAY_POSITION (end) <= pos) 1231 if (OVERLAY_POSITION (end) <= pos)
1229 break; 1232 break;
1244 1247
1245 for (tail = current_buffer->overlays_after; 1248 for (tail = current_buffer->overlays_after;
1246 CONSP (tail); 1249 CONSP (tail);
1247 tail = XCONS (tail)->cdr) 1250 tail = XCONS (tail)->cdr)
1248 { 1251 {
1252 int startpos;
1253
1249 overlay = XCONS (tail)->car; 1254 overlay = XCONS (tail)->car;
1250 if (! OVERLAY_VALID (overlay)) 1255 if (! OVERLAY_VALID (overlay))
1251 continue; 1256 abort ();
1252 1257
1253 start = OVERLAY_START (overlay); 1258 start = OVERLAY_START (overlay);
1254 end = OVERLAY_END (overlay); 1259 end = OVERLAY_END (overlay);
1255 startpos = OVERLAY_POSITION (start); 1260 startpos = OVERLAY_POSITION (start);
1256 if (startpos > pos) 1261 if (pos < startpos)
1257 { 1262 {
1258 if (startpos < next) 1263 if (startpos < next)
1259 next = startpos; 1264 next = startpos;
1260 break; 1265 break;
1261 } 1266 }
1262 if (OVERLAY_POSITION (end) > pos) 1267 if (pos < OVERLAY_POSITION (end))
1263 { 1268 {
1264 if (idx == len) 1269 if (idx == len)
1265 { 1270 {
1266 *len_ptr = len *= 2; 1271 *len_ptr = len *= 2;
1267 vec = (Lisp_Object *) xrealloc (vec, len * sizeof (Lisp_Object)); 1272 vec = (Lisp_Object *) xrealloc (vec, len * sizeof (Lisp_Object));
1297 next = XCONS (tail)->cdr; 1302 next = XCONS (tail)->cdr;
1298 overlay = XCONS (tail)->car; 1303 overlay = XCONS (tail)->car;
1299 1304
1300 /* If the overlay is not valid, get rid of it. */ 1305 /* If the overlay is not valid, get rid of it. */
1301 if (!OVERLAY_VALID (overlay)) 1306 if (!OVERLAY_VALID (overlay))
1307 #if 1
1308 abort ();
1309 #else
1302 { 1310 {
1303 /* Splice the cons cell TAIL out of overlays_before. */ 1311 /* Splice the cons cell TAIL out of overlays_before. */
1304 if (!NILP (prev)) 1312 if (!NILP (prev))
1305 XCONS (prev)->cdr = next; 1313 XCONS (prev)->cdr = next;
1306 else 1314 else
1307 buf->overlays_before = next; 1315 buf->overlays_before = next;
1308 tail = prev; 1316 tail = prev;
1309 continue; 1317 continue;
1310 } 1318 }
1319 #endif
1311 1320
1312 beg = OVERLAY_START (overlay); 1321 beg = OVERLAY_START (overlay);
1313 end = OVERLAY_END (overlay); 1322 end = OVERLAY_END (overlay);
1314 1323
1315 if (OVERLAY_POSITION (end) > pos) 1324 if (OVERLAY_POSITION (end) > pos)
1333 Lisp_Object otherbeg, otheroverlay, follower; 1342 Lisp_Object otherbeg, otheroverlay, follower;
1334 int win; 1343 int win;
1335 1344
1336 otheroverlay = XCONS (other)->car; 1345 otheroverlay = XCONS (other)->car;
1337 if (! OVERLAY_VALID (otheroverlay)) 1346 if (! OVERLAY_VALID (otheroverlay))
1338 continue; 1347 abort ();
1339 1348
1340 otherbeg = OVERLAY_START (otheroverlay); 1349 otherbeg = OVERLAY_START (otheroverlay);
1341 if (OVERLAY_POSITION (otherbeg) >= where) 1350 if (OVERLAY_POSITION (otherbeg) >= where)
1342 break; 1351 break;
1343 } 1352 }
1366 next = XCONS (tail)->cdr; 1375 next = XCONS (tail)->cdr;
1367 overlay = XCONS (tail)->car; 1376 overlay = XCONS (tail)->car;
1368 1377
1369 /* If the overlay is not valid, get rid of it. */ 1378 /* If the overlay is not valid, get rid of it. */
1370 if (!OVERLAY_VALID (overlay)) 1379 if (!OVERLAY_VALID (overlay))
1380 #if 1
1381 abort ();
1382 #else
1371 { 1383 {
1372 /* Splice the cons cell TAIL out of overlays_after. */ 1384 /* Splice the cons cell TAIL out of overlays_after. */
1373 if (!NILP (prev)) 1385 if (!NILP (prev))
1374 XCONS (prev)->cdr = next; 1386 XCONS (prev)->cdr = next;
1375 else 1387 else
1376 buf->overlays_after = next; 1388 buf->overlays_after = next;
1377 tail = prev; 1389 tail = prev;
1378 continue; 1390 continue;
1379 } 1391 }
1392 #endif
1380 1393
1381 beg = OVERLAY_START (overlay); 1394 beg = OVERLAY_START (overlay);
1382 end = OVERLAY_END (overlay); 1395 end = OVERLAY_END (overlay);
1383 1396
1384 /* Stop looking, when we know that nothing further 1397 /* Stop looking, when we know that nothing further
1407 Lisp_Object otherend, otheroverlay; 1420 Lisp_Object otherend, otheroverlay;
1408 int win; 1421 int win;
1409 1422
1410 otheroverlay = XCONS (other)->car; 1423 otheroverlay = XCONS (other)->car;
1411 if (! OVERLAY_VALID (otheroverlay)) 1424 if (! OVERLAY_VALID (otheroverlay))
1412 continue; 1425 abort ();
1413 1426
1414 otherend = OVERLAY_END (otheroverlay); 1427 otherend = OVERLAY_END (otheroverlay);
1415 if (OVERLAY_POSITION (otherend) <= where) 1428 if (OVERLAY_POSITION (otherend) <= where)
1416 break; 1429 break;
1417 } 1430 }
1427 } 1440 }
1428 1441
1429 XFASTINT (buf->overlay_center) = pos; 1442 XFASTINT (buf->overlay_center) = pos;
1430 } 1443 }
1431 1444
1445 DEFUN ("overlayp", Foverlayp, Soverlayp, 1, 1, 0,
1446 "Return t if OBJECT is an overlay.")
1447 (object)
1448 Lisp_Object object;
1449 {
1450 return (OVERLAYP (object) ? Qt : Qnil);
1451 }
1452
1432 DEFUN ("make-overlay", Fmake_overlay, Smake_overlay, 2, 3, 0, 1453 DEFUN ("make-overlay", Fmake_overlay, Smake_overlay, 2, 3, 0,
1433 "Create a new overlay with range BEG to END in BUFFER.\n\ 1454 "Create a new overlay with range BEG to END in BUFFER.\n\
1434 If omitted, BUFFER defaults to the current buffer.\n\ 1455 If omitted, BUFFER defaults to the current buffer.\n\
1435 BEG and END may be integers or markers.") 1456 BEG and END may be integers or markers.")
1436 (beg, end, buffer) 1457 (beg, end, buffer)
1463 } 1484 }
1464 else 1485 else
1465 end = Fset_marker (Fmake_marker (), end, buffer); 1486 end = Fset_marker (Fmake_marker (), end, buffer);
1466 1487
1467 overlay = Fcons (Fcons (beg, end), Qnil); 1488 overlay = Fcons (Fcons (beg, end), Qnil);
1489 XSETTYPE (overlay, Lisp_Overlay);
1468 1490
1469 /* Put the new overlay on the wrong list. */ 1491 /* Put the new overlay on the wrong list. */
1470 end = OVERLAY_END (overlay); 1492 end = OVERLAY_END (overlay);
1471 if (OVERLAY_POSITION (end) < XINT (b->overlay_center)) 1493 if (OVERLAY_POSITION (end) < XINT (b->overlay_center))
1472 b->overlays_after = Fcons (overlay, b->overlays_after); 1494 b->overlays_after = Fcons (overlay, b->overlays_after);
1488 (overlay, beg, end, buffer) 1510 (overlay, beg, end, buffer)
1489 Lisp_Object overlay, beg, end, buffer; 1511 Lisp_Object overlay, beg, end, buffer;
1490 { 1512 {
1491 struct buffer *b; 1513 struct buffer *b;
1492 1514
1493 if (!OVERLAY_VALID (overlay)) 1515 CHECK_OVERLAY (overlay, 0);
1494 error ("Invalid overlay object");
1495
1496 if (NILP (buffer)) 1516 if (NILP (buffer))
1497 buffer = Fmarker_buffer (OVERLAY_START (overlay)); 1517 buffer = Fmarker_buffer (OVERLAY_START (overlay));
1498 CHECK_BUFFER (buffer, 3); 1518 CHECK_BUFFER (buffer, 3);
1499
1500 CHECK_NUMBER_COERCE_MARKER (beg, 1); 1519 CHECK_NUMBER_COERCE_MARKER (beg, 1);
1501 CHECK_NUMBER_COERCE_MARKER (end, 1); 1520 CHECK_NUMBER_COERCE_MARKER (end, 1);
1502 1521
1503 if (XINT (beg) > XINT (end)) 1522 if (XINT (beg) > XINT (end))
1504 { 1523 {
1553 (overlay) 1572 (overlay)
1554 Lisp_Object overlay; 1573 Lisp_Object overlay;
1555 { 1574 {
1556 struct buffer *b; 1575 struct buffer *b;
1557 1576
1558 if (OVERLAY_VALID (overlay)) 1577 CHECK_OVERLAY (overlay, 0);
1559 b = XBUFFER (Fmarker_buffer (OVERLAY_START (overlay))); 1578
1560 else 1579 b = XBUFFER (Fmarker_buffer (OVERLAY_START (overlay)));
1561 /* Guess! */
1562 b = current_buffer;
1563 1580
1564 b->overlays_before = Fdelq (overlay, b->overlays_before); 1581 b->overlays_before = Fdelq (overlay, b->overlays_before);
1565 b->overlays_after = Fdelq (overlay, b->overlays_after); 1582 b->overlays_after = Fdelq (overlay, b->overlays_after);
1583
1584 Fset_marker (OVERLAY_START (overlay), 1, Qnil);
1585 Fset_marker (OVERLAY_END (overlay), 1, Qnil);
1566 1586
1567 redisplay_region (b, 1587 redisplay_region (b,
1568 OVERLAY_POSITION (OVERLAY_START (overlay)), 1588 OVERLAY_POSITION (OVERLAY_START (overlay)),
1569 OVERLAY_POSITION (OVERLAY_END (overlay))); 1589 OVERLAY_POSITION (OVERLAY_END (overlay)));
1570 1590
1675 "Get the property of overlay OVERLAY with property name NAME.") 1695 "Get the property of overlay OVERLAY with property name NAME.")
1676 (overlay, prop) 1696 (overlay, prop)
1677 Lisp_Object overlay, prop; 1697 Lisp_Object overlay, prop;
1678 { 1698 {
1679 Lisp_Object plist; 1699 Lisp_Object plist;
1680 for (plist = Fcdr_safe (Fcdr_safe (overlay)); 1700
1701 CHECK_OVERLAY (overlay, 0);
1702
1703 for (plist = Fcdr_safe (XCONS (overlay)->cdr);
1681 CONSP (plist) && CONSP (XCONS (plist)->cdr); 1704 CONSP (plist) && CONSP (XCONS (plist)->cdr);
1682 plist = XCONS (XCONS (plist)->cdr)->cdr) 1705 plist = XCONS (XCONS (plist)->cdr)->cdr)
1683 { 1706 {
1684 if (EQ (XCONS (plist)->car, prop)) 1707 if (EQ (XCONS (plist)->car, prop))
1685 return XCONS (XCONS (plist)->cdr)->car; 1708 return XCONS (XCONS (plist)->cdr)->car;
1686 } 1709 }
1710
1711 return Qnil;
1687 } 1712 }
1688 1713
1689 DEFUN ("overlay-put", Foverlay_put, Soverlay_put, 3, 3, 0, 1714 DEFUN ("overlay-put", Foverlay_put, Soverlay_put, 3, 3, 0,
1690 "Set one property of overlay OVERLAY: give property PROP value VALUE.") 1715 "Set one property of overlay OVERLAY: give property PROP value VALUE.")
1691 (overlay, prop, value) 1716 (overlay, prop, value)
1692 Lisp_Object overlay, prop, value; 1717 Lisp_Object overlay, prop, value;
1693 { 1718 {
1694 Lisp_Object plist, tail; 1719 Lisp_Object plist, tail;
1695 1720
1696 if (!OVERLAY_VALID (overlay)) 1721 CHECK_OVERLAY (overlay, 0);
1697 error ("Invalid overlay object");
1698 1722
1699 redisplay_region (XMARKER (OVERLAY_START (overlay))->buffer, 1723 redisplay_region (XMARKER (OVERLAY_START (overlay))->buffer,
1700 OVERLAY_POSITION (OVERLAY_START (overlay)), 1724 OVERLAY_POSITION (OVERLAY_START (overlay)),
1701 OVERLAY_POSITION (OVERLAY_END (overlay))); 1725 OVERLAY_POSITION (OVERLAY_END (overlay)));
1702 1726
1703 plist = Fcdr_safe (Fcdr_safe (overlay)); 1727 plist = Fcdr_safe (XCONS (overlay)->cdr);
1704 1728
1705 for (tail = plist; 1729 for (tail = plist;
1706 CONSP (tail) && CONSP (XCONS (tail)->cdr); 1730 CONSP (tail) && CONSP (XCONS (tail)->cdr);
1707 tail = XCONS (XCONS (tail)->cdr)->cdr) 1731 tail = XCONS (XCONS (tail)->cdr)->cdr)
1708 { 1732 {
1890 staticpro (&QSFundamental); 1914 staticpro (&QSFundamental);
1891 staticpro (&Vbuffer_alist); 1915 staticpro (&Vbuffer_alist);
1892 staticpro (&Qprotected_field); 1916 staticpro (&Qprotected_field);
1893 staticpro (&Qpermanent_local); 1917 staticpro (&Qpermanent_local);
1894 staticpro (&Qkill_buffer_hook); 1918 staticpro (&Qkill_buffer_hook);
1919 staticpro (&Qoverlayp);
1920
1921 Qoverlayp = intern ("overlayp");
1895 1922
1896 Fput (Qprotected_field, Qerror_conditions, 1923 Fput (Qprotected_field, Qerror_conditions,
1897 Fcons (Qprotected_field, Fcons (Qerror, Qnil))); 1924 Fcons (Qprotected_field, Fcons (Qerror, Qnil)));
1898 Fput (Qprotected_field, Qerror_message, 1925 Fput (Qprotected_field, Qerror_message,
1899 build_string ("Attempt to modify a protected field")); 1926 build_string ("Attempt to modify a protected field"));
2213 defsubr (&Sbarf_if_buffer_read_only); 2240 defsubr (&Sbarf_if_buffer_read_only);
2214 defsubr (&Sbury_buffer); 2241 defsubr (&Sbury_buffer);
2215 defsubr (&Slist_buffers); 2242 defsubr (&Slist_buffers);
2216 defsubr (&Skill_all_local_variables); 2243 defsubr (&Skill_all_local_variables);
2217 2244
2245 defsubr (&Soverlayp);
2218 defsubr (&Smake_overlay); 2246 defsubr (&Smake_overlay);
2219 defsubr (&Sdelete_overlay); 2247 defsubr (&Sdelete_overlay);
2220 defsubr (&Smove_overlay); 2248 defsubr (&Smove_overlay);
2221 defsubr (&Soverlays_at); 2249 defsubr (&Soverlays_at);
2222 defsubr (&Snext_overlay_change); 2250 defsubr (&Snext_overlay_change);