Mercurial > emacs
annotate lisp/vc-hooks.el @ 2298:872a3a2c3fed
* frame.c (Fhandle_switch_frame): Renamed from Fselect_frame.
Doc changed in anticipation of new purpose.
(Fselect_frame): Just call Fhandle_switch_frame for now.
author | Jim Blandy <jimb@redhat.com> |
---|---|
date | Sun, 21 Mar 1993 06:53:04 +0000 |
parents | 4f9d60f7de9d |
children | 5f3061858f47 |
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 |
3 ;; Copyright (C) 1992 Free Software Foundation, Inc. | |
4 | |
5 ;; Author: Eric S. Raymond <esr@snark.thyrsus.com> | |
2227
d86258329922
Increment version number to match vc.el's.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2218
diff
changeset
|
6 ;; Version: 5.2 |
904 | 7 |
2232
4f9d60f7de9d
Add standard library headers.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2227
diff
changeset
|
8 ;; $Id: vc-hooks.el,v 1.10 1993/03/17 14:01:56 eric Exp eric $ |
904 | 9 |
10 ;; This file is part of GNU Emacs. | |
11 | |
12 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
13 ;; it under the terms of the GNU General Public License as published by | |
14 ;; the Free Software Foundation; either version 2, or (at your option) | |
15 ;; any later version. | |
16 | |
17 ;; GNU Emacs is distributed in the hope that it will be useful, | |
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
20 ;; GNU General Public License for more details. | |
21 | |
22 ;; You should have received a copy of the GNU General Public License | |
23 ;; along with GNU Emacs; see the file COPYING. If not, write to | |
24 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | |
25 | |
26 ;;; Commentary: | |
27 | |
28 ;; See the commentary of vc.el. | |
29 | |
30 ;;; Code: | |
31 | |
32 (defvar vc-master-templates | |
33 '(("%sRCS/%s,v" . RCS) ("%s%s,v" . RCS) ("%sRCS/%s" . RCS) | |
34 ("%sSCCS/s.%s" . SCCS) ("%ss.%s". SCCS)) | |
35 "*Where to look for version-control master files. | |
36 The first pair corresponding to a given back end is used as a template | |
37 when creating new masters.") | |
38 | |
39 (defvar vc-make-backup-files nil | |
40 "*If non-nil, backups of registered files are made according to | |
41 the make-backup-files variable. Otherwise, prevents backups being made.") | |
42 | |
43 ;; Tell Emacs about this new kind of minor mode | |
44 (if (not (assoc 'vc-mode-string minor-mode-alist)) | |
45 (setq minor-mode-alist (cons '(vc-mode-string vc-mode-string) | |
46 minor-mode-alist))) | |
47 | |
48 (make-variable-buffer-local 'vc-mode-string) | |
49 | |
50 ;; We need a notion of per-file properties because the version | |
51 ;; control state of a file is expensive to derive --- we don't | |
52 ;; want to recompute it even on every find. | |
53 | |
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
|
54 (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
|
55 (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
|
56 |
904 | 57 (defvar vc-file-prop-obarray [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] |
58 "Obarray for per-file properties.") | |
59 | |
60 (defun vc-file-setprop (file property value) | |
61 ;; set per-file property | |
62 (put (intern file vc-file-prop-obarray) property value)) | |
63 | |
64 (defun vc-file-getprop (file property) | |
65 ;; get per-file property | |
66 (get (intern file vc-file-prop-obarray) property)) | |
67 | |
68 ;;; actual version-control code starts here | |
69 | |
70 (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
|
71 (let (handler handlers) |
13be90dfef0c
Merge today's change by eric with everybody else's
Paul Eggert <eggert@twinsun.com>
parents:
2213
diff
changeset
|
72 (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
|
73 (save-match-data |
13be90dfef0c
Merge today's change by eric with everybody else's
Paul Eggert <eggert@twinsun.com>
parents:
2213
diff
changeset
|
74 (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
|
75 (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
|
76 (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
|
77 (stringp (car (car handlers))) |
13be90dfef0c
Merge today's change by eric with everybody else's
Paul Eggert <eggert@twinsun.com>
parents:
2213
diff
changeset
|
78 (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
|
79 (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
|
80 (setq handlers (cdr handlers))))) |
13be90dfef0c
Merge today's change by eric with everybody else's
Paul Eggert <eggert@twinsun.com>
parents:
2213
diff
changeset
|
81 (if handler |
13be90dfef0c
Merge today's change by eric with everybody else's
Paul Eggert <eggert@twinsun.com>
parents:
2213
diff
changeset
|
82 (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
|
83 ;; 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
|
84 (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
|
85 (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
|
86 (catch 'found |
13be90dfef0c
Merge today's change by eric with everybody else's
Paul Eggert <eggert@twinsun.com>
parents:
2213
diff
changeset
|
87 (mapcar |
13be90dfef0c
Merge today's change by eric with everybody else's
Paul Eggert <eggert@twinsun.com>
parents:
2213
diff
changeset
|
88 (function (lambda (s) |
13be90dfef0c
Merge today's change by eric with everybody else's
Paul Eggert <eggert@twinsun.com>
parents:
2213
diff
changeset
|
89 (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
|
90 (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
|
91 ;; 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
|
92 ;; 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
|
93 ;; 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
|
94 ;; 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
|
95 ;; (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
|
96 ;; directory or attributes differ. |
13be90dfef0c
Merge today's change by eric with everybody else's
Paul Eggert <eggert@twinsun.com>
parents:
2213
diff
changeset
|
97 (or (not (string= dirname |
13be90dfef0c
Merge today's change by eric with everybody else's
Paul Eggert <eggert@twinsun.com>
parents:
2213
diff
changeset
|
98 (file-name-directory trial))) |
13be90dfef0c
Merge today's change by eric with everybody else's
Paul Eggert <eggert@twinsun.com>
parents:
2213
diff
changeset
|
99 (not (equal |
13be90dfef0c
Merge today's change by eric with everybody else's
Paul Eggert <eggert@twinsun.com>
parents:
2213
diff
changeset
|
100 (file-attributes file) |
13be90dfef0c
Merge today's change by eric with everybody else's
Paul Eggert <eggert@twinsun.com>
parents:
2213
diff
changeset
|
101 (file-attributes trial))))) |
13be90dfef0c
Merge today's change by eric with everybody else's
Paul Eggert <eggert@twinsun.com>
parents:
2213
diff
changeset
|
102 (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
|
103 vc-master-templates) |
13be90dfef0c
Merge today's change by eric with everybody else's
Paul Eggert <eggert@twinsun.com>
parents:
2213
diff
changeset
|
104 nil))))) |
904 | 105 |
106 (defun vc-backend-deduce (file) | |
107 "Return the version-control type of a file, nil if it is not registered" | |
108 (and file | |
109 (or (vc-file-getprop file 'vc-backend) | |
110 (vc-file-setprop file 'vc-backend (cdr (vc-registered file)))))) | |
111 | |
112 (defun vc-toggle-read-only () | |
2218
13be90dfef0c
Merge today's change by eric with everybody else's
Paul Eggert <eggert@twinsun.com>
parents:
2213
diff
changeset
|
113 "If the file in the current buffer is under version control, perform the |
904 | 114 logical next version-control action; otherwise, just toggle the buffer's |
115 read-only flag." | |
116 (interactive) | |
117 (if (vc-backend-deduce (buffer-file-name)) | |
118 (vc-next-action nil) | |
119 (toggle-read-only))) | |
120 | |
121 (defun vc-mode-line (file &optional label) | |
122 "Set `vc-mode-string' to display type of version control for FILE. | |
123 The value is set in the current buffer, which should be the buffer | |
124 visiting FILE." | |
2218
13be90dfef0c
Merge today's change by eric with everybody else's
Paul Eggert <eggert@twinsun.com>
parents:
2213
diff
changeset
|
125 (interactive (list buffer-file-name nil)) |
904 | 126 (let ((vc-type (vc-backend-deduce file))) |
127 (if vc-type | |
128 (progn | |
129 (if (null (current-local-map)) | |
130 (use-local-map (make-sparse-keymap))) | |
131 (define-key (current-local-map) "\C-x\C-q" 'vc-toggle-read-only) | |
132 (setq vc-mode-string | |
133 (concat " " (or label (symbol-name vc-type)))))) | |
134 ;; force update of mode line | |
135 (set-buffer-modified-p (buffer-modified-p)) | |
136 vc-type)) | |
137 | |
138 ;;; install a call to the above as a find-file hook | |
139 (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
|
140 ;; 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
|
141 ;; if user has killed the buffer and revisited. |
13be90dfef0c
Merge today's change by eric with everybody else's
Paul Eggert <eggert@twinsun.com>
parents:
2213
diff
changeset
|
142 (vc-file-setprop buffer-file-name 'vc-backend nil) |
904 | 143 (if (and (vc-mode-line buffer-file-name) (not vc-make-backup-files)) |
144 (progn | |
145 (make-local-variable 'make-backup-files) | |
146 (setq make-backup-files nil)))) | |
147 | |
148 (or (memq 'vc-find-file-hook find-file-hooks) | |
149 (setq find-file-hooks | |
150 (cons 'vc-find-file-hook find-file-hooks))) | |
151 | |
152 ;;; more hooks, this time for file-not-found | |
153 (defun vc-file-not-found-hook () | |
154 "When file is not found, try to check it out from RCS or SCCS. | |
155 Returns t if checkout was successful, nil otherwise." | |
156 (if (vc-backend-deduce buffer-file-name) | |
157 (progn | |
158 (require 'vc) | |
159 (not (vc-error-occurred (vc-checkout buffer-file-name)))))) | |
160 | |
161 (or (memq 'vc-file-not-found-hook find-file-not-found-hooks) | |
162 (setq find-file-not-found-hooks | |
163 (cons 'vc-file-not-found-hook find-file-not-found-hooks))) | |
164 | |
165 ;;; Now arrange for bindings and autoloading of the main package. | |
166 ;;; Bindings for this have to go in the global map, as it may have | |
167 ;;; to coexist with a lot of different major modes. | |
168 | |
169 (setq vc-prefix-map (lookup-key global-map "\C-xv")) | |
170 (if (not (keymapp vc-prefix-map)) | |
171 (progn | |
172 (setq vc-prefix-map (make-sparse-keymap)) | |
173 (define-key global-map "\C-xv" vc-prefix-map) | |
174 (define-key vc-prefix-map "a" 'vc-update-change-log) | |
175 (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
|
176 (define-key vc-prefix-map "d" 'vc-directory) |
904 | 177 (define-key vc-prefix-map "h" 'vc-insert-headers) |
178 (define-key vc-prefix-map "i" 'vc-register) | |
179 (define-key vc-prefix-map "l" 'vc-print-log) | |
180 (define-key vc-prefix-map "r" 'vc-retrieve-snapshot) | |
181 (define-key vc-prefix-map "s" 'vc-create-snapshot) | |
182 (define-key vc-prefix-map "u" 'vc-revert-buffer) | |
183 (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
|
184 (define-key vc-prefix-map "=" 'vc-diff) |
904 | 185 )) |
186 | |
187 (provide 'vc-hooks) | |
188 | |
189 ;;; vc-hooks.el ends here |