From 99cb3a7154cd1e1b751b7cdf84479cd850e7da17 Mon Sep 17 00:00:00 2001 From: Juri Linkov Date: Tue, 14 Jun 2022 10:14:52 +0300 Subject: [PATCH] * lisp/minibuffer.el (minibuffer-complete-history): New command. (minibuffer-complete-defaults): New command. https://lists.gnu.org/archive/html/emacs-devel/2022-06/msg00498.html --- etc/NEWS | 6 ++++++ lisp/minibuffer.el | 30 ++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/etc/NEWS b/etc/NEWS index eb4c6956b81..73416fb30cd 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -1090,6 +1090,12 @@ to complete. The value 'visual' is like 'always', but only updates the completions if they are already visible. The default value 't' always hides the completion buffer after some completion is made. +*** New commands to complete the minibuffer history. +'minibuffer-complete-history' ('C-x up') is like 'minibuffer-complete' +but completes on the history items instead of the default completion +table. 'minibuffer-complete-defaults' ('C-x down') completes +on the list of default items. + +++ *** New user option 'completions-sort'. This option controls the sorting of the completion candidates in diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el index bf89874ecc8..7d589c01740 100644 --- a/lisp/minibuffer.el +++ b/lisp/minibuffer.el @@ -4425,6 +4425,36 @@ minibuffer, but don't quit the completions window." (let ((completion-use-base-affixes t)) (choose-completion nil no-exit no-quit)))) +(defun minibuffer-complete-history () + "Complete the minibuffer history as far as possible. +Like `minibuffer-complete' but completes on the history items +instead of the default completion table." + (interactive) + (let ((completions-sort nil) + (history (mapcar (lambda (h) + ;; Support e.g. `C-x ESC ESC TAB' as + ;; a replacement of `list-command-history' + (if (consp h) (format "%S" h) h)) + (symbol-value minibuffer-history-variable)))) + (completion-in-region (minibuffer--completion-prompt-end) (point-max) + history nil))) + +(defun minibuffer-complete-defaults () + "Complete minibuffer defaults as far as possible. +Like `minibuffer-complete' but completes on the default items +instead of the completion table." + (interactive) + (let ((completions-sort nil)) + (when (and (not minibuffer-default-add-done) + (functionp minibuffer-default-add-function)) + (setq minibuffer-default-add-done t + minibuffer-default (funcall minibuffer-default-add-function))) + (completion-in-region (minibuffer--completion-prompt-end) (point-max) + (ensure-list minibuffer-default) nil))) + +(define-key minibuffer-local-map [?\C-x up] 'minibuffer-complete-history) +(define-key minibuffer-local-map [?\C-x down] 'minibuffer-complete-defaults) + (defcustom minibuffer-default-prompt-format " (default %s)" "Format string used to output \"default\" values. When prompting for input, there will often be a default value, -- 2.39.2