This repository has been archived by the owner on Feb 8, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
SyntaxChecker.py
56 lines (49 loc) · 2.51 KB
/
SyntaxChecker.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
import sublime, sublime_plugin
def has_ext(name, exts):
if not isinstance(exts, list):
exts = [exts]
return any(name.endswith(ext) for ext in exts)
class SyntaxChecker(sublime_plugin.EventListener):
def on_post_save(self, view):
global_settings = sublime.load_settings(__name__ + '.sublime-settings')
exts = view.settings().get('checker_extensions', global_settings.get('checker_extensions', {}))
exts['ruby'] = exts['ruby'] or ['.rb']
exts['xml'] = exts['xml'] or ['.xml']
exts['perl'] = exts['perl'] or ['.pl']
exts['php'] = exts['php'] or ['.php', '.php.inc']
print exts
name = view.file_name()
print name
for key in ['ruby', 'perl', 'php', 'xml']:
if has_ext(name, exts[key]):
print "got it"
view.window().run_command(key + "_checker", {"saving": True})
break
class RubyCheckerCommand(sublime_plugin.TextCommand):
def run(self, edit, saving=False):
view = self.view
global_settings = sublime.load_settings(__name__ + '.sublime-settings')
cmd_setting = 'ruby_syntax_checker_cmd'
ruby = view.settings().get(cmd_setting, global_settings.get(cmd_setting))
view.window().run_command("exec", {"cmd": [ruby, "-cw", view.file_name()]})
class PerlCheckerCommand(sublime_plugin.TextCommand):
def run(self, edit, saving=False):
view = self.view
global_settings = sublime.load_settings(__name__ + '.sublime-settings')
cmd_setting = 'perl_syntax_checker_cmd'
perl = view.settings().get(cmd_setting, global_settings.get(cmd_setting))
view.window().run_command("exec", {"cmd": [perl, "-cw", view.file_name()]})
class PhpCheckerCommand(sublime_plugin.TextCommand):
def run(self, edit, saving=False):
view = self.view
global_settings = sublime.load_settings(__name__ + '.sublime-settings')
cmd_setting = 'php_syntax_checker_cmd'
php = view.settings().get(cmd_setting, global_settings.get(cmd_setting))
view.window().run_command("exec", {"cmd": [php, "-l", view.file_name()]})
class XmlCheckerCommand(sublime_plugin.TextCommand):
def run(self, edit, saving=False):
view = self.view
global_settings = sublime.load_settings(__name__ + '.sublime-settings')
cmd_setting = 'xml_syntax_checker_cmd'
xml = view.settings().get(cmd_setting, global_settings.get(cmd_setting))
view.window().run_command("exec", {"cmd": [xml, "--noout", view.file_name()]})