* Re: Absolutely naïve question about line numbering and lisp code
[not found] <mailman.2269.1236085285.31690.help-gnu-emacs@gnu.org>
@ 2009-03-03 15:16 ` B. T. Raven
2009-03-03 16:25 ` Teemu Likonen
0 siblings, 1 reply; 4+ messages in thread
From: B. T. Raven @ 2009-03-03 15:16 UTC (permalink / raw)
To: help-gnu-emacs
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
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Absolutely naïve question about line numbering and lisp code
2009-03-03 15:16 ` Absolutely naïve question about line numbering and lisp code B. T. Raven
@ 2009-03-03 16:25 ` Teemu Likonen
0 siblings, 0 replies; 4+ messages in thread
From: Teemu Likonen @ 2009-03-03 16:25 UTC (permalink / raw)
To: help-gnu-emacs
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
^ permalink raw reply [flat|nested] 4+ messages in thread
* Absolutely naïve question about line numbering and lisp code
@ 2009-03-03 13:01 Armando Martins
2009-03-03 13:08 ` Andy Stewart
0 siblings, 1 reply; 4+ messages in thread
From: Armando Martins @ 2009-03-03 13:01 UTC (permalink / raw)
To: help-gnu-emacs
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
--
Com os melhores cumprimentos,
Armando Martins
Departamento de Linguística e Literaturas
Universidade de Évora, Largo dos Colegiais nº 2
7004-516 ÉVORA
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Absolutely naïve question about line numbering and lisp code
2009-03-03 13:01 Armando Martins
@ 2009-03-03 13:08 ` Andy Stewart
0 siblings, 0 replies; 4+ messages in thread
From: Andy Stewart @ 2009-03-03 13:08 UTC (permalink / raw)
To: help-gnu-emacs
Armando Martins <armandosenra@gmail.com> writes:
> 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
Hi,
Try linum.el
-- Andy
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2009-03-03 16:25 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <mailman.2269.1236085285.31690.help-gnu-emacs@gnu.org>
2009-03-03 15:16 ` Absolutely naïve question about line numbering and lisp code B. T. Raven
2009-03-03 16:25 ` Teemu Likonen
2009-03-03 13:01 Armando Martins
2009-03-03 13:08 ` Andy Stewart
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).