【问题标题】:Syntax-Specific Block Comments for Latex in Sublime Text 2Sublime Text 2 中 Latex 的语法特定块注释
【发布时间】:2013-08-11 20:26:52
【问题描述】:

最近,我发现了一个帖子,其中包含一个出色的脚本,用于继续在 CSS 的崇高文本中进行块评论,Here。并将其添加到特定于环境的键绑定文件就像一个魅力。但是,当我尝试将其更改为与乳胶 cmets 一起使用时(即,将 * 替换为 %)它不起作用。

原代码:

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

【问题讨论】:

  • 定义does not work。另请注意,* 是量词,表示match the preceding token zero or more times。它也很模糊,我的意思是这个脚本应该做什么。你能提供两种情况的一些输入吗?
  • 它应该在块注释部分的每个新行中添加 %,即检查是否有注释字符(css 中的 *,latex 中的 %)。不起作用,我的意思是它什么也没增加。但是第一个添加了 *.
  • latex 中的评论是什么?是/% this is a comment %/ 吗?
  • 你换了一个*,太多了:^[\t ]*\\%[^\\/],或者只是^[\t ]*%[^\\/](因为,正如HamZa所说,第一个*是一个量词)。但是,LaTeX 没有块注释之类的东西,是这样的(除非您自己定义)。目前,sn-p 仍然希望块注释以 /%% 开头,这并没有真正的帮助。

标签: regex comments latex sublimetext2 code-snippets


【解决方案1】:

好的,所以我尝试做的事情有两个主要缺陷。首先,我确实在正则表达式上犯了一个错误,并且替换了太多 *s。其次,原始代码是用于具有块 cmets 样式的 CSS

/*
*
*
*/

而我想要的乳胶块注释的样式(不是内置的)是一个带有页眉和页脚的块,定义了注释的限制并维护其中包含的文本也将被注释,例如:

%%%%%%%%%%%% Comment Section Start %%%%%%%%%%%%
   %%%  Comments here
%%%%%%%%%%%% Comment Section Ends  %%%%%%%%%%%%

以下内容可以对乳胶执行此操作,并且可以对其进行修改以对 R 执行等效操作,以便可以快速且一致地添加 cmets。我将它与添加页眉和页脚部分的 sn-p 一起使用。

//
{"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}
    ]},

感谢提供帮助的 cmets!

【讨论】:

    猜你喜欢
    • 2014-01-23
    • 2017-02-20
    • 2014-11-12
    • 1970-01-01
    • 2013-06-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-16
    相关资源
    最近更新 更多