* Re: emacs insert icrement numbers
[not found] <mailman.5271.1155819472.9609.help-gnu-emacs@gnu.org>
@ 2006-08-17 13:23 ` wenbinye
2006-08-17 13:31 ` Chris McMahan
2006-08-17 13:58 ` Pascal Bourguignon
1 sibling, 1 reply; 10+ messages in thread
From: wenbinye @ 2006-08-17 13:23 UTC (permalink / raw)
There is a elisp: gse-number-rect which can do this:
C-u M-x gse-number-rect
Step0ut wrote:
> 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
>
> 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.
>
> --
> View this message in context: http://www.nabble.com/emacs-insert-icrement-numbers-tf2120701.html#a5848953
> Sent from the Emacs - Help forum at Nabble.com.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: emacs insert icrement numbers
2006-08-17 13:23 ` emacs insert icrement numbers wenbinye
@ 2006-08-17 13:31 ` Chris McMahan
2006-08-17 13:53 ` wenbinye
0 siblings, 1 reply; 10+ messages in thread
From: Chris McMahan @ 2006-08-17 13:31 UTC (permalink / raw)
I was a real fan of this function, but it has ceased to work in the
latest versions of emacs.
Does anybody have a version that works under emacs-22, or a fix for
the existing version (2004.12.22)?
Here's the error message I get:
if: Wrong number of arguments: #[(prompt &optional default)
"<a string of non-printable characters>" [n default prompt str nil string-match
"\\(\\):[ ]*\\'" replace-match format " (default %s)" ...] 8], 3
- Chris
wenbinye@gmail.com writes:
> There is a elisp: gse-number-rect which can do this:
> C-u M-x gse-number-rect
> Step0ut wrote:
>> 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
>>
>> 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.
>>
>> --
>> View this message in context: http://www.nabble.com/emacs-insert-icrement-numbers-tf2120701.html#a5848953
>> Sent from the Emacs - Help forum at Nabble.com.
>
--
(. .)
=ooO=(_)=Ooo=====================================
Chris McMahan | first_initiallastname@one.dot.net
=================================================
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: emacs insert icrement numbers
2006-08-17 13:31 ` Chris McMahan
@ 2006-08-17 13:53 ` wenbinye
2006-08-17 19:31 ` Chris McMahan
0 siblings, 1 reply; 10+ messages in thread
From: wenbinye @ 2006-08-17 13:53 UTC (permalink / raw)
the function gse-number-rectangle use function read-number which is not
compatible
with old version. You have to change the line marked as following:
(interactive
(list
(region-beginning) ; start
(region-end) ; end
(if (functionp 'read-number)
;; change this line (read-number "First number [1]: " t "1") to this
(read-number "First number [1]: " 1) ; start-at
(string-to-int (read-string "First number [1]: " nil nil "1"))) ;
start-at
(read-string "Suffix: " nil 'gse-number-rectangle-history) ;
suffix-text
current-prefix-arg)) ; prefix
Chris McMahan wrote:
> I was a real fan of this function, but it has ceased to work in the
> latest versions of emacs.
>
> Does anybody have a version that works under emacs-22, or a fix for
> the existing version (2004.12.22)?
>
> Here's the error message I get:
>
> if: Wrong number of arguments: #[(prompt &optional default)
> "<a string of non-printable characters>" [n default prompt str nil string-match
> "\\(\\):[ ]*\\'" replace-match format " (default %s)" ...] 8], 3
>
> - Chris
>
> wenbinye@gmail.com writes:
>
> > There is a elisp: gse-number-rect which can do this:
> > C-u M-x gse-number-rect
> > Step0ut wrote:
> >> 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
> >>
> >> 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.
> >>
> >> --
> >> View this message in context: http://www.nabble.com/emacs-insert-icrement-numbers-tf2120701.html#a5848953
> >> Sent from the Emacs - Help forum at Nabble.com.
> >
>
> --
> (. .)
> =ooO=(_)=Ooo=====================================
> Chris McMahan | first_initiallastname@one.dot.net
> =================================================
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: emacs insert icrement numbers
2006-08-17 13:53 ` wenbinye
@ 2006-08-17 19:31 ` Chris McMahan
0 siblings, 0 replies; 10+ messages in thread
From: Chris McMahan @ 2006-08-17 19:31 UTC (permalink / raw)
Outstanding!! It works like a charm too!
- Chris
wenbinye@gmail.com writes:
> the function gse-number-rectangle use function read-number which is not
> compatible
> with old version. You have to change the line marked as following:
>
> (interactive
> (list
> (region-beginning) ; start
> (region-end) ; end
> (if (functionp 'read-number)
> ;; change this line (read-number "First number [1]: " t "1") to this
> (read-number "First number [1]: " 1) ; start-at
> (string-to-int (read-string "First number [1]: " nil nil "1"))) ;
> start-at
> (read-string "Suffix: " nil 'gse-number-rectangle-history) ;
> suffix-text
> current-prefix-arg)) ; prefix
>
> Chris McMahan wrote:
>> I was a real fan of this function, but it has ceased to work in the
>> latest versions of emacs.
>>
>> Does anybody have a version that works under emacs-22, or a fix for
>> the existing version (2004.12.22)?
>>
>> Here's the error message I get:
>>
>> if: Wrong number of arguments: #[(prompt &optional default)
>> "<a string of non-printable characters>" [n default prompt str nil
>> string-match "\\(\\):[ ]*\\'" replace-match format " (default %s)"
>> ...] 8], 3
>>
>> - Chris
...
--
(. .)
=ooO=(_)=Ooo=====================================
Chris McMahan | first_initiallastname@one.dot.net
=================================================
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: emacs insert icrement numbers
[not found] <mailman.5271.1155819472.9609.help-gnu-emacs@gnu.org>
2006-08-17 13:23 ` emacs insert icrement numbers wenbinye
@ 2006-08-17 13:58 ` Pascal Bourguignon
2006-08-17 19:34 ` Chris McMahan
` (2 more replies)
1 sibling, 3 replies; 10+ messages in thread
From: Pascal Bourguignon @ 2006-08-17 13:58 UTC (permalink / raw)
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.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: emacs insert icrement numbers
2006-08-17 13:58 ` Pascal Bourguignon
@ 2006-08-17 19:34 ` Chris McMahan
2006-08-17 21:58 ` Jim Ottaway
[not found] ` <mailman.5302.1155852315.9609.help-gnu-emacs@gnu.org>
2 siblings, 0 replies; 10+ messages in thread
From: Chris McMahan @ 2006-08-17 19:34 UTC (permalink / raw)
Thanks for the code! I'm saving it as part of my "I've got to learn
elisp" library.
- Chris
Pascal Bourguignon <pjb@informatimago.com> writes:
> 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.
--
(. .)
=ooO=(_)=Ooo=====================================
Chris McMahan | first_initiallastname@one.dot.net
=================================================
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: emacs insert icrement numbers
2006-08-17 13:58 ` Pascal Bourguignon
2006-08-17 19:34 ` Chris McMahan
@ 2006-08-17 21:58 ` Jim Ottaway
[not found] ` <mailman.5302.1155852315.9609.help-gnu-emacs@gnu.org>
2 siblings, 0 replies; 10+ messages in thread
From: Jim Ottaway @ 2006-08-17 21:58 UTC (permalink / raw)
Regards,
Pascal Bourguignon <pjb@informatimago.com> writes:
> 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
>
Or
M-x replace-regexp RET ^ RET \,\#
[there are two spaces after the '\#'. I don't know why it needs 2 rather
than one, though]
--
Jim Ottaway
^ permalink raw reply [flat|nested] 10+ messages in thread
[parent not found: <mailman.5302.1155852315.9609.help-gnu-emacs@gnu.org>]
* Re: emacs insert icrement numbers
[not found] ` <mailman.5302.1155852315.9609.help-gnu-emacs@gnu.org>
@ 2006-08-18 6:38 ` David Kastrup
0 siblings, 0 replies; 10+ messages in thread
From: David Kastrup @ 2006-08-18 6:38 UTC (permalink / raw)
Jim Ottaway <j.ottaway@lse.ac.uk> writes:
> Regards,
>
> Pascal Bourguignon <pjb@informatimago.com> writes:
>
>> 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
>>
>
> Or
>
> M-x replace-regexp RET ^ RET \,\#
>
> [there are two spaces after the '\#'. I don't know why it needs 2 rather
> than one, though]
To distinguish this from
\,\#1
for example. The space terminates \#.
--
David Kastrup, Kriemhildstr. 15, 44793 Bochum
^ permalink raw reply [flat|nested] 10+ messages in thread
* emacs insert icrement numbers
@ 2006-08-17 10:41 Step0ut
2006-08-23 0:37 ` Bill Wohler
0 siblings, 1 reply; 10+ messages in thread
From: Step0ut @ 2006-08-17 10:41 UTC (permalink / raw)
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
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.
--
View this message in context: http://www.nabble.com/emacs-insert-icrement-numbers-tf2120701.html#a5848953
Sent from the Emacs - Help forum at Nabble.com.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: emacs insert icrement numbers
2006-08-17 10:41 Step0ut
@ 2006-08-23 0:37 ` Bill Wohler
0 siblings, 0 replies; 10+ messages in thread
From: Bill Wohler @ 2006-08-23 0:37 UTC (permalink / raw)
Step0ut <step0ut@yahoo.gr> 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 <wohler@newt.com> http://www.newt.com/wohler/ GnuPG ID:610BD9AD
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2006-08-23 0:37 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <mailman.5271.1155819472.9609.help-gnu-emacs@gnu.org>
2006-08-17 13:23 ` emacs insert icrement numbers wenbinye
2006-08-17 13:31 ` Chris McMahan
2006-08-17 13:53 ` wenbinye
2006-08-17 19:31 ` Chris McMahan
2006-08-17 13:58 ` Pascal Bourguignon
2006-08-17 19:34 ` Chris McMahan
2006-08-17 21:58 ` Jim Ottaway
[not found] ` <mailman.5302.1155852315.9609.help-gnu-emacs@gnu.org>
2006-08-18 6:38 ` David Kastrup
2006-08-17 10:41 Step0ut
2006-08-23 0:37 ` Bill Wohler
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).