This is a derivative of this question I made some days ago Save file before running custom command in Sublime3.
I've setup a custom keybind in Sublime Text 3:
{
"keys": ["f5"],
"command": "project_venv_repl"
}
to run the project_venv_repl.py
script (see here to learn what it does):
import sublime_plugin
class ProjectVenvReplCommand(sublime_plugin.TextCommand):
"""
Starts a SublimeREPL, attempting to use project's specified
python interpreter.
"""
def run(self, edit, open_file='$file'):
"""Called on project_venv_repl command"""
# Save all files before running REPL <---- THESE TWO LINES
for open_view in self.view.window().views():
open_view.run_command("save")
cmd_list = [self.get_project_interpreter(), '-i', '-u']
if open_file:
cmd_list.append(open_file)
self.repl_open(cmd_list=cmd_list)
# Other functions...
This runs the opened file in a SublimeREPL when the f5
key is pressed. The two lines below # Save all files before running REPL
should save all opened files with unsaved changes, before running the REPL (as stated in the answer to my previous question).
The lines work, ie: they save the files. But they also display two consecutive Save pop-ups, asking me to save the REPL (?):
*REPL* [/home/gabriel/.pyenv/versions/test-env/bin/python -i -u /home/gabriel/Github/test/test.py]
test.py
is the file from where the script project_venv_repl
was called. After I cancel both pop-ups, the script is executed correctly.
How can I get the project_venv_repl
script to save all opened files with unsaved changes before executing, without displaying these annoying Save pop-ups?
(The idea behind all this is to mimic the behavior of Ctrl+B
, which will save all unsaved files prior to building the script)