Вопрос

I have this error sometimes, though not all of the time, and it's driving me crazy. I don't know if it's a bug or if there is some behaviour or fix that I am not aware of.

I am entering a multiple-line command using :{ and :}, and SOMETIMES when I want to conclude the command, like below, I receive the error as shown below:

*MyModule| :}
unknown command ':}'
use :? for help.

I'd say it works properly 97 percent of the time, but 3 percent of the time I get this situation.

As far as I know, it should always work to type :} to close the multiple line entry, as described here:

http://www.haskell.org/ghc/docs/7.4.1/html/users_guide/interactive-evaluation.html

At the moment, the only way that I know to escape this situation when it happens is ctrl+D, which kills ghci unfortunately.

A. Is this a bug or is there some reason that :} would suddenly become an "unknown command"?

B. If I get to this situation, is there a way to recover without using ctrl+D? It doesn't matter how many times I try :}, it always results in "unknown command" once I have entered this situtation, though what I expect is for this command to close the multiple line entry.

Like it says in the question, this is GHCi, version 7.6.3, on Arch Linux.

Это было полезно?

Решение

As I already noted in the comments, the reason for this behaviour is the GHCi doesn't properly reset the prompt when Ctrl-C is pressed. The source of the problem probably lies in the following code (Taken from ghci-ng):

multiLineCmd q = do
  st <- lift getGHCiState
  let p = prompt st
  lift $ setGHCiState st{ prompt = prompt2 st }
  mb_cmd <- collectCommand q ""
  lift $ getGHCiState >>= \st' -> setGHCiState st'{ prompt = p }
  return mb_cmd

(See InteractiveUI.hs line 712)

If collectCommand throws UserInterrupt, then the line that resets the promt will never be executed. I changed this code to:

multiLineCmd q = do
  st <- lift getGHCiState
  let p = prompt st
  lift $ setGHCiState st{ prompt = prompt2 st }
  mb_cmd <- collectCommand q "" `GHC.gfinally` lift (getGHCiState >>= \st' -> setGHCiState st'{ prompt = p })
  return mb_cmd

Which fixes the problem.

Другие советы

This is a known bug. Everything is working fine except that ghci sometimes keeps printing the multiline prompt when it should be printing the normal prompt.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top