Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IEx: No secondary prompt, hang after multiline input #56

Closed
andreas-roehler opened this issue Mar 23, 2015 · 13 comments · Fixed by #197
Closed

IEx: No secondary prompt, hang after multiline input #56

andreas-roehler opened this issue Mar 23, 2015 · 13 comments · Fixed by #197
Labels

Comments

@andreas-roehler
Copy link

Can't put in a form like:

if true do
"asdf"
end

IEx hangs, resp. echos the input, but not the expected result.
Whilst when iex is called from bash, "asdf" appears as expected.

Thanks!

@jtmoulia
Copy link
Contributor

Hey @andreas-roehler -- I just tried your example in the IEx prompt started by elixir-mode-iex and found the same issue. I'd give that a try, and if you find that you still have the issue then elixir-lang/emacs-elixir is probably the culprit rather than alchemist.

@jtmoulia
Copy link
Contributor

jtmoulia commented Apr 3, 2015

Sorry -- scratch what I said. What command are you using for newlines? I found that I was actually using electric-newline-maybe-indent. comint-send-input, however, works like a charm.

@andreas-roehler
Copy link
Author

So do I, after "end" RET, which does comint-send-input. Still hangs...

@andreas-roehler
Copy link
Author

BTW: it's the only example bug shows up - commonly iex works well from alchemist.

@tonini
Copy link
Owner

tonini commented May 16, 2015

@andreas-roehler thanks for reporting, this looks really like a bug and I'll try to find the issue.

Thanks @jtmoulia for helping ❤️

@gleb
Copy link
Contributor

gleb commented Dec 25, 2015

I did some investigating and somehow comint and IEx don't get along.

Here's the minimal test case:

(apply 'make-comint "IEX"
              "/usr/local/bin/iex" nil nil)

got to IEX buffer and paste

"""
foo
"""

and IEX appears to hang.

Erl works fine.

(apply 'make-comint "ERL"
              "/usr/bin/erl" nil nil)

and paste

"""
foo
"""
.

I was wondering if it was something about the prompt. To rule it out I setup .iex.exs

IEx.configure(alive_prompt: "%counter>", default_prompt: "%counter>",)

This makes IEx prompt the same as erl's default prompt. Still hangs with multiline input.

@gleb
Copy link
Contributor

gleb commented Dec 25, 2015

The problem may be in IEx itself.

iex | cat

paste a multi-line expression, get a hang

@gleb
Copy link
Contributor

gleb commented Dec 26, 2015

Jose confirms problem in IEx:
https://groups.google.com/forum/#!topic/elixir-lang-talk/HoTY3YZP3y8

@tonini
Copy link
Owner

tonini commented Dec 27, 2015

Thanks a lot guys for all the effort you put into hunting the issue.

My apology for respond a but late, but all these holidays and my kids were ill too made my days a bit busy. :-)

I have kind of an idea to fix this issue, I'll get back to you if I have a branch for testing ready.

@gleb
Copy link
Contributor

gleb commented Dec 27, 2015

@tonini What's the idea? Tell us more :-)

Still waiting for a reply from Jose on what's the underlying problem with IEx.

Meanwhile I hacked together an IEx wrapper script that seems to workaround the problem. The idea is to always wait for a prompt (maybe secondary prompt) before sending another line of input. Seems to work, even if there are potential corner case correctness issues.

Edit: cleaned up the script

#!/usr/bin/env ruby

# based on http://stackoverflow.com/questions/2730642/wrapper-around-bash-control-stdin-and-stdout

require 'pty'
require 'thread'

mutex = Mutex.new
saw_prompt = ConditionVariable.new

system('stty -echo') if ENV['Emacs']

PTY.spawn("/usr/local/bin/iex") do |p_read, p_write|
  Thread.new do
    loop do
      mutex.synchronize {
        saw_prompt.wait(mutex)
        input = STDIN.gets
#      puts "== read from STDIN: #{input}"
#      STDOUT.flush
        p_write.print input
#      puts "== wrote to process: #{input}"
      }
    end
  end

  loop do
    output = p_read.sysread(512)
#    puts "== read from process: #{output}"
    print output
#    puts "wrote to STDOUT: #{output}"
    STDOUT.flush
    saw_prompt.signal if output.include?("iex(") || output.include?("...(")
  end
end

@tonini
Copy link
Owner

tonini commented Dec 29, 2015

@gleb If the underlaying problem could be fixed Elixir wise that would be great!

On the other hand I realized that there is an issue that we have to wait until the IEx prompt is showed up again after an input. So what I did is sending just always one line to the running IEx process instead the whole block including newlines and then always wait until the prompt is visible again. Works actually solid so far.

I will push the branch soon so you guys could test it.

@tonini
Copy link
Owner

tonini commented Dec 30, 2015

@gleb @andreas-roehler is fixed on master

@gleb
Copy link
Contributor

gleb commented Dec 30, 2015

@tonini Works for me. Thanks! Will use/test it more, and let you know if anything comes up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants