From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: Ikumi Keita Newsgroups: gmane.emacs.devel Subject: Re: Giving "text quotes" syntax in font-lock-syntax-table only Date: Fri, 22 May 2020 17:37:34 +0900 Message-ID: <69586.1590136654@localhost> References: <50114.1589957638@localhost> <55185.1589981051@localhost> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="13072"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Stefan Monnier To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Fri May 22 10:38: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 1jc3CS-0003Ej-T2 for ged-emacs-devel@m.gmane-mx.org; Fri, 22 May 2020 10:38:40 +0200 Original-Received: from localhost ([::1]:54264 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jc3CR-0002ei-UV for ged-emacs-devel@m.gmane-mx.org; Fri, 22 May 2020 04:38:39 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:47932) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jc3C0-0002FL-1E for emacs-devel@gnu.org; Fri, 22 May 2020 04:38:12 -0400 Original-Received: from smtp1a.inetd.co.jp ([210.129.88.11]:46714) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jc3Bx-0003vZ-FD for emacs-devel@gnu.org; Fri, 22 May 2020 04:38:11 -0400 Original-Received: from localhost (42-146-134-146.rev.home.ne.jp [42.146.134.146]) by smtp1a.inetd.co.jp (Postfix) with ESMTPA id 805B32E; Fri, 22 May 2020 17:37:52 +0900 (JST) In-reply-to: <55185.1589981051@localhost> Comments: In-reply-to Ikumi Keita message dated "Wed, 20 May 2020 22:24:11 +0900." X-Mailer: MH-E 8.6+git; nmh 1.7.1; GNU Emacs 26.3 Content-ID: <69585.1590136654.1@localhost> Received-SPF: pass client-ip=210.129.88.11; envelope-from=ikumi@ikumi.que.jp; helo=smtp1a.inetd.co.jp X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/22 04:38:02 X-ACL-Warn: Detected OS = Linux 3.1-3.10 X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, 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:251202 Archived-At: Hi emacs developers, >>>>> Stefan Monnier writes: >> The best way to do that is to set `syntax-ppss-table` to the >> syntax-table that should be used. Thanks for your advice, but unfortunately I couldn't find a good solution yet. 1. As I wrote previously, another problem occurs if we set constant `syntax-ppss-table' in the major mode. 2. I actually tried the following implementation: >>>>> Ikumi Keita writes: > If we temporarily bind `syntax-ppss-table' during font lock by `let', > the problem of conflicting cache emerges again and it causes the > inverted fontification, if I understand correctly. ---------------------------------------------------------------------- (defvar bug-repro-mode-syntax-table (let ((st (make-syntax-table))) (modify-syntax-entry ?$ "$" st) (modify-syntax-entry ?% "<" st) (modify-syntax-entry ?\n ">" st) st)) (defvar bug-repro-syntax-ppss-table (let ((st (make-syntax-table bug-repro-mode-syntax-table))) (modify-syntax-entry ?$ "\"" st) st)) (defun bug-repro-syntactic-face-function (state) (let ((char (nth 3 state))) (if char font-lock-string-face font-lock-comment-face))) (define-derived-mode bug-repro-mode nil "BugRepro" :syntax-table bug-repro-mode-syntax-table (add-hook 'pre-command-hook #'syntax-ppss nil t) (setq font-lock-multiline t) (setq font-lock-defaults '(nil nil nil nil ; ((?$ . "\"")) (font-lock-syntactic-face-function . bug-repro-syntactic-face-function) (font-lock-fontify-region-function . bug-repro-fontify-region)))) (defun bug-repro-fontify-region (beg end loudly) (let ((syntax-ppss-table bug-repro-syntax-ppss-table)) (font-lock-default-fontify-region beg end loudly))) ---------------------------------------------------------------------- But the result was just what I anticipated. So may I ask the following questions again? (1) It doesn't work reliably to give "string quotes" syntax to $ in SYNTAX-ALIST. Is this an emacs bug or an intented restriction? (2) If not a bug, is it reasonable to ask to extend the font lock framework to allow syntactic fontification of $...$ form? E.g. [A] Implement some kind of "separate cache" in syntax-ppss and make it available from font lock. [B] Extend syntax parse state to include information about "the position is in-math state or not" and make `font-lock-fontify-syntactically-region' responsive to the in-math state in addition to in-comment and in-string states. This way, it would no longer be necessary to redefine syntax of $ in SYNTAX-ALIST and we can naturally implement syntactic fontification of $...$ via `font-lock-syntactic-face-function'. This approach would be beneficial for standard tex-mode.el, and potentially other program modes as well, if realized. (3) Or is there some smart way to achieve syntactic fontification of $...$ in the current font lock scheme? Best regards, Ikumi Keita