all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Adam Porter <adam@alphapapa.net>
To: emacs-devel@gnu.org
Subject: Re: Limits of multiline font-lock
Date: Wed, 18 Sep 2019 16:13:09 -0500	[thread overview]
Message-ID: <874l198g0q.fsf@alphapapa.net> (raw)
In-Reply-To: 87impuu7qy.fsf@web.de

Michael Heerdegen <michael_heerdegen@web.de> 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




  parent reply	other threads:[~2019-09-18 21:13 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-14 17:07 Limits of multiline font-lock Michael Heerdegen
2019-09-15 12:28 ` Stefan Monnier
2019-09-15 23:13   ` Michael Heerdegen
2019-09-16 19:00     ` Stefan Monnier
2019-09-18  3:23       ` Michael Heerdegen
2019-09-18 21:13 ` Adam Porter [this message]
2019-09-19  2:05   ` Michael Heerdegen
2019-09-19  2:36     ` Adam Porter
2023-10-07  7:30     ` Adam Porter
2023-10-14  4:06       ` Michael Heerdegen

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=874l198g0q.fsf@alphapapa.net \
    --to=adam@alphapapa.net \
    --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.