fd43e27eeb4d8bd938588ac8c029d54d22e45ef0
[dotfiles.git] / emacs.d / config / init-linum.el
1 ;; refer to https://github.com/aaronbieber/dotfiles/blob/master/configs/emacs.d/lisp/init-linum.el
2 ;; Stuff for line numbers.
3
4
5 (custom-set-faces
6  ;; custom-set-faces was added by Custom.
7  ;; If you edit it by hand, you could mess it up, so be careful.
8  ;; Your init file should contain only one such instance.
9  ;; If there is more than one, they won't work right.
10  '(highlight-current-line-face ((t (:background "gray22"))))
11  '(linum ((t (:background "#000000" :foreground "gray40" :height 0.8 :slant italic :weigth light))))
12  '(linum-relative-current-face ((t (:inherit linum :foreground "Yellow" :weight light :height 0.8)))))
13
14 (require 'linum-relative)
15
16 (defface linum-current
17 ;  '((t (:inherit linum :weight bold :underline "#555")))
18   '((t (:inherit linum :weight bold :foreground "Yellow")))
19   "The current line number.")
20
21 (defun my-linum-get-format-string ()
22  (let* ((width (max 3 (1+ (length (number-to-string
23                              (count-lines (point-min) (point-max)))))))
24          (format (concat "%" (number-to-string width) "d "))
25          (current-line-format (concat "%-" (number-to-string width) "d ")))
26     (setq my-linum-format-string format)
27 ;    (setq my-linum-current-line-format-string current-line-format)))
28     (setq my-linum-current-line-format-string format)))
29
30 (defvar my-linum-current-line-number 0)
31
32 (setq linum-format 'my-linum-relative-line-numbers)
33
34 (defun my-linum-relative-line-numbers (line-number)
35   (let* ((offset (abs (- line-number my-linum-current-line-number)))
36          (linum-display-value (if (= 0 offset)
37                            my-linum-current-line-number
38                                 offset))
39          (format-string (if (= my-linum-current-line-number line-number) my-linum-current-line-format-string my-linum-format-string))
40          (face (if (= my-linum-current-line-number line-number) 'linum-current 'linum)))
41     (propertize (format format-string linum-display-value) 'face face)))
42
43 (defadvice linum-update (around my-linum-update)
44   (let ((my-linum-current-line-number (line-number-at-pos)))
45     ad-do-it))
46 (ad-activate 'linum-update)
47
48 ;;; Set up relative line numbering to mimic `:set number relativenumber`.
49 (global-linum-mode t)
50 (add-hook 'linum-before-numbering-hook 'my-linum-get-format-string)
51
52
53
54
55
56 ;; enable linum-relative in programming mode
57 ;https://github.com/howardabrams/dot-files/blob/master/emacs.org
58 (add-hook 'prog-mode-hook 'linum-mode)
59
60 ;; hight current line
61 (require 'highlight-current-line)
62 (highlight-current-line-on t)
63
64
65
66 (provide 'init-linum)