Just taking a look at Sublime Text 2 with a view to extending it. I've popped up the console with CTRL ', and tried to do:
>>> x = window.new_file()
>>> x
<sublime.View object at 0x00000000032EBA70>
>>> x.insert(0,"Hello")
A new window does indeed open but my insert seemingly doesn't work:
Traceback (most recent call last): File "<string>", line 1, in <module> Boost.Python.ArgumentError: Python argument types in
View.insert(View, int, str) did not match C++ signature:
insert(class SP<class TextBufferView>, class SP<class Edit>, __int64, class std::basic_string<wchar_t,struct std::char_traits<wchar_t>,class std::allocator<wchar_t> >)
Any idea what I'm doing wrong?
The .new_file()
call returned a View
object, so the .insert()
method takes 3 arguments:
insert(edit, point, string)
int
Inserts the givenstring
in the buffer at the specifiedpoint
. Returns the number of characters inserted: this may be different if tabs are being translated into spaces in the current buffer.
See the sublime.View
API reference.
The edit
parameter is meant to be a sublime.Edit
object; you need to call view.begin_edit()
to create one, then call view.end_edit(edit)
to demarque a undoable edit:
edit = x.begin_edit()
x.insert(edit, 0, 'Hello')
x.end_edit(edit)
The Edit
object is a token to group edits into something that can be undone in one step.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With