diff options
| author | Richard M. Stallman | 1994-09-22 02:48:14 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1994-09-22 02:48:14 +0000 |
| commit | 624c0e9d149c1cd4d59cb5c2ebff4dee8688594a (patch) | |
| tree | b1ded43c2a70fcc7f4873620db156c213c4170a8 | |
| parent | 0a56ee6b96756317773c7830bc65a904382f8a06 (diff) | |
| download | emacs-624c0e9d149c1cd4d59cb5c2ebff4dee8688594a.tar.gz emacs-624c0e9d149c1cd4d59cb5c2ebff4dee8688594a.zip | |
(vc-menu-map): Set up menu items.
(vc-status): Use vc-path when calling prs.
(vc-status): New arg vc-type.
(vc-file-not-found-hook): Use save-excursion.
(vc-status): Renamed from vc-rcs-status. Handle SCCS.
(vc-display-status): Renamed from vc-rcs-status.
(vc-mode-line): Call vc-status for SCCS files too.
| -rw-r--r-- | lisp/vc-hooks.el | 191 |
1 files changed, 128 insertions, 63 deletions
diff --git a/lisp/vc-hooks.el b/lisp/vc-hooks.el index dd19ac4a0d9..87ac15556be 100644 --- a/lisp/vc-hooks.el +++ b/lisp/vc-hooks.el | |||
| @@ -38,8 +38,8 @@ when creating new masters.") | |||
| 38 | "*If non-nil, backups of registered files are made as with other files. | 38 | "*If non-nil, backups of registered files are made as with other files. |
| 39 | If nil (the default), files covered by version control don't get backups.") | 39 | If nil (the default), files covered by version control don't get backups.") |
| 40 | 40 | ||
| 41 | (defvar vc-rcs-status t | 41 | (defvar vc-display-status t |
| 42 | "*If non-nil, revision and locks on RCS working file displayed in modeline. | 42 | "*If non-nil, display revision number and lock status in modeline. |
| 43 | Otherwise, not displayed.") | 43 | Otherwise, not displayed.") |
| 44 | 44 | ||
| 45 | ;; Tell Emacs about this new kind of minor mode | 45 | ;; Tell Emacs about this new kind of minor mode |
| @@ -132,16 +132,18 @@ of the buffer." | |||
| 132 | (defun vc-mode-line (file &optional label) | 132 | (defun vc-mode-line (file &optional label) |
| 133 | "Set `vc-mode' to display type of version control for FILE. | 133 | "Set `vc-mode' to display type of version control for FILE. |
| 134 | The value is set in the current buffer, which should be the buffer | 134 | The value is set in the current buffer, which should be the buffer |
| 135 | visiting FILE." | 135 | visiting FILE. Second optional arg LABEL is put in place of version |
| 136 | control system name." | ||
| 136 | (interactive (list buffer-file-name nil)) | 137 | (interactive (list buffer-file-name nil)) |
| 137 | (if file | 138 | (if file |
| 138 | (let ((vc-type (vc-backend-deduce file))) | 139 | (let ((vc-type (vc-backend-deduce file))) |
| 139 | (setq vc-mode | 140 | (setq vc-mode |
| 140 | (and vc-type | 141 | (if vc-type |
| 141 | (concat " " (or label (symbol-name vc-type)) | 142 | (concat " " (or label (symbol-name vc-type)) |
| 142 | (if (and vc-rcs-status (eq vc-type 'RCS)) | 143 | (if vc-display-status |
| 143 | (vc-rcs-status file))))) | 144 | (vc-status file vc-type))))) |
| 144 | ;; Even root shouldn't modify a registered file without locking it first. | 145 | ;; Even root shouldn't modify a registered file without |
| 146 | ;; locking it first. | ||
| 145 | (and vc-type | 147 | (and vc-type |
| 146 | (not buffer-read-only) | 148 | (not buffer-read-only) |
| 147 | (zerop (user-uid)) | 149 | (zerop (user-uid)) |
| @@ -158,9 +160,9 @@ visiting FILE." | |||
| 158 | ;;(set-buffer-modified-p (buffer-modified-p)) ;;use this if Emacs 18 | 160 | ;;(set-buffer-modified-p (buffer-modified-p)) ;;use this if Emacs 18 |
| 159 | vc-type))) | 161 | vc-type))) |
| 160 | 162 | ||
| 161 | (defun vc-rcs-status (file) | 163 | (defun vc-status (file vc-type) |
| 162 | ;; Return string for placement in modeline by `vc-mode-line'. | 164 | ;; Return string for placement in modeline by `vc-mode-line'. |
| 163 | ;; If FILE is not registered under RCS, return nil. | 165 | ;; If FILE is not registered, return nil. |
| 164 | ;; If FILE is registered but not locked, return " REV" if there is a head | 166 | ;; If FILE is registered but not locked, return " REV" if there is a head |
| 165 | ;; revision and " @@" otherwise. | 167 | ;; revision and " @@" otherwise. |
| 166 | ;; If FILE is locked then return all locks in a string of the | 168 | ;; If FILE is locked then return all locks in a string of the |
| @@ -169,18 +171,19 @@ visiting FILE." | |||
| 169 | 171 | ||
| 170 | ;; Algorithm: | 172 | ;; Algorithm: |
| 171 | 173 | ||
| 172 | ;; 1. Check for master file corresponding to FILE being visited. | 174 | ;; Check for master file corresponding to FILE being visited. |
| 173 | ;; | 175 | ;; |
| 174 | ;; 2. Insert the first few characters of the master file into a work | 176 | ;; RCS: Insert the first few characters of the master file into a |
| 175 | ;; buffer. | 177 | ;; work buffer. Search work buffer for "locks...;" phrase; if not |
| 176 | ;; | 178 | ;; found, then keep inserting more characters until the phrase is |
| 177 | ;; 3. Search work buffer for "locks...;" phrase; if not found, then | 179 | ;; found. Extract the locks, and remove control characters |
| 178 | ;; keep inserting more characters until the phrase is found. | ||
| 179 | ;; | ||
| 180 | ;; 4. Extract the locks, and remove control characters | ||
| 181 | ;; separating them, like newlines; the string " user1:revision1 | 180 | ;; separating them, like newlines; the string " user1:revision1 |
| 182 | ;; user2:revision2 ..." is returned. | 181 | ;; user2:revision2 ..." is returned. |
| 183 | 182 | ;; | |
| 183 | ;; SCCS: Check if the p-file exists. If it does, read it and | ||
| 184 | ;; extract the locks, giving them the right format. Else use prs to | ||
| 185 | ;; find the revision number. | ||
| 186 | |||
| 184 | ;; Limitations: | 187 | ;; Limitations: |
| 185 | 188 | ||
| 186 | ;; The output doesn't show which version you are actually looking at. | 189 | ;; The output doesn't show which version you are actually looking at. |
| @@ -188,55 +191,85 @@ visiting FILE." | |||
| 188 | ;; The head revision is probably not what you want if you've used `rcs -b'. | 191 | ;; The head revision is probably not what you want if you've used `rcs -b'. |
| 189 | 192 | ||
| 190 | (let ((master (vc-name file)) | 193 | (let ((master (vc-name file)) |
| 191 | found) | 194 | found |
| 195 | status) | ||
| 192 | 196 | ||
| 193 | ;; If master file exists, then parse its contents, otherwise we return the | 197 | ;; If master file exists, then parse its contents, otherwise we |
| 194 | ;; nil value of this if form. | 198 | ;; return the nil value of this if form. |
| 195 | (if master | 199 | (if (and master vc-type) |
| 196 | (save-excursion | 200 | (save-excursion |
| 197 | 201 | ||
| 198 | ;; Create work buffer. | 202 | ;; Create work buffer. |
| 199 | (set-buffer (get-buffer-create " *vc-rcs-status*")) | 203 | (set-buffer (get-buffer-create " *vc-status*")) |
| 200 | (setq buffer-read-only nil | 204 | (setq buffer-read-only nil |
| 201 | default-directory (file-name-directory master)) | 205 | default-directory (file-name-directory master)) |
| 202 | (erase-buffer) | 206 | (erase-buffer) |
| 203 | 207 | ||
| 204 | ;; Check if we have enough of the header. | 208 | ;; Set the `status' var to the return value. |
| 205 | ;; If not, then keep including more. | 209 | (cond |
| 206 | (while | 210 | |
| 207 | (not (or found | 211 | ;; RCS code. |
| 208 | (let ((s (buffer-size))) | 212 | ((eq vc-type 'RCS) |
| 209 | (goto-char (1+ s)) | 213 | ;; Check if we have enough of the header. |
| 210 | (zerop (car (cdr (insert-file-contents | 214 | ;; If not, then keep including more. |
| 211 | master nil s (+ s 8192)))))))) | 215 | (while |
| 212 | (beginning-of-line) | 216 | (not (or found |
| 213 | (setq found (re-search-forward "^locks\\([^;]*\\);" nil t))) | 217 | (let ((s (buffer-size))) |
| 214 | 218 | (goto-char (1+ s)) | |
| 215 | (if found | 219 | (zerop (car (cdr (insert-file-contents |
| 216 | ;; Clean control characters and self-locks from text. | 220 | master nil s (+ s 8192)))))))) |
| 217 | (let* ((lock-pattern | 221 | (beginning-of-line) |
| 218 | (concat "[ \b\t\n\v\f\r]+\\(" | 222 | (setq found (re-search-forward "^locks\\([^;]*\\);" nil t))) |
| 219 | (regexp-quote (user-login-name)) | 223 | |
| 220 | ":\\)?")) | 224 | (if found |
| 221 | (locks | 225 | ;; Clean control characters and self-locks from text. |
| 222 | (save-restriction | 226 | (let* ((lock-pattern |
| 223 | (narrow-to-region (match-beginning 1) (match-end 1)) | 227 | (concat "[ \b\t\n\v\f\r]+\\(" |
| 224 | (goto-char (point-min)) | 228 | (regexp-quote (user-login-name)) |
| 225 | (while (re-search-forward lock-pattern nil t) | 229 | ":\\)?")) |
| 226 | (replace-match (if (eobp) "" ":") t t)) | 230 | (locks |
| 227 | (buffer-string))) | 231 | (save-restriction |
| 228 | (status | 232 | (narrow-to-region (match-beginning 1) (match-end 1)) |
| 229 | (if (not (string-equal locks "")) | 233 | (goto-char (point-min)) |
| 230 | locks | 234 | (while (re-search-forward lock-pattern nil t) |
| 231 | (goto-char (point-min)) | 235 | (replace-match (if (eobp) "" ":") t t)) |
| 232 | (if (looking-at "head[ \b\t\n\v\f\r]+\\([.0-9]+\\)") | 236 | (buffer-string)))) |
| 233 | (concat "-" (buffer-substring (match-beginning 1) | 237 | (setq status |
| 234 | (match-end 1))) | 238 | (if (not (string-equal locks "")) |
| 235 | " @@")))) | 239 | locks |
| 236 | ;; Clean work buffer. | 240 | (goto-char (point-min)) |
| 237 | (erase-buffer) | 241 | (if (looking-at "head[ \b\t\n\v\f\r]+\\([.0-9]+\\)") |
| 238 | (set-buffer-modified-p nil) | 242 | (concat "-" |
| 239 | status)))))) | 243 | (buffer-substring (match-beginning 1) |
| 244 | (match-end 1))) | ||
| 245 | " @@")))))) | ||
| 246 | |||
| 247 | ;; SCCS code. | ||
| 248 | ((eq vc-type 'SCCS) | ||
| 249 | ;; Build the name of the p-file and put it in the work buffer. | ||
| 250 | (insert master) | ||
| 251 | (search-backward "/s.") | ||
| 252 | (delete-char 2) | ||
| 253 | (insert "/p") | ||
| 254 | (if (not (file-exists-p (buffer-string))) | ||
| 255 | ;; No lock. | ||
| 256 | (let ((exec-path (if vc-path (append exec-path vc-path) | ||
| 257 | exec-path))) | ||
| 258 | (erase-buffer) | ||
| 259 | (insert "-") | ||
| 260 | (if (zerop (call-process "prs" nil t nil "-d:I:" master)) | ||
| 261 | (setq status (buffer-substring 1 (1- (point-max)))))) | ||
| 262 | ;; Locks exist. | ||
| 263 | (insert-file-contents (buffer-string) nil nil nil t) | ||
| 264 | (while (looking-at "[^ ]+ \\([^ ]+\\) \\([^ ]+\\).*\n") | ||
| 265 | (replace-match " \\2:\\1")) | ||
| 266 | (setq status (buffer-string)) | ||
| 267 | (aset status 0 ?:)))) | ||
| 268 | |||
| 269 | ;; Clean work buffer. | ||
| 270 | (erase-buffer) | ||
| 271 | (set-buffer-modified-p nil) | ||
| 272 | status)))) | ||
| 240 | 273 | ||
| 241 | ;;; install a call to the above as a find-file hook | 274 | ;;; install a call to the above as a find-file hook |
| 242 | (defun vc-find-file-hook () | 275 | (defun vc-find-file-hook () |
| @@ -258,7 +291,7 @@ visiting FILE." | |||
| 258 | "When file is not found, try to check it out from RCS or SCCS. | 291 | "When file is not found, try to check it out from RCS or SCCS. |
| 259 | Returns t if checkout was successful, nil otherwise." | 292 | Returns t if checkout was successful, nil otherwise." |
| 260 | (if (vc-backend-deduce buffer-file-name) | 293 | (if (vc-backend-deduce buffer-file-name) |
| 261 | (progn | 294 | (save-excursion |
| 262 | (require 'vc) | 295 | (require 'vc) |
| 263 | (not (vc-error-occurred (vc-checkout buffer-file-name)))))) | 296 | (not (vc-error-occurred (vc-checkout buffer-file-name)))))) |
| 264 | 297 | ||
| @@ -284,8 +317,40 @@ Returns t if checkout was successful, nil otherwise." | |||
| 284 | (define-key vc-prefix-map "u" 'vc-revert-buffer) | 317 | (define-key vc-prefix-map "u" 'vc-revert-buffer) |
| 285 | (define-key vc-prefix-map "v" 'vc-next-action) | 318 | (define-key vc-prefix-map "v" 'vc-next-action) |
| 286 | (define-key vc-prefix-map "=" 'vc-diff) | 319 | (define-key vc-prefix-map "=" 'vc-diff) |
| 287 | (define-key vc-prefix-map "~" 'vc-version-other-window) | 320 | (define-key vc-prefix-map "~" 'vc-version-other-window))) |
| 288 | )) | 321 | |
| 322 | ;;;(define-key vc-menu-map [show-files] | ||
| 323 | ;;; '("Show Files under VC" . (vc-directory t))) | ||
| 324 | (define-key vc-menu-map [vc-directory] '("Show Locked Files" . vc-directory)) | ||
| 325 | (define-key vc-menu-map [separator1] '("----")) | ||
| 326 | (define-key vc-menu-map [vc-rename-file] '("Rename File" . vc-rename-file)) | ||
| 327 | (define-key vc-menu-map [vc-version-other-window] | ||
| 328 | '("Show Other Version" . vc-version-other-window)) | ||
| 329 | (define-key vc-menu-map [vc-diff] '("Compare with Last Version" . vc-diff)) | ||
| 330 | (define-key vc-menu-map [vc-update-change-log] | ||
| 331 | '("Update ChangeLog" . vc-update-change-log)) | ||
| 332 | (define-key vc-menu-map [vc-print-log] '("Show History" . vc-print-log)) | ||
| 333 | (define-key vc-menu-map [separator2] '("----")) | ||
| 334 | (define-key vc-menu-map [undo] '("Undo Last Check-In" . vc-cancel-version)) | ||
| 335 | (define-key vc-menu-map [vc-revert-buffer] | ||
| 336 | '("Revert to Last Version" . vc-revert-buffer)) | ||
| 337 | (define-key vc-menu-map [vc-insert-header] | ||
| 338 | '("Insert Header" . vc-insert-headers)) | ||
| 339 | (define-key vc-menu-map [vc-menu-check-in] '("Check In" . vc-next-action)) | ||
| 340 | (define-key vc-menu-map [vc-check-out] '("Check Out" . vc-toggle-read-only)) | ||
| 341 | (define-key vc-menu-map [vc-register] '("Register" . vc-register)) | ||
| 342 | |||
| 343 | (put 'vc-rename-file 'menu-enable 'vc-mode) | ||
| 344 | (put 'vc-version-other-window 'menu-enable 'vc-mode) | ||
| 345 | (put 'vc-diff 'menu-enable 'vc-mode) | ||
| 346 | (put 'vc-update-change-log 'menu-enable '(eq (vc-backend-deduce (buffer-file-name)) 'RCS)) | ||
| 347 | (put 'vc-print-log 'menu-enable 'vc-mode) | ||
| 348 | (put 'vc-cancel-version 'menu-enable 'vc-mode) | ||
| 349 | (put 'vc-revert-buffer 'menu-enable 'vc-mode) | ||
| 350 | (put 'vc-insert-headers 'menu-enable 'vc-mode) | ||
| 351 | (put 'vc-next-action 'menu-enable '(and vc-mode (not buffer-read-only))) | ||
| 352 | (put 'vc-toggle-read-only 'menu-enable '(and vc-mode buffer-read-only)) | ||
| 353 | (put 'vc-register 'menu-enable '(not vc-mode)) | ||
| 289 | 354 | ||
| 290 | (provide 'vc-hooks) | 355 | (provide 'vc-hooks) |
| 291 | 356 | ||