(patch) sort cycling completion candidates (was: bbdb-complete-name return value)

2011-03-08 Thread 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 +
+++ lisp/minibuffer.el	2011-03-08 14:51:07 +
@@ -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 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/

Re: (patch) sort cycling completion candidates

2011-03-08 Thread Antoine Levitt
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.el2011-02-12 18:30:13 +
 +++ lisp/minibuffer.el2011-03-08 14:51:07 +
 @@ -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/


Re: (patch) sort cycling completion candidates

2011-03-08 Thread Ted Zlatanov
On Tue, 08 Mar 2011 16:32:00 +0100 Antoine Levitt antoine.lev...@gmail.com 
wrote: 

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

Oops.  I had it in my original patch but Stefan suggested a change
before that line and I accidentally deleted it.  Sorry!

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

That seems OK to me.

Your patch is cleaner so I'm in favor of using it.

Ted


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