Hacker News new | ask | show | jobs
by thargor90 1263 days ago
Do you know any IDE or editor that implements this? I would love to try it.
1 comments

I've just tried Spyder, and it seems to work that way.

With this code:

    indent(1)
    
        indent 2

        if x<0:
            function 1
            function 2
        function 3
if you select the if block starting the selection at the "if" (i.e. ignoring the whitespace at its left) up to function 3, and paste it right under indent(1), it produces the following:

    indent(1)
    if x<0:
        function 1
        function 2
    function 3    
    
        indent 2

        if x<0:
            function 1
            function 2
        function 3
Yet if you select the whole line including the initial indentation whitepace and paste it at the same place under indent(1), then it doesn't change the block indentation:

    indent(1)
        if x<0:
            function 1
            function 2
        function 3
    
    
        indent 2

        if x<0:
            function 1
            function 2
        function 3
That looks sensible to me; if you're moving whole lines it will paste them unchanged, but if you move the cursor to select specifically a keyword and its context, it treats it as a code block, reformatting its indentation to that of the place where you are pasting it.
Where as in a language that actually has blocks you don't need to make these arbitrary decisions and hunt for the exact way of copying a block of text.
Python has blocks, in the same way that Javascript has sentences even if you don't end all of them with semicolons.