Haskell: GHCi treats Ctrl-Y like Ctrl-Z
Asked Answered
D

1

12

According to the haskeline documentation, typing CTRL+Y should pop the most recent entry from the kill-ring (e.g. the line I just deleted via CTRL+U). I'm finding that instead, it suspends the REPL, as if I'd typed CTRL+Z.

As a clumsy workaround, I've found that typing CTRL+V CTRL+Y pops from the kill ring as a plain CTRL+Y is supposed to do.

Is this a know bug, or is something else at play? Can I fix it? I'm running GHC version 8.0.2.

Not sure if it matters, but I'm running GHCi via stack (e.g. stack ghci), and I brew installed stack (macOS).

Dannadannel answered 19/9, 2017 at 1:39 Comment(1)
I'm pretty sure Stack is irrelevant, but you should report the GHC version.Hiero
V
8

Mac OS terminals/ttys have a concept of a "dsusp" or "delayed suspend" key, and Ctrl-Y is the usual key assigned. At the tty level, when a CTRL+Y is read, it acts a little like CTRL+Z. The difference is that CTRL+Z causes an immediate suspend when it's typed; CTRL+Y causes the suspend when the underlying process tries to read characters and the CTRL+Y marker pops up in the input stream.

(CTRL+V is usually assigned to the "lnext" key, which skips terminal processing by making the next key "literal", which is why CTRL+V Ctrl+Y works.)

Ideally, GHCi would check for "dsusp" functionality (it doesn't exist on Linux, for example) and disable it if it's detected, but it looks like it's not doing this.

In the meantime, you can disable your "dsusp" key by running:

stty dsusp undef

before you launch GHCi. Sticking this in your ".bashrc" and/or ".profile" is a good idea, since the functionality is largely useless.

Verruca answered 19/9, 2017 at 21:57 Comment(3)
Perfect, thanks! I'm curious why this never impeded Ctrl-Y yank behavior in Bash. I guess when I'm already in the parent shell, it doesn't make sense to suspend the current job?Dannadannel
Well, Bash contains specific code to prevent Ctrl-Y (or Ctrl-Z) from having an effect at the shell prompt itself. If it didn't do this, Bash would suspend like any other process (and would probably just freeze up in the absence of a parent process prepared to handle it).Verruca
Makes perfect sense. Thanks for clarifying.Dannadannel

© 2022 - 2024 — McMap. All rights reserved.