(defvar my-linum-current-line-number 0)
(setq linum-format 'my-linum-relative-line-numbers)
(defun my-linum-relative-line-numbers (line-number)
(let ((test2 (1+ (- line-number my-linum-current-line-number))))
(propertize
(number-to-string (cond ((<= test2 0) (1- test2))
((> test2 0) test2)))
'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)