Metadata Files
Metadata are parameters that can be assigned to certain text sections using scope selectors.
These paremeters can be used for many purposes; for example:
- specifying the current comment markers, even within embedded source code, so that you can toggle comments in any syntax,
- defining rules for auto-indentation,
- marking symbols that Sublime Text will allow you to browse to quickly.
Furthermore, snippets can access metadata declared in the shellVariables setting, which allows you to create a snippet that has different contents depending on where it's used.
File Format
Metadata files have the .tmPreferences extension and use the Property List format. The file name is ignored by Sublime Text.
Metadata files are inherited from TextMate.
Example
Here's an example of a metadata file:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>name</key>
<string>JavaScript Metadata</string>
<key>scope</key>
<string>source.js</string>
<key>settings</key>
<dict>
<key>decreaseIndentPattern</key>
<string>^(.*\*/)?\s*\}.*$</string>
<key>increaseIndentPattern</key>
<string>^.*\{[^}"']*$</string>
<key>bracketIndentNextLinePattern</key>
<string>(?x)
^ \s* \b(if|while|else)\b [^;]* $
| ^ \s* \b(for)\b .* $
</string>
<key>shellVariables</key>
<array>
<dict>
<key>name</key>
<string>TM_COMMENT_START</string>
<key>value</key>
<string>// </string>
</dict>
<dict>
<key>name</key>
<string>TM_COMMENT_START_2</string>
<key>value</key>
<string>/*</string>
</dict>
<dict>
<key>name</key>
<string>TM_COMMENT_END_2</string>
<key>value</key>
<string>*/</string>
</dict>
</array>
</dict>
<key>uuid</key>
<string>BC062860-3346-4D3B-8421-C5543F83D11F</string>
</dict>
</plist>2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
The example file combines several types of metadata.
Structure of a Metadata File
All metadata files share the same topmost structure, which is inherited from the Property List format.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
...
</dict>
</plist>2
3
4
5
6
7
Sublime Text uses the following topmost keys in metadata files; all others are ignored by default.
nameOptional. Name of the metadata. Ignored by Sublime Text.
xml<key>name</key> <string>Shell Variables</string>1
2scopeRequired. Scope selector to determine in which context the metadata should be available.
xml<key>scope</key> <string>source.python</string>1
2settingsRequired. Container for settings.
xml<key>settings</key> <dict> ... </dict>1
2
3
4uuidOptional. A unique identifier for the file. Ignored by Sublime Text.
xml<key>uuid</key> <string>BC062860-3346-4D3B-8421-C5543F83D11F</string>1
2
Subelements of settings
The settings element can contain sub-elements for different purposes, which will be grouped in the following sections.
Some sub-elements have certain functionality associated with them by default, while others can only be accessed via the API.
Indentation Options
Indentation options control aspects of the auto-indentation mechanism.
increaseIndentPatternRegex. If it matches on the current line, the following lines will have their indentation level increased by one
xml<key>increaseIndentPattern</key> <string>insert regex here</string>1
2decreaseIndentPatternRegex. If it matches on the current line, this and the following lines will have their indentation level reduced by one.
xml<key>decreaseIndentPattern</key> <string>insert regex here</string>1
2bracketIndentNextLinePatternRegex. If it matches on the current line, only the next non-blank line will be indented one level further.
xml<key>bracketIndentNextLinePattern</key> <string>insert regex here</string>1
2disableIndentNextLinePatternRegex. If it matches on the current line, the next line will not be indented further.
xml<key>disableIndentNextLinePattern</key> <string>insert regex here</string>1
2unIndentedLinePatternRegex. The auto-indenter will ignore lines matching this regex when computing the next line's indentation level.
xml<key>unIndentedLinePattern</key> <string>insert regex here</string>1
2
Completions Options
Completion options control aspects of the completions mechanism.
cancelCompletionRegex. If it matches on the current line, supresses the autocomplete popup.
xml<key>cancelCompletion</key> <string>insert regex here</string>1
2
Symbol Definitions
Documentation for symbol definitions was moved to a separate page: Symbol Definition settings.
Shell Variables
Shell variables are used for different purposes and can be accessed from snippets.
Note that shell variables are defined as dictionaries in an array, and thus have a different format from settings sub-elements.
shellVariablesContainer for "shell variables".
xml<key>shellVariables</key> <array> ... </array>1
2
3
4
shellVariables Subelements
Subelements of shellVariables are dictionaries with name and value keys.
<dict>
<key>name</key>
<string>BOOK_OPENING</string>
<key>value</key>
<string>Once upon a time...</string>
</dict>2
3
4
5
6
See Also
- Comments
- Shell variables defining comment markers.
Related API Functions
To extract metadata information from plugin code, you can use the view.meta_info(key, point) API call.