unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Teemu Likonen <tlikonen@iki.fi>
To: help-gnu-emacs@gnu.org
Subject: Re: Absolutely naïve question about line numbering and lisp code
Date: Tue, 03 Mar 2009 16:25:39 GMT	[thread overview]
Message-ID: <87skluk1z0.fsf@iki.fi> (raw)
In-Reply-To: YrudnSDyrPB_1DDUnZ2dnUVZ_rjinZ2d@posted.cpinternet

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


  reply	other threads:[~2009-03-03 16:25 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 ` Absolutely naïve question about line numbering and lisp code B. T. Raven
2009-03-03 16:25   ` Teemu Likonen [this message]
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

  List information: https://www.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to=87skluk1z0.fsf@iki.fi \
    --to=tlikonen@iki.fi \
    --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.
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).