From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Teemu Likonen Newsgroups: gmane.emacs.help Subject: Re: Absolutely =?iso-8859-1?q?na=EFve?= question about line numbering and lisp code Date: Tue, 03 Mar 2009 16:25:39 GMT Organization: Sonera Customer Message-ID: <87skluk1z0.fsf@iki.fi> References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1236098541 16764 80.91.229.12 (3 Mar 2009 16:42:21 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 3 Mar 2009 16:42:21 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue Mar 03 17:43:38 2009 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1LeXiS-0003CR-8h for geh-help-gnu-emacs@m.gmane.org; Tue, 03 Mar 2009 17:43:36 +0100 Original-Received: from localhost ([127.0.0.1]:42937 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LeXh7-0007d0-1w for geh-help-gnu-emacs@m.gmane.org; Tue, 03 Mar 2009 11:42:13 -0500 Original-Path: news.stanford.edu!newsfeed.stanford.edu!newshub.sdsu.edu!feeder.erje.net!feeder2.news.saunalahti.fi!feeder1.news.saunalahti.fi!nntp.inet.fi!central1.inet.fi!inet.fi!read4.inet.fi.POSTED!53ab2750!not-for-mail Original-Newsgroups: gnu.emacs.help User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.2 (gnu/linux) Cancel-Lock: sha1:7IHJzhl30Y3t8ZvPY8B1iBd3Nls= Original-Lines: 27 Original-NNTP-Posting-Host: 80.220.180.181 Original-X-Complaints-To: abuse@inet.fi Original-X-Trace: read4.inet.fi 1236097539 80.220.180.181 (Tue, 03 Mar 2009 18:25:39 EET) Original-NNTP-Posting-Date: Tue, 03 Mar 2009 18:25:39 EET Original-Xref: news.stanford.edu gnu.emacs.help:167258 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:62558 Archived-At: On 2009-03-03 09:16 (-0600), B. T. Raven wrote: > If you just want to add line numbers permanently you could run this, > of unknown provenance: > > (defun insert-line-numbers () > "Insert a line number on all lines of the current buffer." > (interactive) > (save-excursion > (save-restriction > (widen) > (let ((fmt (format "%%0%dd " > (1+ (truncate > (log (count-lines (point-min) (point-max)) > 10))))) > (i 0)) > (goto-char (point-min)) > (while (< (point) (point-max)) > (setq i (1+ i)) > (insert (format fmt i)) > (forward-line))))) > );;insert-line-numbers That is quite clever. Usually something like this is enough: M-< M-x replace-regexp RET ^ RET \,(format "%4s. " (1+ \#)) RET