Documentation ¶
Overview ¶
The backend package defines the very soul of Lime.
Some highlevel concepts follow.
Frontend ¶
Lime is designed with the goal of having a clear frontend and backend separation to allow and hopefully simplify the creation of multiple frontend versions.
The two most active frontends are at the time of writing this one for terminals based on termbox-go and a GUI application based on Qt's QML scripting language.
There's also a Proof of Concept html frontend.
Editor ¶
The Editor singleton represents the most fundamental interface that frontends use to access the backend. It keeps a list of editor windows, handles input, detects file changes as well as communicate back to the frontend as needed.
Window ¶
At any time there can be multiple windows of the editor open. Each Window can have a different layout, settings and status.
View ¶
The View class defines a "view" into a specific backing buffer. Multiple views can share the same backing buffer. For instance viewing the same buffer in split view, or viewing the buffer with one syntax definition in one view and another syntax definition in the other.
It is very closely related to the view defined in the Model-view-controller paradigm, and contains settings pertaining to exactly how a buffer is shown to the user.
Command ¶
The command interface defines actions to be executed either for the whole application, a specific window or a specific view.
Key bindings ¶
Key bindings define a sequence of key-presses, a Command and the command's arguments to be executed upon that sequence having been pressed.
Key bindings can optionally have multiple contexts associated with it which allows the exact same key sequence to have different meaning depending on context.
See http://godoc.org/github.com/limetext/lime/backend#QueryContextCallback for details.
Settings ¶
Many of the components have their own key-value Settings object associated with it, but settings are also nested. In other words, if the settings key does not exist in the current object's settings, its parent's settings object is queried next which in turn will query its parent if its settings object didn't contain the key neither.
Index ¶
- Constants
- Variables
- func DefaultName(cmd interface{}) string
- type ApplicationCommand
- type Args
- type BypassUndoCommand
- type Command
- type CommandHandler
- type CustomDefault
- type CustomInit
- type CustomSet
- type DefaultCommand
- type DummyFrontend
- func (h *DummyFrontend) ErrorMessage(msg string)
- func (h *DummyFrontend) MessageDialog(msg string)
- func (h *DummyFrontend) OkCancelDialog(msg string, button string) bool
- func (h *DummyFrontend) SetDefaultAction(action bool)
- func (h *DummyFrontend) Show(v *View, r Region)
- func (h *DummyFrontend) StatusMessage(msg string)
- func (h *DummyFrontend) VisibleRegion(v *View) Region
- type Edit
- type Editor
- func (e *Editor) ActiveWindow() *Window
- func (e *Editor) Arch() string
- func (e *Editor) CommandHandler() CommandHandler
- func (e *Editor) Console() *View
- func (e *Editor) Frontend() Frontend
- func (e *Editor) GetClipboard() string
- func (e *Editor) HandleInput(kp keys.KeyPress)
- func (e *Editor) Init()
- func (e *Editor) LogCommands(l bool)
- func (e *Editor) LogInput(l bool)
- func (e *Editor) NewWindow() *Window
- func (e *Editor) PackagesPath() string
- func (e *Editor) Plat() string
- func (e *Editor) Platform() string
- func (e *Editor) RunCommand(name string, args Args)
- func (e *Editor) SetActiveWindow(w *Window)
- func (e *Editor) SetClipboard(n string)
- func (e *Editor) SetClipboardFuncs(setter func(string) error, getter func() (string, error))
- func (e *Editor) SetFrontend(f Frontend)
- func (e *Editor) Version() string
- func (e *Editor) Windows() []*Window
- type Frontend
- type QueryContextCallback
- type QueryContextEvent
- type QueryContextReturn
- type TextCommand
- type UndoStack
- type View
- func (v *View) AddRegions(key string, regions []Region, scope, icon string, flags render.ViewRegionFlags)
- func (v *View) BeginEdit() *Edit
- func (v *View) Buffer() Buffer
- func (v *View) Classify(point int) (res int)
- func (v *View) Close() bool
- func (v *View) CommandHistory(idx int, modifying_only bool) (name string, args Args, count int)
- func (v *View) EndEdit(edit *Edit)
- func (v *View) Erase(edit *Edit, r Region)
- func (v *View) EraseRegions(key string)
- func (v *View) EraseStatus(key string)
- func (v *View) Erased(changed_buffer Buffer, region_removed Region, data_removed []rune)
- func (v *View) ExpandByClass(r Region, classes int) Region
- func (v *View) ExtractScope(point int) Region
- func (v *View) FileChanged(filename string)
- func (v *View) Find(pat string, pos int, flags int) Region
- func (v *View) FindByClass(point int, forward bool, classes int) int
- func (v *View) GetRegions(key string) (ret []Region)
- func (v *View) GetStatus(key string) string
- func (v *View) Insert(edit *Edit, point int, value string) int
- func (v *View) Inserted(changed_buffer Buffer, region_inserted Region, data_inserted []rune)
- func (v *View) IsDirty() bool
- func (v *View) IsScratch() bool
- func (v *View) OverwriteStatus() bool
- func (v *View) Replace(edit *Edit, r Region, value string)
- func (v *View) Save() error
- func (v *View) SaveAs(name string) (err error)
- func (v *View) ScopeName(point int) string
- func (v *View) ScoreSelector(point int, selector string) int
- func (v *View) Sel() *RegionSet
- func (v *View) SetOverwriteStatus(s bool)
- func (v *View) SetScratch(s bool)
- func (v *View) SetStatus(key string, val string)
- func (v *View) Transform(scheme render.ColourScheme, viewport Region) render.Recipe
- func (v *View) UndoStack() *UndoStack
- func (v *View) Window() *Window
- type ViewEvent
- type ViewEventCallback
- type Window
- type WindowCommand
- type WindowEvent
- type WindowEventCallback
- Bugs
Constants ¶
const ( CLASS_WORD_START = 1 << iota 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 CLASS_MIDDLE_WORD CLASS_WORD_START_WITH_PUNCTUATION CLASS_WORD_END_WITH_PUNCTUATION CLASS_OPENING_PARENTHESIS CLASS_CLOSING_PARENTHESIS DEFAULT_SEPARATORS = "[!\"#$%&'()*+,\\-./:;<=>?@\\[\\\\\\]^`{|}~]" )
const ( LITERAL = 1 << iota IGNORECASE )
Variables ¶
var ( LIME_USER_PACKAGES_PATH = path.Join("..", "..", "packages", "User") LIME_PACKAGES_PATH = path.Join("..", "..", "packages") LIME_DEFAULTS_PATH = path.Join("..", "..", "packages", "Default") )
var ( OnNew ViewEvent //< Called when a new view is created OnLoad ViewEvent //< Called when loading a view's buffer has finished OnActivated ViewEvent //< Called when a view gains input focus. OnDeactivated ViewEvent //< Called when a view loses input focus. OnPreClose ViewEvent //< Called when a view is about to be closed. OnClose ViewEvent //< Called when a view has been closed. OnPreSave ViewEvent //< Called just before a view's buffer is saved. OnPostSave ViewEvent //< Called after a view's buffer has been saved. OnModified ViewEvent //< Called when the contents of a view's underlying buffer has changed. OnSelectionModified ViewEvent //< Called when a view's Selection/cursor has changed. OnNewWindow WindowEvent //< Called when a new window has been created. OnQueryContext QueryContextEvent //< Called when context is being queried. )
Functions ¶
func DefaultName ¶
func DefaultName(cmd interface{}) string
Types ¶
type ApplicationCommand ¶
type ApplicationCommand interface { Command // Execute this command Run() error // Returns whether this command is checked or not. // Used to display a checkbox in the user interface // for boolean commands. IsChecked() bool }
The ApplicationCommand interface extends the base Command interface with functionality specific for ApplicationCommands.
type Args ¶
type Args map[string]interface{}
The Args type is just a generic string key and interface{} value map type used to serialize command arguments.
type BypassUndoCommand ¶
type BypassUndoCommand struct {
DefaultCommand
}
The BypassUndoCommand is the same as the DefaultCommand type, except that its implementation of BypassUndo returns true rather than false.
func (*BypassUndoCommand) BypassUndo ¶
func (b *BypassUndoCommand) BypassUndo() bool
The BypassUndoCommand defaults to bypassing the undo stack.
type Command ¶
type Command interface { // Returns whether the Command is enabled or not. IsEnabled() bool // Returns whether the Command is visible in menus, // the goto anything panel or other user interface // that lists available commands. IsVisible() bool // Returns the textual description of the command. Description() string // Whether or not this Command bypasses the undo stack. BypassUndo() bool }
The Command interface implements the basic interface that is shared between the different more specific command type interfaces.
In the traditional Model-view-controller design, Commands are roughly equivalent to the action-taking controller piece.
type CommandHandler ¶
type CommandHandler interface { Unregister(string) error RegisterWithDefault(cmd interface{}) error Register(name string, cmd interface{}) error // TODO(q): Do the commands need to be split in separate lists? RunWindowCommand(*Window, string, Args) error RunTextCommand(*View, string, Args) error RunApplicationCommand(string, Args) error }
type CustomDefault ¶
type CustomDefault interface {
Default(key string) interface{}
}
type CustomInit ¶
The CustomInit interface can be optionally implemented by a Command and will be called instead of the default command initialization code.
type CustomSet ¶
type CustomSet interface {
Set(v interface{}) error
}
The CustomSet interface can be optionally implemented by struct members of a concrete command struct.
If implemented, it'll be called by the default Command initialization code with the data gotten from the Args map.
type DefaultCommand ¶
type DefaultCommand struct{}
The DefaultCommand implements the default operation of the basic Command interface and is recommended to be used as the base when creating new Commands.
func (*DefaultCommand) BypassUndo ¶
func (d *DefaultCommand) BypassUndo() bool
The default is to not bypass the undo stack.
func (*DefaultCommand) Description ¶
func (d *DefaultCommand) Description() string
By default the string "TODO" is return as the description.
func (*DefaultCommand) IsEnabled ¶
func (d *DefaultCommand) IsEnabled() bool
By default a command is enabled.
func (*DefaultCommand) IsVisible ¶
func (d *DefaultCommand) IsVisible() bool
By default a command is visible.
type DummyFrontend ¶
type DummyFrontend struct {
// contains filtered or unexported fields
}
func (*DummyFrontend) ErrorMessage ¶
func (h *DummyFrontend) ErrorMessage(msg string)
func (*DummyFrontend) MessageDialog ¶
func (h *DummyFrontend) MessageDialog(msg string)
func (*DummyFrontend) OkCancelDialog ¶
func (h *DummyFrontend) OkCancelDialog(msg string, button string) bool
func (*DummyFrontend) SetDefaultAction ¶
func (h *DummyFrontend) SetDefaultAction(action bool)
func (*DummyFrontend) Show ¶
func (h *DummyFrontend) Show(v *View, r Region)
func (*DummyFrontend) StatusMessage ¶
func (h *DummyFrontend) StatusMessage(msg string)
func (*DummyFrontend) VisibleRegion ¶
func (h *DummyFrontend) VisibleRegion(v *View) Region
type Edit ¶
type Edit struct {
// contains filtered or unexported fields
}
The Edit object is an internal type passed as an argument to a TextCommand. All text operations need to be associated with a valid Edit object.
Think of it a bit like an SQL transaction.
func (*Edit) Apply ¶
func (e *Edit) Apply()
Applies the action of this Edit object. Should typically not be manually called.
type Editor ¶
type Editor struct { HasSettings keys.HasKeyBindings *watch.Watcher // contains filtered or unexported fields }
func (*Editor) ActiveWindow ¶
func (*Editor) CommandHandler ¶
func (e *Editor) CommandHandler() CommandHandler
func (*Editor) GetClipboard ¶
func (*Editor) HandleInput ¶
func (*Editor) LogCommands ¶
func (*Editor) PackagesPath ¶
func (*Editor) RunCommand ¶
func (*Editor) SetActiveWindow ¶
func (*Editor) SetClipboard ¶
func (*Editor) SetClipboardFuncs ¶
func (*Editor) SetFrontend ¶
type Frontend ¶
type Frontend interface { // Probe the frontend for the currently // visible region of the given view. VisibleRegion(v *View) Region // Make the frontend show the specified region of the // given view. Show(v *View, r Region) // Sets the status message shown in the status bar StatusMessage(string) // Displays an error message to the user ErrorMessage(string) // Displays a message dialog to the user MessageDialog(string) // Displays an ok / cancel dialog to the user. // "okname" if provided will be used as the text // instead of "Ok" for the ok button. // Returns true when ok was pressed, and false when // cancel was pressed. OkCancelDialog(msg string, okname string) bool }
The Frontend interface defines the API for functionality that is frontend specific.
type QueryContextCallback ¶
type QueryContextCallback func(v *View, key string, operator util.Op, operand interface{}, match_all bool) QueryContextReturn
The context is queried when trying to figure out what action should be performed when certain conditions are met.
Context is just a string identifier, an optional comparison operator, an optional operand, and an optional match_all boolean. The data of the context is optionally provided together with a key binding and the key's action will only be considered if the context conditions are met.
Exactly how these values are interpreted is up to the individual context handlers, which may be fully customized by implementing the callback in a plugin.
For instance pressing the key 'j' will have a different meaning when in a VI command mode emulation and when in a VI insert mode emulation. A plugin would then define two key binding entries for 'j', describe the key binding context to be able to discern which action is appropriate when 'j' is then pressed.
type QueryContextEvent ¶
type QueryContextEvent []QueryContextCallback
A QueryContextEvent is simply a bunch of QueryContextCallbacks.
func (*QueryContextEvent) Add ¶
func (qe *QueryContextEvent) Add(cb QueryContextCallback)
Add the provided QueryContextCallback to the QueryContextEvent. TODO(.): Support removing QueryContextCallbacks?
func (QueryContextEvent) Call ¶
func (qe QueryContextEvent) Call(v *View, key string, operator util.Op, operand interface{}, match_all bool) QueryContextReturn
Searches for a QueryContextCallback and returns the result of the first callback being able to deal with this context, or Unknown if no such callback was found.
type QueryContextReturn ¶
type QueryContextReturn int
The return value returned from a QueryContextCallback.
const ( True QueryContextReturn = iota //< Returned when the context query matches. False //< Returned when the context query does not match. Unknown //< Returned when the QueryContextCallback does not know how to deal with the given context. )
type TextCommand ¶
type TextCommand interface { Command // Execute this command with the specified View and Edit object // as the arguments Run(*View, *Edit) error }
The TextCommand interface extends the base Command interface with functionality specific for TextCommands.
type UndoStack ¶
type UndoStack struct {
// contains filtered or unexported fields
}
func (*UndoStack) Add ¶
Adds the provided Edit object to the UndoStack, potentially destroying the old redo stack if one had been created. TODO(.): It would be nice with branched undo histories
func (*UndoStack) GlueFrom ¶
Glues all edits from the position given by mark, to the current position in the UndoStack, replacing them by a single entry which will now be composite of all those other actions.
In other words, after the glue operation a single "undo" operation will then undo all of those edits and a single redo after that will redo them all again.
func (*UndoStack) Redo ¶
Re-applies the next action in the undo stack if there are any actions on the stack that had been undone.
See comment in Undo regarding the use of "hard".
func (*UndoStack) Undo ¶
Reverts the last action on the UndoStack.
When the argument "hard" is set to true, the "last action" will be the last action that modified the contents of the buffer (rather than just changing the cursor position). In this case, all actions between the current action and the last "hard" action will be reverted.
type View ¶
type View struct { HasSettings HasId // contains filtered or unexported fields }
A View provides a view into a specific underlying buffer with its own set of selections, settings, viewport, etc. Multiple Views can share the same underlying data buffer.
func (*View) AddRegions ¶
func (v *View) AddRegions(key string, regions []Region, scope, icon string, flags render.ViewRegionFlags)
AddRegions lets users mark text regions in a view with a scope name, gutter icon and ViewRegionflags which are then optionally used to alter the display of those regions.
Typical uses would be to draw squiggly lines under misspelled words, show an icon in the gutter to indicate a breakpoint, keeping track of snippet or auto-completion fields, highlight code compilation warnings, etc.
The regions will be automatically adjusted as appropriate when the underlying buffer is changed.
func (*View) BeginEdit ¶
Creates a new Edit object. Think of it a bit like starting an SQL transaction. Another Edit object should not be created before ending the previous one.
TODO(.): Is nesting edits ever valid? Perhaps a nil edit should be returned if the previous wasn't ended? What if it will never be ended? Leaving the buffer in a broken state where no more changes can be made to it is obviously not good and is the reason why ST3 removed the ability to manually create Edit objects to stop people from breaking the undo stack.
func (*View) Buffer ¶
func (v *View) Buffer() Buffer
Returns the underlying Buffer that this View is a view into.
func (*View) Close ¶
Initiate the "close" operation of this view. Returns "true" if the view was closed. Otherwise returns "false".
func (*View) CommandHistory ¶
Returns the CommandHistory entry at the given relative index.
When "modifying_only" is set to true, only commands that actually changed the Buffer in some way (as opposed to just moving the cursor around) are counted as an index. That would be a "hard" command as it is referred to in UndoStack.Undo.
func (*View) EraseRegions ¶
Removes the Regions associated with the given key from the view.
func (*View) EraseStatus ¶
func (*View) ExpandByClass ¶
Expands the selection until the point on each side matches the given classes
func (*View) ExtractScope ¶
Returns the Region of the innermost scope that contains "point". See package lime/backend/parser for details.
func (*View) FileChanged ¶
func (*View) FindByClass ¶
Finds the next location after point that matches the given classes Searches backward if forward is false
func (*View) GetRegions ¶
Returns the Regions associated with the given key.
func (*View) Insert ¶
Inserts text at the given position in the provided edit object. Tabs are (sometimes, depending on the View's settings) translated to spaces. The return value is the length of the string that was inserted.
func (*View) IsDirty ¶
Returns whether the underlying Buffer has any unsaved modifications. Note that Scratch buffers are never considered dirty.
func (*View) IsScratch ¶
Checks the scratch property of the view. TODO(.): Couldn't this just be a value in the View's Settings?
func (*View) OverwriteStatus ¶
Sets the overwrite status property of the view. TODO(.): Couldn't this just be a value in the View's Settings?
func (*View) ScopeName ¶
Returns the full concatenated nested scope name at point. See package lime/backend/parser for details.
func (*View) ScoreSelector ¶
ScoreSelector() takes a point and a selector string and returns a score as to how good that specific selector matches the scope name at that point.
func (*View) Sel ¶
func (v *View) Sel() *RegionSet
Sel() returns a pointer to the RegionSet used by this View to mark possibly multiple cursor positions and selection regions.
Some quick notes: The actual cursor position is always in Region.B. Region{0,0} is a cursor at the start of the text (before any characters in the text).
Region{0,1} has the cursor at position 1 (after the first character), but also selects/highlights the first character. In this instance Region.A = 0, Region.B = 1, Region.Start() returns 0 and Region.End() returns 1.
Region{1,0} has the cursor at position 0 (before the first character), but also selects/highlights the first character. Think holding shift and pressing left on your keyboard. In this instance Region.A = 1, Region.B = 0, Region.Start() returns 0 and Region.End() returns 1.
func (*View) SetOverwriteStatus ¶
Checks the overwrite status property of the view. TODO(.): Couldn't this just be a value in the View's Settings?
func (*View) SetScratch ¶
Sets the scratch property of the view. TODO(.): Couldn't this just be a value in the View's Settings?
func (*View) Transform ¶
func (v *View) Transform(scheme render.ColourScheme, viewport Region) render.Recipe
Transform() takes a ColourScheme and a viewport and returns a Recipe suitable for rendering the contents of this View that is visible in that viewport.
type ViewEvent ¶
type ViewEvent []ViewEventCallback
A ViewEvent is simply a bunch of ViewEventCallbacks.
func (*ViewEvent) Add ¶
func (ve *ViewEvent) Add(cb ViewEventCallback)
Add the provided ViewEventCallback to this ViewEvent TODO(.): Support removing ViewEventCallbacks?
type ViewEventCallback ¶
type ViewEventCallback func(v *View)
An event callback dealing with View events.
type Window ¶
type Window struct { text.HasId text.HasSettings // contains filtered or unexported fields }
func (*Window) ActiveView ¶
func (*Window) Close ¶
Closes the Window and all its Views. Returns "true" if the Window closed successfully. Otherwise returns "false".
func (*Window) CloseAllViews ¶
Closes all of the Window's Views. Returns "true" if all the Views closed successfully. Otherwise returns "false".
func (*Window) SetActiveView ¶
type WindowCommand ¶
type WindowCommand interface { Command // Execute this command with the specified window as the // argument Run(*Window) error }
The WindowCommand interface extends the base Command interface with functionality specific for WindowCommands.
type WindowEvent ¶
type WindowEvent []WindowEventCallback
A WindowEvent is simply a bunch of WindowEventCallbacks.
func (*WindowEvent) Add ¶
func (we *WindowEvent) Add(cb WindowEventCallback)
Add the provided WindowEventCallback to this WindowEvent. TODO(.): Support removing WindowEventCallbacks?
func (*WindowEvent) Call ¶
func (we *WindowEvent) Call(w *Window)
Trigger this WindowEvent by calling all the registered callbacks in order of registration.
type WindowEventCallback ¶
type WindowEventCallback func(w *Window)
A WindowEventCallback deals with Window events.
Notes ¶
Bugs ¶
Sometimes Sel becomes empty. There should always be at a minimum 1 valid cursor.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
This package implements a couple of standard commands available to the editor.
|
This package implements a couple of standard commands available to the editor. |
The render package defines interfaces and functions to stylize a View's contents with colours, fonts and other metadata.
|
The render package defines interfaces and functions to stylize a View's contents with colours, fonts and other metadata. |
This package enables support for Sublime Text 3 python plugins and is an optional import for frontends.
|
This package enables support for Sublime Text 3 python plugins and is an optional import for frontends. |
This package enables support for Textmate Language Syntax definitions (tmLanguage) and Textmate Colour Schemes (tmTheme).
|
This package enables support for Textmate Language Syntax definitions (tmLanguage) and Textmate Colour Schemes (tmTheme). |
Contains various utility functions.
|
Contains various utility functions. |