← 输入框|github.com|刷新
Skip to content

Super Paste #382

Open
Open

Description

@thomasballinger

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 ?

Activity

  1. thomasballinger commented on Sep 11, 2014

    @thomasballinger
    MemberAuthor

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

  2. Trundle commented on Sep 17, 2014

    @Trundle
    Member

    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.

  3. added this to the 0.14 milestone on Sep 17, 2014
  4. thomasballinger commented on Sep 17, 2014

    @thomasballinger
    MemberAuthor

    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.

  5. thomasballinger commented on Oct 18, 2014

    @thomasballinger
    MemberAuthor

    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
  6. thomasballinger commented on Nov 23, 2014

    @thomasballinger
    MemberAuthor

    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.

  7. thomasballinger commented on Nov 23, 2014

    @thomasballinger
    MemberAuthor

    See the add-remove-lines branch for more

  8. thomasballinger commented on Dec 17, 2014

    @thomasballinger
    MemberAuthor

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

  9. thomasballinger commented on Jan 17, 2015

    @thomasballinger
    MemberAuthor

    I just got a paste bug with this code, it should be ripped out and something more comprehensive and carefully tested used instead.

  10. thomasballinger commented on Jan 18, 2015

    @thomasballinger
    MemberAuthor

    I removed the old code and replaced it with something simpler: lines that are blank will be indented to prevent running a partial command.

  11. sebastinas commented on Jan 23, 2015

    @sebastinas
    Contributor

    What's the best way to test this?

  12. thomasballinger commented on Jan 23, 2015

    @thomasballinger
    MemberAuthor

    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.

  13. thomasballinger commented on Jan 25, 2015

    @thomasballinger
    MemberAuthor

    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.

  14. thomasballinger commented on Jan 31, 2015

    @thomasballinger
    MemberAuthor

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

  15. modified the milestones: 0.15, 0.14 on Feb 9, 2015
  16. thomasballinger commented on Feb 9, 2015

    @thomasballinger
    MemberAuthor

    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.

  17. thomasballinger commented on Dec 3, 2015

    @thomasballinger
    MemberAuthor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions