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.help Subject: Re: Migrating from font-lock-syntactic-keywords to syntax-propertize-function Date: Tue, 12 May 2020 10:49:11 -0400 Message-ID: References: <87sgg51msg.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="83322"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) To: help-gnu-emacs@gnu.org Cancel-Lock: sha1:SxdyKSbDQRNSfeo8HKsXT2Sjl/E= Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Tue May 12 16:49:52 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 1jYWEB-000LXd-1L for geh-help-gnu-emacs@m.gmane-mx.org; Tue, 12 May 2020 16:49:51 +0200 Original-Received: from localhost ([::1]:41536 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jYWEA-0001XH-2n for geh-help-gnu-emacs@m.gmane-mx.org; Tue, 12 May 2020 10:49:50 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:59048) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jYWDg-0001WY-Kz for help-gnu-emacs@gnu.org; Tue, 12 May 2020 10:49:20 -0400 Original-Received: from ciao.gmane.io ([159.69.161.202]:46184) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jYWDf-0004ym-MG for help-gnu-emacs@gnu.org; Tue, 12 May 2020 10:49:20 -0400 Original-Received: from list by ciao.gmane.io with local (Exim 4.92) (envelope-from ) id 1jYWDc-000KyK-V1 for help-gnu-emacs@gnu.org; Tue, 12 May 2020 16:49:16 +0200 X-Injected-Via-Gmane: http://gmane.org/ Received-SPF: pass client-ip=159.69.161.202; envelope-from=geh-help-gnu-emacs@m.gmane-mx.org; helo=ciao.gmane.io X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/12 10:49:17 X-ACL-Warn: Detected OS = Linux 3.11 and newer [fuzzy] X-Spam_score_int: -16 X-Spam_score: -1.7 X-Spam_bar: - X-Spam_report: (-1.7 / 5.0 requ) BAYES_00=-1.9, HEADER_FROM_DIFFERENT_DOMAINS=0.249, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action 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:123079 Archived-At: > (defun my-make-syntax-propertize-function () > (syntax-propertize-rules > ;; My rules here. > )) Note that this is a "constant function". It macroexpands to (defun my-make-syntax-propertize-function () (lambda (..) ...)) > 1. With `font-lock-syntactic-keywords', a MATCH-HIGHLIGHT could have the > form (SUBEXP SYNTAX OVERRIDE LAXMATCH) but with > `syntax-propertize-rules' only (NUMBER SYNTAX) is allowed where > SUBEXP and NUMBER have the same meaning. So how does one convert > entries which use OVERRIDE and/or LAXMATCH to the new mechanism? (I > don't use LAXMATCH, so that's not too important.) font-lock-syntactic-keywords was applied by scanning the whole region to apply the first rule, then scanning the whole region again to apply the second rules, etc... So OVERRIDE was needed to decide what to do when two rules match on the same chunk of text. syntax-propertize-rules applies all the rules in a single scan, so only one rule can match at a given spot, and hence OVERRIDE is not useful. (as for LAXMATCH, the rules behave the same way as if LAXMATCH was always set). > 2. Some of my syntax rules are not static, so I cannot provide a fixed > set of rules to `syntax-propertize-rules'. Is there anything better > than using `eval' like > > (defun my-make-syntax-propertize-function () > (eval > `(syntax-propertize-rules > ,@(mapcar > #'my-convert-legacy-syntactic-keywords > (my-compute-syntactic-keywords))))) If your regexps are not static, then indeed you need to resort to `eval`. This is done in `fortran-make-syntax-propertize-function`, if you want to see an example. > or should I prefer writing a manual `syntax-propertize-function'? It's up to you. Of course, another option is `syntax-propertize-via-font-lock`, which I'd not recommend, but if you're just looking for a quick-fix... Stefan