summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Monnier <monnier@iro.umontreal.ca>2014-04-15 09:21:18 -0400
committerStefan Monnier <monnier@iro.umontreal.ca>2014-04-15 09:21:18 -0400
commita019de041b837fe23372078870a6eca8a08fbdf9 (patch)
treebaacda7dd4e21f0bf9f6c8d3c7d733bd63ee59d5
parentef5b917d6448f4a2983746d3b43541defa3cb9d2 (diff)
downloademacs-a019de041b837fe23372078870a6eca8a08fbdf9.tar.gz
* src/buffer.c (Foverlays_at): Add argument `sorted'.
* doc/lispref/display.texi (Overlay Properties): Reword the doc of `priority'. (Finding Overlays): Document new arg of `overlays-at'. * lisp/obsolete/lucid.el (extent-at): * lisp/htmlfontify.el (hfy-overlay-props-at): Use the new `sorted' arg of overlays-at. (hfy-fontify-buffer): Remove unused var `orig-ovls'. * lisp/ps-def.el (ps-generate-postscript-with-faces1): Use the new `sorted' arg of overlays-at. Use `invisible-p'.
-rw-r--r--doc/lispref/display.texi23
-rw-r--r--etc/NEWS2
-rw-r--r--lisp/ChangeLog10
-rw-r--r--lisp/htmlfontify.el11
-rw-r--r--lisp/obsolete/lucid.el10
-rw-r--r--lisp/ps-def.el46
-rw-r--r--src/ChangeLog4
-rw-r--r--src/buffer.c11
8 files changed, 41 insertions, 76 deletions
diff --git a/doc/lispref/display.texi b/doc/lispref/display.texi
index 0246d1a44de..acbef6b9495 100644
--- a/doc/lispref/display.texi
+++ b/doc/lispref/display.texi
@@ -1475,8 +1475,10 @@ the buffer's undo list.
Since more than one overlay can specify a property value for the
same character, Emacs lets you specify a priority value of each
-overlay. You should not make assumptions about which overlay will
-prevail when there is a conflict and they have the same priority.
+overlay. In case two overlays have the same priority value, and one
+is nested in the other, then the inner one will have priority over the
+outer one. If neither is nested in the other then you should not make
+assumptions about which overlay will prevail.
These functions read and set the properties of an overlay:
@@ -1507,9 +1509,9 @@ of them:
@table @code
@item priority
@kindex priority @r{(overlay property)}
-This property's value (which should be a non-negative integer)
-determines the priority of the overlay. No priority, or @code{nil},
-means zero.
+This property's value determines the priority of the overlay. No priority, or
+@code{nil}, means zero. A non-nil and non-integer value has
+undefined behavior.
The priority matters when two or more overlays cover the same
character and both specify the same property; the one whose
@@ -1706,11 +1708,12 @@ Properties}.
@node Finding Overlays
@subsection Searching for Overlays
-@defun overlays-at pos
-This function returns a list of all the overlays that cover the
-character at position @var{pos} in the current buffer. The list is in
-no particular order. An overlay contains position @var{pos} if it
-begins at or before @var{pos}, and ends after @var{pos}.
+@defun overlays-at pos &optional sorted
+This function returns a list of all the overlays that cover the character at
+position @var{pos} in the current buffer. If @var{sorted} is non-nil, the list
+is in decreasing order of priority, otherwise it is in no particular order.
+An overlay contains position @var{pos} if it begins at or before @var{pos}, and
+ends after @var{pos}.
To illustrate usage, here is a Lisp function that returns a list of the
overlays that specify property @var{prop} for the character at point:
diff --git a/etc/NEWS b/etc/NEWS
index db1dd43216b..6c6a8184ac6 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1219,6 +1219,8 @@ treated as regexps rather than literal strings.
* Lisp Changes in Emacs 24.4
+** overlays-at can optionally sort its result by priority.
+
+++
** The second argument of `eval' can now specify a lexical environment.
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index a77ccddb50b..74347bb5644 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,13 @@
+2014-04-15 Stefan Monnier <monnier@iro.umontreal.ca>
+
+ * ps-def.el (ps-generate-postscript-with-faces1): Use the new `sorted'
+ arg of overlays-at. Use `invisible-p'.
+
+ * obsolete/lucid.el (extent-at):
+ * htmlfontify.el (hfy-overlay-props-at): Use the new `sorted' arg of
+ overlays-at.
+ (hfy-fontify-buffer): Remove unused var `orig-ovls'.
+
2014-04-14 João Távora <joaotavora@gmail.com>
* net/shr.el (shr-expand-url): Use `expand-file-name' for relative
diff --git a/lisp/htmlfontify.el b/lisp/htmlfontify.el
index 1282654899f..56887f39bef 100644
--- a/lisp/htmlfontify.el
+++ b/lisp/htmlfontify.el
@@ -1328,9 +1328,7 @@ return a `defface' style list of face properties instead of a face symbol."
(defun hfy-overlay-props-at (p)
"Grab overlay properties at point P.
The plists are returned in descending priority order."
- (sort (mapcar #'overlay-properties (overlays-at p))
- (lambda (A B) (> (or (cadr (memq 'priority A)) 0) ;FIXME: plist-get?
- (or (cadr (memq 'priority B)) 0)))))
+ (mapcar #'overlay-properties (overlays-at p 'sorted)))
;; construct an assoc of (face-name . (css-name . "{ css-style }")) elements:
(defun hfy-compile-stylesheet ()
@@ -1642,7 +1640,6 @@ FILE, if set, is the file name."
(css-map nil)
(invis-ranges nil)
(rovl nil)
- (orig-ovls (overlays-in (point-min) (point-max)))
(rmin (when mark-active (region-beginning)))
(rmax (when mark-active (region-end ))) )
(when (and mark-active
@@ -1664,12 +1661,6 @@ FILE, if set, is the file name."
(set-buffer html-buffer)
;; rip out props that could interfere with our htmlization of the buffer:
(remove-text-properties (point-min) (point-max) hfy-ignored-properties)
- ;; Apply overlay invisible spec
- (setq orig-ovls
- (sort orig-ovls
- (lambda (A B)
- (> (or (cadr (memq 'priority (overlay-properties A))) 0)
- (or (cadr (memq 'priority (overlay-properties B))) 0)))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; at this point, html-buffer retains the fontification of the parent:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
diff --git a/lisp/obsolete/lucid.el b/lisp/obsolete/lucid.el
index d3cb3f135d8..15f80652809 100644
--- a/lisp/obsolete/lucid.el
+++ b/lisp/obsolete/lucid.el
@@ -125,7 +125,7 @@ This is an XEmacs compatibility function."
(defun extent-at (pos &optional object property before)
(with-current-buffer (or object (current-buffer))
- (let ((overlays (overlays-at pos)))
+ (let ((overlays (overlays-at pos 'sorted)))
(when property
(let (filtered)
(while overlays
@@ -133,14 +133,6 @@ This is an XEmacs compatibility function."
(setq filtered (cons (car overlays) filtered)))
(setq overlays (cdr overlays)))
(setq overlays filtered)))
- (setq overlays
- (sort overlays
- (function (lambda (o1 o2)
- (let ((p1 (or (overlay-get o1 'priority) 0))
- (p2 (or (overlay-get o2 'priority) 0)))
- (or (> p1 p2)
- (and (= p1 p2)
- (> (overlay-start o1) (overlay-start o2)))))))))
(if before
(nth 1 (memq before overlays))
(car overlays)))))
diff --git a/lisp/ps-def.el b/lisp/ps-def.el
index 06cef75cbbd..92a2e0b38cd 100644
--- a/lisp/ps-def.el
+++ b/lisp/ps-def.el
@@ -339,53 +339,11 @@
(setq position (min property-change overlay-change)
before-string nil
after-string nil)
- ;; The code below is not quite correct,
- ;; because a non-nil overlay invisible property
- ;; which is inactive according to the current value
- ;; of buffer-invisibility-spec nonetheless overrides
- ;; a face text property.
(setq face
- (cond ((let ((prop (get-text-property from 'invisible)))
- ;; Decide whether this invisible property
- ;; really makes the text invisible.
- (if (eq save-buffer-invisibility-spec t)
- (not (null prop))
- (or (memq prop save-buffer-invisibility-spec)
- (assq prop save-buffer-invisibility-spec))))
+ (cond ((invisible-p from)
'emacs--invisible--face)
- ((get-text-property from 'face))
+ ((get-char-property from 'face))
(t 'default)))
- (let ((overlays (overlays-at from))
- (face-priority -1)) ; text-property
- (while (and overlays
- (not (eq face 'emacs--invisible--face)))
- (let* ((overlay (car overlays))
- (overlay-invisible
- (overlay-get overlay 'invisible))
- (overlay-priority
- (or (overlay-get overlay 'priority) 0)))
- (and (> overlay-priority face-priority)
- (setq before-string
- (or (overlay-get overlay 'before-string)
- before-string)
- after-string
- (or (and (<= (overlay-end overlay) position)
- (overlay-get overlay 'after-string))
- after-string)
- face-priority overlay-priority
- face
- (cond
- ((if (eq save-buffer-invisibility-spec t)
- (not (null overlay-invisible))
- (or (memq overlay-invisible
- save-buffer-invisibility-spec)
- (assq overlay-invisible
- save-buffer-invisibility-spec)))
- 'emacs--invisible--face)
- ((overlay-get overlay 'face))
- (t face)
- ))))
- (setq overlays (cdr overlays))))
;; Plot up to this record.
(and before-string
(ps-plot-string before-string))
diff --git a/src/ChangeLog b/src/ChangeLog
index d0f46e5089f..1660b0f9148 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,7 @@
+2014-04-15 Stefan Monnier <monnier@iro.umontreal.ca>
+
+ * buffer.c (Foverlays_at): Add argument `sorted'.
+
2014-04-14 Eli Zaretskii <eliz@gnu.org>
* insdel.c (invalidate_buffer_caches): When deleting or replacing
diff --git a/src/buffer.c b/src/buffer.c
index a1678951984..3e1359707cd 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -4168,9 +4168,10 @@ OVERLAY. */)
}
-DEFUN ("overlays-at", Foverlays_at, Soverlays_at, 1, 1, 0,
- doc: /* Return a list of the overlays that contain the character at POS. */)
- (Lisp_Object pos)
+DEFUN ("overlays-at", Foverlays_at, Soverlays_at, 1, 2, 0,
+ doc: /* Return a list of the overlays that contain the character at POS.
+If SORTED is non-nil, then sort them by decreasing priority. */)
+ (Lisp_Object pos, Lisp_Object sorted)
{
ptrdiff_t len, noverlays;
Lisp_Object *overlay_vec;
@@ -4190,6 +4191,10 @@ DEFUN ("overlays-at", Foverlays_at, Soverlays_at, 1, 1, 0,
noverlays = overlays_at (XINT (pos), 1, &overlay_vec, &len,
NULL, NULL, 0);
+ if (!NILP (sorted))
+ noverlays = sort_overlays (overlay_vec, noverlays,
+ WINDOWP (sorted) ? XWINDOW (sorted) : NULL);
+
/* Make a list of them all. */
result = Flist (noverlays, overlay_vec);