From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Harald Kirsch Newsgroups: gmane.emacs.devel Subject: Re: Any expert on font-lock machinery able to provide some insight --- problem solved Date: Fri, 3 Jan 2025 17:09:40 +0100 Message-ID: References: <67d9db0a-ba0f-4164-83fd-796089a6e40b@gmx.de> <86ikqwgldg.fsf@gnu.org> <91114d5a-4af9-4ae1-b7c9-b673e5edf25e@gmx.de> <86cyh4gh0t.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="17927"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla Thunderbird To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Fri Jan 03 17:10:33 2025 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1tTkFt-0004Wz-LN for ged-emacs-devel@m.gmane-mx.org; Fri, 03 Jan 2025 17:10:33 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tTkFC-0004Gp-Vi; Fri, 03 Jan 2025 11:09:51 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tTkFA-0004GX-GL for emacs-devel@gnu.org; Fri, 03 Jan 2025 11:09:48 -0500 Original-Received: from mout.gmx.net ([212.227.17.22]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tTkF8-00071E-C4 for emacs-devel@gnu.org; Fri, 03 Jan 2025 11:09:48 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmx.de; s=s31663417; t=1735920582; x=1736525382; i=pifpafpuf@gmx.de; bh=GnT8csIBI+Hy4rCPSAomCGniZdLJWLuk2iNQ8c5ZqNo=; h=X-UI-Sender-Class:Message-ID:Date:MIME-Version:Subject:From:To: References:In-Reply-To:Content-Type:Content-Transfer-Encoding:cc: content-transfer-encoding:content-type:date:from:message-id: mime-version:reply-to:subject:to; b=F6ov2X5EaT3OsrPh+QLYJTC5riQxy6Ctc8hkDZxiOfKlinHjfOM0oDJy8XteZsay VZLoQq24IRJ4iCtrZquDTxroQGtniKy2SLWPb70/8G1cjMjh0mEh+CP2FLkkJMPZ8 lgQcOFTo5f1gBI0jIXvgI0wsY7Ra6MjuBYF3g4Rw9/JZhIZQotBi6geKsEvC6kVhQ qxsbAvyljmFhzyfuSEzver/g8ezae2mUIMhmOJwPUcoeBll3x2XgeVOW8z3NyQgJp VpOZh1h+o26T67EJq2CK0HLvBVXTqxoSSVOT4tKv1+4E9PkdntsbhIyC1nod+WUwc nmqZnWoake/gnGXeSw== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Original-Received: from [192.168.55.104] ([79.247.82.79]) by mail.gmx.net (mrgmx104 [212.227.17.168]) with ESMTPSA (Nemesis) id 1MOA3F-1t5thk3TfF-00NeMV for ; Fri, 03 Jan 2025 17:09:41 +0100 Content-Language: en-US In-Reply-To: X-Provags-ID: V03:K1:6KB9BhLMZUKnupgfrlJFt3qJ6VSr/b6Jl3xxmdMSxfyF89VVJ4d m3jh8+8tTkleY+vQThoY/5DuVgS5AzTvjzVIpjuvaWavqIT4btK9JTepAOhglZyv9a+WvrC vBdgtQSbUe1XriANzM9BWVictPP0GhtMzpV3CX8o279FnMuLCO/KRuwRoofvjLudjHxgHP3 e2K1O9xlezuWF725fkLYg== UI-OutboundReport: notjunk:1;M01:P0:Etc4fMJMLBM=;xz5izYbpT5t0hZ+uHz9fVIPHfUJ i+xWRH/SfCehyee9gAyxqn+NR980pbA6n89gnGo7CYtOT5V/yWntaj2lEOfng42tIFU8fbz/2 JrQL/QhDOWqnr3H09LpJJHgw3t4YXyhkhhFhTS6CkchwD2FFUA50eMlkjPWTtpk5n4U7QKE7G evp3d/luQpsjKOBtm5jazKR/wtyF/Nn+1X4bjko3PUBsX3175ddsUKV9WJ3fErhJUL+e5k0cD nrPz2lVG4xR2G8zeOf5slFNlC2MMmz066woGVaLIZRBKWvGFCVIfIN0uwaHFzMQSQ3Rc+eT+H jMoQkX47iEbImlNWJ5A1rPyBLD2wVi0y41v/XbbiGiGdNptefDDaBh1N8/wF1jb7N+6XP9IaG PYPOFRtAHB8NGvfUCw/QuYBo2HB9kPMKB0LFmaLmDSVATS4nomvRb3e4hdRcbopgU4TYl+w7t 92hLV/zqLh3S3lph72ir7k5gz645HMij4ers2MgzgSaPcwsQNoDes+XHIe8/iC7m6EEMh6218 UNfrPuDo5yXC/omJgKdLocY5J1SelGq9uTaWBNMnP3ovdsKS9d6ahuOVZBZOfQyeEHbxkYziK SaOsw71OZSRx5Knma+F+XDvZC68OZFRoBSGfkJcf3nfroxG6ID8iYvI5MqzlSKyMyAsdd+9Uc qhE0ZK6UlX1gpMGPyJUy+NlNty67G0/NhorlmWkofagYYEaHtnchG0jAT5fK7x/Tg/AXcvwFb xZ5gNSjThRDTQSgJOghDbB6q9jda9G8NRCPO1DB0zgkXCPGuMaWYA711Xwn8Tdd0ByCfxjoC Received-SPF: pass client-ip=212.227.17.22; envelope-from=pifpafpuf@gmx.de; helo=mout.gmx.net X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:327631 Archived-At: 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) > =C2=A0 (message "front %s-%s" beg end) > =C2=A0 (run-with-timer > =C2=A0=C2=A0 0.1 nil > =C2=A0=C2=A0 (lambda () (t-eglot-semtok-request-fontification beg end l= oudly)) ) ) > > (defun t-eglot-semtok-request-fontification (&optional beg end loudly) > =C2=A0 (message "timer %s-%s" beg end) > =C2=A0 (save-excursion > =C2=A0=C2=A0=C2=A0 (font-lock-unfontify-region beg end) > =C2=A0=C2=A0=C2=A0 (goto-char beg) > =C2=A0=C2=A0=C2=A0 (while-let ((mend (re-search-forward "[a-z]+\\(-[a-z= ]+\\)+" end t)) > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0 (mstart (car (match-data))) ) > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (add-face-text-property mstart mend 'bol= d) ) )) > > (setq font-lock-defaults > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 '(nil nil nil nil > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (fon= t-lock-fontify-region-function > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0 . eglot-semtok-request-fontification ) > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (fon= t-lock-fontify-buffer-function > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0 . 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 >>> >>> 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 th= e >>> logging, but it seems a waste nevertheless. >>> >>>>> With describe-char I do see >>>>> >>>>> There are text properties here: >>>>> =C2=A0=C2=A0=C2=A0=C2=A0 fontified=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 defer >>>>> >>>>> not going away. Can this point to the problem? >>>> >>>> This should only happen with buffer positions that were not yet >>>> fontified.=C2=A0 If the buffer position was already fontified, the va= lue >>>> 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 give= n >>> the engine enough info pretending all is done. I don't fully understan= d, >>> how the decision is made to fontify again. >>> >>> Cheers >>> Harald >>>