From: Christophe Rhodes Date: Mon, 11 Jun 2012 10:33:21 +0000 (+0100) Subject: rework commands in light of long cache refresh time X-Git-Tag: v0.1~19 X-Git-Url: http://christophe.rhodes.io/gitweb/?p=iplayer-el.git;a=commitdiff_plain;h=561c68511a2aa272c658192b6e1c08fe666196ed;hp=561c68511a2aa272c658192b6e1c08fe666196ed rework commands in light of long cache refresh time The issue is that of get-iplayer itself managing its cache: if at any point it decides that the cache is sufficiently stale, it goes off and refreshes everything, which seems to take a long time -- if I'm unlucky, breaking my ERC sessions (and in any case making the rest of the editor session unusable). Construct a background process and sentinel to manage the cache updating before calling the real get-iplayer command. The tricky bit here is to make sure that the sentinel and real body get executed in the right context. Many things in the world are simpler with lexical scoping; this would have been one of them, but I am still on emacs 23 and lexical binding is a thing of the future, so instead of making a bunch of thunks to be called later, we have to save commands (well, key sequences), but then those key sequences are divorced from the window and frame that they were originally typed into, so we have to get that context back. Naive ways of doing that turn out not to work, because execute-kbd-macro runs its own command loop, which first of all selects a current frame and window, so if we've navigated away from the *iplayer* window/buffer we end up adding keystrokes to e.g. an ERC buffer, which is suboptimal; however, (ab)using the pre and post command hooks seems to make things work. So do that, and all is well. ---