崇高文字2:构建系统自定义选择器 [英] Sublime Text 2: build system custom selector

查看:53
本文介绍了崇高文字2:构建系统自定义选择器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在带有自定义扩展名的构建系统中定义选择器(例如 *。ltx *。cmake 等),而没有可用的选择器(如 text.tex.latex source.c ++ 等) ?

How can I define a selector in the build system with the custom extension (like *.ltx, *.cmake etc) for which there is no available selector (like text.tex.latex, source.c++ etc)?

有可能吗?如果是,怎么办?

Is it possible? If yes - how?

推荐答案

如果您定义了新的语法定义(即新的.tmLanguage文件),则可能。语法定义可以声明新的作用域名称,然后可以在新的自定义构建系统中使用。

It's possible, if you define a new syntax definition (i.e., a new .tmLanguage file). Syntax definitions can declare new 'scope names' which you can then use in your new, custom build systems.

新语法定义文件实际上不必定义/匹配文件的语法,因为您可以简单地通过文件扩展名进行匹配...!

The new syntax definition file doesn't actually have to define/match the file's syntax, as you can simply match by file extension...!

看看此处为.tmLanguage文件语法。 scopeName项使您可以命名新的范围(即 text.tex.latex等)。我将通过下面的示例。

Take a look here at the .tmLanguage file syntax. The "scopeName" item allows you to name your new scope (i.e., "text.tex.latex", etc.). I'll go through an example below.

我创建了一个新语法,该语法定义了一个新范围-相当简单(就像Sublime中的大多数事情一样):

I created a new syntax which defined a new scope -- it was quite easy (like most things in Sublime):


  • 在命令面板中,选择软件包控制:安装软件包

  • 在软件包列表中,选择 PackageDev

  • 通过选择工具>软件包>软件包开发>新语法定义来创建新语法定义

  • 您的新语法定义将如下所示:

  • In the Command Palette, select 'Package Control: Install Package'
  • In the list of packages, select 'PackageDev'
  • Create a new syntax definition by selecting Tools > Packages > Package Development > New Syntax Definition
  • Your new syntax definition will look like this:

{ "name": "Syntax Name",
  "scopeName": "source.syntax_name",
  "fileTypes": [""],
  "patterns": [
  ],
  "uuid": "..."
}

...用描述性名称替换语法名称 , source.syntax_name和新的作用域名称,然后填写 fileTypes以包含一个或多个文件扩展名。例如:

... replace "Syntax Name" with a descriptive name, "source.syntax_name" with your new scope name, and fill in "fileTypes" to contain one or more file extensions. For instance:

fileTypes:[ tex, ltx]


  • 在程序包/用户下使用 .JSON-tmLanguage扩展名保存文件

  • 选择工具>构建系统>选择Json进行语言翻译

  • 选择工具>构建

  • Save the file using an ".JSON-tmLanguage" extension under Packages/User
  • Select Tools > Build System > Select Json to tmLanguage
  • Select Tools > Build

您完成了!任何碰巧具有在 fileTypes中定义的扩展名之一的新文件都将激活 scopeName作用域。

You're done! Any new files which happen to have one of the extensions defined in "fileTypes" will activate the "scopeName" scope.

您现在可以在新的构建系统中使用此作用域文件(工具>构建系统>新构建系统...

You can now use this scope in a new Build System file (Tools > Build System > New Build System...)

干杯!

这篇关于崇高文字2:构建系统自定义选择器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆