[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Matching labels with buttons
From: |
Stephen Berman |
Subject: |
Re: Matching labels with buttons |
Date: |
Mon, 15 Jul 2024 23:50:46 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) |
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):
(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
- Re: Matching labels with buttons, (continued)
- Re: Matching labels with buttons, Heime, 2024/07/15
- Re: Matching labels with buttons, Stephen Berman, 2024/07/15
- Re: Matching labels with buttons, Heime, 2024/07/15
- Re: Matching labels with buttons, Stephen Berman, 2024/07/15
- Re: Matching labels with buttons, Heime, 2024/07/15
- Re: Matching labels with buttons, Stephen Berman, 2024/07/15
- Re: Matching labels with buttons, Heime, 2024/07/15
- Re: Matching labels with buttons, Heime, 2024/07/15
- Re: Matching labels with buttons, Stephen Berman, 2024/07/15
- Re: Matching labels with buttons, Heime, 2024/07/15
- Re: Matching labels with buttons,
Stephen Berman <=
- Re: Matching labels with buttons, Heime, 2024/07/15
- Re: Matching labels with buttons, Stephen Berman, 2024/07/15
- Re: Matching labels with buttons, Heime, 2024/07/15
Re: Matching labels with buttons, Bruno Barbier, 2024/07/15