]> git.eshelyaron.com Git - emacs.git/commitdiff
* lisp/minibuffer.el (minibuffer-complete-history): New command.
authorJuri Linkov <juri@linkov.net>
Tue, 14 Jun 2022 07:14:52 +0000 (10:14 +0300)
committerJuri Linkov <juri@linkov.net>
Tue, 14 Jun 2022 07:14:52 +0000 (10:14 +0300)
(minibuffer-complete-defaults): New command.
https://lists.gnu.org/archive/html/emacs-devel/2022-06/msg00498.html

etc/NEWS
lisp/minibuffer.el

index eb4c6956b81639c27b7e7dbbdeb47038ab17edf2..73416fb30cda4bd33c976b2c533cdb12da142e0a 100644 (file)
--- 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
index bf89874ecc8e3bfc47bbc5cc7bcb662315efea27..7d589c0174093ba0bd94a445fdf5f28b61190bb2 100644 (file)
@@ -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,