Sublime Text 2: build system custom selector

白昼怎懂夜的黑 提交于 2019-12-04 03:55:57
Greg Sadetsky

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...!

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.


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

  • 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": "..."
}

... 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"]

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

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...)

Cheers!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!