Sublime Forum

Changing indent of the line using Tab in tex files

#1

In emacs when I each press TAB it moves the beginning of the line to next indent position on so on like a cyclic behavior. (I am not sure is it he default behavior of emacs)

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 (mainly on latex (tex) files)? If yes, how?


Follow up link (https://github.com/sublime-emacs/sublemacspro/issues/195#issuecomment-584131948):

0 Likes

#2

Sublime doesn’t do this by default, so in order to get that kind of behaviour you would indeed need a plugin or package of some kind, such as the one that you mentioned in your post.

As mentioned in the comments in the issue you linked, Sublime’s indentation system may stand in the way of getting a good result. As a language-agnostic editor it has a mechanism that needs to be general enough to work for any language out there, which constrains its ability to come up with a desirable outcome for all people in all languages.

As such, if the package/plugin that you use doesn’t do its own examination of the source code to ensure that the indentation level chosen is “correct”, the result may end up being suboptimal.

0 Likes

#3

At least is there any way to do auto-completion only during typing? and if there is not typying in progress tab won’t lead to have a word completion.

0 Likes

#4

One way to do that would be to turn off this setting:

    // When enabled, pressing tab will insert the best matching completion.
    // When disabled, tab will only trigger snippets or insert a tab.
    // Shift+tab can be used to insert an explicit tab when tab_completion is
    // enabled.
    "tab_completion": true,

It defaults to being turned on, but if you turn it off then the tab key acts like a regular tab key; so the autocomplete panel will still open when completions are available, but pressing tab is still a tab. That might do what you want.

However if you’re using a third party package to provide completions, then it may have a key binding on the Tab key to take its own actions, which could get in the way of this setting actually working (but the only way to know if that’s the case is to try it).

0 Likes

#5

"tab_completion": false, didn’t work,

but following worked:

	"tab_completion": false,
	"repl_view_settings": {
        "translate_tabs_to_spaces": false,
        "auto_indent": true,
        "smart_indent": true,
        "spell_check": false,
        "indent_subsequent_lines": false,
        "detect_indentation": false,
        "auto_complete": true,
        "line_numbers": true,
        "gutter": true
    },

=> working as putting tab now. In emacs it was just changing the indent position.

When pressed tab it it possible to force sublimeText to do go beginning of the line and do tab?

0 Likes

#6

You could define a macro that executes the commands for moving home and then doing what tab does, and bind the key to execute the macro.

0 Likes

#7

I was not able to manage to write a working macro, do you have an example for it? Is this correct starting point (https://stackoverflow.com/a/27994582/2402577) => which I wasn’t manage to make it work.

0 Likes

#8

Here is some documentation from the unofficial docs for recording macros

0 Likes