eval-in-repl icon indicating copy to clipboard operation
eval-in-repl copied to clipboard

Blank lines in python functions don't work

Open Wilfred opened this issue 8 years ago • 6 comments

Given the function:

def foo():
    x = 1

    y = x + 1

eir-eval-in-python makes python/ipython thinks that the function ends after x = 1, and tries to evaluate y = x + 1, producing NameError.

Looks like eir-send-to-python is getting the whole string, but it's being misunderstood by the inferior python process. It is possible to send whole functions to *Python* buffers, python-shell-send-defun does the right thing, so I'm not sure what needs changing.

Wilfred avatar Mar 01 '16 18:03 Wilfred

Thanks for your interest in the package. I wasn't aware of this. Deleting the blank line before reaching the inferior python process may be a quick fix. I'm currently busy, so I'll work on this later this month.

kaz-yos avatar Mar 01 '16 19:03 kaz-yos

Yeah, unfortunately this seems like a deal-breaker for Python. For example, I just selected all but one line of a Python script and hit C-RET, and I got a buffer full of tracebacks, mostly about indentation errors. But if I call python-shell-send-region on the same region, it works fine.

alphapapa avatar Nov 08 '16 08:11 alphapapa

Can you give me a reproducible example script?

kaz-yos avatar Nov 08 '16 09:11 kaz-yos

def test_function(t):
    print t

    print t

print "ok"

test_function("ok")

C-x h C-RET:

>>> ... ... >>>   File "<stdin>", line 1
    print t
    ^
IndentationError: unexpected indent
>>> >>> ok
>>> >>> ok

alphapapa avatar Nov 08 '16 21:11 alphapapa

Hi, I'm facing this issue as well. Any workaround for this, other than the remove blank lines?

sainathadapa avatar Jul 12 '17 16:07 sainathadapa

I just released 0.9.5 to address this issue. Please let me know if it works better for you. If this new behavior seems satisfactory, I'll close the issue.

Add eir-use-python-shell-send-string option (default to t). This avoids errors on blank lines by using python-mode's python-shell-send-string function. However, this does not allow showing code in the REPL. To recover the old behavior, set to nil.

0.9.5 https://github.com/kaz-yos/eval-in-repl/releases/tag/v0.9.5

kaz-yos avatar Jul 30 '17 20:07 kaz-yos