forked from Binocular222/Sublime-Text-3-Full-Documentation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Plugin.API.txt
300 lines (289 loc) · 174 KB
/
Plugin.API.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
ST3 API: http://www.sublimetext.com/docs/3/api_reference.html
| Module | Class | Method | Note |
|----------------|--------------------|----------------------------------------|------------------------------------------------------------------------|
| sublime | | [[#sublime. ]] | |
| sublime | Region | [[#sublime.Region]] | Region(a, b) = an area of the buffer. |
| sublime | Edit | has No method | Use to group buffer modifications. |
| | | | Edit objects are passed to TextCommands but not changable. |
| | | | Create new instance of edit object only by making a new TextCommand |
| sublime | Selection | [[#sublime.Selection]] | a set of none-overlap Regions. The regions are kept in sorted order. |
| sublime | Settings | [[#sublime.Settings]] | |
| sublime | View | [[#sublime.View]] | view into a text buffer with unique selection and geometry |
| sublime | Window | [[#sublime.Window]] | |
| sublime_plugin | ApplicationCommand | [[#sublime_plugin.ApplicationCommand]] | |
| sublime_plugin | EventListener | [[#sublime_plugin.EventListener]] | |
| sublime_plugin | TextCommand | [[#sublime_plugin.TextCommand]] | instantiated once per view. self.view return current View object |
| sublime_plugin | WindowCommand | [[#sublime_plugin.WindowCommand]] | instantiated once per window. self.window return current Window object |
Return Value [[Plugin.txt#Object:]]
Some useful pieces of codes: [[Plugin.Snippet.py]]
sublime. :
| Method | Return Value | Description |
|---------------------------------------|--------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| set_timeout(callback, delay) | None | Runs the callback in the main thread after the given delay (in milliseconds). Callbacks with an equal delay will be run in the order they were added. |
| set_async_timeout(callback, delay) | None | Runs the callback on an alternate thread after the given delay (in milliseconds). |
| status_message(string) | None | Sets the message that appears in the status bar. |
| error_message(string) | None | Displays an error dialog to the user. |
| message_dialog(string) | None | Displays a message dialog to the user. |
| ok_cancel_dialog(string, <ok_button>) | bool | Displays an ok / cancel question dialog to the user. If ok_button is provided, this may be used as the text on the ok button. Returns True if the user presses the ok button. |
| yes_no_cancel_dialog() | | |
| load_resource(name) | String | Loads the given resource. The name should be in the format Packages/Default/Main.sublime-menu. |
| load_binary_resource(name) | bytes | Loads the given resource. The name should be in the format Packages/Default/Main.sublime-menu. |
| find_resources(pattern) | [String] | Finds resources whose file name matches the given pattern. |
| encode_value(value, <pretty>) | String | Encode a JSON compatible value into a string representation. If pretty is set to True, the string will include newlines and indentation. |
| decode_value(string) | value | Decodes a JSON string into an object. If the string is invalid, a ValueError will be thrown. |
| load_settings(base_name) | Settings | Loads the named settings. The name should include a file name and extension, but not a path. |
| save_settings(base_name) | None | The packages will be searched for files matching the base name, and the results will be collated into the settings object. |
| windows() | [Window] | Subsequent calls to load_settings with the name base_name will return the same object, and not load the settings from disk again. Flushes any in-memory changes to the named settings object to disk. Returns a list of all the open windows. |
| active_window() | Window | Returns the most recently used window. |
| packages_path() | String | Returns the base path to the packages. |
| installed_packages_path() | String | Returns the path where all the user's *.sublime-package files are. |
| cache_path() | String | Returns the path where Sublime Text stores cache files. |
| get_clipboard(<size_limit>) | String | Returns the contents of the clipboard. size_limit is there to protect against unnecessarily large data, defaults to 16,777,216 characters |
| set_clipboard(string) | None | Sets the contents of the clipboard. |
| score_selector(scope, selector) | Int | Matches the selector against the given scope, returning a score. A score of 0 means no match, above 0 means a match. Different selectors may be compared against the same scope: a higher score means the selector is a better match for the scope. |
| run_command(string, <args>) | None | Runs the named ApplicationCommand with the (optional) given arguments. |
| log_commands(flag) | None | Controls command logging. If enabled, all commands run from key bindings and the menu will be logged to the console. |
| log_input(flag) | None | Controls input logging. If enabled, all key presses will be logged to the console. |
| log_result_regex(flag) | None | Controls result regex logging. This is useful for debugging regular expressions used in build systems. |
| version() | String | Returns the version number |
| platform() | String | Returns the platform, which may be "osx", "linux" or "windows" |
| arch() | String | Returns the CPU architecture, which may be "x32" or "x64" |
| expand_variables() | | sublime.expand_variables("Hello, ${name:Unknown}!", {"name": "World"}) |
| extract_variables() | | |
| Sheet.view() | | |
| executable_path() | String | Path to sublime_text.exe |
sublime.Region:
| Method | Return Value | Description |
|----------------------|--------------|----------------------------------------------------------------------------------|
| begin() | int | Returns the minimum of a and b. |
| end() | int | Returns the maximum of a and b. |
| size() | int | Returns the number of characters spanned by the region. Always >= 0. |
| empty() | bool | Returns true iff begin() == end(). |
| cover(region) | Region | Returns a Region spanning both this and the given regions. |
| intersection(region) | Region | Returns the set intersection of the two regions. |
| intersects(region) | bool | Returns True iff this == region or both include one or more positions in common. |
| contains(region) | bool | Returns True iff the given region is a subset. |
| contains(point) | bool | Returns True iff begin() <= point <= end(). |
sublime.Selection:
| Method | Return Value | Description |
|---------------------|--------------|----------------------------------------------------------------------------------------------------------|
| clear() | None | Removes all regions. |
| add(region) | None | Adds the given region. It will be merged with any intersecting regions already contained within the set. |
| add_all(region_set) | None | Adds all regions in the given set. |
| subtract(region) | None | Subtracts the region from all regions in the set. |
| contains(region) | bool | Returns true if the given region is a subset. |
sublime.Settings:
| Method | Return Value | Description |
|-------------------------------|--------------|-----------------------------------------------------------------------------------------|
| get(name) | value | Returns the named setting. |
| get(name, default) | value | Returns the named setting, or default if it's not defined. |
| set(name, value) | None | Sets the named setting. Only primitive types, lists, and dictionaries are accepted. |
| erase(name) | None | Removes the named setting. Does not remove it from any parent Settings. |
| has(name) | bool | Returns true iff the named option exists in this set of Settings or one of its parents. |
| add_on_change(key, on_change) | None | Register a callback to be run whenever a setting in this object is changed. |
| clear_on_change(key) | None | Remove all callbacks registered with the given key. |
sublime.View:
| Method | Return Value | Description |
|-------------------------------------------------------|--------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| id() | int | Returns a number that uniquely identifies this view. |
| buffer_id() | int | Returns a number that uniquely identifies the buffer underlying this view. |
| file_name() | String | The full name file the file associated with the buffer, or None if it doesn't exist on disk. |
| name() | String | The name assigned to the buffer, if any |
| set_name(name) | None | Assigns a name to the buffer |
| is_loading() | bool | Returns true if the buffer is still loading from disk, and not ready for use. |
| is_dirty() | bool | Returns true if there are any unsaved modifications to the buffer. |
| is_read_only() | bool | Returns true if the buffer may not be modified. |
| set_read_only(value) | None | Sets the read only property on the buffer. |
| is_scratch() | bool | Returns true if the buffer is a scratch buffer. Scratch buffers never report as being dirty. |
| set_scratch(value) | None | Sets the scratch property on the buffer. |
| settings() | Settings | Returns a reference to the views settings object. Any changes to this settings object will be private to this view. |
| window() | Window | Returns a reference to the window containing the view. |
| run_command(string, <args>) | None | Runs the named TextCommand with the (optional) given arguments. |
| size() | int | Returns the number of character in the file. |
| substr(region) | String | Returns the contents of the region as a string. |
| substr(point) | String | Returns the character to the right of the point. |
| 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. |
| erase(edit, region) | None | Erases the contents of the region from the buffer. |
| replace(edit, region, string) | None | Replaces the contents of the region with the given string. |
| sel() | Selection | Returns a reference to the selection. |
| line(point) | Region | Returns the line that contains the point. |
| line(region) | Region | Returns a modified copy of region such that it starts at the beginning of a line, and ends at the end of a line. Note that it may span several lines. |
| full_line(point) | Region | As line(), but the region includes the trailing newline character, if any. |
| full_line(region) | Region | As line(), but the region includes the trailing newline character, if any. |
| lines(region) | [Region] | Returns a list of lines (in sorted order) intersecting the region. |
| split_by_newlines(region) | [Region] | Splits the region up such that each region returned exists on exactly one line. |
| word(point) | Region | Returns the word that contains the point. |
| word(region) | Region | Returns a modified copy of region such that it starts at the beginning of a word, and ends at the end of a word. Note that it may span several words. |
| folded_regions() | Regions | Folded regions |
| classify(point) | int | Classifies pt, returning a bitwise OR of zero or more of these flags: |
| | | CLASS_WORD_START |
| | | CLASS_WORD_END |
| | | CLASS_PUNCTUATION_START |
| | | CLASS_PUNCTUATION_END |
| | | CLASS_SUB_WORD_START |
| | | CLASS_SUB_WORD_END |
| | | CLASS_LINE_START |
| | | CLASS_LINE_END |
| | | CLASS_EMPTY_LINE |
| find_by_class(point, forward, classes, <separators>) | Region | Finds the next location after point that matches the given classes. If forward is False, searches backwards instead of forwards. classes is a bitwise OR of the sublime.CLASS_XXX flags. separators may be passed in, to define what characters should be considered to separate words. |
| expand_by_class(point, classes, <separators>) | Region | Expands point to the left and right, until each side lands on a location that matches classes. classes is a bitwise OR of the sublime.CLASS_XXX flags. separators may be passed in, to define what characters should be considered to separate words. |
| expand_by_class(region, classes, <separators>) | Region | Expands region to the left and right, until each side lands on a location that matches classes. classes is a bitwise OR of the sublime.CLASS_XXX flags. separators may be passed in, to define what characters should be considered to separate words. |
| find(pattern, fromPosition, <flags>) | Region | Returns the first Region matching the regex pattern, starting from the given point, or None if it can't be found. The optional flags parameter may be sublime.LITERAL, sublime.IGNORECASE, or the two ORed together. |
| find_all(pattern, <flags>, <format>, <extractions>) | [Region] | Returns all (non-overlapping) regions matching the regex pattern. The optional flags parameter may be sublime.LITERAL, sublime.IGNORECASE, or the two ORed together. If a format string is given, then all matches will be formatted with the formatted string and placed into the extractions list. |
| rowcol(point) | (int, int) | Calculates the 0 based line and column numbers of the point. |
| text_point(row, col) | int | Calculates the character offset of the given, 0 based, row and column. Note that 'col' is interpreted as the number of characters to advance past the beginning of the row. |
| set_syntax_file(syntax_file) | None | Changes the syntax used by the view. syntax_file should be a name along the lines of Packages/Python/Python.tmLanguage. To retrieve the current syntax, use view.settings().get('syntax'). |
| extract_scope(point) | Region | Returns the extent of the syntax name assigned to the character at the given point. |
| scope_name(point) | String | Returns the syntax name assigned to the character at the given point. |
| score_selector(point, selector) | Int | Matches the selector against the scope at the given location, returning a score. A score of 0 means no match, above 0 means a match. Different selectors may be compared against the same scope: a higher score means the selector is a better match for the scope. |
| find_by_selector(selector) | [Regions] | Finds all regions in the file matching the given selector, returning them as a list. |
| show(point, <show_surrounds>) | None | Scroll the view to show the given point. |
| show(region, <show_surrounds>) | None | Scroll the view to show the given region. |
| show(region_set, <show_surrounds>) | None | Scroll the view to show the given region set. |
| show_at_center(point) | None | Scroll the view to center on the point. |
| show_at_center(region) | None | Scroll the view to center on the region. |
| visible_region() | Region | Returns the currently visible area of the view. |
| viewport_position() | Vector | Returns the offset of the viewport in layout coordinates. |
| set_viewport_position(vector, <animate<) | None | Scrolls the viewport to the given layout position. |
| viewport_extent() | vector | Returns the width and height of the viewport. |
| layout_extent() | vector | Returns the width and height of the layout. |
| text_to_layout(point) | vector | Converts a text position to a layout position |
| layout_to_text(vector) | point | Converts a layout position to a text position |
| line_height() | real | Returns the light height used in the layout |
| em_width() | real | Returns the typical character width used in the layout |
| add_regions(key, [regions], <scope>, <icon>, <flags>) | None | Add a set of regions to the view. If a set of regions already exists with the given key, they will be overwritten. The scope is used to source a color to draw the regions in, it should be the name of a scope, such as "comment" or "string". If the scope is empty, the regions won't be drawn. |
| | | The optional icon name, if given, will draw the named icons in the gutter next to each region. The icon will be tinted using the color associated with the scope. Valid icon names are dot, circle, bookmark and cross. The icon name may also be a full package relative path, such as Packages/Theme - Default/dot.png. |
| | | The optional flags parameter is a bitwise combination of: |
| | | sublime.DRAW_EMPTY. Draw empty regions with a vertical bar. By default, they aren't drawn at all. |
| | | sublime.HIDE_ON_MINIMAP. Don't show the regions on the minimap. |
| | | sublime.DRAW_EMPTY_AS_OVERWRITE. Draw empty regions with a horizontal bar instead of a vertical one. |
| | | sublime.DRAW_NO_FILL. Disable filling the regions, leaving only the outline. |
| | | sublime.DRAW_NO_OUTLINE. Disable drawing the outline of the regions. |
| | | sublime.DRAW_SOLID_UNDERLINE. Draw a solid underline below the regions. |
| | | sublime.DRAW_STIPPLED_UNDERLINE. Draw a stippled underline below the regions. |
| | | sublime.DRAW_SQUIGGLY_UNDERLINE. Draw a squiggly underline below the regions. |
| | | sublime.PERSISTENT. Save the regions in the session. |
| | | sublime.HIDDEN. Don't draw the regions. |
| | | |
| | | The underline styles are exclusive, either zero or one of them should be given. If using an underline, DRAW_NO_FILL and DRAW_NO_OUTLINE should generally be passed in. |
| get_regions(key) | [regions] | Return the regions associated with the given key, if any |
| erase_regions(key) | None | Removed the named regions |
| set_status(key, value) | None | Adds the status key to the view. The value will be displayed in the status bar, in a comma separated list of all status values, ordered by key. Setting the value to the empty string will clear the status. |
| get_status(key) | String | Returns the previously assigned value associated with the key, if any. |
| erase_status(key) | None | Clears the named status. |
| command_history(index, <modifying_only>) | (String,Dict,int) | Returns the command name, command arguments, and repeat count for the given history entry, as stored in the undo / redo stack. |
| | | Index 0 corresponds to the most recent command, -1 the command before that, and so on. Positive values for index indicate to look in the redo stack for commands. If the undo / redo history doesn't extend far enough, then (None, None, 0) will be returned. |
| | | Setting modifying_only to True (the default is False) will only return entries that modified the buffer. |
| change_count() | int | Returns the current change count. Each time the buffer is modified, the change count is incremented. The change count can be used to determine if the buffer has changed since the last it was inspected. |
| fold([regions]) | bool | Folds the given regions, returning False if they were already folded |
| fold(region) | bool | Folds the given region, returning False if it was already folded |
| unfold(region) | [regions] | Unfolds all text in the region, returning the unfolded regions |
| unfold([regions]) | [regions] | Unfolds all text in the regions, returning the unfolded regions |
| encoding() | String | Returns the encoding currently associated with the file |
| set_encoding(encoding) | None | Applies a new encoding to the file. This encoding will be used the next time the file is saved. |
| line_endings() | String | Returns the line endings used by the current file. |
| set_line_endings(line_endings) | None | Sets the line endings that will be applied when next saving. |
| overwrite_status() | Bool | Returns the overwrite status, which the user normally toggles via the insert key. |
| set_overwrite_status(enabled) | None | Sets the overwrite status. |
| symbols(line_endings) | [(Region, String)] | Extract all the symbols defined in the buffer. |
| show_popup_menu(items, on_done, <flags>) | None | Shows a pop up menu at the caret, to select an item in a list. on_done will be called once, with the index of the selected item. If the pop up menu was cancelled, on_done will be called with an argument of -1. |
| | | Items is an array of strings. |
| | | Flags currently only has no option. |
| window_to_layout(self, xy) | | convert from window coordinates to layout coordinates, used to lookup the position in the buffer where the context menu was shown |
| window_to_text(self, xy) | | convert from window coordinates to text coordinates, used to lookup the position in the buffer where the context menu was shown |
| show_popup() | | show a tooltip, i.e: view.show_popup('Hello, <b>World!</b><br><a href="moo">Click Me</a>', on_navigate=print) |
| | | Flag: COOPERATE_WITH_AUTO_COMPLETE |
sublime.Window:
| Method | Return Value | Description |
|-------------------------------------------------------------------------------|----------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| id() | int | Returns a number that uniquely identifies this window. |
| new_file() | View | Creates a new file. The returned view will be empty, and its is_loaded method will return True. |
| open_file(file_name, <flags>) | View | Opens the named file, and returns the corresponding view. If the file is already opened, it will be brought to the front. Note that as file loading is asynchronous, operations on the returned view won't be possible until its is_loading() method returns False. |
| | | The optional flags parameter is a bitwise combination of: |
| | | sublime.ENCODED_POSITION. Indicates the file_name should be searched for a :row or :row:col suffix |
| | | sublime.TRANSIENT. Open the file as a preview only: it won't have a tab assigned it until modified |
| find_open_file(file_name) | View | Finds the named file in the list of open files, and returns the corresponding View, or None if no such file is open. |
| active_view() | View | Returns the currently edited view. |
| active_view_in_group(group) | View | Returns the currently edited view in the given group. |
| views() | [View] | Returns all open views in the window. |
| views_in_group(group) | [View] | Returns all open views in the given group. |
| num_groups() | int | Returns the number of view groups in the window. |
| active_group() | int | Returns the index of the currently selected group. |
| focus_group(group) | None | Makes the given group active. |
| focus_view(view) | None | Switches to the given view. |
| get_view_index(view) | (group, index) | Returns the group, and index within the group of the view. Returns -1 if not found. |
| set_view_index(view, group, index) | None | Moves the view to the given group and index. |
| folders() | [String] | Returns a list of the currently opened folders in project/sidebar. |
| project_file_name() | String | Returns name of the currently opened project file, if any. |
| project_data() | Dictionary | Returns the project data associated with the current window. The data is in the same format as the contents of a .sublime-project file. |
| set_project_data(data) | None | Updates the project data associated with the current window. If the window is associated with a .sublime-project file, the project file will be updated on disk, otherwise the window will store the data internally. |
| run_command(string, <args>) | None | Runs the named Command with the (optional) given arguments. Window.run_command is able to run both any sort of command, dispatching the command via input focus. |
| show_quick_panel(items, on_done, <flags>, <selected_index>, <on_highlighted>) | None | Shows a quick panel, to select an item in a list. on_done will be called once, with the index of the selected item. If the quick panel was cancelled, on_done will be called with an argument of -1. [[obj\show_quick_panel.py]] |
| | | Items may be an array of strings, or an array of string arrays. In the latter case, each entry in the quick panel will show multiple rows. |
| | | Flags currently only has one option, sublime.MONOSPACE_FONT |
| | | on_highlighted, if given, will be called every time the highlighted item in the quick panel is changed. |
| show_input_panel(caption, initial_text, on_done, on_change, on_cancel) | View | Shows the input panel, to collect a line of input from the user. on_done and on_change, if not None, should both be functions that expect a single string argument. on_cancel should be a function that expects no arguments. The view used for the input widget is returned. |
| create_output_panel(name) | View | Returns the view associated with the named output panel, created it if required. The output panel can be shown by running the show_panel window command, with the panel argument set to the name with an "output." prefix. |
| lookup_symbol_in_index(symbol) | [Location] | Returns all locations where the symbol is defined across files in the current project. |
| lookup_symbol_in_open_files(symbol) | [Location] | Returns all locations where the symbol is defined across open files. |
sublime_plugin.ApplicationCommand:
| Method | Return Value | Description |
|---------------------|--------------|------------------------------------------------------------------------------------------------------------------------------------------------------------|
| run(<args>) | None | Called when the command is run. |
| is_enabled(<args>) | bool | Returns true if the command is able to be run at this time. The default implementation simply always returns True. |
| is_visible(<args>) | bool | Returns true if the command should be shown in the menu at this time. The default implementation always returns True. |
| is_checked(<args>) | bool | Returns true if a checkbox should be shown next to the menu item. The .sublime-menu file must have the checkbox attribute set to true for this to be used. |
| description(<args>) | String | Returns a description of the command with the given arguments. Used in the menu, if no caption is provided. Return None to get the default description. |
sublime_plugin.EventListener:
| Method | Return Value | Description |
|-----------------------------------------------------------|------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| on_new(view) | None | Called when a new buffer is created. |
| on_new_async(view) | None | Called when a new buffer is created. Runs in a separate thread, and does not block the application. |
| on_clone(view) | None | Called when a view is cloned from an existing one. |
| on_clone_async(view) | None | Called when a view is cloned from an existing one. Runs in a separate thread, and does not block the application. |
| on_load(view) | None | Called when the file is finished loading. |
| on_load_async(view) | None | Called when the file is finished loading. Runs in a separate thread, and does not block the application. |
| on_pre_close(view) | None | Called when a view is about to be closed. The view will still be in the window at this point. |
| on_close(view) | None | Called when a view is closed (note, there may still be other views into the same buffer). |
| on_pre_save(view) | None | Called just before a view is saved. |
| on_pre_save_async(view) | None | Called just before a view is saved. Runs in a separate thread, and does not block the application. |
| on_post_save(view) | None | Called after a view has been saved. |
| on_post_save_async(view) | None | Called after a view has been saved. Runs in a separate thread, and does not block the application. |
| on_modified(view) | None | Called after changes have been made to a view. |
| on_modified_async(view) | None | Called after changes have been made to a view. Runs in a separate thread, and does not block the application. |
| on_selection_modified(view) | None | Called after the selection has been modified in a view. |
| on_selection_modified_async(view) | None | Called after the selection has been modified in a view. Runs in a separate thread, and does not block the application. |
| on_activated(view) | None | Called when a view gains input focus. |
| on_activated_async(view) | None | Called when a view gains input focus. Runs in a separate thread, and does not block the application. |
| on_deactivated(view) | None | Called when a view loses input focus. |
| on_deactivated_async(view) | None | Called when a view loses input focus. Runs in a separate thread, and does not block the application. |
| on_text_command(view, command_name, args) | (new_command_name, new_args) | Called when a text command is issued. The listener may return a (command, arguments) tuple to rewrite the command, or None to run the command unmodified. |
| on_window_command(window, command_name, args) | (new_command_name, new_args) | Called when a window command is issued. The listener may return a (command, arguments) tuple to rewrite the command, or None to run the command unmodified. |
| post_text_command(view, command_name, args) | None | Called after a text command has been executed. |
| post_window_command(window, command_name, args) | None | Called after a window command has been executed. |
| on_query_context(view, key, operator, operand, match_all) | bool or None | Called when determining to trigger a key binding with the given context key. If the plugin knows how to respond to the context, it should return either True of False. If the context is unknown, it should return None. |
| | | |
| | | operator is one of: |
| | | |
| | | sublime.OP_EQUAL. Is the value of the context equal to the operand? |
| | | sublime.OP_NOT_EQUAL. Is the value of the context not equal to the operand? |
| | | sublime.OP_REGEX_MATCH. Does the value of the context match the regex given in operand? |
| | | sublime.OP_NOT_REGEX_MATCH. Does the value of the context not match the regex given in operand? |
| | | sublime.OP_REGEX_CONTAINS. Does the value of the context contain a substring matching the regex given in operand? |
| | | sublime.OP_NOT_REGEX_CONTAINS. Does the value of the context not contain a substring matching the regex given in operand? |
| | | |
| | | match_all should be used if the context relates to the selections: does every selection have to match (match_all = True), or is at least one matching enough (match_all = Fals)? |
sublime_plugin.TextCommand:
| Method | Return Value | Description |
|---------------------|--------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------|
| run(edit, <args>) | None | Called when the command is run. |
| is_enabled(<args>) | bool | Returns true if the command is able to be run at this time. The default implementation simply always returns True. |
| is_visible(<args>) | bool | Returns true if the command should be shown in the menu at this time. The default implementation always returns True. |
| description(<args>) | String | Returns a description of the command with the given arguments. Used in the menus, and for Undo / Redo descriptions. Return None to get the default description. |
sublime_plugin.WindowCommand:
| Method | Return Value | Description |
|---------------------|--------------|---------------------------------------------------------------------------------------------------------------------------------------------------------|
| run(<args>) | None | Called when the command is run. |
| is_enabled(<args>) | bool | Returns true if the command is able to be run at this time. The default implementation simply always returns True. |
| is_visible(<args>) | bool | Returns true if the command should be shown in the menu at this time. The default implementation always returns True. |
| description(<args>) | String | Returns a description of the command with the given arguments. Used in the menu, if no caption is provided. Return None to get the default description. |