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:20:59 +0200 Message-ID: <87wmlmwdvo.fsf@gmx.net> References: <87r0bug978.fsf@rub.de> <87msmig6lz.fsf@rub.de> <87ikx6g49y.fsf@rub.de> <72n913q3Tv6RlKwXsHxBXRlGEwuYia37iCUcLQg-7S8aHg_qVwE6JhXMRN3wk1IajDCeqvM7QD9yv5EM9yF75G8zwWyPb_VpQAqf_GqasdM=@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="11504"; 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:21:37 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 1sTT8a-0002pl-UR for geh-help-gnu-emacs@m.gmane-mx.org; Mon, 15 Jul 2024 23:21:37 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sTT87-0002ra-3f; Mon, 15 Jul 2024 17:21:07 -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 1sTT85-0002ix-8d for help-gnu-emacs@gnu.org; Mon, 15 Jul 2024 17:21:05 -0400 Original-Received: from mout.gmx.net ([212.227.15.15]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sTT83-0005IE-8y for help-gnu-emacs@gnu.org; Mon, 15 Jul 2024 17:21:05 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmx.net; s=s31663417; t=1721078459; x=1721683259; i=stephen.berman@gmx.net; bh=a51mPqZcFhPMLFQJQk5hlkT8ZTK4ymy/2vPOUeeUQyE=; 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=OLtGg7/qdRRJW5ZeEWm1h43F3fkg4fyYnQ8VbAu4TBXOLFF/2CLVc+kYKGCqvk3L YNx8dh5ZRLf5WdJLLR+MFcJVi6cCIkAF/aftegy54OrfUyrxtNZjsnuyxjhv/RBaJ UHpX0hC/T8fa4wXit9NCG467BEhG3Wr4YRk3j7wKXc6u6M9F3rBdyl4aTA5COBdEg Ux2Zu1ZC3j7D7y2tyfHs7pyqX2kujwjzvxU+QvUK4ODAI0SQdF/vEYscv2NVskZo5 GnxsvEtCkxyk0yiltmGG8qur98Bm/S3+BscwciGmDwtCpPpoDymRG3jsQnFckP/0s zCyQtL46IQenp5Y2Fg== 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 1MUosN-1sthF42kJV-00YhiE; Mon, 15 Jul 2024 23:20:59 +0200 In-Reply-To: <72n913q3Tv6RlKwXsHxBXRlGEwuYia37iCUcLQg-7S8aHg_qVwE6JhXMRN3wk1IajDCeqvM7QD9yv5EM9yF75G8zwWyPb_VpQAqf_GqasdM=@protonmail.com> (Heime's message of "Mon, 15 Jul 2024 17:25:42 +0000") X-Provags-ID: V03:K1:89Cpk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hH Received-SPF: pass client-ip=212.227.15.15; 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:147232 Archived-At: On Mon, 15 Jul 2024 17:25:42 +0000 Heime wrot= e: > On Tuesday, July 16th, 2024 at 4:24 AM, Heime wrote: > >> On Tuesday, July 16th, 2024 at 1:42 AM, Stephen Berman >> stephen.berman@gmx.net wrote: >> >> > On Mon, 15 Jul 2024 12:58:05 +0000 Heime heimeborgia@protonmail.com w= rote: >> > >> > > Sent with Proton Mail secure email. >> > > >> > > On Tuesday, July 16th, 2024 at 12:52 AM, Stephen Berman >> > > stephen.berman@gmx.net wrote: >> > > >> > > > On Mon, 15 Jul 2024 12:35:53 +0000 Heime heimeborgia@protonmail.c= om wrote: >> > > > >> > > > > On Monday, July 15th, 2024 at 11:56 PM, Stephen Berman >> > > > > stephen.berman@gmx.net wrote: >> > > > > >> > > > > > On Mon, 15 Jul 2024 11:25:28 +0000 Heime >> > > > > > heimeborgia@protonmail.com wrote: >> > > > > > >> > > > > > > Sent with Proton Mail secure email. >> > > > > > > >> > > > > > > On Monday, July 15th, 2024 at 11:17 PM, Heime >> > > > > > > heimeborgia@protonmail.com wrote: >> > > > > > > >> > > > > > > > I want to match cases such as >> > > > > > > > >> > > > > > > > Label [-] >> > > > > > > > >> > > > > > > > Have constructed the following regexp, but it does not ma= tch >> > > > > > > > the above >> > > > > > > > >> > > > > > > > "\\(.\\)\\(\\s-\\[\\-\\]\\s-\\)" >> > > > > > > > >> > > > > > > > I aw using >> > > > > > > > >> > > > > > > > (when (string-match "\\(.\\)\\(\\s-\\[\\-\\]\\s-\\)" text= ) >> > > > > > > >> > > > > > > In the code I have >> > > > > > > >> > > > > > > (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))) >> > > > > > > >> > > > > > > Doing some tests with >> > > > > > > >> > > > > > > "OFF [-]" >> > > > > > > >> > > > > > > keeps matching the first string-match >> > > > > > >> > > > > > That's because your regexp isn't anchored, so string-match su= cceeds if >> > > > > > it finds a match anywhere in the string passed to it. To avoi= d this, >> > > > > > start the regexp with "\\`", which anchors it to the start of= the string >> > > > > > being matched against; see (info "(elisp) Regexp Backslash"). >> > > > > > >> > > > > > Steve Berman >> > > > > >> > > > > I would like to have two regex expressions, one to match only "= [-] >> > > > > LABEL " and >> > > > > another to match only " LABEL [-] ". With any number of whitesp= ace. >> > > > > >> > > > > Can one use "^" ? Or is "\\`" preferred ? >> > > > >> > > > If you are always matching against a string, e.g. just using >> > > > string-match, then IIUC "^" and "\\`" give the same results. If y= ou >> > > > are matching against test in a buffer, e.g. with re-search-forwar= d, >> > > > looking-at etc., then they can differ: "^" matches the beginning = the >> > > > the line containing the matched string, "\\\\\\\\\\\\\\\\`" the >> > > > beginning of the string >> > > > itself, regardless of where in the line it is (at point-min the r= esults >> > > > are the same). >> > > > >> > > > > And can one use "[[:space:]]" rather >> > > > > than "\\s-" ? Which is preferred ? >> > > > >> > > > IIUC these both give the same results. >> > > > >> > > > Steve Berman >> > > >> > > Would I introduce \\` before the first grouping >> > > >> > > "\\`\\(\\s-\\[\\-\\]\\s-\\)\\(.*\\)" >> > >> > Since "\\`" matches the empty string, I don't think it matters whethe= r >> > it's inside or outside of the group. But since in this case it's >> > anchoring the entire regexp, it seems conceptually preferable to keep= it >> > outside (in contrast, e.g., to the case where the regexp is a >> > disjunction and you only want to anchor one of the disjuncts). >> > >> > > How would I print \\` in a docstring ? >> > >> > You have to escape the "`": \\\\\\\\\\\\\\\\=3D` (not \\=3D\\`). >> > >> > Steve Berman >> >> I also have to handle the case of " LABEL [-] " with a different regex,= so I can >> distinguish between " [-] LABEL " and " LABEL [-] ". > > In the latter case I want to match [-] at the end with any trailing spac= es. 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