From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Xah Newsgroups: gmane.emacs.help Subject: Re: How to automatically increment an index array Date: Thu, 26 Jun 2008 19:44:34 -0700 (PDT) Organization: http://groups.google.com Message-ID: <9a68abc5-f2c8-4b83-a661-af134cf1519a@h1g2000prh.googlegroups.com> References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1214538043 23843 80.91.229.12 (27 Jun 2008 03:40:43 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 27 Jun 2008 03:40:43 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Jun 27 05:41:27 2008 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1KC4pw-0004WD-WE for geh-help-gnu-emacs@m.gmane.org; Fri, 27 Jun 2008 05:41:25 +0200 Original-Received: from localhost ([127.0.0.1]:58618 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KC4p6-00031b-C6 for geh-help-gnu-emacs@m.gmane.org; Thu, 26 Jun 2008 23:40:32 -0400 Original-Path: news.stanford.edu!newsfeed.stanford.edu!postnews.google.com!h1g2000prh.googlegroups.com!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 68 Original-NNTP-Posting-Host: 24.6.97.120 Original-X-Trace: posting.google.com 1214534674 18450 127.0.0.1 (27 Jun 2008 02:44:34 GMT) Original-X-Complaints-To: groups-abuse@google.com Original-NNTP-Posting-Date: Fri, 27 Jun 2008 02:44:34 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: h1g2000prh.googlegroups.com; posting-host=24.6.97.120; posting-account=bRPKjQoAAACxZsR8_VPXCX27T2YcsyMA User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Macintosh; U; PPC Mac OS X 10_4_11; en) AppleWebKit/525.18 (KHTML, like Gecko) Version/3.1.1 Safari/525.18, gzip(gfe), gzip(gfe) Original-Xref: news.stanford.edu gnu.emacs.help:159748 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:55102 Archived-At: On Jun 26, 12:45 am, "Francis Moreau" wrote: > Hello > > I have this problem: in a buffer, *scratch* for example I have: > > [8735b450] =3D xxx, > [0x15] =3D xxx, > [0x16] =3D xxx, > [0x17] =3D xxx, > [0x18] =3D xxx, > [0x19] =3D xxx, > [0x1a] =3D xxx, > [0x1b] =3D xxx, > > After running a 'magic' command I'd like to calculate the new array index= es > as follow: > > [8735b450] =3D xxx, > [8735b454] =3D xxx, > [8735b458] =3D xxx, > [8735b45c] =3D xxx, > [8735b460] =3D xxx, > [8735b464] =3D xxx, > [8735b468] =3D xxx, > [8735b46c] =3D xxx, If i understand you correctly, you want to insert increment numbers into a column. I needed this every few weeks. Not often, but when needed is rather tedious to do manually, so i've written a elisp to do it once for all. (defun insert-counter-column (n) "Insert a sequence of integers vertically. Example: do this 1 times do this 2 times do this 3 times =2E.. If there are not enough existing lines after the cursor when this function is called, it aborts at the last line. See also: `kill-rectangle' and `string-rectangle'." (interactive "nEnter the max integer: ") (let ((i 1) colpos) (setq colpos (- (point) (point-at-bol))) (while (<=3D i n) (insert (number-to-string i)) (next-line) (beginning-of-line) (forward-char colpos) (setq i (1+ i)) ))) Use it together with buildin kill-rectangle (C-x r k ) and string-rectangle (C-x r t) or query-replace (M-%). Since from your example your increment is 4, and it's hex, you might need to modify the code a bit. Xah =E2=88=91 http://xahlee.org/ =E2=98=84