From: Harald Kirsch <pifpafpuf@gmx.de>
To: emacs-devel@gnu.org
Subject: Re: Any expert on font-lock machinery able to provide some insight --- problem solved
Date: Fri, 3 Jan 2025 17:09:40 +0100 [thread overview]
Message-ID: <c0d23125-daa6-4f5f-a05b-b81fd4cae4e3@gmx.de> (raw)
In-Reply-To: <a55ea3e0-ef48-4e61-8474-6a274a6f6959@gmx.de>
I think I found the problem.
If I wrap the face-adding code into with-silent-modifications, things
start to behave. Interpretation: without it the timer function doing the
font-locking is not under control of jit-lock so it sees the buffer
changes as a trigger to re-evaluate font-locking.
The confusing part was that I have with-silent-modifications in my
original code already. But what I have in fact is:
(combine-change-calls start end
...
(with-silent-modifications
which is (in hindsight obviously) the wrong order :-)
Thanks for your patience.
Harald
On 03.01.25 14:57, Harald Kirsch wrote:
> For better research I made a trivial example font lock function and call
> it, to simulate the async server round-trip, on a timer like so:
>
> ;;; -*- lexical-binding: t; -*-
>
> (defun eglot-semtok-request-fontification (&optional beg end loudly)
> (message "front %s-%s" beg end)
> (run-with-timer
> 0.1 nil
> (lambda () (t-eglot-semtok-request-fontification beg end loudly)) ) )
>
> (defun t-eglot-semtok-request-fontification (&optional beg end loudly)
> (message "timer %s-%s" beg end)
> (save-excursion
> (font-lock-unfontify-region beg end)
> (goto-char beg)
> (while-let ((mend (re-search-forward "[a-z]+\\(-[a-z]+\\)+" end t))
> (mstart (car (match-data))) )
> (add-face-text-property mstart mend 'bold) ) ))
>
> (setq font-lock-defaults
> '(nil nil nil nil
> (font-lock-fontify-region-function
> . eglot-semtok-request-fontification )
> (font-lock-fontify-buffer-function
> . eglot-semtok-request-fontification ) ) )
>
>
> - put into text file (easier to override font-lock)
> - M-x eval-buffer
> - M-x font-lock-mode
> - M-x font-lock-mode
> - insert a space near the top
> - move cursor
>
> See how for each cursor move the same front and timer messages are
> shown. When configuring the t-... function directly in setq and starting
> over, the extra font-lock calls are not seen.
>
> How would eglot-semtok-request-fontification need to change, short of
> actually fontifying everything, to lure font-locking into thinking all
> is fine, no need to run again shortly after?
>
> Harald.
>
>
> On 03.01.25 14:32, Eli Zaretskii wrote:
>> [Please use Reply All, to keep the list CC'ed.]
>>
>>> Date: Fri, 3 Jan 2025 13:44:04 +0100
>>> From: Harald Kirsch <pifpafpuf@gmx.de>
>>>
>>> Hi Eli,
>>>
>>> thanks for the explanation.
>>>
>>> On 03.01.25 12:58, Eli Zaretskii wrote:
>>> ...
>>>>> But it seems I am missing another channel of information which
>>>>> triggers
>>>>> font-locking too often.
>>>>
>>>> Why does it bother you that it happens too often?
>>>
>>> 1. I compare with elisp font-locking which is much less frequent.
>>>
>>> 2. It is eglot-semtok, which does an LSP server call to get font-lock
>>> information. It is quick enough and I wouldn't have noticed without the
>>> logging, but it seems a waste nevertheless.
>>>
>>>>> With describe-char I do see
>>>>>
>>>>> There are text properties here:
>>>>> fontified defer
>>>>>
>>>>> not going away. Can this point to the problem?
>>>>
>>>> This should only happen with buffer positions that were not yet
>>>> fontified. If the buffer position was already fontified, the value
>>>> should be t.
>>>
>>> The buffer position was already fontified, so I should not see this. I
>>> might be doing something wrong so that the font-lock machinery thinks,
>>> font-locking did not happen. The actual fontification happens
>>> asynchronously (due to the server roundtrip), but I thought I had given
>>> the engine enough info pretending all is done. I don't fully understand,
>>> how the decision is made to fontify again.
>>>
>>> Cheers
>>> Harald
>>>
next prev parent reply other threads:[~2025-01-03 16:09 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-03 10:26 Any expert on font-lock machinery able to provide some insight Harald Kirsch
2025-01-03 11:58 ` Eli Zaretskii
[not found] ` <91114d5a-4af9-4ae1-b7c9-b673e5edf25e@gmx.de>
2025-01-03 13:32 ` Eli Zaretskii
2025-01-03 13:57 ` Harald Kirsch
2025-01-03 16:09 ` Harald Kirsch [this message]
2025-01-03 14:42 ` John ff
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=c0d23125-daa6-4f5f-a05b-b81fd4cae4e3@gmx.de \
--to=pifpafpuf@gmx.de \
--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.