From: Eshel Yaron Date: Mon, 25 Dec 2023 11:24:51 +0000 (+0100) Subject: ; Support removing individual completions restrictions X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=51c64a367f3bf366fe3aa81258be60f7a56649f3;p=emacs.git ; Support removing individual completions restrictions * lisp/minibuffer.el (minibuffer-widen-completions): New optional argument ALL, if nil prompt for individual restrictions to remove. Also, take into account completions boundaries when calling 'minibuffer-completion-help'. * doc/emacs/mini.texi (Completion Commands, Narrow Completions): Update documentation. * lisp/menu-bar.el (map): Update help text. --- diff --git a/doc/emacs/mini.texi b/doc/emacs/mini.texi index d635208fc8b..72e857a3c0e 100644 --- a/doc/emacs/mini.texi +++ b/doc/emacs/mini.texi @@ -361,7 +361,8 @@ current minibuffer input Narrow the list of possible completions in a command-specific manner (@code{minibuffer-narrow-completions}). @item C-x n w -Remove all completions restrictions (@code{minibuffer-widen-completions}). +Remove restrictions on the list of possible completions +(@code{minibuffer-widen-completions}). @item ? Display a list of completions (@code{minibuffer-completion-help}). @end table @@ -400,9 +401,14 @@ that list. @xref{Narrow Completions}, for more details. @kindex C-x n w @r{(completion)} @findex minibuffer-widen-completions - @kbd{C-x n w} (@code{minibuffer-widen-completions}) removes all + @kbd{C-x n w} (@code{minibuffer-widen-completions}) removes completions restrictions that you set with @kbd{C-x n n} or with -@kbd{C-x n m}. +@kbd{C-x n m}. This command prompts you for one or more of the +restrictions that you set, and removes those restrictions. If there +is only one restriction, @kbd{C-x n w} removes it without prompting. +If you invoke this command with a prefix argument (@kbd{C-u C-x n w}), +it removes all restrictions without prompting, regardless of how many +there are. @kindex ? @r{(completion)} @cindex completion list @@ -688,9 +694,19 @@ example, typing @kbd{M-x C-x n m foo @key{RET} C-x n m bar @key{RET}} shows only commands that match both @samp{foo} and @samp{bar} in the completions list. - You can use @kbd{C-x n w} (@code{minibuffer-widen-completions}) in -the minibuffer to remove the restrictions on the list of possible + Use @kbd{C-x n w} (@code{minibuffer-widen-completions}) in the +minibuffer to remove the restrictions on the list of possible completions that you set with @kbd{C-x n n} or with @kbd{C-x n m}. +@kbd{C-x n w} prompts you for the description of a current completions +restriction, and removes the corresponding restriction. The default +candidate is the most recent restriction, and you can use completion +to select other restriction descriptions. You can even specify +multiple restrictions to remove at once, by separating their +descriptions with commas in the minibuffer. If there is only one +restriction to begin with, @kbd{C-x n w} removes it without prompting. +If you invoke this command with a prefix argument (@kbd{C-u C-x n w}), +it removes all restrictions without prompting, regardless of how many +there are. @node Completion Options @subsection Completion Options diff --git a/lisp/menu-bar.el b/lisp/menu-bar.el index 1d8efd28996..8826547921e 100644 --- a/lisp/menu-bar.el +++ b/lisp/menu-bar.el @@ -2560,7 +2560,7 @@ It must accept a buffer as its only required argument.") [menu-bar minibuf minibuffer-widen-completions] '(menu-item "Remove Completions Restrictions" minibuffer-widen-completions - :help "Remove all restrictions on completions list" + :help "Remove restrictions on completions list" :enable (minibuffer-narrow-completions-p))) (bindings--define-key map [menu-bar minibuf minibuffer-narrow-completions] diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el index e772486cf40..2c31b9f10a0 100644 --- a/lisp/minibuffer.el +++ b/lisp/minibuffer.el @@ -5094,17 +5094,47 @@ exclude matches to current input from completions list." (gethash key table))) (concat "narrowing to " (prin1-to-string input)))))) -(defun minibuffer-widen-completions () - "Remove all restrictions on current completion candidates." - (interactive "" minibuffer-mode) - (advice-function-mapc - (lambda (a p) - (when (alist-get 'description p) - (remove-function (local 'minibuffer-completion-predicate) a))) - minibuffer-completion-predicate) +(defun minibuffer-widen-completions (&optional all) + "Remove restrictions on current minibuffer completions list. + +Prompt for one or more restrictions that currently apply to the +list of possible minibuffer completions, and remove those +restrictions. You can use completion to select the restrictions +to remove, separating each of your selections with +`crm-separator' (usually, a comma). + +When there is only one restriction, remove it without prompting. +With optional argument ALL (interactively, the prefix argument), +remove all current restrictions without prompting." + (interactive "P" minibuffer-mode) + (let ((desc-pred-alist nil)) + (advice-function-mapc + (lambda (a p) + (when-let ((d (alist-get 'description p))) + (push (cons d a) desc-pred-alist))) + minibuffer-completion-predicate) + (unless desc-pred-alist + (user-error "No completions restrictions")) + ;; Put latest restriction first. + (setq desc-pred-alist (reverse desc-pred-alist)) + (mapc + (lambda (pair) + (remove-function (local 'minibuffer-completion-predicate) (cdr pair))) + (if (or all + ;; Only one restriction. + (not (cdr desc-pred-alist))) + desc-pred-alist + (mapcar (lambda (desc) + (assoc desc desc-pred-alist)) + (completing-read-multiple + (format-prompt "Remove completions restriction,s" + (caar desc-pred-alist)) + desc-pred-alist nil t nil nil (caar desc-pred-alist)))))) (when completion-auto-help - (minibuffer-completion-help)) - (when-let ((completions-buffer (get-buffer "*Completions*"))) + (let ((beg-end (minibuffer--completion-boundaries))) + (minibuffer-completion-help (car beg-end) (cdr beg-end)))) + (when-let ((completions-buffer (and (not (minibuffer-narrow-completions-p)) + (get-buffer "*Completions*")))) (with-current-buffer completions-buffer (completions-narrow-mode -1))))