Sublime API:
Plugin Base Classes:
Methods | Return Value | Description |
---|---|---|
setTimeout(callback, delay) | none | Calls the given callback after the given delay (in milliseconds). Callbacks with an equal delay will be run in the order they were added. It is safe to call setTimeout from multiple threads. |
statusMessage(string) | none | Sets the message that appears in the status bar. |
errorMessage(string) | none | Displays an error dialog to the user. |
messageBox(string) | none | Displays a message box to the user. |
questionBox(string) | bool | Displays a yes / no message box to the user, return True iff they selected yes. |
options() | Options | Returns a reference to the application options. |
windows() | [Window] | Returns a list of all the open windows. |
activeWindow() | Window | Returns the most recently used window. |
runCommand(string, <args>) | none | Runs the named ApplicationCommand with the (optional) given arguments. |
canRunCommand(string, <args>) | none | Returns True iff the command is enabled with the (optional) given arguments |
makeCommand(string, <args>) | String | Builds a command string from a command name and arguments. This string is suitable to use as an argument to showCompletions(). |
packagesPath() | String | Returns the base path to the packages. |
installedPackagesPath() | String | Returns the path where all the user's *.sublime-package files are. |
getClipboard() | String | Returns the contents of the clipboard. |
setClipboard(string) | none | Sets the contents of the clipboard. |
getMacro() | [String] | Returns the current macro. The macro is represented as a list of commands to run. |
setMacro([string]) | none | Sets the current macro. |
Represents a view into a text buffer. Note that multiple views may refer to the same buffer, but they have their own unique selection and geometry.
Methods | Return Value | Description |
---|---|---|
id() | int | Returns a number that uniquely identifies this view. |
bufferId() | int | Returns a number that uniquely identifies the buffer underlying this view. |
fileName() | 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 |
setName(name) | none | Assigns a name to the buffer |
isLoading() | bool | Returns true if the buffer is still loading from disk, and not ready for use. |
isDirty() | bool | Returns true if there are any unsaved modifications to the buffer. |
isReadOnly() | bool | Returns true if the buffer may not be modified. |
setReadOnly(value) | none | Sets the read only property on the buffer. |
isScratch() | bool | Returns true if the buffer is a scratch buffer. Scratch buffers never report as being dirty. |
setScratch(value) | none | Sets the scratch property on the buffer. |
options() | Options | Returns a reference to the file type options for the view. |
window() | Window | Returns a reference to the window containing the view. |
runCommand(string, <args>) | none | Runs the named TextCommand with the (optional) given arguments. |
canRunCommand(string, <args>) | none | Returns True iff the command is enabled 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(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(region) | none | Erases the contents of the region from the buffer. |
replace(region, string) | none | Replaces the contents of the region with the given string. |
sel() | RegionSet | 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. |
fullLine(point) | Region | As line(), but the region includes the trailing newline character, if any. |
fullLine(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. |
splitByNewlines(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. |
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. |
findAll(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. |
textPoint(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. |
extractScope(point) | Region | Returns the extents of the syntax name assigned to the character at the given point. |
syntaxName(point) | String | Returns the syntax name assigned to the character at the given point. |
matchSelector(point, selector) | bool | Returns True iff the selector matches the syntax name assigned to the character at the given point. |
show(point, <showSurrounds>) | none | Scroll the view to show the given point. |
show(region, <showSurrounds>) | none | Scroll the view to show the given region. |
show(regionSet, <showSurrounds>) | none | Scroll the view to show the given regionSet. |
visibleRegion() | Region | Returns the currently visible area of the view. |
extractCompletions(prefix, <point>) | [String] | Returns the completions for the given prefix, based on the contents of the buffer. Completions will be ordered by frequency, and distance from the given point, if supplied. |
showCompletions(point, prefix, [completions]) | none | Shows the autocomplete menu, at the given point, with the given completions. If an entry is selected, the given prefix will be replaced with the selected completion. Each completion may be either a string, or a tuple consisting of a description and a command to run. |
addRegions(key, [regions], scope, <flags>) | none | Add a set of regions to the view. If a set of regions already exists with the given key, they'll 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 flags parameter is a bitwise combination of:
|
getRegions(key) | [regions] | Return the regions associated with the given key, if any |
eraseRegions(key) | none | Removed the named regions |
setStatus(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. |
getStatus(key) | String | Returns the previously assigned value associated with the key, if any. |
eraseStatus(key) | none | Clears the named status. |
Maintains a set of Regions, ensuring that none overlap, and that they are kept in sorted order.
Methods | 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. |
addAll(regionSet) | 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 iff the given region is a subset. |
Represents an area of the buffer. Empty regions, where a == b are valid.
Constructors | Description |
---|---|
Region(a, b) | Creates a Region with initial values a and b. |
Properties | Type | Description |
---|---|---|
a | int | The first end of the region. |
b | int | The second end of the region. May be less that a, in which case the region is a reversed one. |
Methods | 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(). |
Methods | Return Value | Description |
---|---|---|
id() | int | Returns a number that uniquely identifies this window. |
newFile() | View | Creates a new file. The returned view will be empty, and its isLoaded method will return true. |
openFile(filename, <row>, <col>) | View | Opens the named file, and returns the corresponding view. Row and col are optional and may be omitted. 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 isLoading method returns false. |
activeView() | View | Returns the currently edited view. |
activeViewInGroup(groupIdx) | View | Returns the active view in the given group. |
views() | [View] | Returns a list of all the views in the current window. |
viewsInGroup(groupIdx) | [View] | Returns a list of all the views in given group. |
focusView(view) | none | Focuses the given view. |
numGroups() | int | Returns the number of view groups in the window. |
activeGroup() | int | Returns the index of the currently selected group. |
getViewPosition(view) | groupIdx, viewIdx | Returns the group, and the index within the group, of the given view. |
setViewPosition(view, groupIdx, viewIdx) | none | Moves the view to to the given group and index within the group. |
runCommand(string, <args>) | none | Runs the named WindowCommand with the (optional) given arguments. |
canRunCommand(string, <args>) | none | Returns True iff the command is enabled with the (optional) given arguments |
isFullScreen() | bool | Returns true of the Window is currently in full screen mode. |
showQuickPanel(key, command, args, <displayArgs>, <flags>) | none | Shows the quick panel, populated with displayArgs. When an entry is selected, the command is run, with the arg corresponding to the selected display arg as a parameter. key should be used if updating the list asynchronously, or left blank otherwise.
displayArgs is optional, and will default to the list given for args. The optional flags parameter is a bitwise combination of:
|
showSelectPanel(displayArgs, onSelect, onCancel, flags, <key>, <selectedIndex>) | none | Shows the quick panel, populated with displayArgs.
onSelect will be run for each item selected, with the index of the item passed in as a parameter. onCancel will be run if the panel is closed without any items being selected. The flags parameter should be 0, or a bitwise combination of:
key should be used if updating the list asynchronously, or left blank otherwise. selectedIndex should be the index of the item to be initially selected, or omitted otherwise. |
showInputPanel(caption, initialText, onDone, onChange, onCancel) | View | Shows the input panel, to collect a line of input from the user. onDone and onChange, if not None, should both be functions that expect a single string argument. onCancel should be a function that expects no arguments. The view used for the input widget is returned. |
renderer() | String | Returns the name of the active Renderer, either "DirectX", or "OpenGL". |
hwnd() | HWND | Returns the win32 window handle for the window. |
Methods | Return Value | Description |
---|---|---|
getString(name) | String | Returns the string value of the named option. |
get(name) | value | Returns the named option as the appropriate type. |
get(name, default) | value | Returns the named option as the appropriate type, or default if it's not defined. |
set(name, value) | none | Sets the named option. Only primitive types are accepted. |
erase(name) | none | Removes the named option. Does not remove it from any parent Options. |
has(name) | bool | Returns true iff the named option exists in this set of Options or one of its parents. |
Methods | Return Value | Description |
---|---|---|
(no methods) |
Note that many of these events are triggered by the buffer underlying the view, and thus the method is only called once, with the first view as the parameter.
Methods | Return Value | Description |
---|---|---|
onNew(view) | none | Called when a new buffer is created. |
onClone(view) | none | Called when a view is cloned from an existing one. |
onLoad(view) | none | Called when the file is finished loading. |
onClose(view) | none | Called when a view is closed (note, there may still be other views into the same buffer). |
onPreSave(view) | none | Called just before a view is saved. |
onPostSave(view) | none | Called after a view has been saved. |
onModified(view) | none | Called after changes have been made to a view. |
onSelectionModified(view) | none | Called after the selection has been modified in a view. |
onActivated(view) | none | Called when a view gains input focus. |
onProjectLoad(window) | none | Called after a project has been loaded. |
onProjectClose(window) | none | Called after a project has been closed. |
onQueryContext(view, key, value) | 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. |
Methods | Return Value | Description |
---|---|---|
run(args) | none | Called when the command is run. |
isEnabled(args) | bool | Returns true if the command is able to be run at this time. The default implementation simply always returns True. |
Methods | Return Value | Description |
---|---|---|
run(window, args) | none | Called when the command is run. |
isEnabled(window, args) | bool | Returns true if the command is able to be run at this time. The default implementation simply always returns True. |
Methods | Return Value | Description |
---|---|---|
run(view, args) | none | Called when the command is run. |
isEnabled(view, args) | bool | Returns true if the command is able to be run at this time. The default implementation simply always returns True. |