unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: David Kastrup <dak@gnu.org>
To: emacs-devel@gnu.org
Subject: Re: Is there something like `on-display-functions'?
Date: Wed, 27 Jan 2010 15:27:16 +0100	[thread overview]
Message-ID: <87hbq7wrln.fsf@lola.goethe.zz> (raw)
In-Reply-To: 20100127135716.GA3432@muc.de

Alan Mackenzie <acm@muc.de> 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





  parent reply	other threads:[~2010-01-27 14:27 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-01-27 13:57 Is there something like `on-display-functions'? Alan Mackenzie
2010-01-27 13:53 ` Lennart Borgman
2010-01-27 14:55   ` Alan Mackenzie
2010-01-27 15:11   ` Stefan Monnier
2010-01-27 15:37     ` Alan Mackenzie
2010-01-27 17:44       ` Eli Zaretskii
2010-01-27 19:24         ` Stefan Monnier
2010-01-27 20:08           ` Eli Zaretskii
2010-01-27 21:04             ` Stefan Monnier
2010-01-28  6:49               ` Eli Zaretskii
2010-01-28 19:37                 ` Stefan Monnier
2010-01-28 20:53                   ` Eli Zaretskii
2010-01-28 23:12                     ` Stefan Monnier
2010-01-29  9:09                       ` Eli Zaretskii
2010-01-29 18:08                         ` Stefan Monnier
2010-01-28  6:55               ` Eli Zaretskii
2010-01-28 10:38                 ` Alan Mackenzie
2010-01-28 12:54                   ` Eli Zaretskii
2010-01-28 14:47                     ` Alan Mackenzie
2010-01-28 19:18                       ` Eli Zaretskii
2010-01-29 13:09                         ` Alan Mackenzie
2010-01-28 19:37                   ` Stefan Monnier
2010-01-29 13:17                     ` Alan Mackenzie
2010-01-29 18:13                       ` Stefan Monnier
2010-01-29 19:17                         ` Alan Mackenzie
2010-01-30 21:02                           ` Stefan Monnier
2010-01-27 17:55       ` Eli Zaretskii
2010-01-28 10:27         ` Alan Mackenzie
2010-01-28 11:30       ` Doc patch for `fontification-functions': [was: Is there something like `on-display-functions'?] Alan Mackenzie
2010-01-28 15:34         ` Doc patch for `fontification-functions': Chong Yidong
2010-01-28 16:40           ` Alan Mackenzie
2010-01-28 18:38         ` Doc patch for `fontification-functions': [was: Is there something like `on-display-functions'?] Eli Zaretskii
2010-01-28 19:44         ` Doc patch for `fontification-functions': Stefan Monnier
2010-01-27 14:16 ` Is there something like `on-display-functions'? alin.s
2010-01-27 14:27 ` David Kastrup [this message]
2010-01-27 15:20   ` Alan Mackenzie
2010-01-27 16:31   ` Stephen J. Turnbull
2010-01-27 14:59 ` Davis Herring
2010-01-28  1:41 ` Daniel Colascione
2010-01-28 10:14   ` Alan Mackenzie
2010-01-28 19:39     ` Stefan Monnier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87hbq7wrln.fsf@lola.goethe.zz \
    --to=dak@gnu.org \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).