GNU bug report logs -
#5042
23.1; linum-mode gives incorrect line numbers with narrowed buffers
Previous Next
Full log
Message #20 received at 5042 <at> emacsbugs.donarmstrong.com (full text, mbox):
On Thu, Dec 10, 2009 at 06:34, Mark Lillibridge <mark.lillibridge <at> hp.com> wrote:
> The entire point of having line numbers is that they correspond to
> something useful. Either an external program's line number (e.g., a gcc
> error number) or an internal Emacs notion such as that provided by
> goto-line. The current behavior does neither.
Well, there are many definitions of useful. I find the current
behavior useful, because my main use of linum is knowing at a glance
how many lines there are in the file (or in the region, if narrowing
is in effect).
> Note that other line numbering modes like wb-line-number implement
> the behavior that I describe as correct.
Yes. But linum allows you to use line numbers in a quite more flexible
way. You could do
(defvar num-of-lines nil)
(defvar num-format nil)
(make-variable-buffer-local 'num-of-lines)
(make-variable-buffer-local 'num-format)
(add-hook 'linum-before-numbering-hook
(lambda ()
(save-restriction
(widen)
(let ((lines (count-lines (point-min) (point-max))))
(setq num-format (format "%%%dd" (length
(int-to-string lines))))
(setq num-of-lines (1+ lines))))))
(setq linum-format
(lambda (line)
(format num-format (- num-of-lines line))))
if you fancied numbering lines in reverse, for example.
Juanma
This bug report was last modified 4 years and 228 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.