Subject: bug#44597: 26.3; bibtex should allow reverse sorting

From: Francesco Potortì <[email-masked]>
Date: Sat, 14 Nov 2020 18:31:18 +0100

>> I wish bibtex mode would allow for reverse sorting of entries.
>>
>> Some years ago I used to obtain that behaviour by advising the sort-subr
>> functions when called inside a bibtex-mode buffer.  No more.
>>
>> The modern bibtex.el sorts an entry when bibtex-clean-entry is called
>> when bibtex-maintain-sorted-entries is t without calling sort-subr, but
>> relying only on bibtex-lessp, which is not easy to advice.
>
>I haven't looked at the code closely, but wouldn't advising bibtex-lessp
>to just swap the parameters work?

Yes.  In fact, after writing my bug report I looked at the code again
and I did just that :)

However, I think that reversing the sorting order is just the most
common of various criteria that one would like to use for sorting.
Recently I had a reason for getting one hundred bibtex entries sorted by
date in reverse order, a task that would take a long time by hand,
especially in front of frequent modifications of the list of entries to
be sorted.

Fortunately I was able to use bibtex2html to do the job, but the most
natural thing would have been to use bibtex.el with a proper sorting
function.  Ideally, bibtex.el should provide a hook where one can
install any function for sorting.  The hook should get some arguments
(the type of entry, the name of entry, the date, a bibtex custom field
and maybe others).  That would make bibtex.el more generally flexible.