emacs-devel
[Top][All Lists]
Advanced

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

Re: Improve `replace-regexp-in-string' ergonomics?


From: Lars Ingebrigtsen
Subject: Re: Improve `replace-regexp-in-string' ergonomics?
Date: Wed, 22 Sep 2021 10:09:55 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

Adam Porter <adam@alphapapa.net> writes:

> Agreed, the name seems too long, and the function's signature is awkward
> (I always have to check the argument list when I use it).  Most of the
> time, I don't want to replace with automatic case matching, nor do I
> want to substitute the original matched text, so I have to add the
> FIXEDCASE argument, and then carefully re-read the docstring for LITERAL
> and decide whether I need it, too.

Functions in Emacs are generally on the DWIM side, so we could make a
new `regexp-replace' function be more well-defined.  That is, it could
be always-FIXEDCASE and never LITERAL.

> The SUBEXP argument, I'm not so sure about.

Yeah, that one is actually useful.  It's used in 5% of the cases in the
Emacs tree...

> Having it at the end would break threading.  Having it after the
> replacement would mean having a "nil" much of the time, which wouldn't
> be as pretty.  I suppose the third argument could be either a SUBEXP
> or the string, and if a SUBEXP, an optional fourth argument could be
> the string?  But since these are likely called often and in loops, I
> suppose that might be undesirable.

The replacement could be a cons like ("foo" . 2) to only replace subexp
2, perhaps.  If we allow a bunch of regexp/replacement pairs, then I
guess that'd be necessary anyway.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no



reply via email to

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