I've been using Vim for a while and now I've discovered Spacemacs and I found it great how it blends Vim ease of editing with Emacs superior power.
I really loved some parts of my Vim config, one of them was relative numbering.
In oder to have an idea, this is the Vim setup I'm trying to emulate (notice that relative numbering is off since Vim window doesn't have focus when taking the screen grab): vim setup
Trying to get the line numbering right aligned with a separator space in Spacemacs was quite complicated. But I'm finding it impossible to do the same for relative numbering. This is my code taken from emacs wiki for right aligned line numbering with a separator space:
(unless window-system
(add-hook 'linum-before-numbering-hook
(lambda ()
(setq-local linum-format-fmt
(let ((w (length (number-to-string
(count-lines (point-min) (point-max))))))
(concat "%" (number-to-string w) "d"))))))
(defun linum-format-func (line)
(concat
(propertize (format linum-format-fmt line) 'face 'linum)
(propertize " " 'face 'mode-line)))
(unless window-system
(setq linum-format 'linum-format-func))
Any idea on how to achieve the same thing for linum-relative?
EDIT 1: I've tried the following code:
(defvar my-linum-relative-format-string "%4s")
(defun my-linum-relative-get-format-string ()
(let* ((width (length (number-to-string
(count-lines (point-min) (point-max)))))
(format (concat "%" (number-to-string width) "s")))
(setq my-linum-relative-format-string format)))
(setq linum-relative-format 'my-linum-relative-format)
(defun my-linum-relative-format (line-number)
(propertize (format my-linum-relative-format-string line-number) 'face 'linum-relative))
But it fails with the error: Error in post-command-hook (linum-update-current): (wrong-type-argument stringp my-linum-relative-format)