Plugin API Reference

Sublime API:

Plugin Base Classes:

Module sublime

MethodsReturn ValueDescription
setTimeout(callback, delay)noneCalls 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)noneSets the message that appears in the status bar.
errorMessage(string)noneDisplays an error dialog to the user.
messageBox(string)noneDisplays a message box to the user.
questionBox(string)boolDisplays a yes / no message box to the user, return True iff they selected yes.
options()OptionsReturns a reference to the application options.
runCommand(string)noneRuns the named ApplicationCommand.
runCommand(string, args)noneRuns the named ApplicationCommand with the given arguments.
packagesPath()StringReturns the base path to the packages.
installedPackagesPath()StringReturns the path where all the user's *.sublime-package files are.
getClipboard()StringReturns the contents of the clipboard.
setClipboard(string)noneSets the contents of the clipboard.

Class sublime.View

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.

MethodsReturn ValueDescription
fileName()StringThe full name file the file associated with the buffer, or None if it doesn't exist on disk.
options()OptionsReturns a reference to the file type options for the view.
window()WindowReturns a reference to the window containing the view.
runCommand(string)noneRuns the named ViewCommand.
runCommand(string, args)noneRuns the named ViewCommand with the given arguments.
size()intReturns the number of character in the file.
substr(region)StringReturns the contents of the region as a string.
substr(point)StringReturns the character to the right of the point.
insert(point, string)noneInserts the given string in the buffer at the specified point.
erase(region)noneErases the contents of the region from the buffer.
replace(region, string)noneReplaces the contents of the region with the given string.
sel()RegionSetReturns a reference to the selection.
line(point)RegionReturns the line that contains the point.
line(region)RegionReturns 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)RegionAs line(), but the region includes the trailing newline character, if any.
fullLine(region)RegionAs 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.
splitByLines(region)[Region]Splits the region up such that each region returned exists on exactly one line.
rowcol(point)(int, int)Calculates the 0 based line and column numbers of the point.
textPoint(row, col)intCalculates 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)RegionReturns the extents of the syntax name assigned to the character at the given point.
syntaxName(point)StringReturns the syntax name assigned to the character at the given point.
matchSelector(point, selector)boolReturns True iff the selector matches the syntax name assigned to the character at the given point.

Class sublime.RegionSet

Maintains a set of Regions, ensuring that none overlap, and that they are kept in sorted order.

MethodsReturn ValueDescription
clear()noneRemoves all regions.
add(region)noneAdds the given region. It will be merged with any intersecting regions already contained within the set.
addAll(regionSet)noneAdds all regions in the given set.
subtract(region)noneSubtracts the region from all regions in the set.
contains(region)boolReturns true iff the given region is a subset.

Class sublime.Region

Represents an area of the buffer. Empty regions, where a == b are valid.

ConstructorsDescription
Region(a, b)Creates a Region with initial values a and b.
PropertiesTypeDescription
aintThe first end of the region.
bintThe second end of the region. May be less that a, in which case the region is a reversed one.
MethodsReturn ValueDescription
begin()intReturns the minimum of a and b.
end()intReturns the maximum of a and b.
size()intReturns the number of characters spanned by the region. Always >= 0.
empty()boolReturns true iff begin() == end().
cover(region)RegionReturns a Region spanning both this and the given regions.
intersection(region)RegionReturns the set intersection of the two regions.
intersects(region)boolReturns True iff this == region or both include one or more positions in common.
contains(region)boolReturns True iff the given region is a subset.
contains(point)boolReturns True iff begin() <= point <= end().

Class sublime.Window

MethodsReturn ValueDescription
newFile()ViewCreates a new file.
openFile(filename, row, col)noneOpens the given file, and returns a view. Row and col are optional and may be omitted. Note that as file loading is asynchronous, this method returns nothing.
activeView()ViewReturns the currently edited view.
runCommand(string)noneRuns the named WindowCommand.
runCommand(string, args)noneRuns the named WindowCommand with the given arguments.

Class sublime.Options

MethodsReturn ValueDescription
getString(name)StringReturns the string value of the named option.
get(name)valueReturns the named option as the appropriate type.
get(name, default)valueReturns the named option as the appropriate type, or default if it's not defined.
set(name, value)noneSets the named option. Only primitive types are accepted.
erase(name)noneRemoves the named option. Does not remove it from any parent Options.
has(name)boolReturns true iff the named option exists in this set of Options or one of its parents.

Module sublimeplugin

MethodsReturn ValueDescription
(no methods)

Class sublimeplugin.Plugin

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.

MethodsReturn ValueDescription
onNew(view)noneCalled when a new buffer is created.
onClone(view)noneCalled when a view is cloned from an existing one.
onLoad(view)noneCalled when the file is finished loading.
onClose(view)noneCalled when a view is closed (note, there may still be other views into the same buffer).
onPreSave(view)noneCalled just before a view is saved.
onPostSave(view)noneCalled after a view has been saved.
onModified(view)noneCalled after changes have been made to a view.
onActivated(view)noneCalled when a view gains input focus.

Class sublimeplugin.ApplicationCommand(Plugin)

MethodsReturn ValueDescription
run(args)noneCalled when the command is run.
isEnabled(args)boolReturns true if the command is able to be run at this time. The default implementation simply always returns True.

Class sublimeplugin.WindowCommand(Plugin)

MethodsReturn ValueDescription
run(window, args)noneCalled when the command is run.
isEnabled(window, args)boolReturns true if the command is able to be run at this time. The default implementation simply always returns True.

Class sublimeplugin.TextCommand(Plugin)

MethodsReturn ValueDescription
run(view, args)noneCalled when the command is run.
isEnabled(view, args)boolReturns true if the command is able to be run at this time. The default implementation simply always returns True.