[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#5042: 23.1; linum-mode gives incorrect line numbers with narrowed b
From: |
Juanma Barranquero |
Subject: |
bug#5042: 23.1; linum-mode gives incorrect line numbers with narrowed buffers |
Date: |
Thu, 10 Dec 2009 12:41:21 +0100 |
On Thu, Dec 10, 2009 at 06:34, Mark Lillibridge <mark.lillibridge@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
- bug#5042: 23.1; linum-mode gives incorrect line numbers with narrowed buffers, Mark Lillibridge, 2009/12/10
- bug#5042: 23.1; linum-mode gives incorrect line numbers with narrowed buffers,
Juanma Barranquero <=
- bug#5042: 23.1; linum-mode gives incorrect line numbers with narrowed buffers, Mark Lillibridge, 2009/12/21
- bug#5042: 23.1; linum-mode gives incorrect line numbers with narrowed buffers, Juanma Barranquero, 2009/12/21
- bug#5042: 23.1; linum-mode gives incorrect line numbers with narrowed buffers, Drew Adams, 2009/12/21
- bug#5042: 23.1; linum-mode gives incorrect line numbers with narrowed buffers, Mark Lillibridge, 2009/12/23
- bug#5042: 23.1; linum-mode gives incorrect line numbers with narrowed buffers, Drew Adams, 2009/12/23
- bug#5042: 23.1; linum-mode gives incorrect line numbers with narrowed buffers, Mark Lillibridge, 2009/12/23
- bug#5042: 23.1; linum-mode gives incorrect line numbers with narrowed buffers, Stefan Monnier, 2009/12/23
- bug#5042: 23.1; linum-mode gives incorrect line numbers with narrowed buffers, Kevin Rodgers, 2009/12/30