- Search and replace 'mypackage'
Last active
December 12, 2015 10:19
-
-
Save robcowie/4758607 to your computer and use it in GitHub Desktop.
Skeleton Sublime Text 2 Plugin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Show hidden characters
{ | |
"something": true | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ | |
{ | |
"caption": "Preferences: mypackage Settings – Default", | |
"command": "open_file", | |
"args": { | |
"file": "${packages}/mypackage/Base File.sublime-settings" | |
} | |
}, | |
{ | |
"caption": "My example command", | |
"command": "my" | |
} | |
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Exanple: json file-specific settings | |
{ | |
"something": true | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- 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