Path: utzoo!utgpu!watmath!uunet!tut.cis.ohio-state.edu!SCIENCE.UTAH.EDU!Beebe From: Beebe@SCIENCE.UTAH.EDU ("Nelson H.F. Beebe") Newsgroups: gnu.emacs Subject: Displaying line numbers in a buffer Message-ID: <12457619080.9.BEEBE@SCIENCE.UTAH.EDU> Date: 27 Dec 88 01:05:26 GMT Sender: daemon@tut.cis.ohio-state.edu Distribution: gnu Organization: GNUs Not Usenet Lines: 27 In response to a recent request on this newsgroup, here is some code I wrote to add (and remove) line numbers in a buffer; it is public domain, so do what you like with it: (defun show-line-numbers () "Show line numbers in a copy of the current buffer." (interactive) (let ((n 0)) (goto-char (point-min)) (while (< (point) (point-max)) (setq n (1+ n)) (insert (format "%5d:\t" n)) (forward-line 1))) (toggle-read-only) ) (defun remove-line-numbers () "Remove line numbers installed by show-line-numbers." (interactive) (toggle-read-only) (save-excursion (goto-char (point-min)) ;; use loop rather than replace-regexp so M-x undo can undo it (while (re-search-forward "^[ 0-9][ 0-9][ 0-9][ 0-9][ 0-9]:\t" (point-max) t) (replace-match "" t t)))) -------