From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Adam Porter Newsgroups: gmane.emacs.devel Subject: Re: Limits of multiline font-lock Date: Wed, 18 Sep 2019 16:13:09 -0500 Message-ID: <874l198g0q.fsf@alphapapa.net> References: <87impuu7qy.fsf@web.de> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="78916"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Sep 18 23:14:03 2019 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1iAhGz-000KNw-07 for ged-emacs-devel@m.gmane.org; Wed, 18 Sep 2019 23:14:01 +0200 Original-Received: from localhost ([::1]:35332 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iAhGx-0003XQ-Ji for ged-emacs-devel@m.gmane.org; Wed, 18 Sep 2019 17:13:59 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:49146) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iAhGM-0003X5-5T for emacs-devel@gnu.org; Wed, 18 Sep 2019 17:13:23 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iAhGK-000159-Vp for emacs-devel@gnu.org; Wed, 18 Sep 2019 17:13:22 -0400 Original-Received: from 195-159-176-226.customer.powertech.no ([195.159.176.226]:59824 helo=blaine.gmane.org) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iAhGK-00014O-BD for emacs-devel@gnu.org; Wed, 18 Sep 2019 17:13:20 -0400 Original-Received: from list by blaine.gmane.org with local (Exim 4.89) (envelope-from ) id 1iAhGH-000JaW-H6 for emacs-devel@gnu.org; Wed, 18 Sep 2019 23:13:17 +0200 X-Injected-Via-Gmane: http://gmane.org/ X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 195.159.176.226 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.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:240155 Archived-At: Michael Heerdegen writes: > Hello, > > I want to provide a hi-lock like feature for el-search patterns: an on > the fly highlighting of any expressions matching a certain el-search > pattern. Elisp expressions can be multiline, of course. After reading what > the manual says about multiline font lock I'm not sure if I can use > font-lock for that. > > My use case is a bit different from the existing cases because I don't > need the multiline font-lock to implement a major mode. So ideally I > don't want to mess with buffer local font-lock variables (like > `font-lock-extend-region-functions'). > > I noticed that it seems to be allowed in a font-lock function > (lambda (end) ...) to look backwards, and attach the font-lock-multiline > property to text that extends to text before the font-lock search > start. Is this correct? > > I also noticed that highlighting of strings already works with something > called syntactical matching or so, so what I need seems to be already > existing but it also seems that there are no Lisp functions to reuse > this stuff. > > Before I reinvent the wheel or invest unnecessary amounts of time: is it > possible to base el-search-hi-lock on font-lock? How would I ideally > approach? > > TIA, > > Michael. Hi Michael, You might be interested in this package I published recently. It implements depth-based syntax highlighting for Lisp and some other languages. https://github.com/alphapapa/prism.el I had to deal with similar issues about multiline font-locking. After reading the manual section about it a few times, I managed to come up with a solution that works fairly well, although I'm sure it's quite primitive: I add a function to font-lock-extend-region-functions which extends the font-lock region forward and backwards before the matching function is called. I don't know if it's the optimal way to do it--the manual mentioned that there are a few ways--but it seems to work. However, I have discovered a performance issue in the case of sexps that span large portions of the buffer (e.g. in my init files, I have some large use-package forms that contain many functions and span hundreds of lines). If I could solve that, it would be great, but it works fine for most code. Please let me know if you have any suggestions. Sometimes font-locking feels like an arcane art. :) Thanks, Adam