annotate lisp/packages/vc-hooks.el @ 16:0293115a14e9 r19-15b91

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