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

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

Re: elisp find/replace efficiency question


From: Stefan Monnier
Subject: Re: elisp find/replace efficiency question
Date: Wed, 08 Dec 2010 15:31:16 -0000
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux)

>>>>> "Xah" == Xah Lee <xahlee@gmail.com> writes:

> suppose i want write a command that do a find/replace on a region
> which is more efficient?

Based on the suggestion of C-h f replace-regexp RET I'd say:

 (defun space2underscore-region (p1 p2)
   "Replace space by underscore in region."
   (interactive "r")
   (setq p2 (copy-marker p2 t))
   (goto-char p1)
   (while (search-forward " " p2 t) (replace-match "_")))


-- Stefan


reply via email to

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