From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Pascal Bourguignon Newsgroups: gmane.emacs.help Subject: Re: prefix line with number WAS: Are Windows-Emacs' scrollbars broken? Date: 18 Apr 2003 02:16:24 +0200 Organization: informatimago.com Sender: help-gnu-emacs-bounces+gnu-help-gnu-emacs=m.gmane.org@gnu.org Message-ID: <878yu8zmlj.fsf@thalassa.informatimago.com> References: <445cd6bf.0304100110.360fdd1f@posting.google.com> <7263-Sat12Apr2003120721+0300-eliz@elta.co.il> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: main.gmane.org 1050625302 11793 80.91.224.249 (18 Apr 2003 00:21:42 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Fri, 18 Apr 2003 00:21:42 +0000 (UTC) Original-X-From: help-gnu-emacs-bounces+gnu-help-gnu-emacs=m.gmane.org@gnu.org Fri Apr 18 02:21:40 2003 Return-path: Original-Received: from monty-python.gnu.org ([199.232.76.173]) by main.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 196JcJ-00030X-00 for ; Fri, 18 Apr 2003 02:20:35 +0200 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.10.13) id 196Jc4-0005UO-04 for gnu-help-gnu-emacs@m.gmane.org; Thu, 17 Apr 2003 20:20:20 -0400 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!fu-berlin.de!uni-berlin.de!thalassa.informatimago.COM!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 107 Original-NNTP-Posting-Host: thalassa.informatimago.com (195.114.85.194) Original-X-Trace: fu-berlin.de 1050624984 3026536 195.114.85.194 (16 [41911]) User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3.50 Original-Xref: shelby.stanford.edu gnu.emacs.help:112078 Original-To: help-gnu-emacs@gnu.org X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1b5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Help: List-Post: List-Subscribe: , List-Archive: List-Unsubscribe: , Errors-To: help-gnu-emacs-bounces+gnu-help-gnu-emacs=m.gmane.org@gnu.org Xref: main.gmane.org gmane.emacs.help:8578 X-Report-Spam: http://spam.gmane.org/gmane.emacs.help:8578 John Kliff Jochens writes: > On Sat, 2003-04-12 at 07:07, Eli Zaretskii wrote: > > > > > > It doesn't scroll all the way to the bottom, stopping a couple of > > > lines before the end of the buffer. > > > And the scrolling text jitters up & down while scrolling. > > > > This is because Emacs sets the scroll-bar thumb size based on the > > number of characters, not lines. One reason is that Emacs doesn't > > count lines in the buffer unless specifically required to do so by > > some command. > > Now that you mentioned it, how can I have each line of the buffer > prefixed with its number? All I managed to do was to show on the line > with the file name (and etc), as well as the column, but I'd preffer to > have the line shown at the begginig of line. > > Anyone knows how to do that (GNU Emacs 21.2.1)? Perhaps faster than searching anything on the web and trying to install it inside emacs would be to write this in one's .emacs: (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 Then you may want to have line numbers inserted on new lines: (defun lse-newline () "Insert newline and line number incremented with the same step as previously." (interactive) (newline) (let ((nlpt (point)) (line (progn (forward-line -1) (beginning-of-line) (if (looking-at "[0-9]+") (let ((curr (string-to-number (match-string 0)))) (forward-line -1) (beginning-of-line) (if (looking-at "[0-9]+") (let ((prev (string-to-number (match-string 0)))) (+ curr (abs (- curr prev)))) (+ 10 curr))) 10)))) (goto-char nlpt) (beginning-of-line) (insert (format "%d " line)) (when (looking-at " +") (delete-region (match-beginning 0) (match-end 0))))) And activating with: (setq line-num-map (make-sparse-keymap)) (define-key line-num-map "\n" 'lse-newline) (define-key line-num-map "\r" 'lse-newline) and: M-x eval-expression RETURN (use-local-map line-num-map) RETURN in the buffer. (or you can add these keys to the map of the mode of these buffers). But then you have to renumber lines sometimes: (defun delete-line-numbers () (interactive) (save-excursion (save-restriction (widen) (goto-char (point-min)) (while (< (point) (point-max)) (if (looking-at "[0-9][0-9]* ") (delete-region (match-beginning 0) (match-end 0))) (forward-line)))) );;delete-line-numbers (defun renumber-lines () (interactive) (delete-line-numbers) (insert-line-numbers)) -- __Pascal_Bourguignon__ http://www.informatimago.com/ ---------------------------------------------------------------------- Do not adjust your mind, there is a fault in reality.