[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Column replace
From: |
Peter Lee |
Subject: |
Re: Column replace |
Date: |
Wed, 13 Jun 2007 16:01:59 -0500 |
User-agent: |
Gnus/5.11 (Gnus v5.11) Emacs/22.1.50 (windows-nt) |
>>>> deprecated writes:
> Just in case anyone was worried that emacs has only two solutions to
> this problem, there is a third way ..... :)
Don't know where I got this, but this is what I use:
(defun another-line (num-lines)
"Copies line, preserving cursor column, and increments any numbers found.
Copies a block of optional NUM-LINES lines. If no optional argument is given,
then only one line is copied."
(interactive "p")
(if (not num-lines) (setq num-lines 0) (setq num-lines (1- num-lines)))
(let* ((col (current-column))
(bol (save-excursion (forward-line (- num-lines)) (beginning-of-line)
(point)))
(eol (progn (end-of-line) (point)))
(line (buffer-substring bol eol)))
(goto-char bol)
(while (re-search-forward "[0-9]+" eol 1)
(let ((num (string-to-number (buffer-substring
(match-beginning 0) (match-end 0)))))
(replace-match (int-to-string (1+ num))))
(setq eol (save-excursion (goto-char eol) (end-of-line) (point))))
(goto-char bol)
(insert line "\n")
(move-to-column col)))
(global-set-key (kbd "M-O") 'another-line)
- Re: Column replace, (continued)
- Re: Column replace, Peter Dyballa, 2007/06/12
- Re: Column replace, Juanma Barranquero, 2007/06/12
- Message not available
- Re: Column replace, weber, 2007/06/12
- Re: Column replace, Juanma Barranquero, 2007/06/12
- Message not available
- Re: Column replace, weber, 2007/06/12
- Re: Column replace, Juanma Barranquero, 2007/06/12
- Message not available
- Re: Column replace, weber, 2007/06/12
- Re: Column replace, weber, 2007/06/12
- Re: Column replace, Juanma Barranquero, 2007/06/12
Re: Column replace, deprecated, 2007/06/12
- Re: Column replace,
Peter Lee <=
Re: Column replace, Colin S. Miller, 2007/06/13