aboutsummaryrefslogtreecommitdiffstats
path: root/src/buffer.c
diff options
context:
space:
mode:
authorKarl Heuer1994-02-09 03:23:48 +0000
committerKarl Heuer1994-02-09 03:23:48 +0000
commit5985d248dbe5ca68243057a39b4f3d7197c6f138 (patch)
tree999888495c0d9dcc10cbdf223f2f1be6ac75a16b /src/buffer.c
parent9e3891de7c3886dce11f9d13b7aad2b6ee1eb48b (diff)
downloademacs-5985d248dbe5ca68243057a39b4f3d7197c6f138.tar.gz
emacs-5985d248dbe5ca68243057a39b4f3d7197c6f138.zip
(sort-overlays): New function, extracted from xfaces.c.
Diffstat (limited to 'src/buffer.c')
-rw-r--r--src/buffer.c85
1 files changed, 85 insertions, 0 deletions
diff --git a/src/buffer.c b/src/buffer.c
index 72a05c16fe9..9f0d81e7068 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -133,6 +133,8 @@ Lisp_Object Qget_file_buffer;
133 133
134Lisp_Object Qoverlayp; 134Lisp_Object Qoverlayp;
135 135
136Lisp_Object Qpriority, Qwindow;
137
136Lisp_Object Qmodification_hooks; 138Lisp_Object Qmodification_hooks;
137Lisp_Object Qinsert_in_front_hooks; 139Lisp_Object Qinsert_in_front_hooks;
138Lisp_Object Qinsert_behind_hooks; 140Lisp_Object Qinsert_behind_hooks;
@@ -1365,6 +1367,85 @@ overlays_at (pos, extend, vec_ptr, len_ptr, next_ptr)
1365 return idx; 1367 return idx;
1366} 1368}
1367 1369
1370struct sortvec
1371{
1372 Lisp_Object overlay;
1373 int beg, end;
1374 int priority;
1375};
1376
1377static int
1378compare_overlays (s1, s2)
1379 struct sortvec *s1, *s2;
1380{
1381 if (s1->priority != s2->priority)
1382 return s1->priority - s2->priority;
1383 if (s1->beg != s2->beg)
1384 return s1->beg - s2->beg;
1385 if (s1->end != s2->end)
1386 return s2->end - s1->end;
1387 return 0;
1388}
1389
1390/* Sort an array of overlays by priority. The array is modified in place.
1391 The return value is the new size; this may be smaller than the original
1392 size if some of the overlays were invalid or were window-specific. */
1393int
1394sort_overlays (overlay_vec, noverlays, w)
1395 Lisp_Object *overlay_vec;
1396 int noverlays;
1397 struct window *w;
1398{
1399 int i, j;
1400 struct sortvec *sortvec;
1401 sortvec = (struct sortvec *) alloca (noverlays * sizeof (struct sortvec));
1402
1403 /* Put the valid and relevant overlays into sortvec. */
1404
1405 for (i = 0, j = 0; i < noverlays; i++)
1406 {
1407 Lisp_Object overlay = overlay_vec[i];
1408
1409 if (OVERLAY_VALID (overlay)
1410 && OVERLAY_POSITION (OVERLAY_START (overlay)) > 0
1411 && OVERLAY_POSITION (OVERLAY_END (overlay)) > 0)
1412 {
1413 Lisp_Object window;
1414 window = Foverlay_get (overlay, Qwindow);
1415
1416 /* Also ignore overlays limited to one window
1417 if it's not the window we are using. */
1418 if (XTYPE (window) != Lisp_Window
1419 || XWINDOW (window) == w)
1420 {
1421 Lisp_Object tem;
1422
1423 /* This overlay is good and counts:
1424 put it in sortvec. */
1425 sortvec[j].overlay = overlay;
1426 sortvec[j].beg = OVERLAY_POSITION (OVERLAY_START (overlay));
1427 sortvec[j].end = OVERLAY_POSITION (OVERLAY_END (overlay));
1428 tem = Foverlay_get (overlay, Qpriority);
1429 if (INTEGERP (tem))
1430 sortvec[j].priority = XINT (tem);
1431 else
1432 sortvec[j].priority = 0;
1433 j++;
1434 }
1435 }
1436 }
1437 noverlays = j;
1438
1439 /* Sort the overlays into the proper order: increasing priority. */
1440
1441 if (noverlays > 1)
1442 qsort (sortvec, noverlays, sizeof (struct sortvec), compare_overlays);
1443
1444 for (i = 0; i < noverlays; i++)
1445 overlay_vec[i] = sortvec[i].overlay;
1446 return (noverlays);
1447}
1448
1368/* Shift overlays in BUF's overlay lists, to center the lists at POS. */ 1449/* Shift overlays in BUF's overlay lists, to center the lists at POS. */
1369 1450
1370void 1451void
@@ -2197,6 +2278,10 @@ syms_of_buffer ()
2197 Qinsert_behind_hooks = intern ("insert-behind-hooks"); 2278 Qinsert_behind_hooks = intern ("insert-behind-hooks");
2198 staticpro (&Qget_file_buffer); 2279 staticpro (&Qget_file_buffer);
2199 Qget_file_buffer = intern ("get-file-buffer"); 2280 Qget_file_buffer = intern ("get-file-buffer");
2281 Qpriority = intern ("priority");
2282 staticpro (&Qpriority);
2283 Qwindow = intern ("window");
2284 staticpro (&Qwindow);
2200 2285
2201 Qoverlayp = intern ("overlayp"); 2286 Qoverlayp = intern ("overlayp");
2202 2287