* Doing numbered changes in a buffer
@ 2005-12-15 21:53 gamename
2005-12-16 1:10 ` Quokka
2005-12-16 16:54 ` Brendan Halpin
0 siblings, 2 replies; 4+ messages in thread
From: gamename @ 2005-12-15 21:53 UTC (permalink / raw)
Hi,
I have a tcl file with lots of messages which are about as descriptive
as this:
puts "something went wrong"
...
puts "something went wrong"
Is there any way to do a string replace in the buffer such that each
instance of "puts" would be assigned a unique message number? For
example:
puts "001 - something went wrong"
...
puts "002 - something went wrong"
TIA,
-T
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Doing numbered changes in a buffer
2005-12-15 21:53 Doing numbered changes in a buffer gamename
@ 2005-12-16 1:10 ` Quokka
2005-12-16 16:54 ` Brendan Halpin
1 sibling, 0 replies; 4+ messages in thread
From: Quokka @ 2005-12-16 1:10 UTC (permalink / raw)
gamename wrote:
> Hi,
>
> I have a tcl file with lots of messages which are about as descriptive
> as this:
>
> puts "something went wrong"
> ...
> puts "something went wrong"
>
> Is there any way to do a string replace in the buffer such that each
> instance of "puts" would be assigned a unique message number? For
> example:
>
> puts "001 - something went wrong"
> ...
> puts "002 - something went wrong"
You could use a keyboard macro and the keyboard macro counter
From the help:
The command `C-x C-k C-i' (`kmacro-insert-counter') inserts the
current value of the keyboard macro counter and increments the counter
by 1. You can use a numeric prefix argument to specify a different
increment. If you just specify a `C-u' prefix, the last inserted
counter value is repeated and the counter is not incremented. For
example, if you enter the following sequence while defining a macro
So the sequence is
C-x (
search for puts "something went wrong"
move cursor back to start of string
C-x C-k -Ci -> inserts the current counter value
C-x )
The C-x e to repeat.
Hope that helps
Paul
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Doing numbered changes in a buffer
2005-12-15 21:53 Doing numbered changes in a buffer gamename
2005-12-16 1:10 ` Quokka
@ 2005-12-16 16:54 ` Brendan Halpin
2005-12-17 21:29 ` gamename
1 sibling, 1 reply; 4+ messages in thread
From: Brendan Halpin @ 2005-12-16 16:54 UTC (permalink / raw)
"gamename" <namesagame-usenet@yahoo.com> writes:
> Is there any way to do a string replace in the buffer such that each
> instance of "puts" would be assigned a unique message number? For
> example:
>
> puts "001 - something went wrong"
> ...
> puts "002 - something went wrong"
Using these two functions below (the second of which I got off
Usenet many years ago, and have used regularly since), put point at
the start of where you want the changes to happen, and do:
M-x enumerate-bit-of-text RET something went wrong RET
You can fine-tune the result by adding e.g. "(forward-char 5)"
before the "insert" function, or inserting more than the "!1". If
you really want the leading zeros, use a format statement in the
"(insert (int-to-string start))" enumerate function.
Regards,
Brendan
(defun enumerate-bit-of-text (text)
(interactive "sText to enumerate: ")
(save-excursion
(while (re-search-forward text nil t)
(goto-char (match-beginning 0))
(insert "!1")
(goto-char (match-end 0))))
(enumerate "!1" 1))
;; A function I got from David Biesack, SAS Institute Inc., many
;; years ago:
(defun enumerate (&optional pattern start)
"Replace PATTERN with sequential numbers beginning
with prefix arg START (default is 1). "
(interactive "sRegular expression to enumerate [default \"!1\"]: \np")
(if (string= "" pattern) (setq pattern "!1"))
(save-excursion
(while (re-search-forward pattern nil t)
(delete-region (match-beginning 0) (match-end 0))
(insert (int-to-string start))
(setq start (1+ start)))))
--
Brendan Halpin, Department of Sociology, University of Limerick, Ireland
Tel: w +353-61-213147 f +353-61-202569 h +353-61-338562; Room F2-025 x 3147
mailto:brendan.halpin@ul.ie http://www.ul.ie/sociology/brendan.halpin.html
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Doing numbered changes in a buffer
2005-12-16 16:54 ` Brendan Halpin
@ 2005-12-17 21:29 ` gamename
0 siblings, 0 replies; 4+ messages in thread
From: gamename @ 2005-12-17 21:29 UTC (permalink / raw)
Cool! Thanks.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2005-12-17 21:29 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-12-15 21:53 Doing numbered changes in a buffer gamename
2005-12-16 1:10 ` Quokka
2005-12-16 16:54 ` Brendan Halpin
2005-12-17 21:29 ` gamename
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).