Home Download Buy Blog Forum Support

How to retrieve the current's view content/buffer

How to retrieve the current's view content/buffer

Postby bchhun on Tue Oct 18, 2011 7:15 pm

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
bchhun
 
Posts: 4
Joined: Tue Oct 18, 2011 6:47 pm

Re: How to retrieve the current's view content/buffer

Postby adzenith on Tue Oct 18, 2011 7:20 pm

You'll want to use view.substr(0, view.size()).
adzenith
 
Posts: 1215
Joined: Mon Oct 19, 2009 9:12 pm

Re: How to retrieve the current's view content/buffer

Postby bchhun on Wed Oct 19, 2011 1:46 am

adzenith wrote:You'll want to use view.substr(0, view.size()).


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.
bchhun
 
Posts: 4
Joined: Tue Oct 18, 2011 6:47 pm

Re: How to retrieve the current's view content/buffer

Postby bizoo on Wed Oct 19, 2011 7:09 am

The correct syntax is:
Code: Select all
view.substr(sublime.Region(0, view.size()))
bizoo
 
Posts: 880
Joined: Wed Dec 08, 2010 6:53 am
Location: Switzerland

Re: How to retrieve the current's view content/buffer

Postby Mylith on Wed Oct 19, 2011 8:43 am

I'll join with a question, is there any chance to get view encoding according to the order: detected, fallback_encoding (if set)?
Mylith
 
Posts: 30
Joined: Mon Oct 17, 2011 12:58 pm

Re: How to retrieve the current's view content/buffer

Postby bizoo on Wed Oct 19, 2011 9:09 am

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

Already asked viewtopic.php?f=3&t=3219#p15206 but no answer yet.
bizoo
 
Posts: 880
Joined: Wed Dec 08, 2010 6:53 am
Location: Switzerland

Re: How to retrieve the current's view content/buffer

Postby Mylith on Wed Oct 19, 2011 9:46 am

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

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

Thanks mate, I will join Your topic.
Mylith
 
Posts: 30
Joined: Mon Oct 17, 2011 12:58 pm

Re: How to retrieve the current's view content/buffer

Postby jbjornson on Wed Oct 19, 2011 1:16 pm

jbjornson
 
Posts: 348
Joined: Tue Oct 27, 2009 4:25 pm
Location: Zurich, Switzerland


Return to Plugin Development

Who is online

Users browsing this forum: No registered users and 5 guests