Sublime Text allows you to customize where the build results can be displayed through its versatile build system. Here are 10 places where Sublime's Build Results can be displayed with instructions on how to set them up:
- Output Panel:
To display the build results in the output panel, create a custom build system, and set the target to exec. This is the default behavior.
{
"cmd": ["your-command", "your-arguments"],
"selector": "source.your_language"
}
- New file:
To display build results in a new file, create a custom build system and specify a plugin to handle it.
{
"cmd": ["your-command", "your-arguments"],
"selector": "source.your_language",
"target": "build_output_to_new_file"
}
Create a new plugin:
- Go to
Tools > Developer > New Plugin.
- Replace the existing template with the following code:
import sublime_plugin
class BuildOutputToNewFileCommand(sublime_plugin.WindowCommand):
def run(self, **kwargs):
self.window.run_command('exec', kwargs)
self.orig_view = self.window.active_view()
def on_done(output_view_id):
output_view = sublime.View(output_view_id)
content = output_view.substr(sublime.Region(0, output_view.size()))
new_view = self.window.new_file()
new_view.run_command('insert_snippet', {'contents': content})
new_view.set_name('Build Output')
self.window.run_command('show_panel', {'panel': 'output.exec', 'wait': True, 'cb': on_done})
-
Save the file as BuildOutputToNewFile.py in the Packages/User folder.
-
Specific existing file:
To display build results in a specific existing file, use the same custom build system and plugin developed in the previous step. It's just necessary to change the on_done function to open the specified file.
Replace the on_done function with the following lines:
def on_done(output_view_id):
output_view = sublime.View(output_view_id)
content = output_view.substr(sublime.Region(0, output_view.size()))
output_file = 'your_output_file_path_here'
existing_view = self.window.find_open_file(output_file)
if not existing_view:
existing_view = self.window.open_file(output_file)
existing_view.run_command('select_all')
existing_view.run_command('right_delete')
existing_view.run_command('insert_snippet', {'contents': content})
- Quick Panel:
To display build results in the quick panel, create a custom build system and specify a plugin to handle it.
{
"cmd": ["your-command", "your-arguments"],
"selector": "source.your_language",
"target": "build_output_to_quick_panel"
}
Create a new plugin:
- Go to
Tools > Developer > New Plugin.
- Replace the existing template with the following code:
import sublime
import sublime_plugin
class BuildOutputToQuickPanelCommand(sublime_plugin.WindowCommand):
def run(self, cmd):
self.output = ""
proc = subprocess.Popen(
syntax.cmd,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
shell=True
)
for line in proc.stdout:
self.output += line.decode('utf-8')
for line in proc.stderr:
self.output += line.decode('utf-8')
proc.communicate()
self.output_list = self.output.split('\n')
self.window.show_quick_panel(self.output_list, self.on_done)
def on_done(self, picked):
if picked == -1:
return
sublime.status_message(self.output_list[picked])
-
Save the file as BuildOutputToQuickPanel.py in the Packages/User folder.
-
Status Bar:
To display build results in the status bar, create a custom build system and specify a plugin to handle it.
{
"cmd": ["your-command", "your-arguments"],
"selector": "source.your_language",
"target": "build_output_to_status_bar"
}
Create a new plugin:
- Go to
Tools > Developer > New Plugin.
- Replace the existing template with the following code:
import sublime
import sublime_plugin
import subprocess
class BuildOutputToStatusBarCommand(sublime_plugin.WindowCommand):
def run(self, **kwargs):
self.window.run_command('exec', kwargs)
def on_done():
output_view = self.window.find_output_panel('exec')
content = output_view.substr(sublime.Region(0, output_view.size()))
self.window.active_view().set_status("output", content)
self.window.run_command('show_panel', {'panel': 'output.exec', 'wait': True, 'cb': on_done})
-
Save the file as BuildOutputToStatusBar.py in the Packages/User folder.
-
In a comment in the current document:
To display build results as a comment in the current document, create a custom build system and specify a plugin to handle it.
{
"cmd": ["your-command", "your-arguments"],
"selector": "source.your_language",
"target": "build_output_to_comment"
}