annotate lisp/packages/vc-hooks.el @ 12:bcdc7deadc19 r19-15b7

Import from CVS: tag r19-15b7
author cvs
date Mon, 13 Aug 2007 08:48:16 +0200
parents 376386a54a3c
children 0293115a14e9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 ;;; vc-hooks.el --- resident support for version-control
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 ;; Copyright (C) 1992, 1993, 1994 Free Software Foundation, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4 ;; Copyright (C) 1995 Tinker Systems and INS Engineering Corp.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 ;; Author: Eric S. Raymond <esr@snark.thyrsus.com>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 ;; Maintainer: ttn@netcom.com
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 ;; Version: 5.3 + CVS hacks by ceder@lysator.liu.se made in Jan-Feb 1994.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 ;; XEmacs fixes, CVS fixes, and general improvements
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 ;; by Jonathan Stigelman <Stig@hackvan.com>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ;; This file is part of XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 ;; XEmacs is free software; you can redistribute it and/or modify it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 ;; under the terms of the GNU General Public License as published by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 ;; the Free Software Foundation; either version 2, or (at your option)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 ;; any later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 ;; XEmacs is distributed in the hope that it will be useful, but
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23 ;; General Public License for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 ;; You should have received a copy of the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 ;; along with XEmacs; see the file COPYING. If not, write to the Free
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 ;; Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 ;;; Synched up with: FSF 19.28.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 ;;; Commentary:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 ;; See the commentary of vc.el.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 ;;; Code:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 (defvar vc-master-templates
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 '(("%sRCS/%s,v" . RCS) ("%s%s,v" . RCS) ("%sRCS/%s" . RCS)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 ("%sSCCS/s.%s" . SCCS) ("%ss.%s". SCCS)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 ("%s%s@@" . CC)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 vc-find-cvs-master)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 "*Where to look for version-control master files.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 The first pair corresponding to a given back end is used as a template
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 when creating new masters.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 (defvar vc-make-backup-files nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 "*If non-nil, backups of registered files are made as with other files.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 If nil (the default), files covered by version control don't get backups.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 (defvar vc-display-status t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 "*If non-nil, display revision number and lock status in modeline.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 Otherwise, not displayed.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 ;; Tell Emacs about this new kind of minor mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 ;(if (not (assoc 'vc-mode minor-mode-alist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 ; (setq minor-mode-alist (cons '(vc-mode vc-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 ; minor-mode-alist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 ;; NO! Do it right.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 (add-minor-mode 'vc-mode 'vc-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 (defvar vc-mode nil) ; used for modeline flag
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 (make-variable-buffer-local 'vc-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 (put 'vc-mode 'permanent-local t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 ;; We need a notion of per-file properties because the version
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 ;; control state of a file is expensive to derive --- we don't
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 ;; want to recompute it even on every find.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 (defmacro vc-error-occurred (&rest body)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 (list 'condition-case nil (cons 'progn (append body '(nil))) '(error t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 (defvar vc-file-prop-obarray (make-vector 17 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 "Obarray for per-file properties.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 (defun vc-file-setprop (file property value)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 ;; set per-file property
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 (put (intern file vc-file-prop-obarray) property value))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 (defun vc-file-getprop (file property)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 ;; get per-file property
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 (get (intern file vc-file-prop-obarray) property))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 ;;; actual version-control code starts here
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 (defun vc-registered (file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 (let (handler)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 (if (boundp 'file-name-handler-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 (setq handler (find-file-name-handler file 'vc-registered)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 (if handler
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 (funcall handler 'vc-registered file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 ;; Search for a master corresponding to the given file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 (let ((dirname (or (file-name-directory file) ""))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 (basename (file-name-nondirectory file)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 (catch 'found
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 (mapcar
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 (function (lambda (s)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 (if (atom s)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 (funcall s dirname basename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 (let ((trial (format (car s) dirname basename)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 (if (and (file-exists-p trial)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 ;; Make sure the file we found with name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 ;; TRIAL is not the source file itself.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 ;; That can happen with RCS-style names
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 ;; if the file name is truncated
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 ;; (e.g. to 14 chars). See if either
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 ;; directory or attributes differ.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 (or (not (string= dirname
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 (file-name-directory trial)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 (not (equal
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 (file-attributes file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 (file-attributes trial)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 (throw 'found (cons trial (cdr s))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 vc-master-templates)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 nil)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 (defun vc-find-cvs-master (dirname basename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 ;; Check if DIRNAME/BASENAME is handled by CVS.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 ;; If it is, do a (throw 'found (cons MASTER 'CVS)).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 ;; Note: If the file is ``cvs add''ed but not yet ``cvs commit''ed
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 ;; the MASTER will not actually exist yet. The other parts of VC
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 ;; checks for this condition. This function returns something random if
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 ;; DIRNAME/BASENAME is not handled by CVS.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 (and (string= "" dirname) (setq dirname default-directory))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 (if (and (file-directory-p (concat dirname "CVS/"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 (file-readable-p (concat dirname "CVS/Entries")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 (let ((fname (concat dirname basename))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 sbuf rev)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 (unwind-protect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 (set-buffer (generate-new-buffer " vc-scratch"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 (setq sbuf (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 (insert-file-contents (concat dirname "CVS/Entries"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 ((re-search-forward
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 (concat "^/" (regexp-quote basename) "/\\([0-9.]*\\)/.*/\\(T\\([^/\n]+\\)\\)?$")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 ;; We found it. Store version number, and branch tag
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 (setq rev (buffer-substring (match-beginning 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 (match-end 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 (vc-file-setprop fname 'vc-your-latest-version rev)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 ;; XEmacs - we put something useful in the modeline
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 (vc-file-setprop fname 'sticky-tag
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 (cond ((string= "0" rev) "newfile")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 ((match-beginning 3)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 (buffer-substring (match-beginning 3)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 (match-end 3)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 (t "main")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 (erase-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 (insert-file-contents (concat dirname "CVS/Repository"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 (let ((master
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 (concat (file-name-as-directory
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 (buffer-substring (point-min)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 (1- (point-max))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 basename
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 ",v")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 (throw 'found (cons master 'CVS))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 (kill-buffer sbuf)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 (defun vc-name (file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 "Return the master name of a file, nil if it is not registered."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 (or (vc-file-getprop file 'vc-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 (let ((name-and-type (vc-registered file)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 (if name-and-type
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 (vc-file-setprop file 'vc-backend (cdr name-and-type))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 (vc-file-setprop file 'vc-name (car name-and-type)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 (defun vc-backend-deduce (file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 "Return the version-control type of a file, nil if it is not registered."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 (and file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 (or (vc-file-getprop file 'vc-backend)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 (let ((name-and-type (vc-registered file)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 (if name-and-type
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 (vc-file-setprop file 'vc-name (car name-and-type))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 (vc-file-setprop file 'vc-backend (cdr name-and-type))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 (defun vc-toggle-read-only (&optional verbose)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 "Change read-only status of current buffer, perhaps via version control.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 If the buffer is visiting a file registered with a form of version control
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 that locks files by making them read-only (i.e.: not CVS), then check the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 file in or out. Otherwise, just change the read-only flag of the buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 If you provide a prefix argument, we pass it on to `vc-next-action'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 (let ((vc-type (vc-backend-deduce (buffer-file-name))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 (cond ((and vc-type
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 buffer-read-only
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 (file-writable-p buffer-file-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 (/= 0 (user-uid)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 ;; XEmacs - The buffer isn't read-only because it's locked, so
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 ;; keep vc out of this...
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 (toggle-read-only))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 ((and vc-type (not (eq 'CVS vc-type)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 (vc-next-action verbose))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 (toggle-read-only)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 (define-key global-map "\C-x\C-q" 'vc-toggle-read-only)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 (defun vc-file-owner (file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 ;; XEmacs - vc-locking-user is just WAY too slow.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 (let* ((fa (file-attributes file)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 (cond ((eq ?w (aref (nth 8 fa) 2)) ; -rw-r--r--
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 ;; #### - if it's writable, we trust unix...dumb move?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 (user-login-name (nth 2 fa)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 ;; big slowness here...
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 (require 'vc)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 (vc-locking-user file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 ))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 (defun vc-mode-line (file &optional label)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 "Set `vc-mode' to display type of version control for FILE.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 The value is set in the current buffer, which should be the buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 visiting FILE. Second optional arg LABEL is put in place of version
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 control system name."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 (interactive (list buffer-file-name nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 (if file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 (let ((vc-type (vc-backend-deduce file)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 (setq vc-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 (if vc-type
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 (concat " " (or label (symbol-name vc-type))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 (if vc-display-status
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 (vc-status file vc-type)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 ;; Even root shouldn't modify a registered file without
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 ;; locking it first.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 (and vc-type
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 (not (string= (user-login-name) (vc-file-owner file)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 (setq buffer-read-only t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 (and (null vc-type)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 (file-symlink-p file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 (let ((link-type (vc-backend-deduce (file-symlink-p file))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 (if link-type
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 (message
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 "Warning: symbolic link to %s-controlled source file"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 link-type))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 (redraw-modeline)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 ;;(set-buffer-modified-p (buffer-modified-p)) ;;use this if Emacs 18
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 vc-type)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 (defun vc-status (file vc-type)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 ;; Return string for placement in modeline by `vc-mode-line'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 ;; If FILE is not registered, return nil.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 ;; If FILE is registered but not locked, return " REV" if there is a head
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 ;; revision and " @@" otherwise.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 ;; If FILE is locked then return all locks in a string of the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 ;; form " LOCKER1:REV1 LOCKER2:REV2 ...", where "LOCKERi:" is empty if you
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 ;; are the locker, and otherwise is the name of the locker followed by ":".
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 ;; Algorithm:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 ;; Check for master file corresponding to FILE being visited.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 ;; RCS: Insert the first few characters of the master file into a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 ;; work buffer. Search work buffer for "locks...;" phrase; if not
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 ;; found, then keep inserting more characters until the phrase is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 ;; found. Extract the locks, and remove control characters
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 ;; separating them, like newlines; the string " user1:revision1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 ;; user2:revision2 ..." is returned.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 ;; SCCS: Check if the p-file exists. If it does, read it and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 ;; extract the locks, giving them the right format. Else use prs to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 ;; find the revision number.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 ;; CVS: vc-find-cvs-master has already stored the current revision
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 ;; number and sticky-tag for the file. XEmacs displays the sticky-tag.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 ;; Limitations:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 ;; The output doesn't show which version you are actually looking at.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 ;; The modeline can get quite cluttered when there are multiple locks.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 ;; The head revision is probably not what you want if you've used `rcs -b'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 (let ((master (vc-name file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 found
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 status)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 ;; If master file exists, then parse its contents, otherwise we
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 ;; return the nil value of this if form.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 (if (and master vc-type)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 ;; Create work buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 (set-buffer (get-buffer-create " *vc-status*"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 (setq buffer-read-only nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 default-directory (file-name-directory master))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289 (erase-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 ;; Set the `status' var to the return value.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 ;; RCS code.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 ((eq vc-type 'RCS)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 ;; Check if we have enough of the header.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 ;; If not, then keep including more.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 (while
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 (not (or found
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300 (let ((s (buffer-size)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301 (goto-char (1+ s))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 (zerop (car (cdr (insert-file-contents
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 master nil s (+ s 8192))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 (setq found (re-search-forward "^locks\\([^;]*\\);" nil t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 (if found
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 ;; Clean control characters and self-locks from text.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 (let* ((lock-pattern
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310 (concat "[ \b\t\n\v\f\r]+\\("
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 (regexp-quote (user-login-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312 ":\\)?"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 (locks
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 (save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 (narrow-to-region (match-beginning 1) (match-end 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 (while (re-search-forward lock-pattern nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 (replace-match (if (eobp) "" ":") t t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 (buffer-string))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 (setq status
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 (if (not (string-equal locks ""))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 locks
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324 (if (looking-at "head[ \b\t\n\v\f\r]+\\([.0-9]+\\)")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325 (concat "-"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326 (buffer-substring (match-beginning 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327 (match-end 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328 " @@"))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330 ;; SCCS code.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331 ((eq vc-type 'SCCS)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332 ;; Build the name of the p-file and put it in the work buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333 (insert master)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334 (search-backward "/s.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335 (delete-char 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336 (insert "/p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337 (if (not (file-exists-p (buffer-string)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 ;; No lock.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339 (let ((exec-path (if (boundp 'vc-path) (append exec-path vc-path)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340 exec-path)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341 (erase-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342 (insert "-")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343 (if (zerop (call-process "prs" nil t nil "-d:I:" master))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344 (setq status (buffer-substring 1 (1- (point-max))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345 ;; Locks exist.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346 (insert-file-contents (buffer-string) nil nil nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347 (while (looking-at "[^ ]+ \\([^ ]+\\) \\([^ ]+\\).*\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348 (replace-match " \\2:\\1"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349 (setq status (buffer-string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
350 (aset status 0 ?:)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
351 ;; CVS code.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352 ((eq vc-type 'CVS)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353 ;; sticky-tag is initialized by vc-backend-deduce
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354 (setq status (concat ":" (vc-file-getprop file 'sticky-tag) "-"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355 (vc-file-getprop file 'vc-your-latest-version)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
356 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
358 ;; ClearCase code.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
359 ((eq vc-type 'CC)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
360 (require 'vc)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
361 (setq status (concat ":" (vc-latest-version file)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
362 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
363
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
364 ;; Clean work buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
365 (erase-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
366 (set-buffer-modified-p nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
367 status))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
368
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
369 ;;; install a call to the above as a find-file hook
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
370 (defun vc-find-file-hook ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
371 ;; Recompute whether file is version controlled,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
372 ;; if user has killed the buffer and revisited.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
373 (if buffer-file-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
374 (vc-file-setprop buffer-file-name 'vc-backend nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
375 (if (and (vc-mode-line buffer-file-name) (not vc-make-backup-files))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
376 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
377 ;; Use this variable, not make-backup-files,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
378 ;; because this is for things that depend on the file name.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
379 (set (make-local-variable 'backup-inhibited) t))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
380
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
381 (add-hook 'find-file-hooks 'vc-find-file-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
382
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
383 ;;; more hooks, this time for file-not-found
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
384 (defun vc-file-not-found-hook ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
385 "When file is not found, try to check it out from RCS or SCCS.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
386 Returns t if checkout was successful, nil otherwise."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
387 (if (vc-backend-deduce buffer-file-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
388 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
389 (require 'vc)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
390 (not (vc-error-occurred (vc-checkout buffer-file-name))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
391
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
392 (add-hook 'find-file-not-found-hooks 'vc-file-not-found-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
393
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
394 ;;; Now arrange for bindings and autoloading of the main package.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
395 ;;; Bindings for this have to go in the global map, as we'll often
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
396 ;;; want to call them from random buffers.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
397
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
398 ; XEmacs - this is preloaded. let's not be obtuse!
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
399 (defconst vc-prefix-map
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
400 (let ((map (make-sparse-keymap)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
401 (set-keymap-name map 'vc-prefix-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
402 (define-key map "a" 'vc-update-change-log)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
403 (define-key map "c" 'vc-cancel-version)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
404 (define-key map "d" 'vc-directory)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
405 (define-key map "h" 'vc-insert-headers)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
406 (define-key map "i" 'vc-register)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
407 (define-key map "l" 'vc-print-log)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
408 (define-key map "r" 'vc-retrieve-snapshot)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
409 (define-key map "s" 'vc-create-snapshot)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
410 (define-key map "u" 'vc-revert-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
411 (define-key map "v" 'vc-next-action)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
412 (define-key map "=" 'vc-diff)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
413 (define-key map "?" 'vc-file-status) ; XEmacs - this doesn't fit elsewhere
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
414 (define-key map "~" 'vc-version-other-window)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
415 (global-set-key "\C-xv" map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
416 map
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
417 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
418
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
419 ;; FSF menus...
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
420 ;; (if (not (boundp 'vc-menu-map))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
421 ;; ;; Don't do the menu bindings if menu-bar.el wasn't loaded to defvar
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
422 ;; ;; vc-menu-map.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
423 ;; ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
424 ;; ;;(define-key vc-menu-map [show-files]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
425 ;; ;; '("Show Files under VC" . (vc-directory t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
426 ;; (define-key vc-menu-map [vc-directory] '("Show Locked Files" . vc-directory))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
427 ;; (define-key vc-menu-map [separator1] '("----"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
428 ;; (define-key vc-menu-map [vc-rename-file] '("Rename File" . vc-rename-file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
429 ;; (define-key vc-menu-map [vc-version-other-window]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
430 ;; '("Show Other Version" . vc-version-other-window))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
431 ;; (define-key vc-menu-map [vc-diff] '("Compare with Last Version" . vc-diff))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
432 ;; (define-key vc-menu-map [vc-update-change-log]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
433 ;; '("Update ChangeLog" . vc-update-change-log))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
434 ;; (define-key vc-menu-map [vc-print-log] '("Show History" . vc-print-log))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
435 ;; (define-key vc-menu-map [separator2] '("----"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
436 ;; (define-key vc-menu-map [undo] '("Undo Last Check-In" . vc-cancel-version))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
437 ;; (define-key vc-menu-map [vc-revert-buffer]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
438 ;; '("Revert to Last Version" . vc-revert-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
439 ;; (define-key vc-menu-map [vc-insert-header]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
440 ;; '("Insert Header" . vc-insert-headers))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
441 ;; (define-key vc-menu-map [vc-menu-check-in] '("Check In" . vc-next-action))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
442 ;; (define-key vc-menu-map [vc-check-out] '("Check Out" . vc-toggle-read-only))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
443 ;; (define-key vc-menu-map [vc-register] '("Register" . vc-register))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
444 ;; (put 'vc-rename-file 'menu-enable 'vc-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
445 ;; (put 'vc-version-other-window 'menu-enable 'vc-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
446 ;; (put 'vc-diff 'menu-enable 'vc-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
447 ;; (put 'vc-update-change-log 'menu-enable
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
448 ;; '(eq (vc-backend-deduce (buffer-file-name)) 'RCS))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
449 ;; (put 'vc-print-log 'menu-enable 'vc-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
450 ;; (put 'vc-cancel-version 'menu-enable 'vc-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
451 ;; (put 'vc-revert-buffer 'menu-enable 'vc-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
452 ;; (put 'vc-insert-headers 'menu-enable 'vc-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
453 ;; (put 'vc-next-action 'menu-enable '(and vc-mode (not buffer-read-only)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
454 ;; (put 'vc-toggle-read-only 'menu-enable '(and vc-mode buffer-read-only))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
455 ;; (put 'vc-register 'menu-enable '(not vc-mode))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
456 ;; )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
457
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
458 ;; #### - sync with fsf menus
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
459 (defconst vc-menu
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
460 '("VC"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
461 :filter vc-menu-filter
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
462 ["" vc-next-action buffer-file-name nil]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
463 ;; ^^^ this gets changed to checkin, checkout, register, or steal
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
464 ["Show status of" vc-file-status nil nil]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
465 ;;["Show Locked Files" vc-directory t] ;; needs new dired
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
466 "----"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
467 ["Revert to Last Revision" vc-revert-buffer vc-mode nil]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
468 ["Cancel Last Checkin" vc-cancel-version vc-mode]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
469 ["Rename File" vc-rename-this-file vc-mode nil]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
470 "----"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
471 ["Diff Against Last Version" vc-diff vc-mode]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
472 ["Diff Between Revisions..." vc-version-diff vc-mode]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
473 ;;["Ediff Between Revisions..." ediff-revision vc-mode]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
474 ["Visit Other Version..." vc-version-other-window vc-mode]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
475 ["Show Edit History" vc-print-log vc-mode]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
476 "----"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
477 ;; The two commented out List functions simply don't work at the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
478 ;; moment.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
479 ;;["List Locked Files" (vc-directory '(16)) t]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
480 ["List Locked Files Any User" vc-directory t]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
481 ;;["List Registered Files" (vc-directory '(4)) t]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
482 "----"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
483 ["Create Snapshot" vc-create-snapshot t]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
484 ["Retrieve Snapshot" vc-retrieve-snapshot t]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
485 "----"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
486 ["CVS Update Directory" cvs-update t] ; pcl-cvs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
487 ;;["Show File Status" vc-cvs-file-status vc-mode]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
488 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
489 "Menubar entry for using the revision control system.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
490
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
491 (defun vc-menu-filter (menu-items)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
492 (let* ((result menu-items) ; modify in-place
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
493 (case-fold-search t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
494 (type (vc-backend-deduce buffer-file-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
495 (file (if buffer-file-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
496 (file-name-nondirectory buffer-file-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
497 (buffer-name)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
498 op owner item status)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
499 (setq op (cond ((null type)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
500 "Register File")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
501 ((eq type 'CVS)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
502 (setq status
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
503 (vc-file-getprop buffer-file-name 'cvs-status))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
504 (if status
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
505 (cdr (assoc status
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
506 '(("Locally Modified" . "Commit")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
507 ("Needs Merge" . "Merge with repository")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
508 ("Up-to-date" . "Do nothing to")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
509 ("Needs Checkout" . "Update"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
510 ;; #### - we're not gonna call cvs status just to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
511 ;; post a lousy menu...that's insane!
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
512 "Next action on"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
513 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
514 ;; these are all for RCS and SCCS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
515 ((not (setq owner (vc-file-owner file)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
516 ;; #### - ugh! this is broken.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
517 ;; vc-file-owner is not a suitable
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
518 ;; substitute for vc-locking-user.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
519 "Check out File")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
520 ((not (string-equal owner (user-login-name)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
521 "Steal File Lock")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
522 (t "Check in File")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
523 (while (setq item (pop menu-items))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
524 (and (vectorp item)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
525 (cond ((eq 'vc-next-action (aref item 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
526 (aset item 0 op)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
527 (aset item 3 file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
528 ((eq 'vc-file-status (aref item 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
529 (aset item 2 (eq 'CVS type))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
530 (aset item 3 file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
531 ((> (length item) 3)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
532 (aset item 3 file)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
533 result))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
534
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
535 (add-hook 'before-init-hook
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
536 #'(lambda () (and (featurep 'menubar)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
537 current-menubar
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
538 (car (find-menu-item current-menubar '("Tools")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
539 (add-submenu '("Tools") vc-menu "Compare")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
540 (add-menu-item '("Tools") "---" nil nil "Compare"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
541 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
542
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
543 ;; #### called by files.el. Define it like this until we're merged.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
544 (defun vc-after-save ())
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
545
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
546 (provide 'vc-hooks)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
547
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
548 ;;; vc-hooks.el ends here