authors.el: Add some renamed/moved files
[bpt/emacs.git] / lisp / vc / vc-annotate.el
index 479dbb5..424b48a 100644 (file)
@@ -1,9 +1,9 @@
-;;; 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
 
@@ -29,8 +29,7 @@
 (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."
@@ -120,6 +119,7 @@ List of factors, used to expand/compress the time scale.  See `vc-annotate'."
   (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)
@@ -128,6 +128,8 @@ List of factors, used to expand/compress the time scale.  See `vc-annotate'."
     (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.")
 
@@ -192,7 +194,7 @@ The current time is used as the offset."
   (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))
 
@@ -304,9 +306,9 @@ use; you may override this using the second optional arg MODE."
         (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
@@ -314,6 +316,8 @@ use; you may override this using the second optional arg 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.
@@ -395,16 +399,16 @@ mode-specific menu.  `vc-annotate-color-map' and
                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.
@@ -489,7 +493,7 @@ Return a cons (REV . FILENAME)."
   "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")
@@ -519,12 +523,12 @@ the file in question, search for the log entry required and move point ."
             (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
@@ -532,17 +536,15 @@ the file in question, search for the log entry required and move point ."
                                (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."
@@ -630,7 +632,7 @@ or OFFSET if present."
              (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)))
 
@@ -673,6 +675,36 @@ The annotations are relative to the current time, unless overridden by OFFSET."
   ;; 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