Aha! I had not thought to look for such a hook. Are they common? This is very close to what I'm looking for, thank you. Then, to toggle, I guess I would automate closing and reopening the file.
Edit: Oops. Now I'm thinking this would probably break all code analysis features. It would be nice if there was a notion of a 'view' that is very superficial and doesn't impact the code analysis.