aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndré Spiegel1998-03-08 10:03:50 +0000
committerAndré Spiegel1998-03-08 10:03:50 +0000
commit4b398f5de97a70bf211b04a65abf130fa102b4ed (patch)
treeb5719d32f207c53457ceb5a17df91a9426d27df2
parent3c3d11e7764c2afc4496c21a0f2356ab45abf88d (diff)
downloademacs-4b398f5de97a70bf211b04a65abf130fa102b4ed.tar.gz
emacs-4b398f5de97a70bf211b04a65abf130fa102b4ed.zip
(vc-context-matches-p): New function.
(vc-restore-buffer-context): Restore point and mark only if they don't match the context. (vc-revert-buffer1, vc-clear-headers): Use save-excursion to relocate point and mark, and vc-restore-buffer-context as a backup. (vc-resynch-buffer): When operating on the current buffer, don't use save-excursion, because that would undo the effects of the above functions. (vc-resynch-window): Deleted code that removed vc-find-file-hook temporarily. This was unnecessary, because find-file-hooks are not called when the buffer is reverted. (vc-register): Added comment for prev change.
-rw-r--r--lisp/vc.el65
1 files changed, 42 insertions, 23 deletions
diff --git a/lisp/vc.el b/lisp/vc.el
index 228569ba5fb..328c69b3270 100644
--- a/lisp/vc.el
+++ b/lisp/vc.el
@@ -5,7 +5,7 @@
5;; Author: Eric S. Raymond <esr@snark.thyrsus.com> 5;; Author: Eric S. Raymond <esr@snark.thyrsus.com>
6;; Maintainer: Andre Spiegel <spiegel@inf.fu-berlin.de> 6;; Maintainer: Andre Spiegel <spiegel@inf.fu-berlin.de>
7 7
8;; $Id: vc.el,v 1.208.1.1 1998/02/27 18:28:44 spiegel Exp $ 8;; $Id: vc.el,v 1.209 1998/02/27 18:44:14 spiegel Exp spiegel $
9 9
10;; This file is part of GNU Emacs. 10;; This file is part of GNU Emacs.
11 11
@@ -618,6 +618,15 @@ to an optional list of FLAGS."
618 ;; to beginning of OSTRING 618 ;; to beginning of OSTRING
619 (- (point) (length context-string)))))))) 619 (- (point) (length context-string))))))))
620 620
621(defun vc-context-matches-p (posn context)
622 ;; Returns t if POSN matches CONTEXT, nil otherwise.
623 (let* ((context-string (nth 2 context))
624 (len (length context-string))
625 (end (+ posn len)))
626 (if (> end (1+ (buffer-size)))
627 nil
628 (string= context-string (buffer-substring posn end)))))
629
621(defun vc-buffer-context () 630(defun vc-buffer-context ()
622 ;; Return a list '(point-context mark-context reparse); from which 631 ;; Return a list '(point-context mark-context reparse); from which
623 ;; vc-restore-buffer-context can later restore the context. 632 ;; vc-restore-buffer-context can later restore the context.
@@ -678,12 +687,14 @@ to an optional list of FLAGS."
678 (setq compilation-error-list (cdr compilation-error-list)))))) 687 (setq compilation-error-list (cdr compilation-error-list))))))
679 (setq reparse (cdr reparse))) 688 (setq reparse (cdr reparse)))
680 689
681 ;; Restore point and mark 690 ;; if necessary, restore point and mark
682 (let ((new-point (vc-find-position-by-context point-context))) 691 (if (not (vc-context-matches-p (point) point-context))
683 (if new-point (goto-char new-point))) 692 (let ((new-point (vc-find-position-by-context point-context)))
693 (if new-point (goto-char new-point))))
684 (if mark-context 694 (if mark-context
685 (let ((new-mark (vc-find-position-by-context mark-context))) 695 (if (not (vc-context-matches-p (mark) mark-context))
686 (if new-mark (set-mark new-mark)))))) 696 (let ((new-mark (vc-find-position-by-context mark-context)))
697 (if new-mark (set-mark new-mark)))))))
687 698
688(defun vc-revert-buffer1 (&optional arg no-confirm) 699(defun vc-revert-buffer1 (&optional arg no-confirm)
689 ;; Revert buffer, try to keep point and mark where user expects them in spite 700 ;; Revert buffer, try to keep point and mark where user expects them in spite
@@ -692,8 +703,14 @@ to an optional list of FLAGS."
692 (interactive "P") 703 (interactive "P")
693 (widen) 704 (widen)
694 (let ((context (vc-buffer-context))) 705 (let ((context (vc-buffer-context)))
695 ;; t means don't call normal-mode; that's to preserve various minor modes. 706 ;; Use save-excursion here, because it may be able to restore point
696 (revert-buffer arg no-confirm t) 707 ;; and mark properly even in cases where vc-restore-buffer-context
708 ;; would fail. However, save-excursion might also get it wrong --
709 ;; in this case, vc-restore-buffer-context gives it a second try.
710 (save-excursion
711 ;; t means don't call normal-mode;
712 ;; that's to preserve various minor modes.
713 (revert-buffer arg no-confirm t))
697 (vc-restore-buffer-context context))) 714 (vc-restore-buffer-context context)))
698 715
699 716
@@ -984,6 +1001,7 @@ merge in the changes into your working copy."
984 (format "Initial version level for %s: " buffer-file-name))) 1001 (format "Initial version level for %s: " buffer-file-name)))
985 vc-default-init-version) 1002 vc-default-init-version)
986 comment) 1003 comment)
1004 ;; Recompute backend property (it may have been set to nil before).
987 (setq vc-buffer-backend (vc-backend (buffer-file-name))) 1005 (setq vc-buffer-backend (vc-backend (buffer-file-name)))
988 ) 1006 )
989 1007
@@ -997,11 +1015,7 @@ merge in the changes into your working copy."
997 (and (string= buffer-file-name file) 1015 (and (string= buffer-file-name file)
998 (if keep 1016 (if keep
999 (progn 1017 (progn
1000 ;; temporarily remove vc-find-file-hook, so that
1001 ;; we don't lose the properties
1002 (remove-hook 'find-file-hooks 'vc-find-file-hook)
1003 (vc-revert-buffer1 t noquery) 1018 (vc-revert-buffer1 t noquery)
1004 (add-hook 'find-file-hooks 'vc-find-file-hook)
1005 (and view-read-only 1019 (and view-read-only
1006 (if (file-writable-p file) 1020 (if (file-writable-p file)
1007 (and view-mode 1021 (and view-mode
@@ -1015,11 +1029,13 @@ merge in the changes into your working copy."
1015 1029
1016(defun vc-resynch-buffer (file &optional keep noquery) 1030(defun vc-resynch-buffer (file &optional keep noquery)
1017 ;; if FILE is currently visited, resynch its buffer 1031 ;; if FILE is currently visited, resynch its buffer
1018 (let ((buffer (get-file-buffer file))) 1032 (if (string= buffer-file-name file)
1019 (if buffer 1033 (vc-resynch-window file keep noquery)
1020 (save-excursion 1034 (let ((buffer (get-file-buffer file)))
1021 (set-buffer buffer) 1035 (if buffer
1022 (vc-resynch-window file keep noquery))))) 1036 (save-excursion
1037 (set-buffer buffer)
1038 (vc-resynch-window file keep noquery))))))
1023 1039
1024(defun vc-start-entry (file rev comment msg action &optional after-hook) 1040(defun vc-start-entry (file rev comment msg action &optional after-hook)
1025 ;; Accept a comment for an operation on FILE revision REV. If COMMENT 1041 ;; Accept a comment for an operation on FILE revision REV. If COMMENT
@@ -1448,12 +1464,15 @@ the variable `vc-header-alist'."
1448 ;; Don't lose point and mark during this. 1464 ;; Don't lose point and mark during this.
1449 (let ((context (vc-buffer-context)) 1465 (let ((context (vc-buffer-context))
1450 (case-fold-search nil)) 1466 (case-fold-search nil))
1451 (goto-char (point-min)) 1467 ;; save-excursion may be able to relocate point and mark properly.
1452 (while (re-search-forward 1468 ;; If it fails, vc-restore-buffer-context will give it a second try.
1453 (concat "\\$\\(Author\\|Date\\|Header\\|Id\\|Locker\\|Name\\|" 1469 (save-excursion
1454 "RCSfile\\|Revision\\|Source\\|State\\): [^\\$\\n]+\\$") 1470 (goto-char (point-min))
1455 nil t) 1471 (while (re-search-forward
1456 (replace-match "$\\1$")) 1472 (concat "\\$\\(Author\\|Date\\|Header\\|Id\\|Locker\\|Name\\|"
1473 "RCSfile\\|Revision\\|Source\\|State\\): [^$\n]+\\$")
1474 nil t)
1475 (replace-match "$\\1$")))
1457 (vc-restore-buffer-context context))) 1476 (vc-restore-buffer-context context)))
1458 1477
1459;; The VC directory major mode. Coopt Dired for this. 1478;; The VC directory major mode. Coopt Dired for this.