Hey everyone.
Here’s what I want to achieve:
- Have an app let’s call this /bin/wr, that does some operations. I want the output of this to replace the contents of the currently open file.
- Before calling /bin/wr, I want the file to saved, and afterwards once I replace the contents, saved again.
Unfortunately I couldn’t get the saving part working with the run_command, exec, etc. tried both async and sync. The file is always left dirty and never saved before calling the process.
Here’s a simplified version of my code. Ignore syntax/indentation errors if there are any, I’m not used to this forum input.
import sublime
import sublime_plugin
import subprocess
class RunBinaryCommand(sublime_plugin.TextCommand):
def run(self, edit, name):
p = subprocess.Popen("/bin/wr " + name, stdout=subprocess.PIPE, bufsize=1, text=True)
out, err = p.communicate()
self.view.replace(edit, sublime.Region(0, self.view.size()), out)
sublime.set_timeout(lambda: sublime.run_command('save', {"async": false}))
I’ve simplified the code a bit, the plugin is working as intended without the saving part. The real version is slightly more meaningful with more parameters passed in, in this simplified example there’s no need to do any of this, so just assume I have a meaningful reason behind all this please
Also, do I need to use something else other than a text command plugin?