[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to increase a number under cursor?

From: Eric Ludlam
Subject: Re: How to increase a number under cursor?
Date: 21 May 2003 08:27:45 -0400
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2

>>> Wang Yin <address@hidden> seems to think that:
>I want to record a macro to type flexible numbered lists.

This is one of my favorite commands I pulled off of one of these
newsgroups many years ago, and have been tweaking ever since.  I bound
it to M-o, and use it quite often.

;;; Original author: address@hidden, 28-Jan-1996
;;; Modified for multiple lines: Eric
(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) 
         (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-int (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)))

Eric Ludlam             "Photonic Doodler"    The MathWorks x 7556
address@hidden         (work)
address@hidden         (home)

reply via email to

[Prev in Thread] Current Thread [Next in Thread]