The displays for unambiguous matches have ` [Matched]' appended
\(whether complete or not), or ` [No matches]', if no eligible
matches exist."
- (let* ((ignored-extension-re
- (and minibuffer-completing-file-name
- icomplete-with-completion-tables
- completion-ignored-extensions
- (concat "\\(?:\\`\\.\\./\\|"
- (regexp-opt completion-ignored-extensions)
- "\\)\\'")))
- (minibuffer-completion-table candidates)
- (minibuffer-completion-predicate
- (if ignored-extension-re
- (lambda (cand)
- (and (not (string-match ignored-extension-re cand))
- (or (null predicate)
- (funcall predicate cand))))
- predicate))
+ (let* ((minibuffer-completion-table candidates)
(md (completion--field-metadata (icomplete--field-beg)))
(comps (icomplete--sorted-completions))
(open-bracket (if require-match "(" "["))
(ido-find-literal nil))
(unless filename
- (setq ido-saved-vc-hb vc-handled-backends)
- (let ((minibuffer-completing-file-name t))
- (setq filename
- (ido-read-internal item
- (or prompt "Find file: ")
- 'ido-file-history
- (and (eq method 'alt-file) buffer-file-name)
- (confirm-nonexistent-file-or-buffer)
- initial))))
+ (setq ido-saved-vc-hb vc-handled-backends
+ filename
+ (ido-read-internal item
+ (or prompt "Find file: ")
+ 'ido-file-history
+ (and (eq method 'alt-file) buffer-file-name)
+ (confirm-nonexistent-file-or-buffer)
+ initial)))
;; Choose the file name: either the text typed in, or the head
;; of the list of matches
(get this-command 'ido)) 'find-file)
nil 'ignore))
(vc-handled-backends (and (boundp 'vc-handled-backends) vc-handled-backends))
- (minibuffer-completing-file-name t)
(ido-current-directory (ido-expand-directory dir))
(ido-directory-nonreadable (not (file-readable-p ido-current-directory)))
(ido-directory-too-big (and (not ido-directory-nonreadable)
Read directory name, prompting with PROMPT and completing in directory DIR.
See `read-directory-name' for additional parameters."
(let* (filename
- (minibuffer-completing-file-name t)
(ido-context-switch-command 'ignore)
ido-saved-vc-hb
(ido-current-directory (ido-expand-directory dir))
table)
"Syntax table used when reading a file name in the minibuffer.")
+(defvar-local minibuffer-completing-file-name nil
+ "Whether the current minibuffer reads a file name.")
+
(defun minibuffer--sort-file-names-by-last-modified-time (files)
"Sort file name completion candidates FILES by last modified time."
(sort files
(initial (cons (minibuffer-maybe-quote-filename initial) 0)))))
(let ((ignore-case read-file-name-completion-ignore-case)
- (minibuffer-completing-file-name t)
(pred (or predicate 'file-exists-p))
(add-to-history nil)
(require-match (if (functionp mustmatch)
(minibuffer-with-setup-hook
(lambda ()
(setq default-directory dir)
+ (setq-local minibuffer-completing-file-name t)
;; When the first default in `minibuffer-default'
;; duplicates initial input `insdef',
;; reset `minibuffer-default' to nil.
(completion-basic--pattern
beforepoint afterpoint bounds)))
(all (completion-pcm--all-completions prefix pattern table pred)))
- (if minibuffer-completing-file-name
- (setq all (completion-pcm--filename-try-filter all)))
(completion-pcm--merge-try pattern all prefix suffix)))))
(defun completion-basic-all-completions (string table pred point)
pattern
""))
-;; We want to provide the functionality of `try', but we use `all'
-;; and then merge it. In most cases, this works perfectly, but
-;; if the completion table doesn't consider the same completions in
-;; `try' as in `all', then we have a problem. The most common such
-;; case is for filename completion where completion-ignored-extensions
-;; is only obeyed by the `try' code. We paper over the difference
-;; here. Note that it is not quite right either: if the completion
-;; table uses completion-table-in-turn, this filtering may take place
-;; too late to correctly fallback from the first to the
-;; second alternative.
-(defun completion-pcm--filename-try-filter (all)
- "Filter to adjust `all' file completion to the behavior of `try'."
- (when all
- (let ((try ())
- (re (concat "\\(?:\\`\\.\\.?/\\|"
- (regexp-opt completion-ignored-extensions)
- "\\)\\'")))
- (dolist (f all)
- (unless (string-match-p re f) (push f try)))
- (or (nreverse try) all))))
-
-
(defun completion-pcm--merge-try (pattern all prefix suffix)
(cond
((not (consp all)) all)
(defun completion-pcm-try-completion (string table pred point)
(pcase-let ((`(,pattern ,all ,prefix ,suffix)
(completion-pcm--find-all-completions
- string table pred point
- (if minibuffer-completing-file-name
- 'completion-pcm--filename-try-filter))))
+ string table pred point)))
(completion-pcm--merge-try pattern all prefix suffix)))
;;; Substring completion
(pcase-let ((`(,all ,pattern ,prefix ,suffix ,_carbounds)
(completion-substring--all-completions
string table pred point)))
- (if minibuffer-completing-file-name
- (setq all (completion-pcm--filename-try-filter all)))
(completion-pcm--merge-try pattern all prefix suffix)))
(defun completion-substring-all-completions (string table pred point)
(completion-substring--all-completions
string table pred point
#'completion-flex--make-flex-pattern)))
- (if minibuffer-completing-file-name
- (setq all (completion-pcm--filename-try-filter all)))
;; Try some "merging", meaning add as much as possible to the
;; user's pattern without losing any possible matches in `all'.
;; i.e this will augment "cfi" to "config" if all candidates
(let ((completion-ignored-extensions nil)
(completion-ignore-case completion-ignore-case)
(tramp-mode (and tramp-mode (not pcomplete-remote-file-ignore)))
- (non-essential (not (file-remote-p s)))
- (minibuffer-completing-file-name (not (file-remote-p s))))
+ (non-essential (not (file-remote-p s))))
(completion-table-with-predicate
#'comint-completion-file-name-table pred 'strict s p a))))))
:group 'minibuffer
:version "22.1"
(if file-name-shadow-mode
- ;; Enable the mode
(add-hook 'minibuffer-setup-hook 'rfn-eshadow-setup-minibuffer)
- ;; Disable the mode
(remove-hook 'minibuffer-setup-hook 'rfn-eshadow-setup-minibuffer)
;; Remove our entry from any post-command-hook variable's it's still in
(dolist (minibuf rfn-eshadow-frobbed-minibufs)
specbind (Qminibuffer_default, defalt);
specbind (Qinhibit_read_only, Qnil);
- /* If Vminibuffer_completing_file_name is `lambda' on entry, it was t
- in previous recursive minibuffer, but was not set explicitly
- to t for this invocation, so set it to nil in this minibuffer.
- Save the old value now, before we change it. */
- specbind (Qminibuffer_completing_file_name,
- Vminibuffer_completing_file_name);
- if (EQ (Vminibuffer_completing_file_name, Qlambda))
- Vminibuffer_completing_file_name = Qnil;
-
#ifdef HAVE_WINDOW_SYSTEM
if (display_hourglass_p)
cancel_hourglass ();
minibuf_prompt = Fcopy_sequence (prompt);
Vminibuffer_history_position = histpos;
Vminibuffer_history_variable = histvar;
- /* If this minibuffer is reading a file name, that doesn't mean
- recursive ones are. But we cannot set it to nil, because
- completion code still need to know the minibuffer is completing a
- file name. So use `lambda' as intermediate value meaning
- "t" in this minibuffer, but "nil" in next minibuffer. */
- if (!NILP (Vminibuffer_completing_file_name))
- Vminibuffer_completing_file_name = Qlambda;
/* If variable is unbound, make it nil. */
histval = find_symbol_value (histvar);
DEFSYM (Qminibuffer_mode, "minibuffer-mode");
DEFSYM (Qminibuffer_inactive_mode, "minibuffer-inactive-mode");
- DEFSYM (Qminibuffer_completing_file_name, "minibuffer-completing-file-name");
DEFSYM (Qselect_frame_set_input_focus, "select-frame-set-input-focus");
DEFSYM (Qadd_to_history, "add-to-history");
DEFSYM (Qpush_window_buffer_onto_prev, "push-window-buffer-onto-prev");
completion commands listed in `minibuffer-confirm-exit-commands'. */);
Vminibuffer_completion_confirm = Qnil;
- DEFVAR_LISP ("minibuffer-completing-file-name",
- Vminibuffer_completing_file_name,
- doc: /* Non-nil means completing file names. */);
- Vminibuffer_completing_file_name = Qnil;
-
DEFVAR_LISP ("minibuffer-history-variable", Vminibuffer_history_variable,
doc: /* History list symbol to add minibuffer values to.
Each string of minibuffer input, as it appears on exit from the minibuffer,
(ignore-errors (delete-file tmp-name1))
(ignore-errors (delete-file tmp-name3))))))
-(ert-deftest tramp-test26-file-name-completion ()
- "Check `file-name-completion' and `file-name-all-completions'."
- (skip-unless (tramp--test-enabled))
-
- ;; Method and host name in completion mode.
- (let ((tramp-fuse-remove-hidden-files t)
- (method (file-remote-p ert-remote-temporary-file-directory 'method))
- (host (file-remote-p ert-remote-temporary-file-directory 'host))
- (orig-syntax tramp-syntax)
- (minibuffer-completing-file-name t))
- (when (and (stringp host) (string-match tramp-host-with-port-regexp host))
- (setq host (match-string 1 host)))
-
- (unwind-protect
- (dolist (syntax (if (tramp--test-expensive-test-p)
- (tramp-syntax-values) `(,orig-syntax)))
- (tramp-change-syntax syntax)
- ;; This has cleaned up all connection data, which are used
- ;; for completion. We must refill the cache.
- (tramp-set-connection-property tramp-test-vec "property" nil)
-
- (let (;; This is needed for the `separate' syntax.
- (prefix-format (substring tramp-prefix-format 1))
- ;; This is needed for the IPv6 host name syntax.
- (ipv6-prefix
- (and (string-match-p tramp-ipv6-regexp host)
- tramp-prefix-ipv6-format))
- (ipv6-postfix
- (and (string-match-p tramp-ipv6-regexp host)
- tramp-postfix-ipv6-format)))
- ;; Complete method name.
- (unless (or (tramp-string-empty-or-nil-p method)
- (string-empty-p tramp-method-regexp))
- (should
- (member
- (concat prefix-format method tramp-postfix-method-format)
- (file-name-all-completions
- (concat prefix-format (substring method 0 1)) "/"))))
- ;; Complete host name.
- (unless (or (tramp-string-empty-or-nil-p method)
- (string-empty-p tramp-method-regexp)
- (tramp-string-empty-or-nil-p host))
- (should
- (member
- (concat
- prefix-format method tramp-postfix-method-format
- ipv6-prefix host ipv6-postfix tramp-postfix-host-format)
- (file-name-all-completions
- (concat prefix-format method tramp-postfix-method-format)
- "/"))))))
-
- ;; Cleanup.
- (tramp-change-syntax orig-syntax)))
-
- (dolist (non-essential '(nil t))
- (dolist (quoted (if (tramp--test-expensive-test-p) '(nil t) '(nil)))
- (let ((tramp-fuse-remove-hidden-files t)
- (tmp-name (tramp--test-make-temp-name nil quoted)))
- ;; Local files.
- (make-directory tmp-name)
- (should (file-directory-p tmp-name))
- (write-region "foo" nil (expand-file-name "foo" tmp-name))
- (should (file-exists-p (expand-file-name "foo" tmp-name)))
- (write-region "bar" nil (expand-file-name "bold" tmp-name))
- (should (file-exists-p (expand-file-name "bold" tmp-name)))
- (make-directory (expand-file-name "boz" tmp-name))
- (should (file-directory-p (expand-file-name "boz" tmp-name)))
- (should (equal (file-name-completion "fo" tmp-name) "foo"))
- (should (equal (file-name-completion "foo" tmp-name) t))
- (should (equal (file-name-completion "b" tmp-name) "bo"))
- (should-not (file-name-completion "a" tmp-name))
- ;; `file-name-completion' should not err out if
- ;; directory does not exist. (Bug#61890)
- ;; Ange-FTP does not support this.
- (unless (tramp--test-ange-ftp-p)
- (should-not
- (file-name-completion
- "a" (tramp-compat-file-name-concat tmp-name "fuzz"))))
- ;; Ange-FTP does not support predicates.
- (unless (tramp--test-ange-ftp-p)
- (should
- (equal
- (file-name-completion "b" tmp-name #'file-directory-p)
- "boz/")))
- (should
- (equal (file-name-all-completions "fo" tmp-name) '("foo")))
- (should
- (equal
- (sort (file-name-all-completions "b" tmp-name) #'string-lessp)
- '("bold" "boz/")))
- (should-not (file-name-all-completions "a" tmp-name))
- ;; Cleanup.
- (ignore-errors (delete-directory tmp-name 'recursive))))))
-
-(tramp--test-deftest-with-perl tramp-test26-file-name-completion)
-
-(tramp--test-deftest-with-ls tramp-test26-file-name-completion)
-
(ert-deftest tramp-test27-load ()
"Check `load'."
(skip-unless (tramp--test-enabled))