@var{predicate} is called with two arguments, the string key and the
associated value.
-In addition, to be acceptable, a completion must also match all the
-regular expressions in @code{completion-regexp-list}. (Unless
-@var{collection} is a function, in which case that function has to
-handle @code{completion-regexp-list} itself.)
-
In the first of the following examples, the string @samp{foo} is
matched by three of the alist @sc{car}s. All of the matches begin with
the characters @samp{fooba}, so that is the result. In the second
@end smallexample
@end defun
-@c Removed obsolete argument nospace.
@defun all-completions string collection &optional predicate
This function returns a list of all possible completions of
@var{string}. The arguments to this function
-@c (aside from @var{nospace})
-are the same as those of @code{try-completion}, and it
-uses @code{completion-regexp-list} in the same way that
-@code{try-completion} does.
-
-@ignore
-The optional argument @var{nospace} is obsolete. If it is
-non-@code{nil}, completions that start with a space are ignored unless
-@var{string} starts with a space.
-@end ignore
+are the same as those of @code{try-completion}.
If @var{collection} is a function, it is called with three arguments:
@var{string}, @var{predicate} and @code{t}; then @code{all-completions}
strings, this is true if @var{string} appears in the list and
@var{predicate} is satisfied.
-This function uses @code{completion-regexp-list} in the same
-way that @code{try-completion} does.
-
If @var{predicate} is non-@code{nil} and if @var{collection} contains
several strings that are equal to each other, as determined by
@code{compare-strings} according to @code{completion-ignore-case},
Completion}).
@end defvar
-@defvar completion-regexp-list
-This is a list of regular expressions. The completion functions only
-consider a completion acceptable if it matches all regular expressions
-in this list, with @code{case-fold-search} (@pxref{Searching and Case})
-bound to the value of @code{completion-ignore-case}.
-
-Do not set this variable to a non-@code{nil} value globally, as that
-is not safe and will probably cause errors in completion commands.
-This variable should be only let-bound to non-@code{nil} values around
-calls to basic completion functions: @code{try-completion},
-@code{test-completion}, and @code{all-completions}.
-@end defvar
-
@defmac lazy-completion-table var fun
This macro provides a way to initialize the variable @var{var} as a
collection for completion in a lazy way, not computing its actual
for the MODE to customize."
(interactive
(list
- (let ((completion-regexp-list '("-mode\\'"))
- (group (custom-group-of-mode major-mode)))
+ (let ((group (custom-group-of-mode major-mode)))
(if (and group (not current-prefix-arg))
major-mode
(intern
"Return the custom group corresponding to the major or minor MODE.
If no such group is found, return nil."
(or (get mode 'custom-mode-group)
- (if (or (get mode 'custom-group)
- (and (string-match "-mode\\'" (symbol-name mode))
- (get (setq mode (intern (substring (symbol-name mode)
- 0 (match-beginning 0))))
- 'custom-group)))
+ (if (and (string-match "-mode\\'" (symbol-name mode))
+ (get (setq mode (intern (substring (symbol-name mode)
+ 0 (match-beginning 0))))
+ 'custom-group))
mode)))
;;; Properties.
;; Recurse on the sorted list.
(let* ((max-lisp-eval-depth 10000)
(completion-ignore-case nil)
- (completion-regexp-list nil)
(open (cond ((stringp paren) paren) (paren "\\(")))
(re (if strings
(regexp-opt-group
(push file names)
(push file fullnames)
(push (substring file 0 (match-beginning 0)) names)))))
- ;; Switching from names to names+fullnames creates a non-monotonicity
- ;; which can cause problems with things like partial-completion.
- ;; To minimize the problem, filter out completion-regexp-list, so that
- ;; M-x load-library RET t/x.e TAB finds some files. Also remove elements
- ;; from `names' that matched `string' only when they still had
- ;; their suffix.
+ ;; Switching from names to names+fullnames creates a
+ ;; non-monotonicity which can cause problems with things like
+ ;; partial-completion. To minimize the problem, filter out
+ ;; elements from `names' that matched `string' only when they
+ ;; still had their suffix.
(setq names (all-completions string-file names))
;; Remove duplicates of the first element, so that we can easily check
;; if `names' really contains only a single element.
(when completions
(pcase-let*
((prefix
- (let ((completion-regexp-list nil))
- (try-completion "" (cons (substring ustring boundary)
- completions))))
+ (try-completion "" (cons (substring ustring boundary)
+ completions)))
(`(,qfullpos . ,qfun)
(funcall requote (+ boundary (length prefix)) string))
(qfullprefix (substring string 0 qfullpos))
(let* (;; Convert search pattern to a standard regular expression.
(regex (completion-pcm--pattern->regex pattern))
(case-fold-search completion-ignore-case)
- (completion-regexp-list (cons regex completion-regexp-list))
(compl (all-completions
(concat prefix
(if (stringp (car pattern)) (car pattern) ""))
table pred)))
- (if (not (functionp table))
- ;; The internal functions already obeyed completion-regexp-list.
- compl
- (let ((poss ()))
- (dolist (c compl)
- (when (string-match-p regex c) (push c poss)))
- (nreverse poss))))))
+ (let ((poss ()))
+ (dolist (c compl)
+ (when (string-match-p regex c) (push c poss)))
+ (nreverse poss)))))
(defvar flex-score-match-tightness 3
"Controls how the `flex' completion style scores its matches.
(remove-hook 'minibuffer-setup-hook #'completions-auto-update-setup)
(remove-hook 'minibuffer-exit-hook #'completions-auto-update-exit)))
-(provide 'minibuffer)
+(defvar completion-regexp-list nil "Unused obsolete variable.")
+(make-obsolete-variable 'completion-regexp-list nil "30.1")
+(provide 'minibuffer)
;;; minibuffer.el ends here
(tramp-skeleton-file-name-all-completions filename directory
(all-completions
filename
- (let* (completion-regexp-list
- tramp-crypt-enabled
+ (let* (tramp-crypt-enabled
(directory (file-name-as-directory directory))
(enc-dir (tramp-crypt-encrypt-file-name directory)))
(mapcar
(dolist (elt '(".." "."))
(when (string-prefix-p ,filename elt)
(setq result (cons (concat elt "/") result)))))
- (if (consp completion-regexp-list)
- ;; Discriminate over `completion-regexp-list'.
- (mapcar
- (lambda (x)
- (when (stringp x)
- (catch 'match
- (dolist (elt completion-regexp-list x)
- (unless (string-match-p elt x) (throw 'match nil))))))
- result)
- result))))))
+ result)))))
(defvar tramp--last-hop-directory nil
"Tracks the directory from which to run login programs.")
As a special case, the universal argument \\[universal-argument] forces completion of
function names in places where the default would be a keyword.
-Two prefix argument, \\[universal-argument] \\[universal-argument], prompts for a regexp by which to limit
-completion.
-
For Lisp programmers only:
When we force a keyword, optional argument MODULE can contain the module name.
When we force a method or a method keyword, CLASS can specify the class."
(idlwave-make-force-complete-where-list arg module class)
(idlwave-where)))
(what (nth 2 where-list))
- (idlwave-force-class-query (equal arg '(4)))
- (completion-regexp-list
- (if (equal arg '(16))
- (list (read-string (concat "Completion Regexp: "))))))
+ (idlwave-force-class-query (equal arg '(4))))
(if (and module (string-match "::" module))
(setq class (substring module 0 (match-beginning 0))
If PREDICATE is non-nil, call PREDICATE with each possible
completion (in absolute form) and ignore it if PREDICATE returns nil.
-This function ignores some of the possible completions as determined
-by the variables `completion-regexp-list' and
-`completion-ignored-extensions', which see. `completion-regexp-list'
-is matched against file and directory names relative to DIRECTORY. */)
+This function ignores some of the possible completions as determined by
+the variable `completion-ignored-extensions', which see. */)
(Lisp_Object file, Lisp_Object directory, Lisp_Object predicate)
{
Lisp_Object handler;
DEFUN ("file-name-all-completions", Ffile_name_all_completions,
Sfile_name_all_completions, 2, 2, 0,
doc: /* Return a list of all completions of file name FILE in directory DIRECTORY.
-These are all file names in directory DIRECTORY which begin with FILE.
-
-This function ignores some of the possible completions as determined
-by `completion-regexp-list', which see. `completion-regexp-list'
-is matched against file and directory names relative to DIRECTORY. */)
+These are all file names in directory DIRECTORY which begin with FILE. */)
(Lisp_Object file, Lisp_Object directory)
{
Lisp_Object handler;
}
}
- Lisp_Object regexps, table = (completion_ignore_case
- ? Vascii_canon_table : Qnil);
-
- /* Ignore this element if it fails to match all the regexps. */
- for (regexps = Vcompletion_regexp_list; CONSP (regexps);
- regexps = XCDR (regexps))
- if (fast_string_match_internal (XCAR (regexps), name, table) < 0)
- break;
-
- if (CONSP (regexps))
- continue;
+ Lisp_Object table = (completion_ignore_case ? Vascii_canon_table : Qnil);
/* This is a possible completion */
if (directoryp)
return unbind_to (count, result);
}
\f
-static bool
-match_regexps (Lisp_Object string, Lisp_Object regexps,
- bool ignore_case)
-{
- ptrdiff_t val;
- for (; CONSP (regexps); regexps = XCDR (regexps))
- {
- CHECK_STRING (XCAR (regexps));
-
- val = fast_string_match_internal
- (XCAR (regexps), string,
- (ignore_case ? BVAR (current_buffer, case_canon_table) : Qnil));
-
- if (val == -2)
- error ("Stack overflow in regexp matcher");
- if (val < 0)
- return false;
- }
- return true;
-}
-
DEFUN ("try-completion", Ftry_completion, Stry_completion, 2, 3, 0,
doc: /* Return longest common substring of all completions of STRING in COLLECTION.
If COLLECTION is a hash-table, PREDICATE is called with two arguments:
the string key and the associated value.
-To be acceptable, a possible completion must also match all the regexps
-in `completion-regexp-list' (unless COLLECTION is a function, in
-which case that function should itself handle `completion-regexp-list').
-
If `completion-ignore-case' is non-nil, possible completions are matched
while ignoring letter-case, but no guarantee is made about the letter-case
of the return value, except that it comes either from the user's input
completion_ignore_case ? Qt : Qnil),
EQ (Qt, tem)))
{
- /* Ignore this element if it fails to match all the regexps. */
- if (!match_regexps (eltstring, Vcompletion_regexp_list,
- completion_ignore_case))
- continue;
-
/* Ignore this element if there is a predicate
and the predicate doesn't like it. */
If COLLECTION is a hash-table, PREDICATE is called with two arguments:
the string key and the associated value.
-To be acceptable, a possible completion must also match all the regexps
-in `completion-regexp-list' (unless COLLECTION is a function, in
-which case that function should itself handle `completion-regexp-list').
-
An obsolete optional fourth argument HIDE-SPACES is still accepted for
backward compatibility. If non-nil, strings in COLLECTION that start
with a space are ignored unless STRING itself starts with a space. */)
completion_ignore_case ? Qt : Qnil),
EQ (Qt, tem)))
{
- /* Ignore this element if it fails to match all the regexps. */
- if (!match_regexps (eltstring, Vcompletion_regexp_list,
- completion_ignore_case))
- continue;
-
/* Ignore this element if there is a predicate
and the predicate doesn't like it. */
else
return call3 (collection, string, predicate, Qlambda);
- /* Reject this element if it fails to match all the regexps. */
- if (!match_regexps (string, Vcompletion_regexp_list,
- completion_ignore_case))
- return Qnil;
-
/* Finally, check the predicate. */
if (!NILP (predicate))
{
Some uses of the echo area also raise that frame (since they use it too). */);
minibuffer_auto_raise = 0;
- DEFVAR_LISP ("completion-regexp-list", Vcompletion_regexp_list,
- doc: /* List of regexps that should restrict possible completions.
-The basic completion functions only consider a completion acceptable
-if it matches all regular expressions in this list, with
-`case-fold-search' bound to the value of `completion-ignore-case'.
-See Info node `(elisp)Basic Completion', for a description of these
-functions.
-
-Do not set this variable to a non-nil value globally, as that is not
-safe and will probably cause errors in completion commands. This
-variable should be only let-bound to non-nil values around calls to
-basic completion functions like `try-completion' and `all-completions'. */);
- Vcompletion_regexp_list = Qnil;
-
DEFVAR_BOOL ("minibuffer-allow-text-properties",
minibuffer_allow_text_properties,
doc: /* Whether `read-from-minibuffer' preserves text properties. */);
;; Cleanup.
(tramp-archive-cleanup-hash))))
-(ert-deftest tramp-archive-test26-file-name-completion ()
- "Check `file-name-completion' and `file-name-all-completions'."
- :tags '(:expensive-test)
- (skip-unless tramp-archive-enabled)
-
- (let ((tmp-name tramp-archive-test-archive))
- (unwind-protect
- (progn
- ;; Local files.
- (should (equal (file-name-completion "fo" tmp-name) "foo."))
- (should (equal (file-name-completion "foo.txt" tmp-name) t))
- (should (equal (file-name-completion "b" tmp-name) "ba"))
- (should-not (file-name-completion "a" tmp-name))
- (should
- (equal
- (file-name-completion "b" tmp-name #'file-directory-p) "bar/"))
- (should
- (equal
- (sort (file-name-all-completions "fo" tmp-name) #'string-lessp)
- '("foo.hrd" "foo.lnk" "foo.txt")))
- (should
- (equal
- (sort (file-name-all-completions "b" tmp-name) #'string-lessp)
- '("bar/" "baz.tar")))
- (should-not (file-name-all-completions "a" tmp-name))
- ;; `completion-regexp-list' restricts the completion to
- ;; files which match all expressions in this list.
- (let ((completion-regexp-list
- `(,directory-files-no-dot-files-regexp "b")))
- (should
- (equal (file-name-completion "" tmp-name) "ba"))
- (should
- (equal
- (sort (file-name-all-completions "" tmp-name) #'string-lessp)
- '("bar/" "baz.tar")))))
-
- ;; Cleanup.
- (tramp-archive-cleanup-hash))))
-
(ert-deftest tramp-archive-test40-make-nearby-temp-file ()
"Check `make-nearby-temp-file' and `temporary-file-directory'."
(skip-unless tramp-archive-enabled)
(equal
(sort (file-name-all-completions "b" tmp-name) #'string-lessp)
'("bold" "boz/")))
- (should-not (file-name-all-completions "a" tmp-name))
- ;; `completion-regexp-list' restricts the completion to
- ;; files which match all expressions in this list.
- ;; Ange-FTP does not complete "".
- (unless (tramp--test-ange-ftp-p)
- (let ((completion-regexp-list
- `(,directory-files-no-dot-files-regexp "b")))
- (should
- (equal (file-name-completion "" tmp-name) "bo"))
- (should
- (equal
- (sort
- (file-name-all-completions "" tmp-name) #'string-lessp)
- '("bold" "boz/")))))
+ (should-not (file-name-all-completions "a" tmp-name))))
;; `file-name-completion' ignores file names that end in
;; any string in `completion-ignored-extensions'.
(let ((completion-ignored-extensions '(".ext")))
(should-not (try-completion "abc" +abba #'ignore))
(should-not (try-completion "abcd" +abba #'ignore))))
-(defun minibuf-tests--try-completion-regexp (xform-collection)
- (let ((abcdef (funcall xform-collection '("abc" "def")))
- (+abba (funcall xform-collection '("abc" "abba" "def"))))
- (let ((completion-regexp-list '(".")))
- (should (equal (try-completion "a" abcdef) "abc"))
- (should (equal (try-completion "a" +abba) "ab"))
- (should (equal (try-completion "abc" +abba) t))
- (should (equal (try-completion "abcd" +abba) nil)))
- (let ((completion-regexp-list '("X")))
- (should-not (try-completion "a" abcdef))
- (should-not (try-completion "a" +abba))
- (should-not (try-completion "abc" +abba))
- (should-not (try-completion "abcd" +abba)))))
-
(defun minibuf-tests--all-completions (xform-collection)
(let* ((abcdef (funcall xform-collection '("abc" "def")))
(+abba (funcall xform-collection '("abc" "abba" "def"))))
(should-not (all-completions "abc" +abba #'ignore))
(should-not (all-completions "abcd" +abba #'ignore))))
-(defun minibuf-tests--all-completions-regexp (xform-collection)
- (let ((abcdef (funcall xform-collection '("abc" "def")))
- (+abba (funcall xform-collection '("abc" "abba" "def"))))
- (let ((completion-regexp-list '(".")))
- (should (equal (all-completions "a" abcdef) '("abc")))
- (should (minibuf-tests--set-equal (all-completions "a" +abba)
- '("abc" "abba")))
- (should (equal (all-completions "abc" +abba) '("abc")))
- (should (equal (all-completions "abcd" +abba) nil)))
- (let ((completion-regexp-list '("X")))
- (should-not (all-completions "a" abcdef))
- (should-not (all-completions "a" +abba))
- (should-not (all-completions "abc" +abba))
- (should-not (all-completions "abcd" +abba)))))
-
(defun minibuf-tests--test-completion (xform-collection)
(let* ((abcdef (funcall xform-collection '("abc" "def")))
(+abba (funcall xform-collection '("abc" "abba" "def"))))
(should-not (test-completion "abba" +abba #'ignore))
(should-not (test-completion "abcd" +abba #'ignore))))
-(defun minibuf-tests--test-completion-regexp (xform-collection)
- (let ((abcdef (funcall xform-collection '("abc" "def")))
- (+abba (funcall xform-collection '("abc" "abba" "def"))))
- (let ((completion-regexp-list '(".")))
- (should (test-completion "abc" abcdef))
- (should (test-completion "def" +abba))
- (should (test-completion "abba" +abba))
- (should-not (test-completion "abcd" +abba)))
- (let ((completion-regexp-list '("X")))
- (should-not (test-completion "abc" abcdef))
- (should-not (test-completion "def" +abba))
- (should-not (test-completion "abba" +abba))
- (should-not (test-completion "abcd" +abba)))))
-
\f
;;; Tests for `try-completion'.
(ert-deftest try-completion-string-list ()