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, 12 Oct 2021 09:53:42 +0300
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (x86_64-pc-linux-gnu)

>> 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)))
>
> Otherwise, after adding replacement pairs as args of 'regexp-replace',
> replacements should be applied "simultaneously".

Such simultaneous replacement could be implemented the same way as
in mm-uu-configure that creates a composite regexp from all regexps:

(defun mm-uu-configure (&optional symbol value)
  (setq mm-uu-beginning-regexp
        (mapconcat #'mm-uu-beginning-regexp
                   (delq nil (mapcar
                              (lambda (entry)
                                (if (mm-uu-configure-p (mm-uu-type entry)
                                                       'disabled)
                                    nil entry))
                              mm-uu-type-alist))
                   "\\|")))

Then it's used like this:

      (while (re-search-forward mm-uu-beginning-regexp nil t)

In case of replacements, it should replace the found composite regexp
with the corresponding string from replacement pairs.



reply via email to

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