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: Mon, 15 Jul 2024 23:50:46 +0200 Message-ID: <87sewawci1.fsf@gmx.net> References: <87r0bug978.fsf@rub.de> <87msmig6lz.fsf@rub.de> <87ikx6g49y.fsf@rub.de> <72n913q3Tv6RlKwXsHxBXRlGEwuYia37iCUcLQg-7S8aHg_qVwE6JhXMRN3wk1IajDCeqvM7QD9yv5EM9yF75G8zwWyPb_VpQAqf_GqasdM=@protonmail.com> <87wmlmwdvo.fsf@gmx.net> <9zCSPBgOs4sWfvgWJ8YPTCCX0MCgtllMZ1mtZ4Y6CyxxfQA7fmwaTTfOYigIm0X6BHsBp--fmt7MHVReMf7A6vIsFR6zZh1Pf9rK1KT5eZY=@protonmail.com> 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="11114"; 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 Mon Jul 15 23:51:47 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 1sTTbn-0002ht-4c for geh-help-gnu-emacs@m.gmane-mx.org; Mon, 15 Jul 2024 23:51:47 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sTTaw-0005Sk-P7; Mon, 15 Jul 2024 17:50:54 -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 1sTTau-0005SZ-2c for help-gnu-emacs@gnu.org; Mon, 15 Jul 2024 17:50:52 -0400 Original-Received: from mout.gmx.net ([212.227.17.22]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sTTas-0002aM-6Y for help-gnu-emacs@gnu.org; Mon, 15 Jul 2024 17:50:51 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmx.net; s=s31663417; t=1721080247; x=1721685047; i=stephen.berman@gmx.net; bh=reX/vXhEjjG87Y0m7VpPZSbnC0HZJLPFSPLReGEqvWY=; 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=lg/8TlGsSDMw4JCFSbPAa62C7pQBJTny9VsaSWZ9wZuH+PhHZ2yK2CU/lOUxQemP ii1xyOReoHdtj9ORCyH5bnaoojyUaqPGK5q7HfHRMEJHC359ec+VWameRrD/Aa79k PB8V4cHHjAQsj19UFUnnT/NIM3rTMivqldeimCK5pge4At4+CD+EUPDzLZC5lf3BE 8rqB16EuC+BsyIzooCmnGluZltOzUtWQE6EsgnQix0ZutbmeolzMzi5kEjut9xq9N I3tnkFoDGP+Rbneo275C1SEOYZ8rLUF4age0ueiAV4pFJn6H26qnbg9T0Q0L5at5p yUdvWm6nQTXBNHm3eQ== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Original-Received: from strobelfs ([88.130.50.244]) by mail.gmx.net (mrgmx104 [212.227.17.168]) with ESMTPSA (Nemesis) id 1Mwwdf-1s9rJ61K6V-017knu; Mon, 15 Jul 2024 23:50:47 +0200 In-Reply-To: <9zCSPBgOs4sWfvgWJ8YPTCCX0MCgtllMZ1mtZ4Y6CyxxfQA7fmwaTTfOYigIm0X6BHsBp--fmt7MHVReMf7A6vIsFR6zZh1Pf9rK1KT5eZY=@protonmail.com> (Heime's message of "Mon, 15 Jul 2024 21:29:38 +0000") X-Provags-ID: V03:K1:O/Iwx4cbJmUuLtFz+rF0RwAyCDLM3Vu+FXy7oqvXlOVQmeFkZmm JGJ3hKT+3vNgKNnjDdQhoE2eVaqlmheTUvCoIgh7bcYBXadZyYgJGpCpZ9t3DGV0Az3Y0Gz ruQU5dJ1zhhx7aFtpD/CRsOffktcP59fY/tM+FTsZXi5VVz39bdyPuTXndaQgiD1eBUts65 O1e+LRs0g/O3xEXkxqVkw== UI-OutboundReport: notjunk:1;M01:P0:Uhn/yRyMIgc=;RiX6SBwY4OcRyevieDcIvWmLwq3 S8jV5KZMYwqgL60vayRJO0aMV1glyLsQIRH+0tC6gjKUH7EN5YCV2cxzkf1wdqufMltoEyT6x LVpIqC+JioVFQgicTSrD4KAN1UiBfNtWxFPBDg2z/PCZOvq4dq9CQPVRfqtKOWYQiooOruxKp z8mHRtJ79KwNxhlUUuHS67rs0DUYOJSuHiIdge8YU/Q+QXRTH7dw6IEcm0WCEUhj5MsHFUij3 I+7fmA9VvtjqnW58fzWYfM4kF6inzSYEzAmnOVWOQFP60k18Pk38kmaje+GmiT1lH86xwSieK LofH0qtJLMcjMSWu7F6F5d/4XuV3gXOqWn5dAVOuDDtfcdUl6aROx9WiV5+GnFzzyJin7nJwf 5IKagD+OgCw+rqL2o91UTaQIHqDqdrZfokz1U9GHFvCWFP+reSPqDLcARs8/Pj8ZpZGvSFfSE 017geqtzqd4QPAAB0pBCbsXvabBW3BU7UBatWbLoCdfXSdBPYYNlFruU6PurNX7AXhuect50C uz18C86+aL+Wi322Jb/qRJtSK0GydzqK/dtisIT6tbGUJ41lwxT317otcOUvb6I79fYWCMily cF8MqDeHwSgRjqdJTjfKLrofg+gIvBUX2twERhe3+4dpLNzUZS6+VBRb0MFXn1ks+6pjj6Pwz pQDD5fJDd0gWBr8F6/epenXEY3YHM/RFoL7lFAB+sxLa6Dy1vJXUDrZynSdQOYLB1qYPGlBcz H7VCmZdN/VbiJiGvcNz1f3363/2BYgp26a8Q4W1qTqGVX19z5fxRP5Tloyd3nDQjYmrn3LiJ Received-SPF: pass client-ip=212.227.17.22; 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, RCVD_IN_MSPIKE_H3=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.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:147234 Archived-At: On Mon, 15 Jul 2024 21:29:38 +0000 Heime wrot= e: > On Tuesday, July 16th, 2024 at 9:20 AM, Stephen Berman > wrote: > >> On Mon, 15 Jul 2024 17:25:42 +0000 Heime heimeborgia@protonmail.com wro= te: >> >> > 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 different re= gex, >> > > so I can >> > > distinguish between " [-] LABEL " and " LABEL [-] ". >> > >> > In the latter case I want to match [-] at the end with any trailing s= paces. >> >> >> With your original code amended by anchoring the first regexp as I >> suggested, I think it handles both cases you want; at least the brief >> 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): (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