-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlinum-highlight-current-line-number.el
81 lines (74 loc) · 2.87 KB
/
linum-highlight-current-line-number.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
;;; linum-highlight-current-line-number.el --- highlight the current line number
;;
;; Copyright (C) 2014-2017 Emanuele Tomasi <[email protected]>
;;
;; Author: Emanuele Tomasi <[email protected]>
;; URL: https://github.com/targzeta/linum-highlight-current-line-number
;; Maintainer: Emanuele Tomasi <[email protected]>
;; Keywords: convenience
;; Version: 1.0
;;
;; This file is NOT part of GNU Emacs.
;;
;; This program is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;;
;;; Commentary:
;;
;; A function for the `linum-format' variable to highlight the current line
;; number with a custom face.
;;
;;; Usage:
;;
;; Copy this file in a directory which is in the Emacs `load-path'. Then,
;; execute the following code either directly or in your .emacs file:
;;
;; (require 'linum-highlight-current-line-number)
;; (setq linum-format 'linum-highlight-current-line-number)
;;
;; Customization:
;;
;; You can change the face for the current line number with:
;;
;; M-x customize-group and then "linum". Finally, "Linum Current Line Number Face"
;;
;;; Code:
(require 'linum)
;; Customization
(defface linum-current-line-number-face
`((t :inherit linum
:foreground "goldenrod"
:weight bold))
"Face for displaying the current line number."
:group 'linum)
(defvar linum-current-line 1 "Current line number.")
(defvar linum-border-width 1 "Border width for linum.")
;; Functions
(defadvice linum-update (before advice-linum-update activate)
"Set the current line."
(setq linum-current-line (line-number-at-pos)
;; It's the same algorithm that linum dynamic. I only had added one
;; space in front of the first digit.
linum-border-width (number-to-string
(+ 1 (length
(number-to-string
(count-lines (point-min) (point-max))))))))
(defun linum-highlight-current-line-number (line-number)
"Highlight the current line number using `linum-current-line-number-face' face."
(let ((face (if (= line-number linum-current-line)
'linum-current-line-number-face
'linum)))
(propertize (format (concat "%" linum-border-width "d") line-number)
'face face)))
(provide 'linum-highlight-current-line-number)
;;; linum-highlight-current-line-number.el ends here