comparison lisp/vc.el @ 2226:b2216b3b8f57

(vc-header-strings) Name changed to vc-header-alist, to match the docs. (vc-finish-logentry, vc-next-comment, vc-previous-comment, vc-comment-search-forward, vc-comment-search-backward) The VC comment ring is now a separate buffer from *VC-log*; editing of old comments is no longer destructive.
author Eric S. Raymond <esr@snark.thyrsus.com>
date Wed, 17 Mar 1993 13:58:48 +0000
parents a729b16f7427
children 61e1f8813d03
comparison
equal deleted inserted replaced
2225:19e1e3cb7415 2226:b2216b3b8f57
1 ;;; vc.el --- drive a version-control system from within Emacs 1 ;;; vc.el --- drive a version-control system from within Emacs
2 2
3 ;; Copyright (C) 1992 Free Software Foundation, Inc. 3 ;; Copyright (C) 1992 Free Software Foundation, Inc.
4 4
5 ;; Author: Eric S. Raymond <esr@snark.thyrsus.com> 5 ;; Author: Eric S. Raymond <esr@snark.thyrsus.com>
6 ;; Version: 5.0 6 ;; Version: 5.2
7 7
8 ;; $Id: vc.el,v 1.26.1.1 1993/03/16 20:54:53 eggert Exp $ 8 ;; $Id: vc.el,v 1.27 1993/03/16 21:09:56 eggert Exp eric $
9 9
10 ;; This file is part of GNU Emacs. 10 ;; This file is part of GNU Emacs.
11 11
12 ;; GNU Emacs is free software; you can redistribute it and/or modify 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 13 ;; it under the terms of the GNU General Public License as published by
88 (defconst vc-static-header-alist 88 (defconst vc-static-header-alist
89 '(("\\.c$" . 89 '(("\\.c$" .
90 "\n#ifndef lint\nstatic char vcid[] = \"\%s\";\n#endif /* lint */\n")) 90 "\n#ifndef lint\nstatic char vcid[] = \"\%s\";\n#endif /* lint */\n"))
91 "*Associate static header string templates with file types. A \%s in the 91 "*Associate static header string templates with file types. A \%s in the
92 template is replaced with the first string associated with the file's 92 template is replaced with the first string associated with the file's
93 verson-control type in vc-header-strings.") 93 verson-control type in vc-header-alist.")
94
94 (defvar vc-comment-alist 95 (defvar vc-comment-alist
95 '((nroff-mode ".\\\"" "")) 96 '((nroff-mode ".\\\"" ""))
96 "*Special comment delimiters to be used in generating vc headers only. 97 "*Special comment delimiters to be used in generating vc headers only.
97 Add an entry in this list if you need to override the normal comment-start 98 Add an entry in this list if you need to override the normal comment-start
98 and comment-end variables. This will only be necessary if the mode language 99 and comment-end variables. This will only be necessary if the mode language
218 (search-forward context-string nil t))) 219 (search-forward context-string nil t)))
219 ;; to beginning of OSTRING 220 ;; to beginning of OSTRING
220 (- (point) (length context-string)))))))) 221 (- (point) (length context-string))))))))
221 222
222 (defun vc-revert-buffer1 (&optional arg no-confirm) 223 (defun vc-revert-buffer1 (&optional arg no-confirm)
223 ;; This code was shamelessly lifted from Sebastian Kremer's rcs.el mode. 224 ;; Most of this was shamelessly lifted from Sebastian Kremer's rcs.el mode.
224 ;; Revert buffer, try to keep point and mark where user expects them in spite 225 ;; Revert buffer, try to keep point and mark where user expects them in spite
225 ;; of changes because of expanded version-control key words. 226 ;; of changes because of expanded version-control key words.
226 ;; This is quite important since otherwise typeahead won't work as expected. 227 ;; This is quite important since otherwise typeahead won't work as expected.
227 (interactive "P") 228 (interactive "P")
228 (widen) 229 (widen)
230 ;; Use mark-marker to avoid confusion in transient-mark-mode. 231 ;; Use mark-marker to avoid confusion in transient-mark-mode.
231 (mark-context (if (eq (marker-buffer (mark-marker)) (current-buffer)) 232 (mark-context (if (eq (marker-buffer (mark-marker)) (current-buffer))
232 (vc-position-context (mark-marker)))) 233 (vc-position-context (mark-marker))))
233 ;; Make the right thing happen in transient-mark-mode. 234 ;; Make the right thing happen in transient-mark-mode.
234 (mark-active nil)) 235 (mark-active nil))
236
237 ;; the actual revisit
235 (revert-buffer arg no-confirm) 238 (revert-buffer arg no-confirm)
239
240 ;; Restore point and mark
236 (let ((new-point (vc-find-position-by-context point-context))) 241 (let ((new-point (vc-find-position-by-context point-context)))
237 (if new-point (goto-char new-point))) 242 (if new-point (goto-char new-point)))
238 (if mark-context 243 (if mark-context
239 (let ((new-mark (vc-find-position-by-context mark-context))) 244 (let ((new-mark (vc-find-position-by-context mark-context)))
240 (if new-mark (set-mark new-mark)))))) 245 (if new-mark (set-mark new-mark))))))
342 347
343 ;;; These functions help the vc-next-action entry point 348 ;;; These functions help the vc-next-action entry point
344 349
345 (defun vc-checkout-writeable-buffer () 350 (defun vc-checkout-writeable-buffer ()
346 "Retrieve a writeable copy of the latest version of the current buffer's file." 351 "Retrieve a writeable copy of the latest version of the current buffer's file."
347 (vc-checkout buffer-file-name t) 352 (vc-checkout (buffer-file-name) t)
348 ) 353 )
349 354
350 ;;;###autoload 355 ;;;###autoload
351 (defun vc-register (&optional override) 356 (defun vc-register (&optional override)
352 "Register the current file into your version-control system." 357 "Register the current file into your version-control system."
459 (defun vc-finish-logentry () 464 (defun vc-finish-logentry ()
460 "Complete the operation implied by the current log entry." 465 "Complete the operation implied by the current log entry."
461 (interactive) 466 (interactive)
462 (goto-char (point-max)) 467 (goto-char (point-max))
463 (if (not (bolp)) (newline)) 468 (if (not (bolp)) (newline))
464 ;; delimit current page 469 ;; Append the contents of the log buffer to the comment ring
465 (save-excursion 470 (save-excursion
466 (widen) 471 (set-buffer (get-buffer-create "*VC-comment-ring*"))
467 (goto-char (point-max)) 472 (goto-char (point-max))
473 (set-mark (point))
474 (insert-buffer-substring "*VC-log*")
468 (if (and (not (bobp)) (not (= (char-after (1- (point))) ?\f))) 475 (if (and (not (bobp)) (not (= (char-after (1- (point))) ?\f)))
469 (insert-char ?\f 1))) 476 (insert-char ?\f 1))
470 (if (not (bobp)) 477 (if (not (bobp))
471 (forward-char -1)) 478 (forward-char -1))
472 (mark-page) 479 (exchange-point-and-mark)
473 ;; Check for errors 480 ;; Check for errors
474 (vc-backend-logentry-check vc-log-file) 481 (vc-backend-logentry-check vc-log-file)
482 )
475 ;; OK, do it to it 483 ;; OK, do it to it
476 (if vc-log-operation 484 (if vc-log-operation
477 (funcall vc-log-operation 485 (funcall vc-log-operation
478 vc-log-file 486 vc-log-file
479 vc-log-version 487 vc-log-version
480 (buffer-substring (region-beginning) (1- (region-end)))) 488 (buffer-string))
481 (error "No log operation is pending.")) 489 (error "No log operation is pending."))
482 ;; Return to "parent" buffer of this checkin and remove checkin window 490 ;; Return to "parent" buffer of this checkin and remove checkin window
483 (pop-to-buffer (get-file-buffer vc-log-file)) 491 (pop-to-buffer (get-file-buffer vc-log-file))
484 (delete-window (get-buffer-window "*VC-log*")) 492 (delete-window (get-buffer-window "*VC-log*"))
485 (bury-buffer "*VC-log*") 493 (bury-buffer "*VC-log*")
494 (bury-buffer "*VC-comment-ring*")
486 ;; Now make sure we see the expanded headers 495 ;; Now make sure we see the expanded headers
487 (vc-resynch-window buffer-file-name vc-keep-workfiles t) 496 (vc-resynch-window buffer-file-name vc-keep-workfiles t)
488 (run-hooks vc-log-after-operation-hook) 497 (run-hooks vc-log-after-operation-hook)
489 ) 498 )
490 499
491 ;; Code for access to the comment ring 500 ;; Code for access to the comment ring
492 501
493 (defun vc-next-comment () 502 (defun vc-next-comment ()
494 "Fill the log buffer with the next message in the msg ring." 503 "Fill the log buffer with the next message in the msg ring."
495 (interactive) 504 (interactive)
496 (widen) 505 (erase-buffer)
497 (forward-page) 506 (save-excursion
498 (if (= (point) (point-max)) 507 (set-buffer "*VC-comment-ring*")
499 (goto-char (point-min))) 508 (forward-page)
500 (mark-page) 509 (if (= (point) (point-max))
501 (narrow-to-page)) 510 (goto-char (point-min)))
511 (mark-page)
512 (append-to-buffer "*VC-log*" (point) (1- (mark)))
513 ))
502 514
503 (defun vc-previous-comment () 515 (defun vc-previous-comment ()
504 "Fill the log buffer with the previous message in the msg ring." 516 "Fill the log buffer with the previous message in the msg ring."
505 (interactive) 517 (interactive)
506 (widen) 518 (erase-buffer)
507 (if (= (point) (point-min)) 519 (save-excursion
508 (goto-char (point-max))) 520 (set-buffer "*VC-comment-ring*")
509 (backward-page) 521 (if (= (point) (point-min))
510 (mark-page) 522 (goto-char (point-max)))
511 (narrow-to-page)) 523 (backward-page)
524 (mark-page)
525 (append-to-buffer "*VC-log*" (point) (1- (mark)))
526 ))
512 527
513 (defun vc-comment-search-backward (regexp) 528 (defun vc-comment-search-backward (regexp)
514 "Fill the log buffer with the last message in the msg ring matching REGEXP." 529 "Fill the log buffer with the last message in the msg ring matching REGEXP."
515 (interactive "sSearch backward for: ") 530 (interactive "sSearch backward for: ")
516 (widen) 531 (erase-buffer)
517 (if (= (point) (point-min)) 532 (save-excursion
518 (goto-char (point-max))) 533 (set-buffer "*VC-comment-ring*")
519 (re-search-backward regexp nil t) 534 (if (= (point) (point-min))
520 (mark-page) 535 (goto-char (point-max)))
521 (narrow-to-page)) 536 (re-search-backward regexp nil t)
537 (mark-page)
538 (append-to-buffer "*VC-log*" (point) (1- (mark)))
539 ))
522 540
523 (defun vc-comment-search-forward (regexp) 541 (defun vc-comment-search-forward (regexp)
524 "Fill the log buffer with the next message in the msg ring matching REGEXP." 542 "Fill the log buffer with the next message in the msg ring matching REGEXP."
525 (interactive "sSearch forward for: ") 543 (interactive "sSearch forward for: ")
526 (widen) 544 (erase-buffer)
527 (if (= (point) (point-min)) 545 (save-excursion
528 (goto-char (point-max))) 546 (set-buffer "*VC-comment-ring*")
529 (re-search-forward regexp nil t) 547 (if (= (point) (point-max))
530 (mark-page) 548 (goto-char (point-min)))
531 (narrow-to-page)) 549 (re-search-forward regexp nil t)
550 (mark-page)
551 (append-to-buffer "*VC-log*" (point) (1- (mark)))
552 ))
532 553
533 ;; Additional entry points for examining version histories 554 ;; Additional entry points for examining version histories
534 555
535 ;;;###autoload 556 ;;;###autoload
536 (defun vc-diff (historic) 557 (defun vc-diff (historic)
600 621
601 ;;;###autoload 622 ;;;###autoload
602 (defun vc-insert-headers () 623 (defun vc-insert-headers ()
603 "Insert headers in a file for use with your version-control system. 624 "Insert headers in a file for use with your version-control system.
604 Headers desired are inserted at the start of the buffer, and are pulled from 625 Headers desired are inserted at the start of the buffer, and are pulled from
605 the variable vc-header-strings" 626 the variable vc-header-alist"
606 (interactive) 627 (interactive)
607 (save-excursion 628 (save-excursion
608 (save-restriction 629 (save-restriction
609 (widen) 630 (widen)
610 (if (or (not (vc-check-headers)) 631 (if (or (not (vc-check-headers))
673 (basic-save-buffer) 694 (basic-save-buffer)
674 (kill-buffer (current-buffer)) 695 (kill-buffer (current-buffer))
675 )) 696 ))
676 697
677 (defun vc-lookup-triple (file name) 698 (defun vc-lookup-triple (file name)
678 (or 699 ;; Return the numeric version corresponding to a named snapshot of file
679 name 700 ;; If name is nil or a version number string it's just passed through
680 (let ((firstchar (aref name 0))) 701 (cond ((null name) "")
681 (and (>= firstchar ?0) (<= firstchar ?9) name)) 702 ((let ((firstchar (aref name 0)))
682 (car (vc-master-info 703 (and (>= firstchar ?0) (<= firstchar ?9)))
683 (concat (vc-backend-subdirectory-name file) "/" vc-name-assoc-file) 704 name)
684 (list (concat name "\t:\t" file "\t\\(.+\\)")))) 705 (t
685 )) 706 (car (vc-master-info
707 (concat (vc-backend-subdirectory-name file) "/" vc-name-assoc-file)
708 (list (concat name "\t:\t" file "\t\\(.+\\)"))))
709 )))
686 710
687 ;; Named-configuration entry points 711 ;; Named-configuration entry points
688 712
689 (defun vc-quiescent-p () 713 (defun vc-quiescent-p ()
690 ;; Is the current directory ready to be snapshot? 714 ;; Is the current directory ready to be snapshot?
764 788
765 ;;;###autoload 789 ;;;###autoload
766 (defun vc-cancel-version (norevert) 790 (defun vc-cancel-version (norevert)
767 "Undo your latest checkin." 791 "Undo your latest checkin."
768 (interactive "P") 792 (interactive "P")
769 (let ((target (vc-your-latest-version (buffer-file-name)))) 793 (let ((target (concat (vc-latest-version (buffer-file-name))))
770 (if (null target) 794 (yours (concat (vc-your-latest-version)))
771 (error "You didn't check in the last change.")) 795 (prompt (if (string-equal yours target)
772 (and (yes-or-no-p (format "Remove version %s from master? " target)) 796 "Remove your version %s from master?"
773 (vc-backend-uncheck (buffer-file-name) target))) 797 "Version %s was not your change. Remove it anyway?")))
774 (if norevert 798 (if (null (yes-or-no-p (format prompt target)))
775 (vc-mode-line (buffer-file-name)) 799 nil
776 (vc-checkout (buffer-file-name) nil)) 800 (vc-backend-uncheck (buffer-file-name) target)
801 (if norevert
802 (vc-mode-line (buffer-file-name))
803 (vc-checkout (buffer-file-name) nil)))
804 )
777 ) 805 )
778 806
779 (defun vc-rename-file (old new) 807 (defun vc-rename-file (old new)
780 "Rename a file, taking its master files with it." 808 "Rename a file, taking its master files with it."
781 (interactive "fOld name: \nFNew name: ") 809 (interactive "fOld name: \nFNew name: ")
961 989
962 ;; Collect back-end-dependent stuff here 990 ;; Collect back-end-dependent stuff here
963 ;; 991 ;;
964 ;; Everything eventually funnels through these functions. To implement 992 ;; Everything eventually funnels through these functions. To implement
965 ;; support for a new version-control system, add another branch to the 993 ;; support for a new version-control system, add another branch to the
966 ;; vc-backend-dispatch macro (in vc-hooks.el) and fill it in in each call. 994 ;; vc-backend-dispatch macro and fill it in in each call. The variable
995 ;; vc-master-templates in vc-hooks.el will also have to change.
967 996
968 (defmacro vc-backend-dispatch (f s r) 997 (defmacro vc-backend-dispatch (f s r)
969 "Execute FORM1 or FORM2 depending on whether we're using SCCS or RCS." 998 "Execute FORM1 or FORM2 depending on whether we're using SCCS or RCS."
970 (list 'let (list (list 'type (list 'vc-backend-deduce f))) 999 (list 'let (list (list 'type (list 'vc-backend-deduce f)))
971 (list 'cond 1000 (list 'cond
1089 1118
1090 (defun vc-backend-logentry-check (file) 1119 (defun vc-backend-logentry-check (file)
1091 (vc-backend-dispatch file 1120 (vc-backend-dispatch file
1092 (if (>= (- (region-end) (region-beginning)) 512) ;; SCCS 1121 (if (>= (- (region-end) (region-beginning)) 512) ;; SCCS
1093 (progn 1122 (progn
1094 (message "Reverting %s..." file)
1095 (goto-char 512) 1123 (goto-char 512)
1096 (error 1124 (error
1097 "Log must be less than 512 characters. Point is now at char 512."))) 1125 "Log must be less than 512 characters. Point is now at char 512.")))
1098 nil) 1126 nil)
1099 ) 1127 )
1100 1128
1101 (defun vc-backend-checkin (file &optional rev comment) 1129 (defun vc-backend-checkin (file &optional rev comment)
1102 ;; Register changes to FILE as level REV with explanatory COMMENT. 1130 ;; Register changes to FILE as level REV with explanatory COMMENT.
1103 ;; Automatically retrieves a read-only version of the file with 1131 ;; Automatically retrieves a read-only version of the file with
1104 (message "Reverting %s...done" file)
1105 ;; keywords expanded if vc-keep-workfiles is non-nil, otherwise 1132 ;; keywords expanded if vc-keep-workfiles is non-nil, otherwise
1106 ;; it deletes the workfile. 1133 ;; it deletes the workfile.
1107 (message "Checking in %s..." file) 1134 (message "Checking in %s..." file)
1108 (save-excursion 1135 (save-excursion
1109 ;; Change buffers to get local value of vc-checkin-switches. 1136 ;; Change buffers to get local value of vc-checkin-switches.
1183 ) 1210 )
1184 ) 1211 )
1185 1212
1186 (defun vc-backend-diff (file oldvers &optional newvers) 1213 (defun vc-backend-diff (file oldvers &optional newvers)
1187 ;; Get a difference report between two versions 1214 ;; Get a difference report between two versions
1215 (if (eq (vc-backend-deduce file) 'SCCS)
1216 (setq oldvers (vc-lookup-triple file oldvers))
1217 (setq newvers (vc-lookup-triple file newvers)))
1188 (apply 'vc-do-command 1 1218 (apply 'vc-do-command 1
1189 (or (vc-backend-dispatch file "vcdiff" "rcsdiff") 1219 (or (vc-backend-dispatch file "vcdiff" "rcsdiff")
1190 (error "File %s is not under version control." file)) 1220 (error "File %s is not under version control." file))
1191 file 1221 file
1192 (and oldvers (concat "-r" oldvers)) 1222 (and oldvers (concat "-r" oldvers))
1250 notably for reversions. 1280 notably for reversions.
1251 1281
1252 vc-diff-options A list consisting of the flags 1282 vc-diff-options A list consisting of the flags
1253 to be used for generating context diffs. 1283 to be used for generating context diffs.
1254 1284
1255 vc-header-strings Which keywords to insert when adding headers 1285 vc-header-alist Which keywords to insert when adding headers
1256 with \\[vc-insert-headers]. Defaults to 1286 with \\[vc-insert-headers]. Defaults to
1257 '(\"\%\W\%\") under SCCS, '(\"\$Id\$\") under RCS. 1287 '(\"\%\W\%\") under SCCS, '(\"\$Id\$\") under RCS.
1258 1288
1259 vc-static-header-alist By default, version headers inserted in C files 1289 vc-static-header-alist By default, version headers inserted in C files
1260 get stuffed in a static string area so that 1290 get stuffed in a static string area so that