This is for ELPA. Admittedly this is pretty hacky, but it has worked for me since ages. It also has a bug I have no idea how to chase: every once in a blue moon it will fail to restore the cursor color. I'm guessing it's probably a bug in Emacs since the implementation is so simple and restoring the style works, but don't know really.