diff --git a/org-sync.el b/org-sync.el index f460e3d..49feb54 100644 --- a/org-sync.el +++ b/org-sync.el @@ -345,22 +345,56 @@ Return ELEM if it was added, nil otherwise." (url-hexify-string (cdr p)))) final "&")))) -;; OPEN bugs sorted by mod time then CLOSED bugs sorted by mod time + +;; KEY is a function returning alist of tuples of (value, =value, )) + (,id . (= . <))))) + + (defun org-sync-bug-sort (a b) - "Return non-nil if bug A should appear before bug B." - (cl-flet ((time-less-safe (a b) - (if (and a b) - (time-less-p a b) - (or a b)))) - (let* ((ao (eq 'open (org-sync-get-prop :status a))) - (bc (not (eq 'open (org-sync-get-prop :status b)))) - (am (time-less-safe - (org-sync-get-prop :date-modification b) - (org-sync-get-prop :date-modification a)))) - (or - (and ao am) - (and bc am) - (and ao bc))))) + (funcall (key-to-comparator 'org-sync-cmp-key) a b)) + (defun org-sync-buglist-to-element (bl) "Return buglist BL as an element." diff --git a/test/compare-test.el b/test/compare-test.el new file mode 100644 index 0000000..e9c48ab --- /dev/null +++ b/test/compare-test.el @@ -0,0 +1,14 @@ +(require 'org-sync) + +(ert-deftest test-key-to-comparator () + (defun my-key (s) + ; sort by decreasing length and then lexicographically + `( + (,(length s) . (= . >)) + (,s . (string= . string<)))) + + (defun predicate (a b) + (funcall (key-to-comparator 'my-key) a b)) + + (should (equal '("loooooong" "emacs" "hello" "a") + (sort '("a" "emacs" "loooooong" "hello") 'predicate))))