ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
## 示例插件 Several pre-made plugins come with Sublime Text, you can find them in the Default package: * Packages/Default/delete_word.py Deletes a word to the left or right of the cursor * Packages/Default/duplicate_line.py Duplicates the current line * Packages/Default/exec.py Uses phantoms to display errors inline * Packages/Default/font.py Shows how to work with settings * Packages/Default/goto_line.py Prompts the user for input, then updates the selection * Packages/Default/mark.py Uses add_regions() to add an icon to the gutter * Packages/Default/show_scope_name.py Uses a popup to show the scope names at the caret * Packages/Default/trim_trailing_whitespace.py Modifies a buffer just before its saved * Packages/Default/arithmetic.py Accepts an input from the user when run via the Command Palette ## 插件生命周期 在导入时间,插件无法调用任何api函数,除了sublime.version(), sublime.platform(), sublime.architecture() and sublime.channel()。 At importing time, plugins may not call any API functions, with the exception of sublime.version(), sublime.platform(), sublime.architecture() and sublime.channel(). 如果一个插件定义了一个模块级别的函数`plugin_loaded()`,当api准备好就会立即被调用。插件也可以定义 `plugin_unloaded()`,将在被unload时通知调用 If a plugin defines a module level function plugin_loaded(), this will be called when the API is ready to use. Plugins may also define plugin_unloaded(), to get notified just before the plugin is unloaded. ### THREADING 线程 所有Api函数是线程安全,记住这点,运行在备用线程里的代码,将在被执行时生效。 All API functions are thread-safe, however keep in mind that from the perspective of code running in an alternate thread, application state will be changing while the code is running. ### UNITS AND COORDINATES 单位和坐标 API函数接收或者返回坐标或尺寸使用独立于设备的像素(DIP)值。某些情况下他们和设备像素相等,大多数情况下不等。基于CSS规范,minihtml视px为设备像素。 API functions that accept or return coordinates or dimensions do so using device-independent pixel (dip) values. While in some cases these will be equivalent to device pixels, this is often not the case. Per the CSS specification, minihtml treats the px unit as device-independent. ### TYPES 类型 本文档通常说的是Python数据类型。有些类型的名称是这里记录的类,但是也有一些引用特定语义的构造的自定义类型名称。 This documentation generally refers to simply Python data types. Some type names are classes documented herein, however there are also a few custom type names that refer to construct with specific semantics: `location`: 包含符号位置信息的元组(STR、STR、int(int、int))。第一个字符串是绝对文件路径,第二个字符串是与项目相关的文件路径,第三个元素是行和列的两个元素元组 a tuple of (str, str, (int, int)) that contains information about a location of a symbol. The first string is the absolute file path, the second is the file path relative to the project, the third element is a two-element tuple of the row and column. `point`: 表示编辑器缓冲区开头的偏移量的int。视图的方法 an int that represents the offset from the beginning of the editor buffer. The View methods text_point() and rowcol() allow converting to and from this format. `value`: 任何的Python数据类型为int,float,,STR,列表或字典any of the Python data types bool, int, float, str, list or dict. `dip`: 表示设备独立像素的浮点数 a float that represents a device-independent pixel. `vector`: 表示x和y坐标的元组(DIP、DIP) a tuple of (dip, dip) representing x and y coordinates. `CommandInputHandler`: 一个textinputhandler或listinputhandler子类 a subclass of either TextInputHandler or ListInputHandler.