help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to automatically increment an index array


From: Rupert Swarbrick
Subject: Re: How to automatically increment an index array
Date: Thu, 26 Jun 2008 12:52:29 +0100
User-agent: Gnus/5.110011 (No Gnus v0.11) Emacs/22.2 (gnu/linux)

Rupert Swarbrick <rswarbrick@gmail.com> writes:

> (defun do-hex-incrementing ()
>   (interactive)
>   (save-excursion
>     (re-search-forward "\\[[0-9a-z]+\\]")
>     (let ((pt) (base))
>       (setf pt (1- (point)))
>       (search-backward "\[")
>       (setf base
>             (string-to-number
>              (buffer-substring (1+ (point)) pt) 16))
>       (while
>           (re-search-forward  "\\[0x[0-9a-z]+\]" nil t)
>         (search-backward "[0x")
>         (forward-char)
>         (insert
>          (format "%x"
>                  (+ (string-to-number
>                      (substring (thing-at-point 'word) 2) 16)
>                     base)))
>         (setf pt (point))
>         (search-forward "]")
>         (delete-region pt (1- (point)))))))

I've just realised that I've used setf throughout. Too much common lisp
recently! In this case, I could have just used setq, so either replace
all setf's with setq's in the above or (require 'cl) beforehand.

Rupert


reply via email to

[Prev in Thread] Current Thread [Next in Thread]