Hello. I'd like to contribute the attached patch, which adds hooks into gain and loss of focus events. This allows saving all buffers on loss of focus. (Alt-tabbing between an editor and browser is a popular workflow for web programmers.) It also allows reversion of buffers on regain of focus, convenient if one is switching between Emacs and another editor. People will probably find other handy uses for these hooks. Best, Brian Jenkins