2013-04-16 4 views
4

Просто взгляните на Sublime Text 2 с целью его расширения. Я выскочила консоль с CTRL ', и попытался сделать:Возвышенный текст, создающий новый вид

>>> x = window.new_file() 
>>> x 
<sublime.View object at 0x00000000032EBA70> 
>>> x.insert(0,"Hello") 

новое окно делает действительно открытым, но моя вставка, казалось бы, не работает:

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

Любая идея, что я Неправильно?

ответ

6

.new_file() вызов возвратил View объект, поэтому метод .insert()принимает 3 аргументы:

insert(edit, point, string)
int
Inserts the given string in the buffer at the specified point . Returns the number of characters inserted: this may be different if tabs are being translated into spaces in the current buffer.

ВИДЕТЬ sublime.View API reference.

Параметр edit предназначен для использования в качестве объекта sublime.Edit; вам нужно позвонить view.begin_edit(), чтобы создать, а затем вызвать view.end_edit(edit) к demarque с невыполнимым редактирования:

edit = x.begin_edit() 
x.insert(edit, 0, 'Hello') 
x.end_edit(edit) 

Объект Edit является маркером для группы редактирует в то, что может быть отменена в одном шаге.

+0

Это просто дает мне: NameError: имя 'изменить' не определен –

+1

@DaveF: 'edit' является * параметр * типа [' sublime.Edit'] (Http: //www.sublimetext .com/документы/2/api_reference.html # sublime.Edit). Используйте 'view.begin_edit()' для его создания. –

+0

А, отлично .. вот что мне не хватало, спасибо большое –

1
>>> x = window.new_file() 
>>> e = x.begin_edit() 
>>> x.insert(e,0,"Hello") 
5 
>>> x.end_edit(e) 
Смежные вопросы