aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndré Spiegel2004-01-20 17:39:09 +0000
committerAndré Spiegel2004-01-20 17:39:09 +0000
commit1b5a73430e988671570d8fb4efa4c02952ade0fc (patch)
tree06723b0778de6be426fef6eea9e0229523e1d4a3
parenta73c299983c507800be4df533358dcfeef7a77b2 (diff)
downloademacs-1b5a73430e988671570d8fb4efa4c02952ade0fc.tar.gz
emacs-1b5a73430e988671570d8fb4efa4c02952ade0fc.zip
* vc.el (vc-default-previous-version): Doc enhancement.
(vc-default-next-version): New function. (vc-print-log): New arg FOCUS-REV. (vc-annotate-mode): Derives from view-mode now. (vc-annotate): New args REVISION, DISPLAY-MODE. (vc-annotate-prev-version): New function. (vc-annotate-prev-version): New function. (vc-annotate-next-version): New function. (vc-annotate-workfile-version): New function. (vc-annotate-extract-revision-at-line): New function. (vc-annotate-revision-at-line): New function. (vc-annotate-revision-previous-to-line): New function. (vc-annotate-show-log-revision-at-line): New function. (vc-annotate-show-diff-revision-at-line): New function. (vc-current-line): New function. (vc-annotate-warp-version): New function.
-rw-r--r--lisp/vc.el257
1 files changed, 235 insertions, 22 deletions
diff --git a/lisp/vc.el b/lisp/vc.el
index b015d56c87f..6e2eabcb9df 100644
--- a/lisp/vc.el
+++ b/lisp/vc.el
@@ -7,7 +7,7 @@
7;; Maintainer: Andre Spiegel <spiegel@gnu.org> 7;; Maintainer: Andre Spiegel <spiegel@gnu.org>
8;; Keywords: tools 8;; Keywords: tools
9 9
10;; $Id: vc.el,v 1.360 2003/09/01 15:45:17 miles Exp $ 10;; $Id: vc.el,v 1.361 2003/12/24 23:18:10 uid66361 Exp $
11 11
12;; This file is part of GNU Emacs. 12;; This file is part of GNU Emacs.
13 13
@@ -347,6 +347,13 @@
347;; time with hours, minutes, and seconds included. Probably safe to 347;; time with hours, minutes, and seconds included. Probably safe to
348;; ignore. Return the current-time, in units of fractional days. 348;; ignore. Return the current-time, in units of fractional days.
349;; 349;;
350;; - annotate-extract-revision-at-line ()
351;;
352;; Only required if `annotate-command' is defined for the backend.
353;; Invoked from a buffer in vc-annotate-mode, return the revision
354;; corresponding to the current line, or nil if there is no revision
355;; corresponding to the current line.
356;;
350;; SNAPSHOT SYSTEM 357;; SNAPSHOT SYSTEM
351;; 358;;
352;; - create-snapshot (dir name branchp) 359;; - create-snapshot (dir name branchp)
@@ -392,7 +399,13 @@
392;; 399;;
393;; - previous-version (file rev) 400;; - previous-version (file rev)
394;; 401;;
395;; Return the version number that precedes REV for FILE. 402;; Return the version number that precedes REV for FILE, or nil if no such
403;; version exists.
404;;
405;; - next-version (file rev)
406;;
407;; Return the version number that follows REV for FILE, or nil if no such
408;; version exists.
396;; 409;;
397;; - check-headers () 410;; - check-headers ()
398;; 411;;
@@ -631,6 +644,14 @@ List of factors, used to expand/compress the time scale. See `vc-annotate'."
631 m) 644 m)
632 "Local keymap used for VC-Annotate mode.") 645 "Local keymap used for VC-Annotate mode.")
633 646
647(define-key vc-annotate-mode-map "A" 'vc-annotate-revision-previous-to-line)
648(define-key vc-annotate-mode-map "D" 'vc-annotate-show-diff-revision-at-line)
649(define-key vc-annotate-mode-map "J" 'vc-annotate-revision-at-line)
650(define-key vc-annotate-mode-map "L" 'vc-annotate-show-log-revision-at-line)
651(define-key vc-annotate-mode-map "N" 'vc-annotate-next-version)
652(define-key vc-annotate-mode-map "P" 'vc-annotate-prev-version)
653(define-key vc-annotate-mode-map "W" 'vc-annotate-workfile-version)
654
634(defvar vc-annotate-mode-menu nil 655(defvar vc-annotate-mode-menu nil
635 "Local keymap used for VC-Annotate mode's menu bar menu.") 656 "Local keymap used for VC-Annotate mode's menu bar menu.")
636 657
@@ -714,9 +735,10 @@ The keys are \(BUFFER . BACKEND\). See also `vc-annotate-get-backend'.")
714 (substring rev (match-beginning 0) (match-end 0))) 735 (substring rev (match-beginning 0) (match-end 0)))
715 736
716(defun vc-default-previous-version (backend file rev) 737(defun vc-default-previous-version (backend file rev)
717 "Guess the version number immediately preceding REV for FILE. 738 "Return the version number immediately preceding REV for FILE,
718This default implementation works for <major>.<minor>-style version numbers 739or nil if there is no previous version. This default
719as used by RCS and CVS." 740implementation works for <major>.<minor>-style version numbers as
741used by RCS and CVS."
720 (let ((branch (vc-branch-part rev)) 742 (let ((branch (vc-branch-part rev))
721 (minor-num (string-to-number (vc-minor-part rev)))) 743 (minor-num (string-to-number (vc-minor-part rev))))
722 (when branch 744 (when branch
@@ -731,6 +753,16 @@ as used by RCS and CVS."
731 ;; return version of starting point 753 ;; return version of starting point
732 (vc-branch-part branch)))))) 754 (vc-branch-part branch))))))
733 755
756(defun vc-default-next-version (backend file rev)
757 "Return the version number immediately following REV for FILE,
758or nil if there is no next version. This default implementation
759works for <major>.<minor>-style version numbers as used by RCS
760and CVS."
761 (when (not (string= rev (vc-workfile-version file)))
762 (let ((branch (vc-branch-part rev))
763 (minor-num (string-to-number (vc-minor-part rev))))
764 (concat branch "." (number-to-string (1+ minor-num))))))
765
734;; File property caching 766;; File property caching
735 767
736(defun vc-clear-context () 768(defun vc-clear-context ()
@@ -2285,11 +2317,13 @@ allowed and simply skipped)."
2285;; Miscellaneous other entry points 2317;; Miscellaneous other entry points
2286 2318
2287;;;###autoload 2319;;;###autoload
2288(defun vc-print-log () 2320(defun vc-print-log (&optional focus-rev)
2289 "List the change log of the current buffer in a window." 2321 "List the change log of the current buffer in a window. If
2322FOCUS-REV is non-nil, leave the point at that revision."
2290 (interactive) 2323 (interactive)
2291 (vc-ensure-vc-buffer) 2324 (vc-ensure-vc-buffer)
2292 (let ((file buffer-file-name)) 2325 (let ((file buffer-file-name))
2326 (or focus-rev (setq focus-rev (vc-workfile-version file)))
2293 (vc-call print-log file) 2327 (vc-call print-log file)
2294 (set-buffer "*vc*") 2328 (set-buffer "*vc*")
2295 (pop-to-buffer (current-buffer)) 2329 (pop-to-buffer (current-buffer))
@@ -2307,7 +2341,7 @@ allowed and simply skipped)."
2307 ;; move point to the log entry for the current version 2341 ;; move point to the log entry for the current version
2308 (vc-call-backend ',(vc-backend file) 2342 (vc-call-backend ',(vc-backend file)
2309 'show-log-entry 2343 'show-log-entry
2310 ',(vc-workfile-version file)) 2344 ',focus-rev)
2311 (set-buffer-modified-p nil))))) 2345 (set-buffer-modified-p nil)))))
2312 2346
2313(defun vc-default-show-log-entry (backend rev) 2347(defun vc-default-show-log-entry (backend rev)
@@ -2778,6 +2812,14 @@ Uses `rcs2log' which only works for RCS and CVS."
2778(defvar vc-annotate-ratio nil "Global variable.") 2812(defvar vc-annotate-ratio nil "Global variable.")
2779(defvar vc-annotate-backend nil "Global variable.") 2813(defvar vc-annotate-backend nil "Global variable.")
2780 2814
2815;; internal buffer-local variables
2816(defvar vc-annotate-parent-file nil)
2817(defvar vc-annotate-parent-rev nil)
2818(defvar vc-annotate-parent-display-mode nil)
2819(make-local-variable 'vc-annotate-parent-file)
2820(make-local-variable 'vc-annotate-parent-rev)
2821(make-local-variable 'vc-annotate-parent-display-mode)
2822
2781(defconst vc-annotate-font-lock-keywords 2823(defconst vc-annotate-font-lock-keywords
2782 ;; The fontification is done by vc-annotate-lines instead of font-lock. 2824 ;; The fontification is done by vc-annotate-lines instead of font-lock.
2783 '((vc-annotate-lines))) 2825 '((vc-annotate-lines)))
@@ -2788,7 +2830,7 @@ Return nil if no match made. Associations are made based on
2788`vc-annotate-buffers'." 2830`vc-annotate-buffers'."
2789 (cdr (assoc buffer vc-annotate-buffers))) 2831 (cdr (assoc buffer vc-annotate-buffers)))
2790 2832
2791(define-derived-mode vc-annotate-mode fundamental-mode "Annotate" 2833(define-derived-mode vc-annotate-mode view-mode "Annotate"
2792 "Major mode for output buffers of the `vc-annotate' command. 2834 "Major mode for output buffers of the `vc-annotate' command.
2793 2835
2794You can use the mode-specific menu to alter the time-span of the used 2836You can use the mode-specific menu to alter the time-span of the used
@@ -2885,7 +2927,23 @@ cover the range from the oldest annotation to the newest."
2885 (unless (eq vc-annotate-display-mode 'fullscale) 2927 (unless (eq vc-annotate-display-mode 'fullscale)
2886 (vc-annotate-display-select nil 'fullscale)) 2928 (vc-annotate-display-select nil 'fullscale))
2887 :style toggle :selected 2929 :style toggle :selected
2888 (eq vc-annotate-display-mode 'fullscale)]))) 2930 (eq vc-annotate-display-mode 'fullscale)])
2931 (list "--")
2932 (list ["Annotate previous revision"
2933 (call-interactively 'vc-annotate-prev-version)])
2934 (list ["Annotate next revision"
2935 (call-interactively 'vc-annotate-next-version)])
2936 (list ["Annotate revision at line"
2937 (vc-annotate-revision-at-line)])
2938 (list ["Annotate revision previous to line"
2939 (vc-annotate-revision-previous-to-line)])
2940 (list ["Annotate latest revision"
2941 (vc-annotate-workfile-version)])
2942 (list ["Show log of revision at line"
2943 (vc-annotate-show-log-revision-at-line)])
2944 (list ["Show diff of revision at line"
2945 (vc-annotate-show-diff-revision-at-line)])))
2946
2889 ;; Define the menu 2947 ;; Define the menu
2890 (if (or (featurep 'easymenu) (load "easymenu" t)) 2948 (if (or (featurep 'easymenu) (load "easymenu" t))
2891 (easy-menu-define vc-annotate-mode-menu vc-annotate-mode-map 2949 (easy-menu-define vc-annotate-mode-menu vc-annotate-mode-map
@@ -2922,7 +2980,7 @@ use; you may override this using the second optional arg MODE."
2922;;;; the contents in BUFFER. 2980;;;; the contents in BUFFER.
2923 2981
2924;;;###autoload 2982;;;###autoload
2925(defun vc-annotate (prefix) 2983(defun vc-annotate (prefix &optional revision display-mode)
2926 "Display the edit history of the current file using colours. 2984 "Display the edit history of the current file using colours.
2927 2985
2928This command creates a buffer that shows, for each line of the current 2986This command creates a buffer that shows, for each line of the current
@@ -2949,19 +3007,24 @@ mode-specific menu. `vc-annotate-color-map' and
2949colors. `vc-annotate-background' specifies the background color." 3007colors. `vc-annotate-background' specifies the background color."
2950 (interactive "P") 3008 (interactive "P")
2951 (vc-ensure-vc-buffer) 3009 (vc-ensure-vc-buffer)
2952 (let* ((temp-buffer-name (concat "*Annotate " (buffer-name) "*")) 3010 (let* ((temp-buffer-name nil)
2953 (temp-buffer-show-function 'vc-annotate-display-select) 3011 (temp-buffer-show-function 'vc-annotate-display-select)
2954 (rev (vc-workfile-version buffer-file-name)) 3012 (rev (or revision (vc-workfile-version buffer-file-name)))
3013 (bfn buffer-file-name)
2955 (vc-annotate-version 3014 (vc-annotate-version
2956 (if prefix (read-string 3015 (if prefix (read-string
2957 (format "Annotate from version: (default %s) " rev) 3016 (format "Annotate from version: (default %s) " rev)
2958 nil nil rev) 3017 nil nil rev)
2959 rev))) 3018 rev)))
2960 (if prefix 3019 (if display-mode
2961 (setq vc-annotate-display-mode 3020 (setq vc-annotate-display-mode display-mode)
2962 (float (string-to-number 3021 (if prefix
2963 (read-string "Annotate span days: (default 20) " 3022 (setq vc-annotate-display-mode
2964 nil nil "20"))))) 3023 (float (string-to-number
3024 (read-string "Annotate span days: (default 20) "
3025 nil nil "20"))))))
3026 (setq temp-buffer-name (format "*Annotate %s (rev %s)*"
3027 (buffer-name) vc-annotate-version))
2965 (setq vc-annotate-backend (vc-backend buffer-file-name)) 3028 (setq vc-annotate-backend (vc-backend buffer-file-name))
2966 (message "Annotating...") 3029 (message "Annotating...")
2967 (if (not (vc-find-backend-function vc-annotate-backend 'annotate-command)) 3030 (if (not (vc-find-backend-function vc-annotate-backend 'annotate-command))
@@ -2972,6 +3035,12 @@ colors. `vc-annotate-background' specifies the background color."
2972 buffer-file-name 3035 buffer-file-name
2973 (get-buffer temp-buffer-name) 3036 (get-buffer temp-buffer-name)
2974 vc-annotate-version)) 3037 vc-annotate-version))
3038 (save-excursion
3039 (set-buffer temp-buffer-name)
3040 (setq vc-annotate-parent-file bfn)
3041 (setq vc-annotate-parent-rev vc-annotate-version)
3042 (setq vc-annotate-parent-display-mode vc-annotate-display-mode))
3043
2975 ;; Don't use the temp-buffer-name until the buffer is created 3044 ;; Don't use the temp-buffer-name until the buffer is created
2976 ;; (only after `with-output-to-temp-buffer'.) 3045 ;; (only after `with-output-to-temp-buffer'.)
2977 (setq vc-annotate-buffers 3046 (setq vc-annotate-buffers
@@ -2979,6 +3048,150 @@ colors. `vc-annotate-background' specifies the background color."
2979 (list (cons (get-buffer temp-buffer-name) vc-annotate-backend)))) 3048 (list (cons (get-buffer temp-buffer-name) vc-annotate-backend))))
2980 (message "Annotating... done"))) 3049 (message "Annotating... done")))
2981 3050
3051(defun vc-annotate-prev-version (prefix)
3052 "Visit the annotation of the version previous to this one.
3053
3054With a numeric prefix argument, annotate the version that many
3055versions previous."
3056 (interactive "p")
3057 (vc-annotate-warp-version (- 0 prefix)))
3058
3059(defun vc-annotate-next-version (prefix)
3060 "Visit the annotation of the version after this one.
3061
3062With a numeric prefix argument, annotate the version that many
3063versions after."
3064 (interactive "p")
3065 (vc-annotate-warp-version prefix))
3066
3067(defun vc-annotate-workfile-version ()
3068 "Visit the annotation of the workfile version of this file."
3069 (interactive)
3070 (if (not (equal major-mode 'vc-annotate-mode))
3071 (message "Cannot be invoked outside of a vc annotate buffer")
3072 (let ((warp-rev (vc-workfile-version vc-annotate-parent-file)))
3073 (if (equal warp-rev vc-annotate-parent-rev)
3074 (message "Already at version %s" warp-rev)
3075 (vc-annotate-warp-version warp-rev)))))
3076
3077(defun vc-annotate-extract-revision-at-line ()
3078 "Extract the revision number of the current line."
3079 ;; This function must be invoked from a buffer in vc-annotate-mode
3080 (save-window-excursion
3081 (vc-ensure-vc-buffer)
3082 (setq vc-annotate-backend (vc-backend buffer-file-name)))
3083 (vc-call-backend vc-annotate-backend 'annotate-extract-revision-at-line))
3084
3085(defun vc-annotate-revision-at-line ()
3086 "Visit the annotation of the version identified in the current line."
3087 (interactive)
3088 (if (not (equal major-mode 'vc-annotate-mode))
3089 (message "Cannot be invoked outside of a vc annotate buffer")
3090 (let ((rev-at-line (vc-annotate-extract-revision-at-line)))
3091 (if (not rev-at-line)
3092 (message "Cannot extract revision number from the current line")
3093 (if (equal rev-at-line vc-annotate-parent-rev)
3094 (message "Already at version %s" rev-at-line)
3095 (vc-annotate-warp-version rev-at-line))))))
3096
3097(defun vc-annotate-revision-previous-to-line ()
3098 "Visit the annotation of the version before the version at line."
3099 (interactive)
3100 (if (not (equal major-mode 'vc-annotate-mode))
3101 (message "Cannot be invoked outside of a vc annotate buffer")
3102 (let ((rev-at-line (vc-annotate-extract-revision-at-line))
3103 (prev-rev nil))
3104 (if (not rev-at-line)
3105 (message "Cannot extract revision number from the current line")
3106 (setq prev-rev
3107 (vc-call previous-version vc-annotate-parent-file rev-at-line))
3108 (vc-annotate-warp-version prev-rev)))))
3109
3110(defun vc-annotate-show-log-revision-at-line ()
3111 "Visit the log of the version at line."
3112 (interactive)
3113 (if (not (equal major-mode 'vc-annotate-mode))
3114 (message "Cannot be invoked outside of a vc annotate buffer")
3115 (let ((rev-at-line (vc-annotate-extract-revision-at-line)))
3116 (if (not rev-at-line)
3117 (message "Cannot extract revision number from the current line")
3118 (vc-print-log rev-at-line)))))
3119
3120(defun vc-annotate-show-diff-revision-at-line ()
3121 "Visit the diff of the version at line from its previous version."
3122 (interactive)
3123 (if (not (equal major-mode 'vc-annotate-mode))
3124 (message "Cannot be invoked outside of a vc annotate buffer")
3125 (let ((rev-at-line (vc-annotate-extract-revision-at-line))
3126 (prev-rev nil))
3127 (if (not rev-at-line)
3128 (message "Cannot extract revision number from the current line")
3129 (setq prev-rev
3130 (vc-call previous-version vc-annotate-parent-file rev-at-line))
3131 (if (not prev-rev)
3132 (message "Cannot diff from any version prior to %s" rev-at-line)
3133 (save-window-excursion
3134 (vc-version-diff vc-annotate-parent-file prev-rev rev-at-line))
3135 (switch-to-buffer "*vc-diff*"))))))
3136
3137(defun vc-current-line ()
3138 "Return the current buffer's line number."
3139 (let ((oldpoint (point)) start)
3140 (save-excursion
3141 (save-restriction
3142 (goto-char (point-min))
3143 (widen)
3144 (forward-line 0)
3145 (setq start (point))
3146 (goto-char oldpoint)
3147 (forward-line 0)
3148 (1+ (count-lines (point-min) (point)))))))
3149
3150(defun vc-annotate-warp-version (revspec)
3151 "Annotate the version described by REVSPEC.
3152
3153If REVSPEC is a positive integer, warp that many versions
3154forward, if possible, otherwise echo a warning message. If
3155REVSPEC is a negative integer, warp that many versions backward,
3156if possible, otherwise echo a warning message. If REVSPEC is a
3157string, then it describes a revision number, so warp to that
3158revision."
3159 (if (not (equal major-mode 'vc-annotate-mode))
3160 (message "Cannot be invoked outside of a vc annotate buffer")
3161 (let* ((oldline (vc-current-line))
3162 (revspeccopy revspec)
3163 (newrev nil))
3164 (cond
3165 ((and (integerp revspec) (> revspec 0))
3166 (setq newrev vc-annotate-parent-rev)
3167 (while (and (> revspec 0) newrev)
3168 (setq newrev (vc-call next-version
3169 vc-annotate-parent-file newrev))
3170 (setq revspec (1- revspec)))
3171 (if (not newrev)
3172 (message "Cannot increment %d versions from version %s"
3173 revspeccopy vc-annotate-parent-rev)))
3174 ((and (integerp revspec) (< revspec 0))
3175 (setq newrev vc-annotate-parent-rev)
3176 (while (and (< revspec 0) newrev)
3177 (setq newrev (vc-call previous-version
3178 vc-annotate-parent-file newrev))
3179 (setq revspec (1+ revspec)))
3180 (if (not newrev)
3181 (message "Cannot decrement %d versions from version %s"
3182 (- 0 revspeccopy) vc-annotate-parent-rev)))
3183 ((stringp revspec) (setq newrev revspec))
3184 (t (error "Invalid argument to vc-annotate-warp-version")))
3185 (when newrev
3186 (save-window-excursion
3187 (find-file vc-annotate-parent-file)
3188 (vc-annotate nil newrev vc-annotate-parent-display-mode))
3189 (kill-buffer (current-buffer)) ;; kill the buffer we started from
3190 (switch-to-buffer (car (car (last vc-annotate-buffers))))
3191 (goto-line (min oldline (progn (goto-char (point-max))
3192 (previous-line)
3193 (vc-current-line))))))))
3194
2982(defun vc-annotate-car-last-cons (a-list) 3195(defun vc-annotate-car-last-cons (a-list)
2983 "Return car of last cons in association list A-LIST." 3196 "Return car of last cons in association list A-LIST."
2984 (if (not (eq nil (cdr a-list))) 3197 (if (not (eq nil (cdr a-list)))