2020-10-26 Scrolling all windows simultaneously

One of the things which I need very seldom is simultaneous scrolling in more than one window. One possible use-case is comparing two versions of the same source code, where a usual diff is less than useful (this happens, and there are ways to help with that, but sometimes the diff is just a total mess, and sometimes you really want to see the whole code, not just the changed places). Another one – which happened to me yesterday – was translation. I had the English source in the right-hand window and my Polish translation in the left-hand window, and when I scroll the left one, I’d like to scroll the right one, too.

Of course, there is scroll-other-window, bound to C-M-v by default, and its sibling scroll-other-window-down (C-M-S-v), but they are manual – I need to press those keys. What would be even nicer is that when I scroll one window, the other one scrolls by the same amount automatically.

And guess what? Emacs has me covered. Enter scroll-all-mode. It is a global minor mode which makes scrolling commands work in all the windows in the current frame simultaneously. Though it looks like magic, it really isn’t, and it is even quite simplistic. It just runs a function in post-command-hook which checks if the current command has anything to do with scrolling, and if yes, it runs it in all the windows in the current frame. And it is in fact slightly un-Emacs-y in that the list of scrolling commands is not really configurable at all – it is just hard-coded in one of the functions defined by that package (and quite short). Yikes. (I might be tempted to fix that or at least report as a bug.) On the other hand, the fact that it does not magically apply to all possible commands is a good thing, since e.g. the aforementioned C-M-v and C-M-S-v are unaffected by it – and thus provide a way to manually override its decisions (after all, the amount of lines in e.g. the source and translation may be different).

And by the way, if you are curious what I’ve been translating, well, one of my earlier posts should give you a hint. After translating The Princess Bride, I started another localization project, again for my family, and with another cult classic. (To cut a long story short, that time I should probably wear a terribly comfortable mask while doing the translation, and this time I should probably wear a bow tie. ;-) )

Now the issue is that subed-mode somehow messes up scroll-all-mode workings (which is a pity). When I save the buffer in subed-mode, it gets recentered – and C-l is not on scroll-all-mode​‘s list (and it should be). And even if it were, that would not help – for starters, it is not called by the subed mode (why the buffer gets recentered is still a bit of a mystery to me, though I have a certain suspicion), and even if it were, it would be most probably called non-interactively, so post-command-hook would have no chance to fire anyway.

So, either I’m going to live with this, or I’ll need to do some Emacs hacking again – which would be nice, but I don’t have too much time for that right now. ;-)

And anyway, even with these shortcomings, scroll-all-mode is something that you might need very rarely, but when you do, it is really nice.

CategoryEnglish, CategoryBlog, CategoryEmacs