Documentation
¶
Overview ¶
Package command implements vi/ex-style command parsing and execution.
Command format: :{range}{command}{flags} Supported commands:
:q Quit
:q! Force quit (no save)
:w Save
:wq Save and quit
:w {path} Save as
:e {path} Open file
:10,20d Delete lines 10-20
:%s/old/new/g Replace all
:3,5s/old/new Replace in range
:set nu Show line numbers (etc.)
Design: Uses a recursive descent parser that walks each token of the command string, builds a Command struct, then executes it via the Executor on the Document.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CmdKind ¶
type CmdKind int
CmdKind is the command type enumeration.
const ( CmdNone CmdKind = iota CmdDelete // d - delete lines CmdSubstitute // s - substitute CmdWrite // w - write CmdQuit // q - quit CmdWriteQuit // wq - write and quit CmdForceQuit // q! - force quit CmdEdit // e - edit file CmdSet // set - set option CmdGoto // goto line (e.g. :42) CmdUninstall // uninstall - remove editor and config )
type Command ¶
type Command struct {
Kind CmdKind // Command type
Range Range // Line range
Args []string // Command arguments
SubOld string // s command match pattern
SubNew string // s command replacement text
SubFlg string // s command flags (g global, i ignore case)
SetOpt *SetOption // set command option
Force bool // Force flag (!)
}
Command represents a parsed command.
func Parse ¶
Parse parses a command string (e.g. "10,20d", "%%s/old/new/g", "wq!"), returning a Command. Input should not include the leading colon.
func (*Command) CompileRegex ¶
CompileRegex compiles the substitution pattern regex (handles ignoreCase flag).
func (*Command) MakeGlobal ¶
MakeGlobal returns whether the substitution is global (g flag).
type Executor ¶
type Executor struct {
DeleteRange func(startLine, endLine int) (string, error)
GetLineText func(line int) string
SetOption func(name, value string) error
OpenFile func(path string) error
WriteFile func(path string) error
Quit func(force bool) error
ShowMsg func(msg string)
ReplaceText func(oldPattern, newText string, startLine, endLine int, global, ignoreCase bool) (int, error)
GetLineCount func() int
GotoLine func(line int) error
Uninstall func() error
}
Executor executes commands on the document. To avoid circular dependency (command depending on document), Executor uses callback functions for operations.
type ParseError ¶
type ParseError struct {
Msg string
}
ParseError represents a command parsing error.
func (*ParseError) Error ¶
func (e *ParseError) Error() string