编程语言
首页 > 编程语言> > python – 创建新视图的Sublime文本

python – 创建新视图的Sublime文本

作者:互联网

只需看看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> >)

知道我做错了什么吗?

解决方法:

.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)去取消一个可撤销的编辑:

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

Edit对象是一个令牌,用于将编辑分组为可以在一个步骤中撤消的内容.

标签:python,sublimetext2
来源: https://codeday.me/bug/20190613/1229464.html