Sublime Forum

Helping understanding context in the context of reindent

#1

Hi. . . I discovered the same thing that another user discovered with respect to reindent - namely, it works much like emacs so I wanted to bind reindent to a key but lo’ and behold, it seems to already be bound?

{ "keys": ["tab"], "command": "replace_completion_with_next_completion", "context": [ { "key": "last_command", "operator": "equal", "operand": "insert_best_completion" }, { "key": "setting.tab_completion", "operator": "equal", "operand": true } ] }, **{ "keys": ["tab"], "command": "reindent", "context":** [ { "key": "setting.auto_indent", "operator": "equal", "operand": true }, { "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true }, { "key": "preceding_text", "operator": "regex_match", "operand": "^$", "match_all": true }, { "key": "following_text", "operator": "regex_match", "operand": "^$", "match_all": true } ] },

Actually, there are a lot more context bindings for tab, but trying to limit the sprawl.

So it looks to me that reindent is already bound to tab but in practice it doesn’t seem to work. I checked my settings and auto_indent is set to true. Am I misunderstanding this binding?

0 Likes

#2

I assume the binding you’re referring to is this one (the formatting is a bit hard to read in your post):

{ "keys": ["tab"], "command": "reindent", "context":
    [
        { "key": "setting.auto_indent", "operator": "equal", "operand": true },
        { "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
        { "key": "preceding_text", "operator": "regex_match", "operand": "^$", "match_all": true },
        { "key": "following_text", "operator": "regex_match", "operand": "^$", "match_all": true }
    ]
},

In order for this binding to be active, all of the items in the context have to match; if any of them don’t, the binding is considered inactive in that situation.

The first one requires that the auto indent setting be enabled, the second indicates that the selection has to be empty, and the last two require that the text both preceeding and following the cursor match the regex ^$ (i.e. be empty) ; the match_all requires that the condition be true for all of the carets in the buffer.

As such, this binding is only active when all cursors are in the first column of the file with no text following them. That means that doesn’t reindent text, it just jumps the cursor from the left margin to the appropriate indent level (based on indent rules in effect).

0 Likes

#3

Thanks, that was very helpful! So I just removed the preceding.. and following.. and changed the selection.. operand to false which for the moment seems to be doing what I wanted it do. I’m tickled for now but waiting for the other shoe to drop to find out how that new binding is going to surprise me… :slight_smile:

0 Likes

#4

Incidentally, I see some messages on the forum marked “Solved”. Is that still in use? I didn’t see a way to mark any of my questions solved (though they were).

0 Likes

#5

It is, but only questions in the Technical Support section of the forum currently allow you to mark things as solutions. In that case there’s a little check mark box for it below the post, next to the icons for liking, linking, etc.

1 Like

#6

I changed the category for you, but only you can mark a reply as the solving one. :wink:

2 Likes