diff options
| author | Richard M. Stallman | 1994-09-21 08:14:33 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1994-09-21 08:14:33 +0000 |
| commit | 239c932bb27fd1c2d817b61d5227c92662bce346 (patch) | |
| tree | 08898bbbd4e52fdf8add5e91da19f9d704000328 /src/buffer.c | |
| parent | d4af3687405fc0326418d1c257226e1383247e1c (diff) | |
| download | emacs-239c932bb27fd1c2d817b61d5227c92662bce346.tar.gz emacs-239c932bb27fd1c2d817b61d5227c92662bce346.zip | |
(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.
Diffstat (limited to 'src/buffer.c')
| -rw-r--r-- | src/buffer.c | 79 |
1 files changed, 68 insertions, 11 deletions
diff --git a/src/buffer.c b/src/buffer.c index bd4c8c91f3e..0ddd5198a68 100644 --- a/src/buffer.c +++ b/src/buffer.c | |||
| @@ -1295,6 +1295,9 @@ the normal hook `change-major-mode-hook'.") | |||
| 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. |
| @@ -1305,25 +1308,27 @@ the normal hook `change-major-mode-hook'.") | |||
| 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) |
| @@ -1331,8 +1336,15 @@ overlays_at (pos, extend, vec_ptr, len_ptr, next_ptr) | |||
| 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 | { |
| @@ -1363,7 +1375,7 @@ overlays_at (pos, extend, vec_ptr, len_ptr, next_ptr) | |||
| 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) |
| @@ -1378,7 +1390,8 @@ overlays_at (pos, extend, vec_ptr, len_ptr, next_ptr) | |||
| 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 | { |
| @@ -1396,9 +1409,14 @@ overlays_at (pos, extend, vec_ptr, len_ptr, next_ptr) | |||
| 1396 | vec[idx] = overlay; | 1409 | vec[idx] = overlay; |
| 1397 | idx++; | 1410 | idx++; |
| 1398 | } | 1411 | } |
| 1412 | else if (endpos < pos && endpos > prev) | ||
| 1413 | prev = endpos; | ||
| 1399 | } | 1414 | } |
| 1400 | 1415 | ||
| 1401 | *next_ptr = next; | 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 | ||
| @@ -2005,7 +2023,6 @@ DEFUN ("overlays-at", Foverlays_at, Soverlays_at, 1, 1, 0, | |||
| 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; |
| @@ -2017,7 +2034,7 @@ DEFUN ("overlays-at", Foverlays_at, Soverlays_at, 1, 1, 0, | |||
| 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); |
| @@ -2037,7 +2054,6 @@ If there are no more overlay boundaries after POS, return (point-max).") | |||
| 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); |
| @@ -2048,7 +2064,7 @@ If there are no more overlay boundaries after POS, return (point-max).") | |||
| 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. */ |
| @@ -2066,6 +2082,46 @@ If there are no more overlay boundaries after POS, return (point-max).") | |||
| 2066 | xfree (overlay_vec); | 2082 | xfree (overlay_vec); |
| 2067 | return make_number (endpos); | 2083 | return make_number (endpos); |
| 2068 | } | 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); | ||
| 2124 | } | ||
| 2069 | 2125 | ||
| 2070 | /* These functions are for debugging overlays. */ | 2126 | /* These functions are for debugging overlays. */ |
| 2071 | 2127 | ||
| @@ -2960,6 +3016,7 @@ is a member of the list."); | |||
| 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); |