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 PackagesPath() string
- func PascalCaseToSnakeCase(in string) string
- type ApplicationCommand
- type Args
- type BypassUndoCommand
- type Command
- type CommandHandler
- 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) 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 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) 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) SetFrontend(f Frontend)
- func (e *Editor) UnWatch(name string)
- func (e *Editor) Version() string
- func (e *Editor) Watch(file WatchedFile)
- func (e *Editor) Watcher() *fsnotify.Watcher
- func (e *Editor) Windows() []*Window
- type Frontend
- type Key
- type KeyBinding
- type KeyBindings
- func (k *KeyBindings) Action(v *View) (kb *KeyBinding)
- func (k *KeyBindings) DropLessEqualKeys(count int)
- func (k *KeyBindings) Filter(kp KeyPress) (ret KeyBindings)
- func (k *KeyBindings) Len() int
- func (k *KeyBindings) Less(i, j int) bool
- func (k KeyBindings) String() string
- func (k *KeyBindings) Swap(i, j int)
- func (k *KeyBindings) UnmarshalJSON(d []byte) error
- type KeyContext
- type KeyPress
- type Op
- 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) Close()
- 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) ExtractScope(point int) Region
- func (v *View) GetRegions(key string) (ret []Region)
- func (v *View) Insert(edit *Edit, point int, value string) int
- 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) Transform(scheme render.ColourScheme, viewport Region) render.Recipe
- func (v *View) UndoStack() *UndoStack
- func (v *View) Window() *Window
- type ViewEvent
- type ViewEventCallback
- type WatchedFile
- type WatchedSettingFile
- type WatchedUserFile
- type Window
- type WindowCommand
- type WindowEvent
- type WindowEventCallback
- Bugs
Constants ¶
const ( Left Key = 0x2190 + iota Up Right Down Enter = '\n' Escape = 0x001B Backspace = 0x0008 Delete = 0x007F KeypadEnter = '\n' )
const DEFAULT_SUBLIME_SETTINGS_PATH = "../../backend/packages/Default/Default.sublime-settings"
Variables ¶
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 PackagesPath ¶
func PackagesPath() string
func PascalCaseToSnakeCase ¶
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 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 { // Default return value for OkCancelDialog DefaultAction bool }
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) 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 // 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) SetFrontend ¶
func (*Editor) Watch ¶
func (e *Editor) Watch(file WatchedFile)
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 usser 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 that is frontend specific.
type KeyBinding ¶
type KeyBinding struct { Keys []KeyPress Command string Args Args Context []KeyContext // contains filtered or unexported fields }
A single KeyBinding for which after pressing the given sequence of Keys, and the Context matches, the Command will be invoked with the provided Args.
type KeyBindings ¶
type KeyBindings struct { Bindings []*KeyBinding // contains filtered or unexported fields }
func (*KeyBindings) Action ¶
func (k *KeyBindings) Action(v *View) (kb *KeyBinding)
Tries to resolve all the current KeyBindings in k to a single action. If any action is appropriate as determined by context, the return value will be the specific KeyBinding that is possible to execute now, otherwise it is nil.
func (*KeyBindings) DropLessEqualKeys ¶
func (k *KeyBindings) DropLessEqualKeys(count int)
Drops all KeyBindings that are a sequence of key presses less or equal to the given number.
func (*KeyBindings) Filter ¶
func (k *KeyBindings) Filter(kp KeyPress) (ret KeyBindings)
Filters the KeyBindings, returning a new KeyBindings object containing a subset of matches for the given key press.
func (*KeyBindings) Less ¶
func (k *KeyBindings) Less(i, j int) bool
Compares one KeyBinding to another for sorting purposes.
func (KeyBindings) String ¶
func (k KeyBindings) String() string
func (*KeyBindings) Swap ¶
func (k *KeyBindings) Swap(i, j int)
Swaps the two KeyBindings at the given positions.
func (*KeyBindings) UnmarshalJSON ¶
func (k *KeyBindings) UnmarshalJSON(d []byte) error
type KeyContext ¶
type KeyContext struct {
// contains filtered or unexported fields
}
A Context definition for which a key binding is to be considered.
func (*KeyContext) UnmarshalJSON ¶
func (k *KeyContext) UnmarshalJSON(d []byte) error
type KeyPress ¶
A Key press with the given Key and modifiers.
func (KeyPress) Index ¶
Returns an index used for sorting key presses. TODO(.): This is in no way a unique index with quite a lot of collisions and potentially resulting in bad lookups.
func (KeyPress) IsCharacter ¶
Returns whether this KeyPress is a print character or not.
func (*KeyPress) UnmarshalJSON ¶
type Op ¶
type Op int
A comparison operation used in context queries.
const ( OpEqual Op = iota //< Compare for equality. OpNotEqual //< Compare for difference. OpRegexMatch //< Compare for a regular expression match. OpNotRegexMatch //< Compare for a regular expression difference. OpRegexContains //< Compare whether the given regular expression matches some substring of the operand. OpNotRegexContains //< Compare whether the given regular expression does not match some substring of the operand. )
func (*Op) UnmarshalJSON ¶
type QueryContextCallback ¶
type QueryContextCallback func(v *View, key string, operator 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 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) 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) ExtractScope ¶
Returns the Region of the innermost scope that contains "point". See package lime/backend/parser for details.
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 WatchedFile ¶
type WatchedFile interface { Name() string Reload() }
type WatchedSettingFile ¶
type WatchedSettingFile struct {
// contains filtered or unexported fields
}
func NewWatchedSettingFile ¶
func NewWatchedSettingFile(path string) *WatchedSettingFile
func (*WatchedSettingFile) Name ¶
func (o *WatchedSettingFile) Name() string
func (*WatchedSettingFile) Reload ¶
func (o *WatchedSettingFile) Reload()
type WatchedUserFile ¶
type WatchedUserFile struct {
// contains filtered or unexported fields
}
func NewWatchedUserFile ¶
func NewWatchedUserFile(view *View) *WatchedUserFile
func (*WatchedUserFile) Name ¶
func (o *WatchedUserFile) Name() string
func (*WatchedUserFile) Reload ¶
func (o *WatchedUserFile) Reload()
func (WatchedUserFile) String ¶
func (o WatchedUserFile) String() string
type Window ¶
type Window struct { text.HasId text.HasSettings // contains filtered or unexported fields }
func (*Window) ActiveView ¶
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. |
json
This file was generated, and shouldn't be manually changed
|
This file was generated, and shouldn't be manually changed |
plist
This file was generated, and shouldn't be manually changed
|
This file was generated, and shouldn't be manually changed |
The parser package defines interfaces responsible for creating an Abstract Syntax Tree like structure of a text document.
|
The parser package defines interfaces responsible for creating an Abstract Syntax Tree like structure of a text document. |
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. |