diff options
| author | Richard M. Stallman | 1997-06-09 06:01:12 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1997-06-09 06:01:12 +0000 |
| commit | 7d2d94821205cfcdef159ebaf04c36113d27bc11 (patch) | |
| tree | 7f02933e3cb9aa95cf389eaa0804b0c11941a603 | |
| parent | 421a590c24b1371bfbe07a4a789fbebfe40718f9 (diff) | |
| download | emacs-7d2d94821205cfcdef159ebaf04c36113d27bc11.tar.gz emacs-7d2d94821205cfcdef159ebaf04c36113d27bc11.zip | |
(diff-switches): defvar deleted.
(vc-annotate-*): New functions and variables.
| -rw-r--r-- | lisp/vc.el | 221 |
1 files changed, 220 insertions, 1 deletions
diff --git a/lisp/vc.el b/lisp/vc.el index d261692db04..837c98da1df 100644 --- a/lisp/vc.el +++ b/lisp/vc.el | |||
| @@ -154,10 +154,50 @@ These are passed to the checkin program by \\[vc-register]." | |||
| 154 | "Maximum number of saved comments in the comment ring.") | 154 | "Maximum number of saved comments in the comment ring.") |
| 155 | 155 | ||
| 156 | ;;; This is duplicated in diff.el. | 156 | ;;; This is duplicated in diff.el. |
| 157 | ;;; ...and customized. | ||
| 158 | (defvar diff-switches "-c" | 157 | (defvar diff-switches "-c" |
| 159 | "*A string or list of strings specifying switches to be be passed to diff.") | 158 | "*A string or list of strings specifying switches to be be passed to diff.") |
| 160 | 159 | ||
| 160 | (defcustom vc-annotate-color-map | ||
| 161 | '(( 26.3672 . "#FF0000") | ||
| 162 | ( 52.7344 . "#FF3800") | ||
| 163 | ( 79.1016 . "#FF7000") | ||
| 164 | (105.4688 . "#FFA800") | ||
| 165 | (131.8359 . "#FFE000") | ||
| 166 | (158.2031 . "#E7FF00") | ||
| 167 | (184.5703 . "#AFFF00") | ||
| 168 | (210.9375 . "#77FF00") | ||
| 169 | (237.3047 . "#3FFF00") | ||
| 170 | (263.6719 . "#07FF00") | ||
| 171 | (290.0391 . "#00FF31") | ||
| 172 | (316.4063 . "#00FF69") | ||
| 173 | (342.7734 . "#00FFA1") | ||
| 174 | (369.1406 . "#00FFD9") | ||
| 175 | (395.5078 . "#00EEFF") | ||
| 176 | (421.8750 . "#00B6FF") | ||
| 177 | (448.2422 . "#007EFF")) | ||
| 178 | "*Association list of age versus color, for \\[vc-annotate]. | ||
| 179 | Ages are given in units of 2**-16 seconds. | ||
| 180 | Default is eighteen steps using a twenty day increment." | ||
| 181 | :type 'sexp | ||
| 182 | :group 'vc) | ||
| 183 | |||
| 184 | (defcustom vc-annotate-very-old-color "#0046FF" | ||
| 185 | "*Color for lines older than CAR of last cons in `vc-annotate-color-map'." | ||
| 186 | :type 'string | ||
| 187 | :group 'vc) | ||
| 188 | |||
| 189 | (defcustom vc-annotate-background "black" | ||
| 190 | "*Background color for \\[vc-annotate]. | ||
| 191 | Default color is used if nil." | ||
| 192 | :type 'string | ||
| 193 | :group 'vc) | ||
| 194 | |||
| 195 | (defcustom vc-annotate-menu-elements '(2 0.5 0.1 0.01) | ||
| 196 | "*Menu elements for the mode-specific menu of VC-Annotate mode. | ||
| 197 | List of factors, used to expand/compress the time scale. See `vc-annotate'." | ||
| 198 | :type 'sexp | ||
| 199 | :group 'vc) | ||
| 200 | |||
| 161 | ;;;###autoload | 201 | ;;;###autoload |
| 162 | (defcustom vc-checkin-hook nil | 202 | (defcustom vc-checkin-hook nil |
| 163 | "*Normal hook (List of functions) run after a checkin is done. | 203 | "*Normal hook (List of functions) run after a checkin is done. |
| @@ -172,6 +212,12 @@ See `run-hooks'." | |||
| 172 | :type 'hook | 212 | :type 'hook |
| 173 | :group 'vc) | 213 | :group 'vc) |
| 174 | 214 | ||
| 215 | ;;;###autoload | ||
| 216 | (defcustom vc-annotate-mode-hook nil | ||
| 217 | "*Hooks to run when VC-Annotate mode is turned on." | ||
| 218 | :type 'hook | ||
| 219 | :group 'vc) | ||
| 220 | |||
| 175 | ;; Header-insertion hair | 221 | ;; Header-insertion hair |
| 176 | 222 | ||
| 177 | (defcustom vc-header-alist | 223 | (defcustom vc-header-alist |
| @@ -1933,7 +1979,179 @@ default directory." | |||
| 1933 | "failed")) | 1979 | "failed")) |
| 1934 | (cd (file-name-directory changelog)) | 1980 | (cd (file-name-directory changelog)) |
| 1935 | (delete-file tempfile))))) | 1981 | (delete-file tempfile))))) |
| 1982 | |||
| 1983 | ;; vc-annotate functionality (CVS only). | ||
| 1984 | (defvar vc-annotate-mode nil | ||
| 1985 | "Variable indicating if VC-Annotate mode is active.") | ||
| 1986 | |||
| 1987 | (defvar vc-annotate-mode-map () | ||
| 1988 | "Local keymap used for VC-Annotate mode.") | ||
| 1989 | |||
| 1990 | ;; Syntax Table | ||
| 1991 | (defvar vc-annotate-mode-syntax-table nil | ||
| 1992 | "Syntax table used in VC-Annotate mode buffers.") | ||
| 1993 | |||
| 1994 | (defun vc-annotate-mode-variables () | ||
| 1995 | (if (not vc-annotate-mode-syntax-table) | ||
| 1996 | (progn (setq vc-annotate-mode-syntax-table (make-syntax-table)) | ||
| 1997 | (set-syntax-table vc-annotate-mode-syntax-table))) | ||
| 1998 | (if (not vc-annotate-mode-map) | ||
| 1999 | (setq vc-annotate-mode-map (make-sparse-keymap)))) | ||
| 2000 | |||
| 2001 | (defun vc-annotate-mode () | ||
| 2002 | "Major mode for buffers displaying output from the CVS `annotate' command. | ||
| 2003 | |||
| 2004 | You can use the mode-specific menu to alter the time-span of the used | ||
| 2005 | colors. See variable `vc-annotate-menu-elements' for customizing the | ||
| 2006 | menu items." | ||
| 2007 | (interactive) | ||
| 2008 | (kill-all-local-variables) ; Recommended by RMS. | ||
| 2009 | (vc-annotate-mode-variables) ; This defines various variables. | ||
| 2010 | (use-local-map vc-annotate-mode-map) ; This provides the local keymap. | ||
| 2011 | (set-syntax-table vc-annotate-mode-syntax-table) | ||
| 2012 | (setq major-mode 'vc-annotate-mode) ; This is how `describe-mode' | ||
| 2013 | ; finds out what to describe. | ||
| 2014 | (setq mode-name "Annotate") ; This goes into the mode line. | ||
| 2015 | (run-hooks 'vc-annotate-mode-hook) | ||
| 2016 | (vc-annotate-add-menu)) | ||
| 2017 | |||
| 2018 | (defun vc-annotate-display-default (&optional event) | ||
| 2019 | "Use the default color spectrum for VC Annotate mode." | ||
| 2020 | (interactive) | ||
| 2021 | (vc-annotate-display (get-buffer (buffer-name)))) | ||
| 2022 | |||
| 2023 | (defun vc-annotate-add-menu () | ||
| 2024 | "Adds the menu 'Annotate' to the menu bar in VC-Annotate mode." | ||
| 2025 | (setq vc-annotate-mode-menu (make-sparse-keymap "Annotate")) | ||
| 2026 | (define-key vc-annotate-mode-menu [default] | ||
| 2027 | '("Default" . vc-annotate-display-default)) | ||
| 2028 | (let ((menu-elements vc-annotate-menu-elements)) | ||
| 2029 | (while menu-elements | ||
| 2030 | (let* ((element (car menu-elements)) | ||
| 2031 | (days (round (* element | ||
| 2032 | (vc-annotate-car-last-cons vc-annotate-color-map) | ||
| 2033 | 0.7585)))) | ||
| 2034 | (setq menu-elements (cdr menu-elements)) | ||
| 2035 | (define-key vc-annotate-mode-menu | ||
| 2036 | (vector days) | ||
| 2037 | (cons (format "Span %d days" | ||
| 2038 | days) | ||
| 2039 | `(lambda () | ||
| 2040 | ,(format "Use colors spanning %d days" days) | ||
| 2041 | (vc-annotate-display (get-buffer (buffer-name)) | ||
| 2042 | (vc-annotate-time-span ,element))))))))) | ||
| 2043 | |||
| 2044 | (defvar vc-annotate-ratio) | ||
| 1936 | 2045 | ||
| 2046 | ;;;###autoload | ||
| 2047 | (defun vc-annotate (ratio) | ||
| 2048 | "Display the result of the CVS `annotate' command using colors. | ||
| 2049 | New lines are displayed in red, old in blue. | ||
| 2050 | A prefix argument specifies a factor for stretching the time scale. | ||
| 2051 | |||
| 2052 | `vc-annotate-menu-elements' customizes the menu elements of the | ||
| 2053 | mode-specific menu. `vc-annotate-color-map' and | ||
| 2054 | `vc-annotate-very-old-color' defines the mapping of time to | ||
| 2055 | colors. `vc-annotate-background' specifies the background color." | ||
| 2056 | (interactive "p") | ||
| 2057 | (if (not (eq (vc-buffer-backend) 'CVS)) ; This only works with CVS | ||
| 2058 | (vc-registration-error (buffer-file-name))) | ||
| 2059 | (message "Annotating...") | ||
| 2060 | (let ((temp-buffer-name (concat "*cvs annotate " (buffer-name) "*")) | ||
| 2061 | (temp-buffer-show-function 'vc-annotate-display) | ||
| 2062 | (vc-annotate-ratio ratio)) | ||
| 2063 | (with-output-to-temp-buffer temp-buffer-name | ||
| 2064 | (call-process "cvs" nil (get-buffer temp-buffer-name) nil | ||
| 2065 | "annotate" (file-name-nondirectory (buffer-file-name))))) | ||
| 2066 | (message "Annotating... done")) | ||
| 2067 | |||
| 2068 | (defun vc-annotate-car-last-cons (assoc-list) | ||
| 2069 | "Return car of last cons in ASSOC-LIST." | ||
| 2070 | (if (not (eq nil (cdr assoc-list))) | ||
| 2071 | (vc-annotate-car-last-cons (cdr assoc-list)) | ||
| 2072 | (car (car assoc-list)))) | ||
| 2073 | |||
| 2074 | ;; Return an association list with span factor applied to the | ||
| 2075 | ;; time-span of assoc-list. Optionaly quantize to the factor of | ||
| 2076 | ;; quantize. | ||
| 2077 | (defun vc-annotate-time-span (assoc-list span &optional quantize) | ||
| 2078 | ;; Apply span to each car of every cons | ||
| 2079 | (if (not (eq nil assoc-list)) | ||
| 2080 | (append (list (cons (* (car (car assoc-list)) span) | ||
| 2081 | (cdr (car assoc-list)))) | ||
| 2082 | (vc-annotate-time-span (nthcdr (cond (quantize) ; optional | ||
| 2083 | (1)) ; Default to cdr | ||
| 2084 | assoc-list) span quantize)))) | ||
| 2085 | |||
| 2086 | (defun vc-annotate-compcar (threshold &rest args) | ||
| 2087 | "Test successive cars of ARGS against THRESHOLD. | ||
| 2088 | Return the first cons which CAR is not less than THRESHOLD, nil otherwise" | ||
| 2089 | ;; If no list is exhausted, | ||
| 2090 | (if (and (not (memq 'nil args)) (< (car (car (car args))) threshold)) | ||
| 2091 | ;; apply to CARs. | ||
| 2092 | (apply 'vc-annotate-compcar threshold | ||
| 2093 | ;; Recurse for rest of elements. | ||
| 2094 | (mapcar 'cdr args)) | ||
| 2095 | ;; Return the proper result | ||
| 2096 | (car (car args)))) | ||
| 2097 | |||
| 2098 | (defun vc-annotate-display (buffer &optional color-map) | ||
| 2099 | "Do the VC-Annotate display in BUFFER using COLOR-MAP." | ||
| 2100 | |||
| 2101 | (if (and (not color-map) vc-annotate-ratio) | ||
| 2102 | (setq color-map (vc-annotate-time-span color-map vc-annotate-ratio))) | ||
| 2103 | |||
| 2104 | ;; We need a list of months and their corresponding numbers. | ||
| 2105 | (let* ((local-month-numbers | ||
| 2106 | '(("Jan" . 1) ("Feb" . 2) ("Mar" . 3) ("Apr" . 4) | ||
| 2107 | ("May" . 5) ("Jun" . 6) ("Jul" . 7) ("Aug" . 8) | ||
| 2108 | ("Sep" . 9) ("Oct" . 10) ("Nov" . 11) ("Dec" . 12))) | ||
| 2109 | ;; XEmacs use extents, GNU Emacs overlays. | ||
| 2110 | (overlay-or-extent (if (string-match "XEmacs" emacs-version) | ||
| 2111 | (cons 'make-extent 'set-extent-property) | ||
| 2112 | (cons 'make-overlay 'overlay-put))) | ||
| 2113 | (make-overlay-or-extent (car overlay-or-extent)) | ||
| 2114 | (set-property-overlay-or-extent (cdr overlay-or-extent))) | ||
| 2115 | |||
| 2116 | (set-buffer buffer) | ||
| 2117 | (display-buffer buffer) | ||
| 2118 | (if (not vc-annotate-mode) ; Turn on vc-annotate-mode if not done | ||
| 2119 | (vc-annotate-mode)) | ||
| 2120 | (goto-char (point-min)) ; Position at the top of the buffer. | ||
| 2121 | (while (re-search-forward | ||
| 2122 | "^[0-9]+\\(\.[0-9]+\\)*\\s-+(\\sw+\\s-+\\([0-9]+\\)-\\(\\sw+\\)-\\([0-9]+\\)): " | ||
| 2123 | nil t) | ||
| 2124 | |||
| 2125 | (let* (;; Unfortunately, order is important. match-string will | ||
| 2126 | ;; be corrupted by extent functions in XEmacs. Access | ||
| 2127 | ;; string-matches first. | ||
| 2128 | (day (string-to-number (match-string 2))) | ||
| 2129 | (month (cdr (assoc (match-string 3) local-month-numbers))) | ||
| 2130 | (year-tmp (string-to-number (match-string 4))) | ||
| 2131 | (year (+ (if (> 100 year-tmp) 1900 0) year-tmp)) ; Possible millenium problem | ||
| 2132 | (high (- (car (current-time)) | ||
| 2133 | (car (encode-time 0 0 0 day month year)))) | ||
| 2134 | (color (cond ((vc-annotate-compcar high (cond (color-map) | ||
| 2135 | (vc-annotate-color-map)))) | ||
| 2136 | ((cons nil vc-annotate-very-old-color)))) | ||
| 2137 | ;; substring from index 1 to remove any leading `#' in the name | ||
| 2138 | (face-name (concat "vc-annotate-face-" (substring (cdr color) 1))) | ||
| 2139 | ;; Make the face if not done. | ||
| 2140 | (face (cond ((intern-soft face-name)) | ||
| 2141 | ((make-face (intern face-name))))) | ||
| 2142 | (point (point)) | ||
| 2143 | (foo (forward-line 1)) | ||
| 2144 | (overlay (cond ((if (string-match "XEmacs" emacs-version) | ||
| 2145 | (extent-at point) | ||
| 2146 | (car (overlays-at point )))) | ||
| 2147 | ((apply make-overlay-or-extent point (point) nil))))) | ||
| 2148 | |||
| 2149 | (if vc-annotate-background | ||
| 2150 | (set-face-background face vc-annotate-background)) | ||
| 2151 | (set-face-foreground face (cdr color)) | ||
| 2152 | (apply set-property-overlay-or-extent overlay | ||
| 2153 | 'face face nil))))) | ||
| 2154 | |||
| 1937 | ;; Collect back-end-dependent stuff here | 2155 | ;; Collect back-end-dependent stuff here |
| 1938 | 2156 | ||
| 1939 | (defun vc-backend-admin (file &optional rev comment) | 2157 | (defun vc-backend-admin (file &optional rev comment) |
| @@ -2451,6 +2669,7 @@ These bindings are added to the global keymap when you enter this mode: | |||
| 2451 | \\[vc-diff] show diffs between file versions | 2669 | \\[vc-diff] show diffs between file versions |
| 2452 | \\[vc-version-other-window] visit old version in another window | 2670 | \\[vc-version-other-window] visit old version in another window |
| 2453 | \\[vc-directory] show all files locked by any user in or below . | 2671 | \\[vc-directory] show all files locked by any user in or below . |
| 2672 | \\[vc-annotate] colorful display of the cvs annotate command | ||
| 2454 | \\[vc-update-change-log] add change log entry from recent checkins | 2673 | \\[vc-update-change-log] add change log entry from recent checkins |
| 2455 | 2674 | ||
| 2456 | While you are entering a change log message for a version, the following | 2675 | While you are entering a change log message for a version, the following |