## 示例插件
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.