[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: ordering candidates when using completion-at-point-functions

From: Dirk-Jan C . Binnema
Subject: Re: ordering candidates when using completion-at-point-functions
Date: Thu, 04 Jul 2013 08:02:08 +0300
User-agent: mu4e; emacs

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'("" ""
                   "" ""))

(defun my-completion-function (&optional start)
  (let ((end (point))
         (start (or start
                    (re-search-backward "\\(\\`\\|[\n:,]\\)[ \t]*")
                    (goto-char (match-end 0))
    (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:  

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

I tried to write a completion function as per
(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-Jan C. Binnema                  Helsinki, Finland 
pgp: D09C E664 897D 7D39 5047 A178 E96A C7A1 017D DA3C

reply via email to

[Prev in Thread] Current Thread [Next in Thread]