From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Thien-Thi Nguyen Newsgroups: gmane.emacs.help Subject: Re: query-replace-regexp number number+1 Date: Wed, 12 Apr 2006 10:22:53 +0200 Organization: sometimes Message-ID: <7eirpfp5ia.fsf@ada2.unipv.it> References: <1144771499.122669.267040@v46g2000cwv.googlegroups.com> <8564lg9jil.fsf@lola.goethe.zz> <1144780563.044266.202000@g10g2000cwb.googlegroups.com> <85lkuc6iho.fsf@lola.goethe.zz> <4v0%f.3588$sq5.3185@newsread2.news.atl.earthlink.net> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1144831297 27916 80.91.229.2 (12 Apr 2006 08:41:37 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Wed, 12 Apr 2006 08:41:37 +0000 (UTC) Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed Apr 12 10:41:36 2006 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1FTaud-0005lY-QO for geh-help-gnu-emacs@m.gmane.org; Wed, 12 Apr 2006 10:41:20 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1FTauc-00030u-N2 for geh-help-gnu-emacs@m.gmane.org; Wed, 12 Apr 2006 04:41:18 -0400 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!headwall.stanford.edu!newsfeed.news2me.com!newsfeed.icl.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!news.tiscali.de!uio.no!quimby.gnus.org!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 67 Original-NNTP-Posting-Host: ada2.unipv.it Original-X-Trace: quimby.gnus.org 1144830174 18572 193.204.44.145 (12 Apr 2006 08:22:54 GMT) Original-X-Complaints-To: usenet@quimby.gnus.org Original-NNTP-Posting-Date: Wed, 12 Apr 2006 08:22:54 +0000 (UTC) User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (gnu/linux) Cancel-Lock: sha1:3YD3mpFgio5fXsc08pY2Y0gP8Oo= Original-Xref: shelby.stanford.edu gnu.emacs.help:138711 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:34329 Archived-At: "B. T. Raven" writes: > Convert a bunch of lines like: > > p.150 > > into > > p.150(125)... and then p.151 into p.151(126) etc. see below. not pretty, but... munge to taste. thi ______________________________ ;;; another-line.el ;;; ;;; Rel:v-1-55 ;;; ;;; Copyright (C) 1997, 1998, 2004 Thien-Thi Nguyen ;;; This file is part of ttn's personal elisp library, released under GNU ;;; GPL with ABSOLUTELY NO WARRANTY. See the file COPYING for details. ;;; Description: Copy current line, incrementing numbers. Bus-friendly. :-> ;;;###autoload (defun another-line () "Copy line, preserving cursor column, and increment any numbers found. This should probably be generalized in the future." (interactive) (let* ((col (current-column)) (bol (progn (beginning-of-line) (point))) (eol (progn (end-of-line) (point))) (line (buffer-substring bol eol))) (beginning-of-line) (while (re-search-forward "[0-9]+" eol 1) (let ((num (string-to-int (buffer-substring (match-beginning 0) (match-end 0))))) (replace-match (int-to-string (1+ num))))) (beginning-of-line) (insert line "\n") (move-to-column col))) ; 1999/03/19 01:46:00 ; ; This is contributed by Jeff Tuckey. It only works if `transient-mark-mode' ; is nil, so we will mull on it a bit before deciding what to do. ; ; (defun copy-yank-and-increment (beg end) ; "Copy region to kill-ring, yanks this back to the buffer and ; increment any numbers found in the yanked text." ; (interactive "r") ; (copy-region-as-kill beg end) ; (yank '(4)) ; (let ((p (point)) ; (m (mark-marker))) ; (while (re-search-forward "[0-9]+" m 1) ; (let ((num (string-to-int (buffer-substring ; (match-beginning 0) (match-end 0))))) ; (replace-match (int-to-string (1+ num))))) ; (set-mark p))) (provide 'another-line) ;;; another-line.el ends here