|
From: | B. T. Raven |
Subject: | Re: Absolutely naïve question about line numbering and lisp code |
Date: | Tue, 03 Mar 2009 09:16:59 -0600 |
User-agent: | Thunderbird 2.0.0.19 (Windows/20081209) |
Armando Martins wrote:
Hello! I am trying to numer the lines of a text (not the buffer, although this solution could work around). I google and I find files in lisp code, say: num.el, setnu.el, line.el... How can I make it work on a text file I have. Do I download (wherever) and open it and click "evaluate lisp" and then it will work for all the session? I am using Windows Vista. Thanks for your help
Yes. Just copy that file (say, setnu.el) into say, site-lisp directory and then M-x load-library setnu. Now M-x setnu-mode should toggle line numbers on and off. 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-numbersOf course if you add or delete a line then you would have to delete the rectangle in the the line number "region" and re-run M-x insert-line-numbers. Not very flexible.
Ed
[Prev in Thread] | Current Thread | [Next in Thread] |