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

Super Paste #382

Open
thomasballinger opened this issue Sep 11, 2014 · 15 comments
Open

Super Paste #382

thomasballinger opened this issue Sep 11, 2014 · 15 comments

Comments

@thomasballinger
Copy link
Member

@thomasballinger thomasballinger commented Sep 11, 2014

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 ?

@thomasballinger
Copy link
Member Author

@thomasballinger thomasballinger commented Sep 11, 2014

Would also be cool if this allowed too-indented code to be run.

@Trundle
Copy link
Member

@Trundle Trundle commented 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 thomasballinger added this to the 0.14 milestone Sep 17, 2014
@thomasballinger
Copy link
Member Author

@thomasballinger thomasballinger commented 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
Copy link
Member Author

@thomasballinger thomasballinger commented Oct 18, 2014

Similarly, bringing in

class Foo(object):
    pass
1 + 1

from the external editor should work as well. Maybe going along with detection of syntax error? Get a block of text, and

  • if there are indented lines after blank lines, delete the blank lines
  • if there are syntax errors that would be solved by blank lines, put them it
@thomasballinger
Copy link
Member Author

@thomasballinger thomasballinger commented 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
Copy link
Member Author

@thomasballinger thomasballinger commented Nov 23, 2014

See the add-remove-lines branch for more

@thomasballinger
Copy link
Member Author

@thomasballinger thomasballinger commented Dec 17, 2014

I'm feeling less good about this code, and thinking about removing it. It should at least be improved.

@thomasballinger thomasballinger added the bug label Jan 17, 2015
@thomasballinger
Copy link
Member Author

@thomasballinger thomasballinger commented 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
Copy link
Member Author

@thomasballinger thomasballinger commented 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
Copy link
Contributor

@sebastinas sebastinas commented Jan 23, 2015

What's the best way to test this?

@thomasballinger
Copy link
Member Author

@thomasballinger thomasballinger commented Jan 23, 2015

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.

@thomasballinger
Copy link
Member Author

@thomasballinger thomasballinger commented 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 thomasballinger removed the bug label Jan 31, 2015
@thomasballinger
Copy link
Member Author

@thomasballinger thomasballinger commented Jan 31, 2015

Not a bug anymore, it either works or gives up and the paste doesn't work.

@sebastinas sebastinas modified the milestones: 0.15, 0.14 Feb 9, 2015
@thomasballinger
Copy link
Member Author

@thomasballinger thomasballinger commented Feb 9, 2015

What works currently:

  • classes
  • functions with blank lines

What doesn't work:

  • try/except/else or try/except/finally with blank lines

Also multiline pastes onto lines already containing text are not tested.

@thomasballinger thomasballinger added help wanted and removed bitesize labels Dec 1, 2015
@thomasballinger
Copy link
Member Author

@thomasballinger thomasballinger commented Dec 3, 2015

If anyone works on this, check out the currently skipped tests in the test/test_preprocess.py

@sebastinas sebastinas modified the milestones: 0.15, feature paradise Apr 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.