From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: David Engster Newsgroups: gmane.emacs.devel Subject: font lock with functions (was: emacs rendering comparisson between emacs23 and emacs26.3) Date: Tue, 31 Mar 2020 12:15:49 +0200 Message-ID: <87a73w4yp6.fsf@randomsample> References: <86tv2h2vww.fsf@gmail.com> <20200322123818.GB32470@ACM> <87eetk5swm.fsf@gnu.org> <20200326193128.GC14092@ACM> <86d08y4zsx.fsf@gmail.com> <83sghs7qdz.fsf@gnu.org> <7ee94ed4-7a11-90bd-df69-c0eeacaf191c@gmail.com> <835zeo7c92.fsf@gnu.org> <05de335b-383e-b32d-2e7e-e79192d364de@yandex.ru> <03981ead-3aca-c238-a9d0-88407ffae451@yandex.ru> <83wo745tw6.fsf@gnu.org> <837dz35j30.fsf@gnu.org> <9b013d7f-664a-711d-0b7b-d7bd961b8ef0@yandex.ru> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="68396"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.90 (gnu/linux) Cc: Eli Zaretskii , cpitclaudel@gmail.com, Stefan Monnier , emacs-devel@gnu.org To: Dmitry Gutov Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Tue Mar 31 12:17:03 2020 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 1jJDx9-000HiO-R8 for ged-emacs-devel@m.gmane-mx.org; Tue, 31 Mar 2020 12:17:03 +0200 Original-Received: from localhost ([::1]:35290 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jJDx8-0001PM-Qc for ged-emacs-devel@m.gmane-mx.org; Tue, 31 Mar 2020 06:17:02 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:47125) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jJDwM-0000JS-Se for emacs-devel@gnu.org; Tue, 31 Mar 2020 06:16:16 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jJDwL-0004KL-Fd for emacs-devel@gnu.org; Tue, 31 Mar 2020 06:16:14 -0400 Original-Received: from randomsample.de ([5.45.97.173]:36958) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jJDwL-0004Ed-2i; Tue, 31 Mar 2020 06:16:13 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=randomsample.de; s=a; h=Content-Type:MIME-Version:Message-ID:Date:References:In-Reply-To:Subject:Cc:To:From; bh=HptAC/hqDWbDEmRk7WeF6t4UUkPEmdSJbbNTEoyGoHA=; b=D7OqiZ/ra9VpnfmgiYdUW8Q0BXtu8sIbioONEssRXcl7+0kMdDRAZxe4L+jJ/TP+21lm0zHZ3iUSU61R4ON/yXWiU6GBg6P/AOrj4v9QTX1ypHkX40fTXqCzoYIm89mO; Original-Received: from ip5f5abaee.dynamic.kabel-deutschland.de ([95.90.186.238] helo=void) by randomsample.de with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.80) (envelope-from ) id 1jJDwC-0003FT-DQ; Tue, 31 Mar 2020 12:16:04 +0200 In-Reply-To: <9b013d7f-664a-711d-0b7b-d7bd961b8ef0@yandex.ru> (Dmitry Gutov's message of "Sun, 29 Mar 2020 21:10:51 +0300") X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 5.45.97.173 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 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" Xref: news.gmane.io gmane.emacs.devel:246082 Archived-At: > On 29.03.2020 19:39, Stefan Monnier wrote: >> I think it's just a reflection of the fact that author doesn't know >> enough about jit-lock and font-lock. > > Indeed, that font-lock rule can be a function is not very well-known. Indeed. Since I'm currently writing a major-mode which makes heavy use of this feature, let me add my experience. I found the font-lock documentation in the Emacs Lisp reference manual to be pretty opaque, but I also wouldn't really know how to improve it. What is mostly missing are practical examples, but I understand that a reference manual is probably not the right place for this. I found some helpful posts online, like this SO answer from you https://stackoverflow.com/a/14675550 and this blog post http://www.modernemacs.com/post/advanced-syntax/ Other smaller problems I'm having: - It is very easy during testing to completely hang your Emacs session if one of the font-lock functions hangs. One usually needs to kill Emacs in this case. - Debugging is difficult because you cannot instrument the functions for some reason. Luckily, I found 'font-lock-studio', which is incredibly useful. We should try to get this into ELPA and advertise it in the manual: https://github.com/Lindydancer/font-lock-studio On a more general note: When you use functions for font-locking, I often find myself in the position that I'm more or less writing a parser, and I could readily tell font-lock how to fontify several parts of the buffer with different faces. However, AFAICS, this is not possible with current font-lock? It seems each rule can always only return one type of face, or am I missing something? Of course, you can still make this work, but it makes font-lock pretty slow, because you effectively need to re-parse the changed portions of the buffer several times. I would imagine that fontifying based on tree-sitter would run into the same issue? -David