I don't think there's code in Emacs which does what you want, so if you really need to check proper pairing you're going to have to write the code. Stefan