From 4be7738249239c455eac8581d27c60ea8bef3af5 Mon Sep 17 00:00:00 2001 From: Robin Date: Mon, 5 Dec 2011 12:21:00 +0800 Subject: [PATCH] add settings. --- Default.sublime-commands | 14 ++++++++++ Main.sublime-menu | 35 +++++++++++++++++++++++++ gjslint.py | 17 +++++++----- sublime-closure-linter.sublime-settings | 10 +++++++ 4 files changed, 70 insertions(+), 6 deletions(-) create mode 100644 sublime-closure-linter.sublime-settings diff --git a/Default.sublime-commands b/Default.sublime-commands index feabb7b..d6ac6dd 100644 --- a/Default.sublime-commands +++ b/Default.sublime-commands @@ -6,5 +6,19 @@ { "caption": "Closure Linter: Show Closure Linter Result", "command": "show_closure_linter_result" + }, + { + "caption": "Preferences: Closure Linter Settings – Default", + "command": "open_file", "args": + { + "file": "${packages}/sublime-closure-linter/sublime-closure-linter.sublime-settings" + } + }, + { + "caption": "Preferences: Closure Linter Settings – User", + "command": "open_file", "args": + { + "file": "${packages}/User/sublime-closure-linter.sublime-settings" + } } ] diff --git a/Main.sublime-menu b/Main.sublime-menu index 9c17479..e96fe73 100644 --- a/Main.sublime-menu +++ b/Main.sublime-menu @@ -19,5 +19,40 @@ ] } ] + }, + { + "id": "preferences", + "children": + [ + { + "caption": "Package Settings", + "id": "package-settings", + "children": + [ + { + "caption": "Closure Linter", + "children": + [ + { + "caption": "Settings – Default", + "command": "open_file", + "args": + { + "file": "${packages}/sublime-closure-linter/sublime-closure-linter.sublime-settings" + } + }, + { + "caption": "Settings – User", + "command": "open_file", + "args": + { + "file": "${packages}/User/sublime-closure-linter.sublime-settings" + } + } + ] + } + ] + } + ] } ] diff --git a/gjslint.py b/gjslint.py index 1f5124e..d96b4c4 100644 --- a/gjslint.py +++ b/gjslint.py @@ -6,6 +6,7 @@ from asyncprocess import * RESULT_VIEW_NAME = 'gjslint_result_view' +SETTINGS_FILE = "sublime-closure-linter.sublime-settings" class ShowClosureLinterResultCommand(sublime_plugin.WindowCommand): """show closure linter result""" @@ -14,11 +15,15 @@ def run(self): class ClosureLinterCommand(sublime_plugin.WindowCommand): def run(self): + s = sublime.load_settings(SETTINGS_FILE) + file_path = self.window.active_view().file_name() file_name = os.path.basename(file_path) - cmd = '/usr/local/bin/gjslint "' + file_path + '"' + cmd = s.get('gjslint_path', 'jslint') + ' ' + s.get('gjslint_flags', '') + ' "' + file_path + '"' + + if s.get('debug', False) == True: + print "DEBUG: " + str(cmd) - print "DEBUG: " + str(cmd) self.buffered_data = '' self.file_path = file_path self.file_name = file_name @@ -68,7 +73,7 @@ def append_data(self, proc, data, flush=False): selection_was_at_end = (len(self.output_view.sel()) == 1 and self.output_view.sel()[0] == sublime.Region(self.output_view.size())) self.output_view.set_read_only(False) edit = self.output_view.begin_edit() - self.output_view.insert(edit, self.output_view.size(), str.strip()) + self.output_view.insert(edit, self.output_view.size(), str) if selection_was_at_end: self.output_view.show(self.output_view.size()) self.output_view.end_edit(edit) @@ -101,7 +106,9 @@ def on_deactivated(self, view): if view.name() != RESULT_VIEW_NAME: return self.previous_resion = None - self.file_view.erase_regions(RESULT_VIEW_NAME) + + if self.file_view: + self.file_view.erase_regions(RESULT_VIEW_NAME) def on_selection_modified(self, view): if ClosureLinterEventListener.disabled: @@ -143,5 +150,3 @@ def on_selection_modified(self, view): # highlight file_view line file_view.add_regions(RESULT_VIEW_NAME, [file_region], "string") - - diff --git a/sublime-closure-linter.sublime-settings b/sublime-closure-linter.sublime-settings new file mode 100644 index 0000000..a328e53 --- /dev/null +++ b/sublime-closure-linter.sublime-settings @@ -0,0 +1,10 @@ +{ + // Path to the gjslint. + "gjslint_path": "gjslint", + + // Flags pass to gjslint. + "gjslint_flags": "", + + // debug flag. + "debug": false +}