From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.bugs Subject: bug#41195: 27.0.91; Using syntax-ppss-flush-cache in syntax-propertize-function infloops Date: Tue, 12 May 2020 16:55:18 -0400 Message-ID: References: <1d616b0d-3e1b-5f72-da35-d0aa056322b4@yandex.ru> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="48767"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: 41195-close@debbugs.gnu.org To: Dmitry Gutov Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue May 12 22:56:12 2020 Return-path: Envelope-to: geb-bug-gnu-emacs@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 1jYbwh-000CXu-BD for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 12 May 2020 22:56:11 +0200 Original-Received: from localhost ([::1]:57044 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jYbwg-0000oO-CI for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 12 May 2020 16:56:10 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:58306) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jYbwY-0000m2-6k for bug-gnu-emacs@gnu.org; Tue, 12 May 2020 16:56:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:45071) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jYbwX-0006am-T9 for bug-gnu-emacs@gnu.org; Tue, 12 May 2020 16:56:01 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1jYbwX-0007SB-Sf for bug-gnu-emacs@gnu.org; Tue, 12 May 2020 16:56:01 -0400 Resent-From: Stefan Monnier Original-Sender: "Debbugs-submit" Resent-To: bug-gnu-emacs@gnu.org Resent-Date: Tue, 12 May 2020 20:56:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: cc-closed 41195 X-GNU-PR-Package: emacs Mail-Followup-To: 41195@debbugs.gnu.org, monnier@iro.umontreal.ca, dgutov@yandex.ru Original-Received: via spool by 41195-done@debbugs.gnu.org id=D41195.158931695128626 (code D ref 41195); Tue, 12 May 2020 20:56:01 +0000 Original-Received: (at 41195-close) by debbugs.gnu.org; 12 May 2020 20:55:51 +0000 Original-Received: from localhost ([127.0.0.1]:56615 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jYbw9-0007RP-Eg for submit@debbugs.gnu.org; Tue, 12 May 2020 16:55:51 -0400 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:11186) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jYbw5-0007R8-TH for 41195-close@debbugs.gnu.org; Tue, 12 May 2020 16:55:36 -0400 Original-Received: from pmg3.iro.umontreal.ca (localhost [127.0.0.1]) by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id 499F9450C47; Tue, 12 May 2020 16:55:28 -0400 (EDT) Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id 4831B450A40; Tue, 12 May 2020 16:55:22 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1589316922; bh=+8m3vc10Qg0hI015YiXGZ1fjI8Yos5B9045Ad97xzJg=; h=From:To:Cc:Subject:References:Date:In-Reply-To:From; b=PnZFUW/L1MhNeHTO65zWUhB87tYyWyd6KF/qhgpoPXBiqD+QY9NMKpRT0WepRYuzW SOQ2yB9ho/iOn8enSge3vW5srDrhmylK5RX3Lic8RKKJpb62lEcw0SlBcsB7FbOMrr YGV6qG+gZahYBOISMRSmdjR/dNKRckRVgV0HRnswlOaBCqxljBQIfftKUWe/TCi+vw JVrDRayTRHJpVbRwW/CNrLoLzHxmrjh5swaB5Fly++sjAKxCOn9XNs5X/BhyDkgH0r RSGgaoHNO8pApJMtXj82soOfiLmgSLUoWrZuXaCmh37KU6kZ6IHei+tIXcWVofMgw5 BJCMQxIQQAfXg== Original-Received: from alfajor (unknown [216.154.3.202]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id BB38A1208FA; Tue, 12 May 2020 16:55:21 -0400 (EDT) In-Reply-To: <1d616b0d-3e1b-5f72-da35-d0aa056322b4@yandex.ru> (Dmitry Gutov's message of "Tue, 12 May 2020 02:32:37 +0300") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:180118 Archived-At: Version: 28.1 > In theory, syntax-propertize-function implementations shouldn't change > buffer syntax the way that would affect the current syntax-ppss cache. > Or if they do, they should clear the cache accordingly. > Unfortunately, using syntax-ppss-flush-cache for that purpose doesn't > work: it makes Emacs infloop. I thought at first that the fix should go into `emacs-27`, but then you correctly pointed out that the docstring of `syntax-propertize-function` warned that `syntax-ppss-flush-cache` should not be called, so this bug is really a known and documented limitation. But indeed, it's a limitation that we should lift, so I installed the patch below into `master`. Stefan diff --git a/lisp/emacs-lisp/syntax.el b/lisp/emacs-lisp/syntax.el index 3294378754a..46dc8d9ade8 100644 --- a/lisp/emacs-lisp/syntax.el +++ b/lisp/emacs-lisp/syntax.el @@ -63,9 +63,10 @@ syntax-propertize-function cannot be handled just by the buffer's syntax-table. The specified function may call `syntax-ppss' on any position -before END, but it should not call `syntax-ppss-flush-cache', -which means that it should not call `syntax-ppss' on some -position and later modify the buffer on some earlier position.") +before END, but if it calls `syntax-ppss' on some +position and later modifies the buffer on some earlier position, +then it is its responsability to call `syntax-ppss-flush-cache' to flush +the now obsolete ppss info from the cache.") (defvar syntax-propertize-chunk-size 500) @@ -320,6 +321,11 @@ syntax-propertize-via-font-lock (defvar-local syntax-ppss-table nil "Syntax-table to use during `syntax-ppss', if any.") +(defvar-local syntax-propertize--inhibit-flush nil + "If non-nil, `syntax-ppss-flush-cache' only flushes the ppss cache. +Otherwise it flushes both the ppss cache and the properties +set by `syntax-propertize'") + (defun syntax-propertize (pos) "Ensure that syntax-table properties are set until POS (a buffer point)." (when (< syntax-propertize--done pos) @@ -375,8 +381,13 @@ syntax-propertize ;; (message "syntax-propertizing from %s to %s" start end) (remove-text-properties start end '(syntax-table nil syntax-multiline nil)) - ;; Avoid recursion! - (let ((syntax-propertize--done most-positive-fixnum)) + ;; Make sure we only let-bind it buffer-locally. + (make-local-variable 'syntax-propertize--inhibit-flush) + ;; Let-bind `syntax-propertize--done' to avoid infinite recursion! + (let ((syntax-propertize--done most-positive-fixnum) + ;; Let `syntax-propertize-function' call + ;; `syntax-ppss-flush-cache' without worries. + (syntax-propertize--inhibit-flush t)) (funcall syntax-propertize-function start end))))))))) ;;; Link syntax-propertize with syntax.c. @@ -455,7 +466,8 @@ 'syntax-ppss-after-change-function (defun syntax-ppss-flush-cache (beg &rest ignored) "Flush the cache of `syntax-ppss' starting at position BEG." ;; Set syntax-propertize to refontify anything past beg. - (setq syntax-propertize--done (min beg syntax-propertize--done)) + (unless syntax-propertize--inhibit-flush + (setq syntax-propertize--done (min beg syntax-propertize--done))) ;; Flush invalid cache entries. (dolist (cell (list syntax-ppss-wide syntax-ppss-narrow)) (pcase cell