Sublime Forum

Get text contents of the current file

#1

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

0 Likes

#2

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

(I use sublime-text 2)

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)
0 Likes

#3
body = self.view.substr(sublime.Region(0, self.view.size())

Almost all ST2 API are methods, not properties.

0 Likes

#4

Alright. Thank you very much :smile:

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? :smile:

  • Thanks :smile:
0 Likes