init-linum.el 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. ;;; init-nlinum.el --- .Emacs Configuration -*- lexical-binding: t -*-
  2. ;;; Commentary:
  3. ;;
  4. ;;; Code:
  5. ;;----------------------------------------------------------------------------
  6. ;; Line numbers
  7. ;;----------------------------------------------------------------------------
  8. ;; Linum snippets from: https://www.emacswiki.org/emacs/LineNumbers
  9. (use-package linum
  10. :config
  11. (defun my-linum-get-format ()
  12. "Defines LINUM-GET-FORMAT"
  13. (let* ((width (1+ (length (number-to-string
  14. (count-lines (point-min) (point-max))))))
  15. (format (concat "%" (number-to-string width) "d \u2502")))
  16. (setq my-linum-format-string format)))
  17. (add-hook 'linum-before-numbering-hook 'my-linum-get-format)
  18. (defun my-linum-format (line-number)
  19. "Defines LINE-FORMAT"
  20. (propertize (format my-linum-format-string line-number) 'face
  21. (if (eq line-number my-current-line)
  22. 'my-linum-hl
  23. 'linum)))
  24. (setq linum-format 'my-linum-format)
  25. (defadvice linum-update (around my-linum-update)
  26. "Defines LINUM-UPDATE for update lines"
  27. (let ((my-current-line (line-number-at-pos)))
  28. ad-do-it))
  29. (ad-activate 'linum-update)
  30. ;; Colors line active
  31. ;; set in file init-theme.el
  32. ;; for example:
  33. ;; (defface my-linum-hl
  34. ;; '((t :background "gray20" :foreground "gold"))
  35. ;; "Face for the currently active Line number"
  36. ;; :group 'linum)
  37. ;; )
  38. :bind
  39. (([f6] . linum-mode)))
  40. (provide 'init-linum)
  41. ;; Local Variables:
  42. ;; byte-compile-warnings: (not free-vars)
  43. ;; End:
  44. ;;; init-linum.el ends here