[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Is there something like `on-display-functions'?
From: |
David Kastrup |
Subject: |
Re: Is there something like `on-display-functions'? |
Date: |
Wed, 27 Jan 2010 15:27:16 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/23.1.90 (gnu/linux) |
Alan Mackenzie <address@hidden> writes:
> Hi, Emacs,
>
> Is there some hook called each time something's about to be displayed on
> the screen (regardless of whether or not font-lock is enabled)?
>
> If there is, I could use it to apply the appropriate text properties to
> C++ template delimiters as they're about to be displayed, thus
> potentially speeding up startup for C++ (and like languages).
>
> Yes, I've tried searching for it and not found it.
(info "(elisp) Other display specs")
You can make any display specification conditional. To do that,
package it in another list of the form `(when CONDITION . SPEC)'. Then
the specification SPEC applies only when CONDITION evaluates to a
non-`nil' value. During the evaluation, `object' is bound to the
string or buffer having the conditional `display' property. `position'
and `buffer-position' are bound to the position within `object' and the
buffer position where the `display' property was found, respectively.
Both positions can be different when `object' is a string.
Since CONDITION gets evaluated, you can use it for pretty much anything
you like, even if you decide to let it result in nil always.
That's pretty much butt-ugly but works. preview-latex uses this to
prioritize its image rendering in order to have on-screen images
rendered first.
One of the rare cases where XEmacs has a nicer API for some job. This
use of the Emacs API can't be called more than a hack.
Using the Emacs API, in prv-emacs.el:
(defun preview-add-urgentization (fun ov &rest rest)
"Cause FUN (function call form) to be called when redisplayed.
FUN must be a form with OV as first argument,
REST as the remainder, returning T."
(let ((dispro (overlay-get ov 'display)))
(unless (eq (car dispro) 'when)
(overlay-put ov 'display `(when (,fun ,ov ,@rest) . ,dispro)))))
(defun preview-remove-urgentization (ov)
"Undo urgentization of OV by `preview-add-urgentization'.
Returns the old arguments to `preview-add-urgentization'
if there was any urgentization."
(let ((dispro (overlay-get ov 'display)))
(when (eq (car-safe dispro) 'when)
(prog1
(car (cdr dispro))
(overlay-put ov 'display (cdr (cdr dispro)))))))
Using the XEmacs API, in prv-xemacs.el:
(defun preview-add-urgentization (fun ov &rest rest)
"Cause FUN (function call form) to be called when redisplayed.
FUN must be a form with OV as first argument,
REST as the remainder, returning T. An alternative is to give
what `preview-remove-urgentization' returns, this will reinstate
the previous state."
(set-extent-initial-redisplay-function
ov
(if (null rest)
fun
`(lambda (ov) (,fun ,ov ,@rest)))))
(defun preview-remove-urgentization (ov)
"Undo urgentization of OV by `preview-add-urgentization'.
Returns the old arguments to `preview-add-urgentization'
if there was any urgentization."
(prog1 (list (extent-property ov 'initial-redisplay-function) ov)
(set-extent-initial-redisplay-function ov nil)))
--
David Kastrup
- Re: Is there something like `on-display-functions'?, (continued)
- Re: Is there something like `on-display-functions'?, Eli Zaretskii, 2010/01/27
- Re: Is there something like `on-display-functions'?, Alan Mackenzie, 2010/01/28
- Doc patch for `fontification-functions': [was: Is there something like `on-display-functions'?], Alan Mackenzie, 2010/01/28
- Re: Doc patch for `fontification-functions':, Chong Yidong, 2010/01/28
- Re: Doc patch for `fontification-functions':, Alan Mackenzie, 2010/01/28
- Re: Doc patch for `fontification-functions': [was: Is there something like `on-display-functions'?], Eli Zaretskii, 2010/01/28
- Re: Doc patch for `fontification-functions':, Stefan Monnier, 2010/01/28
Re: Is there something like `on-display-functions'?, alin.s, 2010/01/27
Re: Is there something like `on-display-functions'?,
David Kastrup <=
Re: Is there something like `on-display-functions'?, Davis Herring, 2010/01/27
Re: Is there something like `on-display-functions'?, Daniel Colascione, 2010/01/27