Sublime Forum

How to retrieve the current's view content/buffer

#1

Hey guys,

I’m currently working on a new HTML preprocessor ST2 plugin using http://shpaml.webfactional.com/.

here’s what I want to do:

When you edit a *.shpaml file (let’s say test.html.shpaml) and save it, the preprocessor will kick in.

  • it will copy the current view’s content and use shpaml.convert_text() on it.

  • the processed HTML will then be copied to a new file (test.html)

  • this new file will be created in the same directory as the original shpaml file.

here’s what I’ve been able to do until now:

I’ve been able to create my EventListener and override the on_post_save method to display a message in the console when I save a shpaml file.

I’m checking on the file extension to see if it ends with *.shpaml before showing the console message.

**And this is where I’m stuck. I’ve read the API to see how I could get the view’'s content but can’t find anything useful. I’ve also looked at other plugins but can’t find a good example. **

current code: https://gist.github.com/3490d54d6d7f0837f241

anyone care to help a bit only for this part ?

thanks a bunch.

Bernard

0 Likes

Encoding questions
#2

You’ll want to use view.substr(0, view.size()).

0 Likes

#3

thanks a lot for the answer but it didn’t quite work out for me.

I didn’t need to have complete control over the buffer so I’ve decided to open the current file in read mode and writing back the processed SHPAML into a new file instead.

0 Likes

#4

The correct syntax is:

view.substr(sublime.Region(0, view.size()))
0 Likes

#5

I’ll join with a question, is there any chance to get view encoding according to the order: detected, fallback_encoding (if set)?

0 Likes

#6

Already asked viewtopic.php?f=3&t=3219#p15206 but no answer yet.

0 Likes

#7

[quote=“bizoo”]

Already asked viewtopic.php?f=3&t=3219#p15206 but no answer yet.[/quote]

Thanks mate, I will join Your topic.

0 Likes

#8

Vote for it here:
sublimetext.userecho.com/topic/2 … -position/

0 Likes