From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: haj@posteo.de (Harald =?utf-8?Q?J=C3=B6rg?=) Newsgroups: gmane.emacs.help Subject: Re: Font lock question Date: Wed, 17 Mar 2021 17:31:35 +0100 Message-ID: <877dm5lp20.fsf@hajtower> References: <87a6r29hkl.fsf@fastmail.fm> <87r1kdx1ge.fsf@fastmail.fm> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="18680"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) Cc: help-gnu-emacs@gnu.org To: Joost Kremers Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Wed Mar 17 17:44:15 2021 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 1lMZHL-0004lm-S9 for geh-help-gnu-emacs@m.gmane-mx.org; Wed, 17 Mar 2021 17:44:15 +0100 Original-Received: from localhost ([::1]:52236 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lMZHK-0001Dx-Sg for geh-help-gnu-emacs@m.gmane-mx.org; Wed, 17 Mar 2021 12:44:14 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:35718) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lMZ5R-0007tA-BS for help-gnu-emacs@gnu.org; Wed, 17 Mar 2021 12:32:07 -0400 Original-Received: from mout01.posteo.de ([185.67.36.65]:60663) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lMZ5H-00045U-5j for help-gnu-emacs@gnu.org; Wed, 17 Mar 2021 12:31:57 -0400 Original-Received: from submission (posteo.de [89.146.220.130]) by mout01.posteo.de (Postfix) with ESMTPS id 189FC160064 for ; Wed, 17 Mar 2021 17:31:39 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.de; s=2017; t=1615998700; bh=qZ8M2dc39uI/6LDTLsSu5aR7wgbqlY3v61/7iZ8OQCk=; h=From:To:Cc:Subject:Date:From; b=m0eSkBRr2bq9mn/8WxgdsOkWz1v/xuIyx7rzRAlKMBIuP8Sus/TyXh6aL/gM9b3qw wLork+3MnL9VOu2fVDMXe8CrZbPptVyUSjr/AcQFyHTuopyAu82rmmmqEnRtNl2DHb L6DCRn4JxZbzSi1rlr/Z8kl9Vwv++LQ2N4sPKAfTfhYfUs5zaQ7czj4OOM+cw9xnNF +lsKoZ4ysP76XEm/XZzhbcMVX4H8c5IE9Ah0Vdz9fTj9Z/XJA73kprTuYuo2VbtOJt L6VIDVX9rrfRLg4aktjHORTT5SvGrRT3aUtrw5B2b+7Pw9ZiAKXo/xwk+vPJtVHJ5b ETodTdLTlaAmA== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4F0wdz5bMwz9rxY; Wed, 17 Mar 2021 17:31:35 +0100 (CET) In-Reply-To: <87r1kdx1ge.fsf@fastmail.fm> (Joost Kremers's message of "Wed, 17 Mar 2021 14:46:06 +0100") Received-SPF: pass client-ip=185.67.36.65; envelope-from=haj@posteo.de; helo=mout01.posteo.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no 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:128433 Archived-At: Joost Kremers writes: > On Wed, Mar 17 2021, Stefan Monnier wrote: >> [...] >> Can you clarify what you mean by "doe snot work"? > > Of course. :-) What I mean is that in my test case, e.g., with the following > text in the buffer: > > [aBc; aBc; aBc] > > only the final `aBc` has the right font-lock faces applied to it. The first two > occurrences of `aBc` have no special face. > > I'm testing with the following: > > ``` > (font-lock-add-keywords nil > '(("\\[\\(?:\\(?1:[[:alnum:]]*?\\)\\(?2:B\\)\\(?3:[[:alnum:]]*?\\)[;[:blank:]]*?\\)+\\]" > (1 font-lock-warning-face) > (2 font-lock-keyword-face) > (3 font-lock-warning-face)))) > ``` I had a similar case recently, and also failed to solve it with one regular expression: After all, the match (including the closing "]") succeeds only once, so there's no more than one capture group for 1, 2, and 3 each. My solution was to to combine a rule for [aBc] with a rule of type (MATCHER . ANCHORED-HIGHLIGHTER): The anchor is the opening "[" and the first "aBc", and the anchored matcher matches a semicolon and, as a group, another "aBc". I just saw that Stefan said this would work, so I'll give it a try: ``` (font-lock-add-keywords nil '(("\\[\\(?1:[[:alnum:]]*?\\)\\(?2:B\\)\\(?3:[[:alnum:]]*\\)[];[[:blank:]]*?" (1 font-lock-warning-face) (2 font-lock-keyword-face) (3 font-lock-warning-face)) ("[[:alnum:]]*B[[:alnum:]]*" (";[[:blank:]]*\\(?1:[[:alnum:]]*\\)\\(?2:B\\)\\(?3:[[:alnum:]]*\\)" nil nil (1 font-lock-warning-face) (2 font-lock-keyword-face) (3 font-lock-warning-face))))) ``` -- Cheers, haj