From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Heime Newsgroups: gmane.emacs.help Subject: Re: Matching labels with buttons Date: Mon, 15 Jul 2024 23:02:36 +0000 Message-ID: References: <87ikx6g49y.fsf@rub.de> <72n913q3Tv6RlKwXsHxBXRlGEwuYia37iCUcLQg-7S8aHg_qVwE6JhXMRN3wk1IajDCeqvM7QD9yv5EM9yF75G8zwWyPb_VpQAqf_GqasdM=@protonmail.com> <87wmlmwdvo.fsf@gmx.net> <9zCSPBgOs4sWfvgWJ8YPTCCX0MCgtllMZ1mtZ4Y6CyxxfQA7fmwaTTfOYigIm0X6BHsBp--fmt7MHVReMf7A6vIsFR6zZh1Pf9rK1KT5eZY=@protonmail.com> <87sewawci1.fsf@gmx.net> <87o76yw9xw.fsf@gmx.net> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="19020"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Heime via Users list for the GNU Emacs text editor To: Stephen Berman Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Tue Jul 16 01:03:25 2024 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 1sTUj7-0004nd-0e for geh-help-gnu-emacs@m.gmane-mx.org; Tue, 16 Jul 2024 01:03:25 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sTUiY-0007oA-Bc; Mon, 15 Jul 2024 19:02:50 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sTUiW-0007nS-Kd for help-gnu-emacs@gnu.org; Mon, 15 Jul 2024 19:02:48 -0400 Original-Received: from mail-43166.protonmail.ch ([185.70.43.166]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sTUiR-0006YL-T0 for help-gnu-emacs@gnu.org; Mon, 15 Jul 2024 19:02:48 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1721084560; x=1721343760; bh=567+14286fxGO+HtgwOrQWdBjkufbhZG3AqOUY+9rdM=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector; b=N7diPpxrjBhtDx5/aRyMPIFivZ/AmERd1GNSMKGOUlezHGP/YcTrTq/xlJBFMOUoh lTXAygrUNMvLqTvP17huOiXdl/IgZTmfBcIDjVZ0GycOKEijUbmw1mWxmGA5oUsuUX c6lEG6rnIu65j3CQaHhEWeZCsYfaYDU06rT8/rmlxhqF8gulQW9rFoAtLxft5n5HLX RFz48dB2pkMRbtKXRVK9cfkUG/cIQuJLbjHC1MZUZVBhIu3IfhfW6dXKod8NOfx7QM GONFlq76SuJr8dCqcqzlXSF4+4h6j92PJ8ldDtp/1jwdbY3tbi4nI48jxdQjOumGGP RoEHyphWK+HDQ== In-Reply-To: <87o76yw9xw.fsf@gmx.net> Feedback-ID: 57735886:user:proton X-Pm-Message-ID: 3105af7a86dd6ebb6b9bbb8eccce8d51b2fe5c76 Received-SPF: pass client-ip=185.70.43.166; envelope-from=heimeborgia@protonmail.com; helo=mail-43166.protonmail.ch X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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, FREEMAIL_FROM=0.001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-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.29 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-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.help:147241 Archived-At: On Tuesday, July 16th, 2024 at 10:46 AM, Stephen Berman wrote: > On Mon, 15 Jul 2024 22:29:27 +0000 Heime heimeborgia@protonmail.com wrote= : >=20 > > On Tuesday, July 16th, 2024 at 9:50 AM, Stephen Berman > > stephen.berman@gmx.net wrote: > >=20 > > > On Mon, 15 Jul 2024 21:29:38 +0000 Heime heimeborgia@protonmail.com w= rote: > > >=20 > > > > On Tuesday, July 16th, 2024 at 9:20 AM, Stephen Berman > > > > stephen.berman@gmx.net wrote: > > > >=20 > > > > > On Mon, 15 Jul 2024 17:25:42 +0000 Heime heimeborgia@protonmail.c= om wrote: > > > > >=20 > > > > > > On Tuesday, July 16th, 2024 at 4:24 AM, Heime > > > > > > heimeborgia@protonmail.com wrote: > > >=20 > > > [...] > > >=20 > > > > > > > I also have to handle the case of " LABEL [-] " with a differ= ent regex, > > > > > > > so I can > > > > > > > distinguish between " [-] LABEL " and " LABEL [-] ". > > > > > >=20 > > > > > > In the latter case I want to match [-] at the end with any trai= ling spaces. > > > > >=20 > > > > > With your original code amended by anchoring the first regexp as = I > > > > > suggested, I think it handles both cases you want; at least the b= rief > > > > > tests I tried worked. If you don't get the results you want, plea= se > > > > > show the complete code you're using and examples where it fails. > > > > >=20 > > > > > Steve Berman > > > >=20 > > > > Have used > > > >=20 > > > > "\\`\\(\\s-\\[\\-\\]\\s-\\)\\(.*\\)" for " [-] LABEL " > > > >=20 > > > > and > > > >=20 > > > > "\\(.\\)\\(\\s-\\[\\-\\]\\s-*\\)\\'" for " LABEL [-] " > > >=20 > > > Since you didn't do what I requested, I've done it. Evaluate the > > > following code, which is based on your original code amended as I > > > suggested (I didn't use "\\'" in the second regexp, but the results a= re > > > the same with and without it): > >=20 > > Was that about showing the code ? It is basically writing down the rege= x strings. >=20 >=20 > I asked for the complete code, so I don't have to guess what you're doing= . >=20 > > > (defun heime-button (label) > > > (if (string-match "\\`\\(\\s-\\[\\-\\]\\s-\\)\\(.\\)" label) ; [-] LB > > > (progn > > > (setq bt (match-string 1 label)) > > > (setq lb (match-string 2 label)) > > > (setq result > > > (concat bt (propertize lb 'face '(:foreground "red"))))) > > > (when (string-match "\\(.\\)\\(\\s-\\[\\-\\]\\s-\\)" label) ; LB [-] > > > (setq lb (match-string 1 label)) > > > (setq bt (match-string 2 label)) > > > (setq result > > > (concat (propertize lb 'face '(:foreground "red")) bt)))) > > > (insert result)) > > >=20 > > > (with-current-buffer (get-buffer-create "Heime Test") > > > (erase-buffer) > > > (heime-button " [-] LABEL ") > > > (newline) > > > (heime-button " LABEL [-] ")) > > >=20 > > > (switch-to-buffer "Heime Test") > > >=20 > > > What I see in buffer Heime Test is this: > > >=20 > > > [-] LABEL > > > LABEL [-] > > >=20 > > > where each string "LABEL" is red. Is this not what you want? > > >=20 > > > Steve Berman > >=20 > > Yes it is what I wanted. Having read the documentation, why don't you a= pply > > \\' for the second case to match the empty string, but only at the end = of string > > being matched against ? >=20 >=20 > As I wrote, for the examples you've given, the results are the same with > and without "\\'" at the end of the second regexp, so omitting it > simplifies the regexp. But if you want to avoid matching a string like > " LABEL [-] some other text", then you should include the end anchor "\\'= ". >=20 > Steve Berman Yes, I want to avoid matching " LABEL [-] some other text". =20