I installed linum relative with this. But installing this replaced my fixed linum. I want to have both fixed line number and relative line number as well. How can I do this?
-
Something hacky here: stackoverflow.com/questions/11612364/… ... though perhaps you could use the ideas to customize relative-linum's display. – Joe Corneli Sep 11 '16 at 1:22
-
Maybe (better than the above) use the idea here: emacs.stackexchange.com/questions/21445/… – Joe Corneli Sep 11 '16 at 1:27
-
I just use github.com/scottjad/linum-relativenumber which does it all. – izkon Sep 29 '17 at 16:32
-
This question seems pretty related: emacs.stackexchange.com/questions/36149/… – Att Righ Nov 5 '17 at 15:44
The following links linum wiki and stackoverflow similar issue help me to reach a solution with the following code :
(require 'linum)
(add-hook 'prog-mode-hook 'linum-mode)
(defvar my-linum-format-string "%3d")
(add-hook 'linum-before-numbering-hook 'my-linum-get-format-string)
(defun my-linum-get-format-string ()
(let* ((width (1+ (length (number-to-string
(count-lines (point-min) (point-max))))))
(format (concat "%d (%" (number-to-string width) "d)")))
(setq my-linum-format-string format)))
(defvar my-linum-current-line-number 0)
(setq linum-format 'my-linum-relative-line-numbers)
(defun my-linum-relative-line-numbers (line-number)
(let ((offset (- line-number my-linum-current-line-number))
(current (line-number-at-pos)))
(propertize (format my-linum-format-string current offset) 'face 'linum)))
(defadvice linum-update (around my-linum-update)
(let ((my-linum-current-line-number (line-number-at-pos)))
ad-do-it))
(ad-activate 'linum-update)
It will show in the right column the absolute number of the line and in parenthesis the relative number in regard to the current line.
izkons's comment above seems like an answer to me...
I just use https://github.com/scottjad/linum-relativenumber which does it all. – izkon
Some caveat's about this solution:
- This modifies
linum
settings so might not respect customizations - This might require a restart or a bunch of fiddling to
switch offdisable relative line numbers while keeping absolute line numbers.
Do you want to have them both running? Toggle?
You can try this package https://github.com/coldnew/linum-relative
And then I think you can toggle it
M-x linum-relative-toggle
-
In my question I have mentioned about the package, you have given. I want to have both of them running and shown on emacs. – Ansuman Bebarta Jul 17 '16 at 6:27
-
Hmm those downvotes strike me as a little unfair! So I'll give you some moral support! The general question of "easily see both absolute and relative line numbers" feels related enough to this question that this is a useful answer. – Att Righ Nov 5 '17 at 15:16