From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: Selective font-locking? Date: Tue, 13 Apr 2021 00:04:28 -0400 Message-ID: References: <7A948673-E156-42BA-BA50-E91986908BB5@gmail.com> <65B869A0-CB0B-43C1-90EA-E2B259A74589@gmail.com> <0A6735A5-ABC0-48B0-B7C0-EACF5D85A32B@gmail.com> <98C7D46D-F01E-4C6B-8618-020BB76664C4@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="13525"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: emacs-devel@gnu.org To: JD Smith Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Tue Apr 13 06:06:04 2021 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lWAJQ-0003Qi-LY for ged-emacs-devel@m.gmane-mx.org; Tue, 13 Apr 2021 06:06:04 +0200 Original-Received: from localhost ([::1]:38006 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lWAJP-0005pA-Ns for ged-emacs-devel@m.gmane-mx.org; Tue, 13 Apr 2021 00:06:03 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:55026) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lWAHz-0005CM-Qt for emacs-devel@gnu.org; Tue, 13 Apr 2021 00:04:35 -0400 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:36307) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lWAHx-0006B3-Fs for emacs-devel@gnu.org; Tue, 13 Apr 2021 00:04:35 -0400 Original-Received: from pmg1.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id CB2B41002AC; Tue, 13 Apr 2021 00:04:31 -0400 (EDT) Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id C625910021D; Tue, 13 Apr 2021 00:04:29 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1618286669; bh=GPaQZIgtOvqfk4lgoMCbz96qKDRP7j9RL1wMe6gWQmM=; h=From:To:Cc:Subject:References:Date:In-Reply-To:From; b=ET7m+TQxcSf1xgXvMp+VprysFxzgAK5RRIKg0c42eksiACblfkoQxeXnXO/9Ni9xU 9MHkOM5P+7BXb/7xXJHbrUmdNvT7NqYKgVP7Ls/yFCbaTD0zKFn6eb4g0MyHzwI0oe w61Q40KgP25iU/xDBie9u+LmaDY1uxxBjwV/ZPavReUdOITt+TXHfa6FR9iVsWAhRS 2F1U8Qc3f8164TZgIayJy8CBfqClIO/AO3cZO0XY3wa8Lgc4gmQL+xhBhpBbGl5OtO Q0D7PuH2FgfQpO4J/STLi4adn2BJIVCUZSApv7w5vnEXr0/YLYUZdVtOqKw55mS/SG sslOEIST3oreg== Original-Received: from alfajor (104-222-126-84.cpe.teksavvy.com [104.222.126.84]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 92801120314; Tue, 13 Apr 2021 00:04:29 -0400 (EDT) In-Reply-To: <98C7D46D-F01E-4C6B-8618-020BB76664C4@gmail.com> (JD Smith's message of "Mon, 12 Apr 2021 23:33:59 -0400") Received-SPF: pass client-ip=132.204.25.50; envelope-from=monnier@iro.umontreal.ca; helo=mailscanner.iro.umontreal.ca X-Spam_score_int: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:267991 Archived-At: >> On Apr 12, 2021, at 10:07 PM, Stefan Monnier = wrote: >>=20 >> Calling `font-lock-flush` or `font-lock-ensure` from font-lock-keywords >> is quite odd. I'd call something like `font-lock-fontify-region` instea= d. > > Using `font-lock-fontify-region` instead causes Emacs to become mostly > unresponsive. Sending a USR2 reveals: > > Debugger entered--entering a function: > * #f(compiled-function () #)() > font-lock-default-fontify-region(188 189 nil) > font-lock-fontify-region(188 189) > #f(compiled-function (fun) #)(font-lock-fontif= y-region) > run-hook-wrapped(#f(compiled-function (fun) #)= font-lock-fontify-region) > jit-lock--run-functions(188 189) > jit-lock-fontify-now(188 688) > jit-lock-function(188) > redisplay_internal\ \(C\ function\)()=20=20 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-m= ax)?). >>=20 >> 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 charact= ers >> 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 enti= rely unmatched quote: > > In [12]: print(chr(39)) > ' > > and this does affect the syntax (everything is a string). But unfortunat= ely narrowing as follows doesn=E2=80=99t 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=E2=80=99m not sure it=E2=80=99s the same thing, but I found a related i= ssue with `indent-for-tab-command'. In attempting to ignore the prompt for= computing indentation, I narrowed to a region which excluded it, but inden= t.el calls `indent--funcall-widened=E2=80=99, which undoes my narrowing!=20= =20 > > Is there any way to specify "narrow to this region and don=E2=80=99t let = anybody widen it(!)"? It's called `font-lock-dont-widen`. Stefan