unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Eric Ludlam <eludlam@mathworks.com>
Subject: Re: How to increase a number under cursor?
Date: 21 May 2003 08:27:45 -0400	[thread overview]
Message-ID: <ko65o4jxha.fsf@ludlamelinux.dhcp.mathworks.com> (raw)
In-Reply-To: phwugm3tfv.fsf@wangyin.com

>>> Wang Yin <wang-y01@mails.tsinghua.edu.cn> seems to think that:
>Hi,
>
>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: ttn@netcom.com, 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) (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-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
eludlam@mathworks.com         (work)        http://www.mathworks.com
eric@siege-engine.com         (home)      http://www.siege-engine.com

  parent reply	other threads:[~2003-05-21 12:27 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-05-20  8:37 How to increase a number under cursor? Wang Yin
2003-05-20 12:58 ` Brendan Halpin
2003-05-21  8:10   ` Wang Yin
2003-05-20 13:34 ` Oliver Scholz
2003-05-20 14:17   ` David Kastrup
2003-05-21 12:27 ` Eric Ludlam [this message]
2003-05-21 16:13 ` Sandip Chitale

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ko65o4jxha.fsf@ludlamelinux.dhcp.mathworks.com \
    --to=eludlam@mathworks.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).