From: Stefan Monnier <monnier@iro.umontreal.ca>
To: JD Smith <jdtsmith@gmail.com>
Cc: emacs-devel@gnu.org
Subject: Re: Selective font-locking?
Date: Tue, 13 Apr 2021 00:04:28 -0400 [thread overview]
Message-ID: <jwvlf9m6djt.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <98C7D46D-F01E-4C6B-8618-020BB76664C4@gmail.com> (JD Smith's message of "Mon, 12 Apr 2021 23:33:59 -0400")
>> On Apr 12, 2021, at 10:07 PM, Stefan Monnier <monnier@iro.umontreal.ca> wrote:
>>
>> Calling `font-lock-flush` or `font-lock-ensure` from font-lock-keywords
>> is quite odd. I'd call something like `font-lock-fontify-region` instead.
>
> Using `font-lock-fontify-region` instead causes Emacs to become mostly
> unresponsive. Sending a USR2 reveals:
>
> Debugger entered--entering a function:
> * #f(compiled-function () #<bytecode 0x1fed77d1f329>)()
> font-lock-default-fontify-region(188 189 nil)
> font-lock-fontify-region(188 189)
> #f(compiled-function (fun) #<bytecode 0x1fed77d1f2f9>)(font-lock-fontify-region)
> run-hook-wrapped(#f(compiled-function (fun) #<bytecode 0x1fed77d1f2f9>) font-lock-fontify-region)
> jit-lock--run-functions(188 189)
> jit-lock-fontify-now(188 688)
> jit-lock-function(188)
> redisplay_internal\ \(C\ function\)()
That's not giving enough info to figure out what's going on, sorry.
My crystal ball suggests that maybe your matching function simply
forgets to return nil, so font-lock calls it again and again thinking
we're keeping matching "more stuff" without ever reaching limit.
But it does remind me that rather than mess with `font-lock-keywords`,
you could do a similar dance with `font-lock-fontify-region-function`
(and internally call `font-lock-default-fontify-region`).
It might prove simpler and more reliable.
>> There's one thing with which you might want to be careful, tho, which is
>> the `syntax-ppss` state. You might want to `narrow-to-region` around
>> the call to `font-lock-fontify-region` (maybe narrow to pmark...(point-max)?).
>>
>> This is because in a shell buffer, some of the past interactions may
>> have been truncated (e.g. by `comint-truncate-buffer`), so you may end
>> up with (point-min) being in the middle of a string or something.
>> [ Similar problems can occur if the prompt itself contains funny characters
>> like unmatched quotes. or if past interactions include output which
>> is not lexically valid Python code. ]
>
> Well hmm, this is a bummer. l tested for this issue by inserting an entirely unmatched quote:
>
> In [12]: print(chr(39))
> '
>
> and this does affect the syntax (everything is a string). But unfortunately narrowing as follows doesn’t seem to fix this:
>
> (save-restriction
> (narrow-to-region pmark (point-max))
> (with-syntax-table python-mode-syntax-table
> (font-lock-flush start limit)
> (font-lock-ensure start limit)))))))
>
> I’m not sure it’s the same thing, but I found a related issue with `indent-for-tab-command'. In attempting to ignore the prompt for computing indentation, I narrowed to a region which excluded it, but indent.el calls `indent--funcall-widened’, which undoes my narrowing!
>
> Is there any way to specify "narrow to this region and don’t let anybody widen it(!)"?
It's called `font-lock-dont-widen`.
Stefan
prev parent reply other threads:[~2021-04-13 4:04 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-11 15:27 Selective font-locking? JD Smith
2021-04-11 16:31 ` Stefan Monnier
2021-04-11 20:54 ` JD Smith
2021-04-11 21:10 ` Stefan Monnier
2021-04-13 1:51 ` JD Smith
2021-04-13 2:07 ` Stefan Monnier
2021-04-13 3:33 ` JD Smith
2021-04-13 4:04 ` Stefan Monnier [this message]
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=jwvlf9m6djt.fsf-monnier+emacs@gnu.org \
--to=monnier@iro.umontreal.ca \
--cc=emacs-devel@gnu.org \
--cc=jdtsmith@gmail.com \
/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.