Marcin Borkowski (mbork) has a really great post about arranging for certain commands to prompt for verification before executing. Usually, those prompts are simply annoying but sometimes they’re actually useful. For example, you can arrange for Emacs to ask you for confirmation before exiting. Normally that would be really annoying but after I accidentally exited Emacs several times by fat fingering some shortcut, I began to appreciate its usefulness.
Some, dangerous, commands always prompt for approval. Others, like kill-emacs
don’t ask for approval by default but can be configured to do so to help those like me who are prone to fat fingering. But, of course, most commands don’t ask for confirmation and don’t have a configuration option to enable it.
Mbork gives an example of a command where he wanted approval before it executed. I have another: Several times I fat fingered the command to print the current buffer—which always seemed to send my printer into a schizophrenic fit—and finally decided to do something about it. But what?
Mbork has two suggestions. He first thought about advising the function he wanted to protect—that’s what I did with print buffer—but then it occurred to him there was a builtin solution. He realized that he could simply mark the function in question as disabled
and Emacs would automatically prompt before executing it. Even better, you can also specify what the prompt will be.
But wait! There’s more. While researching that solution he discovered the command command-query
that does exactly what he wanted. You can check out his post for the details but the TL;DR is that if you want a prompt before executing a given command, command-query
is the solution.