Mercurial > emacs
annotate lisp/vc-hooks.el @ 6826:903d03ddf99c
(specbind): Use find_symbol_value.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Tue, 12 Apr 1994 06:26:29 +0000 |
parents | 3715d5bfad50 |
children | cdf928b318d7 |
rev | line source |
---|---|
2232
4f9d60f7de9d
Add standard library headers.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2227
diff
changeset
|
1 ;;; vc-hooks.el --- resident support for version-control |
904 | 2 |
4024
b9f3b023e5c9
(vc-rcs-status): Remove unused var `status'.
Paul Eggert <eggert@twinsun.com>
parents:
3989
diff
changeset
|
3 ;; Copyright (C) 1992, 1993 Free Software Foundation, Inc. |
904 | 4 |
5 ;; Author: Eric S. Raymond <esr@snark.thyrsus.com> | |
2491
5f3061858f47
vc-mode: name change.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2232
diff
changeset
|
6 ;; Version: 5.3 |
904 | 7 |
8 ;; This file is part of GNU Emacs. | |
9 | |
10 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
11 ;; it under the terms of the GNU General Public License as published by | |
12 ;; the Free Software Foundation; either version 2, or (at your option) | |
13 ;; any later version. | |
14 | |
15 ;; GNU Emacs is distributed in the hope that it will be useful, | |
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 ;; GNU General Public License for more details. | |
19 | |
20 ;; You should have received a copy of the GNU General Public License | |
21 ;; along with GNU Emacs; see the file COPYING. If not, write to | |
22 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | |
23 | |
24 ;;; Commentary: | |
25 | |
26 ;; See the commentary of vc.el. | |
27 | |
28 ;;; Code: | |
29 | |
30 (defvar vc-master-templates | |
31 '(("%sRCS/%s,v" . RCS) ("%s%s,v" . RCS) ("%sRCS/%s" . RCS) | |
32 ("%sSCCS/s.%s" . SCCS) ("%ss.%s". SCCS)) | |
33 "*Where to look for version-control master files. | |
34 The first pair corresponding to a given back end is used as a template | |
35 when creating new masters.") | |
36 | |
37 (defvar vc-make-backup-files nil | |
5164
04d6b9e7782a
(vc-make-backup-files): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
4726
diff
changeset
|
38 "*If non-nil, backups of registered files are made as with other files. |
5783
6a97e54241a3
(vc-make-backup-files): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
5743
diff
changeset
|
39 If nil (the default), files covered by version control don't get backups.") |
904 | 40 |
3900
c6f3d2af0df7
(vc-rcs-status): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
3459
diff
changeset
|
41 (defvar vc-rcs-status t |
c6f3d2af0df7
(vc-rcs-status): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
3459
diff
changeset
|
42 "*If non-nil, revision and locks on RCS working file displayed in modeline. |
c6f3d2af0df7
(vc-rcs-status): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
3459
diff
changeset
|
43 Otherwise, not displayed.") |
c6f3d2af0df7
(vc-rcs-status): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
3459
diff
changeset
|
44 |
904 | 45 ;; Tell Emacs about this new kind of minor mode |
2491
5f3061858f47
vc-mode: name change.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2232
diff
changeset
|
46 (if (not (assoc 'vc-mode minor-mode-alist)) |
5f3061858f47
vc-mode: name change.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2232
diff
changeset
|
47 (setq minor-mode-alist (cons '(vc-mode vc-mode) |
904 | 48 minor-mode-alist))) |
49 | |
2491
5f3061858f47
vc-mode: name change.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2232
diff
changeset
|
50 (make-variable-buffer-local 'vc-mode) |
2620
d26f75fd9f5e
(vc-mode-line): Don't alter key bindings.
Richard M. Stallman <rms@gnu.org>
parents:
2491
diff
changeset
|
51 (put 'vc-mode 'permanent-local t) |
904 | 52 |
53 ;; We need a notion of per-file properties because the version | |
54 ;; control state of a file is expensive to derive --- we don't | |
55 ;; want to recompute it even on every find. | |
56 | |
2213
9ff513b5d296
vc-error-occurred: moved to vc-hooks.el in order for ^X^F of a
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1951
diff
changeset
|
57 (defmacro vc-error-occurred (&rest body) |
9ff513b5d296
vc-error-occurred: moved to vc-hooks.el in order for ^X^F of a
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1951
diff
changeset
|
58 (list 'condition-case nil (cons 'progn (append body '(nil))) '(error t))) |
9ff513b5d296
vc-error-occurred: moved to vc-hooks.el in order for ^X^F of a
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1951
diff
changeset
|
59 |
904 | 60 (defvar vc-file-prop-obarray [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] |
61 "Obarray for per-file properties.") | |
62 | |
63 (defun vc-file-setprop (file property value) | |
64 ;; set per-file property | |
65 (put (intern file vc-file-prop-obarray) property value)) | |
66 | |
67 (defun vc-file-getprop (file property) | |
68 ;; get per-file property | |
69 (get (intern file vc-file-prop-obarray) property)) | |
70 | |
71 ;;; actual version-control code starts here | |
72 | |
73 (defun vc-registered (file) | |
2218
13be90dfef0c
Merge today's change by eric with everybody else's
Paul Eggert <eggert@twinsun.com>
parents:
2213
diff
changeset
|
74 (let (handler handlers) |
13be90dfef0c
Merge today's change by eric with everybody else's
Paul Eggert <eggert@twinsun.com>
parents:
2213
diff
changeset
|
75 (if (boundp 'file-name-handler-alist) |
13be90dfef0c
Merge today's change by eric with everybody else's
Paul Eggert <eggert@twinsun.com>
parents:
2213
diff
changeset
|
76 (save-match-data |
13be90dfef0c
Merge today's change by eric with everybody else's
Paul Eggert <eggert@twinsun.com>
parents:
2213
diff
changeset
|
77 (setq handlers file-name-handler-alist) |
13be90dfef0c
Merge today's change by eric with everybody else's
Paul Eggert <eggert@twinsun.com>
parents:
2213
diff
changeset
|
78 (while (and (consp handlers) (null handler)) |
13be90dfef0c
Merge today's change by eric with everybody else's
Paul Eggert <eggert@twinsun.com>
parents:
2213
diff
changeset
|
79 (if (and (consp (car handlers)) |
13be90dfef0c
Merge today's change by eric with everybody else's
Paul Eggert <eggert@twinsun.com>
parents:
2213
diff
changeset
|
80 (stringp (car (car handlers))) |
13be90dfef0c
Merge today's change by eric with everybody else's
Paul Eggert <eggert@twinsun.com>
parents:
2213
diff
changeset
|
81 (string-match (car (car handlers)) file)) |
13be90dfef0c
Merge today's change by eric with everybody else's
Paul Eggert <eggert@twinsun.com>
parents:
2213
diff
changeset
|
82 (setq handler (cdr (car handlers)))) |
13be90dfef0c
Merge today's change by eric with everybody else's
Paul Eggert <eggert@twinsun.com>
parents:
2213
diff
changeset
|
83 (setq handlers (cdr handlers))))) |
13be90dfef0c
Merge today's change by eric with everybody else's
Paul Eggert <eggert@twinsun.com>
parents:
2213
diff
changeset
|
84 (if handler |
13be90dfef0c
Merge today's change by eric with everybody else's
Paul Eggert <eggert@twinsun.com>
parents:
2213
diff
changeset
|
85 (funcall handler 'vc-registered file) |
13be90dfef0c
Merge today's change by eric with everybody else's
Paul Eggert <eggert@twinsun.com>
parents:
2213
diff
changeset
|
86 ;; Search for a master corresponding to the given file |
13be90dfef0c
Merge today's change by eric with everybody else's
Paul Eggert <eggert@twinsun.com>
parents:
2213
diff
changeset
|
87 (let ((dirname (or (file-name-directory file) "")) |
13be90dfef0c
Merge today's change by eric with everybody else's
Paul Eggert <eggert@twinsun.com>
parents:
2213
diff
changeset
|
88 (basename (file-name-nondirectory file))) |
13be90dfef0c
Merge today's change by eric with everybody else's
Paul Eggert <eggert@twinsun.com>
parents:
2213
diff
changeset
|
89 (catch 'found |
13be90dfef0c
Merge today's change by eric with everybody else's
Paul Eggert <eggert@twinsun.com>
parents:
2213
diff
changeset
|
90 (mapcar |
13be90dfef0c
Merge today's change by eric with everybody else's
Paul Eggert <eggert@twinsun.com>
parents:
2213
diff
changeset
|
91 (function (lambda (s) |
13be90dfef0c
Merge today's change by eric with everybody else's
Paul Eggert <eggert@twinsun.com>
parents:
2213
diff
changeset
|
92 (let ((trial (format (car s) dirname basename))) |
13be90dfef0c
Merge today's change by eric with everybody else's
Paul Eggert <eggert@twinsun.com>
parents:
2213
diff
changeset
|
93 (if (and (file-exists-p trial) |
13be90dfef0c
Merge today's change by eric with everybody else's
Paul Eggert <eggert@twinsun.com>
parents:
2213
diff
changeset
|
94 ;; Make sure the file we found with name |
13be90dfef0c
Merge today's change by eric with everybody else's
Paul Eggert <eggert@twinsun.com>
parents:
2213
diff
changeset
|
95 ;; TRIAL is not the source file itself. |
13be90dfef0c
Merge today's change by eric with everybody else's
Paul Eggert <eggert@twinsun.com>
parents:
2213
diff
changeset
|
96 ;; That can happen with RCS-style names |
13be90dfef0c
Merge today's change by eric with everybody else's
Paul Eggert <eggert@twinsun.com>
parents:
2213
diff
changeset
|
97 ;; if the file name is truncated |
13be90dfef0c
Merge today's change by eric with everybody else's
Paul Eggert <eggert@twinsun.com>
parents:
2213
diff
changeset
|
98 ;; (e.g. to 14 chars). See if either |
13be90dfef0c
Merge today's change by eric with everybody else's
Paul Eggert <eggert@twinsun.com>
parents:
2213
diff
changeset
|
99 ;; directory or attributes differ. |
13be90dfef0c
Merge today's change by eric with everybody else's
Paul Eggert <eggert@twinsun.com>
parents:
2213
diff
changeset
|
100 (or (not (string= dirname |
13be90dfef0c
Merge today's change by eric with everybody else's
Paul Eggert <eggert@twinsun.com>
parents:
2213
diff
changeset
|
101 (file-name-directory trial))) |
13be90dfef0c
Merge today's change by eric with everybody else's
Paul Eggert <eggert@twinsun.com>
parents:
2213
diff
changeset
|
102 (not (equal |
13be90dfef0c
Merge today's change by eric with everybody else's
Paul Eggert <eggert@twinsun.com>
parents:
2213
diff
changeset
|
103 (file-attributes file) |
13be90dfef0c
Merge today's change by eric with everybody else's
Paul Eggert <eggert@twinsun.com>
parents:
2213
diff
changeset
|
104 (file-attributes trial))))) |
13be90dfef0c
Merge today's change by eric with everybody else's
Paul Eggert <eggert@twinsun.com>
parents:
2213
diff
changeset
|
105 (throw 'found (cons trial (cdr s))))))) |
13be90dfef0c
Merge today's change by eric with everybody else's
Paul Eggert <eggert@twinsun.com>
parents:
2213
diff
changeset
|
106 vc-master-templates) |
13be90dfef0c
Merge today's change by eric with everybody else's
Paul Eggert <eggert@twinsun.com>
parents:
2213
diff
changeset
|
107 nil))))) |
904 | 108 |
3989
c24f84e2f019
(vc-name): Moved from vc.el; vc-rcs-status now uses it.
Paul Eggert <eggert@twinsun.com>
parents:
3974
diff
changeset
|
109 (defun vc-name (file) |
c24f84e2f019
(vc-name): Moved from vc.el; vc-rcs-status now uses it.
Paul Eggert <eggert@twinsun.com>
parents:
3974
diff
changeset
|
110 "Return the master name of a file, nil if it is not registered." |
c24f84e2f019
(vc-name): Moved from vc.el; vc-rcs-status now uses it.
Paul Eggert <eggert@twinsun.com>
parents:
3974
diff
changeset
|
111 (or (vc-file-getprop file 'vc-name) |
c24f84e2f019
(vc-name): Moved from vc.el; vc-rcs-status now uses it.
Paul Eggert <eggert@twinsun.com>
parents:
3974
diff
changeset
|
112 (let ((name-and-type (vc-registered file))) |
c24f84e2f019
(vc-name): Moved from vc.el; vc-rcs-status now uses it.
Paul Eggert <eggert@twinsun.com>
parents:
3974
diff
changeset
|
113 (if name-and-type |
c24f84e2f019
(vc-name): Moved from vc.el; vc-rcs-status now uses it.
Paul Eggert <eggert@twinsun.com>
parents:
3974
diff
changeset
|
114 (progn |
c24f84e2f019
(vc-name): Moved from vc.el; vc-rcs-status now uses it.
Paul Eggert <eggert@twinsun.com>
parents:
3974
diff
changeset
|
115 (vc-file-setprop file 'vc-backend (cdr name-and-type)) |
c24f84e2f019
(vc-name): Moved from vc.el; vc-rcs-status now uses it.
Paul Eggert <eggert@twinsun.com>
parents:
3974
diff
changeset
|
116 (vc-file-setprop file 'vc-name (car name-and-type))))))) |
c24f84e2f019
(vc-name): Moved from vc.el; vc-rcs-status now uses it.
Paul Eggert <eggert@twinsun.com>
parents:
3974
diff
changeset
|
117 |
904 | 118 (defun vc-backend-deduce (file) |
3989
c24f84e2f019
(vc-name): Moved from vc.el; vc-rcs-status now uses it.
Paul Eggert <eggert@twinsun.com>
parents:
3974
diff
changeset
|
119 "Return the version-control type of a file, nil if it is not registered." |
904 | 120 (and file |
121 (or (vc-file-getprop file 'vc-backend) | |
3989
c24f84e2f019
(vc-name): Moved from vc.el; vc-rcs-status now uses it.
Paul Eggert <eggert@twinsun.com>
parents:
3974
diff
changeset
|
122 (let ((name-and-type (vc-registered file))) |
c24f84e2f019
(vc-name): Moved from vc.el; vc-rcs-status now uses it.
Paul Eggert <eggert@twinsun.com>
parents:
3974
diff
changeset
|
123 (if name-and-type |
c24f84e2f019
(vc-name): Moved from vc.el; vc-rcs-status now uses it.
Paul Eggert <eggert@twinsun.com>
parents:
3974
diff
changeset
|
124 (progn |
c24f84e2f019
(vc-name): Moved from vc.el; vc-rcs-status now uses it.
Paul Eggert <eggert@twinsun.com>
parents:
3974
diff
changeset
|
125 (vc-file-setprop file 'vc-name (car name-and-type)) |
c24f84e2f019
(vc-name): Moved from vc.el; vc-rcs-status now uses it.
Paul Eggert <eggert@twinsun.com>
parents:
3974
diff
changeset
|
126 (vc-file-setprop file 'vc-backend (cdr name-and-type)))))))) |
904 | 127 |
128 (defun vc-toggle-read-only () | |
2620
d26f75fd9f5e
(vc-mode-line): Don't alter key bindings.
Richard M. Stallman <rms@gnu.org>
parents:
2491
diff
changeset
|
129 "Change read-only status of current buffer, perhaps via version control. |
d26f75fd9f5e
(vc-mode-line): Don't alter key bindings.
Richard M. Stallman <rms@gnu.org>
parents:
2491
diff
changeset
|
130 If the buffer is visiting a file registered with version control, |
d26f75fd9f5e
(vc-mode-line): Don't alter key bindings.
Richard M. Stallman <rms@gnu.org>
parents:
2491
diff
changeset
|
131 then check the file in or out. Otherwise, just change the read-only flag |
d26f75fd9f5e
(vc-mode-line): Don't alter key bindings.
Richard M. Stallman <rms@gnu.org>
parents:
2491
diff
changeset
|
132 of the buffer." |
904 | 133 (interactive) |
134 (if (vc-backend-deduce (buffer-file-name)) | |
135 (vc-next-action nil) | |
136 (toggle-read-only))) | |
2620
d26f75fd9f5e
(vc-mode-line): Don't alter key bindings.
Richard M. Stallman <rms@gnu.org>
parents:
2491
diff
changeset
|
137 (define-key global-map "\C-x\C-q" 'vc-toggle-read-only) |
904 | 138 |
139 (defun vc-mode-line (file &optional label) | |
2491
5f3061858f47
vc-mode: name change.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2232
diff
changeset
|
140 "Set `vc-mode' to display type of version control for FILE. |
904 | 141 The value is set in the current buffer, which should be the buffer |
142 visiting FILE." | |
2218
13be90dfef0c
Merge today's change by eric with everybody else's
Paul Eggert <eggert@twinsun.com>
parents:
2213
diff
changeset
|
143 (interactive (list buffer-file-name nil)) |
904 | 144 (let ((vc-type (vc-backend-deduce file))) |
4338
0e9960f5e99c
(vc-mode-line): Set vc-mode to nil if FILE no longer is version-controlled.
Paul Eggert <eggert@twinsun.com>
parents:
4310
diff
changeset
|
145 (setq vc-mode |
0e9960f5e99c
(vc-mode-line): Set vc-mode to nil if FILE no longer is version-controlled.
Paul Eggert <eggert@twinsun.com>
parents:
4310
diff
changeset
|
146 (and vc-type |
0e9960f5e99c
(vc-mode-line): Set vc-mode to nil if FILE no longer is version-controlled.
Paul Eggert <eggert@twinsun.com>
parents:
4310
diff
changeset
|
147 (concat " " (or label (symbol-name vc-type)) |
0e9960f5e99c
(vc-mode-line): Set vc-mode to nil if FILE no longer is version-controlled.
Paul Eggert <eggert@twinsun.com>
parents:
4310
diff
changeset
|
148 (if (and vc-rcs-status (eq vc-type 'RCS)) |
0e9960f5e99c
(vc-mode-line): Set vc-mode to nil if FILE no longer is version-controlled.
Paul Eggert <eggert@twinsun.com>
parents:
4310
diff
changeset
|
149 (vc-rcs-status file))))) |
5327
526f3bb9b653
(vc-mode-line): Make buffer read-only for root if file is locked.
Richard M. Stallman <rms@gnu.org>
parents:
5164
diff
changeset
|
150 ;; Even root shouldn't modify a registered file without locking it first. |
526f3bb9b653
(vc-mode-line): Make buffer read-only for root if file is locked.
Richard M. Stallman <rms@gnu.org>
parents:
5164
diff
changeset
|
151 (and vc-type |
526f3bb9b653
(vc-mode-line): Make buffer read-only for root if file is locked.
Richard M. Stallman <rms@gnu.org>
parents:
5164
diff
changeset
|
152 (not buffer-read-only) |
526f3bb9b653
(vc-mode-line): Make buffer read-only for root if file is locked.
Richard M. Stallman <rms@gnu.org>
parents:
5164
diff
changeset
|
153 (zerop (user-uid)) |
526f3bb9b653
(vc-mode-line): Make buffer read-only for root if file is locked.
Richard M. Stallman <rms@gnu.org>
parents:
5164
diff
changeset
|
154 (require 'vc) |
526f3bb9b653
(vc-mode-line): Make buffer read-only for root if file is locked.
Richard M. Stallman <rms@gnu.org>
parents:
5164
diff
changeset
|
155 (not (string-equal (user-login-name) (vc-locking-user file))) |
526f3bb9b653
(vc-mode-line): Make buffer read-only for root if file is locked.
Richard M. Stallman <rms@gnu.org>
parents:
5164
diff
changeset
|
156 (setq buffer-read-only t)) |
5743
9ad79a0fb0aa
(vc-mode-line): use force-mode-line-update instead of the Emacs 18
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
5327
diff
changeset
|
157 (force-mode-line-update) |
9ad79a0fb0aa
(vc-mode-line): use force-mode-line-update instead of the Emacs 18
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
5327
diff
changeset
|
158 ;;(set-buffer-modified-p (buffer-modified-p)) ;;use this if Emacs 18 |
904 | 159 vc-type)) |
160 | |
3900
c6f3d2af0df7
(vc-rcs-status): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
3459
diff
changeset
|
161 (defun vc-rcs-status (file) |
4063
cebb261b0f10
(vc-rcs-status): Include head version number in mode line if there
Paul Eggert <eggert@twinsun.com>
parents:
4024
diff
changeset
|
162 ;; Return string for placement in modeline by `vc-mode-line'. |
cebb261b0f10
(vc-rcs-status): Include head version number in mode line if there
Paul Eggert <eggert@twinsun.com>
parents:
4024
diff
changeset
|
163 ;; If FILE is not registered under RCS, return nil. |
cebb261b0f10
(vc-rcs-status): Include head version number in mode line if there
Paul Eggert <eggert@twinsun.com>
parents:
4024
diff
changeset
|
164 ;; If FILE is registered but not locked, return " REV" if there is a head |
cebb261b0f10
(vc-rcs-status): Include head version number in mode line if there
Paul Eggert <eggert@twinsun.com>
parents:
4024
diff
changeset
|
165 ;; revision and " @@" otherwise. |
cebb261b0f10
(vc-rcs-status): Include head version number in mode line if there
Paul Eggert <eggert@twinsun.com>
parents:
4024
diff
changeset
|
166 ;; If FILE is locked then return all locks in a string of the |
4159
e0bddf2ba112
(vc-rcs-status): Omit "LOCKER:" if you are the locker.
Paul Eggert <eggert@twinsun.com>
parents:
4104
diff
changeset
|
167 ;; form " LOCKER1:REV1 LOCKER2:REV2 ...", where "LOCKERi:" is empty if you |
e0bddf2ba112
(vc-rcs-status): Omit "LOCKER:" if you are the locker.
Paul Eggert <eggert@twinsun.com>
parents:
4104
diff
changeset
|
168 ;; are the locker, and otherwise is the name of the locker followed by ":". |
3900
c6f3d2af0df7
(vc-rcs-status): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
3459
diff
changeset
|
169 |
c6f3d2af0df7
(vc-rcs-status): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
3459
diff
changeset
|
170 ;; Algorithm: |
c6f3d2af0df7
(vc-rcs-status): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
3459
diff
changeset
|
171 |
3989
c24f84e2f019
(vc-name): Moved from vc.el; vc-rcs-status now uses it.
Paul Eggert <eggert@twinsun.com>
parents:
3974
diff
changeset
|
172 ;; 1. Check for master file corresponding to FILE being visited. |
3900
c6f3d2af0df7
(vc-rcs-status): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
3459
diff
changeset
|
173 ;; |
3989
c24f84e2f019
(vc-name): Moved from vc.el; vc-rcs-status now uses it.
Paul Eggert <eggert@twinsun.com>
parents:
3974
diff
changeset
|
174 ;; 2. Insert the first few characters of the master file into a work |
3900
c6f3d2af0df7
(vc-rcs-status): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
3459
diff
changeset
|
175 ;; buffer. |
c6f3d2af0df7
(vc-rcs-status): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
3459
diff
changeset
|
176 ;; |
4024
b9f3b023e5c9
(vc-rcs-status): Remove unused var `status'.
Paul Eggert <eggert@twinsun.com>
parents:
3989
diff
changeset
|
177 ;; 3. Search work buffer for "locks...;" phrase; if not found, then |
b9f3b023e5c9
(vc-rcs-status): Remove unused var `status'.
Paul Eggert <eggert@twinsun.com>
parents:
3989
diff
changeset
|
178 ;; keep inserting more characters until the phrase is found. |
3900
c6f3d2af0df7
(vc-rcs-status): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
3459
diff
changeset
|
179 ;; |
4024
b9f3b023e5c9
(vc-rcs-status): Remove unused var `status'.
Paul Eggert <eggert@twinsun.com>
parents:
3989
diff
changeset
|
180 ;; 4. Extract the locks, and remove control characters |
3900
c6f3d2af0df7
(vc-rcs-status): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
3459
diff
changeset
|
181 ;; separating them, like newlines; the string " user1:revision1 |
c6f3d2af0df7
(vc-rcs-status): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
3459
diff
changeset
|
182 ;; user2:revision2 ..." is returned. |
c6f3d2af0df7
(vc-rcs-status): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
3459
diff
changeset
|
183 |
c6f3d2af0df7
(vc-rcs-status): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
3459
diff
changeset
|
184 ;; Limitations: |
c6f3d2af0df7
(vc-rcs-status): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
3459
diff
changeset
|
185 |
c6f3d2af0df7
(vc-rcs-status): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
3459
diff
changeset
|
186 ;; The output doesn't show which version you are actually looking at. |
c6f3d2af0df7
(vc-rcs-status): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
3459
diff
changeset
|
187 ;; The modeline can get quite cluttered when there are multiple locks. |
4063
cebb261b0f10
(vc-rcs-status): Include head version number in mode line if there
Paul Eggert <eggert@twinsun.com>
parents:
4024
diff
changeset
|
188 ;; The head revision is probably not what you want if you've used `rcs -b'. |
3900
c6f3d2af0df7
(vc-rcs-status): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
3459
diff
changeset
|
189 |
3989
c24f84e2f019
(vc-name): Moved from vc.el; vc-rcs-status now uses it.
Paul Eggert <eggert@twinsun.com>
parents:
3974
diff
changeset
|
190 (let ((master (vc-name file)) |
4024
b9f3b023e5c9
(vc-rcs-status): Remove unused var `status'.
Paul Eggert <eggert@twinsun.com>
parents:
3989
diff
changeset
|
191 found) |
3900
c6f3d2af0df7
(vc-rcs-status): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
3459
diff
changeset
|
192 |
c6f3d2af0df7
(vc-rcs-status): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
3459
diff
changeset
|
193 ;; If master file exists, then parse its contents, otherwise we return the |
c6f3d2af0df7
(vc-rcs-status): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
3459
diff
changeset
|
194 ;; nil value of this if form. |
3989
c24f84e2f019
(vc-name): Moved from vc.el; vc-rcs-status now uses it.
Paul Eggert <eggert@twinsun.com>
parents:
3974
diff
changeset
|
195 (if master |
3900
c6f3d2af0df7
(vc-rcs-status): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
3459
diff
changeset
|
196 (save-excursion |
c6f3d2af0df7
(vc-rcs-status): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
3459
diff
changeset
|
197 |
c6f3d2af0df7
(vc-rcs-status): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
3459
diff
changeset
|
198 ;; Create work buffer. |
4104
d42fc10d9c96
(vc-rcs-status): Make work buffer's name start w/ space.
Richard M. Stallman <rms@gnu.org>
parents:
4063
diff
changeset
|
199 (set-buffer (get-buffer-create " *vc-rcs-status*")) |
3900
c6f3d2af0df7
(vc-rcs-status): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
3459
diff
changeset
|
200 (setq buffer-read-only nil |
c6f3d2af0df7
(vc-rcs-status): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
3459
diff
changeset
|
201 default-directory (file-name-directory master)) |
c6f3d2af0df7
(vc-rcs-status): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
3459
diff
changeset
|
202 (erase-buffer) |
c6f3d2af0df7
(vc-rcs-status): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
3459
diff
changeset
|
203 |
3989
c24f84e2f019
(vc-name): Moved from vc.el; vc-rcs-status now uses it.
Paul Eggert <eggert@twinsun.com>
parents:
3974
diff
changeset
|
204 ;; Check if we have enough of the header. |
c24f84e2f019
(vc-name): Moved from vc.el; vc-rcs-status now uses it.
Paul Eggert <eggert@twinsun.com>
parents:
3974
diff
changeset
|
205 ;; If not, then keep including more. |
c24f84e2f019
(vc-name): Moved from vc.el; vc-rcs-status now uses it.
Paul Eggert <eggert@twinsun.com>
parents:
3974
diff
changeset
|
206 (while |
c24f84e2f019
(vc-name): Moved from vc.el; vc-rcs-status now uses it.
Paul Eggert <eggert@twinsun.com>
parents:
3974
diff
changeset
|
207 (not (or found |
c24f84e2f019
(vc-name): Moved from vc.el; vc-rcs-status now uses it.
Paul Eggert <eggert@twinsun.com>
parents:
3974
diff
changeset
|
208 (let ((s (buffer-size))) |
c24f84e2f019
(vc-name): Moved from vc.el; vc-rcs-status now uses it.
Paul Eggert <eggert@twinsun.com>
parents:
3974
diff
changeset
|
209 (goto-char (1+ s)) |
c24f84e2f019
(vc-name): Moved from vc.el; vc-rcs-status now uses it.
Paul Eggert <eggert@twinsun.com>
parents:
3974
diff
changeset
|
210 (zerop (car (cdr (insert-file-contents |
c24f84e2f019
(vc-name): Moved from vc.el; vc-rcs-status now uses it.
Paul Eggert <eggert@twinsun.com>
parents:
3974
diff
changeset
|
211 master nil s (+ s 8192)))))))) |
c24f84e2f019
(vc-name): Moved from vc.el; vc-rcs-status now uses it.
Paul Eggert <eggert@twinsun.com>
parents:
3974
diff
changeset
|
212 (beginning-of-line) |
c24f84e2f019
(vc-name): Moved from vc.el; vc-rcs-status now uses it.
Paul Eggert <eggert@twinsun.com>
parents:
3974
diff
changeset
|
213 (setq found (re-search-forward "^locks\\([^;]*\\);" nil t))) |
3900
c6f3d2af0df7
(vc-rcs-status): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
3459
diff
changeset
|
214 |
3989
c24f84e2f019
(vc-name): Moved from vc.el; vc-rcs-status now uses it.
Paul Eggert <eggert@twinsun.com>
parents:
3974
diff
changeset
|
215 (if found |
4159
e0bddf2ba112
(vc-rcs-status): Omit "LOCKER:" if you are the locker.
Paul Eggert <eggert@twinsun.com>
parents:
4104
diff
changeset
|
216 ;; Clean control characters and self-locks from text. |
e0bddf2ba112
(vc-rcs-status): Omit "LOCKER:" if you are the locker.
Paul Eggert <eggert@twinsun.com>
parents:
4104
diff
changeset
|
217 (let* ((lock-pattern |
e0bddf2ba112
(vc-rcs-status): Omit "LOCKER:" if you are the locker.
Paul Eggert <eggert@twinsun.com>
parents:
4104
diff
changeset
|
218 (concat "[ \b\t\n\v\f\r]+\\(" |
e0bddf2ba112
(vc-rcs-status): Omit "LOCKER:" if you are the locker.
Paul Eggert <eggert@twinsun.com>
parents:
4104
diff
changeset
|
219 (regexp-quote (user-login-name)) |
4170
bc40c23884ec
(vc-rcs-status): Use "-", not " ", to separate locks, so that the RCS
Paul Eggert <eggert@twinsun.com>
parents:
4159
diff
changeset
|
220 ":\\)?")) |
4159
e0bddf2ba112
(vc-rcs-status): Omit "LOCKER:" if you are the locker.
Paul Eggert <eggert@twinsun.com>
parents:
4104
diff
changeset
|
221 (locks |
4063
cebb261b0f10
(vc-rcs-status): Include head version number in mode line if there
Paul Eggert <eggert@twinsun.com>
parents:
4024
diff
changeset
|
222 (save-restriction |
cebb261b0f10
(vc-rcs-status): Include head version number in mode line if there
Paul Eggert <eggert@twinsun.com>
parents:
4024
diff
changeset
|
223 (narrow-to-region (match-beginning 1) (match-end 1)) |
cebb261b0f10
(vc-rcs-status): Include head version number in mode line if there
Paul Eggert <eggert@twinsun.com>
parents:
4024
diff
changeset
|
224 (goto-char (point-min)) |
4159
e0bddf2ba112
(vc-rcs-status): Omit "LOCKER:" if you are the locker.
Paul Eggert <eggert@twinsun.com>
parents:
4104
diff
changeset
|
225 (while (re-search-forward lock-pattern nil t) |
5164
04d6b9e7782a
(vc-make-backup-files): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
4726
diff
changeset
|
226 (replace-match (if (eobp) "" ":") t t)) |
4063
cebb261b0f10
(vc-rcs-status): Include head version number in mode line if there
Paul Eggert <eggert@twinsun.com>
parents:
4024
diff
changeset
|
227 (buffer-string))) |
cebb261b0f10
(vc-rcs-status): Include head version number in mode line if there
Paul Eggert <eggert@twinsun.com>
parents:
4024
diff
changeset
|
228 (status |
cebb261b0f10
(vc-rcs-status): Include head version number in mode line if there
Paul Eggert <eggert@twinsun.com>
parents:
4024
diff
changeset
|
229 (if (not (string-equal locks "")) |
cebb261b0f10
(vc-rcs-status): Include head version number in mode line if there
Paul Eggert <eggert@twinsun.com>
parents:
4024
diff
changeset
|
230 locks |
cebb261b0f10
(vc-rcs-status): Include head version number in mode line if there
Paul Eggert <eggert@twinsun.com>
parents:
4024
diff
changeset
|
231 (goto-char (point-min)) |
cebb261b0f10
(vc-rcs-status): Include head version number in mode line if there
Paul Eggert <eggert@twinsun.com>
parents:
4024
diff
changeset
|
232 (if (looking-at "head[ \b\t\n\v\f\r]+\\([.0-9]+\\)") |
4170
bc40c23884ec
(vc-rcs-status): Use "-", not " ", to separate locks, so that the RCS
Paul Eggert <eggert@twinsun.com>
parents:
4159
diff
changeset
|
233 (concat "-" (buffer-substring (match-beginning 1) |
4063
cebb261b0f10
(vc-rcs-status): Include head version number in mode line if there
Paul Eggert <eggert@twinsun.com>
parents:
4024
diff
changeset
|
234 (match-end 1))) |
cebb261b0f10
(vc-rcs-status): Include head version number in mode line if there
Paul Eggert <eggert@twinsun.com>
parents:
4024
diff
changeset
|
235 " @@")))) |
3989
c24f84e2f019
(vc-name): Moved from vc.el; vc-rcs-status now uses it.
Paul Eggert <eggert@twinsun.com>
parents:
3974
diff
changeset
|
236 ;; Clean work buffer. |
c24f84e2f019
(vc-name): Moved from vc.el; vc-rcs-status now uses it.
Paul Eggert <eggert@twinsun.com>
parents:
3974
diff
changeset
|
237 (erase-buffer) |
c24f84e2f019
(vc-name): Moved from vc.el; vc-rcs-status now uses it.
Paul Eggert <eggert@twinsun.com>
parents:
3974
diff
changeset
|
238 (set-buffer-modified-p nil) |
c24f84e2f019
(vc-name): Moved from vc.el; vc-rcs-status now uses it.
Paul Eggert <eggert@twinsun.com>
parents:
3974
diff
changeset
|
239 status)))))) |
3900
c6f3d2af0df7
(vc-rcs-status): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
3459
diff
changeset
|
240 |
904 | 241 ;;; install a call to the above as a find-file hook |
242 (defun vc-find-file-hook () | |
2218
13be90dfef0c
Merge today's change by eric with everybody else's
Paul Eggert <eggert@twinsun.com>
parents:
2213
diff
changeset
|
243 ;; Recompute whether file is version controlled, |
13be90dfef0c
Merge today's change by eric with everybody else's
Paul Eggert <eggert@twinsun.com>
parents:
2213
diff
changeset
|
244 ;; if user has killed the buffer and revisited. |
3459
763bc1ba714e
(vc-find-file-hook): Check buffer-file-name is non-nil.
Richard M. Stallman <rms@gnu.org>
parents:
2620
diff
changeset
|
245 (if buffer-file-name |
763bc1ba714e
(vc-find-file-hook): Check buffer-file-name is non-nil.
Richard M. Stallman <rms@gnu.org>
parents:
2620
diff
changeset
|
246 (vc-file-setprop buffer-file-name 'vc-backend nil)) |
904 | 247 (if (and (vc-mode-line buffer-file-name) (not vc-make-backup-files)) |
248 (progn | |
6545
3715d5bfad50
(vc-find-file-hook): Set backup-inhibited.
Richard M. Stallman <rms@gnu.org>
parents:
5783
diff
changeset
|
249 ;; Use this variable, not make-backup-files, |
3715d5bfad50
(vc-find-file-hook): Set backup-inhibited.
Richard M. Stallman <rms@gnu.org>
parents:
5783
diff
changeset
|
250 ;; because this is for things that depend on the file name. |
3715d5bfad50
(vc-find-file-hook): Set backup-inhibited.
Richard M. Stallman <rms@gnu.org>
parents:
5783
diff
changeset
|
251 (make-local-variable 'backup-inhibited) |
3715d5bfad50
(vc-find-file-hook): Set backup-inhibited.
Richard M. Stallman <rms@gnu.org>
parents:
5783
diff
changeset
|
252 (setq backup-inhibited t)))) |
904 | 253 |
4655
604a401e05a4
(vc-find-file-hook, vc-file-not-found-hook): Use add-hook to install.
Paul Eggert <eggert@twinsun.com>
parents:
4338
diff
changeset
|
254 (add-hook 'find-file-hooks 'vc-find-file-hook) |
904 | 255 |
256 ;;; more hooks, this time for file-not-found | |
257 (defun vc-file-not-found-hook () | |
258 "When file is not found, try to check it out from RCS or SCCS. | |
259 Returns t if checkout was successful, nil otherwise." | |
260 (if (vc-backend-deduce buffer-file-name) | |
261 (progn | |
262 (require 'vc) | |
263 (not (vc-error-occurred (vc-checkout buffer-file-name)))))) | |
264 | |
4655
604a401e05a4
(vc-find-file-hook, vc-file-not-found-hook): Use add-hook to install.
Paul Eggert <eggert@twinsun.com>
parents:
4338
diff
changeset
|
265 (add-hook 'find-file-not-found-hooks 'vc-file-not-found-hook) |
904 | 266 |
267 ;;; Now arrange for bindings and autoloading of the main package. | |
2491
5f3061858f47
vc-mode: name change.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2232
diff
changeset
|
268 ;;; Bindings for this have to go in the global map, as we'll often |
5f3061858f47
vc-mode: name change.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2232
diff
changeset
|
269 ;;; want to call them from random buffers. |
904 | 270 |
271 (setq vc-prefix-map (lookup-key global-map "\C-xv")) | |
272 (if (not (keymapp vc-prefix-map)) | |
273 (progn | |
274 (setq vc-prefix-map (make-sparse-keymap)) | |
275 (define-key global-map "\C-xv" vc-prefix-map) | |
276 (define-key vc-prefix-map "a" 'vc-update-change-log) | |
277 (define-key vc-prefix-map "c" 'vc-cancel-version) | |
2218
13be90dfef0c
Merge today's change by eric with everybody else's
Paul Eggert <eggert@twinsun.com>
parents:
2213
diff
changeset
|
278 (define-key vc-prefix-map "d" 'vc-directory) |
904 | 279 (define-key vc-prefix-map "h" 'vc-insert-headers) |
280 (define-key vc-prefix-map "i" 'vc-register) | |
281 (define-key vc-prefix-map "l" 'vc-print-log) | |
282 (define-key vc-prefix-map "r" 'vc-retrieve-snapshot) | |
283 (define-key vc-prefix-map "s" 'vc-create-snapshot) | |
284 (define-key vc-prefix-map "u" 'vc-revert-buffer) | |
285 (define-key vc-prefix-map "v" 'vc-next-action) | |
2218
13be90dfef0c
Merge today's change by eric with everybody else's
Paul Eggert <eggert@twinsun.com>
parents:
2213
diff
changeset
|
286 (define-key vc-prefix-map "=" 'vc-diff) |
4726
f7a2f8a2f883
(vc-prefix-map): Bind C-x v ~ to vc-version-other-window.
Paul Eggert <eggert@twinsun.com>
parents:
4655
diff
changeset
|
287 (define-key vc-prefix-map "~" 'vc-version-other-window) |
904 | 288 )) |
289 | |
290 (provide 'vc-hooks) | |
291 | |
292 ;;; vc-hooks.el ends here |