gpt4 book ai didi

python - Sublime Text 创建新 View

转载 作者:太空狗 更新时间:2023-10-30 02:21:28 25 4
gpt4 key购买 nike

只是为了扩展它而看一下 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 - Sublime Text 创建新 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16035385/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com