From e030627aeb75d654e42e3e250ff108f950946a75 Mon Sep 17 00:00:00 2001 From: Adam Porter Date: Thu, 16 Mar 2023 07:39:29 -0500 Subject: [PATCH] WIP: Add display-sort-function --- org-ql-completing-read.el | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/org-ql-completing-read.el b/org-ql-completing-read.el index 127a866..0456a29 100644 --- a/org-ql-completing-read.el +++ b/org-ql-completing-read.el @@ -216,7 +216,16 @@ single predicate)." (cons 'category 'org-heading) (cons 'group-function #'group) (cons 'affixation-function #'affix) - (cons 'annotation-function #'annotate))) + (cons 'annotation-function #'annotate) + (cons 'display-sort-function + (lambda (strings) + (let ((quoted-tokens (mapcar #'regexp-quote query-tokens))) + (sort strings + (lambda (a b) + (cl-labels ((matches + (s) (cl-loop for token in quoted-tokens + count (string-match-p token s)))) + (> (matches a) (matches b)))))))))) (`t ;; (debug-message "COLLECTION:t INPUT:%S KEYS:%S" ;; input (hash-table-keys table))