Skip to content

Instantly share code, notes, and snippets.

@VICTORVICKIE
Last active August 28, 2021 05:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save VICTORVICKIE/79e6ef8428f962733b8c953cd0f635fa to your computer and use it in GitHub Desktop.
Save VICTORVICKIE/79e6ef8428f962733b8c953cd0f635fa to your computer and use it in GitHub Desktop.
Sublime Per Tab Panel Execution
{
"target":"special_build",
// "shell_cmd":"gcc \"${file}\" -o \"${file_path}/${file_base_name}\" && \"${file_path}/${file_base_name}\"",
// selector: "source.c"
"selector": "source.python",
}
#This file lies in Packages/TabExecution
import sublime
import sublime_plugin
import os
from Terminus.terminus.terminal import Terminal
def _getname(window):
"""basically getting the file name from the path"""
view = window.active_view()
if view.file_name() is None:
return None
name = os.path.basename(view.file_name())
folder = os.path.dirname(view.file_name()).split(os.path.sep)[-1]
return "%s-%s" % (folder, name)
class SpecialBuildCommand(sublime_plugin.WindowCommand):
def run(self, shell_cmd = None):
window = self.window
name = _getname(window)
if name is None:
window.status_message('File is not saved to disk')
return
window.run_command(
"terminus_open", {
"shell_cmd" : shell_cmd if shell_cmd else "python -u \"$file\"",
# "tag" : "build-%s" % name,
"panel_name" : "%s's Build" % name,
"cwd" : "${file_path:${folder}}",
"auto_close" : False,
"timeit" : True,
"focus": False,
"cancellable": True
})
class SpecialCancelBuildCommand(sublime_plugin.WindowCommand):
def run(self, *args, **kwargs):
window = self.window
# If there's no active panel, or the current panel isn't a build panel
# that we opened, don't do anything.
if not window.active_panel() or "'s Build" not in window.active_panel():
window.status_message('Cannot cancel build; no build is focusd')
return
panel_name = window.active_panel().replace("output.", "")
view = window.find_output_panel(panel_name)
if not view:
return
terminal = Terminal.from_id(view.id())
if not terminal:
return
print("out")
if terminal.cancellable:
print("in")
terminal.cleanup(by_user=True)
class AutoRevealAssociatedBuildListener(sublime_plugin.EventListener):
def on_activated(self, view):
if not view.settings().get("auto_reveal_associated_build", False):
return
window = view.window()
if (window.active_panel() and "output." not in window.active_panel()):
return
for panel in window.panels():
if "%s's Build" % _getname(window) in panel:
window.run_command("show_panel", {"panel": panel})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment