Re: replace with a counter
- From: "xahlee@xxxxxxxxx" <xahlee@xxxxxxxxx>
- Date: Thu, 13 Nov 2008 06:47:15 -0800 (PST)
On Nov 7, 3:26 am, Daneel Yaitskov <rtfm.rtfm.r...@xxxxxxxxx> wrote:
Hi All.
Frequently I have to write a text consisting from the same rows. These
rows distinguish themselvs only word. For example:
There is one row:
LEFT JOIN menu a1 ON a1.c_menu||a1.c_rec = C_PLANT
I copied the row and pasted 6 times. (key stroke C-u 6 C-x r i r -
doesn't work)
LEFT JOIN menu a1 ON a1.c_menu||a1.c_rec = C_PLANT
LEFT JOIN menu a1 ON a1.c_menu||a1.c_rec = C_PLANT
LEFT JOIN menu a1 ON a1.c_menu||a1.c_rec = C_PLANT
LEFT JOIN menu a1 ON a1.c_menu||a1.c_rec = C_PLANT
LEFT JOIN menu a1 ON a1.c_menu||a1.c_rec = C_PLANT
LEFT JOIN menu a1 ON a1.c_menu||a1.c_rec = C_PLANT
I need to replace a1 to a2, a3 and so on.
...
Your question is a FAQ.
This function will be useful to you.
(defun insert-counter-column (n)
"Insert a sequence of integers vertically.
For example, if your text is:
a b
c d
e f
and your cursor is after “a”, then calling this function with argument
3 will change it to become:
a1 b
c2 d
e3 f
If there are not enough existing lines after the cursor
when this function is called, it aborts at the last line.
See also: `kill-rectangle' and `string-rectangle'."
(interactive "nEnter the max integer: ")
(let ((i 1) colpos)
(setq colpos (- (point) (point-at-bol)))
(while (<= i n)
(insert (number-to-string i))
(next-line) (beginning-of-line) (forward-char colpos)
(setq i (1+ i))
)))
You migth find other simple elisp examples useful:
• Emacs Lisp Examples
http://xahlee.org/emacs/elisp_examples.html
Xah
∑ http://xahlee.org/
☄
.
- References:
- replace with a counter
- From: Daneel Yaitskov
- replace with a counter
- Prev by Date: Re: replace with a counter
- Next by Date: reversing dired e command
- Previous by thread: Re: replace with a counter
- Next by thread: emacs compiling
- Index(es):
Relevant Pages
|