Sublime Forum

Auto-complete comma / semicolon at end of line

#1

Right now Sublime auto-adds for example a closing bracket when I type {. It would be cool if Sublime would detect that I am for example adding an item to a Javascript (or any language) object and that a comma should be added after.

For example:
var object = { a: 'b', // add item here like "b: 'c'", auto add a "," after the closing bracket as Sublime detects there are more items after this one c: 'd' }

0 Likes

#2

To this I wish to add the following idea: auto-complete a ; when for example it is detected that an array value is assigned to a variable.

Example (PHP): I type $array = [
Autocomplete to: $array = [<cursur_position>];
(Instead of $array = [], without the semicolon)

0 Likes

#3

maybe add this to your keybindings:

{ "keys": ["["], "command": "insert_snippet", "args": {"contents": "[$0];"}, "context":
    [
        { "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },
        { "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
        { "key": "following_text", "operator": "regex_contains", "operand": "$", "match_all": true },
        { "key": "preceding_text", "operator": "regex_contains", "operand": "^\\s*\\$\\w+\\s*=\\s*$", "match_all": true },
        { "key": "eol_selector", "operator": "equal", "operand": "source.php - string.quoted.single - punctuation.definition.string.end", "match_all": true }
    ]
}
0 Likes

#4

General answer regarding automatic semicolon insertion, taken from another post

The JavaScript specification describes a feature called Automatic Semicolon Insertion, which is widely regarded as something you don’t want to use. Most prominently, it has been expressed in Douglas Crockford book JavaScript: The Good Parts in the chapter “Awful Parts”.

In short, there are cases in which automatic semicolon insertion leads undesired results, making your code behaving differently then intended (e.g. when returning an object.) For some in-depth information, this article describes the problem pretty well.

However, you can manually append a semicolon using the AppendSemiColon package.

0 Likes

#5

Try PHP Grammar. Open issues about other smart completions and I’ll do my best to add them.

0 Likes