5

I'm sending some commands to my emacs using emacsclient --eval on a timer. The only problem with this is if at the time I happen to be using emacs and press C-g to cancel something, instead of canceling what I intended to cancel it will cancel the commands that emacsclient is sending, printing the message "Quit emacsclient request." I actually want to let the emacsclient code finish, and then have C-g cancel whatever I originally intended to cancel.

I thought I could wrap the commands I'm sending in (let ((inhibit-quit t)) ...). But it turns out if you look at the source for server-execute and server-eval-and-print that they override inhibit-quit, on the reasoning that emacsclient actions are usually instigated by the user and that must be what they want to have quit.

Ideally, I'd have two hotkeys, C-g for quitting my normal interactive stuff, and something else, say C-S-g for quitting emacsclient stuff (in case I accidentally send an infinite loop).

I know I could copy pasta the server-execute function and rip out the quit handling bit, but then I'd be left at the mercy of infinite loops when they do come up. Ideas?

4

After a lot of experimenting with writing wrappers around keyboard-quit (the default binding of C-g), I discovered that C-g has special behavior. If you bind C-S-g to keyboard-quit, it will not interrupt emacsclient requests. Only C-g will. In fact, C-g will do so even if you unbind it with global-unset-key! I don't know why, but in the end this gives me the behavior I want. C-S-g doesn't interrupt emacsclient evals and C-g does.

Edit: Turns out I was wrong. Sometimes it still interrupts, it's just more rare.

  • 1
    I think the quit-char explains what you're seeing. This is tersely documented in Input Modes. You may need to dive into the source code if you want to find out the gritty details. I don't know how this works on a terminal type other than tty. – Gilles 'SO- stop being evil' Dec 4 '14 at 0:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.