Skip to content

[Python] Auto-pair triple quotes #4584

Description

@Mr7F

Expected behavior

It would be nice to auto-pair the triple quotes in python, like zed does

Something like this seems to work for "
(we should do the same for ')

Edit: there’s a better behavior than the poc bellow, see discussion

  {
    "keys": [
      "\""
    ],
    "command": "insert_snippet",
    "args": {
      "contents": "\"$0\"\"\""
    },
    "context": [
      {
        "key": "setting.auto_match_enabled"
      },
      {
        "key": "selector",
        "operand": "source.python"
      },
      {
        "key": "selection_empty",
        "match_all": true
      },
      {
        "key": "preceding_text",
        "operator": "regex_contains",
        "operand": "\"\"$",
        "match_all": true
      },
      {
        "key": "following_text",
        "operator": "not_regex_contains",
        "operand": "^\"",
        "match_all": true
      }
    ]
  },
  {
    "keys": [
      "\""
    ],
    "command": "move",
    "args": {
      "by": "characters",
      "forward": true
    },
    "context": [
      {
        "key": "setting.auto_match_enabled"
      },
      {
        "key": "selector",
        "operand": "source.python"
      },
      {
        "key": "selection_empty",
        "match_all": true
      },
      {
        "key": "following_text",
        "operator": "regex_contains",
        "operand": "^\"",
        "match_all": true
      },
      {
        "key": "selector",
        "operator": "not_equal",
        "operand": "punctuation.definition.string.begin",
        "match_all": true
      },
      {
        "key": "eol_selector",
        "operator": "not_equal",
        "operand": "string.quoted.double - punctuation.definition.string.end",
        "match_all": true
      }
    ]
  },

Actual behavior

"| + " -> ""
""| + " -> """
""" + " -> """|"""
"""|""" + """ -> """"""|
[aaa] + " -> "[aaa]"
"[aaa]" + "" -> """[aaa]"""

Steps to reproduce

Metadata

Metadata

Assignees

No one assigned

    Labels

    C: Syntaxhttps://www.sublimetext.com/docs/syntax.html

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions