From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stephen Berman Newsgroups: gmane.emacs.help Subject: Re: Matching labels with buttons Date: Tue, 16 Jul 2024 00:46:03 +0200 Message-ID: <87o76yw9xw.fsf@gmx.net> References: <87msmig6lz.fsf@rub.de> <87ikx6g49y.fsf@rub.de> <72n913q3Tv6RlKwXsHxBXRlGEwuYia37iCUcLQg-7S8aHg_qVwE6JhXMRN3wk1IajDCeqvM7QD9yv5EM9yF75G8zwWyPb_VpQAqf_GqasdM=@protonmail.com> <87wmlmwdvo.fsf@gmx.net> <9zCSPBgOs4sWfvgWJ8YPTCCX0MCgtllMZ1mtZ4Y6CyxxfQA7fmwaTTfOYigIm0X6BHsBp--fmt7MHVReMf7A6vIsFR6zZh1Pf9rK1KT5eZY=@protonmail.com> <87sewawci1.fsf@gmx.net> Mime-Version: 1.0 Content-Type: text/plain Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="14784"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: Heime via Users list for the GNU Emacs text editor To: Heime Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Tue Jul 16 00:46:27 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 1sTUSh-0003de-Au for geh-help-gnu-emacs@m.gmane-mx.org; Tue, 16 Jul 2024 00:46:27 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sTUSS-0005ne-SY; Mon, 15 Jul 2024 18:46:12 -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 1sTUSR-0005nT-69 for help-gnu-emacs@gnu.org; Mon, 15 Jul 2024 18:46:11 -0400 Original-Received: from mout.gmx.net ([212.227.15.19]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sTUSN-0003po-GC for help-gnu-emacs@gnu.org; Mon, 15 Jul 2024 18:46:10 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmx.net; s=s31663417; t=1721083564; x=1721688364; i=stephen.berman@gmx.net; bh=fXyCHudjQrgoSzUy+F1ctomj6Z9dxjwZ0mD35SFY6xY=; h=X-UI-Sender-Class:From:To:Cc:Subject:In-Reply-To:References:Date: Message-ID:MIME-Version:Content-Type:Content-Transfer-Encoding:cc: content-transfer-encoding:content-type:date:from:message-id: mime-version:reply-to:subject:to; b=YlniAa5IkRwEiNwLS2cbLOTLpSFM+VEQlgDDHBzH4w9V7c6/HHnc7lGlTP3THsA3 r5LrPNksuSs5cHxz1fVWczlK5LqdvcutK7Tq+NQjwzMjR33gM0+Vhd/1cw3n66egh eTE8oY9WcSjT+sP4q5Rf4IM8rfNj0dEEIBhEQJBRQbMIWm/yl7B9Kd1H/XC6K8Yfq rie48Iezz2FND1ninmZm60P/j9ADbVGBNBUNziC5LxceOvB7Za6NWzDtMFKrJUJkV qeTIKv4fp7CCqAyhddgpj7KqIGElVn9zTEUy3dX3mxBNcjItvXHNZ2UgIYJ01GJOT UKZGGZSKoNl10ManFQ== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Original-Received: from strobelfs ([88.130.50.244]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MGhyS-1sYQ8M1gVG-00CTnG; Tue, 16 Jul 2024 00:46:04 +0200 In-Reply-To: (Heime's message of "Mon, 15 Jul 2024 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7V8WR19MlAw6UjUtePiuzakICuOuQlXiB7X1GJm+eNmWZE Received-SPF: pass client-ip=212.227.15.19; envelope-from=stephen.berman@gmx.net; helo=mout.gmx.net X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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_DNSWL_LOW=-0.7, 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.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:147240 Archived-At: On Mon, 15 Jul 2024 22:29:27 +0000 Heime wrot= e: > On Tuesday, July 16th, 2024 at 9:50 AM, Stephen Berman > wrote: > >> On Mon, 15 Jul 2024 21:29:38 +0000 Heime heimeborgia@protonmail.com wro= te: >> >> > On Tuesday, July 16th, 2024 at 9:20 AM, Stephen Berman >> > stephen.berman@gmx.net wrote: >> > >> > > On Mon, 15 Jul 2024 17:25:42 +0000 Heime heimeborgia@protonmail.com= wrote: >> > > >> > > > On Tuesday, July 16th, 2024 at 4:24 AM, Heime >> > > > heimeborgia@protonmail.com wrote: >> >> [...] >> >> > > > > I also have to handle the case of " LABEL [-] " with a differen= t regex, >> > > > > so I can >> > > > > distinguish between " [-] LABEL " and " LABEL [-] ". >> > > > >> > > > In the latter case I want to match [-] at the end with any traili= ng spaces. >> > > >> > > With your original code amended by anchoring the first regexp as I >> > > suggested, I think it handles both cases you want; at least the bri= ef >> > > tests I tried worked. If you don't get the results you want, please >> > > show the complete code you're using and examples where it fails. >> > > >> > > Steve Berman >> > >> > Have used >> > >> > "\\`\\(\\s-\\[\\-\\]\\s-\\)\\(.*\\)" for " [-] LABEL " >> > >> > and >> > >> > "\\(.\\)\\(\\s-\\[\\-\\]\\s-*\\)\\'" for " LABEL [-] " >> >> >> 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 are >> the same with and without it): > > Was that about showing the code ? It is basically writing down the rege= x strings. I asked for the complete code, so I don't have to guess what you're doing. >> (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)) >> >> (with-current-buffer (get-buffer-create "Heime Test") >> (erase-buffer) >> (heime-button " [-] LABEL ") >> (newline) >> (heime-button " LABEL [-] ")) >> >> (switch-to-buffer "Heime Test") >> >> What I see in buffer Heime Test is this: >> >> [-] LABEL >> LABEL [-] >> >> where each string "LABEL" is red. Is this not what you want? >> >> Steve Berman > > 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 o= f string > being matched against ? 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 "\\'"= . Steve Berman