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: Mon, 12 Apr 2021 22:07:13 -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> 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="8125"; 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 04:08:52 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 1lW8U0-00022b-9z for ged-emacs-devel@m.gmane-mx.org; Tue, 13 Apr 2021 04:08:52 +0200 Original-Received: from localhost ([::1]:33894 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lW8Tz-0007Hj-BF for ged-emacs-devel@m.gmane-mx.org; Mon, 12 Apr 2021 22:08:51 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:34582) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lW8Se-0006ha-2Q for emacs-devel@gnu.org; Mon, 12 Apr 2021 22:07:28 -0400 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:51889) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lW8Sa-00081v-CY for emacs-devel@gnu.org; Mon, 12 Apr 2021 22:07:27 -0400 Original-Received: from pmg1.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id C17381001D2; Mon, 12 Apr 2021 22:07:22 -0400 (EDT) Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id 1DC92100040; Mon, 12 Apr 2021 22:07:14 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1618279634; bh=w8zi9c+b4DeaBI/dCoE8oTwYhCLmt83jvkCcqDX7rY0=; h=From:To:Cc:Subject:References:Date:In-Reply-To:From; b=M/7mIUkO1l8tEKguKbwIvjCrDIAFWyjG1iR8OJ8wqHvk9a796U6cYjZn1/NK65WkJ KLNPDNxZDJlGzR+pjlC3eCWKyLtWuqwxOdou+/0vWg+T6pM+cExfAjk8iV1cwJm+GL Mq7uv4KE3OWDoyqD7seNkNyAdld+n9IhTJkrW040R4J5Tm3GKevwnriTs5Apap5gsy bYsxFZhySrK+YoPBwAvo5WmFL7nWgjUkmo1Qs7R/8/du6B1i6FjmcMBbvGw6HuV3xk XNcN4KvHuAJLMeDvtQpb+mv2h7levSBGbQlkkFeThJwHLfzGtCEAK5pygArgQcnzpJ /8u574Q71LPlQ== Original-Received: from alfajor (104-222-126-84.cpe.teksavvy.com [104.222.126.84]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id E930B1201A7; Mon, 12 Apr 2021 22:07:13 -0400 (EDT) In-Reply-To: <0A6735A5-ABC0-48B0-B7C0-EACF5D85A32B@gmail.com> (JD Smith's message of "Mon, 12 Apr 2021 21:51:28 -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:267985 Archived-At: > (defun python-shell-multiline--apply-font-lock (limit) > (if-let ((process (get-buffer-process (current-buffer))) > (pmark (process-mark))) > (if (> limit pmark) > (let ((font-lock-keywords python-shell-multiline-font-lock-keywords) > (font-lock-syntactic-face-function > #'python-font-lock-syntactic-face-function) > (start (max pmark (point)))) > (with-syntax-table python-mode-syntax-table > (font-lock-flush start limit) > (font-lock-ensure start limit)))))) 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. > It seems to me this general technique could be useful for lots of > different =E2=80=9Cmixed fontification buffers=E2=80=9D, simply rebinding > font-lock-keywords/syntax table/etc. as needed for the region under > consideration. It=E2=80=99s much simpler than the round-trip copy + full > buffer re-fontify that many modes use, with no extra buffers to > manage, post-command-hooks, etc. Indeed that matches my intuition. 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. ] Stefan