Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save hetsch/5869655 to your computer and use it in GitHub Desktop.
Save hetsch/5869655 to your computer and use it in GitHub Desktop.

Skeleton Sublime Text 2 Plugin

  • Search and replace 'mypackage'
[
{
"caption": "Preferences: mypackage Settings – Default",
"command": "open_file",
"args": {
"file": "${packages}/mypackage/Base File.sublime-settings"
}
},
{
"caption": "My example command",
"command": "my"
}
]
// Exanple: json file-specific settings
{
"something": true
}
# -*- coding: utf8 -*-
import functools
import threading
import sublime
class ThreadProgress(object):
def __init__(self, thread, label, success_message, additional_msg=None):
self.thread = thread
self.label = label
self.success_message = success_message
self.additional_msg = additional_msg or noop
self.addend = 1
self.size = 8
sublime.set_timeout(lambda: self.run(0), 100)
def run(self, i):
if not self.thread.is_alive():
if hasattr(self.thread, 'result') and not self.thread.result:
sublime.status_message('')
return
sublime.status_message(self.success_message)
return
before = i % self.size
after = (self.size - 1) - before
sublime.status_message(u'{0} [{1}={2}] {3}'.format(
self.label,
u' ' * before,
u' ' * after,
self.additional_msg() or u''
))
if not after:
self.addend = -1
if not before:
self.addend = 1
i += self.addend
sublime.set_timeout(lambda: self.run(i), 100)
class WorkerThread(threading.Thread):
def __init__(self, action, callback):
self.action = action
self.callback = callback
threading.Thread.__init__(self)
def run(self):
result = self.action()
callback = functools.partial(self.callback, result)
sublime.set_timeout(callback, 10)
def noop(*args, **kargs):
pass
def do_when(conditional, callback, *args, **kwargs):
if conditional():
return callback(*args, **kwargs)
sublime.set_timeout(functools.partial(do_when, conditional, callback, *args, **kwargs), 50)
[
{
"caption": "Preferences",
"mnemonic": "n",
"id": "preferences",
"children":
[
{
"caption": "Package Settings",
"mnemonic": "P",
"id": "package-settings",
"children":
[
{
"caption": "My Package",
"children":
[
{
"command": "open_file",
"args": {"file": "${packages}/mypackage/Base File.sublime-settings"},
"caption": "Settings – Default"
},
{
"command": "open_file",
"args": {"file": "${packages}/User/Base File.sublime-settings"},
"caption": "Settings – User"
},
{
"command": "open_file_settings",
"caption": "Settings – Syntax Specific – User"
},
{
"command": "open_file",
"args": {
"file": "${packages}/mypackage/Default (Windows).sublime-keymap",
"platform": "Windows"
},
"caption": "Key Bindings – Default"
},
{
"command": "open_file",
"args": {
"file": "${packages}/mypackage/Default (OSX).sublime-keymap",
"platform": "OSX"
},
"caption": "Key Bindings – Default"
},
{
"command": "open_file",
"args": {
"file": "${packages}/mypackage/Default (Linux).sublime-keymap",
"platform": "Linux"
},
"caption": "Key Bindings – Default"
},
{
"command": "open_file",
"args": {
"file": "${packages}/User/Default (Windows).sublime-keymap",
"platform": "Windows"
},
"caption": "Key Bindings – User"
},
{
"command": "open_file",
"args": {
"file": "${packages}/User/Default (OSX).sublime-keymap",
"platform": "OSX"
},
"caption": "Key Bindings – User"
},
{
"command": "open_file",
"args": {
"file": "${packages}/User/Default (Linux).sublime-keymap",
"platform": "Linux"
},
"caption": "Key Bindings – User"
},
{ "caption": "-" }
]
}
]
}
]
}
]
# -*- coding: utf8 -*-
import sublime
import sublime_plugin
import lib
class MyCommand(sublime_plugin.TextCommand):
def run(self, edit):
view = self.view
sel = view.sel()
settings = view.settings()
tab_size = int(settings.get('tab_size', 8))
use_spaces = settings.get('translate_tabs_to_spaces')
import time
import functools
action = functools.partial(time.sleep, 3)
callback = lib.noop
wrk = lib.WorkerThread(action, callback)
wrk.start()
lib.ThreadProgress(wrk, 'Working', '')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment