From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Brendan Halpin Newsgroups: gmane.emacs.help Subject: Re: Doing numbered changes in a buffer Date: Fri, 16 Dec 2005 16:54:00 +0000 Message-ID: <873bktrniv.fsf@wivenhoe.staff8.ul.ie> References: <1134683622.782732.293210@g47g2000cwa.googlegroups.com> Reply-To: brendan.halpin@ul.ie NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1134764830 30693 80.91.229.2 (16 Dec 2005 20:27:10 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Fri, 16 Dec 2005 20:27:10 +0000 (UTC) Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Dec 16 21:27:08 2005 Return-path: Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1EnM8h-0006Ub-Mf for geh-help-gnu-emacs@m.gmane.org; Fri, 16 Dec 2005 21:25:15 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1EnM9P-0002IG-J7 for geh-help-gnu-emacs@m.gmane.org; Fri, 16 Dec 2005 15:25:59 -0500 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!news.tele.dk!news.tele.dk!small.news.tele.dk!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 52 Original-X-Trace: individual.net fwdTtjZp64u4sfmTFzn45AxQVFyIZyOdq4vGmNU0F0RngodPWD User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (gnu/linux) Cancel-Lock: sha1:Kch5iaRccg5j2zrnY6Hkq+PmND8= Original-Xref: shelby.stanford.edu gnu.emacs.help:136345 Original-To: help-gnu-emacs@gnu.org X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:31997 Archived-At: "gamename" writes: > Is there any way to do a string replace in the buffer such that each > instance of "puts" would be assigned a unique message number? For > example: > > puts "001 - something went wrong" > ... > puts "002 - something went wrong" Using these two functions below (the second of which I got off Usenet many years ago, and have used regularly since), put point at the start of where you want the changes to happen, and do: M-x enumerate-bit-of-text RET something went wrong RET You can fine-tune the result by adding e.g. "(forward-char 5)" before the "insert" function, or inserting more than the "!1". If you really want the leading zeros, use a format statement in the "(insert (int-to-string start))" enumerate function. Regards, Brendan (defun enumerate-bit-of-text (text) (interactive "sText to enumerate: ") (save-excursion (while (re-search-forward text nil t) (goto-char (match-beginning 0)) (insert "!1") (goto-char (match-end 0)))) (enumerate "!1" 1)) ;; A function I got from David Biesack, SAS Institute Inc., many ;; years ago: (defun enumerate (&optional pattern start) "Replace PATTERN with sequential numbers beginning with prefix arg START (default is 1). " (interactive "sRegular expression to enumerate [default \"!1\"]: \np") (if (string= "" pattern) (setq pattern "!1")) (save-excursion (while (re-search-forward pattern nil t) (delete-region (match-beginning 0) (match-end 0)) (insert (int-to-string start)) (setq start (1+ start))))) -- Brendan Halpin, Department of Sociology, University of Limerick, Ireland Tel: w +353-61-213147 f +353-61-202569 h +353-61-338562; Room F2-025 x 3147 mailto:brendan.halpin@ul.ie http://www.ul.ie/sociology/brendan.halpin.html