forked from evandroforks/SublimePackageDefault
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
new_templates.py
123 lines (100 loc) · 4.2 KB
/
new_templates.py
1
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
import os
import textwrap
import sublime
import sublime_plugin
def reformat(template):
return textwrap.dedent(template).lstrip()
class NewBuildSystemCommand(sublime_plugin.WindowCommand):
def run(self):
v = self.window.new_file()
v.settings().set('default_dir', os.path.join(sublime.packages_path(), 'User'))
v.assign_syntax('Packages/JavaScript/JSON.sublime-syntax')
v.set_name('untitled.sublime-build')
template = reformat(
"""
{
\t"shell_cmd": "${0:make}"
}
""")
v.run_command("insert_snippet", {"contents": template})
class NewPluginCommand(sublime_plugin.WindowCommand):
def run(self):
v = self.window.new_file()
v.settings().set('default_dir', os.path.join(sublime.packages_path(), 'User'))
v.assign_syntax('Packages/Python/Python.sublime-syntax')
template = reformat(
"""
import sublime
import sublime_plugin
class ExampleCommand(sublime_plugin.TextCommand):
\tdef run(self, edit):
\t\t$0self.view.insert(edit, 0, "Hello, World!")
""")
v.run_command("insert_snippet", {"contents": template})
class NewSnippetCommand(sublime_plugin.WindowCommand):
def run(self):
v = self.window.new_file()
v.settings().set('default_dir', os.path.join(sublime.packages_path(), 'User'))
v.settings().set('default_extension', 'sublime-snippet')
v.assign_syntax('Packages/XML/XML.sublime-syntax')
template = reformat(
"""
<snippet>
\t<content><![CDATA[
Hello, \\${1:this} is a \\${2:snippet}.
]]></content>
\t<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
\t<!-- <tabTrigger>hello</tabTrigger> -->
\t<!-- Optional: Set a scope to limit where the snippet will trigger -->
\t<!-- <scope>source.python</scope> -->
</snippet>
""")
v.run_command("insert_snippet", {"contents": template})
class NewSyntaxCommand(sublime_plugin.WindowCommand):
def run(self):
v = self.window.new_file()
v.settings().set('default_dir', os.path.join(sublime.packages_path(), 'User'))
v.settings().set('default_extension', 'sublime-syntax')
v.assign_syntax("Packages/YAML/YAML.sublime-syntax")
template = reformat(
R"""
%YAML 1.2
---
# See http://www.sublimetext.com/docs/syntax.html
file_extensions:
- ec
scope: source.example-c
contexts:
main:
# Strings begin and end with quotes, and use backslashes as an escape
# character
- match: '"'
scope: punctuation.definition.string.begin.example-c
push: double_quoted_string
# Comments begin with a '//' and finish at the end of the line
- match: '//'
scope: punctuation.definition.comment.example-c
push: line_comment
# Keywords are if, else for and while.
# Note that blackslashes don't need to be escaped within single quoted
# strings in YAML. When using single quoted strings, only single quotes
# need to be escaped: this is done by using two single quotes next to each
# other.
- match: '\b(if|else|for|while)\b'
scope: keyword.control.example-c
# Numbers
- match: '\b(-)?[0-9.]+\b'
scope: constant.numeric.example-c
double_quoted_string:
- meta_scope: string.quoted.double.example-c
- match: '\\.'
scope: constant.character.escape.example-c
- match: '"'
scope: punctuation.definition.string.end.example-c
pop: true
line_comment:
- meta_scope: comment.line.example-c
- match: $
pop: true
""")
v.run_command('append', {'characters': template})