all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "B. T. Raven" <nihil@nihilo.net>
To: help-gnu-emacs@gnu.org
Subject: Re: Absolutely naïve question about line numbering and lisp code
Date: Tue, 03 Mar 2009 09:16:59 -0600	[thread overview]
Message-ID: <YrudnSDyrPB_1DDUnZ2dnUVZ_rjinZ2d@posted.cpinternet> (raw)
In-Reply-To: <mailman.2269.1236085285.31690.help-gnu-emacs@gnu.org>

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-numbers

Of 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


       reply	other threads:[~2009-03-03 15:16 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <mailman.2269.1236085285.31690.help-gnu-emacs@gnu.org>
2009-03-03 15:16 ` B. T. Raven [this message]
2009-03-03 16:25   ` Absolutely naïve question about line numbering and lisp code Teemu Likonen
2009-03-03 13:01 Armando Martins
2009-03-03 13:08 ` Andy Stewart

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YrudnSDyrPB_1DDUnZ2dnUVZ_rjinZ2d@posted.cpinternet \
    --to=nihil@nihilo.net \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.