all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Alan Mackenzie <acm@muc.de>
To: Drew Adams <drew.adams@oracle.com>
Cc: emacs-devel@gnu.org
Subject: Re: command to fontify whole buffer?
Date: Thu, 22 Sep 2011 15:27:01 +0000	[thread overview]
Message-ID: <20110922152701.GC3134@acm.acm> (raw)
In-Reply-To: <BABE6DA813E749E9AE3608642BD59EDE@us.oracle.com>

Hi, Drew.

On Thu, Sep 22, 2011 at 07:56:52AM -0700, Drew Adams wrote:
> > > `font-lock-fontify-buffer' doesn't do it.

> > Are you sure?  I thought it did, and looking again at the 
> > fine source, it does appear to.

> No, I only think I'm sure. ;-)

> After calling `font-lock-fontify-buffer', I can search for zones with face
> `font-lock-function-name-face', for example, and I can see that there are no
> such zones after some minimal portion of the buffer.

Ah.  OK.

> > > Marking the whole buffer and using 
> > `(font-lock-fontify-region BEG END)'
> > > doesn't do it.

> > Ditto.

> ditto

ditto.

> > > Digging more than a bit, I finally found non-interactive function
> > > `jit-lock-fontify-now', which seems to do the trick.  Why 
> > > not provide a command that does it?

> > jit-lock-fontify-now                 just calls the function
> > font-lock-fontify-region             (via a hook) which calls
> > font-lock-default-fontify-region     (via another hook).

> I believe you, but I'm not seeing `font-lock-default-fontify-region' fontify
> everything.  I'm no expert on this at all.  Just going by what I think I see.

> > Surely 'fontified DOES do it.  If it has the value t throughout the
> > buffer, that buffer is fully fontified, otherwise not.

> Perhaps you're right that if I checked that property throughout the entire
> buffer it would be sufficient.  Dunno.  I probably didn't try testing it
> everywhere.  But if that's the best test for full-buffer fontification then I
> would still prefer something simpler/quicker.

Surely `next-property-change' is going to be fast enough.

> > Or have I misunderstood something?

> No, no doubt I have.  No doubt I still do. ;-)

> > By the way, I drew a diagram of how jit-lock works about 5 years ago,
> > tracing the functions which call each other, and the hooks 
> > out of which things get hoiked.  Would you be interested in a copy of it?

> I guess so; thanks.  But I would mostly be interested in confirmation that you
> are right etc.  I do not see (e.g. by searching for property zones) that the
> entire buffer gets fontified by `font-lock-fontify-buffer', but you say it
> does/should.

OK, here goes.  Bear in mind it's five years old.

#########################################################################

(i) DEMAND.  This is a call from the display engine to fontify a bit of the
  buffer.  JIT either fontifies immediately, or sets 'fontified to 'defer,
  invoking deferred fontification ((iii)).
(ii) STEALTH.  This is fontification which happens during idleness.
(iii) DEFERRED.  After a (short, ~0.25 second) idleness period, deferred bits
  (from demand ((i))) get 'fontified set to nil.  WHOOPS!  This leads to an

(iv) CONTEXT.  After a change, 'fontified is marked nil on the buffer from
  that point on.  Intended for unmatched string openers, etc.
(v) AFTER CHANGE.  On a buffer change, the 'fontified property on the
  pertinent text is set to nil.


"*" means that the routine adjusts the region to whole lines.

DEMAND (called by display code)  <----------------------------|
      [fontification-functions] (hook)                        |
      jit-lock-function ->-|                                  |
|-------------<------------+ <is defer-font enabled>?         |
|                          |                                  |
|                          v                                  ^
| |-----------<------------|                                  |
| |                                                           |
| |->* jit-lock-fontify-now  <----------------------------|   |
|      jit-lock-functions (hook)                          |   |
v      font-lock-fontify-region  <------------------------+---+----|
|      [font-lock-fontify-region-function] (hook)         |   |    |
|    * font-lock-default-fontify-region                   |   |    |
|                                                         |   |    |
|DEFERRED (invoked by jit-lock-defer-timer)               |   |    |
|-->   jit-lock-deferred-fontify  ------------------>-----+---|    |
         This sets 'fontified to nil, and calls sit-for,  |   |    |
         causing immediate display (by DEMAND).           |   |    |
                                                          |   |    |
STEALTH (invoked by jit-lock-stealth-timer                |   |    |
      jit-lock-stealth-fontify                            |   ^    |
      jit-lock-fontify-now ----------------->-------------|   |    |
                                                              |    |
CONTEXT (invoked by jit-lock-context-timer)                   |    |
      jit-lock-context-fontify (from timer) -------->---------+    |
        This sets 'fontified to nil on the (extended)         |    |
        region.                                               |    |
                                                              |    |
JIT AFTER CHANGE (called from the after-change hook)          |    ^
    * jit-lock-after-change --------------->------------------|    |
      This sets 'fontified to nil, and relies on DEMAND            |
      to refontify the changed bit during display.                 |
                                                                   |
ORDINARY AFTER CHANGE (without jit)                                |
    * font-lock-after-change-function                              |
      font-lock-fontify-region ---------------->-------------------|
                                                                   |
COMMANDS                                                           |
      font-lock-fontify-block                                      |
      font-lock-fontify-region ---------------->-------------------|
                                                                   |
      font-lock-fontify-buffer                                     |
      [font-lock-fontify-buffer-function] (hook)                   |
      font-lock-default-fontify-buffer                             |
      font-lock-fontify-region ---------------->-------------------|

#########################################################################

Interpretation: Of the five possible triggers (e.g. DEMAND) for
fontification, this shows the sequence of functions triggered by each of
them.  [Symbols] in brackets are hook variables.

As you surmise above, jit-lock-fontify-now is the central function which
actually gets the fontification done.

-- 
Alan Mackenzie (Nuremberg, Germany).



  reply	other threads:[~2011-09-22 15:27 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-09-22 13:32 command to fontify whole buffer? Drew Adams
2011-09-22 14:33 ` Alan Mackenzie
2011-09-22 14:46   ` Lennart Borgman
2011-09-22 15:33     ` Alan Mackenzie
2011-09-22 17:30       ` Dave Abrahams
2011-09-22 22:31         ` Lennart Borgman
2011-09-22 14:56   ` Drew Adams
2011-09-22 15:27     ` Alan Mackenzie [this message]
2011-09-22 15:43       ` Drew Adams
2011-09-22 22:34       ` Lennart Borgman
2011-09-25 20:54       ` Nix
2011-09-23  4:23 ` Stefan Monnier
2011-09-23  4:55   ` Jambunathan K

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

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

  git send-email \
    --in-reply-to=20110922152701.GC3134@acm.acm \
    --to=acm@muc.de \
    --cc=drew.adams@oracle.com \
    --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 external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.