Home Download Buy Blog Forum Support

Get and modify entire contents of a view

Get and modify entire contents of a view

Postby nmeirik on Sat Oct 01, 2011 9:55 am

Hi,

How do I get and modify (replace) the entire contents of a view?

Thanks in advance!
nmeirik
 
Posts: 8
Joined: Fri Sep 09, 2011 9:10 am

Re: Get and modify entire contents of a view

Postby nmeirik on Sun Oct 02, 2011 8:08 am

Never mind, I got it. Here is is for anyone else that might be interested (assuming your're using a WindowCommand):

Code: Select all
# get the current contents of the file
body = self.window.active_view().substr(sublime.Region(0, self.window.active_view().size()))

# begin edit
edit = self.window.active_view().begin_edit()

# deleted the contents of the file
self.window.active_view().erase(edit, sublime.Region(0, self.window.active_view().size()))

# insert new html
self.window.active_view().insert(edit, 0, html)
       
# end edit
self.window.active_view().end_edit(edit)
nmeirik
 
Posts: 8
Joined: Fri Sep 09, 2011 9:10 am


Return to Plugin Development

Who is online

Users browsing this forum: Alexa [Bot] and 2 guests