diff options
| author | Dan Nicolaescu | 2009-04-01 15:42:09 +0000 |
|---|---|---|
| committer | Dan Nicolaescu | 2009-04-01 15:42:09 +0000 |
| commit | 32ca5ee4f7ef217724fb3ad0836ef88959f1ba08 (patch) | |
| tree | f1852417a06cfc0a578a935527f65a19242d5eb9 | |
| parent | fd211f0b3c67e1840fe3dc0ea3904064cdbc9440 (diff) | |
| download | emacs-32ca5ee4f7ef217724fb3ad0836ef88959f1ba08.tar.gz emacs-32ca5ee4f7ef217724fb3ad0836ef88959f1ba08.zip | |
(vc-name): Avoid calling vc-backend twice.
(vc-mode-line): Accept and use an optional argument for the
backend.
(vc-find-file-hook): Use when instead of if. Avoid calling
vc-backend multiple times, pass down the value computed the first
time.
| -rw-r--r-- | lisp/ChangeLog | 9 | ||||
| -rw-r--r-- | lisp/vc-hooks.el | 161 |
2 files changed, 91 insertions, 79 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 851a1fb7c93..42aaaa40439 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,12 @@ | |||
| 1 | 2009-04-01 Dan Nicolaescu <dann@ics.uci.edu> | ||
| 2 | |||
| 3 | * vc-hooks.el (vc-name): Avoid calling vc-backend twice. | ||
| 4 | (vc-mode-line): Accept and use an optional argument for the | ||
| 5 | backend. | ||
| 6 | (vc-find-file-hook): Use when instead of if. Avoid calling | ||
| 7 | vc-backend multiple times, pass down the value computed the first | ||
| 8 | time. | ||
| 9 | |||
| 1 | 2009-03-30 Andreas Schwab <schwab@linux-m68k.org> | 10 | 2009-03-30 Andreas Schwab <schwab@linux-m68k.org> |
| 2 | 11 | ||
| 3 | * ansi-color.el (ansi-color-get-face): Use | 12 | * ansi-color.el (ansi-color-get-face): Use |
diff --git a/lisp/vc-hooks.el b/lisp/vc-hooks.el index aacb0daa1a4..f9a73b21b2e 100644 --- a/lisp/vc-hooks.el +++ b/lisp/vc-hooks.el | |||
| @@ -409,9 +409,10 @@ If the file is not registered, or the master name is not known, return nil." | |||
| 409 | (or (vc-file-getprop file 'vc-name) | 409 | (or (vc-file-getprop file 'vc-name) |
| 410 | ;; force computation of the property by calling | 410 | ;; force computation of the property by calling |
| 411 | ;; vc-BACKEND-registered explicitly | 411 | ;; vc-BACKEND-registered explicitly |
| 412 | (if (and (vc-backend file) | 412 | (let ((backend (vc-backend file))) |
| 413 | (vc-call-backend (vc-backend file) 'registered file)) | 413 | (if (and backend |
| 414 | (vc-file-getprop file 'vc-name)))) | 414 | (vc-call-backend backend 'registered file)) |
| 415 | (vc-file-getprop file 'vc-name))))) | ||
| 415 | 416 | ||
| 416 | (defun vc-checkout-model (backend files) | 417 | (defun vc-checkout-model (backend files) |
| 417 | "Indicate how FILES are checked out. | 418 | "Indicate how FILES are checked out. |
| @@ -761,47 +762,48 @@ Before doing that, check if there are any old backups and get rid of them." | |||
| 761 | (define-key map [mode-line down-mouse-1] vc-menu-entry) | 762 | (define-key map [mode-line down-mouse-1] vc-menu-entry) |
| 762 | map)) | 763 | map)) |
| 763 | 764 | ||
| 764 | (defun vc-mode-line (file) | 765 | (defun vc-mode-line (file &optional backend) |
| 765 | "Set `vc-mode' to display type of version control for FILE. | 766 | "Set `vc-mode' to display type of version control for FILE. |
| 766 | The value is set in the current buffer, which should be the buffer | 767 | The value is set in the current buffer, which should be the buffer |
| 767 | visiting FILE." | 768 | visiting FILE. |
| 769 | If BACKEND is passed use it as the VC backend when computing the result." | ||
| 768 | (interactive (list buffer-file-name)) | 770 | (interactive (list buffer-file-name)) |
| 769 | (let ((backend (vc-backend file))) | 771 | (setq backend (or backend (vc-backend file))) |
| 770 | (if (not backend) | 772 | (if (not backend) |
| 771 | (setq vc-mode nil) | 773 | (setq vc-mode nil) |
| 772 | (let* ((ml-string (vc-call-backend backend 'mode-line-string file)) | 774 | (let* ((ml-string (vc-call-backend backend 'mode-line-string file)) |
| 773 | (ml-echo (get-text-property 0 'help-echo ml-string))) | 775 | (ml-echo (get-text-property 0 'help-echo ml-string))) |
| 774 | (setq vc-mode | 776 | (setq vc-mode |
| 775 | (concat | 777 | (concat |
| 776 | " " | 778 | " " |
| 777 | (if (null vc-display-status) | 779 | (if (null vc-display-status) |
| 778 | (symbol-name backend) | 780 | (symbol-name backend) |
| 779 | (propertize | 781 | (propertize |
| 780 | ml-string | 782 | ml-string |
| 781 | 'mouse-face 'mode-line-highlight | 783 | 'mouse-face 'mode-line-highlight |
| 782 | 'help-echo | 784 | 'help-echo |
| 783 | (concat (or ml-echo | 785 | (concat (or ml-echo |
| 784 | (format "File under the %s version control system" | 786 | (format "File under the %s version control system" |
| 785 | backend)) | 787 | backend)) |
| 786 | "\nmouse-1: Version Control menu") | 788 | "\nmouse-1: Version Control menu") |
| 787 | 'local-map vc-mode-line-map))))) | 789 | 'local-map vc-mode-line-map))))) |
| 788 | ;; If the file is locked by some other user, make | 790 | ;; If the file is locked by some other user, make |
| 789 | ;; the buffer read-only. Like this, even root | 791 | ;; the buffer read-only. Like this, even root |
| 790 | ;; cannot modify a file that someone else has locked. | 792 | ;; cannot modify a file that someone else has locked. |
| 791 | (and (equal file buffer-file-name) | 793 | (and (equal file buffer-file-name) |
| 792 | (stringp (vc-state file)) | 794 | (stringp (vc-state file)) |
| 793 | (setq buffer-read-only t)) | 795 | (setq buffer-read-only t)) |
| 794 | ;; If the user is root, and the file is not owner-writable, | 796 | ;; If the user is root, and the file is not owner-writable, |
| 795 | ;; then pretend that we can't write it | 797 | ;; then pretend that we can't write it |
| 796 | ;; even though we can (because root can write anything). | 798 | ;; even though we can (because root can write anything). |
| 797 | ;; This way, even root cannot modify a file that isn't locked. | 799 | ;; This way, even root cannot modify a file that isn't locked. |
| 798 | (and (equal file buffer-file-name) | 800 | (and (equal file buffer-file-name) |
| 799 | (not buffer-read-only) | 801 | (not buffer-read-only) |
| 800 | (zerop (user-real-uid)) | 802 | (zerop (user-real-uid)) |
| 801 | (zerop (logand (file-modes buffer-file-name) 128)) | 803 | (zerop (logand (file-modes buffer-file-name) 128)) |
| 802 | (setq buffer-read-only t))) | 804 | (setq buffer-read-only t))) |
| 803 | (force-mode-line-update) | 805 | (force-mode-line-update) |
| 804 | backend)) | 806 | backend) |
| 805 | 807 | ||
| 806 | (defun vc-default-mode-line-string (backend file) | 808 | (defun vc-default-mode-line-string (backend file) |
| 807 | "Return string for placement in modeline by `vc-mode-line' for FILE. | 809 | "Return string for placement in modeline by `vc-mode-line' for FILE. |
| @@ -868,48 +870,49 @@ current, and kill the buffer that visits the link." | |||
| 868 | "Function for `find-file-hook' activating VC mode if appropriate." | 870 | "Function for `find-file-hook' activating VC mode if appropriate." |
| 869 | ;; Recompute whether file is version controlled, | 871 | ;; Recompute whether file is version controlled, |
| 870 | ;; if user has killed the buffer and revisited. | 872 | ;; if user has killed the buffer and revisited. |
| 871 | (if vc-mode | 873 | (when vc-mode |
| 872 | (setq vc-mode nil)) | 874 | (setq vc-mode nil)) |
| 873 | (when buffer-file-name | 875 | (when buffer-file-name |
| 874 | (vc-file-clearprops buffer-file-name) | 876 | (vc-file-clearprops buffer-file-name) |
| 875 | (add-hook 'mode-line-hook 'vc-mode-line nil t) | 877 | (add-hook 'mode-line-hook 'vc-mode-line nil t) |
| 876 | (cond | 878 | (let (backend) |
| 877 | ((with-demoted-errors (vc-backend buffer-file-name)) | 879 | (cond |
| 878 | ;; Compute the state and put it in the modeline. | 880 | ((setq backend (with-demoted-errors (vc-backend buffer-file-name))) |
| 879 | (vc-mode-line buffer-file-name) | 881 | ;; Compute the state and put it in the modeline. |
| 880 | (unless vc-make-backup-files | 882 | (vc-mode-line buffer-file-name backend) |
| 881 | ;; Use this variable, not make-backup-files, | 883 | (unless vc-make-backup-files |
| 882 | ;; because this is for things that depend on the file name. | 884 | ;; Use this variable, not make-backup-files, |
| 883 | (set (make-local-variable 'backup-inhibited) t)) | 885 | ;; because this is for things that depend on the file name. |
| 884 | ;; Let the backend setup any buffer-local things he needs. | 886 | (set (make-local-variable 'backup-inhibited) t)) |
| 885 | (vc-call-backend (vc-backend buffer-file-name) 'find-file-hook)) | 887 | ;; Let the backend setup any buffer-local things he needs. |
| 886 | ((let ((link-type (and (not (equal buffer-file-name buffer-file-truename)) | 888 | (vc-call-backend backend 'find-file-hook)) |
| 887 | (vc-backend buffer-file-truename)))) | 889 | ((let ((link-type (and (not (equal buffer-file-name buffer-file-truename)) |
| 888 | (cond ((not link-type) nil) ;Nothing to do. | 890 | (vc-backend buffer-file-truename)))) |
| 889 | ((eq vc-follow-symlinks nil) | 891 | (cond ((not link-type) nil) ;Nothing to do. |
| 890 | (message | 892 | ((eq vc-follow-symlinks nil) |
| 891 | "Warning: symbolic link to %s-controlled source file" link-type)) | ||
| 892 | ((or (not (eq vc-follow-symlinks 'ask)) | ||
| 893 | ;; If we already visited this file by following | ||
| 894 | ;; the link, don't ask again if we try to visit | ||
| 895 | ;; it again. GUD does that, and repeated questions | ||
| 896 | ;; are painful. | ||
| 897 | (get-file-buffer | ||
| 898 | (abbreviate-file-name | ||
| 899 | (file-chase-links buffer-file-name)))) | ||
| 900 | |||
| 901 | (vc-follow-link) | ||
| 902 | (message "Followed link to %s" buffer-file-name) | ||
| 903 | (vc-find-file-hook)) | ||
| 904 | (t | ||
| 905 | (if (yes-or-no-p (format | ||
| 906 | "Symbolic link to %s-controlled source file; follow link? " link-type)) | ||
| 907 | (progn (vc-follow-link) | ||
| 908 | (message "Followed link to %s" buffer-file-name) | ||
| 909 | (vc-find-file-hook)) | ||
| 910 | (message | 893 | (message |
| 911 | "Warning: editing through the link bypasses version control") | 894 | "Warning: symbolic link to %s-controlled source file" link-type)) |
| 912 | )))))))) | 895 | ((or (not (eq vc-follow-symlinks 'ask)) |
| 896 | ;; If we already visited this file by following | ||
| 897 | ;; the link, don't ask again if we try to visit | ||
| 898 | ;; it again. GUD does that, and repeated questions | ||
| 899 | ;; are painful. | ||
| 900 | (get-file-buffer | ||
| 901 | (abbreviate-file-name | ||
| 902 | (file-chase-links buffer-file-name)))) | ||
| 903 | |||
| 904 | (vc-follow-link) | ||
| 905 | (message "Followed link to %s" buffer-file-name) | ||
| 906 | (vc-find-file-hook)) | ||
| 907 | (t | ||
| 908 | (if (yes-or-no-p (format | ||
| 909 | "Symbolic link to %s-controlled source file; follow link? " link-type)) | ||
| 910 | (progn (vc-follow-link) | ||
| 911 | (message "Followed link to %s" buffer-file-name) | ||
| 912 | (vc-find-file-hook)) | ||
| 913 | (message | ||
| 914 | "Warning: editing through the link bypasses version control") | ||
| 915 | ))))))))) | ||
| 913 | 916 | ||
| 914 | (add-hook 'find-file-hook 'vc-find-file-hook) | 917 | (add-hook 'find-file-hook 'vc-find-file-hook) |
| 915 | 918 | ||