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

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

Re: replace-regexp


From: Emanuel Berg
Subject: Re: replace-regexp
Date: Sun, 09 May 2021 04:48:19 +0200

> Again, I don't think the user, not even the Lisp user,
> should do this thing. I'll see if I can show you what
> I mean, later.

Here, what is wrong with this?

(defun replace-regexp-1 (regexp to-string &optional beg end)
  (interactive
   `(,(read-from-minibuffer "regexp: ")
     ,(read-from-minibuffer "to string: ")
     ,@(if (use-region-p)
           (list (region-beginning) (region-end))
         (list (point-min) (point-max))) ))
  (let ((beg-set (or beg (point-min)))
        (end-set (or end (point-max))) )
    (save-excursion
      (goto-char end-set)
      (while (re-search-backward regexp beg-set t)
        (replace-match to-string) ))))

Works interactively and non-interactively using the same good
function... or?

-- 
underground experts united
https://dataswamp.org/~incal




reply via email to

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