Function: compat--sort
compat--sort is a byte-compiled function defined in compat-30.el.
Signature
(compat--sort SEQ &optional LESSP &rest REST)
Documentation
[Compatibility function for sort, defined in Emacs 30.1. See (compat) Emacs
30.1' for more details.]
Sort function with support for keyword arguments. The following arguments are defined:
:key FUNC -- FUNC is a function that takes a single element from SEQ and returns
the key value to be used in comparison. If absent or nil, identity is used.
:lessp FUNC -- FUNC is a function that takes two arguments and returns non-nil
if the first element should come before the second. If absent or nil,
value< is used.
:reverse BOOL -- if BOOL is non-nil, the sorting order implied by FUNC is
reversed. This does not affect stability: equal elements still retain their
order in the input sequence.
:in-place BOOL -- if BOOL is non-nil, SEQ is sorted in-place and returned.
Otherwise, a sorted copy of SEQ is returned and SEQ remains unmodified; this
is the default.
For compatibility, the calling convention (sort SEQ LESSP) can also be used; in this case, sorting is always done in-place.
Source Code
;; Defined in ~/.emacs.d/elpa/compat-31.1.0.0/compat-30.el
(compat-defun sort (seq &optional lessp &rest rest) ;; <compat-tests:sort>
"Sort function with support for keyword arguments.
The following arguments are defined:
:key FUNC -- FUNC is a function that takes a single element from SEQ and
returns the key value to be used in comparison. If absent or nil,
`identity' is used.
:lessp FUNC -- FUNC is a function that takes two arguments and returns
non-nil if the first element should come before the second.
If absent or nil, `value<' is used.
:reverse BOOL -- if BOOL is non-nil, the sorting order implied by FUNC is
reversed. This does not affect stability: equal elements still retain
their order in the input sequence.
:in-place BOOL -- if BOOL is non-nil, SEQ is sorted in-place and returned.
Otherwise, a sorted copy of SEQ is returned and SEQ remains unmodified;
this is the default.
For compatibility, the calling convention (sort SEQ LESSP) can also be used;
in this case, sorting is always done in-place."
:extended t
(let ((in-place t) (reverse nil))
(when (or (not lessp) rest)
(setq
rest (if lessp (cons lessp rest) rest)
in-place (plist-get rest :in-place)
reverse (plist-get rest :reverse)
lessp (let ((key (plist-get rest :key))
(< (or (plist-get rest :lessp) #'value<)))
(if key
(lambda (a b) (funcall < (funcall key a) (funcall key b)))
<))
seq (if in-place seq (copy-sequence seq))))
(if reverse
(nreverse (sort (nreverse seq) lessp))
(sort seq lessp))))