Re: replace with a counter



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/


.



Relevant Pages

  • Re: The Center of the Universe and Radio Waves
    ... > E=MC2 implies that at the center of the universe a unitary substance ... > consisting only of gravity waves existed. ... Move cursor over blinkers ...
    (sci.physics)
  • Re: Cursor disappears in table
    ... I ran into the exact same problem today as c3000ca. ... long table consisting of 3 columns per page. ... I can see my cursor on ... Any fix would be greatly appreciated. ...
    (microsoft.public.word.application.errors)