From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Kyle Meyer Newsgroups: gmane.emacs.bugs Subject: bug#26313: 25.1; completion: display-sort-function=identity shows reverse Date: Thu, 30 Mar 2017 14:34:47 -0400 Message-ID: <87lgrm7gvs.fsf@kyleam.com> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1490898979 25006 195.159.176.226 (30 Mar 2017 18:36:19 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Thu, 30 Mar 2017 18:36:19 +0000 (UTC) To: 26313@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Thu Mar 30 20:36:11 2017 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ctevY-0005S5-61 for geb-bug-gnu-emacs@m.gmane.org; Thu, 30 Mar 2017 20:36:08 +0200 Original-Received: from localhost ([::1]:37170 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ctevd-00067S-7K for geb-bug-gnu-emacs@m.gmane.org; Thu, 30 Mar 2017 14:36:13 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:51307) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ctevW-000670-9b for bug-gnu-emacs@gnu.org; Thu, 30 Mar 2017 14:36:07 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ctevS-0000k6-Cq for bug-gnu-emacs@gnu.org; Thu, 30 Mar 2017 14:36:06 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:54977) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ctevS-0000jz-9r for bug-gnu-emacs@gnu.org; Thu, 30 Mar 2017 14:36:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1ctevS-00022e-5S for bug-gnu-emacs@gnu.org; Thu, 30 Mar 2017 14:36:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Kyle Meyer Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 30 Mar 2017 18:36:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 26313 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.14908989057783 (code B ref -1); Thu, 30 Mar 2017 18:36:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 30 Mar 2017 18:35:05 +0000 Original-Received: from localhost ([127.0.0.1]:53175 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cteuW-00021S-Cp for submit@debbugs.gnu.org; Thu, 30 Mar 2017 14:35:05 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:59955) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cteuU-00020u-08 for submit@debbugs.gnu.org; Thu, 30 Mar 2017 14:35:02 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cteuN-0008P5-LP for submit@debbugs.gnu.org; Thu, 30 Mar 2017 14:34:56 -0400 Original-Received: from lists.gnu.org ([2001:4830:134:3::11]:45041) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cteuN-0008P1-Hr for submit@debbugs.gnu.org; Thu, 30 Mar 2017 14:34:55 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:50920) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cteuM-0005v4-3t for bug-gnu-emacs@gnu.org; Thu, 30 Mar 2017 14:34:55 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cteuI-0008N6-78 for bug-gnu-emacs@gnu.org; Thu, 30 Mar 2017 14:34:54 -0400 Original-Received: from pb-smtp2.pobox.com ([64.147.108.71]:52667 helo=sasl.smtp.pobox.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cteuI-0008MR-1w for bug-gnu-emacs@gnu.org; Thu, 30 Mar 2017 14:34:50 -0400 Original-Received: from sasl.smtp.pobox.com (unknown [127.0.0.1]) by pb-smtp2.pobox.com (Postfix) with ESMTP id 989AA6D67D for ; Thu, 30 Mar 2017 14:34:48 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=pobox.com; h=from:to :subject:date:message-id:mime-version:content-type; s=sasl; bh=R WZI0kCD8UvMuXq1Y1u6vl6CjW0=; b=guRfRtW0hPzGCNtBzkXcvptOUTAaIkvee I0WqrZ0LXuIy3MdNQTJtrZFOaXHEIbqgJXifwzBYCsShbZX3Z0pjZ729HKTeBI50 QbmMZZC7vyMCRCZq37+XavLHR+zzRjr2TklM2WsVNnbPDsz2TpUY3qY3IGqG5HDu yFj6xfqdHI= Original-Received: from pb-smtp2.nyi.icgroup.com (unknown [127.0.0.1]) by pb-smtp2.pobox.com (Postfix) with ESMTP id 902616D67C for ; Thu, 30 Mar 2017 14:34:48 -0400 (EDT) Original-Received: from localhost (unknown [24.60.167.92]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pb-smtp2.pobox.com (Postfix) with ESMTPSA id 130876D67B for ; Thu, 30 Mar 2017 14:34:48 -0400 (EDT) X-Pobox-Relay-ID: 8DB5E052-1577-11E7-B12F-FC50AE2156B6-24757444!pb-smtp2.pobox.com DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=kyleam.com; h=from:to:subject:date:message-id:mime-version:content-type; s=mesmtp; bh=RWZI0kCD8UvMuXq1Y1u6vl6CjW0=; b=onGeu/vPN4HdgZDi7VYT0XxNb8DWwcTZ7KTt7QELJkuw+qqV5qoVoy0JZ4xySS8qI9UA0fMmCReJ34hrzATOA1VHaJj687FyR0/syHXwZvRS8ahsKiRedFtV29cu+JxGyr4MN/2aK2UUJGRgvEcyUv0H11iFECNhiCtyItg1NUM= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:131104 Archived-At: 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" 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