Skip to content

Instantly share code, notes, and snippets.

@christianwish
Last active September 21, 2018 09:43
Show Gist options
  • Save christianwish/20ed4d3a049fc9de6f3e3e0f7af7e18b to your computer and use it in GitHub Desktop.
Save christianwish/20ed4d3a049fc9de6f3e3e0f7af7e18b to your computer and use it in GitHub Desktop.
first-sublime.py
import sublime
import sublime_plugin
def getHtml(color, width):
html = '''
<body id="my-plugin-feature">
<style>
div.error , body , html {
left: 0px;
right: 0px;
position: static;
width: ''' + width + ''';
display: block;
}
.scratcher {
position: relative;
display: block;
padding-left: ''' + width + ''';
}
</style>
<div class="scratcher"></div>
<div class="success">
''' + color + "---" + width + """</div>
</body>
"""
return html
class ExampleCommand(sublime_plugin.EventListener): # ~docu
def on_query_completions(self, view, prefix, locations):
a = prefix + "-Something"
print("ttt")
return [("TEST", a)]
def on_modified(self, view):
width = view.viewport_extent()[0] - 60
pxWidth = str(round(width)) + "px"
c = len(view.find_all("\\#[a-fA-F0-9]{6,8}"))
view.set_status("My Plugin", "Lines: ✅" + str(c + 1) + " ")
self.phantom_set = sublime.PhantomSet(view)
phantoms = []
# Don't do any calculations on 1MB or larger files
candidates = view.find_all("~docu")
for r in candidates:
color = view.substr(r).strip("'")
view.set_status("My Plugin", color)
phantoms.append(sublime.Phantom(
sublime.Region(r.b),
getHtml(color, pxWidth),
sublime.LAYOUT_BLOCK
))
self.phantom_set.update(phantoms)
import sublime
import sublime_plugin
class ExampleCommand(sublime_plugin.EventListener):
def on_query_completions(self, view, prefix, locations):
a = prefix + "-Something"
return [("TEST", a)]
def on_post_save(self, view):
c = len(view.find_all("\\bclass\\b"))
view.set_status("My Plugin", "Lines: ✅" + str(c) + " ")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment