* What to do when font-lock-flush + font-lock-ensure do less than font-lock-fontify-buffer?
@ 2016-02-22 4:55 Clément Pit--Claudel
2016-02-22 8:56 ` Anders Lindgren
` (2 more replies)
0 siblings, 3 replies; 21+ messages in thread
From: Clément Pit--Claudel @ 2016-02-22 4:55 UTC (permalink / raw)
To: Emacs developers
[-- Attachment #1: Type: text/plain, Size: 644 bytes --]
Hi emacs-devel,
IIUC the proper way in Emacs 25 to signal changes that require a refontification to font-lock is to call font-lock-flush. This doesn't always do as much as font-lock-fontify-buffer does, though.
In particular, when the font-lock-fontified variable is nil (which does happen, though I don't know why; I don't know what this variable is for), then calling font-lock-fontify buffer does refontify the whole buffer, but font-lock-flush and font-lock-ensure don't seem to do anything.
What's the proper way to mark a buffer for refontification (and refontify the visible portion) immediately in 25?
Thanks,
Clément.
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: What to do when font-lock-flush + font-lock-ensure do less than font-lock-fontify-buffer?
2016-02-22 4:55 What to do when font-lock-flush + font-lock-ensure do less than font-lock-fontify-buffer? Clément Pit--Claudel
@ 2016-02-22 8:56 ` Anders Lindgren
2016-02-22 13:49 ` Clément Pit--Claudel
2016-02-22 16:13 ` Eli Zaretskii
2016-02-24 3:52 ` Stefan Monnier
2 siblings, 1 reply; 21+ messages in thread
From: Anders Lindgren @ 2016-02-22 8:56 UTC (permalink / raw)
To: Clément Pit--Claudel; +Cc: Emacs developers
[-- Attachment #1: Type: text/plain, Size: 383 bytes --]
>
> What's the proper way to mark a buffer for refontification (and refontify
> the visible portion) immediately in 25?
>
I've been using `(font-lock-region (point-min) (point-max))' to force a
refontification of the entire buffer, for my htmlize-like packages
(`faceup' and `e2ani'). I'm not sure if it's the "right way" to do it, but
it works in practice.
-- Anders Lindgren
[-- Attachment #2: Type: text/html, Size: 681 bytes --]
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: What to do when font-lock-flush + font-lock-ensure do less than font-lock-fontify-buffer?
2016-02-22 4:55 What to do when font-lock-flush + font-lock-ensure do less than font-lock-fontify-buffer? Clément Pit--Claudel
2016-02-22 8:56 ` Anders Lindgren
@ 2016-02-22 16:13 ` Eli Zaretskii
2016-02-22 16:29 ` Clément Pit--Claudel
2016-02-24 3:52 ` Stefan Monnier
2 siblings, 1 reply; 21+ messages in thread
From: Eli Zaretskii @ 2016-02-22 16:13 UTC (permalink / raw)
To: Clément Pit--Claudel; +Cc: emacs-devel
> From: Clément Pit--Claudel <clement.pit@gmail.com>
> Date: Sun, 21 Feb 2016 23:55:04 -0500
>
> IIUC the proper way in Emacs 25 to signal changes that require a refontification to font-lock is to call font-lock-flush. This doesn't always do as much as font-lock-fontify-buffer does, though.
>
> In particular, when the font-lock-fontified variable is nil (which does happen, though I don't know why; I don't know what this variable is for), then calling font-lock-fontify buffer does refontify the whole buffer, but font-lock-flush and font-lock-ensure don't seem to do anything.
>
> What's the proper way to mark a buffer for refontification (and refontify the visible portion) immediately in 25?
I think what you describe _is_ the proper way. Can you show a test
case which demonstrates how calling font-lock-flush followed by
font-lock-ensure fails to do the job?
Thanks.
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: What to do when font-lock-flush + font-lock-ensure do less than font-lock-fontify-buffer?
2016-02-22 16:13 ` Eli Zaretskii
@ 2016-02-22 16:29 ` Clément Pit--Claudel
2016-02-22 16:35 ` Kaushal Modi
2016-02-22 16:40 ` Eli Zaretskii
0 siblings, 2 replies; 21+ messages in thread
From: Clément Pit--Claudel @ 2016-02-22 16:29 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: emacs-devel
[-- Attachment #1: Type: text/plain, Size: 1215 bytes --]
On 02/22/2016 11:13 AM, Eli Zaretskii wrote:
>> From: Clément Pit--Claudel <clement.pit@gmail.com>
>> Date: Sun, 21 Feb 2016 23:55:04 -0500
>>
>> IIUC the proper way in Emacs 25 to signal changes that require a refontification to font-lock is to call font-lock-flush. This doesn't always do as much as font-lock-fontify-buffer does, though.
>>
>> In particular, when the font-lock-fontified variable is nil (which does happen, though I don't know why; I don't know what this variable is for), then calling font-lock-fontify buffer does refontify the whole buffer, but font-lock-flush and font-lock-ensure don't seem to do anything.
>>
>> What's the proper way to mark a buffer for refontification (and refontify the visible portion) immediately in 25?
>
> I think what you describe _is_ the proper way. Can you show a test
> case which demonstrates how calling font-lock-flush followed by
> font-lock-ensure fails to do the job?
In any case where font-lock-fontified is nil font-lock-fontify-buffer will properly refontify the whole buffer, but font-lock-flush and font-lock ensure will not do anything. I don't know what causes that variable to be nil in the first place, though.
Clément.
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: What to do when font-lock-flush + font-lock-ensure do less than font-lock-fontify-buffer?
2016-02-22 16:29 ` Clément Pit--Claudel
@ 2016-02-22 16:35 ` Kaushal Modi
2016-02-22 16:40 ` Eli Zaretskii
1 sibling, 0 replies; 21+ messages in thread
From: Kaushal Modi @ 2016-02-22 16:35 UTC (permalink / raw)
To: Clément Pit--Claudel; +Cc: Eli Zaretskii, Emacs developers
[-- Attachment #1: Type: text/plain, Size: 1116 bytes --]
On Mon, Feb 22, 2016 at 11:29 AM, Clément Pit--Claudel <
clement.pit@gmail.com> wrote:
> In any case where font-lock-fontified is nil font-lock-fontify-buffer will
> properly refontify the whole buffer, but font-lock-flush and font-lock
> ensure will not do anything. I don't know what causes that variable to be
> nil in the first place, though.
I am not sure if this is related. But in order for hi-lock-file-patterns to
work in a text-mode buffer, I need to do the below because
font-lock-fontified is nil for text-mode (as technically there are no
comments or keywords to highlight in that major mode).
;; Enable `hi-lock-mode' in `text-mode' too
;; The hi-lock fontification will not be visible (the
`font-lock-keywords'
;; variable will not be updated unless `font-lock-fontified' is already
`t'.
;; This was derived by studying the definition of
`hi-lock-font-lock-hook'
;; function.
(defun modi/hi-lock-enable-in-text-mode ()
(setq-local font-lock-fontified t))
(add-hook 'text-mode-hook #'modi/hi-lock-enable-in-text-mode)
--
Kaushal Modi
[-- Attachment #2: Type: text/html, Size: 1939 bytes --]
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: What to do when font-lock-flush + font-lock-ensure do less than font-lock-fontify-buffer?
2016-02-22 16:29 ` Clément Pit--Claudel
2016-02-22 16:35 ` Kaushal Modi
@ 2016-02-22 16:40 ` Eli Zaretskii
2016-02-22 17:28 ` Clément Pit--Claudel
1 sibling, 1 reply; 21+ messages in thread
From: Eli Zaretskii @ 2016-02-22 16:40 UTC (permalink / raw)
To: Clément Pit--Claudel; +Cc: emacs-devel
> Cc: emacs-devel@gnu.org
> From: Clément Pit--Claudel <clement.pit@gmail.com>
> Date: Mon, 22 Feb 2016 11:29:10 -0500
>
> > I think what you describe _is_ the proper way. Can you show a test
> > case which demonstrates how calling font-lock-flush followed by
> > font-lock-ensure fails to do the job?
>
> In any case where font-lock-fontified is nil
> font-lock-fontify-buffer will properly refontify the whole buffer,
> but font-lock-flush and font-lock ensure will not do anything.
That's not what I see in the code, that's why I asked for a test
case. I'm probably missing something.
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: What to do when font-lock-flush + font-lock-ensure do less than font-lock-fontify-buffer?
2016-02-22 16:40 ` Eli Zaretskii
@ 2016-02-22 17:28 ` Clément Pit--Claudel
2016-02-23 16:57 ` Eli Zaretskii
0 siblings, 1 reply; 21+ messages in thread
From: Clément Pit--Claudel @ 2016-02-22 17:28 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: emacs-devel
[-- Attachment #1: Type: text/plain, Size: 1297 bytes --]
On 02/22/2016 11:40 AM, Eli Zaretskii wrote:
>> Cc: emacs-devel@gnu.org
>> From: Clément Pit--Claudel <clement.pit@gmail.com>
>> Date: Mon, 22 Feb 2016 11:29:10 -0500
>>
>>> I think what you describe _is_ the proper way. Can you show a test
>>> case which demonstrates how calling font-lock-flush followed by
>>> font-lock-ensure fails to do the job?
>>
>> In any case where font-lock-fontified is nil
>> font-lock-fontify-buffer will properly refontify the whole buffer,
>> but font-lock-flush and font-lock ensure will not do anything.
>
> That's not what I see in the code, that's why I asked for a test
> case. I'm probably missing something.
Here's a test case:
(with-current-buffer (get-buffer-create "temp")
(erase-buffer)
(setq-default prettify-symbols-unprettify-at-point 'right-edge)
(emacs-lisp-mode)
(prettify-symbols-mode)
(insert "lambda\n\nlambda")
(pop-to-buffer (current-buffer)))
Moving around in this buffer unprettifies and reprettifies ‘lambda’s into ‘λ’s as the point moves in and out of them. Setting ‘font-lock-fontified’ to nil breaks that mechanism (the ‘λ’s are unprettified but no reprettified), and no series of ‘font-lock-flush’ and ‘font-lock-ensure’ will reprettify them.
Does this help?
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: What to do when font-lock-flush + font-lock-ensure do less than font-lock-fontify-buffer?
2016-02-22 17:28 ` Clément Pit--Claudel
@ 2016-02-23 16:57 ` Eli Zaretskii
2016-02-23 18:08 ` Clément Pit--Claudel
0 siblings, 1 reply; 21+ messages in thread
From: Eli Zaretskii @ 2016-02-23 16:57 UTC (permalink / raw)
To: Clément Pit--Claudel; +Cc: emacs-devel
> Cc: emacs-devel@gnu.org
> From: Clément Pit--Claudel <clement.pit@gmail.com>
> Date: Mon, 22 Feb 2016 12:28:13 -0500
>
> (with-current-buffer (get-buffer-create "temp")
> (erase-buffer)
> (setq-default prettify-symbols-unprettify-at-point 'right-edge)
> (emacs-lisp-mode)
> (prettify-symbols-mode)
> (insert "lambda\n\nlambda")
> (pop-to-buffer (current-buffer)))
>
> Moving around in this buffer unprettifies and reprettifies ‘lambda’s into ‘λ’s as the point moves in and out of them. Setting ‘font-lock-fontified’ to nil breaks that mechanism (the ‘λ’s are unprettified but no reprettified), and no series of ‘font-lock-flush’ and ‘font-lock-ensure’ will reprettify them.
>
> Does this help?
Yes, thanks. I will look into this soon.
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: What to do when font-lock-flush + font-lock-ensure do less than font-lock-fontify-buffer?
2016-02-22 4:55 What to do when font-lock-flush + font-lock-ensure do less than font-lock-fontify-buffer? Clément Pit--Claudel
2016-02-22 8:56 ` Anders Lindgren
2016-02-22 16:13 ` Eli Zaretskii
@ 2016-02-24 3:52 ` Stefan Monnier
2016-02-24 17:12 ` Eli Zaretskii
2 siblings, 1 reply; 21+ messages in thread
From: Stefan Monnier @ 2016-02-24 3:52 UTC (permalink / raw)
To: emacs-devel
> In particular, when the font-lock-fontified variable is nil (which does
> happen, though I don't know why; I don't know what this variable is for),
AFAIK this only happens when font-lock-mode is OFF, or when jit-lock is
not used and the buffer is larger than font-lock-maximum-size.
> then calling font-lock-fontify buffer does refontify the whole buffer, but
> font-lock-flush and font-lock-ensure don't seem to do anything.
It's normal for font-lock-flush to do nothing. As for font-lock-ensure
it's a bug which I believe I fixed a few weeks ago.
Stefan
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: What to do when font-lock-flush + font-lock-ensure do less than font-lock-fontify-buffer?
2016-02-24 3:52 ` Stefan Monnier
@ 2016-02-24 17:12 ` Eli Zaretskii
2016-02-24 18:55 ` Stefan Monnier
[not found] ` <<jwv1t829byc.fsf-monnier+emacs@gnu.org>
0 siblings, 2 replies; 21+ messages in thread
From: Eli Zaretskii @ 2016-02-24 17:12 UTC (permalink / raw)
To: Stefan Monnier; +Cc: emacs-devel
> From: Stefan Monnier <monnier@iro.umontreal.ca>
> Date: Tue, 23 Feb 2016 22:52:38 -0500
>
> > In particular, when the font-lock-fontified variable is nil (which does
> > happen, though I don't know why; I don't know what this variable is for),
>
> AFAIK this only happens when font-lock-mode is OFF, or when jit-lock is
> not used and the buffer is larger than font-lock-maximum-size.
>
> > then calling font-lock-fontify buffer does refontify the whole buffer, but
> > font-lock-flush and font-lock-ensure don't seem to do anything.
>
> It's normal for font-lock-flush to do nothing. As for font-lock-ensure
> it's a bug which I believe I fixed a few weeks ago.
Actually, in this particular case I think this is a bug in
prettify-symbols-mode: it should define its own
font-lock-ensure-function. The default value doesn't cover the kind
of stuff that this mode uses font-lock for.
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: What to do when font-lock-flush + font-lock-ensure do less than font-lock-fontify-buffer?
2016-02-24 17:12 ` Eli Zaretskii
@ 2016-02-24 18:55 ` Stefan Monnier
2016-02-24 19:17 ` Eli Zaretskii
[not found] ` <<jwv1t829byc.fsf-monnier+emacs@gnu.org>
1 sibling, 1 reply; 21+ messages in thread
From: Stefan Monnier @ 2016-02-24 18:55 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: emacs-devel
> Actually, in this particular case I think this is a bug in
> prettify-symbols-mode: it should define its own
> font-lock-ensure-function. The default value doesn't cover the kind
> of stuff that this mode uses font-lock for.
Hmm... I don't see any reason why that should be the case.
IOW I think that if a change is needed it should be font-lock.el because
prettify-symbols-mode seems to be using font-lock in a "normal" way.
Stefan
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: What to do when font-lock-flush + font-lock-ensure do less than font-lock-fontify-buffer?
2016-02-24 18:55 ` Stefan Monnier
@ 2016-02-24 19:17 ` Eli Zaretskii
2016-02-24 20:09 ` Stefan Monnier
0 siblings, 1 reply; 21+ messages in thread
From: Eli Zaretskii @ 2016-02-24 19:17 UTC (permalink / raw)
To: Stefan Monnier; +Cc: emacs-devel
> From: Stefan Monnier <monnier@IRO.UMontreal.CA>
> Cc: emacs-devel@gnu.org
> Date: Wed, 24 Feb 2016 13:55:42 -0500
>
> > Actually, in this particular case I think this is a bug in
> > prettify-symbols-mode: it should define its own
> > font-lock-ensure-function. The default value doesn't cover the kind
> > of stuff that this mode uses font-lock for.
>
> Hmm... I don't see any reason why that should be the case.
> IOW I think that if a change is needed it should be font-lock.el because
> prettify-symbols-mode seems to be using font-lock in a "normal" way.
I'm not sure about this (this machinery and its implications were
never sufficiently documented, and what I think I know is the result
of a desperate attempt to document it). However, please explain why
font-lock-ensure-function calls font-lock-DEFAULT-fontify-buffer. If
it's supposed to be good for any mode, why does it call the default
fontification?
As a matter of fact, if I replace the font-lock-default-fontify-buffer
call with a call to font-lock-fontify-buffer, the problem described by
the OP goes away. That is why I said what I said.
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: What to do when font-lock-flush + font-lock-ensure do less than font-lock-fontify-buffer?
2016-02-24 19:17 ` Eli Zaretskii
@ 2016-02-24 20:09 ` Stefan Monnier
2016-04-09 18:59 ` Clément Pit--Claudel
0 siblings, 1 reply; 21+ messages in thread
From: Stefan Monnier @ 2016-02-24 20:09 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: emacs-devel
> However, please explain why font-lock-ensure-function calls
> font-lock-DEFAULT-fontify-buffer.
Good question.
> As a matter of fact, if I replace the font-lock-default-fontify-buffer
> call with a call to font-lock-fontify-buffer, the problem described by
> the OP goes away. That is why I said what I said.
I haven't seen the beginning of the thread, but if that fixes the
problem, then I think it's a good change.
To go back to the previous question. I guess I used
font-lock-default-fontify-buffer because the whole point is to get rid
of all the misuses of font-lock-fontify-buffer, but I think in this case
it's indeed the right thing to do.
Stefan
^ permalink raw reply [flat|nested] 21+ messages in thread
[parent not found: <<jwv1t829byc.fsf-monnier+emacs@gnu.org>]
end of thread, other threads:[~2016-04-10 20:10 UTC | newest]
Thread overview: 21+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-02-22 4:55 What to do when font-lock-flush + font-lock-ensure do less than font-lock-fontify-buffer? Clément Pit--Claudel
2016-02-22 8:56 ` Anders Lindgren
2016-02-22 13:49 ` Clément Pit--Claudel
2016-02-22 15:53 ` Anders Lindgren
2016-02-22 16:13 ` Eli Zaretskii
2016-02-22 16:29 ` Clément Pit--Claudel
2016-02-22 16:35 ` Kaushal Modi
2016-02-22 16:40 ` Eli Zaretskii
2016-02-22 17:28 ` Clément Pit--Claudel
2016-02-23 16:57 ` Eli Zaretskii
2016-02-23 18:08 ` Clément Pit--Claudel
2016-02-24 3:52 ` Stefan Monnier
2016-02-24 17:12 ` Eli Zaretskii
2016-02-24 18:55 ` Stefan Monnier
2016-02-24 19:17 ` Eli Zaretskii
2016-02-24 20:09 ` Stefan Monnier
2016-04-09 18:59 ` Clément Pit--Claudel
2016-04-09 19:37 ` Eli Zaretskii
2016-04-09 19:54 ` Clément Pit--Claudel
2016-04-10 20:10 ` Stefan Monnier
[not found] ` <<jwv1t829byc.fsf-monnier+emacs@gnu.org>
[not found] ` <<838u29hq9x.fsf@gnu.org>
2016-02-24 19:20 ` Drew Adams
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).