diff options
| author | Michael Albinus | 2008-04-28 19:07:26 +0000 |
|---|---|---|
| committer | Michael Albinus | 2008-04-28 19:07:26 +0000 |
| commit | 2e27119583f1117187014ab1409f6cd2c1eae97e (patch) | |
| tree | e7056354e80a0b9b95c731590884073fb815fd3f | |
| parent | fb4a622af4f461c101c5d7a78481f58f7cbdae74 (diff) | |
| download | emacs-2e27119583f1117187014ab1409f6cd2c1eae97e.tar.gz emacs-2e27119583f1117187014ab1409f6cd2c1eae97e.zip | |
* net/tramp.el (tramp-mode): New defcustom.
(tramp-file-name-handler, tramp-completion-file-name-handler): Use
it.
(tramp-replace-environment-variables): Handle "$$".
| -rw-r--r-- | lisp/net/tramp.el | 69 |
1 files changed, 42 insertions, 27 deletions
diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el index 1008897d9ea..be6900766cb 100644 --- a/lisp/net/tramp.el +++ b/lisp/net/tramp.el | |||
| @@ -150,6 +150,14 @@ | |||
| 150 | :group 'files | 150 | :group 'files |
| 151 | :version "22.1") | 151 | :version "22.1") |
| 152 | 152 | ||
| 153 | ;; Maybe we need once a real Tramp mode, with key bindings etc. | ||
| 154 | ;;;###autoload | ||
| 155 | (defcustom tramp-mode t | ||
| 156 | "*Whether Tramp is enabled. | ||
| 157 | If it is set to nil, all remote file names are used literally." | ||
| 158 | :group 'tramp | ||
| 159 | :type 'boolean) | ||
| 160 | |||
| 153 | (defcustom tramp-verbose 3 | 161 | (defcustom tramp-verbose 3 |
| 154 | "*Verbosity level for Tramp. | 162 | "*Verbosity level for Tramp. |
| 155 | Any level x includes messages for all levels 1 .. x-1. The levels are | 163 | Any level x includes messages for all levels 1 .. x-1. The levels are |
| @@ -3574,12 +3582,15 @@ the result will be a local, non-Tramp, filename." | |||
| 3574 | (defun tramp-replace-environment-variables (filename) | 3582 | (defun tramp-replace-environment-variables (filename) |
| 3575 | "Replace environment variables in FILENAME. | 3583 | "Replace environment variables in FILENAME. |
| 3576 | Return the string with the replaced variables." | 3584 | Return the string with the replaced variables." |
| 3577 | (when (string-match "$\\w+" filename) | 3585 | (save-match-data |
| 3578 | (setq filename | 3586 | (let ((idx (string-match "$\\w+" filename))) |
| 3579 | (replace-match | 3587 | ;; `$' is coded as `$$'. |
| 3580 | (substitute-in-file-name (match-string 0 filename)) | 3588 | (when (and idx (or (zerop idx) (not (eq ?$ (aref filename (1- idx)))))) |
| 3581 | t nil filename))) | 3589 | (setq filename |
| 3582 | filename) | 3590 | (replace-match |
| 3591 | (substitute-in-file-name (match-string 0 filename)) | ||
| 3592 | t nil filename))) | ||
| 3593 | filename))) | ||
| 3583 | 3594 | ||
| 3584 | (defun tramp-handle-substitute-in-file-name (filename) | 3595 | (defun tramp-handle-substitute-in-file-name (filename) |
| 3585 | "Like `substitute-in-file-name' for Tramp files. | 3596 | "Like `substitute-in-file-name' for Tramp files. |
| @@ -4486,26 +4497,29 @@ ARGS are the arguments OPERATION has been called with." | |||
| 4486 | (defun tramp-file-name-handler (operation &rest args) | 4497 | (defun tramp-file-name-handler (operation &rest args) |
| 4487 | "Invoke Tramp file name handler. | 4498 | "Invoke Tramp file name handler. |
| 4488 | Falls back to normal file name handler if no Tramp file name handler exists." | 4499 | Falls back to normal file name handler if no Tramp file name handler exists." |
| 4489 | (save-match-data | 4500 | (if tramp-mode |
| 4490 | (let* ((filename | 4501 | (save-match-data |
| 4491 | (tramp-replace-environment-variables | 4502 | (let* ((filename |
| 4492 | (apply 'tramp-file-name-for-operation operation args))) | 4503 | (tramp-replace-environment-variables |
| 4493 | (completion (tramp-completion-mode-p)) | 4504 | (apply 'tramp-file-name-for-operation operation args))) |
| 4494 | (foreign (tramp-find-foreign-file-name-handler filename))) | 4505 | (completion (tramp-completion-mode-p)) |
| 4495 | (with-parsed-tramp-file-name filename nil | 4506 | (foreign (tramp-find-foreign-file-name-handler filename))) |
| 4496 | (cond | 4507 | (with-parsed-tramp-file-name filename nil |
| 4497 | ;; When we are in completion mode, some operations shouldn't be | 4508 | (cond |
| 4498 | ;; handled by backend. | 4509 | ;; When we are in completion mode, some operations |
| 4499 | ((and completion (zerop (length localname)) | 4510 | ;; shouldn't be handled by backend. |
| 4500 | (memq operation '(file-exists-p file-directory-p))) | 4511 | ((and completion (zerop (length localname)) |
| 4501 | t) | 4512 | (memq operation '(file-exists-p file-directory-p))) |
| 4502 | ((and completion (zerop (length localname)) | 4513 | t) |
| 4503 | (memq operation '(file-name-as-directory))) | 4514 | ((and completion (zerop (length localname)) |
| 4504 | filename) | 4515 | (memq operation '(file-name-as-directory))) |
| 4505 | ;; Call the backend function. | 4516 | filename) |
| 4506 | (foreign (apply foreign operation args)) | 4517 | ;; Call the backend function. |
| 4507 | ;; Nothing to do for us. | 4518 | (foreign (apply foreign operation args)) |
| 4508 | (t (tramp-run-real-handler operation args))))))) | 4519 | ;; Nothing to do for us. |
| 4520 | (t (tramp-run-real-handler operation args)))))) | ||
| 4521 | ;; When `tramp-mode' is not enabled, we don't do anything. | ||
| 4522 | (tramp-run-real-handler operation args))) | ||
| 4509 | 4523 | ||
| 4510 | ;; In Emacs, there is some concurrency due to timers. If a timer | 4524 | ;; In Emacs, there is some concurrency due to timers. If a timer |
| 4511 | ;; interrupts Tramp and wishes to use the same connection buffer as | 4525 | ;; interrupts Tramp and wishes to use the same connection buffer as |
| @@ -4559,7 +4573,8 @@ Falls back to normal file name handler if no Tramp file name handler exists." | |||
| 4559 | ;; would otherwise use backslash. | 4573 | ;; would otherwise use backslash. |
| 4560 | (let ((directory-sep-char ?/) | 4574 | (let ((directory-sep-char ?/) |
| 4561 | (fn (assoc operation tramp-completion-file-name-handler-alist))) | 4575 | (fn (assoc operation tramp-completion-file-name-handler-alist))) |
| 4562 | (if fn | 4576 | ;; When `tramp-mode' is not enabled, we don't do anything. |
| 4577 | (if (and fn tramp-mode) | ||
| 4563 | (save-match-data (apply (cdr fn) args)) | 4578 | (save-match-data (apply (cdr fn) args)) |
| 4564 | (tramp-completion-run-real-handler operation args))))) | 4579 | (tramp-completion-run-real-handler operation args))))) |
| 4565 | 4580 | ||