Sublime Forum

A view.set_dirty() method would be really useful. Here's why

#1

This is a feature request for a view.set_dirty() method (or view.set_change_count(), if that’s how dirty is determined.)

Context:

I am building a simple plugin that filters text when loading it, then again when it’s saved. It works by hooking on_load, on_pre_save, on_post_save. It’s a tab-width converter; so when you load a file, it converts 2->4. When you save it, it converts back 4->2. A bit silly I know :slight_smile: But this way you can just edit a file in the tabs you’d like to see, but it’s saved in a format that is more friendly for your co-workers.

Thanks to the excellent API in Sublime this works perfectly and was simple to write… except for one thing!

The problem is that the file is marked dirty when the tabs are converted over. Ideally, I’d want to convert tabs at load, and then clear the dirty flag. That way if I closed it, the file wouldn’t prompt to be be saved again.

As well, it converts 4->2 before saving (on_pre_save) but after saving immediately converts back to 4; so the file is dirty again, even though it’s just been saved. So if I use this plugin as-is, I always get the “this file has been modified” dialog box when I go to close a file, even though it really hasn’t.

Related question: in the meantime, is there an undocumented way to clear the dirty flag?

1 Like

#2

a similar request was also made on the issue tracker, albeit it looks like only a request to set the view as dirty, not a way to unmark it as dirty:

0 Likes