是否有可能制作一个 python 片段来转换代码,就像我在示例中解释的那样?
"Hello world".print
- 点击 Tab 将其转换为
print("Hello world")
如果自动理解它是字符串还是表达式会很好所以如果我创建一个变量例如“a”并且我在末尾写“.print”并点击选项卡它不会添加“”或''所以在这样它就不会把它转换成别的东西。
a = 10
a.print - hitting tab
将其转化为:
print(a)
不属于:
print("a")
进步(如果可以这样说的话)
所以
TM_CURRENT_LINE
工作不正常(可能是)。
所以 "${TM_CURRENT_LINE/[0-9a-z.]//g}"它应该删除每个数字、小写字符和 "."从线。这段正则表达式代码(片段)有效但实际上无效。
当我写作时
mytext.py - hit tab/enter
它删除前缀点之间的所有内容
图片中使用的代码片段。
"Print to console - test": {
"scope": "python",
"prefix": ".print",
"body": [
"${TM_CURRENT_LINE/[0-9a-z.]//g}"
],
"description": "Log output to console"
}
我错了还是这位配偶删除了该行中的所有内容?
我认为这不可能完全符合您的需要。比如:
"Print": {
"prefix": ".print",
"body": [
"print(${TM_CURRENT_LINE/(.*)\\..+$/$1/})$0"
],
"description": "Print"
}
如果我写 a.print 并点击 ENTER
这将是输出:
aprint(a)
如果我写“a”.print 这将是输出:
"a"print("a")
然后您应该删除第一部分。这是基于我所知道的,到目前为止,进行一些搜索并没有找到更好的解决方案。
如果你在包含其他语句的行上使用它会出现一些问题,因为它会占用 TM_CURRENT_LINE
。参见 Variables .
我是一名优秀的程序员,十分优秀!