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 22:29:27 +0000 Message-ID: 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; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="12489"; 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 00:30:24 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 1sTUD7-00032Y-Ud for geh-help-gnu-emacs@m.gmane-mx.org; Tue, 16 Jul 2024 00:30:21 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sTUCU-00038P-F4; Mon, 15 Jul 2024 18:29:42 -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 1sTUCQ-00037t-09 for help-gnu-emacs@gnu.org; Mon, 15 Jul 2024 18:29:38 -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 1sTUCN-0000lB-TO for help-gnu-emacs@gnu.org; Mon, 15 Jul 2024 18:29:37 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1721082572; x=1721341772; bh=jtbQGTvDQQ7OnMrB0aiTF2TsQV+TdcXnDw9Xuez2YKw=; 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=x2OwuD+VEfCXWa+SbwodeX8A3zTG1V6yR4hYOEKzx45lXUtX2EkeEKmd7zuk/uI/T eQCyMPkrdVXyLZtoAbGHWUIDcRuOzIOE5Xvg/fiupm23oqKCWe7y3xquns1m1xxSM+ fW5Uo2TmuWJv+0ENhWjUnLs1EyNp0BHcZzK1fegAUAwvCtASCN0BgzIsYZkEVGg8q6 BP2Om2fXx7Uyd6VF67WDrvuiajBOYf+E5d4NRIsrdgx7XUUwnlTcAklsJU4yhPI9OI kDKxMCE2QBoDn6wXHaLWAc15oY/VkoaDIPE2N9tgfHTy/NPCIYSFmwc+o73ybBqU1M Y8jZZ/8ryYOFA== In-Reply-To: <87sewawci1.fsf@gmx.net> Feedback-ID: 57735886:user:proton X-Pm-Message-ID: 0825984e86a2d26e1f2bf44c4492411f2420660f Received-SPF: pass client-ip=185.70.43.166; envelope-from=heimeborgia@protonmail.com; helo=mail-43166.protonmail.ch 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_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:147238 Archived-At: 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 wrote= : >=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.com w= rote: > > >=20 > > > > On Tuesday, July 16th, 2024 at 4:24 AM, Heime heimeborgia@protonmai= l.com wrote: >=20 > [...] >=20 > > > > > I also have to handle the case of " LABEL [-] " with a different = regex, > > > > > so I can > > > > > distinguish between " [-] LABEL " and " LABEL [-] ". > > > >=20 > > > > In the latter case I want to match [-] at the end with any trailing= 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 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. > > >=20 > > > Steve Berman > >=20 > > Have used > >=20 > > "\\`\\(\\s-\\[\\-\\]\\s-\\)\\(.*\\)" for " [-] LABEL " > >=20 > > and > >=20 > > "\\(.\\)\\(\\s-\\[\\-\\]\\s-*\\)\\'" for " LABEL [-] " >=20 >=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 are > the same with and without it): Was that about showing the code ? It is basically writing down the regex s= trings. > (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 Yes it is what I wanted. Having read the documentation, why don't you appl= y=20 \\' for the second case to match the empty string, but only at the end of s= tring being matched against ?=20