* Re: Apply a transformation on a region
[not found] ` <87ocj5pluj.fsf@informatimago.com>
@ 2010-03-04 7:06 ` jpkotta
0 siblings, 0 replies; only message in thread
From: jpkotta @ 2010-03-04 7:06 UTC (permalink / raw)
To: help-gnu-emacs
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)))).
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2010-03-04 7:06 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <e62da5d4-0600-4b15-826f-11058edb55f8@e23g2000yqd.googlegroups.com>
[not found] ` <87ocj5pluj.fsf@informatimago.com>
2010-03-04 7:06 ` Apply a transformation on a region jpkotta
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).