最近,我发现了一篇文章,其中包含一个优秀的脚本,可以继续在CSS的崇高文本Here中进行块评论。将其添加到特定于环境的键绑定文件就像魅力一样。但是,当我尝试更改它以用于乳胶注释时(即用*代替%)它不起作用。
原始代码:
{"keys": ["enter"], "command": "insert", "args" : {"characters": "\n * "},
"context":
[
{"key": "selection_empty", "operator": "equal", "operand": true},
{"key": "preceding_text", "operator": "regex_contains",
"operand": "\\/\\*\\*$", "match_all": true}
]
},
{"keys": ["enter"], "command": "insert", "args" : {"characters": "\n* "},
"context":
[
//{"key": "selection_empty", "operator": "equal", "operand": true},
{"key": "preceding_text", "operator": "regex_contains",
"operand": "^[\t ]*\\*[^\\/]", "match_all": true}
]
},
我的代码:
{"keys": ["enter"], "command": "insert", "args" : {"characters": "\n % "},
"context":
[
{"key": "selection_empty", "operator": "equal", "operand": true},
{"key": "preceding_text", "operator": "regex_contains",
"operand": "\\/\\%\\%$", "match_all": true}
]
},
{"keys": ["enter"], "command": "insert", "args" : {"characters": "\n % "},
"context":
[
//{"key": "selection_empty", "operator": "equal", "operand": true},
{"key": "preceding_text", "operator": "regex_contains",
"operand": "^[\t ]%\\%[^\\/]", "match_all": true}
]
},
答案 0 :(得分:1)
好吧,所以我尝试做的事情有两个主要缺陷。首先,我确实犯了正则表达式的错误并替换了太多的* s。其次,原始代码用于CSS,其中包含样式的块注释
/*
*
*
*/
虽然我想要的乳胶块注释的样式(不是内置的)是一个带有标题和页脚的块,用于定义注释的限制,并且维护包含在其中的文本也会被注释,例如:
%%%%%%%%%%%% Comment Section Start %%%%%%%%%%%%
%%% Comments here
%%%%%%%%%%%% Comment Section Ends %%%%%%%%%%%%
以下内容可以对这两种乳胶执行此操作,并且可以对其进行修改以与R等效,以便可以快速一致地添加注释。我将它与一个添加页眉和页脚部分的片段一起使用。
//
{"keys": ["enter"], "command": "insert", "args" : {"characters": "\n%%%\t"},
"context":
[
{"key": "selection_empty", "operator": "equal", "operand": true},
{"key": "preceding_text", "operator": "regex_contains",
"operand": "\t*%%%.*$", "match_all": true}
]},
{"keys": ["enter"], "command": "insert", "args" : {"characters": "\n%%%\t"},
"context":
[
//{"key": "selection_empty", "operator": "equal", "operand": true},
{"key": "preceding_text", "operator": "regex_contains",
"operand": "\t*%%%", "match_all": true}
]},
感谢有用的评论!!