Thanks for the insightful comments - yes, everything you say makes sense. I've implemented what you describe. However, I'm a little unsure of this one - I had to advise a comint primitive and even re-implement part of an existing comint function. It feels like comint should perhaps have a way to do this sort of thing within itself, but I couldn't find any. I've attached the latest revision.