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

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

Re: not-replace-regexp.el


From: Ehud Karni
Subject: Re: not-replace-regexp.el
Date: Sun, 8 Aug 2004 18:28:13 +0300

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Sat, 07 Aug 2004 13:22:46 -0500, Joe Corneli <address@hidden> wrote:
>
> ;; I'm not sure why there isn't a standard short-hand for the idiom
> ;;
> ;;   (while (re-search-forward regexp nil t)
> ;;    (replace-match to-string nil nil))
> ;;
> ;; However, it is not clear whether there is any benefit to a shorter
> ;; version it unless it really was adopted as a new standard, since
> ;; the above is so ubiquitous at this point in time, and any new
> ;; short-hand would likely to confuse most people.

I wrote some time ago (1995) the following 2 simple functions that
I use as short-hand for the above.

(defun replace-regexp-whole-buffer (REGEXP TO-STRING)
"Replace REGEXP in the whole buffer with TO-STRING (exactly as is).
Saves cursor position. Can be undone by UNDO only !"
       (let ((pos (point-marker)))
           (goto-char (point-min))
           (while (re-search-forward REGEXP nil t)
               (replace-match TO-STRING t t))
           (goto-char pos)))

(defun replace-string-whole-buffer (STRING TO-STRING)
"Replace STRING in the whole buffer with TO-STRING (exactly as is).
Saves cursor position. Can be undone by UNDO only !"
       (let ((pos (point-marker)))
           (goto-char (point-min))
           (while (search-forward STRING nil t)
               (replace-match TO-STRING t t))
           (goto-char pos)))

Ehud.


- --
 Ehud Karni           Tel: +972-3-7966-561  /"\
 Mivtach - Simon      Fax: +972-3-7966-667  \ /  ASCII Ribbon Campaign
 Insurance agencies   (USA) voice mail and   X   Against   HTML   Mail
 http://www.mvs.co.il  FAX:  1-815-5509341  / \
 GnuPG: 98EA398D <http://www.keyserver.net/>    Better Safe Than Sorry
-----BEGIN PGP SIGNATURE-----
Comment: use http://www.keyserver.net/ to get my key (and others)

iD8DBQFBFkaMLFvTvpjqOY0RAjLeAJ9msGz1PFSpUTWwX4YAGI7l7Y8aCwCfUhaQ
EJK/LXVtZyzIAdW+45V8EOU=
=/vwy
-----END PGP SIGNATURE-----




reply via email to

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