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: Thu, 3 Jan 2013 09:39:45 -0800 Message-ID: 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 1357234808 9523 80.91.229.3 (3 Jan 2013 17:40:08 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 3 Jan 2013 17:40:08 +0000 (UTC) Cc: 13322@debbugs.gnu.org To: "'Stefan Monnier'" Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Thu Jan 03 18:40:25 2013 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 1TqomG-0001JD-9h for geb-bug-gnu-emacs@m.gmane.org; Thu, 03 Jan 2013 18:40:24 +0100 Original-Received: from localhost ([::1]:38065 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tqom0-000864-Lr for geb-bug-gnu-emacs@m.gmane.org; Thu, 03 Jan 2013 12:40:08 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:56485) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tqolw-00083j-Ur for bug-gnu-emacs@gnu.org; Thu, 03 Jan 2013 12:40:06 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Tqolv-0002dH-Nr for bug-gnu-emacs@gnu.org; Thu, 03 Jan 2013 12:40:04 -0500 Original-Received: from debbugs.gnu.org ([140.186.70.43]:59823) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tqolv-0002aV-KF for bug-gnu-emacs@gnu.org; Thu, 03 Jan 2013 12:40:03 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.72) (envelope-from ) id 1Tqolv-00008Y-4m for bug-gnu-emacs@gnu.org; Thu, 03 Jan 2013 12:40:03 -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: Thu, 03 Jan 2013 17:40:02 +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.1357234798509 (code B ref 13322); Thu, 03 Jan 2013 17:40:02 +0000 Original-Received: (at 13322) by debbugs.gnu.org; 3 Jan 2013 17:39:58 +0000 Original-Received: from localhost ([127.0.0.1]:41841 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1Tqolp-000088-A0 for submit@debbugs.gnu.org; Thu, 03 Jan 2013 12:39:57 -0500 Original-Received: from aserp1040.oracle.com ([141.146.126.69]:50423) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1Tqolk-00007x-PD for 13322@debbugs.gnu.org; Thu, 03 Jan 2013 12:39:54 -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 r03HdlPk011946 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 3 Jan 2013 17:39:49 GMT Original-Received: from acsmt356.oracle.com (acsmt356.oracle.com [141.146.40.156]) by acsinet21.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id r03HdkBP025290 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 3 Jan 2013 17:39:47 GMT Original-Received: from abhmt120.oracle.com (abhmt120.oracle.com [141.146.116.72]) by acsmt356.oracle.com (8.12.11.20060308/8.12.11) with ESMTP id r03HdkWV002702; Thu, 3 Jan 2013 11:39:46 -0600 Original-Received: from dradamslap1 (/130.35.178.8) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 03 Jan 2013 09:39:46 -0800 X-Mailer: Microsoft Office Outlook 11 In-Reply-To: Thread-Index: Ac3p1CXKym2PZstiQi27UU3vgrQhUgAAVcYA X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.6157 X-Source-IP: acsinet21.oracle.com [141.146.126.237] 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:69338 Archived-At: > Since the completion-all-sorted-completions function just returns the > value of the completion-all-sorted-completions cache when > that cache is populated, it clearly can't take arguments since they'd > not always be obeyed. They would be obeyed whenever the function does not simply return the cached value. That's the point. Code can call `completion--flush-all-sorted-completions' when it wants `completion-all-sorted-completions' to update the cache. That function (`c--f-a-s-c') should not be "internal", BTW, IMHO. (It might also be helpful for `completion-all-sorted-completions' itself to be able to decide whether to reuse the cached value - other than testing its mere presence. It could do so based on another optional argument or on a(nother) global variable value.) FWIW, as an example, in `icomplete+.el' I use this version, which is essentially what I sent here before, but this also handles `completion-ignored-extensions' and an alist COLLECTION arg of absolute file names (for Icicles). (See also bug #12939, which has gotten no reply, about handling `completion-ignored-extensions'.) (defun icompletep-completion-all-sorted-completions (&optional sort-function dont-remove-dups) "Like `completion-all-sorted-completions', but with added optional args. If SORT-FUNCTION is nil, sort per `completion-all-sorted-completions': * per property `cycle-sort-function', if defined * else by shorter length, then by recent use." (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 ()) ;; Exclude files for `completion-ignored-extensions'. (when (or minibuffer-completing-file-name (and (boundp 'icicle-abs-file-candidates) icicle-abs-file-candidates)) (setq all (delete-if (lambda (fl) (string-match-p (regexp-opt completion-ignored-extensions) fl)) all))) (unless dont-remove-dups (setq all (delete-dups all))) (setq last (last all) all (if sort-fun (funcall sort-fun all) (sort all (lambda (c1 c2) (< (length c1) (length c2)))))) (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)))))))) (completion--cache-all-sorted-completions (nconc all base-size)))))) I call `completion--flush-all-sorted-completions' from Icicles when a user hits `C-,' in the minibuffer, which cycles to the next Icicles candidate sort order. This cache flushing makes Icomplete re-order the candidates, so the order in Icomplete reflects the new current (Icicles) sort order.