Mercurial > emacs
comparison lisp/vc.el @ 21113:fcf0d1459d81
(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.
author | André Spiegel <spiegel@gnu.org> |
---|---|
date | Sun, 08 Mar 1998 10:03:50 +0000 |
parents | 9a6179e6eff6 |
children | 73a8874d25ce |
comparison
equal
deleted
inserted
replaced
21112:b113342cb7ad | 21113:fcf0d1459d81 |
---|---|
3 ;; Copyright (C) 1992, 93, 94, 95, 96, 97 Free Software Foundation, Inc. | 3 ;; Copyright (C) 1992, 93, 94, 95, 96, 97 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 ;; 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 |
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 |
616 ;; beginning of buffer like backward-char would | 616 ;; beginning of buffer like backward-char would |
617 (search-forward context-string nil t))) | 617 (search-forward context-string nil t))) |
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. |
624 (let ((point-context (vc-position-context (point))) | 633 (let ((point-context (vc-position-context (point))) |
625 ;; Use mark-marker to avoid confusion in transient-mark-mode. | 634 ;; Use mark-marker to avoid confusion in transient-mark-mode. |
676 (while (and compilation-error-list | 685 (while (and compilation-error-list |
677 (/= error-pos (car (car compilation-error-list)))) | 686 (/= error-pos (car (car compilation-error-list)))) |
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 |
690 ;; of changes because of expanded version-control key words. | 701 ;; of changes because of expanded version-control key words. |
691 ;; This is quite important since otherwise typeahead won't work as expected. | 702 ;; This is quite important since otherwise typeahead won't work as expected. |
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 |
700 (defun vc-buffer-sync (&optional not-urgent) | 717 (defun vc-buffer-sync (&optional not-urgent) |
701 ;; Make sure the current buffer and its working file are in sync | 718 ;; Make sure the current buffer and its working file are in sync |
982 (or (and override | 999 (or (and override |
983 (read-string | 1000 (read-string |
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 |
990 (defun vc-resynch-window (file &optional keep noquery) | 1008 (defun vc-resynch-window (file &optional keep noquery) |
991 ;; If the given file is in the current buffer, | 1009 ;; If the given file is in the current buffer, |
995 ;; NOQUERY should be t *only* if it is known the only difference | 1013 ;; NOQUERY should be t *only* if it is known the only difference |
996 ;; between the buffer and the file is due to RCS rather than user editing! | 1014 ;; between the buffer and the file is due to RCS rather than user editing! |
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 |
1008 (let ((view-old-buffer-read-only nil)) | 1022 (let ((view-old-buffer-read-only nil)) |
1009 (view-mode-exit))) | 1023 (view-mode-exit))) |
1013 (vc-mode-line buffer-file-name)) | 1027 (vc-mode-line buffer-file-name)) |
1014 (kill-buffer (current-buffer))))) | 1028 (kill-buffer (current-buffer))))) |
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 |
1026 ;; is nil, pop up a VC-log buffer, emit MSG, and set the | 1042 ;; is nil, pop up a VC-log buffer, emit MSG, and set the |
1027 ;; action on close to ACTION; otherwise, do action immediately. | 1043 ;; action on close to ACTION; otherwise, do action immediately. |
1446 ;; Clear all version headers in the current buffer, i.e. reset them | 1462 ;; Clear all version headers in the current buffer, i.e. reset them |
1447 ;; to the nonexpanded form. Only implemented for RCS, yet. | 1463 ;; to the nonexpanded form. Only implemented for RCS, yet. |
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. |
1460 ;; All VC commands get mapped into logical equivalents. | 1479 ;; All VC commands get mapped into logical equivalents. |
1461 | 1480 |