Function: tramp-handle-file-name-completion

tramp-handle-file-name-completion is a byte-compiled function defined in tramp.el.gz.

Signature

(tramp-handle-file-name-completion FILENAME DIRECTORY &optional PREDICATE)

Documentation

Like file-name-completion for Tramp files.

Source Code

;; Defined in /usr/src/emacs/lisp/net/tramp.el.gz
(defun tramp-handle-file-name-completion
  (filename directory &optional predicate)
  "Like `file-name-completion' for Tramp files."
  (let (hits-ignored-extensions fnac)
    (setq fnac (file-name-all-completions filename directory))
    ;; "." and ".." are never interesting as completions, and are
    ;; actually in the way in a directory with only one file.  See
    ;; file_name_completion() in dired.c.
    (when (and (consp fnac)
	       (tramp-compat-length= (delete "./" (delete "../" fnac)) 1))
      (setq fnac (delete "./" (delete "../" fnac))))
    (or
     (try-completion
      filename fnac
      (lambda (x)
	(when (funcall (or predicate #'identity) (expand-file-name x directory))
	  (not
	   (and
	    completion-ignored-extensions
	    (string-match-p
	     (rx (regexp (regexp-opt completion-ignored-extensions)) eos) x)
	    ;; We remember the hit.
	    (push x hits-ignored-extensions))))))
     ;; No match.  So we try again for ignored files.
     (try-completion filename hits-ignored-extensions))))