Okular inverse search for multiple editors (e.g. Kile)

Setting up inverse search for Kile/Okular is well documented, e.g. in the official Kile docs. What has always bugged me, though, is that the inverse search editor is set globally in the okularpartrc config file, which means that you can't set up inverse search with different editors for different source code types.
I put together a workaround that changes Okular's editor choice to Kile when Okular is called from Kile by temporarily overwriting the okularpartrc file.