Skip to content

Commit

Permalink
[Git Files] Add Git Files package (sublimehq#1126)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan Boehning authored and wbond committed Mar 20, 2018
1 parent 7993030 commit a7284db
Show file tree
Hide file tree
Showing 30 changed files with 2,708 additions and 0 deletions.
21 changes: 21 additions & 0 deletions Git Files/Comments.tmPreferences
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<plist version="1.0">
<dict>
<key>name</key>
<string>Comments</string>
<key>scope</key>
<string>text.git</string>
<key>settings</key>
<dict>
<key>shellVariables</key>
<array>
<dict>
<key>name</key>
<string>TM_COMMENT_START</string>
<key>value</key>
<string># </string>
</dict>
</array>
</dict>
</dict>
</plist>
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"scope": "meta.attributes-list.git.attributes - meta.mapping.value - punctuation.separator",
"completions": [
{"trigger": "binary\tattribute", "contents": "binary"},
{"trigger": "conflict-marker-size\tattribute", "contents": "conflict-marker-size"},
{"trigger": "delta\tattribute", "contents": "delta"},
{"trigger": "diff\tattribute", "contents": "diff"},
{"trigger": "encoding\tattribute", "contents": "encoding"},
{"trigger": "eol\tattribute", "contents": "eol"},
{"trigger": "export-ignore\tattribute", "contents": "export-ignore"},
{"trigger": "export-subst\tattribute", "contents": "export-subst"},
{"trigger": "filter\tattribute", "contents": "filter"},
{"trigger": "ident\tattribute", "contents": "ident"},
{"trigger": "merge\tattribute", "contents": "merge"},
{"trigger": "text\tattribute", "contents": "text"},
{"trigger": "whitespace\tattribute", "contents": "whitespace"}
]
}
25 changes: 25 additions & 0 deletions Git Files/Completions/Git Attributes - Diff.sublime-completions
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"scope": "meta.mapping.expect-value & meta.attribute.builtin.diff.git.attributes",
"completions": [
{"trigger": "ada\t(built-in) diff", "contents": "ada"},
{"trigger": "astextplain\t(built-in) diff", "contents": "astextplain"},
{"trigger": "bibtex\t(built-in) diff", "contents": "bibtex"},
{"trigger": "cpp\t(built-in) diff", "contents": "cpp"},
{"trigger": "csharp\t(built-in) diff", "contents": "csharp"},
{"trigger": "css\t(built-in) diff", "contents": "css"},
{"trigger": "exif\t(built-in) diff", "contents": "exif"},
{"trigger": "fortran\t(built-in) diff", "contents": "fortran"},
{"trigger": "fountain\t(built-in) diff", "contents": "fountain"},
{"trigger": "html\t(built-in) diff", "contents": "html"},
{"trigger": "java\t(built-in) diff", "contents": "java"},
{"trigger": "matlab\t(built-in) diff", "contents": "matlab"},
{"trigger": "objc\t(built-in) diff", "contents": "objc"},
{"trigger": "pascal\t(built-in) diff", "contents": "pascal"},
{"trigger": "perl\t(built-in) diff", "contents": "perl"},
{"trigger": "php\t(built-in) diff", "contents": "php"},
{"trigger": "python\t(built-in) diff", "contents": "python"},
{"trigger": "ruby\t(built-in) diff", "contents": "ruby"},
{"trigger": "tex\t(built-in) diff", "contents": "tex"},
{"trigger": "word\t(built-in) diff", "contents": "word"}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"scope": "meta.mapping.expect-value & meta.attribute.builtin.eol.git.attributes",
"completions": [
{"trigger": "crlf\teol", "contents": "crlf"},
{"trigger": "lf\teol", "contents": "lf"}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"scope": "meta.mapping.expect-value & meta.attribute.builtin.encoding.git.attributes",
"completions": [
{"trigger": "ASCII\tAscii", "contents": "ascii"},
{"trigger": "UTF-8\tUnicode", "contents": "utf-8"},
{"trigger": "UTF-16 LE\tUnicode", "contents": "utf-16-le"},
{"trigger": "UTF-16 BE\tUnicode", "contents": "utf-16-be"},
{"trigger": "ISO 8859-1\tWestern", "contents": "iso-8859-1"},
{"trigger": "ISO 8859-10\tNordic", "contents": "iso-8859-10"},
{"trigger": "ISO 8859-13\tEstonian", "contents": "iso-8859-13"},
{"trigger": "ISO 8859-14\tCeltic", "contents": "iso-8859-14"},
{"trigger": "ISO 8859-15\tWestern", "contents": "iso-8859-15"},
{"trigger": "ISO 8859-16\tRomanian", "contents": "iso-8859-16"},
{"trigger": "ISO 8859-2\tCentral European", "contents": "iso-8859-2"},
{"trigger": "ISO 8859-3\tWestern", "contents": "iso-8859-3"},
{"trigger": "ISO 8859-4\tBaltic", "contents": "iso-8859-4"},
{"trigger": "ISO 8859-5\tCyrillic", "contents": "iso-8859-5"},
{"trigger": "ISO 8859-6\tArabic", "contents": "iso-8859-6"},
{"trigger": "ISO 8859-7\tGreek", "contents": "iso-8859-7"},
{"trigger": "ISO 8859-8\tHebrew", "contents": "iso-8859-8"},
{"trigger": "ISO 8859-9\tTurkish", "contents": "iso-8859-9"},
{"trigger": "Windows 866\tCyrillic", "contents": "windows-866"},
{"trigger": "Windows 1250\tCentral European", "contents": "windows-1250"},
{"trigger": "Windows 1251\tCyrillic", "contents": "windows-1251"},
{"trigger": "Windows 1252\tWestern", "contents": "windows-1252"},
{"trigger": "Windows 1253\tGreek", "contents": "windows-1253"},
{"trigger": "Windows 1254\tTurkish", "contents": "windows-1254"},
{"trigger": "Windows 1255\tHebrew", "contents": "windows-1255"},
{"trigger": "Windows 1256\tArabic", "contents": "windows-1256"},
{"trigger": "Windows 1257\tBaltic", "contents": "windows-1257"},
{"trigger": "Windows 1258\tVietnamese", "contents": "windows-1258"},
{"trigger": "big5\tChineese Traditional", "contents": "gb2312"},
{"trigger": "CP 437\tDOS", "contents": "cp-437"},
{"trigger": "euc_jp\tJapaneese", "contents": "euc_jp"},
{"trigger": "euc_kr\tKorean", "contents": "euc_kr"},
{"trigger": "gb2312\tChineese Simplified", "contents": "gb2312"},
{"trigger": "KOI8-R\tCyrillic", "contents": "koi8-r"},
{"trigger": "KOI8-U\tCyrillic", "contents": "koi8-u"},
{"trigger": "Mac Roman\tWestern", "contents": "mac-roman"},
{"trigger": "Shift_JIS\tJapaneese", "contents": "Shift_JIS"},
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"scope": "meta.mapping.expect-value & meta.attribute.builtin.filter.git.attributes",
"completions": [
]
}
13 changes: 13 additions & 0 deletions Git Files/Completions/Git Attributes - Merge.sublime-completions
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"scope": "meta.mapping.expect-value & meta.attribute.builtin.merge.git.attributes",
"completions": [
{"trigger": "binary\t(built-in) merge", "contents": "binary"},
{"trigger": "ours\t(built-in) merge", "contents": "ours"},
{"trigger": "patience\t(built-in) merge", "contents": "patience"},
{"trigger": "recursive\t(built-in) merge", "contents": "recursive"},
{"trigger": "resolve\t(built-in) merge", "contents": "resolve"},
{"trigger": "text\t(built-in) merge", "contents": "text"},
{"trigger": "theirs\t(built-in) merge", "contents": "theirs"},
{"trigger": "union\t(built-in) merge", "contents": "union"}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"scope": "meta.mapping.expect-value & meta.attribute.builtin.text.git.attributes",
"completions": [
{"trigger": "auto\ttext", "contents": "auto"}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"scope": "meta.mapping.expect-value & meta.attribute.builtin.whitespace.git.attributes",
"completions": [
{"trigger": "blank-at-eof\twhitespace", "contents": "blank-at-eof"},
{"trigger": "blank-at-eol\twhitespace", "contents": "blank-at-eol"},
{"trigger": "cr-at-eol\twhitespace", "contents": "cr-at-eol"},
{"trigger": "indent-with-non-tab\twhitespace", "contents": "indent-with-non-tab"},
{"trigger": "space-before-tab\twhitespace", "contents": "space-before-tab"},
{"trigger": "tab-in-indent\twhitespace", "contents": "tab-in-indent"},
{"trigger": "trailing-space\twhitespace", "contents": "trailing-space"},
{"trigger": "tabwidth=x\twhitespace", "contents": "tabwidth=${0:8}"}
]
}
14 changes: 14 additions & 0 deletions Git Files/Git Attributes.sublime-settings
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"auto_complete_selector": "text.git - comment - string.quoted",
"auto_complete_triggers": [
{
"selector": "meta.attributes-list.git.attributes - meta.attribute - punctuation.separator",
"characters": " -!"
},
{
"selector": "meta.attribute.builtin & meta.mapping.expect-value.git.attributes",
"characters": "-=,"
}
],
"word_separators": "./\\()\"':,.;<>~!@#$%^&*|+=[]{}`~?" // default without '-'
}
210 changes: 210 additions & 0 deletions Git Files/Git Attributes.sublime-syntax
Original file line number Diff line number Diff line change
@@ -0,0 +1,210 @@
%YAML 1.2
---
# Syntax based on documentation here:
# https://git-scm.com/docs/gitattributes
# https://git-scm.com/book/en/v2/Customizing-Git-Git-Attributes

# Examples: https://github.com/alexkaratarakis/gitattributes

name: Git Attributes
file_extensions:
- attributes # .git/info/attributes
- gitattributes # *.gitattributes
- .gitattributes # ~/.gitattributes
scope: text.git.attributes

contexts:

main:
- include: Git Common.sublime-syntax#comments-line
- include: macro
- include: pattern

##[ MACROS ]###########################################################

macro:
- match: (\[)([^-!]\S*)(\])
scope: meta.brackets.git.attributes
captures:
1: punctuation.definition.brackets.begin.git.attributes
2: string.unquoted.git.attributes entity.name.macro.git.attributes
3: punctuation.definition.brackets.end.git.attributes
push: attributes-list

##[ PATH PATTERN ]#####################################################

pattern:
# ignore whitespace at the beginning of a line
# patterns may not start with operators: - ! [
- match: '[-!\[]|(?=\S)'
scope: invalid.illegal.operator.git.attributes
push: [pattern-attributes, pattern-content]

pattern-content:
# quoted path pattern
- match: \"
scope: punctuation.definition.string.begin.git.attributes
set: [pattern-content-quoted, Git Common.sublime-syntax#fnmatch-start]
# unquoted path pattern
- match: ''
set: [pattern-content-unquoted, Git Common.sublime-syntax#fnmatch-start]

pattern-content-quoted:
- meta_scope: string.quoted.double.git.attributes
- meta_content_scope: entity.name.pattern.git.attributes
- include: string-end
- include: Git Common.sublime-syntax#fnmatch-body

pattern-content-unquoted:
- meta_scope: string.unquoted.git.attributes
- meta_content_scope: entity.name.pattern.git.attributes
- match: (?=\s)
pop: true
- include: Git Common.sublime-syntax#fnmatch-body

pattern-attributes:
- match: ''
set: attributes-list

##[ ATTRIBUTES LIST ]##################################################

attributes-list:
- meta_content_scope: meta.attributes-list.git.attributes
# attriubte list ends with line
- match: $\n?
scope: meta.attributes-list.git.attributes
pop: true
# set/unset operators
- match: '[-!](?=\w)'
scope: keyword.operator.logical.git.attributes
# known attributes
- match: (?=diff\b)
push: [meta-diff, attribute-key]
- match: (?=encoding\b)
push: [meta-encoding, attribute-key]
- match: (?=eol\b)
push: [meta-eol, attribute-key]
- match: (?=filter\b)
push: [meta-filter, attribute-key]
- match: (?=merge\b)
push: [meta-merge, attribute-key]
- match: (?=text\b)
push: [meta-text, attribute-key]
- match: (?=whitespace\b)
push: [meta-whitespace, attribute-key]
# unknown/other attribute
- match: (?=\w)
push: [meta-other, attribute-key]
# close the meta mapping gab
- match: \s+
scope: meta.mapping.git.attributes
# invalid attribute name
- match: \S+
scope: invalid.illegal.attribute-name.git.attributes

meta-diff:
- meta_scope: meta.attribute.builtin.diff.git.attributes
- include: else-pop

meta-encoding:
- meta_scope: meta.attribute.builtin.encoding.git.attributes
- include: else-pop

meta-eol:
- meta_scope: meta.attribute.builtin.eol.git.attributes
- include: else-pop

meta-filter:
- meta_scope: meta.attribute.builtin.filter.git.attributes
- include: else-pop

meta-merge:
- meta_scope: meta.attribute.builtin.merge.git.attributes
- include: else-pop

meta-text:
- meta_scope: meta.attribute.builtin.text.git.attributes
- include: else-pop

meta-whitespace:
- meta_scope: meta.attribute.builtin.whitespace.git.attributes
- include: else-pop

meta-other:
- meta_scope: meta.attribute.other.git.attributes
- include: else-pop

##[ ATTRIBUTE KEY VALUE ]##############################################

attribute-key:
- match: \w+[-\w]*\b
scope: meta.mapping.key.git.attributes variable.language.attribute.git.attributes
set: attribute-maybe-value-list
- include: else-pop

attribute-maybe-value-list:
- meta_content_scope: meta.mapping.git.attributes
- match: =(?=\S)
scope: punctuation.separator.mapping.key-value.git.attributes
set: [attribute-value-list, attribute-value-content]
- match: =
scope: punctuation.separator.mapping.key-value.git.attributes
set: attribute-value-expected
- include: attribute-separator
- include: else-pop

attribute-value-list:
- meta_content_scope: meta.mapping.value.git.attributes
- include: attribute-separator
- match: ',(?=\S)'
scope: punctuation.separator.mapping.values.git.attributes
push: attribute-value-content
- match: ','
scope: punctuation.separator.mapping.values.git.attributes
set: attribute-value-expected
- match: \S
scope: invalid.illegal.value.git.attributes
- include: else-pop

attribute-value-content:
# double quoted value
- match: \"
scope: punctuation.definition.string.begin.git.attributes
set:
- meta_scope: string.quoted.double.git.attributes
- include: string-end
- match: \\[\\\"\'fnrst]
scope: constant.character.escape.git.attributes
# unquoted value is everything except , and whitespace
- match: '[^,\s]*'
scope: string.unquoted.git.attributes
pop: true
- include: else-pop

attribute-value-expected:
# Attributes are separated by whitespace
# One whitespace after each attribute/value is captured as separator
- match: \s
scope: meta.mapping.expect-value.git.attributes punctuation.separator.mapping.pair.git.attributes
pop: true

attribute-separator:
# Attributes are separated by whitespace
# One whitespace after each attribute/value is captured as separator
- match: \s
scope: meta.mapping.git.attributes punctuation.separator.mapping.pair.git.attributes
pop: true

##[ PROTOTYPES ]#######################################################

string-end:
- match: \"
scope: punctuation.definition.string.end.git.attributes
pop: true
- match: $\n?
scope: invalid.illegal.unexpected.eol.git.attributes
pop: true

else-pop:
- match: ''
pop: true
Loading

0 comments on commit a7284db

Please sign in to comment.