I’m trying to create a plugin that saves and closes views to non-saved but existing files. This used to work in ST3:
for v in sublime.active_window().views():
if v.file_name() and os.path.isfile(v.file_name()):
if v.is_dirty():
v.run_command("save")
v.print(v.is_dirty())
v.close()
In ST4 it no longer works. v still reports as dirty after v.run_command("save")
(though the file looks saved) and this causes the v.close()
to triggers a Save Changes dialog. It seems that the actual saving of the file is postponed until the function that contains the call for saving returns. I could bypass the save dialog by issuing a v.set_scratch(True)
before the v.close()
but I feel that is a workaround rather than a solution. It could also conceal any real problems that might occur during the save and cause data loss.
Any hints on what could go wrong here?