-;;; vc-annotate.el --- VC Annotate Support
+;;; vc-annotate.el --- VC Annotate Support -*- lexical-binding: t -*-
-;; Copyright (C) 1997-1998, 2000-2011 Free Software Foundation, Inc.
+;; Copyright (C) 1997-1998, 2000-2014 Free Software Foundation, Inc.
;; Author: Martin Lorentzson <emwson@emw.ericsson.se>
-;; Maintainer: FSF
+;; Maintainer: emacs-devel@gnu.org
;; Keywords: vc tools
;; Package: vc
(require 'vc)
;;; Code:
-(eval-when-compile
- (require 'cl))
+(eval-when-compile (require 'cl-lib))
(defcustom vc-annotate-display-mode 'fullscale
"Which mode to color the output of \\[vc-annotate] with by default."
(let ((m (make-sparse-keymap)))
(define-key m "a" 'vc-annotate-revision-previous-to-line)
(define-key m "d" 'vc-annotate-show-diff-revision-at-line)
+ (define-key m "=" 'vc-annotate-show-diff-revision-at-line)
(define-key m "D" 'vc-annotate-show-changeset-diff-revision-at-line)
(define-key m "f" 'vc-annotate-find-revision-at-line)
(define-key m "j" 'vc-annotate-revision-at-line)
(define-key m "p" 'vc-annotate-prev-revision)
(define-key m "w" 'vc-annotate-working-revision)
(define-key m "v" 'vc-annotate-toggle-annotation-visibility)
+ (define-key m "v" 'vc-annotate-toggle-annotation-visibility)
+ (define-key m "\C-m" 'vc-annotate-goto-line)
m)
"Local keymap used for VC-Annotate mode.")
(let ((bol (point))
(date (vc-call-backend vc-annotate-backend 'annotate-time))
(inhibit-read-only t))
- (assert (>= (point) bol))
+ (cl-assert (>= (point) bol))
(put-text-property bol (point) 'invisible 'vc-annotate-annotation)
date))
(vc-annotate-display-default (or vc-annotate-ratio 1.0)))
;; One of the auto-scaling modes
((eq vc-annotate-display-mode 'scale)
- (vc-exec-after `(vc-annotate-display-autoscale)))
+ (vc-run-delayed (vc-annotate-display-autoscale)))
((eq vc-annotate-display-mode 'fullscale)
- (vc-exec-after `(vc-annotate-display-autoscale t)))
+ (vc-run-delayed (vc-annotate-display-autoscale t)))
((numberp vc-annotate-display-mode) ; A fixed number of days lookback
(vc-annotate-display-default
(/ vc-annotate-display-mode
(t (error "No such display mode: %s"
vc-annotate-display-mode))))
+(defvar vc-sentinel-movepoint)
+
;;;###autoload
(defun vc-annotate (file rev &optional display-mode buf move-point-to vc-bk)
"Display the edit history of the current FILE using colors.
display-mode))))
(with-current-buffer temp-buffer-name
- (vc-exec-after
- `(progn
- ;; Ideally, we'd rather not move point if the user has already
- ;; moved it elsewhere, but really point here is not the position
- ;; of the user's cursor :-(
- (when ,current-line ;(and (bobp))
- (goto-line ,current-line)
- (setq vc-sentinel-movepoint (point)))
- (unless (active-minibuffer-window)
- (message "Annotating... done")))))))
+ (vc-run-delayed
+ ;; Ideally, we'd rather not move point if the user has already
+ ;; moved it elsewhere, but really point here is not the position
+ ;; of the user's cursor :-(
+ (when current-line ;(and (bobp))
+ (goto-char (point-min))
+ (forward-line (1- current-line))
+ (setq vc-sentinel-movepoint (point)))
+ (unless (active-minibuffer-window)
+ (message "Annotating... done"))))))
(defun vc-annotate-prev-revision (prefix)
"Visit the annotation of the revision previous to this one.
"Visit the log of the revision at line.
If the VC backend supports it, only show the log entry for the revision.
If a *vc-change-log* buffer exists and already shows a log for
-the file in question, search for the log entry required and move point ."
+the file in question, search for the log entry required and move point."
(interactive)
(if (not (equal major-mode 'vc-annotate-mode))
(message "Cannot be invoked outside of a vc annotate buffer")
(car rev-at-line) t 1)))))))
(defun vc-annotate-show-diff-revision-at-line-internal (filediff)
- (if (not (equal major-mode 'vc-annotate-mode))
+ (if (not (derived-mode-p 'vc-annotate-mode))
(message "Cannot be invoked outside of a vc annotate buffer")
(let* ((rev-at-line (vc-annotate-extract-revision-at-line))
- (prev-rev nil)
- (rev (car rev-at-line))
- (fname (cdr rev-at-line)))
+ (prev-rev nil)
+ (rev (car rev-at-line))
+ (fname (cdr rev-at-line)))
(if (not rev-at-line)
(message "Cannot extract revision number from the current line")
(setq prev-rev
(if filediff fname nil) rev))
(if (not prev-rev)
(message "Cannot diff from any revision prior to %s" rev)
- (save-window-excursion
- (vc-diff-internal
- nil
- ;; The value passed here should follow what
- ;; `vc-deduce-fileset' returns.
- (list vc-annotate-backend
- (if filediff
- (list fname)
- nil))
- prev-rev rev))
- (switch-to-buffer "*vc-diff*"))))))
+ (vc-diff-internal
+ t
+ ;; The value passed here should follow what
+ ;; `vc-deduce-fileset' returns.
+ (list vc-annotate-backend
+ (if filediff
+ (list fname)
+ nil))
+ prev-rev rev))))))
(defun vc-annotate-show-diff-revision-at-line ()
"Visit the diff of the revision at line from its previous revision."
(vc-call-backend vc-annotate-backend 'annotate-current-time))
next-time))))
-(defun vc-default-annotate-current-time (backend)
+(defun vc-default-annotate-current-time (_backend)
"Return the current time, encoded as fractional days."
(vc-annotate-convert-time (current-time)))
;; Pretend to font-lock there were no matches.
nil)
+(defun vc-annotate-goto-line ()
+ "Go to the line corresponding to the current VC Annotate line."
+ (interactive)
+ (unless (eq major-mode 'vc-annotate-mode)
+ (error "Not in a VC-Annotate buffer"))
+ (let ((line (save-restriction
+ (widen)
+ (line-number-at-pos)))
+ (rev vc-annotate-parent-rev))
+ (pop-to-buffer
+ (or (and (buffer-live-p vc-parent-buffer)
+ vc-parent-buffer)
+ (and (file-exists-p vc-annotate-parent-file)
+ (find-file-noselect vc-annotate-parent-file))
+ (error "File not found: %s" vc-annotate-parent-file)))
+ (save-restriction
+ (widen)
+ (goto-char (point-min))
+ (forward-line (1- line))
+ (recenter))
+ ;; Issue a warning if the lines might be incorrect.
+ (cond
+ ((buffer-modified-p)
+ (message "Buffer modified; annotated line numbers may be incorrect"))
+ ((not (eq (vc-state buffer-file-name) 'up-to-date))
+ (message "File is not up-to-date; annotated line numbers may be incorrect"))
+ ((not (equal rev (vc-working-revision buffer-file-name)))
+ (message "Annotations were for revision %s; line numbers may be incorrect"
+ rev)))))
+
(provide 'vc-annotate)
;;; vc-annotate.el ends here