From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: Tassilo Horn Newsgroups: gmane.emacs.help Subject: Re: Migrating from font-lock-syntactic-keywords to syntax-propertize-function Date: Thu, 14 May 2020 11:56:31 +0200 Message-ID: <87eermrga8.fsf@gnu.org> References: <87sgg51msg.fsf@gnu.org> <87y2pwpzm8.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="115552"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: help-gnu-emacs@gnu.org To: Dmitry Gutov , Stefan Monnier Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Thu May 14 11:57:06 2020 Return-path: Envelope-to: geh-help-gnu-emacs@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 1jZAby-000TxB-HJ for geh-help-gnu-emacs@m.gmane-mx.org; Thu, 14 May 2020 11:57:06 +0200 Original-Received: from localhost ([::1]:34882 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jZAbx-0006tj-KB for geh-help-gnu-emacs@m.gmane-mx.org; Thu, 14 May 2020 05:57:05 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:33446) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jZAbU-0006dn-Fs for help-gnu-emacs@gnu.org; Thu, 14 May 2020 05:56:36 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]:57510) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jZAbT-0002vt-J6; Thu, 14 May 2020 05:56:35 -0400 Original-Received: from auth1-smtp.messagingengine.com ([66.111.4.227]:41515) by fencepost.gnu.org with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.82) (envelope-from ) id 1jZAbS-0005sb-Qo; Thu, 14 May 2020 05:56:35 -0400 Original-Received: from compute7.internal (compute7.nyi.internal [10.202.2.47]) by mailauth.nyi.internal (Postfix) with ESMTP id 53A3227C0054; Thu, 14 May 2020 05:56:34 -0400 (EDT) Original-Received: from mailfrontend1 ([10.202.2.162]) by compute7.internal (MEProxy); Thu, 14 May 2020 05:56:34 -0400 X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduhedrleeigddulecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefhvffufhffjgfkfgggtgesthdtredttdertdenucfhrhhomhepvfgrshhsihhl ohcujfhorhhnuceothhsughhsehgnhhurdhorhhgqeenucggtffrrghtthgvrhhnpeelhf duuedvvdduteetgedtffehuedutdejtefhjeetgeethffftdffgfduveekffenucffohhm rghinhepghhnuhdrohhrghenucfkphepleefrddvfeeirddufeekrddvtdenucevlhhush htvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehthhhorhhnodhmvghs mhhtphgruhhthhhpvghrshhonhgrlhhithihqdekieejfeekjeekgedqieefhedvleekqd htshguhheppehgnhhurdhorhhgsehfrghsthhmrghilhdrfhhm X-ME-Proxy: Original-Received: from thinkpad-t440p (p5dec8a14.dip0.t-ipconnect.de [93.236.138.20]) by mail.messagingengine.com (Postfix) with ESMTPA id 67B413280063; Thu, 14 May 2020 05:56:33 -0400 (EDT) In-Reply-To: <87y2pwpzm8.fsf@gnu.org> (Tassilo Horn's message of "Wed, 13 May 2020 00:17:19 +0200") X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.io gmane.emacs.help:123092 Archived-At: Tassilo Horn writes: > thank you both, I think I somehow made it. > > http://git.savannah.gnu.org/cgit/auctex.git/commit/?h=font-latex-update&id=e6076a4f8cf2f06e956ad1a60728ca3b2eb11a83 That was a bit too quick. It didn't work because we have a lot of matchers with back-references in order to set syntax properties for things like \verb|(setq foo t)| where the delimiter (here |) may be any character, e.g., \verb/(setq foo t)/, \verb-(setq foo t)- would also be ok. So for now I this `syntax-propertize-function': --8<---------------cut here---------------start------------->8--- (defun font-latex-syntax-propertize-function (start end) "The `syntax-propertize-function' for (La)TeX documents." (with-no-warnings (let ((font-lock-syntactic-keywords (if (derived-mode-p 'doctex-mode) font-latex-doctex-syntactic-keywords font-latex-syntactic-keywords))) (font-lock-fontify-syntactic-keywords-region start end)))) --8<---------------cut here---------------end--------------->8--- That works good but of course is still the obsolete mechanism, right? However, I don't feel like implementing the search and syntax-property setting myself would have a better outcome. Why does `syntax-propertize-rules' not support back-references? It already tracks which regexp group is what, so it could also renumber back-references, no? Natively hacking away, it seems like this would do the trick: --8<---------------cut here---------------start------------->8--- modified lisp/emacs-lisp/syntax.el @@ -140,13 +140,15 @@ syntax-propertize-multiline (cons beg end)) (defun syntax-propertize--shift-groups (re n) - (replace-regexp-in-string - "\\\\(\\?\\([0-9]+\\):" - (lambda (s) - (replace-match - (number-to-string (+ n (string-to-number (match-string 1 s)))) - t t s 1)) - re t t)) + (let ((incr (lambda (s) + (replace-match + (number-to-string + (+ n (string-to-number (match-string 1 s)))) + t t s 1)))) + (replace-regexp-in-string + "[^\\]\\\\\\([0-9]+\\)" incr + (replace-regexp-in-string "\\\\(\\?\\([0-9]+\\):" incr re t t) + t t))) (defmacro syntax-propertize-precompile-rules (&rest rules) "Return a precompiled form of RULES to pass to `syntax-propertize-rules'. --8<---------------cut here---------------end--------------->8--- Judging from the result of --8<---------------cut here---------------start------------->8--- (syntax-propertize-rules ("\\(one\\)\\(two\\)\\(\\1\\)" (1 "|") (2 ".")) ("\\(three\\)\\(four\\)\\(\\1\\)" (1 "|") (2 "."))) --8<---------------cut here---------------end--------------->8--- I'd say it works (in this simple case). Bye, Tassilo