(#includes): Allow compilation with only Xaw.
[emacs.git] / lisp / vc-hooks.el
blobda42dcbc12eeb540823bae14d1061eee89a17b98
1 ;;; vc-hooks.el --- resident support for version-control
3 ;; Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998 Free Software Foundation, Inc.
5 ;; Author: Eric S. Raymond <esr@snark.thyrsus.com>
6 ;; Maintainer: Andre Spiegel <spiegel@inf.fu-berlin.de>
8 ;; $Id: vc-hooks.el,v 1.113 1998/11/11 18:47:32 kwzh Exp $
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; any later version.
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
25 ;; Boston, MA 02111-1307, USA.
27 ;;; Commentary:
29 ;; This is the always-loaded portion of VC.
30 ;; It takes care VC-related activities that are done when you visit a file,
31 ;; so that vc.el itself is loaded only when you use a VC command.
32 ;; See the commentary of vc.el.
34 ;;; Code:
36 ;; Customization Variables (the rest is in vc.el)
38 (defcustom vc-default-back-end nil
39 "*Back-end actually used by this interface; may be SCCS or RCS.
40 The value is only computed when needed to avoid an expensive search."
41 :type '(choice (const nil) (const RCS) (const SCCS))
42 :group 'vc)
44 (defcustom vc-handle-cvs t
45 "*If non-nil, use VC for files managed with CVS.
46 If it is nil, don't use VC for those files."
47 :type 'boolean
48 :group 'vc)
50 (defcustom vc-rcsdiff-knows-brief nil
51 "*Indicates whether rcsdiff understands the --brief option.
52 The value is either `yes', `no', or nil. If it is nil, VC tries
53 to use --brief and sets this variable to remember whether it worked."
54 :type '(choice (const nil) (const yes) (const no))
55 :group 'vc)
57 (defcustom vc-path
58 (if (file-directory-p "/usr/sccs")
59 '("/usr/sccs")
60 nil)
61 "*List of extra directories to search for version control commands."
62 :type '(repeat directory)
63 :group 'vc)
65 (defcustom vc-master-templates
66 '(("%sRCS/%s,v" . RCS) ("%s%s,v" . RCS) ("%sRCS/%s" . RCS)
67 ("%sSCCS/s.%s" . SCCS) ("%ss.%s". SCCS)
68 vc-find-cvs-master
69 vc-search-sccs-project-dir)
70 "*Where to look for version-control master files.
71 The first pair corresponding to a given back end is used as a template
72 when creating new masters.
73 Setting this variable to nil turns off use of VC entirely."
74 :type '(repeat sexp)
75 :group 'vc)
77 (defcustom vc-make-backup-files nil
78 "*If non-nil, backups of registered files are made as with other files.
79 If nil (the default), files covered by version control don't get backups."
80 :type 'boolean
81 :group 'vc)
83 (defcustom vc-follow-symlinks 'ask
84 "*Indicates what to do if you visit a symbolic link to a file
85 that is under version control. Editing such a file through the
86 link bypasses the version control system, which is dangerous and
87 probably not what you want.
88 If this variable is t, VC follows the link and visits the real file,
89 telling you about it in the echo area. If it is `ask', VC asks for
90 confirmation whether it should follow the link. If nil, the link is
91 visited and a warning displayed."
92 :type '(choice (const ask) (const nil) (const t))
93 :group 'vc)
95 (defcustom vc-display-status t
96 "*If non-nil, display revision number and lock status in modeline.
97 Otherwise, not displayed."
98 :type 'boolean
99 :group 'vc)
102 (defcustom vc-consult-headers t
103 "*If non-nil, identify work files by searching for version headers."
104 :type 'boolean
105 :group 'vc)
107 (defcustom vc-keep-workfiles t
108 "*If non-nil, don't delete working files after registering changes.
109 If the back-end is CVS, workfiles are always kept, regardless of the
110 value of this flag."
111 :type 'boolean
112 :group 'vc)
114 (defcustom vc-mistrust-permissions nil
115 "*If non-nil, don't assume that permissions and ownership track
116 version-control status. If nil, do rely on the permissions.
117 See also variable `vc-consult-headers'."
118 :type 'boolean
119 :group 'vc)
121 (defcustom vc-ignore-vc-files nil
122 "*If non-nil don't look for version control information when finding files.
124 It may be useful to set this if (say) you edit files in a directory
125 containing corresponding RCS files but don't have RCS available;
126 similarly for other version control systems."
127 :type 'boolean
128 :group 'vc
129 :version "20.3")
131 (defun vc-mistrust-permissions (file)
132 ;; Access function to the above.
133 (or (eq vc-mistrust-permissions 't)
134 (and vc-mistrust-permissions
135 (funcall vc-mistrust-permissions
136 (vc-backend-subdirectory-name file)))))
138 ;; Tell Emacs about this new kind of minor mode
139 (if (not (assoc 'vc-mode minor-mode-alist))
140 (setq minor-mode-alist (cons '(vc-mode vc-mode)
141 minor-mode-alist)))
143 (make-variable-buffer-local 'vc-mode)
144 (put 'vc-mode 'permanent-local t)
146 ;; We need a notion of per-file properties because the version
147 ;; control state of a file is expensive to derive --- we compute
148 ;; them when the file is initially found, keep them up to date
149 ;; during any subsequent VC operations, and forget them when
150 ;; the buffer is killed.
152 (defmacro vc-error-occurred (&rest body)
153 (list 'condition-case nil (cons 'progn (append body '(nil))) '(error t)))
155 (defvar vc-file-prop-obarray [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
156 "Obarray for per-file properties.")
158 (defvar vc-buffer-backend t)
159 (make-variable-buffer-local 'vc-buffer-backend)
161 (defun vc-file-setprop (file property value)
162 ;; set per-file property
163 (put (intern file vc-file-prop-obarray) property value))
165 (defun vc-file-getprop (file property)
166 ;; get per-file property
167 (get (intern file vc-file-prop-obarray) property))
169 (defun vc-file-clearprops (file)
170 ;; clear all properties of a given file
171 (setplist (intern file vc-file-prop-obarray) nil))
173 ;;; Functions that determine property values, by examining the
174 ;;; working file, the master file, or log program output
176 (defun vc-match-substring (bn)
177 (buffer-substring (match-beginning bn) (match-end bn)))
179 (defun vc-lock-file (file)
180 ;; Generate lock file name corresponding to FILE
181 (let ((master (vc-name file)))
182 (and
183 master
184 (string-match "\\(.*/\\)s\\.\\(.*\\)" master)
185 (concat
186 (substring master (match-beginning 1) (match-end 1))
187 "p."
188 (substring master (match-beginning 2) (match-end 2))))))
190 (defun vc-parse-buffer (patterns &optional file properties)
191 ;; Use PATTERNS to parse information out of the current buffer.
192 ;; Each element of PATTERNS is a list of 2 to 3 elements. The first element
193 ;; is the pattern to be matched, and the second (an integer) is the
194 ;; number of the subexpression that should be returned. If there's
195 ;; a third element (also the number of a subexpression), that
196 ;; subexpression is assumed to be a date field and we want the most
197 ;; recent entry matching the template.
198 ;; If FILE and PROPERTIES are given, the latter must be a list of
199 ;; properties of the same length as PATTERNS; each property is assigned
200 ;; the corresponding value.
201 (mapcar (function (lambda (p)
202 (goto-char (point-min))
203 (cond
204 ((eq (length p) 2) ;; search for first entry
205 (let ((value nil))
206 (if (re-search-forward (car p) nil t)
207 (setq value (vc-match-substring (elt p 1))))
208 (if file
209 (progn (vc-file-setprop file (car properties) value)
210 (setq properties (cdr properties))))
211 value))
212 ((eq (length p) 3) ;; search for latest entry
213 (let ((latest-date "") (latest-val))
214 (while (re-search-forward (car p) nil t)
215 (let ((date (vc-match-substring (elt p 2))))
216 (if (string< latest-date date)
217 (progn
218 (setq latest-date date)
219 (setq latest-val
220 (vc-match-substring (elt p 1)))))))
221 (if file
222 (progn (vc-file-setprop file (car properties) latest-val)
223 (setq properties (cdr properties))))
224 latest-val)))))
225 patterns)
228 (defun vc-insert-file (file &optional limit blocksize)
229 ;; Insert the contents of FILE into the current buffer.
230 ;; Optional argument LIMIT is a regexp. If present,
231 ;; the file is inserted in chunks of size BLOCKSIZE
232 ;; (default 8 kByte), until the first occurrence of
233 ;; LIMIT is found. The function returns nil if FILE
234 ;; doesn't exist.
235 (erase-buffer)
236 (cond ((file-exists-p file)
237 (cond (limit
238 (if (not blocksize) (setq blocksize 8192))
239 (let (found s)
240 (while (not found)
241 (setq s (buffer-size))
242 (goto-char (1+ s))
243 (setq found
244 (or (zerop (car (cdr
245 (insert-file-contents file nil s
246 (+ s blocksize)))))
247 (progn (beginning-of-line)
248 (re-search-forward limit nil t)))))))
249 (t (insert-file-contents file)))
250 (set-buffer-modified-p nil)
251 (auto-save-mode nil)
253 (t nil)))
255 (defun vc-parse-locks (file locks)
256 ;; Parse RCS or SCCS locks.
257 ;; The result is a list of the form ((VERSION USER) (VERSION USER) ...),
258 ;; which is returned and stored into the property `vc-master-locks'.
259 (if (not locks)
260 (vc-file-setprop file 'vc-master-locks 'none)
261 (let ((found t) (index 0) master-locks version user)
262 (cond ((eq (vc-backend file) 'SCCS)
263 (while (string-match "^\\([0-9.]+\\) [0-9.]+ \\([^ ]+\\) .*\n?"
264 locks index)
265 (setq version (substring locks
266 (match-beginning 1) (match-end 1)))
267 (setq user (substring locks
268 (match-beginning 2) (match-end 2)))
269 (setq master-locks (append master-locks
270 (list (cons version user))))
271 (setq index (match-end 0))))
272 ((eq (vc-backend file) 'RCS)
273 (while (string-match "[ \t\n]*\\([^:]+\\):\\([0-9.]+\\)"
274 locks index)
275 (setq version (substring locks
276 (match-beginning 2) (match-end 2)))
277 (setq user (substring locks
278 (match-beginning 1) (match-end 1)))
279 (setq master-locks (append master-locks
280 (list (cons version user))))
281 (setq index (match-end 0)))
282 (if (string-match ";[ \t\n]+strict;" locks index)
283 (vc-file-setprop file 'vc-checkout-model 'manual)
284 (vc-file-setprop file 'vc-checkout-model 'implicit))))
285 (vc-file-setprop file 'vc-master-locks (or master-locks 'none)))))
287 (defun vc-simple-command (okstatus command file &rest args)
288 ;; Simple version of vc-do-command, for use in vc-hooks only.
289 ;; Don't switch to the *vc-info* buffer before running the
290 ;; command, because that would change its default directory
291 (save-excursion (set-buffer (get-buffer-create "*vc-info*"))
292 (erase-buffer))
293 (let ((exec-path (append vc-path exec-path)) exec-status
294 ;; Add vc-path to PATH for the execution of this command.
295 (process-environment
296 (cons (concat "PATH=" (getenv "PATH")
297 path-separator
298 (mapconcat 'identity vc-path path-separator))
299 process-environment)))
300 (setq exec-status
301 (apply 'call-process command nil "*vc-info*" nil
302 (append args (list file))))
303 (cond ((> exec-status okstatus)
304 (switch-to-buffer (get-file-buffer file))
305 (shrink-window-if-larger-than-buffer
306 (display-buffer "*vc-info*"))
307 (error "Couldn't find version control information")))
308 exec-status))
310 (defun vc-parse-cvs-status (&optional full)
311 ;; Parse output of "cvs status" command in the current buffer and
312 ;; set file properties accordingly. Unless FULL is t, parse only
313 ;; essential information.
314 (let (file status)
315 (goto-char (point-min))
316 (if (re-search-forward "^File: " nil t)
317 (cond
318 ((looking-at "no file") nil)
319 ((re-search-forward "\\=\\([^ \t]+\\)" nil t)
320 (setq file (concat default-directory (match-string 1)))
321 (vc-file-setprop file 'vc-backend 'CVS)
322 (if (not (re-search-forward "\\=[ \t]+Status: \\(.*\\)" nil t))
323 (setq status "Unknown")
324 (setq status (match-string 1)))
325 (if (and full
326 (re-search-forward
327 "\\(RCS Version\\|RCS Revision\\|Repository revision\\):[\t ]+\\([0-9.]+\\)"
328 nil t))
329 (vc-file-setprop file 'vc-latest-version (match-string 2)))
330 (cond
331 ((string-match "Up-to-date" status)
332 (vc-file-setprop file 'vc-cvs-status 'up-to-date)
333 (vc-file-setprop file 'vc-checkout-time
334 (nth 5 (file-attributes file))))
335 ((vc-file-setprop file 'vc-cvs-status
336 (cond
337 ((string-match "Locally Modified" status) 'locally-modified)
338 ((string-match "Needs Merge" status) 'needs-merge)
339 ((string-match "Needs \\(Checkout\\|Patch\\)" status)
340 'needs-checkout)
341 ((string-match "Unresolved Conflict" status)
342 'unresolved-conflict)
343 ((string-match "File had conflicts on merge" status)
344 'unresolved-conflict)
345 ((string-match "Locally Added" status) 'locally-added)
346 ((string-match "New file!" status) 'locally-added)
347 (t 'unknown))))))))))
349 (defun vc-fetch-master-properties (file)
350 ;; Fetch those properties of FILE that are stored in the master file.
351 ;; For an RCS file, we don't get vc-latest-version vc-your-latest-version
352 ;; here because that is slow.
353 ;; That gets done if/when the functions vc-latest-version
354 ;; and vc-your-latest-version get called.
355 (save-excursion
356 (cond
357 ((eq (vc-backend file) 'SCCS)
358 (set-buffer (get-buffer-create "*vc-info*"))
359 (if (vc-insert-file (vc-lock-file file))
360 (vc-parse-locks file (buffer-string))
361 (vc-file-setprop file 'vc-master-locks 'none))
362 (vc-insert-file (vc-name file) "^\001e")
363 (vc-parse-buffer
364 (list '("^\001d D \\([^ ]+\\)" 1)
365 (list (concat "^\001d D \\([^ ]+\\) .* "
366 (regexp-quote (vc-user-login-name)) " ") 1))
367 file
368 '(vc-latest-version vc-your-latest-version)))
370 ((eq (vc-backend file) 'RCS)
371 (set-buffer (get-buffer-create "*vc-info*"))
372 (vc-insert-file (vc-name file) "^[0-9]")
373 (vc-parse-buffer
374 (list '("^head[ \t\n]+\\([^;]+\\);" 1)
375 '("^branch[ \t\n]+\\([^;]+\\);" 1)
376 '("^locks[ \t\n]*\\([^;]*;\\([ \t\n]*strict;\\)?\\)" 1))
377 file
378 '(vc-head-version
379 vc-default-branch
380 vc-master-locks))
381 ;; determine vc-master-workfile-version: it is either the head
382 ;; of the trunk, the head of the default branch, or the
383 ;; "default branch" itself, if that is a full revision number.
384 (let ((default-branch (vc-file-getprop file 'vc-default-branch)))
385 (cond
386 ;; no default branch
387 ((or (not default-branch) (string= "" default-branch))
388 (vc-file-setprop file 'vc-master-workfile-version
389 (vc-file-getprop file 'vc-head-version)))
390 ;; default branch is actually a revision
391 ((string-match "^[0-9]+\\.[0-9]+\\(\\.[0-9]+\\.[0-9]+\\)*$"
392 default-branch)
393 (vc-file-setprop file 'vc-master-workfile-version default-branch))
394 ;; else, search for the head of the default branch
395 (t (vc-insert-file (vc-name file) "^desc")
396 (vc-parse-buffer (list (list
397 (concat "^\\("
398 (regexp-quote default-branch)
399 "\\.[0-9]+\\)\ndate[ \t]+\\([0-9.]+\\);") 1 2))
400 file '(vc-master-workfile-version)))))
401 ;; translate the locks
402 (vc-parse-locks file (vc-file-getprop file 'vc-master-locks)))
404 ((eq (vc-backend file) 'CVS)
405 (save-excursion
406 ;; Call "cvs status" in the right directory, passing only the
407 ;; nondirectory part of the file name -- otherwise CVS might
408 ;; silently give a wrong result.
409 (let ((default-directory (file-name-directory file)))
410 (vc-simple-command 0 "cvs" (file-name-nondirectory file) "status"))
411 (set-buffer (get-buffer "*vc-info*"))
412 (vc-parse-cvs-status t))))
413 (if (get-buffer "*vc-info*")
414 (kill-buffer (get-buffer "*vc-info*")))))
416 ;;; Functions that determine property values, by examining the
417 ;;; working file, the master file, or log program output
419 (defun vc-consult-rcs-headers (file)
420 ;; Search for RCS headers in FILE, and set properties
421 ;; accordingly. This function can be disabled by setting
422 ;; vc-consult-headers to nil.
423 ;; Returns: nil if no headers were found
424 ;; (or if the feature is disabled,
425 ;; or if there is currently no buffer
426 ;; visiting FILE)
427 ;; 'rev if a workfile revision was found
428 ;; 'rev-and-lock if revision and lock info was found
429 (cond
430 ((or (not vc-consult-headers)
431 (not (get-file-buffer file))) nil)
432 ((let (status version locking-user)
433 (save-excursion
434 (set-buffer (get-file-buffer file))
435 (goto-char (point-min))
436 (cond
437 ;; search for $Id or $Header
438 ;; -------------------------
439 ;; The `\ 's below avoid an RCS 5.7 bug when checking in this file.
440 ((or (and (search-forward "$Id\ : " nil t)
441 (looking-at "[^ ]+ \\([0-9.]+\\) "))
442 (and (progn (goto-char (point-min))
443 (search-forward "$Header\ : " nil t))
444 (looking-at "[^ ]+ \\([0-9.]+\\) ")))
445 (goto-char (match-end 0))
446 ;; if found, store the revision number ...
447 (setq version (buffer-substring-no-properties (match-beginning 1)
448 (match-end 1)))
449 ;; ... and check for the locking state
450 (cond
451 ((looking-at
452 (concat "[0-9]+[/-][01][0-9][/-][0-3][0-9] " ; date
453 "[0-2][0-9]:[0-5][0-9]+:[0-6][0-9]+\\([+-][0-9:]+\\)? " ; time
454 "[^ ]+ [^ ]+ ")) ; author & state
455 (goto-char (match-end 0)) ; [0-6] in regexp handles leap seconds
456 (cond
457 ;; unlocked revision
458 ((looking-at "\\$")
459 (setq locking-user 'none)
460 (setq status 'rev-and-lock))
461 ;; revision is locked by some user
462 ((looking-at "\\([^ ]+\\) \\$")
463 (setq locking-user
464 (buffer-substring-no-properties (match-beginning 1)
465 (match-end 1)))
466 (setq status 'rev-and-lock))
467 ;; everything else: false
468 (nil)))
469 ;; unexpected information in
470 ;; keyword string --> quit
471 (nil)))
472 ;; search for $Revision
473 ;; --------------------
474 ((re-search-forward (concat "\\$"
475 "Revision: \\([0-9.]+\\) \\$")
476 nil t)
477 ;; if found, store the revision number ...
478 (setq version (buffer-substring-no-properties (match-beginning 1)
479 (match-end 1)))
480 ;; and see if there's any lock information
481 (goto-char (point-min))
482 (if (re-search-forward (concat "\\$" "Locker:") nil t)
483 (cond ((looking-at " \\([^ ]+\\) \\$")
484 (setq locking-user (buffer-substring-no-properties
485 (match-beginning 1)
486 (match-end 1)))
487 (setq status 'rev-and-lock))
488 ((looking-at " *\\$")
489 (setq locking-user 'none)
490 (setq status 'rev-and-lock))
492 (setq locking-user 'none)
493 (setq status 'rev-and-lock)))
494 (setq status 'rev)))
495 ;; else: nothing found
496 ;; -------------------
497 (t nil)))
498 (if status (vc-file-setprop file 'vc-workfile-version version))
499 (and (eq status 'rev-and-lock)
500 (eq (vc-backend file) 'RCS)
501 (vc-file-setprop file 'vc-locking-user locking-user)
502 ;; If the file has headers, we don't want to query the master file,
503 ;; because that would eliminate all the performance gain the headers
504 ;; brought us. We therefore use a heuristic for the checkout model
505 ;; now: If we trust the file permissions, and the file is not
506 ;; locked, then if the file is read-only the checkout model is
507 ;; `manual', otherwise `implicit'.
508 (not (vc-mistrust-permissions file))
509 (not (vc-locking-user file))
510 (if (string-match ".r-..-..-." (nth 8 (file-attributes file)))
511 (vc-file-setprop file 'vc-checkout-model 'manual)
512 (vc-file-setprop file 'vc-checkout-model 'implicit)))
513 status))))
515 ;;; Access functions to file properties
516 ;;; (Properties should be _set_ using vc-file-setprop, but
517 ;;; _retrieved_ only through these functions, which decide
518 ;;; if the property is already known or not. A property should
519 ;;; only be retrieved by vc-file-getprop if there is no
520 ;;; access function.)
522 ;;; properties indicating the backend
523 ;;; being used for FILE
525 (defun vc-backend-subdirectory-name (&optional file)
526 ;; Where the master and lock files for the current directory are kept
527 (symbol-name
529 (and file (vc-backend file))
530 vc-default-back-end
531 (setq vc-default-back-end (if (vc-find-binary "rcs") 'RCS 'SCCS)))))
533 (defun vc-name (file)
534 "Return the master name of a file, nil if it is not registered.
535 For CVS, the full name of CVS/Entries is returned."
536 (or (vc-file-getprop file 'vc-name)
537 ;; Use the caching mechanism of vc-backend, below.
538 (if (vc-backend file)
539 (vc-file-getprop file 'vc-name))))
541 (defun vc-backend (file)
542 "Return the version-control type of a file, nil if it is not registered."
543 ;; Note that internally, Emacs remembers unregistered
544 ;; files by setting the property to `none'.
545 (if file
546 (let ((property (vc-file-getprop file 'vc-backend))
547 (name-and-type))
548 (cond ((eq property 'none) nil)
549 (property)
550 (t (setq name-and-type (vc-registered file))
551 (if name-and-type
552 (progn
553 (vc-file-setprop file 'vc-name (car name-and-type))
554 (vc-file-setprop file 'vc-backend (cdr name-and-type)))
555 (vc-file-setprop file 'vc-backend 'none)
556 nil))))))
558 (defun vc-checkout-model (file)
559 ;; Return `manual' if the user has to type C-x C-q to check out FILE.
560 ;; Return `implicit' if the file can be modified without locking it first.
562 (vc-file-getprop file 'vc-checkout-model)
563 (cond
564 ((eq (vc-backend file) 'SCCS)
565 (vc-file-setprop file 'vc-checkout-model 'manual))
566 ((eq (vc-backend file) 'RCS)
567 (vc-consult-rcs-headers file)
568 (or (vc-file-getprop file 'vc-checkout-model)
569 (progn (vc-fetch-master-properties file)
570 (vc-file-getprop file 'vc-checkout-model))))
571 ((eq (vc-backend file) 'CVS)
572 (vc-file-setprop file 'vc-checkout-model
573 (cond
574 ((getenv "CVSREAD") 'manual)
575 ;; If the file is not writeable, this is probably because the
576 ;; file is being "watched" by other developers. Use "manual"
577 ;; checkout in this case. (If vc-mistrust-permissions was t,
578 ;; we actually shouldn't trust this, but there is no other way
579 ;; to learn this from CVS at the moment (version 1.9).)
580 ((string-match "r-..-..-." (nth 8 (file-attributes file)))
581 'manual)
582 (t 'implicit)))))))
584 ;;; properties indicating the locking state
586 (defun vc-cvs-status (file)
587 ;; Return the cvs status of FILE
588 ;; (Status field in output of "cvs status")
589 (cond ((vc-file-getprop file 'vc-cvs-status))
590 (t (vc-fetch-master-properties file)
591 (vc-file-getprop file 'vc-cvs-status))))
593 (defun vc-master-locks (file)
594 ;; Return the lock entries in the master of FILE.
595 ;; Return 'none if there are no such entries, and a list
596 ;; of the form ((VERSION USER) (VERSION USER) ...) otherwise.
597 (cond ((vc-file-getprop file 'vc-master-locks))
598 (t (vc-fetch-master-properties file)
599 (vc-file-getprop file 'vc-master-locks))))
601 (defun vc-master-locking-user (file)
602 ;; Return the master file's idea of who is locking
603 ;; the current workfile version of FILE.
604 ;; Return 'none if it is not locked.
605 (let ((master-locks (vc-master-locks file)) lock)
606 (if (eq master-locks 'none) 'none
607 ;; search for a lock on the current workfile version
608 (setq lock (assoc (vc-workfile-version file) master-locks))
609 (cond (lock (cdr lock))
610 ('none)))))
612 (defun vc-lock-from-permissions (file)
613 ;; If the permissions can be trusted for this file, determine the
614 ;; locking state from them. Returns (user-login-name), `none', or nil.
615 ;; This implementation assumes that any file which is under version
616 ;; control and has -rw-r--r-- is locked by its owner. This is true
617 ;; for both RCS and SCCS, which keep unlocked files at -r--r--r--.
618 ;; We have to be careful not to exclude files with execute bits on;
619 ;; scripts can be under version control too. Also, we must ignore the
620 ;; group-read and other-read bits, since paranoid users turn them off.
621 ;; This hack wins because calls to the somewhat expensive
622 ;; `vc-fetch-master-properties' function only have to be made if
623 ;; (a) the file is locked by someone other than the current user,
624 ;; or (b) some untoward manipulation behind vc's back has changed
625 ;; the owner or the `group' or `other' write bits.
626 (let ((attributes (file-attributes file)))
627 (if (not (vc-mistrust-permissions file))
628 (cond ((string-match ".r-..-..-." (nth 8 attributes))
629 (vc-file-setprop file 'vc-locking-user 'none))
630 ((and (= (nth 2 attributes) (user-uid))
631 (string-match ".rw..-..-." (nth 8 attributes)))
632 (vc-file-setprop file 'vc-locking-user (vc-user-login-name)))
633 (nil)))))
635 (defun vc-user-login-name (&optional uid)
636 ;; Return the name under which the user is logged in, as a string.
637 ;; (With optional argument UID, return the name of that user.)
638 ;; This function does the same as `user-login-name', but unlike
639 ;; that, it never returns nil. If a UID cannot be resolved, that
640 ;; UID is returned as a string.
641 (or (user-login-name uid)
642 (and uid (number-to-string uid))
643 (number-to-string (user-uid))))
645 (defun vc-file-owner (file)
646 ;; Return who owns FILE (user name, as a string).
647 (vc-user-login-name (nth 2 (file-attributes file))))
649 (defun vc-rcs-lock-from-diff (file)
650 ;; Diff the file against the master version. If differences are found,
651 ;; mark the file locked. This is only used for RCS with non-strict
652 ;; locking. (If "rcsdiff" doesn't understand --brief, we do a double-take
653 ;; and remember the fact for the future.)
654 (let* ((version (concat "-r" (vc-workfile-version file)))
655 (status (if (eq vc-rcsdiff-knows-brief 'no)
656 (vc-simple-command 1 "rcsdiff" file version)
657 (vc-simple-command 2 "rcsdiff" file "--brief" version))))
658 (if (eq status 2)
659 (if (not vc-rcsdiff-knows-brief)
660 (setq vc-rcsdiff-knows-brief 'no
661 status (vc-simple-command 1 "rcsdiff" file version))
662 (error "rcsdiff failed."))
663 (if (not vc-rcsdiff-knows-brief) (setq vc-rcsdiff-knows-brief 'yes)))
664 (if (zerop status)
665 (vc-file-setprop file 'vc-locking-user 'none)
666 (vc-file-setprop file 'vc-locking-user (vc-file-owner file)))))
668 (defun vc-locking-user (file)
669 ;; Return the name of the person currently holding a lock on FILE.
670 ;; Return nil if there is no such person.
671 ;; Under CVS, a file is considered locked if it has been modified since
672 ;; it was checked out.
673 ;; The property is cached. It is only looked up if it is currently nil.
674 ;; Note that, for a file that is not locked, the actual property value
675 ;; is `none', to distinguish it from an unknown locking state. That value
676 ;; is converted to nil by this function, and returned to the caller.
677 (let ((locking-user (vc-file-getprop file 'vc-locking-user)))
678 (if locking-user
679 ;; if we already know the property, return it
680 (if (eq locking-user 'none) nil locking-user)
682 ;; otherwise, infer the property...
683 (cond
684 ((eq (vc-backend file) 'CVS)
685 (or (and (eq (vc-checkout-model file) 'manual)
686 (vc-lock-from-permissions file))
687 (and (equal (vc-file-getprop file 'vc-checkout-time)
688 (nth 5 (file-attributes file)))
689 (vc-file-setprop file 'vc-locking-user 'none))
690 (vc-file-setprop file 'vc-locking-user (vc-file-owner file))))
692 ((eq (vc-backend file) 'RCS)
693 (let (p-lock)
695 ;; Check for RCS headers first
696 (or (eq (vc-consult-rcs-headers file) 'rev-and-lock)
698 ;; If there are no headers, try to learn it
699 ;; from the permissions.
700 (and (setq p-lock (vc-lock-from-permissions file))
701 (if (eq p-lock 'none)
703 ;; If the permissions say "not locked", we know
704 ;; that the checkout model must be `manual'.
705 (vc-file-setprop file 'vc-checkout-model 'manual)
707 ;; If the permissions say "locked", we can only trust
708 ;; this *if* the checkout model is `manual'.
709 (eq (vc-checkout-model file) 'manual)))
711 ;; Otherwise, use lock information from the master file.
712 (vc-file-setprop file 'vc-locking-user
713 (vc-master-locking-user file)))
715 ;; Finally, if the file is not explicitly locked
716 ;; it might still be locked implicitly.
717 (and (eq (vc-file-getprop file 'vc-locking-user) 'none)
718 (eq (vc-checkout-model file) 'implicit)
719 (vc-rcs-lock-from-diff file))))
721 ((eq (vc-backend file) 'SCCS)
722 (or (vc-lock-from-permissions file)
723 (vc-file-setprop file 'vc-locking-user
724 (vc-master-locking-user file)))))
726 ;; convert a possible 'none value
727 (setq locking-user (vc-file-getprop file 'vc-locking-user))
728 (if (eq locking-user 'none) nil locking-user))))
730 ;;; properties to store current and recent version numbers
732 (defun vc-latest-version (file)
733 ;; Return version level of the latest version of FILE
734 (cond ((vc-file-getprop file 'vc-latest-version))
735 (t (vc-fetch-properties file)
736 (vc-file-getprop file 'vc-latest-version))))
738 (defun vc-your-latest-version (file)
739 ;; Return version level of the latest version of FILE checked in by you
740 (cond ((vc-file-getprop file 'vc-your-latest-version))
741 (t (vc-fetch-properties file)
742 (vc-file-getprop file 'vc-your-latest-version))))
744 (defun vc-master-workfile-version (file)
745 ;; Return the master file's idea of what is the current workfile version.
746 ;; This property is defined for RCS only.
747 (cond ((vc-file-getprop file 'vc-master-workfile-version))
748 (t (vc-fetch-master-properties file)
749 (vc-file-getprop file 'vc-master-workfile-version))))
751 (defun vc-fetch-properties (file)
752 ;; Fetch vc-latest-version and vc-your-latest-version
753 ;; if that wasn't already done.
754 (cond
755 ((eq (vc-backend file) 'RCS)
756 (save-excursion
757 (set-buffer (get-buffer-create "*vc-info*"))
758 (vc-insert-file (vc-name file) "^desc")
759 (vc-parse-buffer
760 (list '("^\\([0-9]+\\.[0-9.]+\\)\ndate[ \t]+\\([0-9.]+\\);" 1 2)
761 (list (concat "^\\([0-9]+\\.[0-9.]+\\)\n"
762 "date[ \t]+\\([0-9.]+\\);[ \t]+"
763 "author[ \t]+"
764 (regexp-quote (vc-user-login-name)) ";") 1 2))
765 file
766 '(vc-latest-version vc-your-latest-version))
767 (if (get-buffer "*vc-info*")
768 (kill-buffer (get-buffer "*vc-info*")))))
769 (t (vc-fetch-master-properties file))
772 (defun vc-workfile-version (file)
773 ;; Return version level of the current workfile FILE
774 ;; This is attempted by first looking at the RCS keywords.
775 ;; If there are no keywords in the working file,
776 ;; vc-master-workfile-version is taken.
777 ;; Note that this property is cached, that is, it is only
778 ;; looked up if it is nil.
779 ;; For SCCS, this property is equivalent to vc-latest-version.
780 (cond ((vc-file-getprop file 'vc-workfile-version))
781 ((eq (vc-backend file) 'SCCS) (vc-latest-version file))
782 ((eq (vc-backend file) 'RCS)
783 (if (vc-consult-rcs-headers file)
784 (vc-file-getprop file 'vc-workfile-version)
785 (let ((rev (cond ((vc-master-workfile-version file))
786 ((vc-latest-version file)))))
787 (vc-file-setprop file 'vc-workfile-version rev)
788 rev)))
789 ((eq (vc-backend file) 'CVS)
790 (if (vc-consult-rcs-headers file) ;; CVS
791 (vc-file-getprop file 'vc-workfile-version)
792 (catch 'found
793 (vc-find-cvs-master (file-name-directory file)
794 (file-name-nondirectory file)))
795 (vc-file-getprop file 'vc-workfile-version)))))
797 ;;; actual version-control code starts here
799 (defun vc-registered (file)
800 (let (handler handlers)
801 (if (boundp 'file-name-handler-alist)
802 (setq handler (find-file-name-handler file 'vc-registered)))
803 (if handler
804 (funcall handler 'vc-registered file)
805 ;; Search for a master corresponding to the given file
806 (let ((dirname (or (file-name-directory file) ""))
807 (basename (file-name-nondirectory file)))
808 (catch 'found
809 (mapcar
810 (function (lambda (s)
811 (if (atom s)
812 (funcall s dirname basename)
813 (let ((trial (format (car s) dirname basename)))
814 (if (and (file-exists-p trial)
815 ;; Make sure the file we found with name
816 ;; TRIAL is not the source file itself.
817 ;; That can happen with RCS-style names
818 ;; if the file name is truncated
819 ;; (e.g. to 14 chars). See if either
820 ;; directory or attributes differ.
821 (or (not (string= dirname
822 (file-name-directory trial)))
823 (not (equal
824 (file-attributes file)
825 (file-attributes trial)))))
826 (throw 'found (cons trial (cdr s))))))))
827 vc-master-templates)
828 nil)))))
830 (defun vc-sccs-project-dir ()
831 ;; Return the full pathname of the SCCS PROJECTDIR, if it exists,
832 ;; otherwise nil. The PROJECTDIR is indicated by the environment
833 ;; variable of the same name. If its value starts with a slash,
834 ;; it must be an absolute path name that points to the
835 ;; directory where SCCS history files reside. If it does not
836 ;; begin with a slash, it is taken as the name of a user,
837 ;; and history files reside in an "src" or "source" subdirectory
838 ;; of that user's home directory.
839 (let ((project-dir (getenv "PROJECTDIR")))
840 (and project-dir
841 (if (eq (elt project-dir 0) ?/)
842 (if (file-exists-p (concat project-dir "/SCCS"))
843 (concat project-dir "/SCCS/")
844 (if (file-exists-p project-dir)
845 project-dir))
846 (setq project-dir (expand-file-name (concat "~" project-dir)))
847 (let (trial)
848 (setq trial (concat project-dir "/src/SCCS"))
849 (if (file-exists-p trial)
850 (concat trial "/")
851 (setq trial (concat project-dir "/src"))
852 (if (file-exists-p trial)
853 (concat trial "/")
854 (setq trial (concat project-dir "/source/SCCS"))
855 (if (file-exists-p trial)
856 (concat trial "/")
857 (setq trial (concat project-dir "/source/"))
858 (if (file-exists-p trial)
859 (concat trial "/"))))))))))
861 (defun vc-search-sccs-project-dir (dirname basename)
862 ;; Check if there is a master file for BASENAME in the
863 ;; SCCS project directory. If yes, throw `found' as
864 ;; expected by vc-registered. If not, return nil.
865 (let* ((project-dir (vc-sccs-project-dir))
866 (master-file (and project-dir (concat project-dir "s." basename))))
867 (and master-file
868 (file-exists-p master-file)
869 (throw 'found (cons master-file 'SCCS)))))
871 (defun vc-find-cvs-master (dirname basename)
872 ;; Check if DIRNAME/BASENAME is handled by CVS.
873 ;; If it is, do a (throw 'found (cons MASTER-FILE 'CVS)).
874 ;; Note: This function throws the name of CVS/Entries
875 ;; NOT that of the RCS master file (because we wouldn't be able
876 ;; to access it under remote CVS).
877 ;; The function returns nil if DIRNAME/BASENAME is not handled by CVS.
878 (if (and vc-handle-cvs
879 (file-directory-p (concat dirname "CVS/"))
880 (file-readable-p (concat dirname "CVS/Entries")))
881 (let ((file (concat dirname basename))
882 buffer)
883 (unwind-protect
884 (save-excursion
885 (setq buffer (set-buffer (get-buffer-create "*vc-info*")))
886 (vc-insert-file (concat dirname "CVS/Entries"))
887 (goto-char (point-min))
888 ;; make sure that the file name is searched
889 ;; case-sensitively - case-fold-search is a buffer-local
890 ;; variable, so setting it here won't affect any other buffers
891 (setq case-fold-search nil)
892 (cond
893 ;; entry for a "locally added" file (not yet committed)
894 ((re-search-forward
895 (concat "^/" (regexp-quote basename) "/0/") nil t)
896 (vc-file-setprop file 'vc-checkout-time 0)
897 (vc-file-setprop file 'vc-workfile-version "0")
898 (throw 'found (cons (concat dirname "CVS/Entries") 'CVS)))
899 ;; normal entry
900 ((re-search-forward
901 (concat "^/" (regexp-quote basename)
902 ;; revision
903 "/\\([^/]*\\)"
904 ;; timestamp
905 "/[A-Z][a-z][a-z]" ;; week day (irrelevant)
906 " \\([A-Z][a-z][a-z]\\)" ;; month name
907 " *\\([0-9]*\\)" ;; day of month
908 " \\([0-9]*\\):\\([0-9]*\\):\\([0-9]*\\)" ;; hms
909 " \\([0-9]*\\)" ;; year
910 ;; optional conflict field
911 "\\(+[^/]*\\)?/")
912 nil t)
913 ;; We found it. Store away version number now that we
914 ;; are anyhow so close to finding it.
915 (vc-file-setprop file
916 'vc-workfile-version
917 (match-string 1))
918 ;; If the file hasn't been modified since checkout,
919 ;; store the checkout-time.
920 (let ((mtime (nth 5 (file-attributes file)))
921 (second (string-to-number (match-string 6)))
922 (minute (string-to-number (match-string 5)))
923 (hour (string-to-number (match-string 4)))
924 (day (string-to-number (match-string 3)))
925 (year (string-to-number (match-string 7))))
926 (if (equal mtime
927 (encode-time
928 second minute hour day
929 (/ (string-match
930 (match-string 2)
931 "xxxJanFebMarAprMayJunJulAugSepOctNovDec")
933 year 0))
934 (vc-file-setprop file 'vc-checkout-time mtime)
935 (vc-file-setprop file 'vc-checkout-time 0)))
936 (throw 'found (cons (concat dirname "CVS/Entries") 'CVS)))
937 ;; entry with arbitrary text as timestamp
938 ;; (this means we should consider it modified)
939 ((re-search-forward
940 (concat "^/" (regexp-quote basename)
941 ;; revision
942 "/\\([^/]*\\)"
943 ;; timestamp (arbitrary text)
944 "/[^/]*"
945 ;; optional conflict field
946 "\\(+[^/]*\\)?/")
947 nil t)
948 ;; We found it. Store away version number now that we
949 ;; are anyhow so close to finding it.
950 (vc-file-setprop file 'vc-workfile-version (match-string 1))
951 (vc-file-setprop file 'vc-checkout-time 0)
952 (throw 'found (cons (concat dirname "CVS/Entries") 'CVS)))
953 (t nil)))
954 (kill-buffer buffer)))))
956 (defun vc-buffer-backend ()
957 "Return the version-control type of the visited file, or nil if none."
958 (if (eq vc-buffer-backend t)
959 (setq vc-buffer-backend (vc-backend (buffer-file-name)))
960 vc-buffer-backend))
962 (defun vc-toggle-read-only (&optional verbose)
963 "Change read-only status of current buffer, perhaps via version control.
964 If the buffer is visiting a file registered with version control,
965 then check the file in or out. Otherwise, just change the read-only flag
966 of the buffer.
967 With prefix argument, ask for version number to check in or check out.
968 Check-out of a specified version number does not lock the file;
969 to do that, use this command a second time with no argument."
970 (interactive "P")
971 (if (or (and (boundp 'vc-dired-mode) vc-dired-mode)
972 ;; use boundp because vc.el might not be loaded
973 (vc-backend (buffer-file-name)))
974 (vc-next-action verbose)
975 (toggle-read-only)))
976 (define-key global-map "\C-x\C-q" 'vc-toggle-read-only)
978 (defun vc-after-save ()
979 ;; Function to be called by basic-save-buffer (in files.el).
980 ;; If the file in the current buffer is under version control,
981 ;; not locked, and the checkout model for it is `implicit',
982 ;; mark it "locked" and redisplay the mode line.
983 (let ((file (buffer-file-name)))
984 (and (vc-backend file)
985 (or (and (equal (vc-file-getprop file 'vc-checkout-time)
986 (nth 5 (file-attributes file)))
987 ;; File has been saved in the same second in which
988 ;; it was checked out. Clear the checkout-time
989 ;; to avoid confusion.
990 (vc-file-setprop file 'vc-checkout-time nil))
992 (not (vc-locking-user file))
993 (eq (vc-checkout-model file) 'implicit)
994 (vc-file-setprop file 'vc-locking-user (vc-user-login-name))
995 (or (and (eq (vc-backend file) 'CVS)
996 (vc-file-setprop file 'vc-cvs-status nil))
998 (vc-mode-line file))))
1000 (defun vc-mode-line (file &optional label)
1001 "Set `vc-mode' to display type of version control for FILE.
1002 The value is set in the current buffer, which should be the buffer
1003 visiting FILE. Second optional arg LABEL is put in place of version
1004 control system name."
1005 (interactive (list buffer-file-name nil))
1006 (let ((vc-type (vc-backend file)))
1007 (setq vc-mode
1008 (and vc-type
1009 (concat " " (or label (symbol-name vc-type))
1010 (and vc-display-status (vc-status file)))))
1011 ;; If the file is locked by some other user, make
1012 ;; the buffer read-only. Like this, even root
1013 ;; cannot modify a file that someone else has locked.
1014 (and vc-type
1015 (equal file (buffer-file-name))
1016 (vc-locking-user file)
1017 (not (string= (vc-user-login-name) (vc-locking-user file)))
1018 (setq buffer-read-only t))
1019 ;; If the user is root, and the file is not owner-writable,
1020 ;; then pretend that we can't write it
1021 ;; even though we can (because root can write anything).
1022 ;; This way, even root cannot modify a file that isn't locked.
1023 (and vc-type
1024 (equal file (buffer-file-name))
1025 (not buffer-read-only)
1026 (zerop (user-real-uid))
1027 (zerop (logand (file-modes (buffer-file-name)) 128))
1028 (setq buffer-read-only t))
1029 (force-mode-line-update)
1030 ;;(set-buffer-modified-p (buffer-modified-p)) ;;use this if Emacs 18
1031 vc-type))
1033 (defun vc-status (file)
1034 ;; Return string for placement in modeline by `vc-mode-line'.
1035 ;; Format:
1037 ;; "-REV" if the revision is not locked
1038 ;; ":REV" if the revision is locked by the user
1039 ;; ":LOCKER:REV" if the revision is locked by somebody else
1040 ;; " @@" for a CVS file that is added, but not yet committed
1042 ;; In the CVS case, a "locked" working file is a
1043 ;; working file that is modified with respect to the master.
1044 ;; The file is "locked" from the moment when the user saves
1045 ;; the modified buffer.
1047 ;; This function assumes that the file is registered.
1049 (let ((locker (vc-locking-user file))
1050 (rev (vc-workfile-version file)))
1051 (cond ((string= "0" rev)
1052 " @@")
1053 ((not locker)
1054 (concat "-" rev))
1055 ((string= locker (vc-user-login-name))
1056 (concat ":" rev))
1058 (concat ":" locker ":" rev)))))
1060 (defun vc-follow-link ()
1061 ;; If the current buffer visits a symbolic link, this function makes it
1062 ;; visit the real file instead. If the real file is already visited in
1063 ;; another buffer, make that buffer current, and kill the buffer
1064 ;; that visits the link.
1065 (let* ((truename (abbreviate-file-name (file-chase-links buffer-file-name)))
1066 (true-buffer (find-buffer-visiting truename))
1067 (this-buffer (current-buffer)))
1068 (if (eq true-buffer this-buffer)
1069 (progn
1070 (kill-buffer this-buffer)
1071 ;; In principle, we could do something like set-visited-file-name.
1072 ;; However, it can't be exactly the same as set-visited-file-name.
1073 ;; I'm not going to work out the details right now. -- rms.
1074 (set-buffer (find-file-noselect truename)))
1075 (set-buffer true-buffer)
1076 (kill-buffer this-buffer))))
1078 ;;; install a call to the above as a find-file hook
1079 (defun vc-find-file-hook ()
1080 ;; Recompute whether file is version controlled,
1081 ;; if user has killed the buffer and revisited.
1082 (cond
1083 ((and (not vc-ignore-vc-files) buffer-file-name)
1084 (vc-file-clearprops buffer-file-name)
1085 (cond
1086 ((vc-backend buffer-file-name)
1087 (vc-mode-line buffer-file-name)
1088 (cond ((not vc-make-backup-files)
1089 ;; Use this variable, not make-backup-files,
1090 ;; because this is for things that depend on the file name.
1091 (make-local-variable 'backup-inhibited)
1092 (setq backup-inhibited t))))
1093 ((let* ((link (file-symlink-p buffer-file-name))
1094 (link-type (and link (vc-backend (file-chase-links link)))))
1095 (if link-type
1096 (cond ((eq vc-follow-symlinks nil)
1097 (message
1098 "Warning: symbolic link to %s-controlled source file" link-type))
1099 ((or (not (eq vc-follow-symlinks 'ask))
1100 ;; If we already visited this file by following
1101 ;; the link, don't ask again if we try to visit
1102 ;; it again. GUD does that, and repeated questions
1103 ;; are painful.
1104 (get-file-buffer
1105 (abbreviate-file-name (file-chase-links buffer-file-name))))
1107 (vc-follow-link)
1108 (message "Followed link to %s" buffer-file-name)
1109 (vc-find-file-hook))
1111 (if (yes-or-no-p (format
1112 "Symbolic link to %s-controlled source file; follow link? " link-type))
1113 (progn (vc-follow-link)
1114 (message "Followed link to %s" buffer-file-name)
1115 (vc-find-file-hook))
1116 (message
1117 "Warning: editing through the link bypasses version control")
1118 ))))))))))
1120 (add-hook 'find-file-hooks 'vc-find-file-hook)
1122 ;;; more hooks, this time for file-not-found
1123 (defun vc-file-not-found-hook ()
1124 "When file is not found, try to check it out from RCS or SCCS.
1125 Returns t if checkout was successful, nil otherwise."
1126 ;; When a file does not exist, ignore cached info about it
1127 ;; from a previous visit.
1128 (vc-file-clearprops buffer-file-name)
1129 (if (and (not vc-ignore-vc-files)
1130 (vc-backend buffer-file-name))
1131 (save-excursion
1132 (require 'vc)
1133 (setq default-directory (file-name-directory (buffer-file-name)))
1134 (not (vc-error-occurred (vc-checkout buffer-file-name))))))
1136 (add-hook 'find-file-not-found-hooks 'vc-file-not-found-hook)
1138 ;; Discard info about a file when we kill its buffer.
1139 (defun vc-kill-buffer-hook ()
1140 (if (stringp (buffer-file-name))
1141 (progn
1142 (vc-file-clearprops (buffer-file-name))
1143 (kill-local-variable 'vc-buffer-backend))))
1145 ;;;(add-hook 'kill-buffer-hook 'vc-kill-buffer-hook)
1147 ;;; Now arrange for bindings and autoloading of the main package.
1148 ;;; Bindings for this have to go in the global map, as we'll often
1149 ;;; want to call them from random buffers.
1151 (setq vc-prefix-map (lookup-key global-map "\C-xv"))
1152 (if (not (keymapp vc-prefix-map))
1153 (progn
1154 (setq vc-prefix-map (make-sparse-keymap))
1155 (define-key global-map "\C-xv" vc-prefix-map)
1156 (define-key vc-prefix-map "a" 'vc-update-change-log)
1157 (define-key vc-prefix-map "c" 'vc-cancel-version)
1158 (define-key vc-prefix-map "d" 'vc-directory)
1159 (define-key vc-prefix-map "g" 'vc-annotate)
1160 (define-key vc-prefix-map "h" 'vc-insert-headers)
1161 (define-key vc-prefix-map "i" 'vc-register)
1162 (define-key vc-prefix-map "l" 'vc-print-log)
1163 (define-key vc-prefix-map "m" 'vc-merge)
1164 (define-key vc-prefix-map "r" 'vc-retrieve-snapshot)
1165 (define-key vc-prefix-map "s" 'vc-create-snapshot)
1166 (define-key vc-prefix-map "u" 'vc-revert-buffer)
1167 (define-key vc-prefix-map "v" 'vc-next-action)
1168 (define-key vc-prefix-map "=" 'vc-diff)
1169 (define-key vc-prefix-map "~" 'vc-version-other-window)))
1171 (if (not (boundp 'vc-menu-map))
1172 ;; Don't do the menu bindings if menu-bar.el wasn't loaded to defvar
1173 ;; vc-menu-map.
1175 ;;(define-key vc-menu-map [show-files]
1176 ;; '("Show Files under VC" . (vc-directory t)))
1177 (define-key vc-menu-map [vc-retrieve-snapshot]
1178 '("Retrieve Snapshot" . vc-retrieve-snapshot))
1179 (define-key vc-menu-map [vc-create-snapshot]
1180 '("Create Snapshot" . vc-create-snapshot))
1181 (define-key vc-menu-map [vc-directory] '("VC Directory Listing" . vc-directory))
1182 (define-key vc-menu-map [separator1] '("----"))
1183 (define-key vc-menu-map [vc-annotate] '("Annotate" . vc-annotate))
1184 (define-key vc-menu-map [vc-rename-file] '("Rename File" . vc-rename-file))
1185 (define-key vc-menu-map [vc-version-other-window]
1186 '("Show Other Version" . vc-version-other-window))
1187 (define-key vc-menu-map [vc-diff] '("Compare with Last Version" . vc-diff))
1188 (define-key vc-menu-map [vc-update-change-log]
1189 '("Update ChangeLog" . vc-update-change-log))
1190 (define-key vc-menu-map [vc-print-log] '("Show History" . vc-print-log))
1191 (define-key vc-menu-map [separator2] '("----"))
1192 (define-key vc-menu-map [undo] '("Undo Last Check-In" . vc-cancel-version))
1193 (define-key vc-menu-map [vc-revert-buffer]
1194 '("Revert to Last Version" . vc-revert-buffer))
1195 (define-key vc-menu-map [vc-insert-header]
1196 '("Insert Header" . vc-insert-headers))
1197 (define-key vc-menu-map [vc-next-action] '("Check In/Out" . vc-next-action))
1198 (define-key vc-menu-map [vc-register] '("Register" . vc-register)))
1200 ;;; These are not correct and it's not currently clear how doing it
1201 ;;; better (with more complicated expressions) might slow things down
1202 ;;; on older systems.
1204 ;;;(put 'vc-rename-file 'menu-enable 'vc-mode)
1205 ;;;(put 'vc-annotate 'menu-enable '(eq (vc-buffer-backend) 'CVS))
1206 ;;;(put 'vc-version-other-window 'menu-enable 'vc-mode)
1207 ;;;(put 'vc-diff 'menu-enable 'vc-mode)
1208 ;;;(put 'vc-update-change-log 'menu-enable
1209 ;;; '(eq (vc-buffer-backend) 'RCS))
1210 ;;;(put 'vc-print-log 'menu-enable 'vc-mode)
1211 ;;;(put 'vc-cancel-version 'menu-enable 'vc-mode)
1212 ;;;(put 'vc-revert-buffer 'menu-enable 'vc-mode)
1213 ;;;(put 'vc-insert-headers 'menu-enable 'vc-mode)
1214 ;;;(put 'vc-next-action 'menu-enable 'vc-mode)
1215 ;;;(put 'vc-register 'menu-enable '(and buffer-file-name (not vc-mode)))
1217 (provide 'vc-hooks)
1219 ;;; vc-hooks.el ends here