Skip to content

Instantly share code, notes, and snippets.

@pykong
Created July 23, 2017 20:44
Show Gist options
  • Save pykong/0975977505da02bbdf29b41e35e85a78 to your computer and use it in GitHub Desktop.
Save pykong/0975977505da02bbdf29b41e35e85a78 to your computer and use it in GitHub Desktop.
Example how to communicate between plugins of Sublime Text 3 via in-memory settings files. Put both python files into plugin directory, include the keybinding (maybe change different key combination if required.) Watch the console and trigger the command. See what happens. Also, see following thread: https://forum.sublimetext.com/t/inter-plugin-…
import sublime
import sublime_plugin
s = sublime.load_settings('var_share.sublime-settings')
def consume():
num = s.get("test_var")
print("Consumer received: ", num)
def plugin_loaded():
print("consumer loaded")
s.add_on_change('test_var', consume)
[
{ "keys": ["ctrl+alt+shift+t"], "command": "send_test"}
]
import sublime
import sublime_plugin
from random import randint
class SendTestCommand(sublime_plugin.TextCommand):
def run(self, edit):
rnd = randint(0, 9)
print("Producer sends: ", rnd)
s = sublime.load_settings('var_share.sublime-settings')
s.set('test_var', rnd)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment