Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for LaTeXTools build output, show build output on error only #18

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ Set to `1` to trigger a build on save. By default, this is set to `1`. I.e., Sub
* **filename_filter**
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)$"`.

* **show_build_window_on_failure_only**
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.

Usage
-----
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).
Expand Down
28 changes: 27 additions & 1 deletion SublimeOnSaveBuild.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import sublime
import sublime_plugin
import re

import functools

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

# Check if we should automatically hide the build window
auto_hide_build_window = view.settings().get('auto_hide_build_window', global_settings.get('auto_hide_build_window', True))

if not should_build:
return

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

# show the 'exec' view before building, so we can read from it afterwards
self.output_view = view.window().get_output_panel("exec")

view.window().run_command('build')

if auto_hide_build_window:
self.num_polls = 0
# start polling for results every 100s
self.poll_for_results(view)

def poll_for_results(self, view):
build_finished = (self.output_view.find('Finished', 0) != None) or (self.output_view.find('Done', 0) != None)

if build_finished:
errors = (self.output_view.find('Error', 0) or self.output_view.find('error', 0))
if errors == None:
view.window().run_command("hide_panel", {"panel": "output.exec"})
else:
view.window().run_command("show_panel", {"panel": "output.exec"})
else:
if self.num_polls < 300:
sublime.set_timeout(functools.partial(self.poll_for_results, view), 200)

self.num_polls += 1