You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It would be cool to be able to paste in code from a file that has newlines in places that could complete a command, but based on input a few lines down, probably doesn't:
class Foo(object):
def bar(self):
asdf
def baz(self):
asdf
if we could do this in a way that didn't differ from python too much. This would be a change in behavior from the normal interpreter, I want to clear it with folks first. Thoughts, @ikanobori@Trundle@sebastinas@bobf ?
Sounds good to me. We differ in details from the interactive (C)Python interpreter anyway (e.g. auto indentation), hence that should not be a big deal.
Cool! I guess this should be implemented either as 1) an extra parse step for paste messages, or 2) when a keypress in a paste event triggers a return, maybe make it an indented return if there are more indented lines later in the paste event.
I've merged the first half of this into master: extra blank lines are no longer a problem! We need more tests for this. The second half should be pretty easy - it something has an error, splitting it into two blocks by adding a line. If still an error, abandon.
Right now there's bpython/test/fodder/original.py and processed.py, and each code snippet in original should be transformed to the corresponding one in processed. This tests a good portion of the logic, though we need to test transforming these when current_line/buffer states have different values. Quite open to suggestions though.
The scope of this issue should be defined. I think any syntactically correct Python code should be able to round-trip from an editor and back, possibly with some whitespace differences like blank lines that contain only whitespace becoming empty lines. For now, we can limit this to pastes that begin on empty lines.
Activity
thomasballinger commentedon Sep 11, 2014
Would also be cool if this allowed too-indented code to be run.
Trundle commentedon Sep 17, 2014
Sounds good to me. We differ in details from the interactive (C)Python interpreter anyway (e.g. auto indentation), hence that should not be a big deal.
thomasballinger commentedon Sep 17, 2014
Cool! I guess this should be implemented either as 1) an extra parse step for paste messages, or 2) when a keypress in a paste event triggers a return, maybe make it an indented return if there are more indented lines later in the paste event.
thomasballinger commentedon Oct 18, 2014
Similarly, bringing in
from the external editor should work as well. Maybe going along with detection of syntax error? Get a block of text, and
thomasballinger commentedon Nov 23, 2014
I've merged the first half of this into master: extra blank lines are no longer a problem! We need more tests for this. The second half should be pretty easy - it something has an error, splitting it into two blocks by adding a line. If still an error, abandon.
thomasballinger commentedon Nov 23, 2014
See the add-remove-lines branch for more
thomasballinger commentedon Dec 17, 2014
I'm feeling less good about this code, and thinking about removing it. It should at least be improved.
thomasballinger commentedon Jan 17, 2015
I just got a paste bug with this code, it should be ripped out and something more comprehensive and carefully tested used instead.
thomasballinger commentedon Jan 18, 2015
I removed the old code and replaced it with something simpler: lines that are blank will be indented to prevent running a partial command.
sebastinas commentedon Jan 23, 2015
What's the best way to test this?
thomasballinger commentedon Jan 23, 2015
Right now there's
bpython/test/fodder/original.pyandprocessed.py, and each code snippet in original should be transformed to the corresponding one in processed. This tests a good portion of the logic, though we need to test transforming these when current_line/buffer states have different values. Quite open to suggestions though.thomasballinger commentedon Jan 25, 2015
The scope of this issue should be defined. I think any syntactically correct Python code should be able to round-trip from an editor and back, possibly with some whitespace differences like blank lines that contain only whitespace becoming empty lines. For now, we can limit this to pastes that begin on empty lines.
thomasballinger commentedon Jan 31, 2015
Not a bug anymore, it either works or gives up and the paste doesn't work.
thomasballinger commentedon Feb 9, 2015
What works currently:
What doesn't work:
Also multiline pastes onto lines already containing text are not tested.
thomasballinger commentedon Dec 3, 2015
If anyone works on this, check out the currently skipped tests in the
test/test_preprocess.py