(Note that, title to the contrary, this question is not the same as How to start in daemon mode and suppress interactive dialogs?, as that question was "answered" by the submitter eliminating what was causing a particular prompt to appear.)
I'd like to know if there is a general way to keep
emacs --daemon from hanging forever waiting for an answer to a prompt displayed in a minibuffer that doesn't exist yet.
It's impossible to connect with an emacsclient to answer these prompts, because the server doesn't start until Emacs finishes the startup sequence. (This means, if you have ALTERNATE_EDITOR set to the empty string, which makes an
emacsclient that can't find a server start a new daemon, you can end up with multiple Emacs daemons all stuck and waiting.) I have to
killall emacs and fix the problem before continuing.
I can play whack-a-mole with each thing causing a prompt on startup when I identify it (by starting Emacs in non-daemon mode and seeing what it's asking), but it's not a solution because it can't stop the next daemon from hanging on startup for a new reason.
To give an example: a common reason it would hang was after a system reboot or Emacs crash, when the first post-reboot Emacs wanted to know whether it was okay to steal lockfiles from the defunct Emacs. I could fix that by creating advice to make that prompt always answer "yes" without interaction. But then, one of the files that was open at the previous session save was a TRAMP file requiring a sudo or SSH password, so the daemon's stuck waiting on a password prompt. So I fix that by manually editing the session file (with
emacs -q!) to remove the offending files—but that doesn't keep it from happening next time.
So, I can stop loading my session automatically on startup and change it to a command I must manually execute from my first emacsclient. But if it isn't loading my session in the background so it's ready by the time I'm ready to use it, the entire purpose of the daemon is lost!
So what I'd like is:
- (Best) Some way to defer minibuffer prompts until I open an emacsclient, while still completing the rest of initialization.
- (OK) Some way to make all minibuffer prompts I haven't already advised otherwise as described above just return
nounless an emacsclient is running. I can live with my TRAMP buffers erroring out so long as it mostly works.
Is there any way to achieve either of these goals?