Mercurial > emacs
annotate lisp/vc-hooks.el @ 2545:d666732c5f41
(readevalloop): New argument is the source file name (or nil if none).
All calls changed. Do the two-step
necessary to call build_load_history with the correct current-globals
list for the current recursion.
(build_load_history): New function.
(eval_region, eval_buffer): Call readevalloop with new arg.
(load_history): New variable.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Sat, 17 Apr 1993 01:27:37 +0000 |
parents | 5f3061858f47 |
children | d26f75fd9f5e |
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> | |
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 | |
38 "*If non-nil, backups of registered files are made according to | |
39 the make-backup-files variable. Otherwise, prevents backups being made.") | |
40 | |
41 ;; 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
|
42 (if (not (assoc 'vc-mode minor-mode-alist)) |
5f3061858f47
vc-mode: name change.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2232
diff
changeset
|
43 (setq minor-mode-alist (cons '(vc-mode vc-mode) |
904 | 44 minor-mode-alist))) |
45 | |
2491
5f3061858f47
vc-mode: name change.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2232
diff
changeset
|
46 (make-variable-buffer-local 'vc-mode) |
904 | 47 |
48 ;; We need a notion of per-file properties because the version | |
49 ;; control state of a file is expensive to derive --- we don't | |
50 ;; want to recompute it even on every find. | |
51 | |
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
|
52 (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
|
53 (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
|
54 |
904 | 55 (defvar vc-file-prop-obarray [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] |
56 "Obarray for per-file properties.") | |
57 | |
58 (defun vc-file-setprop (file property value) | |
59 ;; set per-file property | |
60 (put (intern file vc-file-prop-obarray) property value)) | |
61 | |
62 (defun vc-file-getprop (file property) | |
63 ;; get per-file property | |
64 (get (intern file vc-file-prop-obarray) property)) | |
65 | |
66 ;;; actual version-control code starts here | |
67 | |
68 (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
|
69 (let (handler handlers) |
13be90dfef0c
Merge today's change by eric with everybody else's
Paul Eggert <eggert@twinsun.com>
parents:
2213
diff
changeset
|
70 (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
|
71 (save-match-data |
13be90dfef0c
Merge today's change by eric with everybody else's
Paul Eggert <eggert@twinsun.com>
parents:
2213
diff
changeset
|
72 (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
|
73 (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
|
74 (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
|
75 (stringp (car (car handlers))) |
13be90dfef0c
Merge today's change by eric with everybody else's
Paul Eggert <eggert@twinsun.com>
parents:
2213
diff
changeset
|
76 (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
|
77 (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
|
78 (setq handlers (cdr handlers))))) |
13be90dfef0c
Merge today's change by eric with everybody else's
Paul Eggert <eggert@twinsun.com>
parents:
2213
diff
changeset
|
79 (if handler |
13be90dfef0c
Merge today's change by eric with everybody else's
Paul Eggert <eggert@twinsun.com>
parents:
2213
diff
changeset
|
80 (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
|
81 ;; 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
|
82 (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
|
83 (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
|
84 (catch 'found |
13be90dfef0c
Merge today's change by eric with everybody else's
Paul Eggert <eggert@twinsun.com>
parents:
2213
diff
changeset
|
85 (mapcar |
13be90dfef0c
Merge today's change by eric with everybody else's
Paul Eggert <eggert@twinsun.com>
parents:
2213
diff
changeset
|
86 (function (lambda (s) |
13be90dfef0c
Merge today's change by eric with everybody else's
Paul Eggert <eggert@twinsun.com>
parents:
2213
diff
changeset
|
87 (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
|
88 (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
|
89 ;; 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
|
90 ;; 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
|
91 ;; 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
|
92 ;; 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
|
93 ;; (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
|
94 ;; directory or attributes differ. |
13be90dfef0c
Merge today's change by eric with everybody else's
Paul Eggert <eggert@twinsun.com>
parents:
2213
diff
changeset
|
95 (or (not (string= dirname |
13be90dfef0c
Merge today's change by eric with everybody else's
Paul Eggert <eggert@twinsun.com>
parents:
2213
diff
changeset
|
96 (file-name-directory trial))) |
13be90dfef0c
Merge today's change by eric with everybody else's
Paul Eggert <eggert@twinsun.com>
parents:
2213
diff
changeset
|
97 (not (equal |
13be90dfef0c
Merge today's change by eric with everybody else's
Paul Eggert <eggert@twinsun.com>
parents:
2213
diff
changeset
|
98 (file-attributes file) |
13be90dfef0c
Merge today's change by eric with everybody else's
Paul Eggert <eggert@twinsun.com>
parents:
2213
diff
changeset
|
99 (file-attributes trial))))) |
13be90dfef0c
Merge today's change by eric with everybody else's
Paul Eggert <eggert@twinsun.com>
parents:
2213
diff
changeset
|
100 (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
|
101 vc-master-templates) |
13be90dfef0c
Merge today's change by eric with everybody else's
Paul Eggert <eggert@twinsun.com>
parents:
2213
diff
changeset
|
102 nil))))) |
904 | 103 |
104 (defun vc-backend-deduce (file) | |
105 "Return the version-control type of a file, nil if it is not registered" | |
106 (and file | |
107 (or (vc-file-getprop file 'vc-backend) | |
108 (vc-file-setprop file 'vc-backend (cdr (vc-registered file)))))) | |
109 | |
110 (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
|
111 "If the file in the current buffer is under version control, perform the |
904 | 112 logical next version-control action; otherwise, just toggle the buffer's |
113 read-only flag." | |
114 (interactive) | |
115 (if (vc-backend-deduce (buffer-file-name)) | |
116 (vc-next-action nil) | |
117 (toggle-read-only))) | |
118 | |
119 (defun vc-mode-line (file &optional label) | |
2491
5f3061858f47
vc-mode: name change.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2232
diff
changeset
|
120 "Set `vc-mode' to display type of version control for FILE. |
904 | 121 The value is set in the current buffer, which should be the buffer |
122 visiting FILE." | |
2218
13be90dfef0c
Merge today's change by eric with everybody else's
Paul Eggert <eggert@twinsun.com>
parents:
2213
diff
changeset
|
123 (interactive (list buffer-file-name nil)) |
904 | 124 (let ((vc-type (vc-backend-deduce file))) |
125 (if vc-type | |
126 (progn | |
127 (if (null (current-local-map)) | |
128 (use-local-map (make-sparse-keymap))) | |
129 (define-key (current-local-map) "\C-x\C-q" 'vc-toggle-read-only) | |
2491
5f3061858f47
vc-mode: name change.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2232
diff
changeset
|
130 (setq vc-mode |
904 | 131 (concat " " (or label (symbol-name vc-type)))))) |
132 ;; force update of mode line | |
133 (set-buffer-modified-p (buffer-modified-p)) | |
134 vc-type)) | |
135 | |
136 ;;; install a call to the above as a find-file hook | |
137 (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
|
138 ;; 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
|
139 ;; 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
|
140 (vc-file-setprop buffer-file-name 'vc-backend nil) |
904 | 141 (if (and (vc-mode-line buffer-file-name) (not vc-make-backup-files)) |
142 (progn | |
143 (make-local-variable 'make-backup-files) | |
144 (setq make-backup-files nil)))) | |
145 | |
146 (or (memq 'vc-find-file-hook find-file-hooks) | |
147 (setq find-file-hooks | |
148 (cons 'vc-find-file-hook find-file-hooks))) | |
149 | |
150 ;;; more hooks, this time for file-not-found | |
151 (defun vc-file-not-found-hook () | |
152 "When file is not found, try to check it out from RCS or SCCS. | |
153 Returns t if checkout was successful, nil otherwise." | |
154 (if (vc-backend-deduce buffer-file-name) | |
155 (progn | |
156 (require 'vc) | |
157 (not (vc-error-occurred (vc-checkout buffer-file-name)))))) | |
158 | |
159 (or (memq 'vc-file-not-found-hook find-file-not-found-hooks) | |
160 (setq find-file-not-found-hooks | |
161 (cons 'vc-file-not-found-hook find-file-not-found-hooks))) | |
162 | |
163 ;;; 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
|
164 ;;; 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
|
165 ;;; want to call them from random buffers. |
904 | 166 |
167 (setq vc-prefix-map (lookup-key global-map "\C-xv")) | |
168 (if (not (keymapp vc-prefix-map)) | |
169 (progn | |
170 (setq vc-prefix-map (make-sparse-keymap)) | |
171 (define-key global-map "\C-xv" vc-prefix-map) | |
172 (define-key vc-prefix-map "a" 'vc-update-change-log) | |
173 (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
|
174 (define-key vc-prefix-map "d" 'vc-directory) |
904 | 175 (define-key vc-prefix-map "h" 'vc-insert-headers) |
176 (define-key vc-prefix-map "i" 'vc-register) | |
177 (define-key vc-prefix-map "l" 'vc-print-log) | |
178 (define-key vc-prefix-map "r" 'vc-retrieve-snapshot) | |
179 (define-key vc-prefix-map "s" 'vc-create-snapshot) | |
180 (define-key vc-prefix-map "u" 'vc-revert-buffer) | |
181 (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
|
182 (define-key vc-prefix-map "=" 'vc-diff) |
904 | 183 )) |
184 | |
185 (provide 'vc-hooks) | |
186 | |
187 ;;; vc-hooks.el ends here |