From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.devel Subject: Re: History completion Date: Thu, 09 Jun 2022 10:01:53 +0300 Organization: LINKOV.NET Message-ID: <86czfifgzq.fsf@mail.linkov.net> References: <86mtlbvuq2.fsf@mail.linkov.net> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="30955"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (x86_64-pc-linux-gnu) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Thu Jun 09 09:20:32 2022 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nzCT1-0007tI-2H for ged-emacs-devel@m.gmane-mx.org; Thu, 09 Jun 2022 09:20:31 +0200 Original-Received: from localhost ([::1]:38566 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nzCSz-000633-7F for ged-emacs-devel@m.gmane-mx.org; Thu, 09 Jun 2022 03:20:29 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:48954) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nzCP7-0003f6-28 for emacs-devel@gnu.org; Thu, 09 Jun 2022 03:16:31 -0400 Original-Received: from relay5-d.mail.gandi.net ([217.70.183.197]:45771) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nzCP2-0005GH-To for emacs-devel@gnu.org; Thu, 09 Jun 2022 03:16:28 -0400 Original-Received: (Authenticated sender: juri@linkov.net) by mail.gandi.net (Postfix) with ESMTPSA id F20F21C0003 for ; Thu, 9 Jun 2022 07:16:19 +0000 (UTC) In-Reply-To: <86mtlbvuq2.fsf@mail.linkov.net> (Juri Linkov's message of "Wed, 08 Dec 2021 20:54:40 +0200") Received-SPF: pass client-ip=217.70.183.197; envelope-from=juri@linkov.net; helo=relay5-d.mail.gandi.net X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:290963 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit > 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: --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=minibuffer-complete-history.patch 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, --=-=-=--