From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: David Newsgroups: gmane.emacs.help Subject: Re: How to automatically increment an index array Date: Fri, 27 Jun 2008 10:47:39 +0200 Message-ID: References: <38b2ab8a0806260045o100d1237iff3c6289775e5131@mail.gmail.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1214556525 7327 80.91.229.12 (27 Jun 2008 08:48:45 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 27 Jun 2008 08:48:45 +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 10:49:29 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 1KC9dy-0001OR-1X for geh-help-gnu-emacs@m.gmane.org; Fri, 27 Jun 2008 10:49:22 +0200 Original-Received: from localhost ([127.0.0.1]:39658 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KC9d7-00054M-5B for geh-help-gnu-emacs@m.gmane.org; Fri, 27 Jun 2008 04:48:29 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KC9ci-00054B-Mp for help-gnu-emacs@gnu.org; Fri, 27 Jun 2008 04:48:04 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KC9ch-00053q-6M for help-gnu-emacs@gnu.org; Fri, 27 Jun 2008 04:48:04 -0400 Original-Received: from [199.232.76.173] (port=45897 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KC9ch-00053n-32 for help-gnu-emacs@gnu.org; Fri, 27 Jun 2008 04:48:03 -0400 Original-Received: from main.gmane.org ([80.91.229.2]:33584 helo=ciao.gmane.org) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1KC9cg-0006wr-8J for help-gnu-emacs@gnu.org; Fri, 27 Jun 2008 04:48:02 -0400 Original-Received: from list by ciao.gmane.org with local (Exim 4.43) id 1KC9cR-0003pt-Sf for help-gnu-emacs@gnu.org; Fri, 27 Jun 2008 08:47:47 +0000 Original-Received: from kafka.physik3.gwdg.de ([134.76.92.48]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 27 Jun 2008 08:47:47 +0000 Original-Received: from de_bb by kafka.physik3.gwdg.de with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 27 Jun 2008 08:47:47 +0000 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 56 Original-X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: kafka.physik3.gwdg.de User-Agent: Gnus/5.110011 (No Gnus v0.11) Emacs/22.2 (gnu/linux) Cancel-Lock: sha1:vHZZtgs12ZZzV0+1wSFFwSZ0EmI= X-detected-kernel: by monty-python.gnu.org: Linux 2.6, seldom 2.4 (older, 4) 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:55110 Archived-At: "Francis Moreau" writes: > I have this problem: in a buffer, *scratch* for example I have: > > [8735b450] = xxx, > [0x15] = xxx, > [0x16] = xxx, > [0x17] = xxx, > [0x18] = xxx, > [0x19] = xxx, > [0x1a] = xxx, > [0x1b] = xxx, > > After running a 'magic' command I'd like to calculate the new array indexes > as follow: > > [8735b450] = xxx, > [8735b454] = xxx, > [8735b458] = xxx, > [8735b45c] = xxx, > [8735b460] = xxx, > [8735b464] = xxx, > [8735b468] = xxx, > [8735b46c] = xxx, > ... > > Can anybody give me a hint ? There are already some very nice suggestions on this thread, but one problem here is that the hex numbers will at least on 32bit systems be too large for Emacs to handle (just do C-h v most-positive-fixnum RET). Since these replacement problems one encounters while programming are often slightly different, I usually use keyboard macros instead of fixed functions to tackle them. For the above example, I'd do: C-x C-k C-f %x RET (set macro counter *f*ormat to hex) C-x C-k C-c #xb454 RET (set initial macro *c*ounter value) now go to the line [0x15] and set the cursor on the zero. Then C-x ( DEL DEL DEL DEL (delete existing number) 8 7 3 5 C-x C-k C-i (*i*nsert macro counter, incrementing it by 1) C-x C-k C-a 3 RET (*a*dd another 3) (... move cursor the next line and again on the zero ...) C-x ) (end macro) Now you can just do `C-x e' and repeatedly press `e' to replace the next lines. Maybe this is a bit confusing when doing this the first time, but you get quickly used to it. Note that you need Emacs 22 for using the macro counter. For older Emacsen, use registers instead. -David