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

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

Re: (newbie) search & replace (—match case) all at once without confirma


From: Emanuel Berg
Subject: Re: (newbie) search & replace (—match case) all at once without confirmation automation
Date: Wed, 02 Nov 2022 23:48:59 +0100
User-agent: Gnus/5.13 (Gnus v5.13)

jindam, vani wrote:

> where can i find examples for "search & replace (—match
> case) all at once without confirmation"?

;;; -*- lexical-binding: t -*-
;;
;; this file:
;;   https://dataswamp.org/~incal/emacs-init/regexp.el

(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)) )))
  (or beg (setq beg (point-min)))
  (or 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)

(provide 'regexp)

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




reply via email to

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