Improve smart switch to function to check current buffer.