]> code.delx.au - gnu-emacs/blobdiff - lisp/vc/vc-annotate.el
* lisp/abbrev.el (define-abbrev-table): Don't add a table multiple times.
[gnu-emacs] / lisp / vc / vc-annotate.el
index d21d40d50f2f01d1bad96da373a38449ae2e36f2..b6ecc4c1d750561c3df808b881ddf0fa41c61670 100644 (file)
@@ -1,11 +1,11 @@
 ;;; vc-annotate.el --- VC Annotate Support
 
-;; Copyright (C) 1997, 1998, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
-;;   2007, 2008, 2009, 2010 Free Software Foundation, Inc.
+;; Copyright (C) 1997-1998, 2000-2011 Free Software Foundation, Inc.
 
 ;; Author:     Martin Lorentzson  <emwson@emw.ericsson.se>
 ;; Maintainer: FSF
 ;; Keywords: vc tools
+;; Package: vc
 
 ;; This file is part of GNU Emacs.
 
@@ -120,6 +120,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 +129,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.")
 
@@ -315,8 +318,8 @@ use; you may override this using the second optional arg MODE."
                  vc-annotate-display-mode))))
 
 ;;;###autoload
-(defun vc-annotate (file rev &optional display-mode buf move-point-to)
-  "Display the edit history of the current file using colors.
+(defun vc-annotate (file rev &optional display-mode buf move-point-to vc-bk)
+  "Display the edit history of the current FILE using colors.
 
 This command creates a buffer that shows, for each line of the current
 file, when it was last edited and by whom.  Additionally, colors are
@@ -326,7 +329,7 @@ default, the time scale stretches back one year into the past;
 everything that is older than that is shown in blue.
 
 With a prefix argument, this command asks two questions in the
-minibuffer.  First, you may enter a revision number; then the buffer
+minibuffer.  First, you may enter a revision number REV; then the buffer
 displays and annotates that revision instead of the working revision
 \(type RET in the minibuffer to leave that default unchanged).  Then,
 you are prompted for the time span in days which the color range
@@ -336,6 +339,8 @@ age, and everything that is older than that is shown in blue.
 
 If MOVE-POINT-TO is given, move the point to that line.
 
+If VC-BK is given used that VC backend.
+
 Customization variables:
 
 `vc-annotate-menu-elements' customizes the menu elements of the
@@ -348,9 +353,9 @@ mode-specific menu.  `vc-annotate-color-map' and
      (list buffer-file-name
           (let ((def (vc-working-revision buffer-file-name)))
             (if (null current-prefix-arg) def
-              (read-string
+              (vc-read-revision
                (format "Annotate from revision (default %s): " def)
-               nil nil def)))
+               (list buffer-file-name) nil def)))
           (if (null current-prefix-arg)
               vc-annotate-display-mode
             (float (string-to-number
@@ -376,7 +381,7 @@ mode-specific menu.  `vc-annotate-color-map' and
                ;; In case it had to be uniquified.
                (setq temp-buffer-name (buffer-name))))
     (with-output-to-temp-buffer temp-buffer-name
-      (let ((backend (vc-backend file))
+      (let ((backend (or vc-bk (vc-backend file)))
            (coding-system-for-read buffer-file-coding-system))
         (vc-call-backend backend 'annotate-command file
                          (get-buffer temp-buffer-name) rev)
@@ -462,7 +467,7 @@ Return a cons (REV . FILENAME)."
       (if (not rev-at-line)
          (message "Cannot extract revision number from the current line")
        (switch-to-buffer-other-window
-        (vc-find-revision (cdr rev-at-line) (car rev-at-line)))))))
+        (vc-find-revision (cdr rev-at-line) (car rev-at-line) vc-annotate-backend))))))
 
 (defun vc-annotate-revision-previous-to-line ()
   "Visit the annotation of the revision before the revision at line."
@@ -487,7 +492,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")
@@ -527,7 +532,7 @@ the file in question, search for the log entry required and move point ."
          (message "Cannot extract revision number from the current line")
        (setq prev-rev
              (vc-call-backend vc-annotate-backend 'previous-revision
-                               fname rev))
+                               (if filediff fname nil) rev))
        (if (not prev-rev)
            (message "Cannot diff from any revision prior to %s" rev)
          (save-window-excursion
@@ -597,7 +602,8 @@ describes a revision number, so warp to that revision."
                     ;; place the point in the line.
                     (min oldline (progn (goto-char (point-max))
                                          (forward-line -1)
-                                         (line-number-at-pos))))))))
+                                         (line-number-at-pos)))
+                    vc-annotate-backend)))))
 
 (defun vc-annotate-compcar (threshold a-list)
   "Test successive cons cells of A-LIST against THRESHOLD.
@@ -670,7 +676,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)
 
-;; arch-tag: c3454a89-80e5-4ffd-8993-671b59612898
 ;;; vc-annotate.el ends here