TAB key does not indent #9283

Closed
stefanv opened this Issue Feb 29, 2016 · 14 comments

Comments

Projects
None yet
6 participants
@stefanv
Contributor

stefanv commented Feb 29, 2016

In the git version of IPython, type

def foo(a):
    pass<ENTER>

The new line is not correctly indented, and the tab key does not insert 4 spaces.

/cc @Carreau @takluyver

@Carreau

This comment has been minimized.

Show comment
Hide comment
@Carreau

Carreau Feb 29, 2016

Member

Note that tab also try to complete, so we might want to indent only on empty line.

Member

Carreau commented Feb 29, 2016

Note that tab also try to complete, so we might want to indent only on empty line.

@takluyver

This comment has been minimized.

Show comment
Hide comment
@takluyver

takluyver Feb 29, 2016

Member

Hi Stefan!

The auto-dedenting is correct, I think - when you use something like return, continue, break, or pass, it dedents, because that normally means you've finished the indented block.

Good catch on using the tab key for indentation as well as completion, though - that should work.

Member

takluyver commented Feb 29, 2016

Hi Stefan!

The auto-dedenting is correct, I think - when you use something like return, continue, break, or pass, it dedents, because that normally means you've finished the indented block.

Good catch on using the tab key for indentation as well as completion, though - that should work.

@Carreau

This comment has been minimized.

Show comment
Hide comment
@Carreau

Carreau Feb 29, 2016

Member

Better description of @stefanv problem, | is the cursor <enter> mean pressing enter.

In [1]: def foo():|<enter>
   ...:     1
   ...:

result:

In [1]: def foo():
   ...:|
   ...:     1
   ...:
Member

Carreau commented Feb 29, 2016

Better description of @stefanv problem, | is the cursor <enter> mean pressing enter.

In [1]: def foo():|<enter>
   ...:     1
   ...:

result:

In [1]: def foo():
   ...:|
   ...:     1
   ...:

takluyver added a commit to takluyver/ipython that referenced this issue Feb 29, 2016

@minrk minrk added this to the 5.0 milestone Jun 16, 2016

@Carreau Carreau modified the milestones: 6.0, 5.0 Jun 17, 2016

Carreau added a commit to Carreau/ipython that referenced this issue Feb 9, 2017

Indent on new line by looking at the text before the cursor.
that would allow edit like the following to insert the right amount of
space on the newline (`|` is the cursor)

    class Bar:
        def __init__(self):|<enter>
            self.filed=0

Instead of inserting a blank line with 0 space.

Closes #9283

@takluyver takluyver closed this in #10264 Feb 9, 2017

@stefanv

This comment has been minimized.

Show comment
Hide comment
@stefanv

stefanv Feb 10, 2017

Contributor

The last example above is still broken :/

In [3]: def foo(a):
   ...:
   ...:     1|<enter>

(blankline needed)

In [3]: def foo(a):
   ...:
   ...:     1
   ...:|
Contributor

stefanv commented Feb 10, 2017

The last example above is still broken :/

In [3]: def foo(a):
   ...:
   ...:     1|<enter>

(blankline needed)

In [3]: def foo(a):
   ...:
   ...:     1
   ...:|
@Carreau

This comment has been minimized.

Show comment
Hide comment
@Carreau

Carreau Feb 10, 2017

Member

Updated @stefanv comment for further precision.

Member

Carreau commented Feb 10, 2017

Updated @stefanv comment for further precision.

@Carreau Carreau reopened this Feb 10, 2017

@stefanv

This comment has been minimized.

Show comment
Hide comment
@stefanv

stefanv Feb 10, 2017

Contributor

This may be a new issue or same, but I think you should be able to define a function with a newline in it:

In [1]: def foo():
   ...:     "hello"
   ...:     if 1==0:
   ...:         print(False)
   ...:

In [2]: |

instead of

In [1]: def foo():
   ...:     "hello"
   ...:     if 1==0:
   ...:         print(False)
   ...:
   ...:         |

Contributor

stefanv commented Feb 10, 2017

This may be a new issue or same, but I think you should be able to define a function with a newline in it:

In [1]: def foo():
   ...:     "hello"
   ...:     if 1==0:
   ...:         print(False)
   ...:

In [2]: |

instead of

In [1]: def foo():
   ...:     "hello"
   ...:     if 1==0:
   ...:         print(False)
   ...:
   ...:         |

@takluyver

This comment has been minimized.

Show comment
Hide comment
@takluyver

takluyver Feb 13, 2017

Member

In general, we take a blank line to indicate that input is complete. This has been the idea since forever, although the exact details may have changed. If you want to enter code including blank lines, you can now press F2 to use $EDITOR.

Member

takluyver commented Feb 13, 2017

In general, we take a blank line to indicate that input is complete. This has been the idea since forever, although the exact details may have changed. If you want to enter code including blank lines, you can now press F2 to use $EDITOR.

@Carreau

This comment has been minimized.

Show comment
Hide comment
@Carreau

Carreau Feb 13, 2017

Member

In general, we take a blank line to indicate that input is complete. This has been the idea since forever, although the exact details may have changed.

I think the question was to make it 2 blank lines. I think with the eddition capabilities of PTK whether it was or not the case I think it make sens to consider.

Member

Carreau commented Feb 13, 2017

In general, we take a blank line to indicate that input is complete. This has been the idea since forever, although the exact details may have changed.

I think the question was to make it 2 blank lines. I think with the eddition capabilities of PTK whether it was or not the case I think it make sens to consider.

@carlsmith

This comment has been minimized.

Show comment
Hide comment
@carlsmith

carlsmith Feb 14, 2017

Contributor

I once used a solution to the Return/Enter problem that sounds complicated, but was really intuitive in practice.

By default, Enter would just input a newline, so you could edit multiline inputs just like a regular text editor, and Ctrl+Enter would evaluate the input. That's obviously a pretty common approach. What was novel was what happened if you hit Enter, and the input was a single line, and the input was a one-liner (which IPython can determine statically​). In that case, the shell would evaluate the input when you hit Enter, as though you'd hit Ctrl+Enter.

​It sounds like you would have to think too much, but you actually just think in terms of editing chunks of Python using the default keybindings or quickly entering a command and hitting Enter. It feels like the interpreter just magically knows what you're thinking.

It would obviously be opt-in. Maybe go with Enable Psychic Return Key :)

Contributor

carlsmith commented Feb 14, 2017

I once used a solution to the Return/Enter problem that sounds complicated, but was really intuitive in practice.

By default, Enter would just input a newline, so you could edit multiline inputs just like a regular text editor, and Ctrl+Enter would evaluate the input. That's obviously a pretty common approach. What was novel was what happened if you hit Enter, and the input was a single line, and the input was a one-liner (which IPython can determine statically​). In that case, the shell would evaluate the input when you hit Enter, as though you'd hit Ctrl+Enter.

​It sounds like you would have to think too much, but you actually just think in terms of editing chunks of Python using the default keybindings or quickly entering a command and hitting Enter. It feels like the interpreter just magically knows what you're thinking.

It would obviously be opt-in. Maybe go with Enable Psychic Return Key :)

@Carreau

This comment has been minimized.

Show comment
Hide comment
@Carreau

Carreau Feb 14, 2017

Member

That's mostly how IPython currently work, except there is less distinction multiline/oneline.

  • oneline:
    • if the code is valid and complete: Execute
    • otherwise add new line
  • multiline.
    • if code valid, complete and have at least one new line at the end: Execute
    • otherwise : add new line.

Add on top: cursor need to be at the end of buffer, and Ctrl-Enter always execute.
The question is what if you want a white line in your code ?

Enable Psychic Return Key sounds great, like Write the code I'm thinking of :-)

Member

Carreau commented Feb 14, 2017

That's mostly how IPython currently work, except there is less distinction multiline/oneline.

  • oneline:
    • if the code is valid and complete: Execute
    • otherwise add new line
  • multiline.
    • if code valid, complete and have at least one new line at the end: Execute
    • otherwise : add new line.

Add on top: cursor need to be at the end of buffer, and Ctrl-Enter always execute.
The question is what if you want a white line in your code ?

Enable Psychic Return Key sounds great, like Write the code I'm thinking of :-)

@carlsmith

This comment has been minimized.

Show comment
Hide comment
@carlsmith

carlsmith Feb 15, 2017

Contributor
Contributor

carlsmith commented Feb 15, 2017

@Carreau

This comment has been minimized.

Show comment
Hide comment
@Carreau

Carreau Feb 21, 2017

Member

I've opened #10319 to track the execution semantics of enter.

Closing this as the bug(s) are fixed.

Member

Carreau commented Feb 21, 2017

I've opened #10319 to track the execution semantics of enter.

Closing this as the bug(s) are fixed.

@Carreau Carreau closed this Feb 21, 2017

@anntzer

This comment has been minimized.

Show comment
Hide comment
@anntzer

anntzer Mar 2, 2017

Contributor

@Carreau Perhaps related issue (I can open a new one if you prefer): C-Enter is not working for me (either to force execution of a multiline input without having to press enter twice, with the cursor at the end, or to execute a single or multiline input with the cursor NOT at the end of the buffer). I've tried both vi and emacs input modes on PTK.

Contributor

anntzer commented Mar 2, 2017

@Carreau Perhaps related issue (I can open a new one if you prefer): C-Enter is not working for me (either to force execution of a multiline input without having to press enter twice, with the cursor at the end, or to execute a single or multiline input with the cursor NOT at the end of the buffer). I've tried both vi and emacs input modes on PTK.

@Carreau

This comment has been minimized.

Show comment
Hide comment
@Carreau

Carreau Mar 2, 2017

Member

I can open a new one if you prefer

Yes please. Though if by C you mean Ctrl, there is not much we can do as "Enter" is indistinguishable from Ctrl+J so Ctrl+Enter is the same as enter, and Esc,Enter (or Ctrl-[, Enter) should execute.

Member

Carreau commented Mar 2, 2017

I can open a new one if you prefer

Yes please. Though if by C you mean Ctrl, there is not much we can do as "Enter" is indistinguishable from Ctrl+J so Ctrl+Enter is the same as enter, and Esc,Enter (or Ctrl-[, Enter) should execute.

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