all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Antoine Levitt <antoine.levitt@gmail.com>
To: bbdb-info@lists.sourceforge.net
Cc: emacs-devel@gnu.org
Subject: Re: (patch) sort cycling completion candidates
Date: Tue, 08 Mar 2011 16:32:00 +0100	[thread overview]
Message-ID: <87y64paarz.fsf@gmail.com> (raw)
In-Reply-To: 87mxl5bqcg.fsf@jumptrading.com

08/03/11 16:10, Ted Zlatanov
> Attached please find a patch to sort cycling completion candidates by
> the text property :completion-cycle-penalty (lower is better).
>
> Thanks
> Ted
>
>
> === modified file 'lisp/minibuffer.el'
> --- lisp/minibuffer.el	2011-02-12 18:30:13 +0000
> +++ lisp/minibuffer.el	2011-03-08 14:51:07 +0000
> @@ -704,7 +704,19 @@
>          (when last
>            (setcdr last nil)
>            ;; Prefer shorter completions.
> -          (setq all (sort all (lambda (c1 c2) (< (length c1) (length c2)))))
> +          (setq
> +           all
> +           (sort all
> +                 (lambda (c1 c2)
> +                   (let ((s1 (get-text-property
> +                              0 :completion-cycle-penalty c1))
> +                         (s2 (get-text-property
> +                              0 :completion-cycle-penalty c2)))
> +                     (cond ((and s1 s2) (cond ((< s1 s2) t)
> +                                              ((> s1 s2) nil)
> +                                              (t (< (length c1) (length c2)))))
> +                           (s1 t)
> +                           (s2 nil))))))
>            ;; Prefer recently used completions.
>            (let ((hist (symbol-value minibuffer-history-variable)))
>              (setq all (sort all (lambda (c1 c2)


What about the case when s1 and s2 are nil? Shouldn't there be another
(t (< (length c1) (length c2))) at the end of the second cond ? Am I
missing something?

It seems cleaner to sort two times, instead of once with both
predicates, the way it's already done in the code for recently used
completions.

Also, the comment needs changing.

What about this?

diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el
index 3c8628c..f4af7f3 100644
--- a/lisp/minibuffer.el
+++ b/lisp/minibuffer.el
@@ -710,6 +710,13 @@ scroll the window of possible completions."
             (setq all (sort all (lambda (c1 c2)
                                   (> (length (member c1 hist))
                                      (length (member c2 hist)))))))
+	  ;; Use the completion-cycle-penalty property
+	  (setq all (sort all (lambda (c1 c2)
+				(let ((s1 (get-text-property
+					   0 :completion-cycle-penalty c1))
+				      (s2 (get-text-property
+					   0 :completion-cycle-penalty c2)))
+				  (and s1 (or (not s2) (< s1 s2)))))))
           ;; Cache the result.  This is not just for speed, but also so that
           ;; repeated calls to minibuffer-force-complete can cycle through
           ;; all possibilities.


------------------------------------------------------------------------------
What You Don't Know About Data Connectivity CAN Hurt You
This paper provides an overview of data connectivity, details
its effect on application quality, and explores various alternative
solutions. http://p.sf.net/sfu/progress-d2d
_______________________________________________
bbdb-info@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bbdb-info
BBDB Home Page: http://bbdb.sourceforge.net/


  reply	other threads:[~2011-03-08 15:32 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <87wrlfv9vs.fsf@gmail.com>
     [not found] ` <87hbchkru0.fsf@gmail.com>
     [not found]   ` <19790.55748.877481.348512@gargle.gargle.HOWL>
     [not found]     ` <87r5bljcf1.fsf@gmail.com>
     [not found]       ` <jwvd3mzs2cw.fsf-monnier+gmane.emacs.bbdb.user@gnu.org>
     [not found]         ` <19797.17272.589272.209237@gargle.gargle.HOWL>
     [not found]           ` <jwvwrl6p57f.fsf-monnier+INBOX@gnu.org>
     [not found]             ` <19797.51331.541498.485483@gargle.gargle.HOWL>
     [not found]               ` <jwvvd0qnfz4.fsf-monnier+emacs@gnu.org>
     [not found]                 ` <19798.51132.460403.212914@gargle.gargle.HOWL>
     [not found]                   ` <8739nr3ni1.fsf@lifelogs.com>
     [not found]                     ` <19800.2420.143963.914603@gargle.gargle.HOWL>
     [not found]                       ` <jwvy65jm77n.fsf-monnier+gmane.emacs.bbdb.user@gnu.org>
     [not found]                         ` <87bp2aziyf.fsf@lifelogs.com>
     [not found]                           ` <87bp22ldxh.fsf@lifelogs.com>
     [not found]                             ` <19818.50284.187613.9352@gargle.gargle.HOWL>
     [not found]                               ` <jwvbp1w4ucb.fsf-monnier+gmane.emacs.bbdb.user@gnu.org>
     [not found]                                 ` <87fwr82gpg.fsf@lifelogs.com>
     [not found]                                   ` <jwv7hcj3enw.fsf-monnier+gmane.emacs.bbdb.user@gnu.org>
     [not found]                                     ` <87lj0yvodp.fsf@lifelogs.com>
     [not found]                                       ` <jwvy64tu0nw.fsf-monnier+gmane.emacs.bbdb.user@gnu.org>
2011-03-08 15:10                                         ` (patch) sort cycling completion candidates (was: bbdb-complete-name return value) Ted Zlatanov
2011-03-08 15:32                                           ` Antoine Levitt [this message]
2011-03-08 16:34                                             ` (patch) sort cycling completion candidates Ted Zlatanov
2011-03-15  2:07                                             ` Ted Zlatanov
2011-03-15  2:59                                               ` Stefan Monnier
2011-03-15  9:26                                                 ` Ted Zlatanov
2011-03-20  2:40                                                   ` Stefan Monnier
2011-03-21 18:46                                                     ` Ted Zlatanov
2011-03-21 22:08                                                       ` Stefan Monnier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87y64paarz.fsf@gmail.com \
    --to=antoine.levitt@gmail.com \
    --cc=bbdb-info@lists.sourceforge.net \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.