comparison src/buffer.c @ 8967:80b92977ed08

(overlays_at): New arg PREV_PTR. Return previous overlay end. (Foverlays_at): Pass NULL for last 2 args of overlays_at. (Fnext_overlay_change): Pass new arg to overlays_at. (Fprevious_overlay_change): New function.
author Richard M. Stallman <rms@gnu.org>
date Wed, 21 Sep 1994 08:14:33 +0000
parents c64235231b19
children 186aff8c1f51
comparison
equal deleted inserted replaced
8966:cafc16f356c2 8967:80b92977ed08
1293 /* Find all the overlays in the current buffer that contain position POS. 1293 /* Find all the overlays in the current buffer that contain position POS.
1294 Return the number found, and store them in a vector in *VEC_PTR. 1294 Return the number found, and store them in a vector in *VEC_PTR.
1295 Store in *LEN_PTR the size allocated for the vector. 1295 Store in *LEN_PTR the size allocated for the vector.
1296 Store in *NEXT_PTR the next position after POS where an overlay starts, 1296 Store in *NEXT_PTR the next position after POS where an overlay starts,
1297 or ZV if there are no more overlays. 1297 or ZV if there are no more overlays.
1298 Store in *PREV_PTR the previous position after POS where an overlay ends,
1299 or BEGV if there are no previous overlays.
1300 NEXT_PTR and/or PREV_PTR may be 0, meaning don't store that info.
1298 1301
1299 *VEC_PTR and *LEN_PTR should contain a valid vector and size 1302 *VEC_PTR and *LEN_PTR should contain a valid vector and size
1300 when this function is called. 1303 when this function is called.
1301 1304
1302 If EXTEND is non-zero, we make the vector bigger if necessary. 1305 If EXTEND is non-zero, we make the vector bigger if necessary.
1303 If EXTEND is zero, we never extend the vector, 1306 If EXTEND is zero, we never extend the vector,
1304 and we store only as many overlays as will fit. 1307 and we store only as many overlays as will fit.
1305 But we still return the total number of overlays. */ 1308 But we still return the total number of overlays. */
1306 1309
1307 int 1310 int
1308 overlays_at (pos, extend, vec_ptr, len_ptr, next_ptr) 1311 overlays_at (pos, extend, vec_ptr, len_ptr, next_ptr, prev_ptr)
1309 int pos; 1312 int pos;
1310 int extend; 1313 int extend;
1311 Lisp_Object **vec_ptr; 1314 Lisp_Object **vec_ptr;
1312 int *len_ptr; 1315 int *len_ptr;
1313 int *next_ptr; 1316 int *next_ptr;
1317 int *prev_ptr;
1314 { 1318 {
1315 Lisp_Object tail, overlay, start, end, result; 1319 Lisp_Object tail, overlay, start, end, result;
1316 int idx = 0; 1320 int idx = 0;
1317 int len = *len_ptr; 1321 int len = *len_ptr;
1318 Lisp_Object *vec = *vec_ptr; 1322 Lisp_Object *vec = *vec_ptr;
1319 int next = ZV; 1323 int next = ZV;
1324 int prev = BEGV;
1320 int inhibit_storing = 0; 1325 int inhibit_storing = 0;
1321 1326
1322 for (tail = current_buffer->overlays_before; 1327 for (tail = current_buffer->overlays_before;
1323 XGCTYPE (tail) == Lisp_Cons; 1328 XGCTYPE (tail) == Lisp_Cons;
1324 tail = XCONS (tail)->cdr) 1329 tail = XCONS (tail)->cdr)
1325 { 1330 {
1326 int startpos; 1331 int startpos, endpos;
1327 1332
1328 overlay = XCONS (tail)->car; 1333 overlay = XCONS (tail)->car;
1329 if (XGCTYPE (overlay) != Lisp_Overlay) 1334 if (XGCTYPE (overlay) != Lisp_Overlay)
1330 abort (); 1335 abort ();
1331 1336
1332 start = OVERLAY_START (overlay); 1337 start = OVERLAY_START (overlay);
1333 end = OVERLAY_END (overlay); 1338 end = OVERLAY_END (overlay);
1334 if (OVERLAY_POSITION (end) <= pos) 1339 endpos = OVERLAY_POSITION (end);
1335 break; 1340 if (endpos < pos)
1341 {
1342 if (prev < endpos)
1343 prev = endpos;
1344 break;
1345 }
1346 if (endpos == pos)
1347 continue;
1336 startpos = OVERLAY_POSITION (start); 1348 startpos = OVERLAY_POSITION (start);
1337 if (startpos <= pos) 1349 if (startpos <= pos)
1338 { 1350 {
1339 if (idx == len) 1351 if (idx == len)
1340 { 1352 {
1361 1373
1362 for (tail = current_buffer->overlays_after; 1374 for (tail = current_buffer->overlays_after;
1363 XGCTYPE (tail) == Lisp_Cons; 1375 XGCTYPE (tail) == Lisp_Cons;
1364 tail = XCONS (tail)->cdr) 1376 tail = XCONS (tail)->cdr)
1365 { 1377 {
1366 int startpos; 1378 int startpos, endpos;
1367 1379
1368 overlay = XCONS (tail)->car; 1380 overlay = XCONS (tail)->car;
1369 if (XGCTYPE (overlay) != Lisp_Overlay) 1381 if (XGCTYPE (overlay) != Lisp_Overlay)
1370 abort (); 1382 abort ();
1371 1383
1376 { 1388 {
1377 if (startpos < next) 1389 if (startpos < next)
1378 next = startpos; 1390 next = startpos;
1379 break; 1391 break;
1380 } 1392 }
1381 if (pos < OVERLAY_POSITION (end)) 1393 endpos = OVERLAY_POSITION (end);
1394 if (pos < endpos)
1382 { 1395 {
1383 if (idx == len) 1396 if (idx == len)
1384 { 1397 {
1385 if (extend) 1398 if (extend)
1386 { 1399 {
1394 1407
1395 if (!inhibit_storing) 1408 if (!inhibit_storing)
1396 vec[idx] = overlay; 1409 vec[idx] = overlay;
1397 idx++; 1410 idx++;
1398 } 1411 }
1399 } 1412 else if (endpos < pos && endpos > prev)
1400 1413 prev = endpos;
1401 *next_ptr = next; 1414 }
1415
1416 if (next_ptr)
1417 *next_ptr = next;
1418 if (prev_ptr)
1419 *prev_ptr = prev;
1402 return idx; 1420 return idx;
1403 } 1421 }
1404 1422
1405 struct sortvec 1423 struct sortvec
1406 { 1424 {
2003 "Return a list of the overlays that contain position POS.") 2021 "Return a list of the overlays that contain position POS.")
2004 (pos) 2022 (pos)
2005 Lisp_Object pos; 2023 Lisp_Object pos;
2006 { 2024 {
2007 int noverlays; 2025 int noverlays;
2008 int endpos;
2009 Lisp_Object *overlay_vec; 2026 Lisp_Object *overlay_vec;
2010 int len; 2027 int len;
2011 Lisp_Object result; 2028 Lisp_Object result;
2012 2029
2013 CHECK_NUMBER_COERCE_MARKER (pos, 0); 2030 CHECK_NUMBER_COERCE_MARKER (pos, 0);
2015 len = 10; 2032 len = 10;
2016 overlay_vec = (Lisp_Object *) xmalloc (len * sizeof (Lisp_Object)); 2033 overlay_vec = (Lisp_Object *) xmalloc (len * sizeof (Lisp_Object));
2017 2034
2018 /* Put all the overlays we want in a vector in overlay_vec. 2035 /* Put all the overlays we want in a vector in overlay_vec.
2019 Store the length in len. */ 2036 Store the length in len. */
2020 noverlays = overlays_at (XINT (pos), 1, &overlay_vec, &len, &endpos); 2037 noverlays = overlays_at (XINT (pos), 1, &overlay_vec, &len, NULL, NULL);
2021 2038
2022 /* Make a list of them all. */ 2039 /* Make a list of them all. */
2023 result = Flist (noverlays, overlay_vec); 2040 result = Flist (noverlays, overlay_vec);
2024 2041
2025 xfree (overlay_vec); 2042 xfree (overlay_vec);
2035 { 2052 {
2036 int noverlays; 2053 int noverlays;
2037 int endpos; 2054 int endpos;
2038 Lisp_Object *overlay_vec; 2055 Lisp_Object *overlay_vec;
2039 int len; 2056 int len;
2040 Lisp_Object result;
2041 int i; 2057 int i;
2042 2058
2043 CHECK_NUMBER_COERCE_MARKER (pos, 0); 2059 CHECK_NUMBER_COERCE_MARKER (pos, 0);
2044 2060
2045 len = 10; 2061 len = 10;
2046 overlay_vec = (Lisp_Object *) xmalloc (len * sizeof (Lisp_Object)); 2062 overlay_vec = (Lisp_Object *) xmalloc (len * sizeof (Lisp_Object));
2047 2063
2048 /* Put all the overlays we want in a vector in overlay_vec. 2064 /* Put all the overlays we want in a vector in overlay_vec.
2049 Store the length in len. 2065 Store the length in len.
2050 endpos gets the position where the next overlay starts. */ 2066 endpos gets the position where the next overlay starts. */
2051 noverlays = overlays_at (XINT (pos), 1, &overlay_vec, &len, &endpos); 2067 noverlays = overlays_at (XINT (pos), 1, &overlay_vec, &len, &endpos, NULL);
2052 2068
2053 /* If any of these overlays ends before endpos, 2069 /* If any of these overlays ends before endpos,
2054 use its ending point instead. */ 2070 use its ending point instead. */
2055 for (i = 0; i < noverlays; i++) 2071 for (i = 0; i < noverlays; i++)
2056 { 2072 {
2063 endpos = oendpos; 2079 endpos = oendpos;
2064 } 2080 }
2065 2081
2066 xfree (overlay_vec); 2082 xfree (overlay_vec);
2067 return make_number (endpos); 2083 return make_number (endpos);
2084 }
2085
2086 DEFUN ("previous-overlay-change", Fprevious_overlay_change,
2087 Sprevious_overlay_change, 1, 1, 0,
2088 "Return the previous position before POS where an overlay starts or ends.\n\
2089 If there are no more overlay boundaries after POS, return (point-min).")
2090 (pos)
2091 Lisp_Object pos;
2092 {
2093 int noverlays;
2094 int prevpos;
2095 Lisp_Object *overlay_vec;
2096 int len;
2097 int i;
2098
2099 CHECK_NUMBER_COERCE_MARKER (pos, 0);
2100
2101 len = 10;
2102 overlay_vec = (Lisp_Object *) xmalloc (len * sizeof (Lisp_Object));
2103
2104 /* Put all the overlays we want in a vector in overlay_vec.
2105 Store the length in len.
2106 prevpos gets the position of an overlay end. */
2107 noverlays = overlays_at (XINT (pos), 1, &overlay_vec, &len, NULL, &prevpos);
2108
2109 /* If any of these overlays starts before endpos,
2110 maybe use its starting point instead. */
2111 for (i = 0; i < noverlays; i++)
2112 {
2113 Lisp_Object ostart;
2114 int ostartpos;
2115
2116 ostart = OVERLAY_START (overlay_vec[i]);
2117 ostartpos = OVERLAY_POSITION (ostart);
2118 if (ostartpos > prevpos && ostartpos < XINT (pos))
2119 prevpos = ostartpos;
2120 }
2121
2122 xfree (overlay_vec);
2123 return make_number (prevpos);
2068 } 2124 }
2069 2125
2070 /* These functions are for debugging overlays. */ 2126 /* These functions are for debugging overlays. */
2071 2127
2072 DEFUN ("overlay-lists", Foverlay_lists, Soverlay_lists, 0, 0, 0, 2128 DEFUN ("overlay-lists", Foverlay_lists, Soverlay_lists, 0, 0, 0,
2958 defsubr (&Soverlay_end); 3014 defsubr (&Soverlay_end);
2959 defsubr (&Soverlay_buffer); 3015 defsubr (&Soverlay_buffer);
2960 defsubr (&Soverlay_properties); 3016 defsubr (&Soverlay_properties);
2961 defsubr (&Soverlays_at); 3017 defsubr (&Soverlays_at);
2962 defsubr (&Snext_overlay_change); 3018 defsubr (&Snext_overlay_change);
3019 defsubr (&Sprevious_overlay_change);
2963 defsubr (&Soverlay_recenter); 3020 defsubr (&Soverlay_recenter);
2964 defsubr (&Soverlay_lists); 3021 defsubr (&Soverlay_lists);
2965 defsubr (&Soverlay_get); 3022 defsubr (&Soverlay_get);
2966 defsubr (&Soverlay_put); 3023 defsubr (&Soverlay_put);
2967 } 3024 }