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: Juri Linkov
Subject: Re: Improve `replace-regexp-in-string' ergonomics?
Date: Tue, 05 Oct 2021 19:18:48 +0300
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (x86_64-pc-linux-gnu)

>        (org-babel-read
>         (concat "'"
>               (thread-last
>                 results
>                 (regexp-replace "'" "\"")
>                 (regexp-replace ",[[:space:]]" " ")
>                 (regexp-replace "\\]" ")")
>                 (regexp-replace "\\[" "("))))
>
> We could also consider making `regexp-replace' take a series of pairs,
> since this is so common.  Like:
>
>        (org-babel-read
>         (concat "'"
>               (regexp-replace "'" "\""
>                               ",[[:space:]]" " "
>                               "\\]" ")"
>                               "\\[" "("
>                               results)))

When the user needs to apply more replacements to the results of previous
replacements, then 'thread-last' could be used like in the first example above.
Otherwise, after adding replacement pairs as args of 'regexp-replace',
replacements should be applied "simultaneously".  E.g. in the new version
Julia 1.7: https://lwn.net/SubscriberLink/871486/e4ae97b79d72bb25/
and https://github.com/JuliaLang/julia/pull/40484
the existing function 'replace' has been enhanced to accept
any number of replacement patterns that are applied simultaneously
left to right, e.g.

  replace("abc", "c" => "Z", "Z" => "WWW")

returns "abZ", not "abWWW".



reply via email to

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