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.devel Subject: Re: Giving "text quotes" syntax in font-lock-syntax-table only Date: Wed, 03 Jun 2020 10:12:59 -0400 Message-ID: References: <50114.1589957638@localhost> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="16468"; 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: Ikumi Keita Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Wed Jun 03 16:13:41 2020 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 1jgU9F-0004CR-8F for ged-emacs-devel@m.gmane-mx.org; Wed, 03 Jun 2020 16:13:41 +0200 Original-Received: from localhost ([::1]:59602 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jgU9E-0000WY-AW for ged-emacs-devel@m.gmane-mx.org; Wed, 03 Jun 2020 10:13:40 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:58874) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jgU8i-0008WE-8E for emacs-devel@gnu.org; Wed, 03 Jun 2020 10:13:08 -0400 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:53024) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jgU8g-0000Jf-42 for emacs-devel@gnu.org; Wed, 03 Jun 2020 10:13:07 -0400 Original-Received: from pmg1.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id 6637E10032F; Wed, 3 Jun 2020 10:13:04 -0400 (EDT) Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id 9835E1002BA; Wed, 3 Jun 2020 10:13:02 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1591193582; bh=D0pGfy5g6hnN13iGdbfq/PhKzdspYNXdJKV7YCsDGLY=; h=From:To:Cc:Subject:References:Date:In-Reply-To:From; b=BYNC2FuFgcsptisYHvbQT0IAs26DDuMdpOyHhDDKcsGzup3J9VKx5rtavW5HLmTaF cqZuplxhzLkDNKJL5TB68TGN6+Djmn5XhxTvcdPHmapJQxbREBY4tuaKwY6CBNhh4S w5sRzuZhkPVdF9TwXNAjyK+hD5bDRHBJ6RfmlH6FzRZYC5v+SoexM7SmQtM/26YtKu 3pBoeSDBPKSk2QpCwh9mN4pdmpkXZxO9lNnoRPRfM8xpbCXVuF9sETVeLafN/nQgE5 /4E28oUM7x4Tb2VpLHE7YYqXK9Q1P3+G3uLjTaMQ40S5l9V+jUjNmkN3XJV+ekzu4G Xi+J1GiKyGI1w== Original-Received: from alfajor (76-10-137-254.dsl.teksavvy.com [76.10.137.254]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id AA6971206C3; Wed, 3 Jun 2020 10:13:01 -0400 (EDT) In-Reply-To: (Stefan Monnier's message of "Wed, 20 May 2020 07:53:27 -0400") Received-SPF: pass client-ip=132.204.25.50; envelope-from=monnier@iro.umontreal.ca; helo=mailscanner.iro.umontreal.ca X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/03 10:13:04 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] 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_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN 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:251807 Archived-At: >> We think that the problem comes from running `syntax-ppss'. > > Yes, the problem is that `syntax-ppss` is affected by the current > syntax-table yet it doesn't pay attention to syntax-table changes when > it comes to enforcing that its cache is not stale. > > The arguably better way to solve the problem is to not change the > syntax-table used inside `syntax-ppss` and `syntax-propertize`. This is > especially true for `syntax-propertize` if you use `syntax-ppss` in your > `syntax-propertize-function`. > > The best way to do that is to set `syntax-ppss-table` to the > syntax-table that should be used. While I think the new approach using `font-lock-keywords` instead of `font-lock-syntax-table` is a better solution, I think we should try and avoid this breakage. Could you test the patch below to see if it makes the old code work correctly? Stefan diff --git a/lisp/font-lock.el b/lisp/font-lock.el index e0955b74abc..f4ac00d14bd 100644 --- a/lisp/font-lock.el +++ b/lisp/font-lock.el @@ -575,6 +575,7 @@ font-lock-syntax-table "Non-nil means use this syntax table for fontifying. If this is nil, the major mode's syntax table is used. This is normally set via `font-lock-defaults'.") +(defvar-local font-lock--syntax-table-affects-ppss nil) (defvar font-lock-mark-block-function nil "Non-nil means use this function to mark a block of text. @@ -1610,7 +1611,15 @@ font-lock-fontify-syntactically-region (regexp-quote (replace-regexp-in-string "^ *" "" comment-end)))) ;; Find the `start' state. - (state (syntax-ppss start)) + (state (if (or syntax-ppss-table + (not font-lock--syntax-table-affects-ppss)) + (syntax-ppss start) + ;; If `syntax-ppss' doesn't have its own syntax-table and + ;; we have installed out own syntax-table which + ;; differs from the standard one in ways which affects PPSS, + ;; then we can't use `syntax-ppss' since that would pollute + ;; and be polluted by its cache. + (parse-partial-sexp (point-min) start))) face beg) (if loudly (message "Fontifying %s... (syntactically...)" (buffer-name))) ;; @@ -1907,6 +1916,7 @@ font-lock-set-defaults ;; Case fold during regexp fontification? (setq-local font-lock-keywords-case-fold-search (nth 2 defaults)) ;; Syntax table for regexp and syntactic fontification? + (kill-local-variable 'font-lock--syntax-table-affects-ppss) (if (null (nth 3 defaults)) (setq-local font-lock-syntax-table nil) (setq-local font-lock-syntax-table (copy-syntax-table (syntax-table))) @@ -1916,7 +1926,14 @@ font-lock-set-defaults (dolist (char (if (numberp (car selem)) (list (car selem)) (mapcar #'identity (car selem)))) - (modify-syntax-entry char syntax font-lock-syntax-table))))) + (unless (memq (car (aref font-lock-syntax-table char)) + '(1 2 3)) ;"." "w" "_" + (setq font-lock--syntax-table-affects-ppss t)) + (modify-syntax-entry char syntax font-lock-syntax-table) + (unless (memq (car (aref font-lock-syntax-table char)) + '(1 2 3)) ;"." "w" "_" + (setq font-lock--syntax-table-affects-ppss t)) + )))) ;; (nth 4 defaults) used to hold `font-lock-beginning-of-syntax-function', ;; but that was removed in 25.1, so if it's a cons cell, we assume that ;; it's part of the variable alist.