8
;; License: GPL
9
;; Keywords: git, version control, release management
10
;;
11
-;; Compatibility: Emacs21
12
-
11
+;; Compatibility: Emacs21, Emacs22 and EmacsCVS
12
+;; Git 1.5 and up
13
14
;; This file is *NOT* part of GNU Emacs.
15
;; This file is distributed under the same terms as GNU Emacs.
61
62
;;; Compatibility:
63
;;
64
-;; It requires GNU Emacs 21. If you'are using Emacs 20, try
65
-;; changing this:
64
+;; It requires GNU Emacs 21 or later and Git 1.5.0 and up
65
+;;
66
+;; If you'are using Emacs 20, try changing this:
67
;;
68
;; (overlay-put ovl 'face (list :background
69
;; (cdr (assq 'color (cddddr info)))))
78
;;
79
;;; Code:
80
80
-(require 'cl) ; to use `push', `pop'
81
-
82
-(defun color-scale (l)
83
- (let* ((colors ())
84
- r g b)
85
- (setq r l)
86
- (while r
87
- (setq g l)
88
- (while g
89
- (setq b l)
90
- (while b
91
- (push (concat "#" (car r) (car g) (car b)) colors)
92
- (pop b))
93
- (pop g))
94
- (pop r))
95
- colors))
81
+(eval-when-compile (require 'cl)) ; to use `push', `pop'
82
+
83
+
84
+(defun git-blame-color-scale (&rest elements)
85
+ "Given a list, returns a list of triples formed with each
86
+elements of the list.
87
+
88
+a b => bbb bba bab baa abb aba aaa aab"
89
+ (let (result)
90
+ (dolist (a elements)
91
+ (dolist (b elements)
92
+ (dolist (c elements)
93
+ (setq result (cons (format "#%s%s%s" a b c) result)))))
94
+ result))
95
+
96
+;; (git-blame-color-scale "0c" "04" "24" "1c" "2c" "34" "14" "3c") =>
97
+;; ("#3c3c3c" "#3c3c14" "#3c3c34" "#3c3c2c" "#3c3c1c" "#3c3c24"
98
+;; "#3c3c04" "#3c3c0c" "#3c143c" "#3c1414" "#3c1434" "#3c142c" ...)
99
+
100
+(defmacro git-blame-random-pop (l)
101
+ "Select a random element from L and returns it. Also remove
102
+selected element from l."
103
+ ;; only works on lists with unique elements
104
+ `(let ((e (elt ,l (random (length ,l)))))
105
+ (setq ,l (remove e ,l))
106
+ e))
107
108
(defvar git-blame-dark-colors
98
- (color-scale '("0c" "04" "24" "1c" "2c" "34" "14" "3c")))
109
+ (git-blame-color-scale "0c" "04" "24" "1c" "2c" "34" "14" "3c")
110
+ "*List of colors (format #RGB) to use in a dark environment.
111
+
112
+To check out the list, evaluate (list-colors-display git-blame-dark-colors).")
113
114
(defvar git-blame-light-colors
101
- (color-scale '("c4" "d4" "cc" "dc" "f4" "e4" "fc" "ec")))
115
+ (git-blame-color-scale "c4" "d4" "cc" "dc" "f4" "e4" "fc" "ec")
116
+ "*List of colors (format #RGB) to use in a light environment.
117
+
118
+To check out the list, evaluate (list-colors-display git-blame-light-colors).")
119
103
-(defvar git-blame-ancient-color "dark green")
120
+(defvar git-blame-colors '()
121
+ "Colors used by git-blame. The list is built once when activating git-blame
122
+minor mode.")
123
+
124
+(defvar git-blame-ancient-color "dark green"
125
+ "*Color to be used for ancient commit.")
126
127
(defvar git-blame-autoupdate t
128
"*Automatically update the blame display while editing")
147
"A queue of update requests")
148
(make-variable-buffer-local 'git-blame-update-queue)
149
150
+;; FIXME: docstrings
151
+(defvar git-blame-file nil)
152
+(defvar git-blame-current nil)
153
+
154
(defvar git-blame-mode nil)
155
(make-variable-buffer-local 'git-blame-mode)
156
203
"Recalculate all blame information in the current buffer"
204
(interactive)
205
(unless git-blame-mode
180
- (error "git-blame is not active"))
206
+ (error "Git-blame is not active"))
207
208
(git-blame-cleanup)
209
(git-blame-run))
320
(t
321
nil)))
322
297
-
323
(defun git-blame-new-commit (hash src-line res-line num-lines)
324
(save-excursion
325
(set-buffer git-blame-file)
327
(inhibit-point-motion-hooks t)
328
(inhibit-modification-hooks t))
329
(when (not info)
305
- (let ((color (pop git-blame-colors)))
306
- (unless color
307
- (setq color git-blame-ancient-color))
330
+ ;; Assign a random color to each new commit info
331
+ ;; Take care not to select the same color multiple times
332
+ (let ((color (if git-blame-colors
333
+ (git-blame-random-pop git-blame-colors)
334
+ git-blame-ancient-color)))
335
(setq info (list hash src-line res-line num-lines
336
(git-describe-commit hash)
337
(cons 'color color))))