I noticed that whenever I narrow a region in emacs, the line numbering is relative to the narrowed region rather than being relative to the original file. Is there any way I can preserve the line numbering from the original buffer ?
A little late, but here's what I have in my .emacs. It does change the numbering for all linum-mode enabled buffers, but that's what I generally want:
(require 'linum) (defvar my-linum-base-line nil) (defvar my-linum-format nil) (add-hook 'linum-before-numbering-hook (lambda () (save-excursion (save-restriction (goto-char (point-min)) (widen) (setq my-linum-base-line (count-lines 1 (point))) (setq my-linum-format (format "%%%dd" (length (int-to-string (+ my-linum-base-line (count-lines (point) (point-max))))))))))) (setq-default linum-format (lambda (line) (format my-linum-format (+ line my-linum-base-line))))
There's probably many things wrong with this in regards to proper elisp use, but it seems to work for me :)