1

最近,我遇到了一篇文章,其中包含一个出色的脚本,用于继续在 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}
    ]
},
4

1 回答 1

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}
    ]},

感谢您的有用评论!!

于 2013-08-12T14:00:14.003 回答