Page 1 of 1

Unicode sort

Posted: 2026-03-20 00:27:52
by useeger
Hello together,

in "Edit" > "Transform Paragraphs" there is a command "Sort Ascending (A-Z)". This command sorts for example the letters h and ḥ as if they were the same character. But they are not the same character: h has the Unicode value U+0068 and ḥ U+1E25. So ḥ should be far behind h and also far behind z (U+007A). Does there exist a macro, that sorts paragraphs and words according to the Unicode value?

Thanks for help!
Ulrich

Re: Unicode sort

Posted: 2026-03-20 07:11:18
by phspaelti
Using a macro you can sort any way you like, as Nisus macro language has a .sortWithCommand command for arrays.
A simple Unicode sort, however, can be achieved with the regular array .sort command using an "s" option.

So a macro that will sort all paragraphs of a document in Unicode order looks like this:

Code: Select all

$doc = Document.active
$paras = $doc.text.find('^.+\n', 'Ea').arrayByMakingValuesDoCommand "subtext"
$paras.sort 's'
$doc.text.replaceInRange Range.new(0,$doc.text.length), $paras.join('')
Note that this assumes that there are no empty paragraphs. So this macro should work for files such as word lists.
If you want something that only sorts the current selection, it would need to be modified a bit.

Re: Unicode sort

Posted: 2026-03-20 08:14:22
by useeger
Dear Philip,

that does exactly what I want and need. I have indeed a word list to sort.

Thank you very much!!

Ulrich