From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Dirk-Jan C. Binnema Newsgroups: gmane.emacs.help Subject: Re: ordering candidates when using completion-at-point-functions Date: Thu, 04 Jul 2013 08:02:08 +0300 Message-ID: <87haga9aun.fsf@djcbsoftware.nl> References: <87wqpd2qx9.fsf@djcbsoftware.nl> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1372914154 3737 80.91.229.3 (4 Jul 2013 05:02:34 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 4 Jul 2013 05:02:34 +0000 (UTC) To: "help-gnu-emacs\@gnu.org" Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Jul 04 07:02:36 2013 Return-path: Envelope-to: geh-help-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 1Uubgg-0002FY-CZ for geh-help-gnu-emacs@m.gmane.org; Thu, 04 Jul 2013 07:02:34 +0200 Original-Received: from localhost ([::1]:55847 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Uubgg-0006Jv-0s for geh-help-gnu-emacs@m.gmane.org; Thu, 04 Jul 2013 01:02:34 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:41675) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UubgR-0006Jc-2e for help-gnu-emacs@gnu.org; Thu, 04 Jul 2013 01:02:24 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UubgM-0005h9-Rw for help-gnu-emacs@gnu.org; Thu, 04 Jul 2013 01:02:19 -0400 Original-Received: from mail-lb0-x231.google.com ([2a00:1450:4010:c04::231]:43758) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UubgM-0005gz-KT for help-gnu-emacs@gnu.org; Thu, 04 Jul 2013 01:02:14 -0400 Original-Received: by mail-lb0-f177.google.com with SMTP id 10so828774lbf.8 for ; Wed, 03 Jul 2013 22:02:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:references:user-agent:from:to:subject:in-reply-to:date :message-id:mime-version:content-type; bh=sMHqWR+IPnEM3AiOTuCYUS4+tA8tK+0avVJgFMqwR6A=; b=HxmkeBCO8HnWq7L9BHOBOCH2EYpxBBUoLq6HtXucmhKazFmgVjFmYlSuKeRzqsUxLd kihEbbJDLCWjjJsOrgK67hW3WC28aLzDY6gwJcRL23RoEFNoNCgJt/z6n/GcBVApMTZU KTlB6fvID1UPvI0/6eNsd62/0aXGJs4sa9vBo6cWs/q2+wiwAybsNvslU1M1VLnPWo17 ogkQMeWjVG4VUdaCVv/sHwkvh95VGbNgLkUxHL+rPydAcrezbR05Vpj8vzuvOS/9H7MQ w9sflDblpefuzbD2zbA9Qd4V/OsjmlKBGYiB/xFpZzaoSKWmVbwuziI7kn5wFJcfOgxg NHdQ== X-Received: by 10.152.19.70 with SMTP id c6mr2006024lae.13.1372914133352; Wed, 03 Jul 2013 22:02:13 -0700 (PDT) Original-Received: from borealis (a88-112-252-184.elisa-laajakaista.fi. [88.112.252.184]) by mx.google.com with ESMTPSA id am8sm398586lac.1.2013.07.03.22.02.10 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Wed, 03 Jul 2013 22:02:12 -0700 (PDT) User-agent: mu4e 0.9.9.5; emacs 24.3.50.21 In-reply-to: X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:4010:c04::231 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:91922 Archived-At: Hi Stefan, On Thu, Jul 04 2013, monnier@IRO.UMontreal.CA wrote: >> Instead, I would like to deliver the candidates in order of frequency; I > > What do you mean by "deliver"? Well, I mean the order in which the candidates are presented in the *Completions* buffers, as well as the order in which in can cycle through them. >> (An alternative might be to use a display-sort-function; it seems the > > Using display-sort-function sounds about right, yes. >> current org-contacts[2] does something like that; but this seems /very/ >> complicated solution, which is hopefully not necessary for my modest >> needs...) > > Which part do you find complicated? We can probably provide some helper > function to make it simpler. So, boiled down to the essentials, I have something like this for my message-composition buffer: ---- ;; already sorted (setq candidates'("foo1@example.com" "fnorb2@example.com" "cuux3@example.com" "bar4example.com")) (defun my-completion-function (&optional start) (let ((end (point)) (start (or start (save-excursion (re-search-backward "\\(\\`\\|[\n:,]\\)[ \t]*") (goto-char (match-end 0)) (point))))) (list start (point) candidates))) (add-to-list 'completion-at-point-functions 'my-completion-function) --- So, completing after e.g. "To: ", I get: ---- Possible completions are: bar4@example.com cuux2@example.com fnorb3@example.com foo1@example.com ---- That is, the results are ordered alphabetically, rather than the 1-2-3-4 order I would like, as in my already-sorted list. So, my question is how I can influence the sorting order -- either by telling the completion machinery to not try to sort my candidates, or, if that's not possible, to provide a display-sort-function and/or cycle-sort-function. I tried to write a completion function as per https://www.gnu.org/software/emacs/manual/html_node/elisp/Programmed-Completion.html (and org-contacts, `org-contacts-make-collection-prefix'), but that seems quite a bit of complexity, just to set the sort-functions to identity. Maybe I'm missing something obvious -- or would that be the right way to go forward anyway? Kind regards, Dirk. -- Dirk-Jan C. Binnema Helsinki, Finland e:djcb@djcbsoftware.nl w:www.djcbsoftware.nl pgp: D09C E664 897D 7D39 5047 A178 E96A C7A1 017D DA3C