-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
Comments
Note that tab also try to complete, so we might want to indent only on empty line. |
Hi Stefan! The auto-dedenting is correct, I think - when you use something like Good catch on using the tab key for indentation as well as completion, though - that should work. |
Better description of @stefanv problem,
result:
|
Addresses part of ipythongh-9283
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
The last example above is still broken :/
(blankline needed)
|
Updated @stefanv comment for further precision. |
This may be a new issue or same, but I think you should be able to define a function with a newline in it:
instead of
|
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. |
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. |
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 :) |
That's mostly how IPython currently work, except there is less distinction multiline/oneline.
Add on top: cursor need to be at the end of buffer, and Ctrl-Enter always execute. Enable Psychic Return Key sounds great, like Write the code I'm thinking of :-) |
Yeah, IPython is very similar, but still feels quit different in practice.
The approach I described is less eager to execute, except with line magics
and system commands, where it's the same. With anything else, it assumes
you want to edit a chunk of code, so entering two lines is just a matter of
hitting Return twice.
My style is less efficient when you want to enter a regular Python
one-liner. Often, you don't need to use single line inputs, like if you
want to do a couple of assignments, you can just do it as a two-line block
instead, but still, you often do want to evaluate a single expression, so
it is still a compromise.
Thank you for considering it, Matthias. It's really just food for thought.
…On Tue, 14 Feb 2017 06:18 Matthias Bussonnier, ***@***.***> wrote:
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* :-)
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#9283 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AHNhxOo2cNeH8AWVWlw4ia3QiSpOph-lks5rcUc4gaJpZM4Hl0s_>
.
|
I've opened #10319 to track the execution semantics of enter. Closing this as the bug(s) are fixed. |
@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. |
Yes please. Though if by C you mean Ctrl, there is not much we can do as "Enter" is indistinguishable from |
In the git version of IPython, type
The new line is not correctly indented, and the tab key does not insert 4 spaces.
/cc @Carreau @takluyver
The text was updated successfully, but these errors were encountered: