From: Eshel Yaron Date: Mon, 6 May 2024 02:41:48 +0000 (-0400) Subject: (minibuffer-completing-file-name): Simplify, move to lisp X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=5ada38bc7ccad9ba6b008ddb0bcdb96ddec20338;p=emacs.git (minibuffer-completing-file-name): Simplify, move to lisp --- diff --git a/lisp/icomplete.el b/lisp/icomplete.el index aa3c5680a7e..44bbe9772e4 100644 --- a/lisp/icomplete.el +++ b/lisp/icomplete.el @@ -941,21 +941,7 @@ If there are multiple possibilities, `icomplete-separator' separates them. 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 "(" "[")) diff --git a/lisp/ido.el b/lisp/ido.el index 6e51dc67196..8155bbc0b20 100644 --- a/lisp/ido.el +++ b/lisp/ido.el @@ -2344,15 +2344,14 @@ If cursor is not at the end of the user input, move to end of input." (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 @@ -4905,7 +4904,6 @@ See `read-file-name' for additional parameters." (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) @@ -4948,7 +4946,6 @@ See `read-file-name' for additional parameters." 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)) diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el index 17b17d68498..c07117ef07f 100644 --- a/lisp/minibuffer.el +++ b/lisp/minibuffer.el @@ -4053,6 +4053,9 @@ and `read-file-name-function'." 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 @@ -4096,7 +4099,6 @@ See `read-file-name' for the meaning of the arguments." (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) @@ -4121,6 +4123,7 @@ See `read-file-name' for the meaning of the arguments." (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. @@ -4519,8 +4522,6 @@ Return the new suffix." (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) @@ -5125,28 +5126,6 @@ the same set of elements." 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) @@ -5185,9 +5164,7 @@ the same set of elements." (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 @@ -5220,8 +5197,6 @@ that is non-nil." (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) @@ -5298,8 +5273,6 @@ which is at the core of flex logic. The extra (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 diff --git a/lisp/pcomplete.el b/lisp/pcomplete.el index a22d3d85806..9a94b2bca02 100644 --- a/lisp/pcomplete.el +++ b/lisp/pcomplete.el @@ -920,8 +920,7 @@ this is `comint-dynamic-complete-functions'." (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)))))) diff --git a/lisp/rfn-eshadow.el b/lisp/rfn-eshadow.el index 5cf483bf0b1..6b4bb1abeb3 100644 --- a/lisp/rfn-eshadow.el +++ b/lisp/rfn-eshadow.el @@ -224,9 +224,7 @@ portion dim, invisible, or otherwise less visually noticeable." :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) diff --git a/src/minibuf.c b/src/minibuf.c index 57af908b9e3..a5a0ab7ab71 100644 --- a/src/minibuf.c +++ b/src/minibuf.c @@ -591,15 +591,6 @@ read_minibuf (Lisp_Object map, Lisp_Object initial, Lisp_Object prompt, 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 (); @@ -750,13 +741,6 @@ read_minibuf (Lisp_Object map, Lisp_Object initial, Lisp_Object prompt, 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); @@ -2219,7 +2203,6 @@ syms_of_minibuf (void) 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"); @@ -2326,11 +2309,6 @@ If the value is `confirm-after-completion', the user may exit with an 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, diff --git a/test/lisp/net/tramp-tests.el b/test/lisp/net/tramp-tests.el index f580f3b57b0..a03502bb9a5 100644 --- a/test/lisp/net/tramp-tests.el +++ b/test/lisp/net/tramp-tests.el @@ -4720,104 +4720,6 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'." (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))