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

TAB key does not indent #9283

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

TAB key does not indent #9283

stefanv opened this issue Feb 29, 2016 · 14 comments
Milestone

Comments

@stefanv
Copy link
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
Copy link
Member

Carreau commented Feb 29, 2016

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

@takluyver
Copy link
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.

@Carreau
Copy link
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
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 ipython#9283
@stefanv
Copy link
Contributor Author

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
Copy link
Member

Carreau commented Feb 10, 2017

Updated @stefanv comment for further precision.

@Carreau Carreau reopened this Feb 10, 2017
@stefanv
Copy link
Contributor Author

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
Copy link
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.

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

carlsmith commented Feb 15, 2017 via email

@Carreau
Copy link
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 as completed Feb 21, 2017
@anntzer
Copy link
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
Copy link
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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants