Save all files before running custom command in Sublime3
<p>This is a derivative of this question I made some days ago <a href="http://stackoverflow.com/q/39734390/1391441">Save file before running custom command in Sublime3</a>.</p>

<p>I've setup a custom keybind in Sublime Text 3:</p>

<pre><code>{
    "keys": ["f5"],
    "command": "project_venv_repl"
}
</code></pre>

<p>to run the <code>project_venv_repl.py</code> script (see <a href="http://stackoverflow.com/a/25002696/1391441">here</a> to learn what it does):</p>

<pre class="lang-py prettyprint-override"><code>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 &lt;---- 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...
</code></pre>

<p>This runs the opened file in a <a href="https://github.com/wuub/SublimeREPL" rel="nofollow">SublimeREPL</a> when the <code>f5</code> key is pressed. The two lines below <code># Save all files before running REPL</code> should save all opened files with unsaved changes, before running the REPL (as stated in the <a href="http://stackoverflow.com/a/39734918/1391441">answer</a> to my previous question).</p>

<p>The lines work, ie: they save the files. But they also display two consecutive <em>Save</em> pop-ups, asking me to save the REPL (?):</p>

<pre><code>*REPL* [/home/gabriel/.pyenv/versions/test-env/bin/python -i -u /home/gabriel/Github/test/test.py]
</code></pre>

<p><code>test.py</code> is the file from where the script <code>project_venv_repl</code> was called. After I cancel both pop-ups, the script is executed correctly.</p>

<p>How can I get the <code>project_venv_repl</code> script to save all opened files with unsaved changes before executing, <em>without</em> displaying these annoying <em>Save</em> pop-ups?</p>

<p>(The idea behind all this is to mimic the behavior of <code>Ctrl+B</code>, which will save all unsaved files prior to building the script)</p>

<p>The trick is to only save for files that are dirty and exist on disk.</p>

<pre><code># Write out every buffer (active window) with changes and a file name.
window = sublime.active_window()
for view in window.views():
    if view.is_dirty() and view.file_name():
        view.run_command('save')
</code></pre>

<p>I had a similar issue with <a href="https://github.com/gerardroche/sublime-phpunit" rel="nofollow">PHPUNITKIT</a>.</p>

<blockquote>
  <p><strong>save_all_on_run: Only save files that exist on disk and have dirty buffers</strong></p>
  
  <p>Note: the "save_all_on_run" option no longer saves files that don't
  exist on disk.</p>
  
  <p>The reason for this change is trying to save a file that doesn't exist
  on disk prompts the user with a "save file" dialog, which is generally
  not desired behaviour.</p>
  
  <p>Maybe another option "save_all_on_run_strict" option can be added
  later that will try to save even the files that don't exist on disk.</p>
  
  <p><a href="https://github.com/gerardroche/sublime-phpunit/commit/3138e2b75a8fbb7a5cb8d7dacabc3cf72a77c1bf" rel="nofollow">https://github.com/gerardroche/sublime-phpunit/commit/3138e2b75a8fbb7a5cb8d7dacabc3cf72a77c1bf</a></p>
</blockquote>

python sublimetext3