Skip to content

Commit

Permalink
Added New command
Browse files Browse the repository at this point in the history
  • Loading branch information
dariusf committed Nov 30, 2013
1 parent cfaa905 commit ae3fbe8
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 14 deletions.
5 changes: 5 additions & 0 deletions Default.sublime-commands
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
"command": "synesthesia_delete",
"args": {}
},
{
"caption": "Synesthesia: New Highlighting Scheme",
"command": "synesthesia_new",
"args": {}
},
{
"caption": "Synesthesia: Compile Highlighting Scheme",
"command": "synesthesia_compile",
Expand Down
12 changes: 6 additions & 6 deletions compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class HighlightingScheme():
"""

default_colours = templates.default_colours_template
default_colours = templates.default_colours

def __init__(self, directory, data):
self.directory = directory
Expand All @@ -104,7 +104,7 @@ def save(self, themename):
# prevents recursive dependency, since it only looks in the same directory
if i not in already_included:
already_included.append(i)
_, entries = load_json_data("%s%s%s.json" % (self.directory, PATH_SEPARATOR, i))
_, entries = load_json_data(os.path.join(self.directory, i + '.json'))
if "include" in entries:
inclusions.extend(entries["include"])
if "patterns" in entries:
Expand Down Expand Up @@ -135,14 +135,14 @@ def save(self, themename):
theme_scopes = concat_string_list(theme_scopes)

# produce output files
package_directory = sublime.packages_path() + PATH_SEPARATOR + "Synesthesia" + PATH_SEPARATOR
package_directory = os.path.join(sublime.packages_path(), "Synesthesia")
scope_filename = package_directory + themename + ".tmLanguage"
theme_filename = package_directory + themename + ".tmTheme"
settings_filename = package_directory + themename + ".sublime-settings"
write_file(scope_filename, templates.scope_template % (themename, patterns, "source" if autocompletion else "text", themename, uuid.uuid4()))
write_file(scope_filename, templates.scope % (themename, patterns, "source" if autocompletion else "text", themename, uuid.uuid4()))
print "Written to %s." % scope_filename
write_file(theme_filename, templates.theme_template % (themename, self.default_colours, theme_scopes, uuid.uuid4()))
write_file(theme_filename, templates.theme % (themename, self.default_colours, theme_scopes, uuid.uuid4()))
print "Written to %s." % theme_filename
write_file(settings_filename, templates.default_settings_template % themename)
write_file(settings_filename, templates.default_settings % themename)
print "Written to %s." % settings_filename
sublime.status_message("Highlighting scheme %s generated." % themename)
6 changes: 2 additions & 4 deletions delete.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import sublime, sublime_plugin
import os

PATH_SEPARATOR = "\\" if sublime.platform() == "windows" else "/"

def extract_syntax_name(path):
temp = path.split("/")
return temp[len(temp)-1].split(".")[0]
Expand All @@ -20,12 +18,12 @@ def done(self, which):
v.set_syntax_file("%s/Text/Plain text.tmLanguage" % sublime.packages_path())

# delete the files
package_directory = sublime.packages_path() + PATH_SEPARATOR + "Synesthesia" + PATH_SEPARATOR
package_directory = os.path.join(sublime.packages_path(), "Synesthesia")
files = ["%s.sublime-settings", "%s.tmLanguage", "%s.tmLanguage.cache", "%s.tmTheme", "%s.tmTheme.cache"]
files_deleted = False

for filepath in files:
filepath = package_directory + (filepath % which)
filepath = os.path.join(package_directory, filepath % which)
if os.path.exists(filepath):
os.remove(filepath)
files_deleted = True
Expand Down
11 changes: 11 additions & 0 deletions new.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import sublime, sublime_plugin
import os, tempfile, webbrowser
import templates

class SynesthesiaNewCommand(sublime_plugin.WindowCommand):
def run(self):
v = self.window.new_file()
v.settings().set('default_dir', os.path.join(sublime.packages_path(), 'Synesthesia'))
v.set_syntax_file('Packages/JavaScript/JSON.tmLanguage')

v.run_command("insert_snippet", {"contents": templates.new_file})
17 changes: 13 additions & 4 deletions templates.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

scope_template = """<?xml version="1.0" encoding="UTF-8"?>
scope = """<?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>
Expand All @@ -21,7 +21,16 @@
</plist>
"""

default_colours_template = """
new_file = """{
"include": ["lightmarkdown"],
"autocompletion": false,
"patterns": {
$0"\\b(?hello)\\b": "dodgerblue",
"world": "#ff0000"
}
}"""

default_colours = """
<dict>
<key>settings</key>
<dict>
Expand All @@ -41,7 +50,7 @@
</dict>
"""

theme_template = """<?xml version="1.0" encoding="UTF-8"?>
theme = """<?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>
Expand Down Expand Up @@ -99,7 +108,7 @@
</dict>
"""

default_settings_template = """
default_settings = """
{
"color_scheme": "Packages/Synesthesia/%s.tmTheme"
}
Expand Down

0 comments on commit ae3fbe8

Please sign in to comment.