Function: custom-sort-items
custom-sort-items is a byte-compiled function defined in
cus-edit.el.gz.
Signature
(custom-sort-items ITEMS SORT-ALPHABETICALLY ORDER-GROUPS)
Documentation
Return a sorted copy of ITEMS.
ITEMS should be a list of custom-group properties.
If SORT-ALPHABETICALLY non-nil, sort alphabetically.
If ORDER-GROUPS is first order groups before non-groups, if last order
groups after non-groups, if nil do not order groups at all.
Source Code
;; Defined in /usr/src/emacs/lisp/cus-edit.el.gz
(defun custom-sort-items (items sort-alphabetically order-groups)
"Return a sorted copy of ITEMS.
ITEMS should be a list of `custom-group' properties.
If SORT-ALPHABETICALLY non-nil, sort alphabetically.
If ORDER-GROUPS is `first' order groups before non-groups, if `last' order
groups after non-groups, if nil do not order groups at all."
(sort (copy-sequence items)
(lambda (a b)
(let ((typea (nth 1 a)) (typeb (nth 1 b))
(namea (nth 0 a)) (nameb (nth 0 b)))
(cond ((not order-groups)
;; Since we don't care about A and B order, maybe sort.
(when sort-alphabetically
(string-lessp namea nameb)))
((eq typea 'custom-group)
;; If B is also a group, maybe sort. Otherwise, order A and B.
(if (eq typeb 'custom-group)
(when sort-alphabetically
(string-lessp namea nameb))
(eq order-groups 'first)))
((eq typeb 'custom-group)
;; Since A cannot be a group, order A and B.
(eq order-groups 'last))
(sort-alphabetically
;; Since A and B cannot be groups, sort.
(string-lessp namea nameb)))))))