Sublime Forum

Single quotes shouldn't come in pair in some contexts

#1

I understand that quotes usually come in pairs, and I would like to keep that behaviour — mostly. However, when preceded by a backslash a single quote should NOT be autocompleted, which is especially obvious for someone writing in LaTeX, where the sequence ’ produces acute accents on top of characters.

Is it possible to do that?

0 Likes

#2

The quote pairing is a command being executed. I believe you should be able to scope using “preceding text” in your key binding. The following is from the default (Windows) keybinding, but likely the same on other systems.

//> Auto-pair single quotes
{ “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”: “^(?:\t| |\)|]|\}|>|$)”, “match_all”: true },
{ “key”: “preceding_text”, “operator”: “not_regex_contains”, “operand”: “['a-zA-Z0-9_]$”, “match_all”: true },
{ “key”: “eol_selector”, “operator”: “not_equal”, “operand”: “string.quoted.single - punctuation.definition.string.end”, “match_all”: true }
]
}

0 Likes

#3

Just add this to your keymap:

    { "keys": ["'"], "command": "insert", "args": {"characters": "'"},
        "context":  [
            { "key": "preceding_text", "operator": "regex_contains", "operand": "\\\\$" }
        ]
    },
    { "keys": ["\""], "command": "insert", "args": {"characters": "\""},
        "context":  [
            { "key": "preceding_text", "operator": "regex_contains", "operand": "\\\\$" }
        ]
    },
1 Like

#4

That worked great, thank you!

0 Likes