all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Thien-Thi Nguyen <ttn@glug.org>
Subject: Re: query-replace-regexp number number+1
Date: Wed, 12 Apr 2006 10:22:53 +0200	[thread overview]
Message-ID: <7eirpfp5ia.fsf@ada2.unipv.it> (raw)
In-Reply-To: 4v0%f.3588$sq5.3185@newsread2.news.atl.earthlink.net

"B. T. Raven" <ecinmn@peoplepc.com> writes:

> Convert a bunch of lines like:
>
> p.150
>
> into
>
> p.150(125)... and then p.151 into p.151(126) etc.

see below.
not pretty, but...
munge to taste.

thi

______________________________
;;; another-line.el
;;;
;;; Rel:v-1-55
;;;
;;; Copyright (C) 1997, 1998, 2004 Thien-Thi Nguyen
;;; This file is part of ttn's personal elisp library, released under GNU
;;; GPL with ABSOLUTELY NO WARRANTY.  See the file COPYING for details.

;;; Description: Copy current line, incrementing numbers.  Bus-friendly.  :->

;;;###autoload
(defun another-line ()
  "Copy line, preserving cursor column, and increment any numbers found.
This should probably be generalized in the future."
  (interactive)
  (let* ((col (current-column))
         (bol (progn (beginning-of-line) (point)))
         (eol (progn (end-of-line) (point)))
         (line (buffer-substring bol eol)))
    (beginning-of-line)
    (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)))))
    (beginning-of-line)
    (insert line "\n")
    (move-to-column col)))

; 1999/03/19 01:46:00
;
; This is contributed by Jeff Tuckey.  It only works if `transient-mark-mode'
; is nil, so we will mull on it a bit before deciding what to do.
;
; (defun copy-yank-and-increment (beg end)
;   "Copy region to kill-ring, yanks this back to the buffer and
; increment any numbers found in the yanked text."
;   (interactive "r")
;   (copy-region-as-kill beg end)
;   (yank '(4))
;   (let ((p (point))
;       (m (mark-marker)))
;     (while (re-search-forward "[0-9]+" m 1)
;       (let ((num (string-to-int (buffer-substring
;                                (match-beginning 0) (match-end 0)))))
;       (replace-match (int-to-string (1+ num)))))
;     (set-mark p)))

(provide 'another-line)

;;; another-line.el ends here

  reply	other threads:[~2006-04-12  8:22 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-04-11 16:04 query-replace-regexp number number+1 rturrado
2006-04-11 16:14 ` David Kastrup
2006-04-11 18:36   ` rturrado
2006-04-11 19:05     ` David Kastrup
2006-04-12  5:46       ` B. T. Raven
2006-04-12  8:22         ` Thien-Thi Nguyen [this message]
2006-04-12  8:47         ` David Kastrup
2006-04-12 16:12       ` rturrado
2006-04-12 14:52     ` Giorgos Keramidas

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

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

  git send-email \
    --in-reply-to=7eirpfp5ia.fsf@ada2.unipv.it \
    --to=ttn@glug.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.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.