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: Wed, 20 May 2020 22:24:11 +0900 Message-ID: <55185.1589981051@localhost> References: <50114.1589957638@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="17180"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel@gnu.org To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Wed May 20 15:29:57 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 1jbOnE-0004HN-5w for ged-emacs-devel@m.gmane-mx.org; Wed, 20 May 2020 15:29:56 +0200 Original-Received: from localhost ([::1]:43160 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jbOnD-00055g-6m for ged-emacs-devel@m.gmane-mx.org; Wed, 20 May 2020 09:29:55 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:48250) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jbOho-0001me-Ud for emacs-devel@gnu.org; Wed, 20 May 2020 09:24:20 -0400 Original-Received: from smtp1a.inetd.co.jp ([210.129.88.11]:40614) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jbOhm-0000u3-PR for emacs-devel@gnu.org; Wed, 20 May 2020 09:24:20 -0400 Original-Received: from localhost (125-14-252-253.rev.home.ne.jp [125.14.252.253]) by smtp1a.inetd.co.jp (Postfix) with ESMTPA id 1E4CD62; Wed, 20 May 2020 22:24:13 +0900 (JST) In-reply-to: Comments: In-reply-to Stefan Monnier message dated "Wed, 20 May 2020 07:53:27 -0400." X-Mailer: MH-E 8.6+git; nmh 1.7.1; GNU Emacs 26.3 Content-ID: <55184.1589981051.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/20 09:24:13 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:251038 Archived-At: Hi! >>>>> Stefan Monnier writes: > The best way to do that is to set `syntax-ppss-table` to the > syntax-table that should be used. I suppose that you are suggesting that something like this: ---------------------------------------------------------------------- (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)) (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 syntax-ppss-table (let ((st (make-syntax-table bug-repro-mode-syntax-table))) (modify-syntax-entry ?$ "\"" st) st)) (setq font-lock-defaults '(nil nil nil nil ; ((?$ . "\"")) (font-lock-syntactic-face-function . bug-repro-syntactic-face-function)))) ---------------------------------------------------------------------- This resembles the method to modify the major mode's syntax table (without setting `syntax-ppss-table'). It does eliminate the wrong fontification, but brings another problem in actual use cases of AUCTeX. When `syntax-ppss-table' is non-nil, all functions using `syntax-ppss' obey that syntax table, so they regard math expression $...$ as string constant. This can be problematic for cases like this: ---------------------------------------------------------------------- \documentclass{article} \begin{document} $x^{2}+y^{2} % syntax-ppss wouldn't regard me as a comment. =z^{2}$ \end{document} ---------------------------------------------------------------------- In other words, what we want to carry out is: - to use modified syntax table only within font lock - while keeping to use major mode's syntax table for all other purposes. 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. I can think of no way to achieve our intention in the current framework of syntax.el and font lock. I'm speaking without knowing the detail of syntax.el, so please correct me if I understand something wrongly. Regards, Ikumi Keita