Skip to content

Commit be3d6c5

Browse files
committed
Adding 'show build window on failure' feature from Issue #1
1 parent 67b0191 commit be3d6c5

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ Set to `1` to trigger a build on save. By default, this is set to `1`. I.e., Sub
4444
* **filename_filter**
4545
SublimeOnSaveBuild matches the name of the file being saved against this regular expression to determine if a build should be triggered. By default, the setting has a value of `"\\.(css|js|sass|less|scss)$"`.
4646

47+
* **show_build_window_on_failure_only**
48+
Set to `1` if you want the build window to display only upon a failed build. The default setting is `1`. This setting can be configured on a project level.
49+
4750
Usage
4851
-----
4952
1. Make sure you have a build operation set up in your Sublime Text 2 project and you are able to build using `Control+B` (Linux/Windows) or `Command+B` (OS X).

SublimeOnSaveBuild.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import sublime
22
import sublime_plugin
33
import re
4-
4+
import functools
55

66
class SublimeOnSaveBuild(sublime_plugin.EventListener):
77
def on_post_save(self, view):
@@ -15,10 +15,39 @@ def on_post_save(self, view):
1515
# Load filename filter. Again, a project level setting takes precedence.
1616
filename_filter = view.settings().get('filename_filter', global_settings.get('filename_filter', '*'))
1717

18+
# Check if we should automatically hide the build window
19+
show_build_window_on_failure_only = view.settings().get('show_build_window_on_failure_only', global_settings.get('auto_hide_build_window', True))
20+
1821
if not should_build:
1922
return
2023

2124
if not re.search(filename_filter, view.file_name()):
2225
return
2326

27+
# show the 'exec' view before building, so we can read from it afterwards
28+
self.output_view = view.window().get_output_panel("exec")
29+
2430
view.window().run_command('build')
31+
32+
if show_build_window_on_failure_only:
33+
self.num_polls = 0
34+
# immediately hide the 'exec' panel. Will show it again later if there were errors
35+
view.window().run_command("hide_panel", {"panel": "output.exec"})
36+
# start polling for results every 100s
37+
self.poll_for_results(view)
38+
39+
def poll_for_results(self, view):
40+
build_finished = self.output_view.find('Finished', 0) != None
41+
42+
if build_finished:
43+
errors = self.output_view.find('Error', 0)
44+
if errors != None:
45+
view.window().run_command("show_panel", {"panel": "output.exec"})
46+
else:
47+
if self.num_polls < 50:
48+
sublime.set_timeout(functools.partial(self.poll_for_results, view), 100)
49+
else:
50+
# show the window if the build took longer than the specified amount
51+
view.window().run_command("show_panel", {"panel": "output.exec"})
52+
53+
self.num_polls += 1

0 commit comments

Comments
 (0)