I had some students in our Software Engineering class here take on the
job of providing my ViaVoice module with a reasonable user interface
last semester.  They did a pretty good job, but I still need to clean up
the code a bit.  One thing that is still extremely kludgy is an attempt
to set the ViaVoice grammar by mode.  What I need to make this work
right is a way to run a hook whenever:
(a) some buffer becomes the current buffer; or
(b) the mode (either major or minor) of the current buffer changes.
I don't see anything suitable.  The menubar, toolbar, and gutter are all
changed in those situations, but it looks like they are marked so that
redisplay notices the change and updates accordingly.  I don't see a way
to hook into that process either.  Is there a clean way to do this?  My
students tried redefining or advising all of the user-visible buffer
changing commands (yikes!), which still leaves (b) without a solution.
Thanks,
-- 
Jerry James