[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: emacs insert icrement numbers
From: |
Pascal Bourguignon |
Subject: |
Re: emacs insert icrement numbers |
Date: |
Thu, 17 Aug 2006 15:58:26 +0200 |
User-agent: |
Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (gnu/linux) |
Step0ut <step0ut@yahoo.gr> writes:
> Hi everyone,
>
> I am using emacs as an editor for c++ and latex.
> I am using the command Ctrl-xrt to insert rectangles (usually numbers) quite
> often.
> My question is:
> Is it possible to insert numbers that increament in each line?
> e.g. 0
> 1
> 2
> ...
> 99
>
Well I don't have gse-number-rect, and I bet it'll be faster to write
the following than to use google...
(defun insert-numbers (min max)
(interactive "nFrom: \nnTo: ")
(while (<= min max) (insert (format "\n%d " min)) (setq min (+ 1 min))))
0
1
2
3
It's also possible to record the left margin, and to copy it on each line:
(defun insert-numbers (min max)
(interactive "nFrom: \nnTo: ")
(let ((margin (buffer-substring (save-excursion (beginning-of-line) (point))
(point))))
(when (<= min max)
(insert (format "%d " min))
(setq min (+ 1 min))
(while (<= min max)
(insert (format "\n%s%d " margin min))
(setq min (+ 1 min))))))
==> 0
==> 1
==> 2
==> 3
> Alternatively I was also thinking if it is possible to replace an existing
> string (M-x replace-regexp) with an icrement number. It will do the job as
> well.
With latest versions (>=22), you can use \,form in the the substitutions.
For example, select a region and:
M-x replace-regexp RET \(.*\) RET
\,(progn(defvar n 0)(format "%3d " (incf n)))\1 RET
1 NOTE: The most fundamental particles in this product are held
2 together by a "gluing" force about which little is currently known
3 and whose adhesive power can therefore not be permanently
4 guaranteed.
--
__Pascal Bourguignon__ http://www.informatimago.com/
NOTE: The most fundamental particles in this product are held
together by a "gluing" force about which little is currently known
and whose adhesive power can therefore not be permanently
guaranteed.