From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: Syntax-ppss flush should happen in after-change hook Date: Sat, 16 Mar 2019 14:09:37 -0400 Message-ID: References: <87sgvm50dk.fsf@gmail.com> <87lg1e4t9u.fsf@gmail.com> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="167092"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) Cc: emacs-devel@gnu.org To: Vitalie Spinu Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat Mar 16 19:17:52 2019 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1h5DsW-000hNU-5c for ged-emacs-devel@m.gmane.org; Sat, 16 Mar 2019 19:17:52 +0100 Original-Received: from localhost ([127.0.0.1]:44819 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h5DsV-0002FO-4V for ged-emacs-devel@m.gmane.org; Sat, 16 Mar 2019 14:17:51 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:46823) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h5Dr4-0001T6-FJ for emacs-devel@gnu.org; Sat, 16 Mar 2019 14:16:23 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h5Dkd-0003r5-Cg for emacs-devel@gnu.org; Sat, 16 Mar 2019 14:09:44 -0400 Original-Received: from chene.dit.umontreal.ca ([132.204.246.20]:37337) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h5Dkd-0003q7-2q for emacs-devel@gnu.org; Sat, 16 Mar 2019 14:09:43 -0400 Original-Received: from pastel.home (lechon.iro.umontreal.ca [132.204.27.242]) by chene.dit.umontreal.ca (8.14.7/8.14.1) with ESMTP id x2GI9c3t010027; Sat, 16 Mar 2019 14:09:38 -0400 Original-Received: by pastel.home (Postfix, from userid 20848) id D6B0A6AB8D; Sat, 16 Mar 2019 14:09:37 -0400 (EDT) In-Reply-To: <87lg1e4t9u.fsf@gmail.com> (Vitalie Spinu's message of "Sat, 16 Mar 2019 18:35:09 +0100") X-NAI-Spam-Flag: NO X-NAI-Spam-Threshold: 5 X-NAI-Spam-Score: 0 X-NAI-Spam-Rules: 2 Rules triggered EDT_SA_DN_PASS=0, RV6504=0 X-NAI-Spam-Version: 2.3.0.9418 : core <6504> : inlines <7035> : streams <1815893> : uri <2814056> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 132.204.246.20 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 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.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:234235 Archived-At: > One simple solution is to add a sentinel to the before-change-functions to > explicitly check for syntax-ppss-flush-chache being the first hook: > > (unless (eq (car after-change-functions) 'syntax-ppss-flush-cache) > (delq 'syntax-ppss-flush-cache after-change-functions) > (add-hook 'after-change-functions 'syntax-ppss-flush-cache nil t)) That would require using both b-f-c and a-f-c. I'd much rather "do it right" and change add-hook to understand a notion of depth/priority/order. >> A crude solution could be the ad-hoc hack below. We could make it less >> ad-hoc by adding a way for any hook function (on b-c-f and a-c-f) to >> indicate whether it should stay active within combine-change-calls, >> e.g. with a symbol property `do-not-combine-change-function`. > > AFAICS this will not help with the main part of the problem (second > scenario in OP). The problem is not that some inconsistent state > happens during the combine-change-calls but that after the change ppss > is left in inconsistent state. I believe it does help the problem at hand: the final state of the cache will be correct (and the state of the cache is correct during the combine-change-calls as well). > Combine-change-calls happened in my example, but currently any buffer > change results in inconsistent syntax state. Then I must have misunderstood something. Can you give more details about the problem scenario you have in mind? > As far as I understand, just before the actual change the cache is in > consistent state, so currently, if the changing function requires > syntax properties then At the level of b-c-f and a-c-f the only "changing functions" are things like `insert` or `delete-region` and they should not trigger syntax-propertize or syntax-ppss (other than via b-c-f and a-c-f, obviously). It's only when you start using combine-change-calls (or combine-after-change-calls) that the code the performs the change between a-c-f and b-c-f can run arbitrarly fancy Elisp code. > before-change flush enforces extra syntax-propertize for nothing. In > my example that search need not have had triggered syntax-propertize > would the flush not have had happened. But the search is not done as part of the "change function", so (modulo combine-change-calls) it either done before b-c-f or after a-c-f, never between the two. Stefan