all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Heime <heimeborgia@protonmail.com>
To: Stephen Berman <stephen.berman@gmx.net>
Cc: Heime via Users list for the GNU Emacs text editor
	<help-gnu-emacs@gnu.org>
Subject: Re: Matching labels with buttons
Date: Mon, 15 Jul 2024 23:02:36 +0000	[thread overview]
Message-ID: <jlCiPMpQddX9TjLujQxTdetxz3DH1WAUE9NRA1fKpXKYLSMYcZbBSIULKGSQdi7OBqiyRpOCWXHghPStVHXSrLJpdO09bl8fRM_ZBLQpL08=@protonmail.com> (raw)
In-Reply-To: <87o76yw9xw.fsf@gmx.net>

On Tuesday, July 16th, 2024 at 10:46 AM, Stephen Berman <stephen.berman@gmx.net> wrote:

> On Mon, 15 Jul 2024 22:29:27 +0000 Heime heimeborgia@protonmail.com wrote:
> 
> > On Tuesday, July 16th, 2024 at 9:50 AM, Stephen Berman
> > stephen.berman@gmx.net wrote:
> > 
> > > On Mon, 15 Jul 2024 21:29:38 +0000 Heime heimeborgia@protonmail.com wrote:
> > > 
> > > > 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 different regex,
> > > > > > > so I can
> > > > > > > distinguish between " [-] LABEL " and " LABEL [-] ".
> > > > > > 
> > > > > > In the latter case I want to match [-] at the end with any trailing 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 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):
> > 
> > Was that about showing the code ? It is basically writing down the regex 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 apply
> > \\' for the second case to match the empty string, but only at the end of 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

Yes, I want to avoid matching " LABEL [-] some other text".  




  reply	other threads:[~2024-07-15 23:02 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-15 11:17 Matching labels with buttons Heime
2024-07-15 11:25 ` Heime
2024-07-15 11:56   ` Stephen Berman
2024-07-15 12:35     ` Heime
2024-07-15 12:52       ` Stephen Berman
2024-07-15 12:58         ` Heime
2024-07-15 13:42           ` Stephen Berman
2024-07-15 16:24             ` Heime
2024-07-15 17:25               ` Heime
2024-07-15 21:20                 ` Stephen Berman
2024-07-15 21:29                   ` Heime
2024-07-15 21:50                     ` Stephen Berman
2024-07-15 22:29                       ` Heime
2024-07-15 22:46                         ` Stephen Berman
2024-07-15 23:02                           ` Heime [this message]
2024-07-15 11:57   ` Bruno Barbier
2024-07-15 18:29     ` tpeplt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='jlCiPMpQddX9TjLujQxTdetxz3DH1WAUE9NRA1fKpXKYLSMYcZbBSIULKGSQdi7OBqiyRpOCWXHghPStVHXSrLJpdO09bl8fRM_ZBLQpL08=@protonmail.com' \
    --to=heimeborgia@protonmail.com \
    --cc=help-gnu-emacs@gnu.org \
    --cc=stephen.berman@gmx.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.