Update copyright notices for 2013.
[bpt/emacs.git] / lisp / vc / vc-annotate.el
index 8e626e8..8af4887 100644 (file)
@@ -1,7 +1,6 @@
 ;;; vc-annotate.el --- VC Annotate Support
 
-;; Copyright (C) 1997, 1998, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
-;;   2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
+;; Copyright (C) 1997-1998, 2000-2013 Free Software Foundation, Inc.
 
 ;; Author:     Martin Lorentzson  <emwson@emw.ericsson.se>
 ;; Maintainer: FSF
@@ -30,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."
@@ -121,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)
@@ -129,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.")
 
@@ -193,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))
 
@@ -490,7 +491,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")
@@ -520,12 +521,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
@@ -533,17 +534,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."
@@ -674,6 +673,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