From: Kyle Meyer <kyle@kyleam.com>
To: 26313@debbugs.gnu.org
Subject: bug#26313: 25.1; completion: display-sort-function=identity shows reverse
Date: Thu, 30 Mar 2017 14:34:47 -0400 [thread overview]
Message-ID: <87lgrm7gvs.fsf@kyleam.com> (raw)
I'm trying to make the *Completions* help buffer display the collection
in the original order passed to completing-read. I found a question
about this on Emacs StackExchange [*1*], and Stefan's advice was to
specify display-sort-function for the completion table.
(defun my-presorted-completion-table (completions)
(lambda (string pred action)
(if (eq action 'metadata)
`(metadata (display-sort-function . ,#'identity))
(complete-with-action action completions string pred))))
(completing-read "test: " (my-presorted-completion-table
'("d" "e" "a" "r")))
Hitting tab to bring up the help buffer shows that this does override
the default alphabetical sorting, but it displays the list in reverse,
with "r" as the first item [*2*].
Replacing "identity" with "nreverse" shows the list in the expected
order. It seems that the collection needs to be reversed to get the
original order because completion-pcm--all-completions returns the items
in reverse, constructing the list with "(dolist _ (push ...))".
However, using nreverse for the display-sort-function messes up the
order displayed for partial completions because
completion-pcm--all-completions returns the result of all-completions
rather than following the "dolist" path described above. For example,
(completing-read "test: " (my-presorted-completion-table
'("db" "dd" "da" "e" "a" "r")))
with "d<TAB>" now shows "da dd db" instead of "db dd da".
Should completion-pcm--all-completions reverse the list before returning
it? With identity as the display-sort-function, this change appears to
give the correct order for both cases above (empty input and partial
input).
--8<---------------cut here---------------start------------->8---
diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el
index 355d2ee6af..2e2c55db5e 100644
--- a/lisp/minibuffer.el
+++ b/lisp/minibuffer.el
@@ -2994,7 +2994,7 @@ completion-pcm--all-completions
(let ((poss ()))
(dolist (c compl)
(when (string-match-p regex c) (push c poss)))
- poss)))))
+ (nreverse poss))))))
(defun completion-pcm--hilit-commonality (pattern completions)
(when completions
--8<---------------cut here---------------end--------------->8---
[*1*] http://emacs.stackexchange.com/questions/8115/make-completing-read-respect-sorting-order-of-a-collection/8177#8177
[*2*] Evaluated in a buffer visited with "emacs -Q", Emacs 25.1.1
--
Kyle
next reply other threads:[~2017-03-30 18:34 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-30 18:34 Kyle Meyer [this message]
2017-03-30 19:03 ` bug#26313: 25.1; completion: display-sort-function=identity shows reverse Noam Postavsky
2017-03-30 19:21 ` Kyle Meyer
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=87lgrm7gvs.fsf@kyleam.com \
--to=kyle@kyleam.com \
--cc=26313@debbugs.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.