From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Vitalie Spinu Newsgroups: gmane.emacs.devel Subject: Re: Syntax-ppss flush should happen in after-change hook Date: Sat, 16 Mar 2019 18:35:09 +0100 Message-ID: <87lg1e4t9u.fsf@gmail.com> References: <87sgvm50dk.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="267903"; 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: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat Mar 16 18:35:29 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 1h5DDS-0017V6-2R for ged-emacs-devel@m.gmane.org; Sat, 16 Mar 2019 18:35:26 +0100 Original-Received: from localhost ([127.0.0.1]:44474 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h5DDQ-0002KG-V4 for ged-emacs-devel@m.gmane.org; Sat, 16 Mar 2019 13:35:24 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:42646) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h5DDG-0002IL-6F for emacs-devel@gnu.org; Sat, 16 Mar 2019 13:35:14 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h5DDF-0004RC-8j for emacs-devel@gnu.org; Sat, 16 Mar 2019 13:35:14 -0400 Original-Received: from mail-ed1-x52a.google.com ([2a00:1450:4864:20::52a]:42535) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h5DDE-0004QO-Sj for emacs-devel@gnu.org; Sat, 16 Mar 2019 13:35:13 -0400 Original-Received: by mail-ed1-x52a.google.com with SMTP id j89so10192525edb.9 for ; Sat, 16 Mar 2019 10:35:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=D0UwhITqYzRmOGVpjXmVzxQ6b+uo8oYTPwVOBS+yyp0=; b=G/w97bMMCTReI1V0jlXyIpUdQwshcAJagPMto7F1GTXU2tPK5IUjZmE119WdZt304a hSaA1bhoram9fJqLMYPGT762xxluIB/lI9f4AGI26LPqRvbWenlt80IZz/KOruC4bSb6 RrGzZDvT29kwAmUoGNmIoqBA3MMRSb4MHOK1XLcKG8Ta5S/TXeXEs64vx7QyHBdCByQW WVPwXkVLI1n2/7HXiF/4cNWIlzsnevQBN7/w+0o6rKyZurPV1B9oyIp03z0E/7XZEIQb jLS8yyvaCQj53q8XH66Q4smWojZ207/tMpswTm8xf/eHQUs/TsQvCDI3sHWJM3YJMEtn cOiw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version; bh=D0UwhITqYzRmOGVpjXmVzxQ6b+uo8oYTPwVOBS+yyp0=; b=avRRNRUjEvWsxOfMv3HAqeHEAcg7MH5d676CD9NMNW/s95GTXXC/V9l1yFy4bI77of Tx+MT509XhNESA+ABcpYZC9+vJ5WdLtSI1hdbEsLF/N2HXyXe3qxhnI0mvGNUWnaTyWX jqSaDOT4HJQ70K5T88BPHBrWd+0iZWv2ruhSmplj5bBYiEl+BJ9CvaQRIvXYjBH10pAu jqd/6k4AS7/E4+kSxyt3ody+o6sAImMI15MPZLPMk6xfAE89uqCRav2U8OkNagomBZF4 jczL757zwt1ATLKw/I9pJST7uL6VJILSIblNSGFS6LE6++bHEN5IsDbM2taQ3d689BKo D5FA== X-Gm-Message-State: APjAAAWPJkhD2v8aTVHLEtMSMATVeNhCrCZk8GQwcX7x4Q7wPPQBxMXK 69fDFgWElXW2R0R3vSsEJkk= X-Google-Smtp-Source: APXvYqw6rukIGurb9a6A7pc5Ixy60VhikDzh17EHY/hU0fGtx44WAoN5lPpVkTvVxgYcV4+jLrE7HA== X-Received: by 2002:a50:b1d8:: with SMTP id n24mr6815514edd.137.1552757711147; Sat, 16 Mar 2019 10:35:11 -0700 (PDT) Original-Received: from localhost ([2001:1c00:a17:1300:21d3:c436:f892:a1b8]) by smtp.gmail.com with ESMTPSA id a1sm1705347edr.47.2019.03.16.10.35.09 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 16 Mar 2019 10:35:10 -0700 (PDT) In-Reply-To: (Stefan Monnier's message of "Sat, 16 Mar 2019 11:53:53 -0400") X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::52a 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:234233 Archived-At: >> On Sat, Mar 16 2019 11:53, Stefan Monnier wrote: >> Currently ppss flush happens in before-change hook. This leads to a real >> possibility that syntax-propertize is called before the actual change and not >> refreshed after the change. This could occur in at least two scenarios. >> >> First, when a hook placed after syntax-ppss-flush-cache in >> before-change-functions invokes `syntax-propertize` (for example with a >> search). > If syntax-ppss-flush-cache is on after-change-functions then the risk is > when a hook function is placed before it. So it's inconsistent state for the hooks vs inconsistent state for all the emacs functions after the change. > Given the fact that add-hook defaults to placing functions at the head and > that after-change-functions are much more commonly used than > before-change-functions 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)) > 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. Combine-change-calls happened in my example, but currently any buffer change results in inconsistent syntax state. 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 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. Vitalie