Every now and then, I accidentally hit C-x C-c in Emacs when I'm intending to just hit C-x or C-c. This, of course, closes all open frames and buffers with no confirmation. I know that I can make Emacs prompt "Are you sure you want to exit?", but I don't want to do that all the time, which would get annoying. I just want it to do it when there are more than N files (or buffers) open.
So I'd like to bind C-x C-c to a function along the lines of:
(if (< number of open buffers n)
(save-buffers-kill-emacs)
(are-you-sure))
But I can't figure out how to get the number of open buffers (or the number of open frames, or the number of open files, etc).