[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
regexp replace
From: |
Emanuel Berg |
Subject: |
regexp replace |
Date: |
Sat, 11 Mar 2023 11:54:19 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) |
Hey, this idea is stupid, right, it shouldn't matter what
direction you go?
;;; -*- lexical-binding: t -*-
;;
;; this file:
;; https://dataswamp.org/~incal/emacs-init/regexp.el
(require 'cl-lib)
(require 'dwim)
(defun replace-regexp-1 (re rep &optional beg end rev)
(interactive
`(,(read-string "regexp: ")
,(read-string "replace: ")
,@(use-region t)
,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 "matches replaced: %d" c) ))))
(defalias 'rr #'replace-regexp-1)
(provide 'regexp)
--
underground experts united
https://dataswamp.org/~incal
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- regexp replace,
Emanuel Berg <=