(@code{minibuffer-cycle-completion}).
@item C-l
Restore the minibuffer input that Emacs used to compute the current
-set of completion candidates.
+set of completion candidates
(@code{minibuffer-restore-completion-input}).
@item C-x C-v
Change the order of the list of possible completions
@item C-x n m
Narrow the list of possible completions in a command-specific manner
(@code{minibuffer-narrow-completions}).
+@item C-x n h
+Restrict the list of possible completions according to the minibuffer
+history list (@code{minibuffer-narrow-completions-to-history}).
@item C-x n w
Remove restrictions on the list of possible completions
(@code{minibuffer-widen-completions}).
narrow the completions list depending on the kind of candidates in
that list. @xref{Narrow Completions}, for more details.
+@kindex C-x n h @r{(completion)}
+@findex minibuffer-narrow-completions-to-history
+ @kbd{C-x n h} (@code{minibuffer-narrow-completions-to-history})
+narrows the list of possible completions to only include past inputs,
+i.e., completions that also appear in the minibuffer history list.
+@xref{Minibuffer History}. With a negative prefix argument (@kbd{C--
+C-x n h}), this command does the opposite: instead of keeping only
+past inputs, it excludes them and keeps the rest.
+
@kindex C-x n w @r{(completion)}
@findex minibuffer-widen-completions
@kbd{C-x n w} (@code{minibuffer-widen-completions}) removes
list to only include candidates which match that regular expression.
@xref{Regexps}.
-When you narrow the completions list with @kbd{C-x n n} or with
-@kbd{C-x n m}, Emacs extends the completions heading line with a
+ You can also restrict completions to only include completions that
+you've previously provided as input (that is, members of the current
+minibuffer history list, @pxref{Minibuffer History}). You do this by
+typing @kbd{C-x n h} (@code{minibuffer-narrow-completions-to-history})
+in the minibuffer. This command filters the completions list, keeping
+only your past inputs. If you invoke it with a negative prefix
+argument (@kbd{C-- C-x n h}), this command instead does the opposite:
+it removes past inputs from the completions list, and keeps the rest.
+
+When you narrow the completions list with @kbd{C-x n n}, @kbd{C-x n m}
+or @kbd{C-x n m}, Emacs extends the completions heading line with a
description of the restriction that is currently in effect
(@pxref{Completions Heading Line}). The mode line of the
@file{*Completions*} buffer also indicates the restriction with the
(defvar-keymap minibuffer-narrow-completions-map
:doc "Keymap for completions narrowing commands."
"n" #'minibuffer-narrow-completions-to-current
+ "h" #'minibuffer-narrow-completions-to-history
"m" #'minibuffer-narrow-completions
"w" #'minibuffer-widen-completions)
(gethash key table)))
(concat "narrowing to " (prin1-to-string current))))))
+(defun minibuffer-narrow-completions-to-history (&optional exclude)
+ "EXCLUDE or keep only members of the minibuffer history as completions.
+
+If EXCLUDE is nil, restrict completions to only those that are
+also in the minibuffer history list. In other words, keep only
+your past inputs as completion candidates. Otherwise, if EXCLUDE
+is non-nil, keep only \"new\" completion candidates, excluding
+members of the minibuffer history list."
+ (interactive "P" minibuffer-mode)
+ (if-let ((hist
+ (mapcar
+ (lambda (string)
+ (substring string
+ (car (completion-boundaries
+ string
+ minibuffer-completion-table
+ minibuffer-completion-predicate
+ ""))))
+ (and (not (eq minibuffer-history-variable t))
+ (symbol-value minibuffer-history-variable))))
+ (func (if exclude (lambda (k h) (not (member k h))) #'member)))
+ (minibuffer--add-completions-predicate
+ (lambda (cand &rest _)
+ (let* ((key (cond
+ ((stringp cand) cand)
+ ((symbolp cand) (symbol-name cand))
+ (t (car cand)))))
+ (funcall func key hist)))
+ (concat (when exclude "not ") "previously used"))))
+
(defun minibuffer-widen-completions (&optional all)
"Remove restrictions on current minibuffer completions list.