;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001 ;; David J. Biesack ;; This file is not part of GNU Emacs. ;; GNU Emacs is free software; you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation; either version 2, or (at your option) ;; any later version. ;; GNU Emacs is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with GNU Emacs; see the file COPYING. If not, write to the ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, ;; Boston, MA 02111-1307, USA. ;;; Commentary: ;; insert/remove or renumber line numbers in a buffer ;; probably obsolete now, due to new line number modes ;; in later emacsen, but i forget what they are... ;; Author: David Biesack (David.Biesack@sas.com or biesack@mindspring.com) ;; Last Modified By: biesack@mindspring.com ;; Last Modified: Thu Mar 15 17:49:07 2001 (defun renumber-lines (begin end start increment arg) "Renumber lines in region BEGIN to END, starting with number START and adding INCREMENT each time. With ARG, do not replace existing line numbers, which are of the form \"^NNN\\t\"" (interactive "r\nnStart at: \nnIncrement: \nP") (save-excursion (let ((end-marker (make-marker))) (set-marker end-marker end (current-buffer)) (goto-char begin) (while (< (point) end-marker) (beginning-of-line 1) (back-to-indentation) (if (or arg (looking-at "[0-9]+")) (progn (kill-word 1))) (insert (int-to-string start)) (setq start (+ start increment)) (beginning-of-line 2))))) (defun unnumber-lines (start end) (interactive "r") (save-excursion (save-restriction (narrow-to-region start end) (goto-char start) (message "Renumbering") (replace-regexp "^\\(\\s-*\\)[0-9]+" "\\1") ))) (fset 'number-lines 'renumber-lines)