Skip to content

Commit 44c2f0b

Browse files
committed
Add an option to highlight line background
1 parent ac73ff7 commit 44c2f0b

File tree

1 file changed

+66
-11
lines changed

1 file changed

+66
-11
lines changed

cov.el

Lines changed: 66 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
(require 'subr-x)
4141
(require 'filenotify)
4242
(require 'elquery)
43+
(require 'color)
4344

4445
(defgroup cov nil
4546
"The group for everything in cov.el."
@@ -89,6 +90,16 @@ See `fringe-bitmaps' for a full list of options"
8990
:group 'cov
9091
:type 'symbol)
9192

93+
(defcustom cov-highlight-lines nil
94+
"Hightlight lines."
95+
:group 'cov
96+
:type 'bool)
97+
98+
(defun cov--get-highlight-color (face)
99+
"Return a brighter color from FACE foreground."
100+
(let ((color (apply #'color-rgb-to-hsl (color-name-to-rgb (face-foreground face)))))
101+
(apply #'color-rgb-to-hex (color-hsl-to-rgb (nth 0 color) (nth 1 color) 0.95))))
102+
92103
(defface cov-heavy-face
93104
'((((class color)) :foreground "red"))
94105
"Fringe indicator face used for heavily-run lines See `cov-high-threshold'."
@@ -130,6 +141,47 @@ See `cov-coverage-mode'"
130141
:tag "Cov coverage mode not-run face"
131142
:group 'cov-faces)
132143

144+
(defface cov-heavy-hl-face
145+
`((((class color)) :background ,(cov--get-highlight-color 'cov-heavy-face)))
146+
"Hightlight face used for heavily-run lines See `cov-high-threshold'."
147+
:tag "Cov heavy-use face"
148+
:group 'cov-faces)
149+
150+
(defface cov-med-hl-face
151+
`((((class color)) :background ,(cov--get-highlight-color 'cov-med-face)))
152+
"Hightlight face used for commonly-run lines See `cov-med-threshold'."
153+
:tag "Cov medium-use face"
154+
:group 'cov-faces)
155+
156+
(defface cov-light-hl-face
157+
`((((class color)) :background ,(cov--get-highlight-color 'cov-light-face)))
158+
"Hightlight face used for rarely-run lines.
159+
160+
This face is applied if no other face is applied."
161+
:tag "Cov light-use face"
162+
:group 'cov-faces)
163+
164+
(defface cov-none-hl-face
165+
`((((class color)) :background ,(cov--get-highlight-color 'cov-none-face)))
166+
"Hightlight face used for lines which were not run."
167+
:tag "Cov never-used face"
168+
:group 'cov-faces)
169+
170+
(defface cov-coverage-run-hl-face
171+
`((((class color)) :background ,(cov--get-highlight-color 'cov-coverage-run-face)))
172+
"Hightlight face used in coverage mode for lines which were run.
173+
174+
See `cov-coverage-mode'"
175+
:tag "Cov coverage mode run face"
176+
:group 'cov-faces)
177+
178+
(defface cov-coverage-not-run-hl-face
179+
`((((class color)) :background ,(cov--get-highlight-color 'cov-coverage-not-run-face)))
180+
"Hightlight face used in coverage mode for lines which were not run.
181+
See `cov-coverage-mode'"
182+
:tag "Cov coverage mode not-run face"
183+
:group 'cov-faces)
184+
133185
(defvar cov-coverage-alist '((".gcov" . gcov))
134186
"Alist of coverage tool and file postfix.
135187
@@ -552,7 +604,7 @@ Load FILE-PATH into temp buffer and parse it using `cov--FORMAT-parse'.
552604
(setq-local cov-coverage-file file-path)
553605
(funcall (intern (concat "cov--" (symbol-name format) "-parse")))))
554606

555-
(defun cov--make-overlay (line fringe help)
607+
(defun cov--make-overlay (line fringe help highlight)
556608
"Create an overlay for the LINE.
557609
558610
Uses the FRINGE and sets HELP as `help-echo'."
@@ -562,6 +614,8 @@ Uses the FRINGE and sets HELP as `help-echo'."
562614
(make-overlay (point) (line-end-position)))))
563615
(overlay-put ol 'before-string fringe)
564616
(overlay-put ol 'help-echo help)
617+
(when cov-highlight-lines
618+
(overlay-put ol 'face highlight))
565619
(overlay-put ol 'cov t)
566620
ol))
567621

@@ -572,20 +626,20 @@ Selects the face depending on user preferences and the code's
572626
execution frequency"
573627
(cond
574628
((and cov-coverage-mode (> percentage 0))
575-
'cov-coverage-run-face)
629+
'(cov-coverage-run-face . cov-coverage-run-hl-face))
576630
((and cov-coverage-mode (= percentage 0))
577-
'cov-coverage-not-run-face)
631+
'(cov-coverage-not-run-face . cov-coverage-not-run-hl-face))
578632
((< cov-high-threshold percentage)
579-
'cov-heavy-face)
633+
'(cov-heavy-face . cov-heavy-hl-face))
580634
((< cov-med-threshold percentage)
581-
'cov-med-face)
635+
'(cov-med-face . cov-med-hl-face))
582636
((> percentage 0)
583-
'cov-light-face)
584-
(t 'cov-none-face)))
637+
'(cov-light-face . cov-light-hl-face))
638+
(t '(cov-none-face . cov-none-hl-face))))
585639

586640
(defun cov--get-fringe (percentage)
587641
"Return the fringe with the correct face for PERCENTAGE."
588-
(propertize "f" 'display `(left-fringe ,cov-fringe-symbol ,(cov--get-face percentage))))
642+
(propertize "f" 'display `(left-fringe ,cov-fringe-symbol ,(car (cov--get-face percentage)))))
589643

590644
(defun cov--help (n percentage)
591645
"Return help text for the given N count and PERCENTAGE."
@@ -600,7 +654,8 @@ MAX is the maximum coverage count for any line in the file."
600654
(cov--make-overlay
601655
(car line)
602656
(cov--get-fringe percentage)
603-
(cov--help times-executed percentage))))
657+
(cov--help times-executed percentage)
658+
(cdr (cov--get-face percentage)))))
604659

605660
(defsubst cov--file-mtime (file)
606661
"Return the last modification time of FILE."
@@ -614,8 +669,8 @@ MAX is the maximum coverage count for any line in the file."
614669
(mtime nil :type time :documentation "The mtime for the coverage file last time it was read.")
615670
(buffers nil :type list :documentation "List of `cov-mode' buffers referring to this coverage data.")
616671
(watcher nil :type watcher :documentation "The file notification watcher.")
617-
(coverage nil :type alist :documentation "An alist of (FILE . ((LINE-NUM TIMES-RAN) ...)).")
618-
)
672+
(coverage nil :type alist :documentation "An alist of (FILE . ((LINE-NUM TIMES-RAN) ...))."))
673+
619674

620675
(defsubst cov-data--add-buffer (coverage buffer)
621676
"Add BUFFER to COVERAGE if it not already there."

0 commit comments

Comments
 (0)