unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Juri Linkov <juri@linkov.net>
To: emacs-devel@gnu.org
Subject: Re: History completion
Date: Thu, 09 Jun 2022 10:01:53 +0300	[thread overview]
Message-ID: <86czfifgzq.fsf@mail.linkov.net> (raw)
In-Reply-To: <86mtlbvuq2.fsf@mail.linkov.net> (Juri Linkov's message of "Wed,  08 Dec 2021 20:54:40 +0200")

[-- Attachment #1: Type: text/plain, Size: 727 bytes --]

> So instead of this, tried to show history completions only after
> typing a special key.  TAB can't be reused because in some minibuffers
> such as ‘M-!’ (shell-command), TAB completes the command/file names.
>
> There is ‘C-tab’ bound to file-cache-minibuffer-complete.
> When file-cache is not used, then ‘C-tab’ could be rebound
> to a command that completes on the minibuffer history.

Actually two keys are needed: one to complete on the history,
and another to complete on the list of default values.
So maybe like the ‘up’ key navigates through the history,
‘C-x up’ could complete on the history, and like ‘down’ key
navigates through the future history, ‘C-x down’ could
complete on it:


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: minibuffer-complete-history.patch --]
[-- Type: text/x-diff, Size: 1912 bytes --]

diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el
index cdbde2d340..e0e9893367 100644
--- a/lisp/minibuffer.el
+++ b/lisp/minibuffer.el
@@ -4418,6 +4499,36 @@ minibuffer-choose-completion
     (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,

      parent reply	other threads:[~2022-06-09  7:01 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-08 18:54 History completion Juri Linkov
2021-12-08 20:02 ` André A. Gomes
2021-12-09  6:05   ` Manuel Uberti
2021-12-09 17:12   ` Juri Linkov
2021-12-09 22:52     ` André A. Gomes
2021-12-08 20:52 ` [External] : " Drew Adams
2021-12-09  8:30   ` Daniel Fleischer
2021-12-09 17:16   ` Juri Linkov
2021-12-09 18:13     ` [External] : " Drew Adams
2021-12-09  7:51 ` Manuel Uberti
2021-12-09 17:18   ` Juri Linkov
2021-12-09 17:40     ` Manuel Uberti
2022-06-09  7:01 ` Juri Linkov [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=86czfifgzq.fsf@mail.linkov.net \
    --to=juri@linkov.net \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).