* bug#26313: 25.1; completion: display-sort-function=identity shows reverse
@ 2017-03-30 18:34 Kyle Meyer
2017-03-30 19:03 ` Noam Postavsky
0 siblings, 1 reply; 3+ messages in thread
From: Kyle Meyer @ 2017-03-30 18:34 UTC (permalink / raw
To: 26313
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
^ permalink raw reply related [flat|nested] 3+ messages in thread
* bug#26313: 25.1; completion: display-sort-function=identity shows reverse
2017-03-30 18:34 bug#26313: 25.1; completion: display-sort-function=identity shows reverse Kyle Meyer
@ 2017-03-30 19:03 ` Noam Postavsky
2017-03-30 19:21 ` Kyle Meyer
0 siblings, 1 reply; 3+ messages in thread
From: Noam Postavsky @ 2017-03-30 19:03 UTC (permalink / raw
To: Kyle Meyer; +Cc: 26313
forcemerge 24676 26313
quit
On Thu, Mar 30, 2017 at 2:34 PM, Kyle Meyer <kyle@kyleam.com> wrote:
>
> Should completion-pcm--all-completions reverse the list before returning
> it?
Yeah, it was suggested and approved in
https://debbugs.gnu.org/cgi/bugreport.cgi?bug=24676#11, but never
installed.
Also related, completion-pcm--filename-try-filter has the same
problem: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=25995#8
^ permalink raw reply [flat|nested] 3+ messages in thread
* bug#26313: 25.1; completion: display-sort-function=identity shows reverse
2017-03-30 19:03 ` Noam Postavsky
@ 2017-03-30 19:21 ` Kyle Meyer
0 siblings, 0 replies; 3+ messages in thread
From: Kyle Meyer @ 2017-03-30 19:21 UTC (permalink / raw
To: Noam Postavsky; +Cc: 26313
Noam Postavsky <npostavs@users.sourceforge.net> writes:
> On Thu, Mar 30, 2017 at 2:34 PM, Kyle Meyer <kyle@kyleam.com> wrote:
>>
>> Should completion-pcm--all-completions reverse the list before returning
>> it?
>
> Yeah, it was suggested and approved in
> https://debbugs.gnu.org/cgi/bugreport.cgi?bug=24676#11, but never
> installed.
Thanks. Sorry for missing that report.
--
Kyle
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2017-03-30 19:21 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-03-30 18:34 bug#26313: 25.1; completion: display-sort-function=identity shows reverse Kyle Meyer
2017-03-30 19:03 ` Noam Postavsky
2017-03-30 19:21 ` Kyle Meyer
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.