Ok, here is the improved version of my patch. Thanks all for the feedback. PS: Can we commit it to emacs-23 branch too? -- Eduard Wiebe