aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Albinus2019-09-12 16:38:48 +0200
committerMichael Albinus2019-09-12 16:38:48 +0200
commit5e8d477d63496ada8eb2c42d23735df0cf05ee2d (patch)
treeb19e6b55d6f371644e24fc3be57ebaaa1b1795f1
parent997415504c37b4dc1f486b9d9925c4e16ade015c (diff)
downloademacs-5e8d477d63496ada8eb2c42d23735df0cf05ee2d.tar.gz
emacs-5e8d477d63496ada8eb2c42d23735df0cf05ee2d.zip
Optimize host name completion in Tramp
* lisp/net/tramp-adb.el (tramp-adb-maybe-open-connection): * lisp/net/tramp-gvfs.el (tramp-gvfs-maybe-open-connection): * lisp/net/tramp-rclone.el (tramp-rclone-maybe-open-connection): * lisp/net/tramp-sh.el (tramp-maybe-open-connection): * lisp/net/tramp-smb.el (tramp-smb-maybe-open-connection): * lisp/net/tramp-sudoedit.el (tramp-sudoedit-maybe-open-connection): Throw `non-essential' at the beginning of the function. * lisp/net/tramp.el (tramp-handle-file-exists-p): * lisp/net/tramp-sh.el (tramp-sh-handle-file-exists-p): * lisp/net/tramp-sudoedit.el (tramp-sudoedit-handle-file-exists-p): Run only when host is connectable. This is due to host name completion, which shall be optimized. * lisp/net/tramp-smb.el (tramp-smb-do-file-attributes-with-stat) (tramp-smb-get-file-entries): Access connection buffer only after sending the command. * lisp/net/tramp.el (tramp-get-buffer, tramp-get-connection-buffer): New argument DONT-CREATE. (tramp-message): Use it. (tramp-get-mutex): Check, whether host is connectable. (tramp-file-name-handler): Set thread only when host is connectable. (tramp-connectable-p): Allow also VEC as argument. (tramp-completion-handle-file-name-completion): Do not expand directory.
-rw-r--r--lisp/net/tramp-adb.el12
-rw-r--r--lisp/net/tramp-gvfs.el4
-rw-r--r--lisp/net/tramp-rclone.el13
-rw-r--r--lisp/net/tramp-sh.el41
-rw-r--r--lisp/net/tramp-smb.el73
-rw-r--r--lisp/net/tramp-sudoedit.el25
-rw-r--r--lisp/net/tramp.el72
7 files changed, 120 insertions, 120 deletions
diff --git a/lisp/net/tramp-adb.el b/lisp/net/tramp-adb.el
index df4778c9c96..982522bdaf4 100644
--- a/lisp/net/tramp-adb.el
+++ b/lisp/net/tramp-adb.el
@@ -1191,6 +1191,10 @@ FMT and ARGS are passed to `error'."
1191 "Maybe open a connection VEC. 1191 "Maybe open a connection VEC.
1192Does not do anything if a connection is already open, but re-opens the 1192Does not do anything if a connection is already open, but re-opens the
1193connection if a previous connection has died for some reason." 1193connection if a previous connection has died for some reason."
1194 ;; During completion, don't reopen a new connection.
1195 (unless (tramp-connectable-p vec)
1196 (throw 'non-essential 'non-essential))
1197
1194 (let* ((buf (tramp-get-connection-buffer vec)) 1198 (let* ((buf (tramp-get-connection-buffer vec))
1195 (p (get-buffer-process buf)) 1199 (p (get-buffer-process buf))
1196 (host (tramp-file-name-host vec)) 1200 (host (tramp-file-name-host vec))
@@ -1204,14 +1208,6 @@ connection if a previous connection has died for some reason."
1204 (tramp-error vec 'file-error "Cannot switch to user `%s'" user)) 1208 (tramp-error vec 'file-error "Cannot switch to user `%s'" user))
1205 1209
1206 (unless (process-live-p p) 1210 (unless (process-live-p p)
1207 ;; During completion, don't reopen a new connection. We check
1208 ;; this for the process related to `tramp-buffer-name';
1209 ;; otherwise `start-file-process' wouldn't run ever when
1210 ;; `non-essential' is non-nil.
1211 (when (and (tramp-completion-mode-p)
1212 (null (get-process (tramp-buffer-name vec))))
1213 (throw 'non-essential 'non-essential))
1214
1215 (save-match-data 1211 (save-match-data
1216 (when (and p (processp p)) (delete-process p)) 1212 (when (and p (processp p)) (delete-process p))
1217 (if (zerop (length device)) 1213 (if (zerop (length device))
diff --git a/lisp/net/tramp-gvfs.el b/lisp/net/tramp-gvfs.el
index b9b6b4b6d18..1036865e4ec 100644
--- a/lisp/net/tramp-gvfs.el
+++ b/lisp/net/tramp-gvfs.el
@@ -1787,6 +1787,10 @@ This is relevant for GNOME Online Accounts."
1787 "Maybe open a connection VEC. 1787 "Maybe open a connection VEC.
1788Does not do anything if a connection is already open, but re-opens the 1788Does not do anything if a connection is already open, but re-opens the
1789connection if a previous connection has died for some reason." 1789connection if a previous connection has died for some reason."
1790 ;; During completion, don't reopen a new connection.
1791 (unless (tramp-connectable-p vec)
1792 (throw 'non-essential 'non-essential))
1793
1790 ;; We set the file name, in case there are incoming D-Bus signals or 1794 ;; We set the file name, in case there are incoming D-Bus signals or
1791 ;; D-Bus errors. 1795 ;; D-Bus errors.
1792 (setq tramp-gvfs-dbus-event-vector vec) 1796 (setq tramp-gvfs-dbus-event-vector vec)
diff --git a/lisp/net/tramp-rclone.el b/lisp/net/tramp-rclone.el
index 866e7791bf8..1f0c7eadbc5 100644
--- a/lisp/net/tramp-rclone.el
+++ b/lisp/net/tramp-rclone.el
@@ -520,19 +520,14 @@ file names."
520 "Maybe open a connection VEC. 520 "Maybe open a connection VEC.
521Does not do anything if a connection is already open, but re-opens the 521Does not do anything if a connection is already open, but re-opens the
522connection if a previous connection has died for some reason." 522connection if a previous connection has died for some reason."
523 ;; During completion, don't reopen a new connection.
524 (unless (tramp-connectable-p vec)
525 (throw 'non-essential 'non-essential))
526
523 (let ((host (tramp-file-name-host vec))) 527 (let ((host (tramp-file-name-host vec)))
524 (when (rassoc `(,host) (tramp-rclone-parse-device-names nil)) 528 (when (rassoc `(,host) (tramp-rclone-parse-device-names nil))
525 (if (zerop (length host)) 529 (if (zerop (length host))
526 (tramp-error vec 'file-error "Storage %s not connected" host)) 530 (tramp-error vec 'file-error "Storage %s not connected" host))
527
528 ;; During completion, don't reopen a new connection. We check
529 ;; this for the process related to `tramp-buffer-name';
530 ;; otherwise `start-file-process' wouldn't run ever when
531 ;; `non-essential' is non-nil.
532 (when (and (tramp-completion-mode-p)
533 (null (get-process (tramp-buffer-name vec))))
534 (throw 'non-essential 'non-essential))
535
536 ;; We need a process bound to the connection buffer. Therefore, 531 ;; We need a process bound to the connection buffer. Therefore,
537 ;; we create a dummy process. Maybe there is a better solution? 532 ;; we create a dummy process. Maybe there is a better solution?
538 (unless (get-buffer-process (tramp-get-connection-buffer vec)) 533 (unless (get-buffer-process (tramp-get-connection-buffer vec))
diff --git a/lisp/net/tramp-sh.el b/lisp/net/tramp-sh.el
index bcfac78ee65..4bc37f01694 100644
--- a/lisp/net/tramp-sh.el
+++ b/lisp/net/tramp-sh.el
@@ -1198,18 +1198,22 @@ component is used as the target of the symlink."
1198 1198
1199(defun tramp-sh-handle-file-exists-p (filename) 1199(defun tramp-sh-handle-file-exists-p (filename)
1200 "Like `file-exists-p' for Tramp files." 1200 "Like `file-exists-p' for Tramp files."
1201 (with-parsed-tramp-file-name filename nil 1201 ;; `file-exists-p' is used as predicate in file name completion.
1202 (with-tramp-file-property v localname "file-exists-p" 1202 ;; We don't want to run it when `non-essential' is t, or there is
1203 (or (not (null (tramp-get-file-property 1203 ;; no connection process yet.
1204 v localname "file-attributes-integer" nil))) 1204 (when (tramp-connectable-p filename)
1205 (not (null (tramp-get-file-property 1205 (with-parsed-tramp-file-name filename nil
1206 v localname "file-attributes-string" nil))) 1206 (with-tramp-file-property v localname "file-exists-p"
1207 (tramp-send-command-and-check 1207 (or (not (null (tramp-get-file-property
1208 v 1208 v localname "file-attributes-integer" nil)))
1209 (format 1209 (not (null (tramp-get-file-property
1210 "%s %s" 1210 v localname "file-attributes-string" nil)))
1211 (tramp-get-file-exists-command v) 1211 (tramp-send-command-and-check
1212 (tramp-shell-quote-argument localname))))))) 1212 v
1213 (format
1214 "%s %s"
1215 (tramp-get-file-exists-command v)
1216 (tramp-shell-quote-argument localname))))))))
1213 1217
1214(defun tramp-sh-handle-file-attributes (filename &optional id-format) 1218(defun tramp-sh-handle-file-attributes (filename &optional id-format)
1215 "Like `file-attributes' for Tramp files." 1219 "Like `file-attributes' for Tramp files."
@@ -4762,6 +4766,10 @@ If there is just some editing, retry it after 5 seconds."
4762 "Maybe open a connection VEC. 4766 "Maybe open a connection VEC.
4763Does not do anything if a connection is already open, but re-opens the 4767Does not do anything if a connection is already open, but re-opens the
4764connection if a previous connection has died for some reason." 4768connection if a previous connection has died for some reason."
4769 ;; During completion, don't reopen a new connection.
4770 (unless (tramp-connectable-p vec)
4771 (throw 'non-essential 'non-essential))
4772
4765 (let ((p (tramp-get-connection-process vec)) 4773 (let ((p (tramp-get-connection-process vec))
4766 (process-name (tramp-get-connection-property vec "process-name" nil)) 4774 (process-name (tramp-get-connection-property vec "process-name" nil))
4767 (process-environment (copy-sequence process-environment)) 4775 (process-environment (copy-sequence process-environment))
@@ -4806,15 +4814,6 @@ connection if a previous connection has died for some reason."
4806 ;; New connection must be opened. 4814 ;; New connection must be opened.
4807 (condition-case err 4815 (condition-case err
4808 (unless (process-live-p p) 4816 (unless (process-live-p p)
4809
4810 ;; During completion, don't reopen a new connection. We
4811 ;; check this for the process related to
4812 ;; `tramp-buffer-name'; otherwise `start-file-process'
4813 ;; wouldn't run ever when `non-essential' is non-nil.
4814 (when (and (tramp-completion-mode-p)
4815 (null (get-process (tramp-buffer-name vec))))
4816 (throw 'non-essential 'non-essential))
4817
4818 (with-tramp-progress-reporter 4817 (with-tramp-progress-reporter
4819 vec 3 4818 vec 3
4820 (if (zerop (length (tramp-file-name-user vec))) 4819 (if (zerop (length (tramp-file-name-user vec)))
diff --git a/lisp/net/tramp-smb.el b/lisp/net/tramp-smb.el
index 5df26a1e33e..b008e6b25eb 100644
--- a/lisp/net/tramp-smb.el
+++ b/lisp/net/tramp-smb.el
@@ -832,12 +832,12 @@ PRESERVE-UID-GID and PRESERVE-EXTENDED-ATTRIBUTES are completely ignored."
832 "Implement `file-attributes' for Tramp files using stat command." 832 "Implement `file-attributes' for Tramp files using stat command."
833 (tramp-message 833 (tramp-message
834 vec 5 "file attributes with stat: %s" (tramp-file-name-localname vec)) 834 vec 5 "file attributes with stat: %s" (tramp-file-name-localname vec))
835 (with-current-buffer (tramp-get-connection-buffer vec) 835 (let* (size id link uid gid atime mtime ctime mode inode)
836 (let* (size id link uid gid atime mtime ctime mode inode) 836 (when (tramp-smb-send-command
837 (when (tramp-smb-send-command 837 vec (format "stat \"%s\"" (tramp-smb-get-localname vec)))
838 vec (format "stat \"%s\"" (tramp-smb-get-localname vec)))
839 838
840 ;; Loop the listing. 839 ;; Loop the listing.
840 (with-current-buffer (tramp-get-connection-buffer vec)
841 (goto-char (point-min)) 841 (goto-char (point-min))
842 (unless (re-search-forward tramp-smb-errors nil t) 842 (unless (re-search-forward tramp-smb-errors nil t)
843 (while (not (eobp)) 843 (while (not (eobp))
@@ -1628,40 +1628,40 @@ Result is a list of (LOCALNAME MODE SIZE MONTH DAY TIME YEAR)."
1628 (with-parsed-tramp-file-name (file-name-as-directory directory) nil 1628 (with-parsed-tramp-file-name (file-name-as-directory directory) nil
1629 (setq localname (or localname "/")) 1629 (setq localname (or localname "/"))
1630 (with-tramp-file-property v localname "file-entries" 1630 (with-tramp-file-property v localname "file-entries"
1631 (with-current-buffer (tramp-get-connection-buffer v) 1631 (let* ((share (tramp-smb-get-share v))
1632 (let* ((share (tramp-smb-get-share v)) 1632 (cache (tramp-get-connection-property v "share-cache" nil))
1633 (cache (tramp-get-connection-property v "share-cache" nil)) 1633 res entry)
1634 res entry) 1634
1635 1635 (if (and (not share) cache)
1636 (if (and (not share) cache) 1636 ;; Return cached shares.
1637 ;; Return cached shares. 1637 (setq res cache)
1638 (setq res cache) 1638
1639 1639 ;; Read entries.
1640 ;; Read entries. 1640 (if share
1641 (if share 1641 (tramp-smb-send-command
1642 (tramp-smb-send-command 1642 v (format "dir \"%s*\"" (tramp-smb-get-localname v)))
1643 v (format "dir \"%s*\"" (tramp-smb-get-localname v))) 1643 ;; `tramp-smb-maybe-open-connection' lists also the share names.
1644 ;; `tramp-smb-maybe-open-connection' lists also the share names. 1644 (tramp-smb-maybe-open-connection v))
1645 (tramp-smb-maybe-open-connection v)) 1645
1646 1646 ;; Loop the listing.
1647 ;; Loop the listing. 1647 (with-current-buffer (tramp-get-connection-buffer v)
1648 (goto-char (point-min)) 1648 (goto-char (point-min))
1649 (if (re-search-forward tramp-smb-errors nil t) 1649 (if (re-search-forward tramp-smb-errors nil t)
1650 (tramp-error v 'file-error "%s `%s'" (match-string 0) directory) 1650 (tramp-error v 'file-error "%s `%s'" (match-string 0) directory)
1651 (while (not (eobp)) 1651 (while (not (eobp))
1652 (setq entry (tramp-smb-read-file-entry share)) 1652 (setq entry (tramp-smb-read-file-entry share))
1653 (forward-line) 1653 (forward-line)
1654 (when entry (push entry res)))) 1654 (when entry (push entry res)))))
1655 1655
1656 ;; Cache share entries. 1656 ;; Cache share entries.
1657 (unless share 1657 (unless share
1658 (tramp-set-connection-property v "share-cache" res))) 1658 (tramp-set-connection-property v "share-cache" res)))
1659 1659
1660 ;; Add directory itself. 1660 ;; Add directory itself.
1661 (push '("" "drwxrwxrwx" 0 (0 0)) res) 1661 (push '("" "drwxrwxrwx" 0 (0 0)) res)
1662 1662
1663 ;; Return entries. 1663 ;; Return entries.
1664 (delq nil res)))))) 1664 (delq nil res)))))
1665 1665
1666;; Return either a share name (if SHARE is nil), or a file name. 1666;; Return either a share name (if SHARE is nil), or a file name.
1667;; 1667;;
@@ -1855,6 +1855,10 @@ Does not do anything if a connection is already open, but re-opens the
1855connection if a previous connection has died for some reason. 1855connection if a previous connection has died for some reason.
1856If ARGUMENT is non-nil, use it as argument for 1856If ARGUMENT is non-nil, use it as argument for
1857`tramp-smb-winexe-program', and suppress any checks." 1857`tramp-smb-winexe-program', and suppress any checks."
1858 ;; During completion, don't reopen a new connection.
1859 (unless (tramp-connectable-p vec)
1860 (throw 'non-essential 'non-essential))
1861
1858 (let* ((share (tramp-smb-get-share vec)) 1862 (let* ((share (tramp-smb-get-share vec))
1859 (buf (tramp-get-connection-buffer vec)) 1863 (buf (tramp-get-connection-buffer vec))
1860 (p (get-buffer-process buf))) 1864 (p (get-buffer-process buf)))
@@ -1909,15 +1913,6 @@ If ARGUMENT is non-nil, use it as argument for
1909 (string-equal 1913 (string-equal
1910 share 1914 share
1911 (tramp-get-connection-property p "smb-share" "")))) 1915 (tramp-get-connection-property p "smb-share" ""))))
1912
1913 ;; During completion, don't reopen a new connection. We
1914 ;; check this for the process related to
1915 ;; `tramp-buffer-name'; otherwise `start-file-process'
1916 ;; wouldn't run ever when `non-essential' is non-nil.
1917 (when (and (tramp-completion-mode-p)
1918 (null (get-process (tramp-buffer-name vec))))
1919 (throw 'non-essential 'non-essential))
1920
1921 (save-match-data 1916 (save-match-data
1922 ;; There might be unread output from checking for share names. 1917 ;; There might be unread output from checking for share names.
1923 (when buf (with-current-buffer buf (erase-buffer))) 1918 (when buf (with-current-buffer buf (erase-buffer)))
diff --git a/lisp/net/tramp-sudoedit.el b/lisp/net/tramp-sudoedit.el
index 80ce8f78747..bfc9b3bdc3a 100644
--- a/lisp/net/tramp-sudoedit.el
+++ b/lisp/net/tramp-sudoedit.el
@@ -424,10 +424,14 @@ the result will be a local, non-Tramp, file name."
424 424
425(defun tramp-sudoedit-handle-file-exists-p (filename) 425(defun tramp-sudoedit-handle-file-exists-p (filename)
426 "Like `file-exists-p' for Tramp files." 426 "Like `file-exists-p' for Tramp files."
427 (with-parsed-tramp-file-name filename nil 427 ;; `file-exists-p' is used as predicate in file name completion.
428 (with-tramp-file-property v localname "file-exists-p" 428 ;; We don't want to run it when `non-essential' is t, or there is
429 (tramp-sudoedit-send-command 429 ;; no connection process yet.
430 v "test" "-e" (tramp-compat-file-name-unquote localname))))) 430 (when (tramp-connectable-p filename)
431 (with-parsed-tramp-file-name filename nil
432 (with-tramp-file-property v localname "file-exists-p"
433 (tramp-sudoedit-send-command
434 v "test" "-e" (tramp-compat-file-name-unquote localname))))))
431 435
432(defun tramp-sudoedit-handle-file-name-all-completions (filename directory) 436(defun tramp-sudoedit-handle-file-name-all-completions (filename directory)
433 "Like `file-name-all-completions' for Tramp files." 437 "Like `file-name-all-completions' for Tramp files."
@@ -760,18 +764,13 @@ Remove unneeded output."
760 "Maybe open a connection VEC. 764 "Maybe open a connection VEC.
761Does not do anything if a connection is already open, but re-opens the 765Does not do anything if a connection is already open, but re-opens the
762connection if a previous connection has died for some reason." 766connection if a previous connection has died for some reason."
767 ;; During completion, don't reopen a new connection.
768 (unless (tramp-connectable-p vec)
769 (throw 'non-essential 'non-essential))
770
763 ;; We need a process bound to the connection buffer. Therefore, we 771 ;; We need a process bound to the connection buffer. Therefore, we
764 ;; create a dummy process. Maybe there is a better solution? 772 ;; create a dummy process. Maybe there is a better solution?
765 (unless (tramp-get-connection-process vec) 773 (unless (tramp-get-connection-process vec)
766
767 ;; During completion, don't reopen a new connection. We check
768 ;; this for the process related to `tramp-buffer-name'; otherwise
769 ;; `start-file-process' wouldn't run ever when `non-essential' is
770 ;; non-nil.
771 (when (and (tramp-completion-mode-p)
772 (null (get-process (tramp-buffer-name vec))))
773 (throw 'non-essential 'non-essential))
774
775 (let ((p (make-network-process 774 (let ((p (make-network-process
776 :name (tramp-get-connection-name vec) 775 :name (tramp-get-connection-name vec)
777 :buffer (tramp-get-connection-buffer vec) 776 :buffer (tramp-get-connection-buffer vec)
diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el
index ed0f1def181..8903d38d20f 100644
--- a/lisp/net/tramp.el
+++ b/lisp/net/tramp.el
@@ -1566,25 +1566,27 @@ necessary only. This function will be used in file name completion."
1566 tramp-postfix-host-format)) 1566 tramp-postfix-host-format))
1567 (when localname localname))) 1567 (when localname localname)))
1568 1568
1569(defun tramp-get-buffer (vec) 1569(defun tramp-get-buffer (vec &optional dont-create)
1570 "Get the connection buffer to be used for VEC." 1570 "Get the connection buffer to be used for VEC."
1571 (or (get-buffer (tramp-buffer-name vec)) 1571 (or (get-buffer (tramp-buffer-name vec))
1572 (with-current-buffer (get-buffer-create (tramp-buffer-name vec)) 1572 (unless dont-create
1573 ;; We use the existence of connection property "process-buffer" 1573 (with-current-buffer (get-buffer-create (tramp-buffer-name vec))
1574 ;; as indication, whether a connection is active. 1574 ;; We use the existence of connection property "process-buffer"
1575 (tramp-set-connection-property 1575 ;; as indication, whether a connection is active.
1576 vec "process-buffer" 1576 (tramp-set-connection-property
1577 (tramp-get-connection-property vec "process-buffer" nil)) 1577 vec "process-buffer"
1578 (setq buffer-undo-list t 1578 (tramp-get-connection-property vec "process-buffer" nil))
1579 default-directory (tramp-make-tramp-file-name vec 'noloc 'nohop)) 1579 (setq buffer-undo-list t
1580 (current-buffer)))) 1580 default-directory
1581 1581 (tramp-make-tramp-file-name vec 'noloc 'nohop))
1582(defun tramp-get-connection-buffer (vec) 1582 (current-buffer)))))
1583
1584(defun tramp-get-connection-buffer (vec &optional dont-create)
1583 "Get the connection buffer to be used for VEC. 1585 "Get the connection buffer to be used for VEC.
1584In case a second asynchronous communication has been started, it is different 1586In case a second asynchronous communication has been started, it is different
1585from `tramp-get-buffer'." 1587from `tramp-get-buffer'."
1586 (or (tramp-get-connection-property vec "process-buffer" nil) 1588 (or (tramp-get-connection-property vec "process-buffer" nil)
1587 (tramp-get-buffer vec))) 1589 (tramp-get-buffer vec dont-create)))
1588 1590
1589(defun tramp-get-connection-name (vec) 1591(defun tramp-get-connection-name (vec)
1590 "Get the connection name to be used for VEC. 1592 "Get the connection name to be used for VEC.
@@ -1770,14 +1772,15 @@ applicable)."
1770 ;; Log only when there is a minimum level. 1772 ;; Log only when there is a minimum level.
1771 (when (>= tramp-verbose 4) 1773 (when (>= tramp-verbose 4)
1772 (let ((tramp-verbose 0)) 1774 (let ((tramp-verbose 0))
1773 ;; Append connection buffer for error messages. 1775 ;; Append connection buffer for error messages, if exists.
1774 (when (= level 1) 1776 (when (= level 1)
1775 (with-current-buffer 1777 (ignore-errors
1776 (if (processp vec-or-proc) 1778 (with-current-buffer
1777 (process-buffer vec-or-proc) 1779 (if (processp vec-or-proc)
1778 (tramp-get-connection-buffer vec-or-proc)) 1780 (process-buffer vec-or-proc)
1779 (setq fmt-string (concat fmt-string "\n%s") 1781 (tramp-get-connection-buffer vec-or-proc 'dont-create))
1780 arguments (append arguments (list (buffer-string)))))) 1782 (setq fmt-string (concat fmt-string "\n%s")
1783 arguments (append arguments (list (buffer-string)))))))
1781 ;; Translate proc to vec. 1784 ;; Translate proc to vec.
1782 (when (processp vec-or-proc) 1785 (when (processp vec-or-proc)
1783 (setq vec-or-proc (process-get vec-or-proc 'vector)))) 1786 (setq vec-or-proc (process-get vec-or-proc 'vector))))
@@ -2517,16 +2520,22 @@ Add operations defined in `HANDLER-alist' to `tramp-file-name-handler'."
2517 ;; This variable has been obsoleted in Emacs 26. 2520 ;; This variable has been obsoleted in Emacs 26.
2518 tramp-completion-mode)) 2521 tramp-completion-mode))
2519 2522
2520(defun tramp-connectable-p (filename) 2523(defun tramp-connectable-p (vec-or-filename)
2521 "Check, whether it is possible to connect the remote host w/o side-effects. 2524 "Check, whether it is possible to connect the remote host w/o side-effects.
2522This is true, if either the remote host is already connected, or if we are 2525This is true, if either the remote host is already connected, or if we are
2523not in completion mode." 2526not in completion mode."
2524 (let (tramp-verbose) 2527 (let (tramp-verbose
2525 (and (tramp-tramp-file-p filename) 2528 (vec
2526 (or (not (tramp-completion-mode-p)) 2529 (cond
2527 (process-live-p 2530 ((tramp-file-name-p vec-or-filename) vec-or-filename)
2528 (tramp-get-connection-process 2531 ((tramp-tramp-file-p vec-or-filename)
2529 (tramp-dissect-file-name filename))))))) 2532 (tramp-dissect-file-name vec-or-filename)))))
2533 (when vec
2534 (or ;; We check this for the process related to
2535 ;; `tramp-buffer-name'; otherwise `start-file-process'
2536 ;; wouldn't run ever when `non-essential' is non-nil.
2537 (process-live-p (get-process (tramp-buffer-name vec)))
2538 (not (tramp-completion-mode-p))))))
2530 2539
2531;; Method, host name and user name completion. 2540;; Method, host name and user name completion.
2532;; `tramp-completion-dissect-file-name' returns a list of 2541;; `tramp-completion-dissect-file-name' returns a list of
@@ -2606,8 +2615,7 @@ not in completion mode."
2606 (try-completion 2615 (try-completion
2607 filename 2616 filename
2608 (mapcar #'list (file-name-all-completions filename directory)) 2617 (mapcar #'list (file-name-all-completions filename directory))
2609 (when (and predicate 2618 (when (and predicate (tramp-connectable-p directory))
2610 (tramp-connectable-p (expand-file-name filename directory)))
2611 (lambda (x) (funcall predicate (expand-file-name (car x) directory)))))) 2619 (lambda (x) (funcall predicate (expand-file-name (car x) directory))))))
2612 2620
2613;; I misuse a little bit the `tramp-file-name' structure in order to 2621;; I misuse a little bit the `tramp-file-name' structure in order to
@@ -3096,7 +3104,11 @@ User is always nil."
3096 3104
3097(defun tramp-handle-file-exists-p (filename) 3105(defun tramp-handle-file-exists-p (filename)
3098 "Like `file-exists-p' for Tramp files." 3106 "Like `file-exists-p' for Tramp files."
3099 (not (null (file-attributes filename)))) 3107 ;; `file-exists-p' is used as predicate in file name completion.
3108 ;; We don't want to run it when `non-essential' is t, or there is
3109 ;; no connection process yet.
3110 (when (tramp-connectable-p filename)
3111 (not (null (file-attributes filename)))))
3100 3112
3101(defun tramp-handle-file-in-directory-p (filename directory) 3113(defun tramp-handle-file-in-directory-p (filename directory)
3102 "Like `file-in-directory-p' for Tramp files." 3114 "Like `file-in-directory-p' for Tramp files."