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 15:42:49 +0200 Message-ID: <87ikx6g49y.fsf@rub.de> References: <87r0bug978.fsf@rub.de> <87msmig6lz.fsf@rub.de> 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="17956"; 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 15:43:33 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 1sTLzI-0004Rk-9D for geh-help-gnu-emacs@m.gmane-mx.org; Mon, 15 Jul 2024 15:43:32 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sTLyj-0001Hl-6f; Mon, 15 Jul 2024 09:42:57 -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 1sTLyh-0001C7-IK for help-gnu-emacs@gnu.org; Mon, 15 Jul 2024 09:42:55 -0400 Original-Received: from mout.gmx.net ([212.227.17.20]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sTLyf-0001Xp-MC for help-gnu-emacs@gnu.org; Mon, 15 Jul 2024 09:42:55 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmx.net; s=s31663417; t=1721050970; x=1721655770; i=stephen.berman@gmx.net; bh=nc7wjPFUleA7qZMI3HjfvoKg63SGh/zq5l2tZg/BEXw=; 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=WxE5EA+4klGqKF68gqaLfyYu3gK3p76nUoHM0i2zAekOESQWzTPuDi08d/0WnJtU 5/WTVBe4FOGpuqtJoSxGXOmiG1hEBZuLnUl+YXvP4N0cQP3veszaFg872FZqpdrPY 7UR3wH3zhMO2Qaiv0DDTD0EmeU7SLMhoT41PeaPt6Z40bjqaB25C8+kLL4YQeVTzM 8lqb/0iGKTFOhs10noCOmGvwGCumNMqKOVwgz5VlWZiBBnA6JpietMMxiN+TG5uyY BASXAbqB9q2PjFMh7z894lEA/bD+cqxLXE5tXpY5UAkYBHqXMAyVuk4m+dI8d8PBo VdgY2UAUeegKYCjKKw== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Original-Received: from strobelfs ([88.130.50.244]) by mail.gmx.net (mrgmx105 [212.227.17.168]) with ESMTPSA (Nemesis) id 1N3bSt-1sKzwP1dUB-00qtpr; Mon, 15 Jul 2024 15:42:50 +0200 In-Reply-To: (Heime's message of "Mon, 15 Jul 2024 12:58:05 +0000") X-Provags-ID: V03:K1:1TO/2UU+6g7LMOuK4PWANV0oNxo0kSVRaJ70x4ygV9jWi6O7FNI kOejIBAaD+PMtFoeH6OEbzMLJeRz5vfdHMikP3Nt7WnBinEua/YVzGYKZ0PBOoCFKHXPvEg oqNG7mc83HXeiQMVGnnsA0svFtC59TUiWSMWKjm6MsEy4AwHo4eIFsU9rBkN1DpSEtBlPq0 dY59zsEP7DpRe6r8qhixQ== UI-OutboundReport: notjunk:1;M01:P0:4Xk+DeM3mag=;YHXnmmKs+caN0g54avj9JLX4+50 ONQsd1OeJvbHRS3XZRNruM2Ct1zSUgaU/79JBPo1HewsokB7h2F4xPp129RQAJeuy1zIJQaRh W3CXeyPHC6sb4E+chAX1Kkkh2b2gjqYyz/4XYFSqwZWiIkJKrtksgLYT3AFmb0EiyUKkPxr/1 d7vp+Bm5R8X8lYRrYd/UzjhcNDT+rnxKF+sCOog9BPqLML3ywZQP82SAvWceYx0z2Ev0iW834 qtwwfczaOXQnziU703KWwgCx7lyECPJfIgddNDxcCcFsgHDMgKOLjA/iuTLsTsDd1Xx42ea3z lXHrQTKcxRPLi+xAUqYYGVFK2aEjrORsIqPclSGIbR/4UPV0r+Owhk8r52ShsW9HdNt3iMqlH LNRZ8R3pkLMdQxKvoXyDlzw7vX+DSPft8tT5BEWdcPjT9M1xwnwbihSvm0F3QVFoHzme1VOtz GFBVTs3iig7nt5S5MI6EYt6d80vEuDBc0P1QqFWCZUJtV9nlRPn6qc/U6i2tl6SPxPusFlFbt MKb+zcfWRK1vCwEchKw3oMWcKNnSDvIhybj575yKUYuVuku/d2KuMFKaYIHbfEjeAbYRiCJDO vDY9KZ9UGGPhSddu3Vdc/K25pprhbFQaaqf+32M9yV3yqgumzVvdibF3SAt/HpDtMEC36OQhA x4iHSiN3M9rHwyNrhruP2Ot/xnYc+GZ2GeO3b68h5fp6pQNtK4zW1FhZeny+fpEwh+4tgrx7k qciYDcOYBA3BCMLPb/r3vGuVvWXCBpKgVUxdaif/Dg1kurMLMmXI30wfxreFmrHGWDFQncmA Received-SPF: pass client-ip=212.227.17.20; 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:147222 Archived-At: On Mon, 15 Jul 2024 12:58:05 +0000 Heime wrot= e: > Sent with Proton Mail secure email. > > On Tuesday, July 16th, 2024 at 12:52 AM, Stephen Berman > wrote: > >> On Mon, 15 Jul 2024 12:35:53 +0000 Heime heimeborgia@protonmail.com wro= te: >> >> > 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 match th= e 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 succeeds= if >> > > it finds a match anywhere in the string passed to it. To avoid this= , >> > > start the regexp with "\\`", which anchors it to the start of the s= tring >> > > being matched against; see (info "(elisp) Regexp Backslash"). >> > > >> > > Steve Berman >> > >> > I would like to have two regex expressions, one to match only " [-] L= ABEL " and >> > another to match only " LABEL [-] ". With any number of whitespace. >> > >> > 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 you are >> matching against test in a buffer, e.g. with re-search-forward, 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 results >> 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 whether 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