From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Drew Adams" Newsgroups: gmane.emacs.bugs Subject: bug#13322: 24.3.50; `completion-all-sorted-completions': sorting and duplicate deletion Date: Mon, 31 Dec 2012 13:10:55 -0800 Message-ID: <64F4026487BC4A83892CBBC7C0BCE7D1@us.oracle.com> References: <62F6B49F5A0840038CF7139810B32470@us.oracle.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1356988316 29756 80.91.229.3 (31 Dec 2012 21:11:56 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 31 Dec 2012 21:11:56 +0000 (UTC) To: <13322@debbugs.gnu.org> Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Mon Dec 31 22:12:12 2012 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Tpmea-00060O-DJ for geb-bug-gnu-emacs@m.gmane.org; Mon, 31 Dec 2012 22:12:12 +0100 Original-Received: from localhost ([::1]:42218 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TpmeL-00042r-9E for geb-bug-gnu-emacs@m.gmane.org; Mon, 31 Dec 2012 16:11:57 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:38177) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TpmeI-00042j-UN for bug-gnu-emacs@gnu.org; Mon, 31 Dec 2012 16:11:55 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TpmeE-0002nz-OI for bug-gnu-emacs@gnu.org; Mon, 31 Dec 2012 16:11:54 -0500 Original-Received: from debbugs.gnu.org ([140.186.70.43]:56419) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TpmeE-0002nv-LV for bug-gnu-emacs@gnu.org; Mon, 31 Dec 2012 16:11:50 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.72) (envelope-from ) id 1TpmfO-0005Sd-0s for bug-gnu-emacs@gnu.org; Mon, 31 Dec 2012 16:13:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: "Drew Adams" Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 31 Dec 2012 21:13:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 13322 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 13322-submit@debbugs.gnu.org id=B13322.135698834620940 (code B ref 13322); Mon, 31 Dec 2012 21:13:01 +0000 Original-Received: (at 13322) by debbugs.gnu.org; 31 Dec 2012 21:12:26 +0000 Original-Received: from localhost ([127.0.0.1]:38437 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1Tpmen-0005Rg-OK for submit@debbugs.gnu.org; Mon, 31 Dec 2012 16:12:26 -0500 Original-Received: from aserp1040.oracle.com ([141.146.126.69]:50990) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1Tpmej-0005RX-3U for 13322@debbugs.gnu.org; Mon, 31 Dec 2012 16:12:21 -0500 Original-Received: from ucsinet21.oracle.com (ucsinet21.oracle.com [156.151.31.93]) by aserp1040.oracle.com (Sentrion-MTA-4.2.2/Sentrion-MTA-4.2.2) with ESMTP id qBVLB8Nn020874 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for <13322@debbugs.gnu.org>; Mon, 31 Dec 2012 21:11:08 GMT Original-Received: from acsmt357.oracle.com (acsmt357.oracle.com [141.146.40.157]) by ucsinet21.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id qBVLB7PZ017938 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for <13322@debbugs.gnu.org>; Mon, 31 Dec 2012 21:11:07 GMT Original-Received: from abhmt104.oracle.com (abhmt104.oracle.com [141.146.116.56]) by acsmt357.oracle.com (8.12.11.20060308/8.12.11) with ESMTP id qBVLB79I031564 for <13322@debbugs.gnu.org>; Mon, 31 Dec 2012 15:11:07 -0600 Original-Received: from dradamslap1 (/10.159.239.69) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 31 Dec 2012 13:11:06 -0800 X-Mailer: Microsoft Office Outlook 11 In-reply-to: <62F6B49F5A0840038CF7139810B32470@us.oracle.com> Thread-Index: Ac3njx/09sAl+Gs3Ssakntmb33Z2+AAC793g X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.6157 X-Source-IP: ucsinet21.oracle.com [156.151.31.93] X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 140.186.70.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-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:69259 Archived-At: Oops. Forgot to handle the second sorting occurrence also. If a user supplies a sort function then we should not overrule that to re-sort by history. This code should do it (but the code is just a suggestion, again): (defun completion-all-sorted-completions (&optional sort-function dont-remove-dups) "Like `c-a-s-c', but with added optional args." (or completion-all-sorted-completions (let* ((start (field-beginning)) (end (field-end)) (string (buffer-substring start end)) (md (completion--field-metadata start)) (all (completion-all-completions string minibuffer-completion-table minibuffer-completion-predicate (- (point) start) md)) (last (last all)) (base-size (or (cdr last) 0)) (all-md (completion--metadata (buffer-substring-no-properties start (point)) base-size md minibuffer-completion-table minibuffer-completion-predicate)) (sort-fun (or sort-function (completion-metadata-get all-md 'cycle-sort-function)))) (when last (setcdr last nil) ;; Delete duplicates: do it after setting last's cdr to nil (so ;; it's a proper list), and be careful to reset `last' since it ;; may be a different cons-cell. (unless dont-remove-dups (setq all (delete-dups all))) (setq last (last all)) (setq all (if sort-fun (funcall sort-fun all) ;; Prefer shorter completions, by default. (sort all (lambda (c1 c2) (< (length c1) (length c2)))))) ;; Prefer recently used completions. (when (and (minibufferp) (not sort-fun)) (let ((hist (symbol-value minibuffer-history-variable))) (setq all (sort all (lambda (c1 c2) (> (length (member c1 hist)) (length (member c2 hist)))))))) ;; Cache the result. This is not just for speed, but also so that ;; repeated calls to minibuffer-force-complete can cycle through ;; all possibilities. (completion--cache-all-sorted-completions (nconc all base-size))))))