From: Eshel Yaron Date: Sat, 2 Mar 2024 10:53:15 +0000 (+0100) Subject: Deprecate 'completion-regexp-list' X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=364c3a6cf19ff64ea125100d90f0a08931580910;p=emacs.git Deprecate 'completion-regexp-list' This variable doesn't provide any distinct functionality, because the completion predicate supports regular expression matching as a special case. It's also unused except for one command, where it causes bugs (see Bug#69501). All in all, 'completion-regexp-list' doesn't carry its own weight. --- diff --git a/doc/lispref/minibuf.texi b/doc/lispref/minibuf.texi index 7d5e6678cbb..c7e445af517 100644 --- a/doc/lispref/minibuf.texi +++ b/doc/lispref/minibuf.texi @@ -854,11 +854,6 @@ name) from the obarray. If @var{collection} is a hash table, @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 @@ -911,20 +906,10 @@ too short). Both of those begin with the string @samp{foobar}. @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} @@ -959,9 +944,6 @@ completion alternative specified by @var{collection} and 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}, @@ -1010,19 +992,6 @@ Names}); within @code{read-buffer}, it is overridden by 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 diff --git a/lisp/cus-edit.el b/lisp/cus-edit.el index 87171336743..50453d96252 100644 --- a/lisp/cus-edit.el +++ b/lisp/cus-edit.el @@ -1163,8 +1163,7 @@ argument or if the current major mode has no known group, prompt 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 diff --git a/lisp/custom.el b/lisp/custom.el index a19b14aaf8a..3808165fca8 100644 --- a/lisp/custom.el +++ b/lisp/custom.el @@ -554,11 +554,10 @@ If there already is an entry for OPTION and WIDGET, nothing is done." "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. diff --git a/lisp/emacs-lisp/regexp-opt.el b/lisp/emacs-lisp/regexp-opt.el index 59c1b7d8e10..793c130f437 100644 --- a/lisp/emacs-lisp/regexp-opt.el +++ b/lisp/emacs-lisp/regexp-opt.el @@ -135,7 +135,6 @@ usually more efficient than that of a simplified version: ;; 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 diff --git a/lisp/files.el b/lisp/files.el index 543ef6c3615..8bcce8e4971 100644 --- a/lisp/files.el +++ b/lisp/files.el @@ -1099,12 +1099,11 @@ one or more of those symbols." (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. diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el index d4aa002e35a..d8fa1100c2f 100644 --- a/lisp/minibuffer.el +++ b/lisp/minibuffer.el @@ -684,9 +684,8 @@ METADATA takes precedence over any metadata that TABLE provides." (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)) @@ -4564,18 +4563,14 @@ PATTERN is as returned by `completion-pcm--string->pattern'." (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. @@ -6022,6 +6017,8 @@ This applies to `completions-auto-update-mode', which see." (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 diff --git a/lisp/net/tramp-crypt.el b/lisp/net/tramp-crypt.el index a7af64bff5c..5a605d7a728 100644 --- a/lisp/net/tramp-crypt.el +++ b/lisp/net/tramp-crypt.el @@ -744,8 +744,7 @@ absolute file names." (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 diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el index 4aceb7ea356..6e74ec320b4 100644 --- a/lisp/net/tramp.el +++ b/lisp/net/tramp.el @@ -2766,16 +2766,7 @@ BODY is the backend specific code." (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.") diff --git a/lisp/progmodes/idlwave.el b/lisp/progmodes/idlwave.el index 30442fa0d34..b9766bdbeb7 100644 --- a/lisp/progmodes/idlwave.el +++ b/lisp/progmodes/idlwave.el @@ -5726,9 +5726,6 @@ Possible values are: 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." @@ -5741,10 +5738,7 @@ 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)) diff --git a/src/dired.c b/src/dired.c index 9a372201ae0..0f2872c6470 100644 --- a/src/dired.c +++ b/src/dired.c @@ -442,10 +442,8 @@ Returns nil if DIRECTORY contains no name starting with FILE. 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; @@ -469,11 +467,7 @@ is matched against file and directory names relative to DIRECTORY. */) 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; @@ -730,17 +724,7 @@ file_name_completion (Lisp_Object file, Lisp_Object dirname, bool all_flag, } } - 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) diff --git a/src/minibuf.c b/src/minibuf.c index d59d74addbe..d02e87e417b 100644 --- a/src/minibuf.c +++ b/src/minibuf.c @@ -1544,27 +1544,6 @@ behavior. */) return unbind_to (count, result); } -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. @@ -1599,10 +1578,6 @@ car is a string) from the alist, or a symbol from the obarray. 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 @@ -1687,11 +1662,6 @@ or from one of the possible completions. */) 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. */ @@ -1832,10 +1802,6 @@ car is a string) from the alist, or a symbol from the obarray. 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. */) @@ -1917,11 +1883,6 @@ 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. */ @@ -2096,11 +2057,6 @@ the values STRING, PREDICATE and `lambda'. */) 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)) { @@ -2381,20 +2337,6 @@ is added with 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. */); diff --git a/test/lisp/net/tramp-archive-tests.el b/test/lisp/net/tramp-archive-tests.el index 1ca2fa9b9b3..b11292dc774 100644 --- a/test/lisp/net/tramp-archive-tests.el +++ b/test/lisp/net/tramp-archive-tests.el @@ -808,45 +808,6 @@ This tests also `file-executable-p', `file-writable-p' and `set-file-modes'." ;; 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) diff --git a/test/lisp/net/tramp-tests.el b/test/lisp/net/tramp-tests.el index cdd2a1efdb2..7a062071f70 100644 --- a/test/lisp/net/tramp-tests.el +++ b/test/lisp/net/tramp-tests.el @@ -4813,20 +4813,7 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'." (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"))) diff --git a/test/src/minibuf-tests.el b/test/src/minibuf-tests.el index b790c7fa02a..2712ffb1a3a 100644 --- a/test/src/minibuf-tests.el +++ b/test/src/minibuf-tests.el @@ -86,20 +86,6 @@ (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")))) @@ -124,21 +110,6 @@ (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")))) @@ -161,20 +132,6 @@ (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))))) - ;;; Tests for `try-completion'. (ert-deftest try-completion-string-list ()