Sublime Forum

Convert buffer *right* before it is opened?

#1

Hi all,

the title might be a little confusing, so let me explain.

I’d like to develop a plugin that opens and saves CSS “future-proof”. So if the original file content looks like this:

div {
  -webkit-border-radius: 10px;
  -ms-border-radius: 10px;
  border-radius: 10px;
}

…I would like to display the following to the user:

div {
  border-radius: 10px;
}

Basically preprocessing the document and folding away anything related to cross browser compatibility.

When saving the altered buffer in Sublime, then do the whole thing reverse: Apply something like Prefixr (prefixr.com/) and save the file in the format it was parsed. The idea is to completely fold away complexity and intercept at the right place: The editor.

Now my obvious question: Can this be done with Sublime Text 2? I haven’t seen similar plugins.

Thanks much!

Cheers,
Paul

0 Likes

#2

bump nobody any idea? really?

0 Likes

#3

You “can” but this is difficult to detect on_load events that are caused by “Go To anything” showing temporary tabs.

If you modify such tab, you will break goto anything.
If you don’t modify it, you won’t receive any other events when it’s promoted to a “real” tab.

AFAICT there is no way to do this correctly.
You can see how to to this incorrectly here:

code.wuub.net/subarwe/src/9f9a84 … at=default

0 Likes

#4

Hi Wojciech,

thanks for the advice! Unfortunately, I’m stuck even earlier than that. I was writing code and used the on_load event to watch for a CSS file getting opened, but as soon as I change anything in the view (i.e. insert, replace etc.), the file gets marked as “modified”, which I definitely do not want (basically, what the user modifies and see’s should be a compiled source view, unrelated to the actual file on disk).

view.set_scratch(1) after modification does set the view to unmodified visually and doesn’t bring up the prompt, but when the user now modifies, that will also not show as modified.

Any idea? I realize I’m trying to do something funky, but this might be really useful to lots of web developers.

0 Likes