Skip to content

Commit

Permalink
fixed broken settings menu and added config options
Browse files Browse the repository at this point in the history
  • Loading branch information
emekoi committed Jul 7, 2019
1 parent aeab9e2 commit ecf2bb1
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 15 deletions.
5 changes: 3 additions & 2 deletions Support/Zig.sublime-build → Build Systems/Zig.sublime-build
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"cmd": ["zig", "build"],
"selector": "source.zig",
"file_regex": "^(.+.zig):(\\d+):(\\d+): error: (.+)$",
"line_regex": "^.+.zig:(\\d+):(\\d+): error: (.+)$",
"working_dir": "$folder",
"file_regex": "^(\\S.*):(\\d*):(\\d*): (?:[^:]*): (.*)$",
"line_regex": "^(?:\\S.*):(\\d*):(\\d*): (?:[^:]*): (.*)$",

"variants": [
{
Expand Down
10 changes: 5 additions & 5 deletions Support/Main.sublime-menu → Menus/Main.sublime-menu
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
"children":
[
{
"command": "edit_settings", "args":
{
"base_file": "${packages}/User/Zig.sublime-settings",
"default": "{\n\t$0\n}\n"
"caption": "Settings",
"command": "edit_settings",
"args": {
"base_file": "${packages}/Zig Language/Settings/Zig.sublime-settings",
"default": "// Settings in here override those in \"Zig Language/Settings/Zig.sublime-settings\",\n\n{\n\t$0\n}\n"
},
"caption": "Settings"
},
]
}
Expand Down
2 changes: 2 additions & 0 deletions Zig.sublime-settings → Settings/Zig.sublime-settings
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{
"zig.executable": "zig",
"zig.build.on_save": false,
"zig.fmt.on_save": true,
"zig.fmt.mode": "file",
}
26 changes: 18 additions & 8 deletions Zig.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
import sublime
import sublime_plugin

def fmt(fmt, dic):
for k in dic:
fmt = fmt.replace("{" + k + "}", str(dic[k]))
return fmt
settings = sublime.load_settings('Zig.sublime-settings')


def get_setting(view, opt, default):
return view.settings().get(opt, settings.get(opt, default))


class Zig(sublime_plugin.EventListener):
def on_post_save_async(self, view):
global_settings = sublime.load_settings(fmt("{name}.sublime-settings", { "name": self.__class__.__name__ }))
should_fmt = view.settings().get('fmt.on_save.enabled', global_settings.get('fmt.on_save.enabled'))
if (should_fmt):
view.window().run_command("build", {"variant": "Format File"})
sel = view.sel()[0]
region = view.word(sel)
scope = view.scope_name(region.b)
if scope.find('source.zig') != -1:
should_fmt = get_setting(view, 'zig.fmt.on_save', True)
should_build = get_setting(view, 'zig.build.on_save', False)

if (should_fmt and not should_build):
mode = get_setting(view, 'zig.fmt.mode', 'File').title()
view.window().run_command('build', {'variant': 'Format ' + mode})
elif (should_build and not should_fmt):
view.window().run_command('build')

0 comments on commit ecf2bb1

Please sign in to comment.