;;;###autoload
(defconst tramp-completion-file-name-handler-alist
- '((file-name-all-completions . tramp-completion-handle-file-name-all-completions)
+ '((expand-file-name . tramp-completion-handle-expand-file-name)
+ (file-name-all-completions
+ . tramp-completion-handle-file-name-all-completions)
(file-name-completion . tramp-completion-handle-file-name-completion))
"Alist of completion handler functions.
Used for file names matching `tramp-file-name-regexp'. Operations
(let ((fn (assoc operation tramp-completion-file-name-handler-alist)))
(if (and
;; When `tramp-mode' is not enabled, we don't do anything.
- fn tramp-mode
+ fn tramp-mode (tramp-completion-mode-p)
;; For other syntaxes than `sep', the regexp matches many common
;; situations where the user doesn't actually want to use Tramp.
;; So to avoid autoloading Tramp after typing just "/s", we
;;; File name handler functions for completion mode:
+;;;###autoload
(defvar tramp-completion-mode nil
"If non-nil, external packages signal that they are in file name completion.
;; Tramp file name syntax. Maybe another variable should be introduced
;; overwriting this check in such cases. Or we change Tramp file name
;; syntax in order to avoid ambiguities.
-;;;###tramp-autoload
-(defun tramp-completion-mode-p ()
+;;;###autoload
+(progn (defun tramp-completion-mode-p ()
"Check, whether method / user name / host name completion is active."
(or
;; Signal from outside. `non-essential' has been introduced in Emacs 24.
(equal last-input-event ?\t)
(and (not (event-modifiers last-input-event))
(or (equal last-input-event ?\?)
- (equal last-input-event ?\ )))))))
+ (equal last-input-event ?\ ))))))))
(defun tramp-connectable-p (filename)
"Check, whether it is possible to connect the remote host w/o side-effects.
(p (tramp-get-connection-process v)))
(and p (processp p) (memq (process-status p) '(run open))))))))
+;;;###autoload
+(defun tramp-completion-handle-expand-file-name
+ (name &optional dir)
+ "Like `expand-file-name' for Tramp files."
+ (if (tramp-completion-mode-p)
+ (progn
+ ;; If DIR is not given, use `default-directory' or "/".
+ (setq dir (or dir default-directory "/"))
+ ;; Unless NAME is absolute, concat DIR and NAME.
+ (unless (file-name-absolute-p name)
+ (setq name (concat (file-name-as-directory dir) name)))
+ ;; Return NAME.
+ name)
+
+ (tramp-completion-run-real-handler
+ 'expand-file-name (list name dir))))
+
;; Method, host name and user name completion.
;; `tramp-completion-dissect-file-name' returns a list of
;; tramp-file-name structures. For all of them we return possible completions.
;; `file-name-as-directory' would be sufficient except localname is
;; the empty string.
(let ((v (tramp-dissect-file-name file t)))
- ;; Run the command on the localname portion only.
+ ;; Run the command on the localname portion only unless we are in
+ ;; completion mode.
(tramp-make-tramp-file-name
(tramp-file-name-method v)
(tramp-file-name-user v)
(tramp-file-name-host v)
- (tramp-run-real-handler
- 'file-name-as-directory (list (or (tramp-file-name-localname v) "")))
+ (if (and (tramp-completion-mode-p)
+ (zerop (length (tramp-file-name-localname v))))
+ ""
+ (tramp-run-real-handler
+ 'file-name-as-directory (list (or (tramp-file-name-localname v) ""))))
(tramp-file-name-hop v))))
(defun tramp-handle-file-name-completion
(defun tramp-time-diff (t1 t2)
"Return the difference between the two times, in seconds.
T1 and T2 are time values (as returned by `current-time' for example)."
- (float-time (subtract-time t1 t2)))
+ (float-time (time-subtract t1 t2)))
;; Currently (as of Emacs 20.5), the function `shell-quote-argument'
;; does not deal well with newline characters. Newline is replaced by