>> I haven't the got time to check your code, but you might want to
>> make use of `imenu+.el', which sorts submenus before splitting them, etc.
>> Maybe you'll have better luck with its code, which extends vanilla imenu.el.
>
> Do you have a pointer to a short example of its use? As usual, for a noob,
> the doc leaves MUCH to the imagination regarding actual implementation.
Just put imenu+.el in your `load-path', then (require 'imenu+). It will
first load imenu.el. Then use Imenu+ just like you would use Imenu. It
just adds some enhancements and fixes some problems (such as the fact that
submenus were not being sorted before splitting them).
Sorry, but I don't have more time to get into details. Perhaps someone
else here can help, whether with Imenu or Imenu+ code.