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

Changing indent of the line using Tab #195

Open
avatar-lavventura opened this issue Feb 9, 2020 · 13 comments
Open

Changing indent of the line using Tab #195

avatar-lavventura opened this issue Feb 9, 2020 · 13 comments

Comments

@avatar-lavventura
Copy link

@avatar-lavventura avatar-lavventura commented Feb 9, 2020

In emacs when I each press TAB it moves the beginning of the line to next indent position on so on. (I am not sure is it he default behavior of emacs). In addition to that if curson in between a word it autocorrect instead of aligning the indent.

if __name__ == "__main__":
    for attempt in range(10):
        print(attempt)   # tab pressed
        ^

if __name__ == "__main__":
    for attempt in range(10):
print(attempt)   # tab pressed
^

if __name__ == "__main__":
    for attempt in range(10):
    print(attempt)   # tab pressed
    ^

=> Is it possible to have this approach on sublimeText? If yes, how?

@canoeberry

This comment has been minimized.

Copy link
Collaborator

@canoeberry canoeberry commented Feb 9, 2020

@avatar-lavventura

This comment has been minimized.

Copy link
Author

@avatar-lavventura avatar-lavventura commented Feb 9, 2020

I added keybindings into my sublime-keymap but seems like nothing changed :/

@canoeberry

This comment has been minimized.

Copy link
Collaborator

@canoeberry canoeberry commented Feb 10, 2020

@avatar-lavventura

This comment has been minimized.

Copy link
Author

@avatar-lavventura avatar-lavventura commented Feb 10, 2020

It says command: sbp_tab_cmd {"indent_on_repeat": true}, but tab has its original behavior

@canoeberry

This comment has been minimized.

Copy link
Collaborator

@canoeberry canoeberry commented Feb 10, 2020

This command that I wrote only works if you are anywhere within the indent of the line. If you in non-whitespace parts of the line, it does nothing.

The behaviour is not entirely consistent and I am willing to consider changes. I thought it was fine but I decided to try to explain the behaviour to you in this message, and that's when I realised it doesn't completely make sense.

But it's something like this:

  • if you are in the indent of the line and you press tab the first time, the line will be indented to the right place.
  • if it's already in the right place, your cursor will move to the end of the indent
  • if you hit tab again and again, it will move the line over each time

So the command behaves differently if the previous command was a tab command. It allows you to move to a line and hit tab to reindent it where it thinks it belongs (as long as you are in the white space).

So there are times that all that happens is the cursor moves from the indent to the first non-whitespace character. That is kind of a wasted tab.

And the there are times when it would be nice if it just did that even if the cursor is NOT in the whitespace of the line. I am not sure why I didn't do that but it might have had something to do with the other uses of tab (completion comes to mind ...)

If you want, try describing in detail what you'd like to see and I will consider implementing it.

@canoeberry

This comment has been minimized.

Copy link
Collaborator

@canoeberry canoeberry commented Feb 10, 2020

Wow - I had to look at the code, which fortunately I commented, to see how it is supposed to work:

image

@canoeberry

This comment has been minimized.

Copy link
Collaborator

@canoeberry canoeberry commented Feb 10, 2020

I've made some changes and now it looks like this

image

So if you press the tab command and you don't move, it indents you another level. So there is no longer a wasted tab. I think I like it better. I am going to use it for a while and see what I think.

@avatar-lavventura

This comment has been minimized.

Copy link
Author

@avatar-lavventura avatar-lavventura commented Feb 10, 2020

While typing some stuff if I press TAB it may complete the word.

But I realize if there is already written word when I press tab on sublimeText it completed the word, which is not the default case on emacs:

    def run_cmd()
           ^ # pressed tab, it completed (run_cmd)un_cmd()

What I want (I think its the default case in emacs as well):

=> If I am not typing and pressed tab I want indent to move as cycle and not extent to the right space and do not do any autocompleting.

Screen Shot 2020-02-10 at 16 49 26

Screen Shot 2020-02-10 at 16 49 31

Screen Shot 2020-02-10 at 16 49 36

Screen Shot 2020-02-10 at 16 49 42


But while typing if I press tab is completes the word instead of changing its indent

Screen Shot 2020-02-10 at 16 50 46

Screen Shot 2020-02-10 at 16 51 18

Screen Shot 2020-02-10 at 16 53 55

Screen Shot 2020-02-10 at 16 54 06

@canoeberry

This comment has been minimized.

Copy link
Collaborator

@canoeberry canoeberry commented Feb 10, 2020

@avatar-lavventura

This comment has been minimized.

Copy link
Author

@avatar-lavventura avatar-lavventura commented Feb 10, 2020

=> Would it work on latex (.tex) file?

@canoeberry

This comment has been minimized.

Copy link
Collaborator

@canoeberry canoeberry commented Feb 10, 2020

To expand on this, Emacs is much better at figuring out the proper indent than Sublime. Sublime's algorithm appears to be "give it a go, but when in doubt, indent to the same level as the previous line".

@canoeberry

This comment has been minimized.

Copy link
Collaborator

@canoeberry canoeberry commented Feb 10, 2020

Don't have any experience with .tex files.

What I have done gives me enough flexibility to never be too hampered by Sublime's crap indentation.

BTW - your tab behaviour is different from mine because I don't use tab completion. I have a special key binding for that so that my tab is not messed up.

@avatar-lavventura

This comment has been minimized.

Copy link
Author

@avatar-lavventura avatar-lavventura commented Feb 10, 2020

Your changes works fine for me.

My tab key-binding does python (jedi-completion), I think.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.