unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: JD Smith <jdtsmith@gmail.com>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: emacs-devel@gnu.org
Subject: Re: Selective font-locking?
Date: Mon, 12 Apr 2021 23:33:59 -0400	[thread overview]
Message-ID: <98C7D46D-F01E-4C6B-8618-020BB76664C4@gmail.com> (raw)
In-Reply-To: <jwveeff6j1r.fsf-monnier+emacs@gnu.org>

[-- Attachment #1: Type: text/plain, Size: 2337 bytes --]



> 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\)()  

> 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(!)"?

[-- Attachment #2: Type: text/html, Size: 4196 bytes --]

  reply	other threads:[~2021-04-13  3:33 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 [this message]
2021-04-13  4:04             ` Stefan Monnier

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

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=98C7D46D-F01E-4C6B-8618-020BB76664C4@gmail.com \
    --to=jdtsmith@gmail.com \
    --cc=emacs-devel@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /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 public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).