spock
7/23/2017 - 8:44 PM

Example how to communicate between plugins of Sublime Text 3 via in-memory settings files. Put both python files into plugin directory, incl

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-communication-how-to/29934/5

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)
[
   { "keys": ["ctrl+alt+shift+t"], "command": "send_test"}  
]
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)