backend

package
v0.0.0-...-4d984c5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 25, 2015 License: BSD-2-Clause Imports: 23 Imported by: 0

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/lib#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

View Source
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 = "[!\"#$%&'()*+,\\-./:;<=>?@\\[\\\\\\]^`{|}~]"
)
View Source
const (
	LITERAL = 1 << iota
	IGNORECASE
)

Variables

View Source
var (
	LIME_USER_PACKAGES_PATH = path.Join("..", "packages", "User")
	LIME_PACKAGES_PATH      = path.Join("..", "packages")
	LIME_DEFAULTS_PATH      = path.Join("..", "packages", "Default")
)
View Source
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.
	OnInit         InitEvent         //< Called once at program startup
)

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

type CustomInit interface {
	Init(args Args) error
}

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.

func (*Edit) String

func (e *Edit) String() string

Returns a string describing this Edit object. Should typically not be manually called.

func (*Edit) Undo

func (e *Edit) Undo()

Reverses the application 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 GetEditor

func GetEditor() *Editor

func (*Editor) ActiveWindow

func (e *Editor) ActiveWindow() *Window

func (*Editor) Arch

func (e *Editor) Arch() string

func (*Editor) CommandHandler

func (e *Editor) CommandHandler() CommandHandler

func (*Editor) Console

func (e *Editor) Console() *View

func (*Editor) Frontend

func (e *Editor) Frontend() Frontend

func (*Editor) GetClipboard

func (e *Editor) GetClipboard() string

func (*Editor) HandleInput

func (e *Editor) HandleInput(kp keys.KeyPress)

func (*Editor) Init

func (e *Editor) Init()

func (*Editor) LogCommands

func (e *Editor) LogCommands(l bool)

func (*Editor) LogInput

func (e *Editor) LogInput(l bool)

func (*Editor) NewWindow

func (e *Editor) NewWindow() *Window

func (*Editor) PackagesPath

func (e *Editor) PackagesPath() string

func (*Editor) Plat

func (e *Editor) Plat() string

func (*Editor) Platform

func (e *Editor) Platform() string

func (*Editor) RunCommand

func (e *Editor) RunCommand(name string, args Args)

func (*Editor) SetActiveWindow

func (e *Editor) SetActiveWindow(w *Window)

func (*Editor) SetClipboard

func (e *Editor) SetClipboard(n string)

func (*Editor) SetClipboardFuncs

func (e *Editor) SetClipboardFuncs(setter func(string) error, getter func() (string, error))

func (*Editor) SetFrontend

func (e *Editor) SetFrontend(f Frontend)

func (*Editor) Version

func (e *Editor) Version() string

func (*Editor) Windows

func (e *Editor) Windows() []*Window

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 InitCallback

type InitCallback func()

The InitCallback allows complex (i.e. time consuming) initiation code to be deferred until after the UI is up and running.

type InitEvent

type InitEvent []InitCallback

The InitEvent is executed once at startup, after the UI is up and running and is typically used by feature modules to defer heavy initialization work such as scanning for plugins, loading key bindings, macros etc.

func (*InitEvent) Add

func (ie *InitEvent) Add(i InitCallback)

Add the InitCallback to the InitEvent to be called during initialization. This should be called in a module's init() function.

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

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

func (us *UndoStack) Add(a *Edit)

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

func (us *UndoStack) GlueFrom(mark int)

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) Position

func (us *UndoStack) Position() int

Returns the current position in the UndoStack.

func (*UndoStack) Redo

func (us *UndoStack) Redo(hard bool)

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

func (us *UndoStack) Undo(hard bool)

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

func (v *View) BeginEdit() *Edit

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) Classify

func (v *View) Classify(point int) (res int)

Classifies point, returning a bitwise OR of zero or more of defined flags

func (*View) Close

func (v *View) Close() bool

Initiate the "close" operation of this view. Returns "true" if the view was closed. Otherwise returns "false".

func (*View) CommandHistory

func (v *View) CommandHistory(idx int, modifying_only bool) (name string, args Args, count int)

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) EndEdit

func (v *View) EndEdit(edit *Edit)

Ends the given Edit object.

func (*View) Erase

func (v *View) Erase(edit *Edit, r Region)

Adds an Erase action of the given Region to the provided Edit object.

func (*View) EraseRegions

func (v *View) EraseRegions(key string)

Removes the Regions associated with the given key from the view.

func (*View) EraseStatus

func (v *View) EraseStatus(key string)

func (*View) Erased

func (v *View) Erased(changed_buffer Buffer, region_removed Region, data_removed []rune)

func (*View) ExpandByClass

func (v *View) ExpandByClass(r Region, classes int) Region

Expands the selection until the point on each side matches the given classes

func (*View) ExtractScope

func (v *View) ExtractScope(point int) Region

Returns the Region of the innermost scope that contains "point". See package lime-backend/lib/parser for details.

func (*View) FileChanged

func (v *View) FileChanged(filename string)

func (*View) Find

func (v *View) Find(pat string, pos int, flags int) Region

func (*View) FindByClass

func (v *View) FindByClass(point int, forward bool, classes int) int

Finds the next location after point that matches the given classes Searches backward if forward is false

func (*View) GetRegions

func (v *View) GetRegions(key string) (ret []Region)

Returns the Regions associated with the given key.

func (*View) GetStatus

func (v *View) GetStatus(key string) string

func (*View) Insert

func (v *View) Insert(edit *Edit, point int, value string) int

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) Inserted

func (v *View) Inserted(changed_buffer Buffer, region_inserted Region, data_inserted []rune)

func (*View) IsDirty

func (v *View) IsDirty() bool

Returns whether the underlying Buffer has any unsaved modifications. Note that Scratch buffers are never considered dirty.

func (*View) IsScratch

func (v *View) IsScratch() bool

Checks the scratch property of the view. TODO(.): Couldn't this just be a value in the View's Settings?

func (*View) OverwriteStatus

func (v *View) OverwriteStatus() bool

Sets the overwrite status property of the view. TODO(.): Couldn't this just be a value in the View's Settings?

func (*View) Replace

func (v *View) Replace(edit *Edit, r Region, value string)

Adds a Replace action of the given Region to the provided Edit object.

func (*View) Save

func (v *View) Save() error

Saves the file

func (*View) SaveAs

func (v *View) SaveAs(name string) (err error)

Saves the file to the specified filename

func (*View) ScopeName

func (v *View) ScopeName(point int) string

Returns the full concatenated nested scope name at point. See package lime-backend/lib/parser for details.

func (*View) ScoreSelector

func (v *View) ScoreSelector(point int, selector string) int

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

func (v *View) SetOverwriteStatus(s bool)

Checks the overwrite status property of the view. TODO(.): Couldn't this just be a value in the View's Settings?

func (*View) SetScratch

func (v *View) SetScratch(s bool)

Sets the scratch property of the view. TODO(.): Couldn't this just be a value in the View's Settings?

func (*View) SetStatus

func (v *View) SetStatus(key string, val string)

func (*View) SetSyntaxFile

func (v *View) SetSyntaxFile(file string)

func (*View) Status

func (v *View) Status() map[string]string

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.

func (*View) UndoStack

func (v *View) UndoStack() *UndoStack

Returns the UndoStack of this view. Tread lightly.

func (*View) Window

func (v *View) Window() *Window

Returns the window this View belongs to.

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?

func (*ViewEvent) Call

func (ve *ViewEvent) Call(v *View)

Trigger this ViewEvent by calling all the registered callbacks in order of registration.

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 (w *Window) ActiveView() *View

func (*Window) Close

func (w *Window) Close() bool

Closes the Window and all its Views. Returns "true" if the Window closed successfully. Otherwise returns "false".

func (*Window) CloseAllViews

func (w *Window) CloseAllViews() bool

Closes all of the Window's Views. Returns "true" if all the Views closed successfully. Otherwise returns "false".

func (*Window) NewFile

func (w *Window) NewFile() *View

func (*Window) OpenFile

func (w *Window) OpenFile(filename string, flags int) *View

func (*Window) SetActiveView

func (w *Window) SetActiveView(v *View)

func (*Window) Views

func (w *Window) Views() []*View

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.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL