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

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

replace-regexp-1


From: Emanuel Berg
Subject: replace-regexp-1
Date: Wed, 22 Jun 2022 02:10:49 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux)

;;; -*- lexical-binding: t -*-

(defun replace-regexp-1 (re rep &optional beg end)
  (interactive
   `(,(read-string "regexp: ")
     ,(read-string "replace: ")
     ,@(when (use-region-p)
         (list (region-beginning) (region-end)) )))
  (unless beg (setq beg (point-min)))
  (unless end (setq end (point-max)))
  (save-excursion
    (goto-char end)
    (while (re-search-backward re beg t)
      (replace-match rep) )))

(defalias 'rr #'replace-regexp-1)

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




reply via email to

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