Domanda

I am writing a latex document and I want to insert accented characters..

Suppose I want to insert accented e: è

If I want to write it I use:

\`e

But with sublime autocomplete, when I insert the backquote I get

\`e`

So I have to delete the extra backquote each time I insert an accented character.. Is there a way to avoid closing quote if the first quote is preceded by a backslash?

Thanks

È stato utile?

Soluzione

Try adding the following to your user key bindings.

{ "keys": ["'"], "command": "insert_snippet", "args": {"contents": "'"}, "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", "match_all": true },
        { "key": "preceding_text", "operator": "regex_contains", "operand": "\\\\$", "match_all": true },
        { "key": "selector", "operator": "equal", "operand": "text.tex", "match_all": true }
    ]
}

I took the existing key binding for auto pairing quotes in the default key bindings. I then changed the snippet so it would simply enter a single character. You could change it to an insert command but it doesn't really matter. I then added the last 2 entries to context. The first checks the preceding text for \. The second restricts the key binding to files that have a scope of text.tex.latex. The second entry isn't really necessary, but if it's not there, it will apply to all file types, not just tex files.

edit

Double quote solution

{ "keys": ["\""], "command": "insert_snippet", "args": {"contents": "\""}, "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.double", "match_all": true },
        { "key": "preceding_text", "operator": "regex_contains", "operand": "\\\\$", "match_all": true },
        { "key": "selector", "operator": "equal", "operand": "text.tex", "match_all": true }
    ]
}

To reiterate, I started with the double quote auto pair key binding (from the defaults), and added the two context entries. Failing to parse means you had some malformed json. If I had to guess, you had to many/not enough \ escapes.

edit2

Same procedure. Hopefully I got the right quote this time :)

{ "keys": ["`"], "command": "insert_snippet", "args": {"contents": "`"}, "context":
    [
        { "key": "selector", "operator": "equal", "operand": "text.tex.latex"},
        { "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },
        { "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
        { "key": "preceding_text", "operator": "regex_contains", "operand": "\\\\$", "match_all": true }
    ]
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top