help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: non word abbrevs


From: Leo Butler
Subject: Re: non word abbrevs
Date: Mon, 01 Nov 2021 08:49:34 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)

Jean-Christophe Helary <lists@traduction-libre.org> writes:

>> On Nov 1, 2021, at 21:43, Stefan Monnier via Users list for the GNU Emacs 
>> text editor <help-gnu-emacs@gnu.org> wrote:
>> 
>>>>>   :regexp "\(<?[-=]>?\)")
>>>>> I must be missing something.
>>>> Hmmm... backslashes?  ;-)
>>>> The above string is the same as "(<?[-=]>?)" (in recentish Emacsen the
>>>> above backslashes should presumably be highlighted in
>>>> a font-lock-warning color for that reason).
>>> 
>>> I'm trying in *scratch* with lisp-mode on a recent "master" and I don't get 
>>> that...
>> 
>> I just tried it on my end with both `master` and Emacs-27.1
>> 
>>    emacs -Q
>>    :regexp "\(<?[-=]>?\)")
>> 
>> and the two backslashes got the `font-lock-warning-face` (the strings
>> are colored a kind of brick red and the warning is in red so it doesn't
>> stand out as much as I'd like but it's visible).
>
> Ok, I just rebuilt the latest master and emacs -Q shows them... And I am 
> *not* going to dive into my init.el at this time of the day...
>
>>> :regexp "\\([<>=-]+\\)"
>> 
>> And since Emacs will only use the shortest match, it will only use
>> one-char-long matches :-(
>> 
>> Try something like: "[^<>=-]\\([<>=-]+\\)"
>> [ Yes, this shortest match business is a PITA.  ]
>
> My abbrevs are arrows composed of < or > at the tips and - or = with a 
> minimum of 2 characters and a max of 3:
>
> → ⇒
> ← ⇐
> ↔ ⇔
>
> In a different world, I'd try [<>=-]{2,3}
>
> Is that what you mean ?

Try M-x regexp-builder RET

This is a fast way to check your regexps are matching the way you
intend.

Btw, it might be easier to do something like

(regexp-opt '("=>" "==>") "[^>=<]\\(?:")
===> "[^>=<]\\(?:=\\(?:=?>\\)\\)"

Btw, I just checked that regexp with regexp-builder and it matched only
2 strings in this buffer.

FWIW,
Leo



reply via email to

[Prev in Thread] Current Thread [Next in Thread]