1
0
mirror of https://git.savannah.gnu.org/git/emacs.git synced 2025-01-22 18:35:09 +00:00

* 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'.
This commit is contained in:
Stefan Monnier 2014-04-15 09:21:18 -04:00
parent f596f897c6
commit 20fa59a004
8 changed files with 41 additions and 76 deletions

View File

@ -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:

View File

@ -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.

View File

@ -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

View File

@ -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:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

View File

@ -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)))))

View File

@ -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))

View File

@ -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

View File

@ -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);