[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Apply a transformation on a region
From: |
jpkotta |
Subject: |
Re: Apply a transformation on a region |
Date: |
Tue, 04 May 2010 15:41:17 -0000 |
User-agent: |
G2/1.0 |
On Mar 3, 7:37 am, p...@informatimago.com (Pascal J. Bourguignon)
wrote:
> bdsatish <bdsat...@gmail.com> writes:
> > Hello,
>
> > I have a simple text file in the buffer with following contents,
>
> > ABC00001
> > ABC00002
> > ABC00003
> > ABC00004
> > ABC00005
>
> > and so on till 1000 lines. The number in each line must be
> > incremented, so that after applying an "increment macro", the buffer
> > should reflect
>
> > ABC00002
> > ABC00003
> > ABC00004
> > ABC00005
> > ABC00006
>
> > till 1001
>
> > I want to know how to do it using Emacs-lisp (i dont care about shell
> > scripts or python)
>
> (defun shift-lines ()
> (interactive)
> (goto-line 1)
> (kill-line)
> (goto-line 999)
> (let ((n (let ((bol (progn (beginning-of-line) (point))))
> (parse-integer (buffer-substring (+ 3 bol) (+ 8 bol))))))
> (goto-line 1000)
> (insert (format "ABC%05d\n" (1+ n)))))
>
> --
> __Pascal Bourguignon__http://www.informatimago.com
A slower but perhaps more general way is to do a replace-regexp from \
(ABC\)\([0-9]+\) to \1\,(format "%05d" (1+ (string-to-number \2)))).
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Re: Apply a transformation on a region,
jpkotta <=