unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Peter Lee <pete.a.lee@gmail.com>
To: help-gnu-emacs@gnu.org
Subject: Re: Column replace
Date: Wed, 13 Jun 2007 16:01:59 -0500	[thread overview]
Message-ID: <ubqfjr2k8.fsf@gmail.com> (raw)
In-Reply-To: 1181669823.283617.131480@n15g2000prd.googlegroups.com

>>>> 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)

  reply	other threads:[~2007-06-13 21:01 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-06-12  8:48 Column replace Enchanter
2007-06-12  9:55 ` Juanma Barranquero
2007-06-12 10:39 ` Peter Dyballa
2007-06-12 10:54   ` Juanma Barranquero
2007-06-12 11:11     ` Peter Dyballa
2007-06-12 11:16       ` Juanma Barranquero
     [not found]       ` <mailman.1999.1181646983.32220.help-gnu-emacs@gnu.org>
2007-06-12 12:49         ` weber
2007-06-12 13:43           ` Juanma Barranquero
     [not found]           ` <mailman.2008.1181655831.32220.help-gnu-emacs@gnu.org>
2007-06-12 14:14             ` weber
2007-06-12 14:59               ` Juanma Barranquero
     [not found]               ` <mailman.2022.1181660385.32220.help-gnu-emacs@gnu.org>
2007-06-12 16:11                 ` weber
2007-06-12 17:00                   ` weber
2007-06-12 18:02                   ` Juanma Barranquero
2007-06-12 17:37 ` deprecated
2007-06-13 21:01   ` Peter Lee [this message]
2007-06-12 21:38 ` Colin S. Miller

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=ubqfjr2k8.fsf@gmail.com \
    --to=pete.a.lee@gmail.com \
    --cc=help-gnu-emacs@gnu.org \
    /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).