all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* ordering candidates when using completion-at-point-functions
@ 2013-06-29  9:43 Dirk-Jan C. Binnema
  2013-07-04  0:32 ` Stefan Monnier
  0 siblings, 1 reply; 4+ messages in thread
From: Dirk-Jan C. Binnema @ 2013-06-29  9:43 UTC (permalink / raw)
  To: help-gnu-emacs@gnu.org

Hi all,

I'm using completion-at-point-functions to do address-completion in
mu4e, an email-client that I wrote. This works fine [1]; however, by
default, it seems the candidates are in alphabetical order.

Instead, I would like to deliver the candidates in order of frequency; I
already got my list of contacts sorted in the right order, so all that's
needed (as far as I can see) is to have the completion system /not/ do
any sorting of its own, but just deliver the candidates in the same
order as in the list I provide. Is this possible? And, if so, how?

(An alternative might be to use a display-sort-function; it seems the
current org-contacts[2] does something like that; but this seems /very/
complicated solution, which is hopefully not necessary for my modest
needs...)

Thanks,
Dirk.

[1] https://github.com/djcb/mu/blob/master/mu4e/mu4e-compose.el#L495
[2] http://orgmode.org/cgit.cgi/org-mode.git/tree/contrib/lisp/org-contacts.el

-- 
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



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: ordering candidates when using completion-at-point-functions
  2013-06-29  9:43 ordering candidates when using completion-at-point-functions Dirk-Jan C. Binnema
@ 2013-07-04  0:32 ` Stefan Monnier
  2013-07-04  5:02   ` Dirk-Jan C. Binnema
  0 siblings, 1 reply; 4+ messages in thread
From: Stefan Monnier @ 2013-07-04  0:32 UTC (permalink / raw)
  To: Dirk-Jan C. Binnema; +Cc: help-gnu-emacs@gnu.org

> Instead, I would like to deliver the candidates in order of frequency; I

What do you mean by "deliver"?

> (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.


        Stefan



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: ordering candidates when using completion-at-point-functions
  2013-07-04  0:32 ` Stefan Monnier
@ 2013-07-04  5:02   ` Dirk-Jan C. Binnema
  2013-07-04  5:23     ` Jambunathan K
  0 siblings, 1 reply; 4+ messages in thread
From: Dirk-Jan C. Binnema @ 2013-07-04  5:02 UTC (permalink / raw)
  To: help-gnu-emacs@gnu.org

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



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: ordering candidates when using completion-at-point-functions
  2013-07-04  5:02   ` Dirk-Jan C. Binnema
@ 2013-07-04  5:23     ` Jambunathan K
  0 siblings, 0 replies; 4+ messages in thread
From: Jambunathan K @ 2013-07-04  5:23 UTC (permalink / raw)
  To: Dirk-Jan C. Binnema; +Cc: help-gnu-emacs@gnu.org

Dirk-Jan C. Binnema <djcb@djcbsoftware.nl> writes:

> That is, the results are ordered alphabetically, rather than the 1-2-3-4
> order I would like, as in my already-sorted list.

I don't mean to hijack this thread.  But this touches upon something I
desire.

I would like my completions (of command names) sorted alphabetically
(but with the most recent used ones given a higher preference).  The
current sorting mechanism - sort by length, sort lexicographically - is
confusing.  The primary reason for the confusion is the difficulty in
"anticipate"-ing what one is presented with.  One really doesn't know
how far deep down in the dictionary one is.

Anyways, just a minor tangential comment.





^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2013-07-04  5:23 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-06-29  9:43 ordering candidates when using completion-at-point-functions Dirk-Jan C. Binnema
2013-07-04  0:32 ` Stefan Monnier
2013-07-04  5:02   ` Dirk-Jan C. Binnema
2013-07-04  5:23     ` Jambunathan K

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.