From 29c9cd7e82e1e2cacfe1371d6eaa9517ac5367b5 Mon Sep 17 00:00:00 2001 From: Eshel Yaron Date: Fri, 9 Feb 2024 11:15:24 +0100 Subject: [PATCH] Remove minibuffer up-to-one-word completion Deprecate 'minibuffer-complete-word', and cease binding 'SPC' during minibuffer completion altogether. * lisp/minibuffer.el (minibuffer-complete-word): Turn it into an obsolete alias of 'minibuffer-complete'. (minibuffer-confirm-exit-commands): Remove 'minibuffer-complete-word'. (completion--try-word-completion): Drop it. (minibuffer-local-completion-map): Cease binding 'SPC'. (minibuffer-local-filename-completion-map) (completion-pcm-complete-word-inserts-delimiters): Deprecate. (completion-pcm--string->pattern, completing-read-default): Simplify. * doc/emacs/custom.texi (Minibuffer Maps) * doc/emacs/mini.texi (Completion Commands) * doc/lispref/help.texi (Keys in Documentation) * doc/lispref/minibuf.texi (Completion Commands) * lisp/emulation/viper-ex.el (viper-complete-filename-or-exit) * lisp/gnus/mm-decode.el (mm-viewer-completion-map) * lisp/man.el (Man-completion-table) * lisp/menu-bar.el (map) * test/lisp/help-tests.el (help-tests--test-keymap) (help-tests-substitute-command-keys/keymaps): Adjust. * etc/NEWS: Announce. --- doc/emacs/custom.texi | 5 -- doc/emacs/mini.texi | 13 ---- doc/lispref/help.texi | 1 - doc/lispref/minibuf.texi | 17 ----- etc/NEWS | 6 ++ lisp/emulation/viper-ex.el | 2 +- lisp/gnus/mm-decode.el | 1 - lisp/man.el | 2 +- lisp/menu-bar.el | 3 - lisp/minibuffer.el | 152 ++++--------------------------------- test/lisp/help-tests.el | 2 - 11 files changed, 24 insertions(+), 180 deletions(-) diff --git a/doc/emacs/custom.texi b/doc/emacs/custom.texi index 4725af0ee5f..e047782e150 100644 --- a/doc/emacs/custom.texi +++ b/doc/emacs/custom.texi @@ -1794,7 +1794,6 @@ circumstances. @vindex minibuffer-local-ns-map @vindex minibuffer-local-completion-map @vindex minibuffer-local-must-match-map -@vindex minibuffer-local-filename-completion-map The minibuffer has its own set of local keymaps; they contain various completion and exit commands. @@ -1809,10 +1808,6 @@ just like @key{RET}. @item @code{minibuffer-local-must-match-map} is for strict completion and for cautious completion. -@item -@code{minibuffer-local-filename-completion-map} is like the two -previous ones, but specifically for file name completion. -It does not bind @key{SPC}. @end itemize By default, @key{TAB}, @key{SPC} and @key{?} do completion in diff --git a/doc/emacs/mini.texi b/doc/emacs/mini.texi index 89f563ac17a..efc26bad226 100644 --- a/doc/emacs/mini.texi +++ b/doc/emacs/mini.texi @@ -349,10 +349,6 @@ when completion is allowed. Complete the text in the minibuffer as much as possible; if unable to complete, display a list of possible completions (@code{minibuffer-complete}). -@item @key{SPC} -Complete up to one word from the minibuffer text before point -(@code{minibuffer-complete-word}). This command is not available for -arguments that often include spaces, such as file names. @item @key{RET} Submit the text in the minibuffer as the argument, possibly completing first (@code{minibuffer-complete-and-exit}). @xref{Completion Exit}. @@ -397,15 +393,6 @@ match the existing minibuffer text, and attempts to complete as much as it can. @xref{Completion Styles}, for how completion alternatives are chosen. -@kindex SPC @r{(completion)} -@findex minibuffer-complete-word - @key{SPC} (@code{minibuffer-complete-word}) completes like -@key{TAB}, but only up to the next hyphen or space. If you have -@samp{auto-f} in the minibuffer and type @key{SPC}, it finds that the -completion is @samp{auto-fill-mode}, but it only inserts @samp{ill-}, -giving @samp{auto-fill-}. Another @key{SPC} at this point completes -all the way to @samp{auto-fill-mode}. - @kindex RET @r{(completion)} @findex minibuffer-complete-and-exit @key{RET} (@code{minibuffer-complete-and-exit}) submits the text in diff --git a/doc/lispref/help.texi b/doc/lispref/help.texi index a76bac011b7..ba106e5e93b 100644 --- a/doc/lispref/help.texi +++ b/doc/lispref/help.texi @@ -422,7 +422,6 @@ specifies a key binding that the command does not actually have. @end group ? minibuffer-completion-help -SPC minibuffer-complete-word TAB minibuffer-complete C-j minibuffer-complete-and-exit RET minibuffer-complete-and-exit diff --git a/doc/lispref/minibuf.texi b/doc/lispref/minibuf.texi index 86fe44b90dc..96143f4126e 100644 --- a/doc/lispref/minibuf.texi +++ b/doc/lispref/minibuf.texi @@ -1320,13 +1320,6 @@ The confirmation is requested if the user attempts to exit the minibuffer immediately after calling any command in this list. @end defvar -@deffn Command minibuffer-complete-word -This function completes the minibuffer contents by at most a single -word. Even if the minibuffer contents have only one completion, -@code{minibuffer-complete-word} does not add any characters beyond the -first character that is not a word constituent. @xref{Syntax Tables}. -@end deffn - @deffn Command minibuffer-complete This function completes the minibuffer contents as far as possible. @end deffn @@ -1462,9 +1455,6 @@ keymap makes the following bindings: @item @kbd{?} @code{minibuffer-completion-help} -@item @key{SPC} -@code{minibuffer-complete-word} - @item @key{TAB} @code{minibuffer-complete} @@ -1528,13 +1518,6 @@ bindings: and uses @code{minibuffer-local-completion-map} as its parent keymap. @end defvar -@defvar minibuffer-local-filename-completion-map -This is a sparse keymap that simply unbinds @key{SPC}; because -filenames can contain spaces. The function @code{read-file-name} -combines this keymap with either @code{minibuffer-local-completion-map} -or @code{minibuffer-local-must-match-map}. -@end defvar - @defvar minibuffer-beginning-of-buffer-movement If non-@code{nil}, the @kbd{M-<} command will move to the end of the prompt if point is after the end of the prompt. If point is at or diff --git a/etc/NEWS b/etc/NEWS index 661267a0150..4741b69b564 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -768,6 +768,12 @@ the file with the whole history of the session. The default is nil. ** Minibuffer and Completions +*** 'SPC' in the minibuffer now inserts a space. +'SPC' no longer completes by word in the minibuffer. To have 'SPC' +perform minibuffer completion, add the following form to your init file: + + (keymap-set minibuffer-local-completion-map "SPC" #'minibuffer-complete) + *** New commands 'previous-line-completion' and 'next-line-completion'. Bound to '' and '' arrow keys, respectively, they navigate the "*Completions*" buffer vertically by lines, wrapping at the diff --git a/lisp/emulation/viper-ex.el b/lisp/emulation/viper-ex.el index 11e00aef33d..d585f9499e2 100644 --- a/lisp/emulation/viper-ex.el +++ b/lisp/emulation/viper-ex.el @@ -1071,7 +1071,7 @@ reversed." (insert " ")) (t (setq ex-cmdfile nil) - (minibuffer-complete-word)))) + (minibuffer-complete)))) (defun viper-handle-! () (interactive) diff --git a/lisp/gnus/mm-decode.el b/lisp/gnus/mm-decode.el index f91755e967b..defc9cceb4a 100644 --- a/lisp/gnus/mm-decode.el +++ b/lisp/gnus/mm-decode.el @@ -538,7 +538,6 @@ result of the verification." (defvar mm-viewer-completion-map (let ((map (make-sparse-keymap 'mm-viewer-completion-map))) (set-keymap-parent map minibuffer-local-completion-map) - ;; Should we bind other key to minibuffer-complete-word? (define-key map " " 'self-insert-command) map) "Keymap for input viewer with completion.") diff --git a/lisp/man.el b/lisp/man.el index d96396483d3..6f5a8094aa3 100644 --- a/lisp/man.el +++ b/lisp/man.el @@ -980,7 +980,7 @@ foo(sec)[, bar(sec) [, ...]] [other stuff] - description" ;; require-match anyway, there's not point being clever. ;;((eq action 'lambda) (not (string-match "([^)]*\\'" string))) ((equal string "-k") - ;; Let SPC (minibuffer-complete-word) insert the space. + ;; Let SPC insert the space. (complete-with-action action '("-k ") string pred)) (t (let ((table (cdr Man-completion-cache)) diff --git a/lisp/menu-bar.el b/lisp/menu-bar.el index 05de0578bec..71dfe1cddec 100644 --- a/lisp/menu-bar.el +++ b/lisp/menu-bar.el @@ -2597,9 +2597,6 @@ It must accept a buffer as its only required argument.") (bindings--define-key map [menu-bar minibuf ?\?] '(menu-item "List Completions" minibuffer-completion-help :help "Display all possible completions")) - (bindings--define-key map [menu-bar minibuf space] - '(menu-item "Complete Word" minibuffer-complete-word - :help "Complete at most one word")) (bindings--define-key map [menu-bar minibuf tab] '(menu-item "Complete" minibuffer-complete :help "Complete as far as possible"))) diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el index c1b407d0954..daee432b04d 100644 --- a/lisp/minibuffer.el +++ b/lisp/minibuffer.el @@ -1679,6 +1679,9 @@ scroll the window of possible completions." minibuffer-completion-table minibuffer-completion-predicate)) +(define-obsolete-function-alias 'minibuffer-complete-word + 'minibuffer-complete "30.1") + (defun completion--in-region-1 (beg end) ;; If the previous command was not this, ;; mark the completion buffer obsolete. @@ -2074,8 +2077,7 @@ DONT-CYCLE tells the function not to setup cycling." map))))))))) (defvar minibuffer-confirm-exit-commands - '( completion-at-point minibuffer-complete - minibuffer-complete-word) + '(completion-at-point minibuffer-complete) "List of commands which cause an immediately following `minibuffer-complete-and-exit' to ask for extra confirmation.") @@ -2178,109 +2180,6 @@ appear to be a match." ;; Call do-completion, but ignore errors. (funcall completion-function)))) -(defun completion--try-word-completion (string table predicate point md) - (let ((comp (completion-try-completion string table predicate point md))) - (if (not (consp comp)) - comp - - ;; If completion finds next char not unique, - ;; consider adding a space or a hyphen. - (when (= (length string) (length (car comp))) - ;; Mark the added char with the `completion-word' property, so it - ;; can be handled specially by completion styles such as - ;; partial-completion. - ;; We used to remove `partial-completion' from completion-styles - ;; instead, but it was too blunt, leading to situations where SPC - ;; was the only insertable char at point but minibuffer-complete-word - ;; refused inserting it. - (let ((exts (mapcar (lambda (str) (propertize str 'completion-try-word t)) - '(" " "-"))) - (before (substring string 0 point)) - (after (substring string point)) - tem) - ;; If both " " and "-" lead to completions, prefer " " so SPC behaves - ;; a bit more like a self-inserting key (bug#17375). - (while (and exts (not (consp tem))) - (setq tem (completion-try-completion - (concat before (pop exts) after) - table predicate (1+ point) md))) - (if (consp tem) (setq comp tem)))) - - ;; Completing a single word is actually more difficult than completing - ;; as much as possible, because we first have to find the "current - ;; position" in `completion' in order to find the end of the word - ;; we're completing. Normally, `string' is a prefix of `completion', - ;; which makes it trivial to find the position, but with fancier - ;; completion (plus env-var expansion, ...) `completion' might not - ;; look anything like `string' at all. - (let* ((comppoint (cdr comp)) - (completion (car comp)) - (before (substring string 0 point)) - (combined (concat before "\n" completion))) - ;; Find in completion the longest text that was right before point. - (when (string-match "\\(.+\\)\n.*?\\1" combined) - (let* ((prefix (match-string 1 before)) - ;; We used non-greedy match to make `rem' as long as possible. - (rem (substring combined (match-end 0))) - ;; Find in the remainder of completion the longest text - ;; that was right after point. - (after (substring string point)) - (suffix (if (string-match "\\`\\(.+\\).*\n.*\\1" - (concat after "\n" rem)) - (match-string 1 after)))) - ;; The general idea is to try and guess what text was inserted - ;; at point by the completion. Problem is: if we guess wrong, - ;; we may end up treating as "added by completion" text that was - ;; actually painfully typed by the user. So if we then cut - ;; after the first word, we may throw away things the - ;; user wrote. So let's try to be as conservative as possible: - ;; only cut after the first word, if we're reasonably sure that - ;; our guess is correct. - ;; Note: a quick survey on emacs-devel seemed to indicate that - ;; nobody actually cares about the "word-at-a-time" feature of - ;; minibuffer-complete-word, whose real raison-d'être is that it - ;; tries to add "-" or " ". One more reason to only cut after - ;; the first word, if we're really sure we're right. - (when (and (or suffix (zerop (length after))) - (string-match (concat - ;; Make submatch 1 as small as possible - ;; to reduce the risk of cutting - ;; valuable text. - ".*" (regexp-quote prefix) "\\(.*?\\)" - (if suffix (regexp-quote suffix) "\\'")) - completion) - ;; The new point in `completion' should also be just - ;; before the suffix, otherwise something more complex - ;; is going on, and we're not sure where we are. - (eq (match-end 1) comppoint) - ;; (match-beginning 1)..comppoint is now the stretch - ;; of text in `completion' that was completed at point. - (string-match "\\W" completion (match-beginning 1)) - ;; Is there really something to cut? - (> comppoint (match-end 0))) - ;; Cut after the first word. - (let ((cutpos (match-end 0))) - (setq completion (concat (substring completion 0 cutpos) - (substring completion comppoint))) - (setq comppoint cutpos))))) - - (cons completion comppoint))))) - - -(defun minibuffer-complete-word () - "Complete the minibuffer contents at most a single word. -After one word is completed as much as possible, a space or hyphen -is added, provided that matches some possible completion. -Return nil if there is no valid completion, else t." - (interactive) - (completion-in-region--single-word - (minibuffer--completion-prompt-end) (point-max))) - -(defun completion-in-region--single-word (beg end) - (pcase (completion--do-completion beg end #'completion--try-word-completion) - (#b000 nil) - (_ t))) - (defface completions-annotations '((t :inherit (italic shadow))) "Face to use for annotations in the *Completions* buffer. This face is only used if the strings used for completions @@ -3468,7 +3367,6 @@ The completion method is determined by `completion-at-point-functions'." "C-o" #'minibuffer-cycle-completion "C-l" #'minibuffer-restore-completion-input "C-S-a" #'minibuffer-toggle-completion-ignore-case - "SPC" #'minibuffer-complete-word "?" #'minibuffer-completion-help "" #'switch-to-completions "M-v" #'switch-to-completions @@ -3487,10 +3385,10 @@ The completion method is determined by `completion-at-point-functions'." "C-j" #'minibuffer-complete-and-exit) (defvar-keymap minibuffer-local-filename-completion-map - :doc "Local keymap for minibuffer input with completion for filenames. -Gets combined either with `minibuffer-local-completion-map' or -with `minibuffer-local-must-match-map'." - "SPC" nil) + :doc "This variable is obsolete and no longer used.") + +(make-obsolete-variable 'minibuffer-local-filename-completion-map + nil "30.1") (defvar-keymap minibuffer-local-ns-map :doc "Local keymap for the minibuffer when spaces are not allowed." @@ -4404,14 +4302,13 @@ expression (not containing character ranges like `a-z')." :type 'string) (defcustom completion-pcm-complete-word-inserts-delimiters nil - "Treat the SPC or - inserted by `minibuffer-complete-word' as delimiters. -Those chars are treated as delimiters if this variable is non-nil. -I.e. if non-nil, M-x SPC will just insert a \"-\" in the minibuffer, whereas -if nil, it will list all possible commands in *Completions* because none of -the commands start with a \"-\" or a SPC." + "This variable is obsolete and has no effect." :version "24.1" :type 'boolean) +(make-obsolete-variable 'completion-pcm-complete-word-inserts-delimiters + nil "30.1") + (defun completion-pcm--pattern-trivial-p (pattern) (and (stringp (car pattern)) ;; It can be followed by `point' and "" and still be trivial. @@ -4436,14 +4333,7 @@ or a symbol, see `completion-pcm--merge-completions'." (p0 p) (pending nil)) - (while (and (setq p (string-match completion-pcm--delim-wild-regex - string p)) - (or completion-pcm-complete-word-inserts-delimiters - ;; If the char was added by minibuffer-complete-word, - ;; then don't treat it as a delimiter, otherwise - ;; "M-x SPC" ends up inserting a "-" rather than listing - ;; all completions. - (not (get-text-property p 'completion-try-word string)))) + (while (setq p (string-match completion-pcm--delim-wild-regex string p)) ;; Usually, completion-pcm--delim-wild-regex matches a delimiter, ;; meaning that something can be added *before* it, but it can also ;; match a prefix and postfix, in which case something can be added @@ -5271,23 +5161,13 @@ See `completing-read' for the meaning of the arguments." (1+ (cdr initial-input))))) (let* ((base-keymap (if require-match - minibuffer-local-must-match-map + minibuffer-local-must-match-map minibuffer-local-completion-map)) - (keymap (if (memq minibuffer-completing-file-name '(nil lambda)) - base-keymap - ;; Layer minibuffer-local-filename-completion-map - ;; on top of the base map. - (make-composed-keymap - minibuffer-local-filename-completion-map - ;; Set base-keymap as the parent, so that nil bindings - ;; in minibuffer-local-filename-completion-map can - ;; override bindings in base-keymap. - base-keymap))) (keymap (if minibuffer-visible-completions (make-composed-keymap (list minibuffer-visible-completions-map - keymap)) - keymap)) + base-keymap)) + base-keymap)) (buffer (current-buffer)) (c-i-c completion-ignore-case) (result diff --git a/test/lisp/help-tests.el b/test/lisp/help-tests.el index f27fa979ef0..a6b0a3ece81 100644 --- a/test/lisp/help-tests.el +++ b/test/lisp/help-tests.el @@ -130,7 +130,6 @@ "TAB" #'minibuffer-complete "C-j" #'minibuffer-complete-and-exit "RET" #'minibuffer-complete-and-exit - "SPC" #'minibuffer-complete-word "?" #'minibuffer-completion-help "C-" #'file-cache-minibuffer-complete "" #'previous-history-element @@ -158,7 +157,6 @@ C-g abort-minibuffers TAB minibuffer-complete C-j minibuffer-complete-and-exit RET minibuffer-complete-and-exit -SPC minibuffer-complete-word \\? minibuffer-completion-help C- file-cache-minibuffer-complete previous-history-element -- 2.39.5