aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndré Spiegel2001-10-22 07:54:03 +0000
committerAndré Spiegel2001-10-22 07:54:03 +0000
commit756651414585fca442dfc5ac13b5ce9ce1de2bd0 (patch)
tree08d37774852a6fc477c2c6090e263229707351c9
parentf958c5ac2fc3aa714215c9f09c2c81bde8e95bb0 (diff)
downloademacs-756651414585fca442dfc5ac13b5ce9ce1de2bd0.tar.gz
emacs-756651414585fca442dfc5ac13b5ce9ce1de2bd0.zip
Change scaling algorithm for vc-annotate.
From JD Smith <jdsmith@astro.cornell.edu>. (vc-annotate-display-default): Accept colormap scaling ratio (now deprecated). (vc-annotate-display-autoscale): Added. (vc-annotate-add-menu): New autoscaling menu options "Span to Oldest" and "Span Oldest->Newest". Easymenu support added for toggle menus driven by customize variable `vc-annotate-display-mode'. (vc-annotate-display-select): Added. (vc-annotate): Changed temp-buffer-show-function to `vc-annotate-display-select'. (vc-annotate-display): Removed arguments BUFFER and BACKEND. Added argument OFFSET. Instead of backend function, calls now generic `vc-annotate-difference'. (vc-annotate-difference): Added as generic function instead of backend-specific function. No longer takes argument POINT, but instead accepts a time OFFSET. (vc-default-annotate-current-time): Added.
-rw-r--r--lisp/vc.el290
1 files changed, 196 insertions, 94 deletions
diff --git a/lisp/vc.el b/lisp/vc.el
index 11193f131fd..729c9cc21a2 100644
--- a/lisp/vc.el
+++ b/lisp/vc.el
@@ -6,7 +6,7 @@
6;; Maintainer: Andre Spiegel <spiegel@gnu.org> 6;; Maintainer: Andre Spiegel <spiegel@gnu.org>
7;; Keywords: tools 7;; Keywords: tools
8 8
9;; $Id: vc.el,v 1.312 2001/10/21 12:15:22 spiegel Exp $ 9;; $Id: vc.el,v 1.313 2001/10/21 23:31:45 spiegel Exp $
10 10
11;; This file is part of GNU Emacs. 11;; This file is part of GNU Emacs.
12 12
@@ -302,15 +302,26 @@
302;; of FILE in BUF, relative to version REV. This is currently only 302;; of FILE in BUF, relative to version REV. This is currently only
303;; implemented for CVS, using the `cvs annotate' command. 303;; implemented for CVS, using the `cvs annotate' command.
304;; 304;;
305;; - annotate-difference (point) 305;; - annotate-time ()
306;; 306;;
307;; Only required if `annotate-command' is defined for the backend. 307;; Only required if `annotate-command' is defined for the backend.
308;; Return the difference between the age of the line at point and the 308;; Return the time of the next line of annotation at or after point,
309;; current time. Return NIL if there is no more comparison to be made 309;; as a floating point fractional number of days. The helper
310;; in the buffer. Return value as defined for `current-time'. You can 310;; function `vc-annotate-convert-time' may be useful for converting
311;; safely assume that point is placed at the beginning of each line, 311;; multi-part times as returned by `current-time' and `encode-time'
312;; starting at `point-min'. The buffer that point is placed in is the 312;; to this format. Return NIL if no more lines of annotation appear
313;; Annotate output, as defined by the relevant backend. 313;; in the buffer. You can safely assume that point is placed at the
314;; beginning of each line, starting at `point-min'. The buffer that
315;; point is placed in is the Annotate output, as defined by the
316;; relevant backend.
317;;
318;; - annotate-current-time ()
319;;
320;; Only required if `annotate-command' is defined for the backend,
321;; AND you'd like the current time considered to be anything besides
322;; (vs-annotate-convert-time (current-time)) -- i.e. the current
323;; time with hours, minutes, and seconds included. Probably safe to
324;; ignore. Return the current-time, in units of fractional days.
314;; 325;;
315;; SNAPSHOT SYSTEM 326;; SNAPSHOT SYSTEM
316;; 327;;
@@ -493,6 +504,15 @@ See `run-hooks'."
493 :group 'vc 504 :group 'vc
494 :version "21.1") 505 :version "21.1")
495 506
507(defcustom vc-annotate-display-mode nil
508 "Which mode to color the annotations with by default."
509 :type '(choice (const :tag "Default" nil)
510 (const :tag "Scale to Oldest" scale)
511 (const :tag "Scale Oldest->Newest" fullscale)
512 (number :tag "Specify Fractional Number of Days"
513 :value "20.5"))
514 :group 'vc)
515
496;;;###autoload 516;;;###autoload
497(defcustom vc-checkin-hook nil 517(defcustom vc-checkin-hook nil
498 "*Normal hook (list of functions) run after a checkin is done. 518 "*Normal hook (list of functions) run after a checkin is done.
@@ -517,26 +537,26 @@ version control backend imposes itself."
517 537
518;; Annotate customization 538;; Annotate customization
519(defcustom vc-annotate-color-map 539(defcustom vc-annotate-color-map
520 '(( 26.3672 . "#FF0000") 540 '(( 20. . "#FF0000")
521 ( 52.7344 . "#FF3800") 541 ( 40. . "#FF3800")
522 ( 79.1016 . "#FF7000") 542 ( 60. . "#FF7000")
523 (105.4688 . "#FFA800") 543 ( 80. . "#FFA800")
524 (131.8359 . "#FFE000") 544 (100. . "#FFE000")
525 (158.2031 . "#E7FF00") 545 (120. . "#E7FF00")
526 (184.5703 . "#AFFF00") 546 (140. . "#AFFF00")
527 (210.9375 . "#77FF00") 547 (160. . "#77FF00")
528 (237.3047 . "#3FFF00") 548 (180. . "#3FFF00")
529 (263.6719 . "#07FF00") 549 (200. . "#07FF00")
530 (290.0391 . "#00FF31") 550 (220. . "#00FF31")
531 (316.4063 . "#00FF69") 551 (240. . "#00FF69")
532 (342.7734 . "#00FFA1") 552 (260. . "#00FFA1")
533 (369.1406 . "#00FFD9") 553 (280. . "#00FFD9")
534 (395.5078 . "#00EEFF") 554 (300. . "#00EEFF")
535 (421.8750 . "#00B6FF") 555 (320. . "#00B6FF")
536 (448.2422 . "#007EFF")) 556 (340. . "#007EFF"))
537 "*Association list of age versus color, for \\[vc-annotate]. 557 "*ASSOCIATION list of age versus color, for \\[vc-annotate].
538Ages are given in units of 2**-16 seconds. 558Ages are given in units of fractional days. Default is eighteen steps
539Default is eighteen steps using a twenty day increment." 559using a twenty day increment."
540 :type 'alist 560 :type 'alist
541 :group 'vc) 561 :group 'vc)
542 562
@@ -2828,7 +2848,9 @@ Uses `rcs2log' which only works for RCS and CVS."
2828 2848
2829;; Declare globally instead of additional parameter to 2849;; Declare globally instead of additional parameter to
2830;; temp-buffer-show-function (not possible to pass more than one 2850;; temp-buffer-show-function (not possible to pass more than one
2831;; parameter). 2851;; parameter). The use of annotate-ratio is deprecated in favor of
2852;; annotate-mode, which replaces it with the more sensible "span-to
2853;; days", along with autoscaling support.
2832(defvar vc-annotate-ratio nil "Global variable.") 2854(defvar vc-annotate-ratio nil "Global variable.")
2833(defvar vc-annotate-backend nil "Global variable.") 2855(defvar vc-annotate-backend nil "Global variable.")
2834 2856
@@ -2846,43 +2868,120 @@ colors. See variable `vc-annotate-menu-elements' for customizing the
2846menu items." 2868menu items."
2847 (vc-annotate-add-menu)) 2869 (vc-annotate-add-menu))
2848 2870
2849(defun vc-annotate-display-default (&optional event) 2871(defun vc-annotate-display-default (&optional ratio)
2850 "Use the default color spectrum for VC Annotate mode." 2872 "Use the default color spectrum for VC Annotate mode, scaling the
2873colormap by RATIO, if present. Use the current time as offset."
2851 (interactive "e") 2874 (interactive "e")
2852 (message "Redisplaying annotation...") 2875 (message "Redisplaying annotation...")
2853 (vc-annotate-display (current-buffer) 2876 (vc-annotate-display
2854 nil 2877 (if ratio (vc-annotate-time-span vc-annotate-color-map ratio)))
2855 (vc-annotate-get-backend (current-buffer)))
2856 (message "Redisplaying annotation...done")) 2878 (message "Redisplaying annotation...done"))
2857 2879
2880(defun vc-annotate-display-autoscale (&optional full)
2881 "Re-display annotation using colormap scaled from the current time
2882to the oldest annotation in the buffer, or, with argument FULL set, to
2883cover the full time range, from oldest to newest."
2884 (interactive)
2885 (let ((newest 0.0)
2886 (oldest 999999.) ;Any CVS users at the founding of Rome?
2887 (current (vc-annotate-convert-time (current-time)))
2888 date)
2889 (message "Redisplaying annotation...")
2890 ;; Run through this file and find the oldest and newest dates annotated.
2891 (save-excursion
2892 (goto-char (point-min))
2893 (while (setq date (vc-call-backend vc-annotate-backend 'annotate-time))
2894 (if (> date newest)
2895 (setq newest date))
2896 (if (< date oldest)
2897 (setq oldest date))))
2898 (vc-annotate-display
2899 (vc-annotate-time-span ;return the scaled colormap.
2900 vc-annotate-color-map
2901 (/ (- (if full newest current) oldest)
2902 (vc-annotate-car-last-cons vc-annotate-color-map)))
2903 (if full newest))
2904 (message "Redisplaying annotation...done \(%s\)"
2905 (if full
2906 (format "Spanned from %.1f to %.1f days old"
2907 (- current oldest)
2908 (- current newest))
2909 (format "Spanned to %.1f days old" (- current oldest))))))
2910
2911;; Menu -- Using easymenu.el
2858(defun vc-annotate-add-menu () 2912(defun vc-annotate-add-menu ()
2859 "Add the menu 'Annotate' to the menu bar in VC-Annotate mode." 2913 "Add the menu 'Annotate' to the menu bar in VC-Annotate mode."
2860 (setq vc-annotate-mode-menu (make-sparse-keymap "Annotate")) 2914 (let ((menu-elements vc-annotate-menu-elements)
2861 (define-key vc-annotate-mode-map [menu-bar vc-annotate-mode] 2915 (menu-def
2862 (cons "VC-Annotate" vc-annotate-mode-menu)) 2916 '("VC-Annotate"
2863 (define-key vc-annotate-mode-menu [default] 2917 ["Default" (unless (null vc-annotate-display-mode)
2864 '("Default" . vc-annotate-display-default)) 2918 (setq vc-annotate-display-mode nil)
2865 (let ((menu-elements vc-annotate-menu-elements)) 2919 (vc-annotate-display-select))
2920 :style toggle :selected (null vc-annotate-display-mode)]))
2921 (oldest-in-map (vc-annotate-car-last-cons vc-annotate-color-map)))
2866 (while menu-elements 2922 (while menu-elements
2867 (let* ((element (car menu-elements)) 2923 (let* ((element (car menu-elements))
2868 (days (round (* element 2924 (days (* element oldest-in-map)))
2869 (vc-annotate-car-last-cons vc-annotate-color-map)
2870 0.7585))))
2871 (setq menu-elements (cdr menu-elements)) 2925 (setq menu-elements (cdr menu-elements))
2872 (define-key vc-annotate-mode-menu 2926 (setq menu-def
2873 (vector days) 2927 (append menu-def
2874 (cons (format "Span %d days" 2928 `([,(format "Span %.1f days" days)
2875 days) 2929 (unless (and (numberp vc-annotate-display-mode)
2876 `(lambda () 2930 (= vc-annotate-display-mode ,days))
2877 ,(format "Use colors spanning %d days" days) 2931 (vc-annotate-display-select nil ,days))
2932 :style toggle :selected
2933 (and (numberp vc-annotate-display-mode)
2934 (= vc-annotate-display-mode ,days)) ])))))
2935 (setq menu-def
2936 (append menu-def
2937 (list
2938 ["Span ..."
2939 (let ((days
2940 (float (string-to-number
2941 (read-string "Span how many days? ")))))
2942 (vc-annotate-display-select nil days)) t])
2943 (list "--")
2944 (list
2945 ["Span to Oldest"
2946 (unless (eq vc-annotate-display-mode 'scale)
2947 (vc-annotate-display-select nil 'scale))
2948 :style toggle :selected
2949 (eq vc-annotate-display-mode 'scale)])
2950 (list
2951 ["Span Oldest->Newest"
2952 (unless (eq vc-annotate-display-mode 'fullscale)
2953 (vc-annotate-display-select nil 'fullscale))
2954 :style toggle :selected
2955 (eq vc-annotate-display-mode 'fullscale)])))
2956 ;; Define the menu
2957 (if (or (featurep 'easymenu) (load "easymenu" t))
2958 (easy-menu-define vc-annotate-mode-menu vc-annotate-mode-map
2959 "VC Annotate Display Menu" menu-def))))
2960
2961(defun vc-annotate-display-select (&optional buffer mode)
2962 "Do the default or chosen annotation display as specified in the
2963customizable variable `vc-annotate-display-mode'."
2878 (interactive) 2964 (interactive)
2879 (message "Redisplaying annotation...") 2965 (if mode (setq vc-annotate-display-mode mode))
2880 (vc-annotate-display 2966 (when buffer
2881 (get-buffer (buffer-name)) 2967 (set-buffer buffer)
2882 (vc-annotate-time-span vc-annotate-color-map ,element) 2968 (display-buffer buffer))
2883 (vc-annotate-get-backend (current-buffer))) 2969 (if (not vc-annotate-mode) ; Turn on vc-annotate-mode if not done
2884 (message "Redisplaying annotation...done")))))))) 2970 (vc-annotate-mode))
2885 2971 (cond ((null vc-annotate-display-mode) (vc-annotate-display-default
2972 vc-annotate-ratio))
2973 ((symbolp vc-annotate-display-mode) ; One of the auto-scaling modes
2974 (cond ((eq vc-annotate-display-mode 'scale)
2975 (vc-annotate-display-autoscale))
2976 ((eq vc-annotate-display-mode 'fullscale)
2977 (vc-annotate-display-autoscale t))
2978 (t (error "No such display mode: %s"
2979 vc-annotate-display-mode))))
2980 ((numberp vc-annotate-display-mode) ; A fixed number of days lookback
2981 (vc-annotate-display-default
2982 (/ vc-annotate-display-mode (vc-annotate-car-last-cons
2983 vc-annotate-color-map))))
2984 (t (error "Error in display mode select"))))
2886 2985
2887;;;; (defun vc-BACKEND-annotate-command (file buffer) ...) 2986;;;; (defun vc-BACKEND-annotate-command (file buffer) ...)
2888;;;; Execute "annotate" on FILE by using `call-process' and insert 2987;;;; Execute "annotate" on FILE by using `call-process' and insert
@@ -2918,19 +3017,19 @@ colors. `vc-annotate-background' specifies the background color."
2918 (interactive "P") 3017 (interactive "P")
2919 (vc-ensure-vc-buffer) 3018 (vc-ensure-vc-buffer)
2920 (let* ((temp-buffer-name (concat "*Annotate " (buffer-name) "*")) 3019 (let* ((temp-buffer-name (concat "*Annotate " (buffer-name) "*"))
2921 (temp-buffer-show-function 'vc-annotate-display) 3020 (temp-buffer-show-function 'vc-annotate-display-select)
2922 (rev (vc-workfile-version (buffer-file-name))) 3021 (rev (vc-workfile-version (buffer-file-name)))
2923 (vc-annotate-version 3022 (vc-annotate-version
2924 (if prefix (read-string 3023 (if prefix (read-string
2925 (format "Annotate from version: (default %s) " rev) 3024 (format "Annotate from version: (default %s) " rev)
2926 nil nil rev) 3025 nil nil rev)
2927 rev)) 3026 rev)))
2928 (vc-annotate-ratio 3027 (if prefix
2929 (if prefix (string-to-number 3028 (setq vc-annotate-display-mode
2930 (read-string "Annotate ratio: (default 1.0) " 3029 (float (string-to-number
2931 nil nil "1.0")) 3030 (read-string "Annotate span days: (default 20) "
2932 1.0)) 3031 nil nil "20")))))
2933 (vc-annotate-backend (vc-backend (buffer-file-name)))) 3032 (setq vc-annotate-backend (vc-backend (buffer-file-name)))
2934 (message "Annotating...") 3033 (message "Annotating...")
2935 (if (not (vc-find-backend-function vc-annotate-backend 'annotate-command)) 3034 (if (not (vc-find-backend-function vc-annotate-backend 'annotate-command))
2936 (error "Sorry, annotating is not implemented for %s" 3035 (error "Sorry, annotating is not implemented for %s"
@@ -2947,7 +3046,6 @@ colors. `vc-annotate-background' specifies the background color."
2947 (list (cons (get-buffer temp-buffer-name) vc-annotate-backend)))) 3046 (list (cons (get-buffer temp-buffer-name) vc-annotate-backend))))
2948 (message "Annotating... done"))) 3047 (message "Annotating... done")))
2949 3048
2950
2951(defun vc-annotate-car-last-cons (a-list) 3049(defun vc-annotate-car-last-cons (a-list)
2952 "Return car of last cons in association list A-LIST." 3050 "Return car of last cons in association list A-LIST."
2953 (if (not (eq nil (cdr a-list))) 3051 (if (not (eq nil (cdr a-list)))
@@ -2977,26 +3075,34 @@ nil otherwise"
2977 (setq i (+ i 1))) 3075 (setq i (+ i 1)))
2978 tmp-cons)) ; Return the appropriate value 3076 tmp-cons)) ; Return the appropriate value
2979 3077
2980 3078(defun vc-annotate-convert-time (time)
2981(defun vc-annotate-display (buffer &optional color-map backend) 3079 "Convert high/low times, as returned by `current-time' and
2982 "Do the VC-Annotate display in BUFFER using COLOR-MAP. 3080`encode-time', to a single floating point value in units of days.
2983The original annotating file is supposed to be handled by BACKEND. 3081TIME is list, only the first two elements of TIME are considered,
2984If BACKEND is NIL, variable VC-ANNOTATE-BACKEND is used instead. 3082comprising the high 16 and low 16 bits of the number of seconds since
2985This function is destructive on VC-ANNOTATE-BACKEND when BACKEND is non-nil." 3083Jan 1, 1970."
2986 3084 (/ (+ (* (float (car time)) (lsh 1 16)) (cadr time)) 24 3600))
2987 ;; Handle the case of the global variable vc-annotate-ratio being 3085
2988 ;; set. This variable is used to pass information from function 3086(defun vc-annotate-difference (&optional offset)
2989 ;; vc-annotate since it is not possible to use another parameter 3087 "Calculate the difference, in days, from the current time and the
2990 ;; (see temp-buffer-show-function). 3088time returned from the backend function annotate-time. If OFFSET is
2991 (if (and (not color-map) vc-annotate-ratio) 3089set, use it as the time base instead of the current time."
2992 ;; This will only be true if called from vc-annotate with ratio 3090 (let ((next-time (vc-call-backend vc-annotate-backend 'annotate-time)))
2993 ;; being non-nil. 3091 (if next-time
2994 (setq color-map (vc-annotate-time-span vc-annotate-color-map 3092 (- (or offset
2995 vc-annotate-ratio))) 3093 (vc-call-backend vc-annotate-backend 'annotate-current-time))
2996 (set-buffer buffer) 3094 next-time))))
2997 (display-buffer buffer) 3095
2998 (if (not vc-annotate-mode) ; Turn on vc-annotate-mode if not done 3096(defun vc-default-annotate-current-time (backend)
2999 (vc-annotate-mode)) 3097 "Return the current time, encoded as fractional days."
3098 (vc-annotate-convert-time (current-time)))
3099
3100(defun vc-annotate-display (&optional color-map offset)
3101 "Do the VC-Annotate display in BUFFER using COLOR-MAP, and time
3102offset OFFSET (defaults to the present time). You probably want
3103`vc-annotate-select' instead, after setting
3104`vc-annotate-display-mode'"
3105 (save-excursion
3000 (goto-char (point-min)) ; Position at the top of the buffer. 3106 (goto-char (point-min)) ; Position at the top of the buffer.
3001 ;; Delete old overlays 3107 ;; Delete old overlays
3002 (mapcar 3108 (mapcar
@@ -3005,11 +3111,8 @@ This function is destructive on VC-ANNOTATE-BACKEND when BACKEND is non-nil."
3005 (delete-overlay overlay))) 3111 (delete-overlay overlay)))
3006 (overlays-in (point-min) (point-max))) 3112 (overlays-in (point-min) (point-max)))
3007 (goto-char (point-min)) ; Position at the top of the buffer. 3113 (goto-char (point-min)) ; Position at the top of the buffer.
3008 3114 (let (difference)
3009 (if backend (setq vc-annotate-backend backend)) ; Destructive on `vc-annotate-backend' 3115 (while (setq difference (vc-annotate-difference offset))
3010
3011 (let ((difference (vc-call-backend vc-annotate-backend 'annotate-difference (point))))
3012 (while difference
3013 (let* 3116 (let*
3014 ((color (or (vc-annotate-compcar 3117 ((color (or (vc-annotate-compcar
3015 difference (or color-map vc-annotate-color-map)) 3118 difference (or color-map vc-annotate-color-map))
@@ -3021,16 +3124,15 @@ This function is destructive on VC-ANNOTATE-BACKEND when BACKEND is non-nil."
3021 (let ((tmp-face (make-face (intern face-name)))) 3124 (let ((tmp-face (make-face (intern face-name))))
3022 (set-face-foreground tmp-face (cdr color)) 3125 (set-face-foreground tmp-face (cdr color))
3023 (if vc-annotate-background 3126 (if vc-annotate-background
3024 (set-face-background tmp-face vc-annotate-background)) 3127 (set-face-background tmp-face
3128 vc-annotate-background))
3025 tmp-face))) ; Return the face 3129 tmp-face))) ; Return the face
3026 (point (point)) 3130 (point (point))
3027 overlay) 3131 overlay)
3028 (forward-line 1) 3132 (forward-line 1)
3029 (setq overlay (make-overlay point (point))) 3133 (setq overlay (make-overlay point (point)))
3030 (overlay-put overlay 'face face) 3134 (overlay-put overlay 'face face)
3031 (overlay-put overlay 'vc-annotation t)) 3135 (overlay-put overlay 'vc-annotation t))))))
3032 (setq difference (vc-call-backend vc-annotate-backend 'annotate-difference (point))))))
3033
3034 3136
3035;; Collect back-end-dependent stuff here 3137;; Collect back-end-dependent stuff here
3036 3138