;;; -*- lexical-binding: t -*- ;; ;; this file: ;; https://dataswamp.org/~incal/emacs-init/regexp.el (require 'dwim) (defun replace-regexp-1 (re rep &optional beg end rev) (interactive `(,(read-string "regexp: ") ,(read-string "replace: ") ,@(use-region) ,current-prefix-arg)) (or beg (setq beg (point-min))) (or end (setq end (point-max))) (pcase-let ((`(,start ,sfun ,stop) (if rev (list end #'re-search-backward beg) (list beg #'re-search-forward end) ))) (save-excursion (goto-char start) (let ((c 0)) (while (apply sfun re stop '(t)) (cl-incf c) (replace-match rep) ) (message "replaced: %d" c) )))) (defalias 'rr #'replace-regexp-1) (provide 'regexp)