comparison lisp/vc-hooks.el @ 89909:68c22ea6027c

Sync to HEAD
author Kenichi Handa <handa@m17n.org>
date Fri, 16 Apr 2004 12:51:06 +0000
parents 375f2633d815
children 4c90ffeb71c5
comparison
equal deleted inserted replaced
89908:ee1402f7b568 89909:68c22ea6027c
1 ;;; vc-hooks.el --- resident support for version-control 1 ;;; vc-hooks.el --- resident support for version-control
2 2
3 ;; Copyright (C) 1992,93,94,95,96,98,99,2000,2003 3 ;; Copyright (C) 1992,93,94,95,96,98,99,2000,03,2004
4 ;; Free Software Foundation, Inc. 4 ;; Free Software Foundation, Inc.
5 5
6 ;; Author: FSF (see vc.el for full credits) 6 ;; Author: FSF (see vc.el for full credits)
7 ;; Maintainer: Andre Spiegel <spiegel@gnu.org> 7 ;; Maintainer: Andre Spiegel <spiegel@gnu.org>
8 8
9 ;; $Id: vc-hooks.el,v 1.155 2003/07/26 15:54:53 rost Exp $ 9 ;; $Id: vc-hooks.el,v 1.165 2004/03/28 17:38:03 monnier Exp $
10 10
11 ;; This file is part of GNU Emacs. 11 ;; This file is part of GNU Emacs.
12 12
13 ;; GNU Emacs is free software; you can redistribute it and/or modify 13 ;; GNU Emacs is free software; you can redistribute it and/or modify
14 ;; it under the terms of the GNU General Public License as published by 14 ;; it under the terms of the GNU General Public License as published by
38 (require 'cl)) 38 (require 'cl))
39 39
40 ;; Customization Variables (the rest is in vc.el) 40 ;; Customization Variables (the rest is in vc.el)
41 41
42 (defvar vc-ignore-vc-files nil) 42 (defvar vc-ignore-vc-files nil)
43 (make-obsolete-variable 'vc-ignore-vc-files 'vc-handled-backends) 43 (make-obsolete-variable 'vc-ignore-vc-files
44 "set `vc-handled-backends' to nil to disable VC.")
45
44 (defvar vc-master-templates ()) 46 (defvar vc-master-templates ())
45 (make-obsolete-variable 'vc-master-templates 'vc-BACKEND-master-templates) 47 (make-obsolete-variable 'vc-master-templates
48 "to define master templates for a given BACKEND, use
49 vc-BACKEND-master-templates. To enable or disable VC for a given
50 BACKEND, use `vc-handled-backends'.")
51
46 (defvar vc-header-alist ()) 52 (defvar vc-header-alist ())
47 (make-obsolete-variable 'vc-header-alist 'vc-BACKEND-header) 53 (make-obsolete-variable 'vc-header-alist 'vc-BACKEND-header)
48 54
49 (defcustom vc-handled-backends '(RCS CVS SVN MCVS SCCS) 55 (defcustom vc-handled-backends '(RCS CVS SVN SCCS Arch MCVS)
56 ;; Arch and MCVS come last because they are per-tree rather than per-dir.
50 "*List of version control backends for which VC will be used. 57 "*List of version control backends for which VC will be used.
51 Entries in this list will be tried in order to determine whether a 58 Entries in this list will be tried in order to determine whether a
52 file is under that sort of version control. 59 file is under that sort of version control.
53 Removing an entry from the list prevents VC from being activated 60 Removing an entry from the list prevents VC from being activated
54 when visiting a file managed by that backend. 61 when visiting a file managed by that backend.
257 (t (apply f args))))) 264 (t (apply f args)))))
258 265
259 (defmacro vc-call (fun file &rest args) 266 (defmacro vc-call (fun file &rest args)
260 ;; BEWARE!! `file' is evaluated twice!! 267 ;; BEWARE!! `file' is evaluated twice!!
261 `(vc-call-backend (vc-backend ,file) ',fun ,file ,@args)) 268 `(vc-call-backend (vc-backend ,file) ',fun ,file ,@args))
262
263 269
264 (defsubst vc-parse-buffer (pattern i) 270 (defsubst vc-parse-buffer (pattern i)
265 "Find PATTERN in the current buffer and return its Ith submatch." 271 "Find PATTERN in the current buffer and return its Ith submatch."
266 (goto-char (point-min)) 272 (goto-char (point-min))
267 (if (re-search-forward pattern nil t) 273 (if (re-search-forward pattern nil t)
454 unchanged)))) 460 unchanged))))
455 461
456 (defun vc-default-workfile-unchanged-p (backend file) 462 (defun vc-default-workfile-unchanged-p (backend file)
457 "Check if FILE is unchanged by diffing against the master version. 463 "Check if FILE is unchanged by diffing against the master version.
458 Return non-nil if FILE is unchanged." 464 Return non-nil if FILE is unchanged."
459 ;; If rev1 is nil, `diff' uses the current workfile version. 465 (zerop (condition-case err
460 (zerop (vc-call diff file))) 466 ;; If the implementation supports it, let the output
467 ;; go to *vc*, not *vc-diff*, since this is an internal call.
468 (vc-call diff file nil nil "*vc*")
469 (wrong-number-of-arguments
470 ;; If this error came from the above call to vc-BACKEND-diff,
471 ;; try again without the optional buffer argument (for
472 ;; backward compatibility). Otherwise, resignal.
473 (if (or (not (eq (cadr err)
474 (indirect-function
475 (vc-find-backend-function (vc-backend file)
476 'diff))))
477 (not (eq (caddr err) 5)))
478 (signal wrong-number-of-arguments err)
479 (vc-call diff file))))))
461 480
462 (defun vc-workfile-version (file) 481 (defun vc-workfile-version (file)
463 "Return the version level of the current workfile FILE. 482 "Return the version level of the current workfile FILE.
464 If FILE is not registered, this function always returns nil." 483 If FILE is not registered, this function always returns nil."
465 (or (vc-file-getprop file 'vc-workfile-version) 484 (or (vc-file-getprop file 'vc-workfile-version)
581 600
582 (defun vc-make-version-backup (file) 601 (defun vc-make-version-backup (file)
583 "Make a backup copy of FILE, which is assumed in sync with the repository. 602 "Make a backup copy of FILE, which is assumed in sync with the repository.
584 Before doing that, check if there are any old backups and get rid of them." 603 Before doing that, check if there are any old backups and get rid of them."
585 (unless (and (fboundp 'msdos-long-file-names) 604 (unless (and (fboundp 'msdos-long-file-names)
586 (not (with-no-warnings msdos-long-file-names))) 605 (not (with-no-warnings (msdos-long-file-names))))
587 (vc-delete-automatic-version-backups file) 606 (vc-delete-automatic-version-backups file)
588 (copy-file file (vc-version-backup-file-name file) 607 (copy-file file (vc-version-backup-file-name file)
589 nil 'keep-date))) 608 nil 'keep-date)))
590 609
591 (defun vc-before-save () 610 (defun vc-before-save ()
690 ;; I'm not going to work out the details right now. -- rms. 709 ;; I'm not going to work out the details right now. -- rms.
691 (set-buffer (find-file-noselect truename))) 710 (set-buffer (find-file-noselect truename)))
692 (set-buffer true-buffer) 711 (set-buffer true-buffer)
693 (kill-buffer this-buffer)))) 712 (kill-buffer this-buffer))))
694 713
714 (defun vc-default-find-file-hook (backend)
715 nil)
716
695 (defun vc-find-file-hook () 717 (defun vc-find-file-hook ()
696 "Function for `find-file-hook' activating VC mode if appropriate." 718 "Function for `find-file-hook' activating VC mode if appropriate."
697 ;; Recompute whether file is version controlled, 719 ;; Recompute whether file is version controlled,
698 ;; if user has killed the buffer and revisited. 720 ;; if user has killed the buffer and revisited.
699 (if vc-mode 721 (if vc-mode
705 ;; Compute the state and put it in the modeline. 727 ;; Compute the state and put it in the modeline.
706 (vc-mode-line buffer-file-name) 728 (vc-mode-line buffer-file-name)
707 (unless vc-make-backup-files 729 (unless vc-make-backup-files
708 ;; Use this variable, not make-backup-files, 730 ;; Use this variable, not make-backup-files,
709 ;; because this is for things that depend on the file name. 731 ;; because this is for things that depend on the file name.
710 (set (make-local-variable 'backup-inhibited) t))) 732 (set (make-local-variable 'backup-inhibited) t))
733 ;; Let the backend setup any buffer-local things he needs.
734 (vc-call-backend (vc-backend buffer-file-name) 'find-file-hook))
711 ((let* ((link (file-symlink-p buffer-file-name)) 735 ((let* ((link (file-symlink-p buffer-file-name))
712 (link-type (and link (vc-backend (file-chase-links link))))) 736 (link-type (and link (vc-backend (file-chase-links link)))))
713 (cond ((not link-type) nil) ;Nothing to do. 737 (cond ((not link-type) nil) ;Nothing to do.
714 ((eq vc-follow-symlinks nil) 738 ((eq vc-follow-symlinks nil)
715 (message 739 (message
744 Returns t if checkout was successful, nil otherwise. 768 Returns t if checkout was successful, nil otherwise.
745 Used in `find-file-not-found-functions'." 769 Used in `find-file-not-found-functions'."
746 ;; When a file does not exist, ignore cached info about it 770 ;; When a file does not exist, ignore cached info about it
747 ;; from a previous visit. 771 ;; from a previous visit.
748 (vc-file-clearprops buffer-file-name) 772 (vc-file-clearprops buffer-file-name)
749 (if (and (vc-backend buffer-file-name) 773 (let ((backend (vc-backend buffer-file-name)))
750 (yes-or-no-p 774 (if backend (vc-call-backend backend 'find-file-not-found-hook))))
751 (format "File %s was lost; check out from version control? " 775
752 (file-name-nondirectory buffer-file-name)))) 776 (defun vc-default-find-file-not-found-hook (backend)
753 (save-excursion 777 (if (yes-or-no-p
754 (require 'vc) 778 (format "File %s was lost; check out from version control? "
755 (setq default-directory (file-name-directory buffer-file-name)) 779 (file-name-nondirectory buffer-file-name)))
756 (not (vc-error-occurred (vc-checkout buffer-file-name)))))) 780 (save-excursion
781 (require 'vc)
782 (setq default-directory (file-name-directory buffer-file-name))
783 (not (vc-error-occurred (vc-checkout buffer-file-name))))))
757 784
758 (add-hook 'find-file-not-found-functions 'vc-file-not-found-hook) 785 (add-hook 'find-file-not-found-functions 'vc-file-not-found-hook)
759 786
760 (defun vc-kill-buffer-hook () 787 (defun vc-kill-buffer-hook ()
761 "Discard VC info about a file when we kill its buffer." 788 "Discard VC info about a file when we kill its buffer."
840 ;;(put 'vc-next-action 'menu-enable 'vc-mode) 867 ;;(put 'vc-next-action 'menu-enable 'vc-mode)
841 ;;(put 'vc-register 'menu-enable '(and buffer-file-name (not vc-mode))) 868 ;;(put 'vc-register 'menu-enable '(and buffer-file-name (not vc-mode)))
842 869
843 (provide 'vc-hooks) 870 (provide 'vc-hooks)
844 871
872 ;;; arch-tag: 2e5a6fa7-1d30-48e2-8bd0-e3d335f04f32
845 ;;; vc-hooks.el ends here 873 ;;; vc-hooks.el ends here