From: Bill Wohler <wohler@newt.com>
Subject: Re: emacs insert icrement numbers
Date: Tue, 22 Aug 2006 17:37:10 -0700 [thread overview]
Message-ID: <87u044p9s9.fsf@olgas.newt.com> (raw)
In-Reply-To: 5848953.post@talk.nabble.com
Step0ut <step0ut@yahoo.gr> writes:
> Is it possible to insert numbers that increament in each line?
Here's some lisp I wrote to do this 20 years ago which I still use today...
(defun bw-inc-column (column start inc begin end)
"Increment the numbers in a column.
The numbers are created in COLUMN and start with number START and are
incremented by INC in the region.
In programs, the region is defined by BEGIN and END.
Note that the columns are basically defined by `forward-word' so any space or
punctuation character will split columns."
(interactive "nColumn: \nnStart: \nnIncrement: \nr")
(save-restriction
(save-excursion
(narrow-to-region begin end)
(goto-char (point-min))
(let ((n start))
(while (< (point) (point-max))
(beginning-of-line)
(forward-word column)
(forward-word -1)
(let ((begin (point)))
(forward-word 1)
(delete-region begin (point))
(message (format "n=%d" n))
(insert (int-to-string n)))
(setq n (+ n inc))
(forward-line 1))))))
--
Bill Wohler <wohler@newt.com> http://www.newt.com/wohler/ GnuPG ID:610BD9AD
next prev parent reply other threads:[~2006-08-23 0:37 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-08-17 10:41 emacs insert icrement numbers Step0ut
2006-08-23 0:37 ` Bill Wohler [this message]
[not found] <mailman.5271.1155819472.9609.help-gnu-emacs@gnu.org>
2006-08-17 13:23 ` wenbinye
2006-08-17 13:31 ` Chris McMahan
2006-08-17 13:53 ` wenbinye
2006-08-17 19:31 ` Chris McMahan
2006-08-17 13:58 ` Pascal Bourguignon
2006-08-17 19:34 ` Chris McMahan
2006-08-17 21:58 ` Jim Ottaway
[not found] ` <mailman.5302.1155852315.9609.help-gnu-emacs@gnu.org>
2006-08-18 6:38 ` David Kastrup
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87u044p9s9.fsf@olgas.newt.com \
--to=wohler@newt.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).