From: Juri Linkov <juri@linkov.net>
To: emacs-devel@gnu.org
Subject: Sorting command completions by recency
Date: Wed, 17 Feb 2021 19:53:55 +0200 [thread overview]
Message-ID: <875z2qslwk.fsf@mail.linkov.net> (raw)
[-- Attachment #1: Type: text/plain, Size: 472 bytes --]
The recent discussion about filtering out command completions by mode
reminded the problem that while icomplete shows the most recently used
commands at the top of the list for M-x, trying to see a complete list
with TAB changes the order of displayed commands, i.e. in icomplete
there is one sorting order by recency, but in the *Completions* buffer
alphabetical sorting order.
This code puts the recent commands at the top as well,
but probably it needs to be opt-in:
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: sort-extended-command.patch --]
[-- Type: text/x-diff, Size: 1478 bytes --]
diff --git a/lisp/simple.el b/lisp/simple.el
index 80bc968950..838f344ab5 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -1969,6 +1969,23 @@ read-extended-command
(lambda (string pred action)
(if (and suggest-key-bindings (eq action 'metadata))
'(metadata
+ (display-sort-function
+ . (lambda (commands)
+ (if (minibufferp)
+ ;; Prefer recently used completions and put the default,
+ ;; if it exists, on top.
+ (let ((hist (symbol-value minibuffer-history-variable)))
+ (sort commands
+ (lambda (c1 c2)
+ (cond ((equal c1 minibuffer-default) t)
+ ((equal c2 minibuffer-default) nil)
+ ((and (member c1 hist) (member c2 hist))
+ (> (length (member c1 hist))
+ (length (member c2 hist))))
+ ((member c1 hist) t)
+ ((member c2 hist) nil)
+ (t (string-lessp c1 c2))))))
+ commands)))
(affixation-function . read-extended-command--affixation)
(category . command))
(complete-with-action action obarray string pred)))
next reply other threads:[~2021-02-17 17:53 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-02-17 17:53 Juri Linkov [this message]
2021-02-17 18:33 ` Sorting command completions by recency Lars Ingebrigtsen
2021-02-17 19:55 ` Stefan Monnier
2021-02-17 20:03 ` Clemens
2021-02-17 20:58 ` Stefan Monnier
2021-02-18 17:34 ` Juri Linkov
2021-02-17 20:09 ` Juri Linkov
2021-02-17 22:02 ` [External] : " Drew Adams
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=875z2qslwk.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 external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.