4384 |
(defun tramp-completion-mode (file) |
(defun tramp-completion-mode (file) |
4385 |
"Checks whether method / user name / host name completion is active." |
"Checks whether method / user name / host name completion is active." |
4386 |
(cond |
(cond |
4387 |
|
(tramp-completion-mode t) |
4388 |
((not tramp-unified-filenames) t) |
((not tramp-unified-filenames) t) |
4389 |
((string-match "^/.*:.*:$" file) nil) |
((string-match "^/.*:.*:$" file) nil) |
4390 |
((string-match |
((string-match |
4435 |
(substring |
(substring |
4436 |
file (length (tramp-completion-handle-file-name-directory file)))) |
file (length (tramp-completion-handle-file-name-directory file)))) |
4437 |
|
|
4438 |
|
(defvar tramp-completion-mode nil |
4439 |
|
"If non-nil, we are in file name completion mode.") |
4440 |
|
|
4441 |
;; Method, host name and user name completion. |
;; Method, host name and user name completion. |
4442 |
;; `tramp-completion-dissect-file-name' returns a list of |
;; `tramp-completion-dissect-file-name' returns a list of |
4443 |
;; tramp-file-name structures. For all of them we return possible completions. |
;; tramp-file-name structures. For all of them we return possible completions. |
4444 |
(defun tramp-completion-handle-file-name-all-completions (filename directory) |
(defun tramp-completion-handle-file-name-all-completions (filename directory) |
4445 |
"Like `file-name-all-completions' for partial tramp files." |
"Like `file-name-all-completions' for partial tramp files." |
4446 |
|
|
4447 |
(let* |
(unwind-protect |
4448 |
((fullname (concat directory filename)) |
;; We need to reset `tramp-completion-mode'. |
4449 |
;; local files |
(progn |
4450 |
(result |
(setq tramp-completion-mode t) |
4451 |
(if (tramp-completion-mode fullname) |
(let* |
4452 |
(tramp-run-real-handler |
((fullname (concat directory filename)) |
4453 |
'file-name-all-completions (list filename directory)) |
;; possible completion structures |
4454 |
(tramp-completion-run-real-handler |
(v (tramp-completion-dissect-file-name fullname)) |
4455 |
'file-name-all-completions (list filename directory)))) |
result result1) |
4456 |
;; possible completion structures |
|
4457 |
(v (tramp-completion-dissect-file-name fullname))) |
(while v |
4458 |
|
(let* ((car (car v)) |
4459 |
(while v |
(multi-method (tramp-file-name-multi-method car)) |
4460 |
(let* ((car (car v)) |
(method (tramp-file-name-method car)) |
4461 |
(multi-method (tramp-file-name-multi-method car)) |
(user (tramp-file-name-user car)) |
4462 |
(method (tramp-file-name-method car)) |
(host (tramp-file-name-host car)) |
4463 |
(user (tramp-file-name-user car)) |
(localname (tramp-file-name-localname car)) |
4464 |
(host (tramp-file-name-host car)) |
(m (tramp-find-method multi-method method user host)) |
4465 |
(localname (tramp-file-name-localname car)) |
(tramp-current-user user) ; see `tramp-parse-passwd' |
4466 |
(m (tramp-find-method multi-method method user host)) |
all-user-hosts) |
4467 |
(tramp-current-user user) ; see `tramp-parse-passwd' |
|
4468 |
all-user-hosts) |
(unless (or multi-method ;; Not handled (yet). |
4469 |
|
localname) ;; Nothing to complete |
4470 |
(unless (or multi-method ;; Not handled (yet). |
|
4471 |
localname) ;; Nothing to complete |
(if (or user host) |
4472 |
|
|
4473 |
(if (or user host) |
;; Method dependent user / host combinations |
4474 |
|
(progn |
4475 |
;; Method dependent user / host combinations |
(mapcar |
4476 |
(progn |
(lambda (x) |
4477 |
(mapcar |
(setq all-user-hosts |
4478 |
(lambda (x) |
(append all-user-hosts |
4479 |
(setq all-user-hosts |
(funcall (nth 0 x) (nth 1 x))))) |
4480 |
(append all-user-hosts |
(tramp-get-completion-function m)) |
4481 |
(funcall (nth 0 x) (nth 1 x))))) |
|
4482 |
(tramp-get-completion-function m)) |
(setq result (append result |
4483 |
|
(mapcar |
4484 |
(setq result (append result |
(lambda (x) |
4485 |
(mapcar |
(tramp-get-completion-user-host |
4486 |
(lambda (x) |
method user host (nth 0 x) (nth 1 x))) |
4487 |
(tramp-get-completion-user-host |
(delq nil all-user-hosts))))) |
4488 |
method user host (nth 0 x) (nth 1 x))) |
|
4489 |
(delq nil all-user-hosts))))) |
;; Possible methods |
4490 |
|
(setq result |
4491 |
;; Possible methods |
(append result (tramp-get-completion-methods m))))) |
4492 |
(setq result |
|
4493 |
(append result (tramp-get-completion-methods m))))) |
(setq v (cdr v)))) |
4494 |
|
|
4495 |
(setq v (delq car v)))) |
;; unify list, remove nil elements |
4496 |
|
(while result |
4497 |
;;; unify list, remove nil elements |
(let ((car (car result))) |
4498 |
(let (result1) |
(when car (add-to-list 'result1 car)) |
4499 |
(while result |
(setq result (cdr result)))) |
4500 |
(let ((car (car result))) |
|
4501 |
(when car (add-to-list 'result1 car)) |
;; Complete local parts |
4502 |
(setq result (delq car result)))) |
(append |
4503 |
|
result1 |
4504 |
result1))) |
(condition-case nil |
4505 |
|
(if result1 |
4506 |
|
;; "/ssh:" does not need to be expanded as hostname. |
4507 |
|
(tramp-run-real-handler |
4508 |
|
'file-name-all-completions (list filename directory)) |
4509 |
|
;; No method/user/host found to be expanded. |
4510 |
|
(tramp-completion-run-real-handler |
4511 |
|
'file-name-all-completions (list filename directory))) |
4512 |
|
(error nil))))) |
4513 |
|
;; unwindform |
4514 |
|
(setq tramp-completion-mode nil))) |
4515 |
|
|
4516 |
;; Method, host name and user name completion for a file. |
;; Method, host name and user name completion for a file. |
4517 |
(defun tramp-completion-handle-file-name-completion (filename directory) |
(defun tramp-completion-handle-file-name-completion (filename directory) |