【问题标题】:Pass keystrokes to Sublime snippet with AutoPair on?在 AutoPair 开启的情况下将击键传递给 Sublime 片段?
【发布时间】:2015-11-11 11:24:24
【问题描述】:

我正在为 Python 编写一个新的 def sn-p,它从变量名中添加了一个预先填充的文档字符串。我的正则表达式目前被 SublimeText 自动配对的任何字符阻塞:()""''[]{}

是否可以保留自动配对功能,同时仍将击键信息传递给 sn-p?我的正则表达式目前需要平衡的表达式,但是我什至可以通过一个按键来完成。

"auto_match_enabled": false 在用户键绑定中时,下面的 sn-p 效果很好,设置为 true 时会失败。任何方向都非常感谢!

崇高的格式化:

<snippet>
    <tabTrigger>def</tabTrigger>
    <scope>source.python</scope>
    <description>Function</description>

    <content><![CDATA[def ${1:function}($2) -> (${3:None}):
    """
    ${4:Heading}

    ${5:Description}

    Args:
${2/(?(DEFINE)(?'quote'(?:((?<q>["'])(?:(?!\k<q>|\\).)*(?:\\.(?:(?!\k<q>|\\).)*)*\k<q>))))(?(DEFINE)(?'delim'(?:,\s?)))(?(DEFINE)(?'paren'(?:(\((?>[^()]|(?&paren))*\)))))(?(DEFINE)(?'brac'(?:(\[(?>[^\[\]]|(?&brac))*\]))))(?(DEFINE)(?'curl'(?:(\{(?>[^\{\}]|(?&curl))*\}))))(?(DEFINE)(?'equal'(?:=\s?(?:(?P>quote)|(?>\w+)|(?P>brac)|(?P>curl)|(?P>paren))(?:(?P>delim)|\z))))(?'var'(?>\w+))((?>:\s\w+)(?:(?P>equal)|(?P>delim)|\z)|\s?(?P>equal)|(?P>delim)|\z)/\t\t$+{var}: \n/g}

    Returns:
        ${6:Return description with}

    Tests:
        >>> ${7:2+2}
        ${8:4}

    """

    ${0:pass}]]></content>
</snippet>

正则表达式示例

$2(输入字符串):

x, y: int, z: str="String can have \"quotes\" inside", hah = [1, 2, 3, 4], l = [[1,2],[3,4]]

Args(输出替换):

    x: 
    y: 
    z: 
    hah: 
    l: 

【问题讨论】:

    标签: python regex sublimetext3


    【解决方案1】:

    我找不到直接的答案,但有一个解决方法:在此范围内禁用自动配对键绑定:meta.function.parameters.python

    Full walkthrough on Github.

    如果有人有比这个 hack 更好的答案,我会再开放几天!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-09-08
      • 2021-03-08
      • 2013-11-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多