aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Albinus2016-05-07 22:52:30 +0200
committerMichael Albinus2016-05-07 22:52:30 +0200
commit97776f295d652aff97be91431ad53db5618ad2a2 (patch)
tree8d06804b042c05c25b80be874753dfdf9a1686c2
parent2ac39b069919bf71e614202aa96194c86934988c (diff)
downloademacs-97776f295d652aff97be91431ad53db5618ad2a2.tar.gz
emacs-97776f295d652aff97be91431ad53db5618ad2a2.zip
Continue to fix Bug#10085
* lisp/net/tramp.el (tramp-completion-file-name-handler-alist) <expand-file-name>: Add handler. (tramp-completion-handle-expand-file-name): New defun. (tramp-handle-file-name-as-directory): Handle completion mode case. * test/lisp/net/tramp-tests.el (tramp-test06-directory-file-name): Fix test. (tramp-test24-file-name-completion): Extend test.
-rw-r--r--lisp/net/tramp.el31
-rw-r--r--test/lisp/net/tramp-tests.el67
2 files changed, 75 insertions, 23 deletions
diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el
index 3da60e93b78..87ccae12ca2 100644
--- a/lisp/net/tramp.el
+++ b/lisp/net/tramp.el
@@ -1010,7 +1010,9 @@ means to use always cached values for the directory contents."
1010 1010
1011;;;###autoload 1011;;;###autoload
1012(defconst tramp-completion-file-name-handler-alist 1012(defconst tramp-completion-file-name-handler-alist
1013 '((file-name-all-completions . tramp-completion-handle-file-name-all-completions) 1013 '((expand-file-name . tramp-completion-handle-expand-file-name)
1014 (file-name-all-completions
1015 . tramp-completion-handle-file-name-all-completions)
1014 (file-name-completion . tramp-completion-handle-file-name-completion)) 1016 (file-name-completion . tramp-completion-handle-file-name-completion))
1015 "Alist of completion handler functions. 1017 "Alist of completion handler functions.
1016Used for file names matching `tramp-file-name-regexp'. Operations 1018Used for file names matching `tramp-file-name-regexp'. Operations
@@ -2261,6 +2263,23 @@ not in completion mode."
2261 (p (tramp-get-connection-process v))) 2263 (p (tramp-get-connection-process v)))
2262 (and p (processp p) (memq (process-status p) '(run open)))))))) 2264 (and p (processp p) (memq (process-status p) '(run open))))))))
2263 2265
2266;;;###autoload
2267(defun tramp-completion-handle-expand-file-name
2268 (name &optional dir)
2269 "Like `expand-file-name' for Tramp files."
2270 (if (tramp-completion-mode-p)
2271 (progn
2272 ;; If DIR is not given, use `default-directory' or "/".
2273 (setq dir (or dir default-directory "/"))
2274 ;; Unless NAME is absolute, concat DIR and NAME.
2275 (unless (file-name-absolute-p name)
2276 (setq name (concat (file-name-as-directory dir) name)))
2277 ;; Return NAME.
2278 name)
2279
2280 (tramp-completion-run-real-handler
2281 'expand-file-name (list name dir))))
2282
2264;; Method, host name and user name completion. 2283;; Method, host name and user name completion.
2265;; `tramp-completion-dissect-file-name' returns a list of 2284;; `tramp-completion-dissect-file-name' returns a list of
2266;; tramp-file-name structures. For all of them we return possible completions. 2285;; tramp-file-name structures. For all of them we return possible completions.
@@ -2817,13 +2836,17 @@ User is always nil."
2817 ;; `file-name-as-directory' would be sufficient except localname is 2836 ;; `file-name-as-directory' would be sufficient except localname is
2818 ;; the empty string. 2837 ;; the empty string.
2819 (let ((v (tramp-dissect-file-name file t))) 2838 (let ((v (tramp-dissect-file-name file t)))
2820 ;; Run the command on the localname portion only. 2839 ;; Run the command on the localname portion only unless we are in
2840 ;; completion mode.
2821 (tramp-make-tramp-file-name 2841 (tramp-make-tramp-file-name
2822 (tramp-file-name-method v) 2842 (tramp-file-name-method v)
2823 (tramp-file-name-user v) 2843 (tramp-file-name-user v)
2824 (tramp-file-name-host v) 2844 (tramp-file-name-host v)
2825 (tramp-run-real-handler 2845 (if (and (tramp-completion-mode-p)
2826 'file-name-as-directory (list (or (tramp-file-name-localname v) ""))) 2846 (zerop (length (tramp-file-name-localname v))))
2847 ""
2848 (tramp-run-real-handler
2849 'file-name-as-directory (list (or (tramp-file-name-localname v) ""))))
2827 (tramp-file-name-hop v)))) 2850 (tramp-file-name-hop v))))
2828 2851
2829(defun tramp-handle-file-name-completion 2852(defun tramp-handle-file-name-completion
diff --git a/test/lisp/net/tramp-tests.el b/test/lisp/net/tramp-tests.el
index efb19e9f506..a85eed0302a 100644
--- a/test/lisp/net/tramp-tests.el
+++ b/test/lisp/net/tramp-tests.el
@@ -649,7 +649,9 @@ This checks also `file-name-as-directory', `file-name-directory',
649 (setq file (format "/%s:" file)) 649 (setq file (format "/%s:" file))
650 (should (string-equal (directory-file-name file) file)) 650 (should (string-equal (directory-file-name file) file))
651 (should 651 (should
652 (string-equal (file-name-as-directory file) (concat file "./"))) 652 (string-equal
653 (file-name-as-directory file)
654 (if (tramp-completion-mode-p) file (concat file "./"))))
653 (should (string-equal (file-name-directory file) file)) 655 (should (string-equal (file-name-directory file) file))
654 (should (string-equal (file-name-nondirectory file) ""))))))) 656 (should (string-equal (file-name-nondirectory file) "")))))))
655 657
@@ -1367,25 +1369,52 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'."
1367 "Check `file-name-completion' and `file-name-all-completions'." 1369 "Check `file-name-completion' and `file-name-all-completions'."
1368 (skip-unless (tramp--test-enabled)) 1370 (skip-unless (tramp--test-enabled))
1369 1371
1370 (let ((tmp-name (tramp--test-make-temp-name))) 1372 (dolist (n-e '(nil t))
1371 (unwind-protect 1373 (let ((non-essential n-e)
1372 (progn 1374 (tmp-name (tramp--test-make-temp-name))
1373 (make-directory tmp-name) 1375 (method (file-remote-p tramp-test-temporary-file-directory 'method))
1374 (should (file-directory-p tmp-name)) 1376 (host (file-remote-p tramp-test-temporary-file-directory 'host)))
1375 (write-region "foo" nil (expand-file-name "foo" tmp-name)) 1377
1376 (write-region "bar" nil (expand-file-name "bold" tmp-name)) 1378 (unwind-protect
1377 (make-directory (expand-file-name "boz" tmp-name)) 1379 (progn
1378 (should (equal (file-name-completion "fo" tmp-name) "foo")) 1380 ;; Method and host name in completion mode.
1379 (should (equal (file-name-completion "b" tmp-name) "bo")) 1381 (when (tramp-completion-mode-p)
1380 (should 1382 (unless (zerop (length method))
1381 (equal (file-name-completion "b" tmp-name 'file-directory-p) "boz/")) 1383 (should
1382 (should (equal (file-name-all-completions "fo" tmp-name) '("foo"))) 1384 (member
1383 (should 1385 (format "%s:" method)
1384 (equal (sort (file-name-all-completions "b" tmp-name) 'string-lessp) 1386 (file-name-all-completions (substring method 0 1) "/"))))
1385 '("bold" "boz/")))) 1387 (unless (zerop (length host))
1388 (should
1389 (member
1390 (format "%s:" host)
1391 (file-name-all-completions (substring host 0 1) "/"))))
1392 (unless (or (zerop (length method)) (zerop (length host)))
1393 (should
1394 (member
1395 (format "%s:" host)
1396 (file-name-all-completions
1397 (substring host 0 1) (format "/%s:" method))))))
1398
1399 ;; Local files.
1400 (make-directory tmp-name)
1401 (should (file-directory-p tmp-name))
1402 (write-region "foo" nil (expand-file-name "foo" tmp-name))
1403 (write-region "bar" nil (expand-file-name "bold" tmp-name))
1404 (make-directory (expand-file-name "boz" tmp-name))
1405 (should (equal (file-name-completion "fo" tmp-name) "foo"))
1406 (should (equal (file-name-completion "b" tmp-name) "bo"))
1407 (should
1408 (equal
1409 (file-name-completion "b" tmp-name 'file-directory-p) "boz/"))
1410 (should (equal (file-name-all-completions "fo" tmp-name) '("foo")))
1411 (should
1412 (equal
1413 (sort (file-name-all-completions "b" tmp-name) 'string-lessp)
1414 '("bold" "boz/"))))
1386 1415
1387 ;; Cleanup. 1416 ;; Cleanup.
1388 (ignore-errors (delete-directory tmp-name 'recursive))))) 1417 (ignore-errors (delete-directory tmp-name 'recursive))))))
1389 1418
1390(ert-deftest tramp-test25-load () 1419(ert-deftest tramp-test25-load ()
1391 "Check `load'." 1420 "Check `load'."