How do I disable Ctrl-Z suspend?

I occasionally fat-finger the ctrl-z key which causes kakoune to suspend to the background, it which point I have to kill it because I can’t get it running again without errors. I’ve tried running stty susp undef before launching kakoune. And I’ve added this to my kakrc:

unmap global normal <c-z>
unmap global insert <c-z>
nop %sh{stty susp undef}

hook global WinCreate .* %{
    unmap global normal <c-z>
    unmap global insert <c-z>
    nop %sh{stty susp undef}
}

But still nothing.
What else could I do?

<c-z> is handled by the terminal UI before it gets sent to the Kakoune server, so telling the server to unmap <c-z> doesn’t help. Also, the terminal UI puts the terminal into raw mode where none of the “default” kernel control characters apply (such as <c-c> for SIGINT, <c-\> for SIGQUIT, <c-u> for "delete to start of line) including <c-z>, so the stty invocation doesn’t help either.

If you really want to disable <c-z> handling in Kakoune, you could comment out the code that handles it in terminal_ui.cc and recompile.

Alternatively, resuming from <c-z> suspend really should work. What happens when you run fg in the shell after hitting <c-z>? Does it still break if you launch Kakoune with kak -n? Are you using an unusual shell?

2 Likes

Alright I think I understand the problem now. It’s odd that kakoune does some input processing on the client and especially odd that the client input can’t be remapped. I made the following change and that did indeed disable the behavior.

--- a/src/terminal_ui.cc
+++ b/src/terminal_ui.cc
@@ -447,7 +447,7 @@ TerminalUI::TerminalUI()
         while (auto key = get_next_key())
         {
             if (*key == ctrl('z'))
-                kill(0, SIGTSTP); // We suspend at this line
+                ;//kill(0, SIGTSTP); // We suspend at this line
             else if (*key != Key::Invalid)
                 m_on_key(*key);
         }

What happens when you run fg

Oh neat, that’s how you do it. I was trying to do kill -CONT. That makes it a lot less annoying knowing how to resume background processes, but still a little annoying.

In a traditional interactive command-line tool, like bc or ed or git add -p, the kernel provides a bunch of standard user-interface commands, like <c-u> to clear the input you’ve typed, <c-c> to interrupt the program, and <c-z> to pause the program and return you to the shell so you can use commands like jobs, bg, and fg to multi-task between them. These days people tend to use tools like tmux or even whole separate terminals to handle task-switching between terminal apps, but a lot of people are still used to the Old Ways, so they persist.

Full-screen terminal tools like Kakoune and Vim and top and so forth disable the kernel’s standard UI and provide their own… but for the sake of conforming to people’s expectations, they will often implement the standard commands like <c-c> and <c-z> themselves. Since those functions are normally handled by the kernel rather than the running program, people expect them to work even when the program is stuck or crashed. Therefore, when tools implement those commands themselves, they try to do it as close to the “front-end” as possible, so that they still work if the main logic of the program is not working as expected.

Particularly in Kakoune’s case, the logic needs to be handled in the client, because when you press <c-z> in a particular client, you want that client to suspend, not some other client or the server. Also, if you’re using a non-terminal-based client (like Kakodemon) you wouldn’t want <c-z> to suspend anything, since there’s no shell to return control to.