comparison lisp/vc-hooks.el @ 50879:9cd7a1a60ba0

Consistently use buffer-file-name variable rather than function. (vc-handled-backends): Add SVN and MCVS. (vc-mode-line): Call vc-backend only once.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Wed, 07 May 2003 17:20:29 +0000
parents c1b2182d8ca1
children c4ef9b4c327f
comparison
equal deleted inserted replaced
50878:c7bf6b539118 50879:9cd7a1a60ba0
3 ;; Copyright (C) 1992,93,94,95,96,98,99,2000 Free Software Foundation, Inc. 3 ;; Copyright (C) 1992,93,94,95,96,98,99,2000 Free Software Foundation, Inc.
4 4
5 ;; Author: FSF (see vc.el for full credits) 5 ;; Author: FSF (see vc.el for full credits)
6 ;; Maintainer: Andre Spiegel <spiegel@gnu.org> 6 ;; Maintainer: Andre Spiegel <spiegel@gnu.org>
7 7
8 ;; $Id: vc-hooks.el,v 1.146 2002/10/17 15:46:06 lektu Exp $ 8 ;; $Id: vc-hooks.el,v 1.147 2003/02/05 23:14:06 lektu Exp $
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
43 (defvar vc-master-templates ()) 43 (defvar vc-master-templates ())
44 (make-obsolete-variable 'vc-master-templates 'vc-BACKEND-master-templates) 44 (make-obsolete-variable 'vc-master-templates 'vc-BACKEND-master-templates)
45 (defvar vc-header-alist ()) 45 (defvar vc-header-alist ())
46 (make-obsolete-variable 'vc-header-alist 'vc-BACKEND-header) 46 (make-obsolete-variable 'vc-header-alist 'vc-BACKEND-header)
47 47
48 (defcustom vc-handled-backends '(RCS CVS SCCS) 48 (defcustom vc-handled-backends '(RCS CVS SVN MCVS SCCS)
49 "*List of version control backends for which VC will be used. 49 "*List of version control backends for which VC will be used.
50 Entries in this list will be tried in order to determine whether a 50 Entries in this list will be tried in order to determine whether a
51 file is under that sort of version control. 51 file is under that sort of version control.
52 Removing an entry from the list prevents VC from being activated 52 Removing an entry from the list prevents VC from being activated
53 when visiting a file managed by that backend. 53 when visiting a file managed by that backend.
279 nil)))) 279 nil))))
280 280
281 (defun vc-backend (file) 281 (defun vc-backend (file)
282 "Return the version control type of FILE, nil if it is not registered." 282 "Return the version control type of FILE, nil if it is not registered."
283 ;; `file' can be nil in several places (typically due to the use of 283 ;; `file' can be nil in several places (typically due to the use of
284 ;; code like (vc-backend (buffer-file-name))). 284 ;; code like (vc-backend buffer-file-name)).
285 (when (stringp file) 285 (when (stringp file)
286 (let ((property (vc-file-getprop file 'vc-backend))) 286 (let ((property (vc-file-getprop file 'vc-backend)))
287 ;; Note that internally, Emacs remembers unregistered 287 ;; Note that internally, Emacs remembers unregistered
288 ;; files by setting the property to `none'. 288 ;; files by setting the property to `none'.
289 (cond ((eq property 'none) nil) 289 (cond ((eq property 'none) nil)
485 If you bind this function to \\[toggle-read-only], then Emacs checks files 485 If you bind this function to \\[toggle-read-only], then Emacs checks files
486 in or out whenever you toggle the read-only flag." 486 in or out whenever you toggle the read-only flag."
487 (interactive "P") 487 (interactive "P")
488 (if (or (and (boundp 'vc-dired-mode) vc-dired-mode) 488 (if (or (and (boundp 'vc-dired-mode) vc-dired-mode)
489 ;; use boundp because vc.el might not be loaded 489 ;; use boundp because vc.el might not be loaded
490 (vc-backend (buffer-file-name))) 490 (vc-backend buffer-file-name))
491 (vc-next-action verbose) 491 (vc-next-action verbose)
492 (toggle-read-only))) 492 (toggle-read-only)))
493 493
494 (defun vc-default-make-version-backups-p (backend file) 494 (defun vc-default-make-version-backups-p (backend file)
495 "Return non-nil if unmodified versions should be backed up locally. 495 "Return non-nil if unmodified versions should be backed up locally.
531 (defun vc-before-save () 531 (defun vc-before-save ()
532 "Function to be called by `basic-save-buffer' (in files.el)." 532 "Function to be called by `basic-save-buffer' (in files.el)."
533 ;; If the file on disk is still in sync with the repository, 533 ;; If the file on disk is still in sync with the repository,
534 ;; and version backups should be made, copy the file to 534 ;; and version backups should be made, copy the file to
535 ;; another name. This enables local diffs and local reverting. 535 ;; another name. This enables local diffs and local reverting.
536 (let ((file (buffer-file-name))) 536 (let ((file buffer-file-name))
537 (and (vc-backend file) 537 (and (vc-backend file)
538 (vc-up-to-date-p file) 538 (vc-up-to-date-p file)
539 (eq (vc-checkout-model file) 'implicit) 539 (eq (vc-checkout-model file) 'implicit)
540 (vc-call make-version-backups-p file) 540 (vc-call make-version-backups-p file)
541 (vc-make-version-backup file)))) 541 (vc-make-version-backup file))))
543 (defun vc-after-save () 543 (defun vc-after-save ()
544 "Function to be called by `basic-save-buffer' (in files.el)." 544 "Function to be called by `basic-save-buffer' (in files.el)."
545 ;; If the file in the current buffer is under version control, 545 ;; If the file in the current buffer is under version control,
546 ;; up-to-date, and locking is not used for the file, set 546 ;; up-to-date, and locking is not used for the file, set
547 ;; the state to 'edited and redisplay the mode line. 547 ;; the state to 'edited and redisplay the mode line.
548 (let ((file (buffer-file-name))) 548 (let ((file buffer-file-name))
549 (and (vc-backend file) 549 (and (vc-backend file)
550 (or (and (equal (vc-file-getprop file 'vc-checkout-time) 550 (or (and (equal (vc-file-getprop file 'vc-checkout-time)
551 (nth 5 (file-attributes file))) 551 (nth 5 (file-attributes file)))
552 ;; File has been saved in the same second in which 552 ;; File has been saved in the same second in which
553 ;; it was checked out. Clear the checkout-time 553 ;; it was checked out. Clear the checkout-time
566 (defun vc-mode-line (file) 566 (defun vc-mode-line (file)
567 "Set `vc-mode' to display type of version control for FILE. 567 "Set `vc-mode' to display type of version control for FILE.
568 The value is set in the current buffer, which should be the buffer 568 The value is set in the current buffer, which should be the buffer
569 visiting FILE." 569 visiting FILE."
570 (interactive (list buffer-file-name)) 570 (interactive (list buffer-file-name))
571 (if (not (vc-backend file)) 571 (let ((backend (vc-backend file)))
572 (setq vc-mode nil) 572 (if (not backend)
573 (setq vc-mode (concat " " (if vc-display-status 573 (setq vc-mode nil)
574 (vc-call mode-line-string file) 574 (setq vc-mode (concat " " (if vc-display-status
575 (symbol-name (vc-backend file))))) 575 (vc-call mode-line-string file)
576 ;; If the file is locked by some other user, make 576 (symbol-name backend))))
577 ;; the buffer read-only. Like this, even root 577 ;; If the file is locked by some other user, make
578 ;; cannot modify a file that someone else has locked. 578 ;; the buffer read-only. Like this, even root
579 (and (equal file (buffer-file-name)) 579 ;; cannot modify a file that someone else has locked.
580 (stringp (vc-state file)) 580 (and (equal file buffer-file-name)
581 (setq buffer-read-only t)) 581 (stringp (vc-state file))
582 ;; If the user is root, and the file is not owner-writable, 582 (setq buffer-read-only t))
583 ;; then pretend that we can't write it 583 ;; If the user is root, and the file is not owner-writable,
584 ;; even though we can (because root can write anything). 584 ;; then pretend that we can't write it
585 ;; This way, even root cannot modify a file that isn't locked. 585 ;; even though we can (because root can write anything).
586 (and (equal file (buffer-file-name)) 586 ;; This way, even root cannot modify a file that isn't locked.
587 (not buffer-read-only) 587 (and (equal file buffer-file-name)
588 (zerop (user-real-uid)) 588 (not buffer-read-only)
589 (zerop (logand (file-modes (buffer-file-name)) 128)) 589 (zerop (user-real-uid))
590 (setq buffer-read-only t))) 590 (zerop (logand (file-modes buffer-file-name) 128))
591 (force-mode-line-update) 591 (setq buffer-read-only t)))
592 (vc-backend file)) 592 (force-mode-line-update)
593 backend))
593 594
594 (defun vc-default-mode-line-string (backend file) 595 (defun vc-default-mode-line-string (backend file)
595 "Return string for placement in modeline by `vc-mode-line' for FILE. 596 "Return string for placement in modeline by `vc-mode-line' for FILE.
596 Format: 597 Format:
597 598
696 697
697 (add-hook 'find-file-not-found-hooks 'vc-file-not-found-hook) 698 (add-hook 'find-file-not-found-hooks 'vc-file-not-found-hook)
698 699
699 (defun vc-kill-buffer-hook () 700 (defun vc-kill-buffer-hook ()
700 "Discard VC info about a file when we kill its buffer." 701 "Discard VC info about a file when we kill its buffer."
701 (if (buffer-file-name) 702 (if buffer-file-name
702 (vc-file-clearprops (buffer-file-name)))) 703 (vc-file-clearprops buffer-file-name)))
703 704
704 (add-hook 'kill-buffer-hook 'vc-kill-buffer-hook) 705 (add-hook 'kill-buffer-hook 'vc-kill-buffer-hook)
705 706
706 ;; Now arrange for (autoloaded) bindings of the main package. 707 ;; Now arrange for (autoloaded) bindings of the main package.
707 ;; Bindings for this have to go in the global map, as we'll often 708 ;; Bindings for this have to go in the global map, as we'll often