Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Save the edit when running a Sublime Text 3 plugin

For understanding what I'm trying to achieve : printing delayed text in another view...

I'm trying to make this sublime text 3 plugin run properly I want to call multiple method of my class using the edit passed in parameter of my run method as so :

# sample code, nothing real
class MyCommandClass(sublime_plugin.TextCommand):
    myEdit = None
    def run(self, edit):
        self.myEdit = edit
        # stuff
        self.myMethod()

    def myMethod(self):
        # use self.myEdit ...

And I try to use it later on another method, but when I execute the plugin I get this error :
ValueError: Edit objects may not be used after the TextCommand's run method has returned

For what I understand, all use of the edit object must be before the run command has returned. And as I'm playing with set_timeout, it might not be the case... So what can I do ?

Thanks in advance.

like image 966
nobe4 Avatar asked Dec 09 '13 08:12

nobe4


People also ask

How do I run a Sublime Text 3 project?

Sublime Text is able to run build programs such as 'make', either when a key in pressed (F7 by default), or when a file is saved. The build system to use can be select from the Tools/Build System menu. If a project is open, the selected build system will be remembered for the project.

Does Sublime Text have extension?

Sublime Text is extensible via Python. Extending is simply a matter of placing a python file under the Packages directory (For example C:\Documents and Settings\ username \Application Data\Sublime Text\Packages\User).

Can we use Sublime Text Online?

Yes, you should use Sublime Text as your code editor if you are looking for an affordable editor with package control and other features. The source code editor is easy to use as a browser extension and as a website plugin.


1 Answers

Solution found, to pass an argument to another view and use the edit :

class MainCommand(sublime_plugin.WindowCommand):
    def run(self):
        newFile = self.window.new_file()
        newFile.run_command("second",{ "arg" : "this is an argument"});

class SecondCommand(sublime_plugin.TextCommand):
    def run(self, edit, argument):
        # do stuff with argument
like image 130
nobe4 Avatar answered Sep 26 '22 02:09

nobe4