;;; another-line.el ;;; ;;; Copyright (C) 1997, 1998, 2004, 2007, 2008 Thien-Thi Nguyen ;;; ;;; This file is part of ttn's personal elisp library, released under ;;; the terms of the GNU General Public License as published by the ;;; Free Software Foundation; either version 3, or (at your option) any ;;; later version. There is NO WARRANTY. See 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-number (match-string 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