TextMate:条件格式?

发布于 2024-09-05 17:35:55 字数 238 浏览 5 评论 0原文

我希望能够根据起始字符对线条进行不同的着色。

例如:

- This is line 1
- This is line 2
x This is line 3
- This is line 4
x This is line 5

因此第 1,2,4 行(以“-”开头)应为蓝色,而第 3,5 行(以“x”开头)应为红色。

这可能吗?你会怎么做?

谢谢。

I want to be able to color lines differently based on the starting character.

eg.:

- This is line 1
- This is line 2
x This is line 3
- This is line 4
x This is line 5

So lines 1,2,4 (starting with '-') should be blue while lines 3,5 (starting with 'x') should be red.

Is this possible? How would you do it?

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

洋洋洒洒 2024-09-12 17:35:55

您可以通过定义新语法来定义颜色。我的语法包含以下内容:

{   scopeName = 'text.todo';
    fileTypes = ( 'todo' );
    foldingStartMarker = '\{\s*

我创建了范围 text.todo 并将该语法分配给名为“foo.todo”的文件。

第一个模式表示“任意数量的空格,后跟破折号以及其后的任何内容”。这种匹配称为“常量”,因此 TextMate 将使用在“首选项”>“颜色”中为此范围定义的颜色。 “字体和颜色”。在我的主题中,常量是蓝色的。

第二种模式需要一个“x”而不是破折号,并调用匹配“variable.other.constant”,它在我的主题中恰好是红色的。您应该很容易从这里进行扩展。如果您需要帮助,只需按语法定义下方的问号即可。

; foldingStopMarker = '^\s*\}'; patterns = ( { name = 'constant'; match = '^\s*(-.*)

我创建了范围 text.todo 并将该语法分配给名为“foo.todo”的文件。

第一个模式表示“任意数量的空格,后跟破折号以及其后的任何内容”。这种匹配称为“常量”,因此 TextMate 将使用在“首选项”>“颜色”中为此范围定义的颜色。 “字体和颜色”。在我的主题中,常量是蓝色的。

第二种模式需要一个“x”而不是破折号,并调用匹配“variable.other.constant”,它在我的主题中恰好是红色的。您应该很容易从这里进行扩展。如果您需要帮助,只需按语法定义下方的问号即可。

; }, { name = 'variable.other.constant'; match = '^\s*(x.*)

我创建了范围 text.todo 并将该语法分配给名为“foo.todo”的文件。

第一个模式表示“任意数量的空格,后跟破折号以及其后的任何内容”。这种匹配称为“常量”,因此 TextMate 将使用在“首选项”>“颜色”中为此范围定义的颜色。 “字体和颜色”。在我的主题中,常量是蓝色的。

第二种模式需要一个“x”而不是破折号,并调用匹配“variable.other.constant”,它在我的主题中恰好是红色的。您应该很容易从这里进行扩展。如果您需要帮助,只需按语法定义下方的问号即可。

; }, ); }

我创建了范围 text.todo 并将该语法分配给名为“foo.todo”的文件。

第一个模式表示“任意数量的空格,后跟破折号以及其后的任何内容”。这种匹配称为“常量”,因此 TextMate 将使用在“首选项”>“颜色”中为此范围定义的颜色。 “字体和颜色”。在我的主题中,常量是蓝色的。

第二种模式需要一个“x”而不是破折号,并调用匹配“variable.other.constant”,它在我的主题中恰好是红色的。您应该很容易从这里进行扩展。如果您需要帮助,只需按语法定义下方的问号即可。

You can define the color by defining a new grammar. My grammar contains the following:

{   scopeName = 'text.todo';
    fileTypes = ( 'todo' );
    foldingStartMarker = '\{\s*

I created the scope text.todo and assigned this grammar to an file which is named "foo.todo".

The first pattern says "any amount of whitespaces, followed by a dash and anything after it". This match is called "constant", thus TextMate will use the color which is defined for this scope in "Preferences" > "Fonts & Colors". Constants are blue in my theme.

The second pattern requires an "x" instead of a dash and calls the match "variable.other.constant", which happen to be red in my theme. It should be easy for you to extend from here. If you need help, just press the question mark below your grammar definition.

; foldingStopMarker = '^\s*\}'; patterns = ( { name = 'constant'; match = '^\s*(-.*)

I created the scope text.todo and assigned this grammar to an file which is named "foo.todo".

The first pattern says "any amount of whitespaces, followed by a dash and anything after it". This match is called "constant", thus TextMate will use the color which is defined for this scope in "Preferences" > "Fonts & Colors". Constants are blue in my theme.

The second pattern requires an "x" instead of a dash and calls the match "variable.other.constant", which happen to be red in my theme. It should be easy for you to extend from here. If you need help, just press the question mark below your grammar definition.

; }, { name = 'variable.other.constant'; match = '^\s*(x.*)

I created the scope text.todo and assigned this grammar to an file which is named "foo.todo".

The first pattern says "any amount of whitespaces, followed by a dash and anything after it". This match is called "constant", thus TextMate will use the color which is defined for this scope in "Preferences" > "Fonts & Colors". Constants are blue in my theme.

The second pattern requires an "x" instead of a dash and calls the match "variable.other.constant", which happen to be red in my theme. It should be easy for you to extend from here. If you need help, just press the question mark below your grammar definition.

; }, ); }

I created the scope text.todo and assigned this grammar to an file which is named "foo.todo".

The first pattern says "any amount of whitespaces, followed by a dash and anything after it". This match is called "constant", thus TextMate will use the color which is defined for this scope in "Preferences" > "Fonts & Colors". Constants are blue in my theme.

The second pattern requires an "x" instead of a dash and calls the match "variable.other.constant", which happen to be red in my theme. It should be easy for you to extend from here. If you need help, just press the question mark below your grammar definition.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文