help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: query-replace-regexp number number+1


From: Thien-Thi Nguyen
Subject: Re: query-replace-regexp number number+1
Date: Wed, 12 Apr 2006 10:22:53 +0200
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (gnu/linux)

"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 via email to

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