Home Download Buy Blog Forum Support

Get text contents of the current file

Get text contents of the current file

Postby Paaskehare on Sun Aug 28, 2011 7:37 pm

Hi, I have successfully made a plugin that pastes the selected code in a file to a pastebin, and sets the link in the clipboard.

But now I want it to paste the entire file if nothing is selected.

I know I can do it if I open the file, and read the contents, but I want the contents even if the file hasn't been saved yet.

Is this possible? I didn't see it mentioned in the API.

Thanks in advance
Paaskehare
 
Posts: 7
Joined: Sun Aug 28, 2011 7:32 pm

Re: Get text contents of the current file

Postby Paaskehare on Wed Aug 31, 2011 7:54 am

Thanks for the reply, but I get this error when using your example:

(I use sublime-text 2)

Code: Select all
body = self.view.substr(sublime.Region(0, self.view.size))
Boost.Python.ArgumentError: Python argument types in
    Region.__init__(Region, int, instancemethod)
did not match C++ signature:
    __init__(_object*, long long)
    __init__(_object*, long long, long long, int)
    __init__(_object*, long long, long long)
Paaskehare
 
Posts: 7
Joined: Sun Aug 28, 2011 7:32 pm

Re: Get text contents of the current file

Postby bizoo on Wed Aug 31, 2011 8:03 am

Code: Select all
body = self.view.substr(sublime.Region(0, self.view.size())

Almost all ST2 API are methods, not properties.
bizoo
 
Posts: 888
Joined: Wed Dec 08, 2010 6:53 am
Location: Switzerland

Re: Get text contents of the current file

Postby Paaskehare on Wed Aug 31, 2011 11:09 am

Alright. Thank you very much :)

This is what I ended up with:
https://github.com/Paaskehare/metabox-sublime-plugin

But it fails when the contents of the file/selection not only includes ascii characters, I tried encoding to utf-8, but it wouldn't let me for some reason, can you please enlighten me on this matter too? :)

- Thanks :)
Paaskehare
 
Posts: 7
Joined: Sun Aug 28, 2011 7:32 pm


Return to Plugin Development

Who is online

Users browsing this forum: Google [Bot] and 8 guests