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 11:43:36 -0800 Message-ID: <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 1356983102 24455 80.91.229.3 (31 Dec 2012 19:45:02 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 31 Dec 2012 19:45:02 +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 20:45:17 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 1TplIS-0001Li-T7 for geb-bug-gnu-emacs@m.gmane.org; Mon, 31 Dec 2012 20:45:17 +0100 Original-Received: from localhost ([::1]:44742 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TplID-000241-VY for geb-bug-gnu-emacs@m.gmane.org; Mon, 31 Dec 2012 14:45:01 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:54825) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TplIA-00023e-Sd for bug-gnu-emacs@gnu.org; Mon, 31 Dec 2012 14:44:59 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TplI4-0005MA-AD for bug-gnu-emacs@gnu.org; Mon, 31 Dec 2012 14:44:58 -0500 Original-Received: from debbugs.gnu.org ([140.186.70.43]:56315) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TplI4-0005M5-6M for bug-gnu-emacs@gnu.org; Mon, 31 Dec 2012 14:44:52 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.72) (envelope-from ) id 1TplJC-0000dm-Gy for bug-gnu-emacs@gnu.org; Mon, 31 Dec 2012 14:46: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 19:46:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 13322 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: X-Debbugs-Original-To: Original-Received: via spool by submit@debbugs.gnu.org id=B.13569831152404 (code B ref -1); Mon, 31 Dec 2012 19:46:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 31 Dec 2012 19:45:15 +0000 Original-Received: from localhost ([127.0.0.1]:38333 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1TplIQ-0000ci-JL for submit@debbugs.gnu.org; Mon, 31 Dec 2012 14:45:15 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:43396) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1TplIM-0000cY-JD for submit@debbugs.gnu.org; Mon, 31 Dec 2012 14:45:11 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TplHB-00051x-PA for submit@debbugs.gnu.org; Mon, 31 Dec 2012 14:43:58 -0500 Original-Received: from lists.gnu.org ([208.118.235.17]:54314) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TplHB-00051t-Lt for submit@debbugs.gnu.org; Mon, 31 Dec 2012 14:43:57 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:54748) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TplH6-00021D-0E for bug-gnu-emacs@gnu.org; Mon, 31 Dec 2012 14:43:57 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TplH4-00051F-Kc for bug-gnu-emacs@gnu.org; Mon, 31 Dec 2012 14:43:51 -0500 Original-Received: from aserp1040.oracle.com ([141.146.126.69]:22336) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TplH4-000517-EJ for bug-gnu-emacs@gnu.org; Mon, 31 Dec 2012 14:43:50 -0500 Original-Received: from acsinet21.oracle.com (acsinet21.oracle.com [141.146.126.237]) by aserp1040.oracle.com (Sentrion-MTA-4.2.2/Sentrion-MTA-4.2.2) with ESMTP id qBVJhnii002886 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 31 Dec 2012 19:43:49 GMT Original-Received: from acsmt357.oracle.com (acsmt357.oracle.com [141.146.40.157]) by acsinet21.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id qBVJhmle024108 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Mon, 31 Dec 2012 19:43:48 GMT Original-Received: from abhmt106.oracle.com (abhmt106.oracle.com [141.146.116.58]) by acsmt357.oracle.com (8.12.11.20060308/8.12.11) with ESMTP id qBVJhmbK026542 for ; Mon, 31 Dec 2012 13:43:48 -0600 Original-Received: from dradamslap1 (/10.159.239.69) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 31 Dec 2012 11:43:48 -0800 X-Mailer: Microsoft Office Outlook 11 Thread-Index: Ac3njx/09sAl+Gs3Ssakntmb33Z2+A== X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.6157 X-Source-IP: acsinet21.oracle.com [141.146.126.237] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] 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.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:69251 Archived-At: 1. Please provide for `completion-all-sorted-completions' to sort using a function other than what is returned by `cycle-sort-function' from the metadata. E.g., an optional arg SORT-FUN. 2. Please make duplicate deletion optional. E.g., an optional arg DONT-REMOVE-DUPS. Suggested code below - it just adds the args and respects them. But please also add a doc string in any case. (defun completion-all-sorted-completions (&optional sort-fun dont-remove-dups) "FIXME - I NEED A HELPFUL DOC STRING" (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))) (unless sort-fun (setq sort-fun (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 (minibufferp) (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)))))) `completion-all-sorted-completions' currently does a mix of things. Perhaps those things should be separated into different functions that users could use on their own. Is there a good reason to couple these things? a. calculation of the completions b. duplicate deletion c. sorting d. caching Dunnow whether caching should be separated out, but perhaps b and c could be. In GNU Emacs 24.3.50.1 (i386-mingw-nt5.1.2600) of 2012-12-18 on MS-W7-DANI Bzr revision: 111265 eliz@gnu.org-20121218190556-x9wmq083vwecgu0f Windowing system distributor `Microsoft Corp.', version 5.1.2600 Configured using: `configure --with-gcc (4.7) --no-opt --enable-checking --cflags -Ic:/emacs/libs/libXpm-3.5.10/include -Ic:/emacs/libs/libXpm-3.5.10/src -Ic:/emacs/libs/libpng-dev_1.4.3-1_win32/include -Ic:/emacs/libs/zlib-dev_1.2.5-2_win32/include -Ic:/emacs/libs/giflib-4.1.4-1-lib/include -Ic:/emacs/libs/jpeg-6b-4-lib/include -Ic:/emacs/libs/tiff-3.8.2-1-lib/include -Ic:/emacs/libs/libxml2-2.7.8-w32-bin/include/libxml2 -Ic:/emacs/libs/gnutls-3.0.9-w32-bin/include -Ic:/emacs/libs/libiconv-1.9.2-1-lib/include'