[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Limits of multiline font-lock

From: Adam Porter
Subject: Re: Limits of multiline font-lock
Date: Wed, 18 Sep 2019 16:13:09 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux)

Michael Heerdegen <address@hidden> 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


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.  :)


reply via email to

[Prev in Thread] Current Thread [Next in Thread]