Skip to content

Commit

Permalink
Fixing jabber-roster-sort-items: roster shows items sorted now.
Browse files Browse the repository at this point in the history
It was not using the jabber-roster-sort-functions properly: it didn't stop
at the first ordering result (first a < b as true). Now it execute until one
of the sorting criteria returns a < b or b > a.
cngimenez committed May 18, 2022

Unverified

No user is associated with the committer email.
1 parent a863257 commit 7e082f6
Showing 2 changed files with 12 additions and 21 deletions.
13 changes: 6 additions & 7 deletions jabber.el
Original file line number Diff line number Diff line change
@@ -3817,13 +3817,12 @@ JC is the Jabber connection."
(defun jabber-roster-sort-items (a b)
"Sort roster items A and B according to `jabber-roster-sort-functions'.
Return t if A is less than B."
(dolist (fn jabber-roster-sort-functions)
(let ((comparison (funcall fn a b)))
(cond
((< comparison 0)
t)
((> comparison 0)
nil)))))
(let ((result nil))
(seq-find (lambda (fn)
(setq result (funcall fn a b))
(not (= result 0)))
jabber-roster-sort-functions)
(< result 0))))
;; jabber-roster-sort-items:1 ends here

;; [[file:jabber.org::#roster-sort-by-status][jabber-roster-sort-by-status:1]]
20 changes: 6 additions & 14 deletions jabber.org
Original file line number Diff line number Diff line change
@@ -4743,22 +4743,14 @@ JC is the Jabber connection."
(defun jabber-roster-sort-items (a b)
"Sort roster items A and B according to `jabber-roster-sort-functions'.
Return t if A is less than B."
(dolist (fn jabber-roster-sort-functions)
(let ((comparison (funcall fn a b)))
(cond
((< comparison 0)
t)
((> comparison 0)
nil)))))
(let ((result nil))
(seq-find (lambda (fn)
(setq result (funcall fn a b))
(not (= result 0)))
jabber-roster-sort-functions)
(< result 0))))
#+END_SRC

**** TODO Resolve warning
byte-compiling function throws:

: Warning: value returned from (< (funcall fn a b) 0) is unused

What should we do with the returned value of each function?

*** jabber-roster-sort-by-status :function:
:PROPERTIES:
:CUSTOM_ID: roster-sort-by-status

0 comments on commit 7e082f6

Please sign in to comment.