Thubms up for having a look at this! I didn't have a detailed look at the code but I shamelessly stole the patch and applied during the macOS binary build here
https://github.com/geany/geany-osx/blob/master/geany_patches/08-geany_plugin...
and this function seems to work as advertised.