Use the sorting tag for questions involving arranging things in a defined order: sorting lines alphabetically, bibtex entries by date or author, emails by sender, completion candidates by various criteria, etc.
Emacs provides basic text-sorting functions in library
sort.el. This includes
Details are provided in the manual node
(emacs) Sorting. Further details are provided in the Elisp manual, and many packages provide sorting functions for their particular subject.