From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Bill Wohler Newsgroups: gmane.emacs.help Subject: Re: emacs insert icrement numbers Date: Tue, 22 Aug 2006 17:37:10 -0700 Organization: Newt Software Message-ID: <87u044p9s9.fsf@olgas.newt.com> References: <5848953.post@talk.nabble.com> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1156293472 21592 80.91.229.2 (23 Aug 2006 00:37:52 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Wed, 23 Aug 2006 00:37:52 +0000 (UTC) Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed Aug 23 02:37:50 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 1GFgkd-00046t-T4 for geh-help-gnu-emacs@m.gmane.org; Wed, 23 Aug 2006 02:37:48 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1GFgkd-0005JH-B8 for geh-help-gnu-emacs@m.gmane.org; Tue, 22 Aug 2006 20:37:47 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1GFgkS-0005J9-1U for help-gnu-emacs@gnu.org; Tue, 22 Aug 2006 20:37:36 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1GFgkQ-0005In-9V for help-gnu-emacs@gnu.org; Tue, 22 Aug 2006 20:37:35 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1GFgkQ-0005Ik-3H for help-gnu-emacs@gnu.org; Tue, 22 Aug 2006 20:37:34 -0400 Original-Received: from [80.91.229.2] (helo=ciao.gmane.org) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA:32) (Exim 4.52) id 1GFgs8-0001on-7r for help-gnu-emacs@gnu.org; Tue, 22 Aug 2006 20:45:32 -0400 Original-Received: from list by ciao.gmane.org with local (Exim 4.43) id 1GFgk9-00040d-BV for help-gnu-emacs@gnu.org; Wed, 23 Aug 2006 02:37:18 +0200 Original-Received: from h-68-166-189-178.snvacaid.dynamic.covad.net ([68.166.189.178]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 23 Aug 2006 02:37:17 +0200 Original-Received: from wohler by h-68-166-189-178.snvacaid.dynamic.covad.net with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 23 Aug 2006 02:37:17 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-To: help-gnu-emacs@gnu.org Original-Lines: 32 Original-X-Complaints-To: usenet@sea.gmane.org X-Gmane-NNTP-Posting-Host: h-68-166-189-178.snvacaid.dynamic.covad.net User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (gnu/linux) Cancel-Lock: sha1:FF8p6yQVnfECXdWSSrAAB0wOT5I= 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:36855 Archived-At: Step0ut 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 http://www.newt.com/wohler/ GnuPG ID:610BD9AD