Thanks for the patches; they were very clear and organized, in a difficult code area. I installed them into the Emacs master with minor changes, along with the attached further patch, and am marking this bug as done. As far as patch format goes, I mildly prefer attachments but the form you used was fine. My preference is because I am not on the bug-gnu-emacs mailing list, and don't know how to retrieve your email from debbugs.gnu.org or from lists.gnu.org -- the best I could come up with was the mbox format of lists.gnu.org but that did not apply cleanly.