1 ;;; vc-annotate.el --- VC Annotate Support
3 ;; Copyright (C) 1997-1998, 2000-2011 Free Software Foundation, Inc.
5 ;; Author: Martin Lorentzson <emwson@emw.ericsson.se>
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software: you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation, either version 3 of the License, or
15 ;; (at your option) any later version.
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
35 (defcustom vc-annotate-display-mode
'fullscale
36 "Which mode to color the output of \\[vc-annotate] with by default."
37 :type
'(choice (const :tag
"By Color Map Range" nil
)
38 (const :tag
"Scale to Oldest" scale
)
39 (const :tag
"Scale Oldest->Newest" fullscale
)
40 (number :tag
"Specify Fractional Number of Days"
44 (defcustom vc-annotate-color-map
45 (if (and (tty-display-color-p) (<= (display-color-cells) 8))
46 ;; A custom sorted TTY colormap
52 (string-equal (car x
) "white")
53 (string-equal (car x
) "black") ))
58 ((or (string-equal a
"red") (string-equal b
"blue")) t
)
59 ((or (string-equal b
"red") (string-equal a
"blue")) nil
)
60 ((string-equal a
"yellow") t
)
61 ((string-equal b
"yellow") nil
)
62 ((string-equal a
"cyan") t
)
63 ((string-equal b
"cyan") nil
)
64 ((string-equal a
"green") t
)
65 ((string-equal b
"green") nil
)
66 ((string-equal a
"magenta") t
)
67 ((string-equal b
"magenta") nil
)
70 (delta (/ (- 360. date
) (1- (length colors
)))))
74 (setq date
(+ date delta
)))) colors
))
75 ;; Normal colormap: hue stepped from 0-240deg, value=1., saturation=0.75
94 "Association list of age versus color, for \\[vc-annotate].
95 Ages are given in units of fractional days. Default is eighteen
96 steps using a twenty day increment, from red to blue. For TTY
97 displays with 8 or fewer colors, the default is red to blue with
98 all other colors between (excluding black and white)."
102 (defcustom vc-annotate-very-old-color
"#3F3FFF"
103 "Color for lines older than the current color range in \\[vc-annotate]."
107 (defcustom vc-annotate-background
"black"
108 "Background color for \\[vc-annotate].
109 Default color is used if nil."
110 :type
'(choice (const :tag
"Default background" nil
) (color))
113 (defcustom vc-annotate-menu-elements
'(2 0.5 0.1 0.01)
114 "Menu elements for the mode-specific menu of VC-Annotate mode.
115 List of factors, used to expand/compress the time scale. See `vc-annotate'."
116 :type
'(repeat number
)
119 (defvar vc-annotate-mode-map
120 (let ((m (make-sparse-keymap)))
121 (define-key m
"a" 'vc-annotate-revision-previous-to-line
)
122 (define-key m
"d" 'vc-annotate-show-diff-revision-at-line
)
123 (define-key m
"D" 'vc-annotate-show-changeset-diff-revision-at-line
)
124 (define-key m
"f" 'vc-annotate-find-revision-at-line
)
125 (define-key m
"j" 'vc-annotate-revision-at-line
)
126 (define-key m
"l" 'vc-annotate-show-log-revision-at-line
)
127 (define-key m
"n" 'vc-annotate-next-revision
)
128 (define-key m
"p" 'vc-annotate-prev-revision
)
129 (define-key m
"w" 'vc-annotate-working-revision
)
130 (define-key m
"v" 'vc-annotate-toggle-annotation-visibility
)
132 "Local keymap used for VC-Annotate mode.")
134 ;;; Annotate functionality
136 ;; Declare globally instead of additional parameter to
137 ;; temp-buffer-show-function (not possible to pass more than one
138 ;; parameter). The use of annotate-ratio is deprecated in favor of
139 ;; annotate-mode, which replaces it with the more sensible "span-to
140 ;; days", along with autoscaling support.
141 (defvar vc-annotate-ratio nil
"Global variable.")
143 ;; internal buffer-local variables
144 (defvar vc-annotate-backend nil
)
145 (defvar vc-annotate-parent-file nil
)
146 (defvar vc-annotate-parent-rev nil
)
147 (defvar vc-annotate-parent-display-mode nil
)
149 (defconst vc-annotate-font-lock-keywords
150 ;; The fontification is done by vc-annotate-lines instead of font-lock.
151 '((vc-annotate-lines)))
153 (define-derived-mode vc-annotate-mode special-mode
"Annotate"
154 "Major mode for output buffers of the `vc-annotate' command.
156 You can use the mode-specific menu to alter the time-span of the used
157 colors. See variable `vc-annotate-menu-elements' for customizing the
159 ;; Frob buffer-invisibility-spec so that if it is originally a naked t,
160 ;; it will become a list, to avoid initial annotations being invisible.
161 (add-to-invisibility-spec 'foo
)
162 (remove-from-invisibility-spec 'foo
)
163 (set (make-local-variable 'truncate-lines
) t
)
164 (set (make-local-variable 'font-lock-defaults
)
165 '(vc-annotate-font-lock-keywords t
))
166 (hack-dir-local-variables-non-file-buffer))
168 (defun vc-annotate-toggle-annotation-visibility ()
169 "Toggle whether or not the annotation is visible."
171 (funcall (if (memq 'vc-annotate-annotation buffer-invisibility-spec
)
172 'remove-from-invisibility-spec
173 'add-to-invisibility-spec
)
174 'vc-annotate-annotation
)
175 (force-window-update (current-buffer)))
177 (defun vc-annotate-display-default (ratio)
178 "Display the output of \\[vc-annotate] using the default color range.
179 The color range is given by `vc-annotate-color-map', scaled by RATIO.
180 The current time is used as the offset."
181 (interactive (progn (kill-local-variable 'vc-annotate-color-map
) '(1.0
)))
182 (message "Redisplaying annotation...")
183 (vc-annotate-display ratio
)
184 (message "Redisplaying annotation...done"))
186 (defun vc-annotate-oldest-in-map (color-map)
187 "Return the oldest time in the COLOR-MAP."
188 ;; Since entries should be sorted, we can just use the last one.
189 (caar (last color-map
)))
191 (defun vc-annotate-get-time-set-line-props ()
193 (date (vc-call-backend vc-annotate-backend
'annotate-time
))
194 (inhibit-read-only t
))
195 (assert (>= (point) bol
))
196 (put-text-property bol
(point) 'invisible
'vc-annotate-annotation
)
199 (defun vc-annotate-display-autoscale (&optional full
)
200 "Highlight the output of \\[vc-annotate] using an autoscaled color map.
201 Autoscaling means that the map is scaled from the current time to the
202 oldest annotation in the buffer, or, with prefix argument FULL, to
203 cover the range from the oldest annotation to the newest."
206 (oldest 999999.
) ;Any CVS users at the founding of Rome?
207 (current (vc-annotate-convert-time (current-time)))
209 (message "Redisplaying annotation...")
210 ;; Run through this file and find the oldest and newest dates annotated.
212 (goto-char (point-min))
214 (when (setq date
(vc-annotate-get-time-set-line-props))
215 (when (> date newest
)
217 (when (< date oldest
)
221 (/ (- (if full newest current
) oldest
)
222 (vc-annotate-oldest-in-map vc-annotate-color-map
))
224 (message "Redisplaying annotation...done \(%s\)"
226 (format "Spanned from %.1f to %.1f days old"
229 (format "Spanned to %.1f days old" (- current oldest
))))))
231 ;; Menu -- Using easymenu.el
232 (easy-menu-define vc-annotate-mode-menu vc-annotate-mode-map
233 "VC Annotate Display Menu"
235 ["By Color Map Range" (unless (null vc-annotate-display-mode
)
236 (setq vc-annotate-display-mode nil
)
237 (vc-annotate-display-select))
238 :style toggle
:selected
(null vc-annotate-display-mode
)]
239 ,@(let ((oldest-in-map (vc-annotate-oldest-in-map vc-annotate-color-map
)))
240 (mapcar (lambda (element)
241 (let ((days (* element oldest-in-map
)))
242 `[,(format "Span %.1f days" days
)
243 (vc-annotate-display-select nil
,days
)
244 :style toggle
:selected
245 (eql vc-annotate-display-mode
,days
) ]))
246 vc-annotate-menu-elements
))
248 (vc-annotate-display-select
249 nil
(float (string-to-number (read-string "Span how many days? "))))]
252 (unless (eq vc-annotate-display-mode
'scale
)
253 (vc-annotate-display-select nil
'scale
))
255 "Use an autoscaled color map from the oldest annotation to the current time"
256 :style toggle
:selected
257 (eq vc-annotate-display-mode
'scale
)]
258 ["Span Oldest->Newest"
259 (unless (eq vc-annotate-display-mode
'fullscale
)
260 (vc-annotate-display-select nil
'fullscale
))
262 "Use an autoscaled color map from the oldest to the newest annotation"
263 :style toggle
:selected
264 (eq vc-annotate-display-mode
'fullscale
)]
266 ["Toggle annotation visibility" vc-annotate-toggle-annotation-visibility
268 "Toggle whether the annotation is visible or not"]
269 ["Annotate previous revision" vc-annotate-prev-revision
270 :help
"Visit the annotation of the revision previous to this one"]
271 ["Annotate next revision" vc-annotate-next-revision
272 :help
"Visit the annotation of the revision after this one"]
273 ["Annotate revision at line" vc-annotate-revision-at-line
275 "Visit the annotation of the revision identified in the current line"]
276 ["Annotate revision previous to line" vc-annotate-revision-previous-to-line
277 :help
"Visit the annotation of the revision before the revision at line"]
278 ["Annotate latest revision" vc-annotate-working-revision
279 :help
"Visit the annotation of the working revision of this file"]
281 ["Show log of revision at line" vc-annotate-show-log-revision-at-line
282 :help
"Visit the log of the revision at line"]
283 ["Show diff of revision at line" vc-annotate-show-diff-revision-at-line
284 :help
"Visit the diff of the revision at line from its previous revision"]
285 ["Show changeset diff of revision at line"
286 vc-annotate-show-changeset-diff-revision-at-line
288 (eq 'repository
(vc-call-backend ,vc-annotate-backend
'revision-granularity
))
289 :help
"Visit the diff of the revision at line from its previous revision"]
290 ["Visit revision at line" vc-annotate-find-revision-at-line
291 :help
"Visit the revision identified in the current line"]))
293 (defun vc-annotate-display-select (&optional buffer mode
)
294 "Highlight the output of \\[vc-annotate].
295 By default, the current buffer is highlighted, unless overridden by
296 BUFFER. `vc-annotate-display-mode' specifies the highlighting mode to
297 use; you may override this using the second optional arg MODE."
299 (when mode
(setq vc-annotate-display-mode mode
))
300 (pop-to-buffer (or buffer
(current-buffer)))
301 (cond ((null vc-annotate-display-mode
)
302 ;; The ratio is global, thus relative to the global color-map.
303 (kill-local-variable 'vc-annotate-color-map
)
304 (vc-annotate-display-default (or vc-annotate-ratio
1.0)))
305 ;; One of the auto-scaling modes
306 ((eq vc-annotate-display-mode
'scale
)
307 (vc-exec-after `(vc-annotate-display-autoscale)))
308 ((eq vc-annotate-display-mode
'fullscale
)
309 (vc-exec-after `(vc-annotate-display-autoscale t
)))
310 ((numberp vc-annotate-display-mode
) ; A fixed number of days lookback
311 (vc-annotate-display-default
312 (/ vc-annotate-display-mode
313 (vc-annotate-oldest-in-map vc-annotate-color-map
))))
314 (t (error "No such display mode: %s"
315 vc-annotate-display-mode
))))
318 (defun vc-annotate (file rev
&optional display-mode buf move-point-to vc-bk
)
319 "Display the edit history of the current FILE using colors.
321 This command creates a buffer that shows, for each line of the current
322 file, when it was last edited and by whom. Additionally, colors are
323 used to show the age of each line--blue means oldest, red means
324 youngest, and intermediate colors indicate intermediate ages. By
325 default, the time scale stretches back one year into the past;
326 everything that is older than that is shown in blue.
328 With a prefix argument, this command asks two questions in the
329 minibuffer. First, you may enter a revision number REV; then the buffer
330 displays and annotates that revision instead of the working revision
331 \(type RET in the minibuffer to leave that default unchanged). Then,
332 you are prompted for the time span in days which the color range
333 should cover. For example, a time span of 20 days means that changes
334 over the past 20 days are shown in red to blue, according to their
335 age, and everything that is older than that is shown in blue.
337 If MOVE-POINT-TO is given, move the point to that line.
339 If VC-BK is given used that VC backend.
341 Customization variables:
343 `vc-annotate-menu-elements' customizes the menu elements of the
344 mode-specific menu. `vc-annotate-color-map' and
345 `vc-annotate-very-old-color' define the mapping of time to colors.
346 `vc-annotate-background' specifies the background color."
349 (vc-ensure-vc-buffer)
350 (list buffer-file-name
351 (let ((def (vc-working-revision buffer-file-name
)))
352 (if (null current-prefix-arg
) def
354 (format "Annotate from revision (default %s): " def
)
355 (list buffer-file-name
) nil def
)))
356 (if (null current-prefix-arg
)
357 vc-annotate-display-mode
358 (float (string-to-number
359 (read-string "Annotate span days (default 20): "
361 (vc-ensure-vc-buffer)
362 (setq vc-annotate-display-mode display-mode
) ;Not sure why. --Stef
363 (let* ((temp-buffer-name (format "*Annotate %s (rev %s)*" (buffer-name) rev
))
364 (temp-buffer-show-function 'vc-annotate-display-select
)
365 ;; If BUF is specified, we presume the caller maintains current line,
366 ;; so we don't need to do it here. This implementation may give
367 ;; strange results occasionally in the case of REV != WORKFILE-REV.
368 (current-line (or move-point-to
(unless buf
371 (line-number-at-pos))))))
372 (message "Annotating...")
373 ;; If BUF is specified it tells in which buffer we should put the
374 ;; annotations. This is used when switching annotations to another
375 ;; revision, so we should update the buffer's name.
376 (when buf
(with-current-buffer buf
377 (rename-buffer temp-buffer-name t
)
378 ;; In case it had to be uniquified.
379 (setq temp-buffer-name
(buffer-name))))
380 (with-output-to-temp-buffer temp-buffer-name
381 (let ((backend (or vc-bk
(vc-backend file
)))
382 (coding-system-for-read buffer-file-coding-system
))
383 (vc-call-backend backend
'annotate-command file
384 (get-buffer temp-buffer-name
) rev
)
385 ;; we must setup the mode first, and then set our local
386 ;; variables before the show-function is called at the exit of
387 ;; with-output-to-temp-buffer
388 (with-current-buffer temp-buffer-name
389 (unless (equal major-mode
'vc-annotate-mode
)
391 (set (make-local-variable 'vc-annotate-backend
) backend
)
392 (set (make-local-variable 'vc-annotate-parent-file
) file
)
393 (set (make-local-variable 'vc-annotate-parent-rev
) rev
)
394 (set (make-local-variable 'vc-annotate-parent-display-mode
)
397 (with-current-buffer temp-buffer-name
400 ;; Ideally, we'd rather not move point if the user has already
401 ;; moved it elsewhere, but really point here is not the position
402 ;; of the user's cursor :-(
403 (when ,current-line
;(and (bobp))
404 (goto-line ,current-line
)
405 (setq vc-sentinel-movepoint
(point)))
406 (unless (active-minibuffer-window)
407 (message "Annotating... done")))))))
409 (defun vc-annotate-prev-revision (prefix)
410 "Visit the annotation of the revision previous to this one.
412 With a numeric prefix argument, annotate the revision that many
415 (vc-annotate-warp-revision (- 0 prefix
)))
417 (defun vc-annotate-next-revision (prefix)
418 "Visit the annotation of the revision after this one.
420 With a numeric prefix argument, annotate the revision that many
423 (vc-annotate-warp-revision prefix
))
425 (defun vc-annotate-working-revision ()
426 "Visit the annotation of the working revision of this file."
428 (if (not (equal major-mode
'vc-annotate-mode
))
429 (message "Cannot be invoked outside of a vc annotate buffer")
430 (let ((warp-rev (vc-working-revision vc-annotate-parent-file
)))
431 (if (equal warp-rev vc-annotate-parent-rev
)
432 (message "Already at revision %s" warp-rev
)
433 (vc-annotate-warp-revision warp-rev
)))))
435 (defun vc-annotate-extract-revision-at-line ()
436 "Extract the revision number of the current line.
437 Return a cons (REV . FILENAME)."
438 ;; This function must be invoked from a buffer in vc-annotate-mode
439 (let ((rev (vc-call-backend vc-annotate-backend
440 'annotate-extract-revision-at-line
)))
441 (if (or (null rev
) (consp rev
))
443 (cons rev vc-annotate-parent-file
))))
445 (defun vc-annotate-revision-at-line ()
446 "Visit the annotation of the revision identified in the current line."
448 (if (not (equal major-mode
'vc-annotate-mode
))
449 (message "Cannot be invoked outside of a vc annotate buffer")
450 (let ((rev-at-line (vc-annotate-extract-revision-at-line)))
451 (if (not rev-at-line
)
452 (message "Cannot extract revision number from the current line")
453 (if (and (equal (car rev-at-line
) vc-annotate-parent-rev
)
454 (string= (cdr rev-at-line
) vc-annotate-parent-file
))
455 (message "Already at revision %s" rev-at-line
)
456 (vc-annotate-warp-revision (car rev-at-line
) (cdr rev-at-line
)))))))
458 (defun vc-annotate-find-revision-at-line ()
459 "Visit the revision identified in the current line."
461 (if (not (equal major-mode
'vc-annotate-mode
))
462 (message "Cannot be invoked outside of a vc annotate buffer")
463 (let ((rev-at-line (vc-annotate-extract-revision-at-line)))
464 (if (not rev-at-line
)
465 (message "Cannot extract revision number from the current line")
466 (switch-to-buffer-other-window
467 (vc-find-revision (cdr rev-at-line
) (car rev-at-line
) vc-annotate-backend
))))))
469 (defun vc-annotate-revision-previous-to-line ()
470 "Visit the annotation of the revision before the revision at line."
472 (if (not (equal major-mode
'vc-annotate-mode
))
473 (message "Cannot be invoked outside of a vc annotate buffer")
474 (let* ((rev-at-line (vc-annotate-extract-revision-at-line))
476 (rev (car rev-at-line
))
477 (fname (cdr rev-at-line
)))
478 (if (not rev-at-line
)
479 (message "Cannot extract revision number from the current line")
481 (vc-call-backend vc-annotate-backend
'previous-revision
483 (vc-annotate-warp-revision prev-rev fname
)))))
485 (defvar log-view-vc-backend
)
486 (defvar log-view-vc-fileset
)
488 (defun vc-annotate-show-log-revision-at-line ()
489 "Visit the log of the revision at line.
490 If the VC backend supports it, only show the log entry for the revision.
491 If a *vc-change-log* buffer exists and already shows a log for
492 the file in question, search for the log entry required and move point ."
494 (if (not (equal major-mode
'vc-annotate-mode
))
495 (message "Cannot be invoked outside of a vc annotate buffer")
496 (let ((rev-at-line (vc-annotate-extract-revision-at-line)))
497 (if (not rev-at-line
)
498 (message "Cannot extract revision number from the current line")
499 (let ((backend vc-annotate-backend
)
500 (log-buf (get-buffer "*vc-change-log*"))
504 ;; Look for a log buffer that already displays the correct file.
505 (with-current-buffer log-buf
506 (and (eq backend log-view-vc-backend
)
507 (null (cdr log-view-vc-fileset
))
508 (string= (car log-view-vc-fileset
) (cdr rev-at-line
))
509 ;; Check if the entry we require can be found.
511 backend
'show-log-entry
(car rev-at-line
))
512 (setq pos
(point)))))
514 (pop-to-buffer log-buf
)
516 ;; Ask the backend to display a single log entry.
517 (vc-print-log-internal
518 vc-annotate-backend
(list (cdr rev-at-line
))
519 (car rev-at-line
) t
1)))))))
521 (defun vc-annotate-show-diff-revision-at-line-internal (filediff)
522 (if (not (equal major-mode
'vc-annotate-mode
))
523 (message "Cannot be invoked outside of a vc annotate buffer")
524 (let* ((rev-at-line (vc-annotate-extract-revision-at-line))
526 (rev (car rev-at-line
))
527 (fname (cdr rev-at-line
)))
528 (if (not rev-at-line
)
529 (message "Cannot extract revision number from the current line")
531 (vc-call-backend vc-annotate-backend
'previous-revision
532 (if filediff fname nil
) rev
))
534 (message "Cannot diff from any revision prior to %s" rev
)
535 (save-window-excursion
538 ;; The value passed here should follow what
539 ;; `vc-deduce-fileset' returns.
540 (list vc-annotate-backend
545 (switch-to-buffer "*vc-diff*"))))))
547 (defun vc-annotate-show-diff-revision-at-line ()
548 "Visit the diff of the revision at line from its previous revision."
550 (vc-annotate-show-diff-revision-at-line-internal t
))
552 (defun vc-annotate-show-changeset-diff-revision-at-line ()
553 "Visit the diff of the revision at line from its previous revision for all files in the changeset."
555 (when (eq 'file
(vc-call-backend vc-annotate-backend
'revision-granularity
))
556 (error "The %s backend does not support changeset diffs" vc-annotate-backend
))
557 (vc-annotate-show-diff-revision-at-line-internal nil
))
559 (defun vc-annotate-warp-revision (revspec &optional file
)
560 "Annotate the revision described by REVSPEC.
562 If REVSPEC is a positive integer, warp that many revisions forward,
563 if possible, otherwise echo a warning message. If REVSPEC is a
564 negative integer, warp that many revisions backward, if possible,
565 otherwise echo a warning message. If REVSPEC is a string, then it
566 describes a revision number, so warp to that revision."
567 (if (not (equal major-mode
'vc-annotate-mode
))
568 (message "Cannot be invoked outside of a vc annotate buffer")
569 (let* ((buf (current-buffer))
570 (oldline (line-number-at-pos))
571 (revspeccopy revspec
)
574 ((and (integerp revspec
) (> revspec
0))
575 (setq newrev vc-annotate-parent-rev
)
576 (while (and (> revspec
0) newrev
)
577 (setq newrev
(vc-call-backend vc-annotate-backend
'next-revision
578 (or file vc-annotate-parent-file
) newrev
))
579 (setq revspec
(1- revspec
)))
581 (message "Cannot increment %d revisions from revision %s"
582 revspeccopy vc-annotate-parent-rev
)))
583 ((and (integerp revspec
) (< revspec
0))
584 (setq newrev vc-annotate-parent-rev
)
585 (while (and (< revspec
0) newrev
)
586 (setq newrev
(vc-call-backend vc-annotate-backend
'previous-revision
587 (or file vc-annotate-parent-file
) newrev
))
588 (setq revspec
(1+ revspec
)))
590 (message "Cannot decrement %d revisions from revision %s"
591 (- 0 revspeccopy
) vc-annotate-parent-rev
)))
592 ((stringp revspec
) (setq newrev revspec
))
593 (t (error "Invalid argument to vc-annotate-warp-revision")))
595 (vc-annotate (or file vc-annotate-parent-file
) newrev
596 vc-annotate-parent-display-mode
598 ;; Pass the current line so that vc-annotate will
599 ;; place the point in the line.
600 (min oldline
(progn (goto-char (point-max))
602 (line-number-at-pos)))
603 vc-annotate-backend
)))))
605 (defun vc-annotate-compcar (threshold a-list
)
606 "Test successive cons cells of A-LIST against THRESHOLD.
607 Return the first cons cell with a car that is not less than THRESHOLD,
608 nil if no such cell exists."
610 (tmp-cons (car a-list
)))
611 (while (and tmp-cons
(< (car tmp-cons
) threshold
))
612 (setq tmp-cons
(car (nthcdr i a-list
)))
614 tmp-cons
)) ; Return the appropriate value
616 (defun vc-annotate-convert-time (time)
617 "Convert a time value to a floating-point number of days.
618 The argument TIME is a list as returned by `current-time' or
619 `encode-time', only the first two elements of that list are considered."
620 (/ (+ (* (float (car time
)) (lsh 1 16)) (cadr time
)) 24 3600))
622 (defun vc-annotate-difference (&optional offset
)
623 "Return the time span in days to the next annotation.
624 This calls the backend function annotate-time, and returns the
625 difference in days between the time returned and the current time,
626 or OFFSET if present."
627 (let ((next-time (vc-annotate-get-time-set-line-props)))
630 (vc-call-backend vc-annotate-backend
'annotate-current-time
))
633 (defun vc-default-annotate-current-time (backend)
634 "Return the current time, encoded as fractional days."
635 (vc-annotate-convert-time (current-time)))
637 (defvar vc-annotate-offset nil
)
639 (defun vc-annotate-display (ratio &optional offset
)
640 "Highlight `vc-annotate' output in the current buffer.
641 RATIO is the expansion that should be applied to `vc-annotate-color-map'.
642 The annotations are relative to the current time, unless overridden by OFFSET."
644 (set (make-local-variable 'vc-annotate-color-map
)
645 (mapcar (lambda (elem) (cons (* (car elem
) ratio
) (cdr elem
)))
646 vc-annotate-color-map
)))
647 (set (make-local-variable 'vc-annotate-offset
) offset
)
650 (defun vc-annotate-lines (limit)
651 (while (< (point) limit
)
652 (let ((difference (vc-annotate-difference vc-annotate-offset
))
654 (end (progn (forward-line 1) (point))))
656 (let* ((color (or (vc-annotate-compcar difference vc-annotate-color-map
)
657 (cons nil vc-annotate-very-old-color
)))
658 ;; substring from index 1 to remove any leading `#' in the name
659 (face-name (concat "vc-annotate-face-"
661 (substring (cdr color
) 0 1) "#")
662 (substring (cdr color
) 1)
664 ;; Make the face if not done.
665 (face (or (intern-soft face-name
)
666 (let ((tmp-face (make-face (intern face-name
))))
667 (set-face-foreground tmp-face
(cdr color
))
668 (when vc-annotate-background
669 (set-face-background tmp-face
670 vc-annotate-background
))
671 tmp-face
)))) ; Return the face
672 (put-text-property start end
'face face
)))))
673 ;; Pretend to font-lock there were no matches.
676 (provide 'vc-annotate
)
678 ;;; vc-annotate.el ends here