40
40
(require 'subr-x )
41
41
(require 'filenotify )
42
42
(require 'elquery )
43
+ (require 'color )
43
44
44
45
(defgroup cov nil
45
46
" The group for everything in cov.el."
@@ -89,6 +90,16 @@ See `fringe-bitmaps' for a full list of options"
89
90
:group 'cov
90
91
:type 'symbol )
91
92
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
+
92
103
(defface cov-heavy-face
93
104
'((((class color )) :foreground " red" ))
94
105
" Fringe indicator face used for heavily-run lines See `cov-high-threshold' ."
@@ -130,6 +141,47 @@ See `cov-coverage-mode'"
130
141
:tag " Cov coverage mode not-run face"
131
142
:group 'cov-faces )
132
143
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
+
133
185
(defvar cov-coverage-alist '((" .gcov" . gcov))
134
186
" Alist of coverage tool and file postfix.
135
187
@@ -552,7 +604,7 @@ Load FILE-PATH into temp buffer and parse it using `cov--FORMAT-parse'.
552
604
(setq-local cov-coverage-file file-path)
553
605
(funcall (intern (concat " cov--" (symbol-name format) " -parse" )))))
554
606
555
- (defun cov--make-overlay (line fringe help )
607
+ (defun cov--make-overlay (line fringe help highlight )
556
608
" Create an overlay for the LINE.
557
609
558
610
Uses the FRINGE and sets HELP as `help-echo' ."
@@ -562,6 +614,8 @@ Uses the FRINGE and sets HELP as `help-echo'."
562
614
(make-overlay (point ) (line-end-position )))))
563
615
(overlay-put ol 'before-string fringe )
564
616
(overlay-put ol 'help-echo help)
617
+ (when cov-highlight-lines
618
+ (overlay-put ol 'face highlight ))
565
619
(overlay-put ol 'cov t )
566
620
ol))
567
621
@@ -572,20 +626,20 @@ Selects the face depending on user preferences and the code's
572
626
execution frequency"
573
627
(cond
574
628
((and cov-coverage-mode (> percentage 0 ))
575
- 'cov-coverage-run-face )
629
+ '( cov-coverage-run-face . cov-coverage-run-hl-face) )
576
630
((and cov-coverage-mode (= percentage 0 ))
577
- 'cov-coverage-not-run-face )
631
+ '( cov-coverage-not-run-face . cov-coverage-not-run-hl-face) )
578
632
((< cov-high-threshold percentage)
579
- 'cov-heavy-face )
633
+ '( cov-heavy-face . cov-heavy-hl-face) )
580
634
((< cov-med-threshold percentage)
581
- 'cov-med-face )
635
+ '( cov-med-face . cov-med-hl-face) )
582
636
((> 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) )))
585
639
586
640
(defun cov--get-fringe (percentage )
587
641
" 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) ))))
589
643
590
644
(defun cov--help (n percentage )
591
645
" 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."
600
654
(cov--make-overlay
601
655
(car line)
602
656
(cov--get-fringe percentage)
603
- (cov--help times-executed percentage))))
657
+ (cov--help times-executed percentage)
658
+ (cdr (cov--get-face percentage)))))
604
659
605
660
(defsubst cov--file-mtime (file )
606
661
" Return the last modification time of FILE."
@@ -614,8 +669,8 @@ MAX is the maximum coverage count for any line in the file."
614
669
(mtime nil :type time :documentation " The mtime for the coverage file last time it was read." )
615
670
(buffers nil :type list :documentation " List of `cov-mode' buffers referring to this coverage data." )
616
671
(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
+
619
674
620
675
(defsubst cov-data--add-buffer (coverage buffer )
621
676
" Add BUFFER to COVERAGE if it not already there."
0 commit comments