Documentation ¶
Index ¶
- Variables
- func FindNext(m Movable, re *regexp.Regexp, from geom.Vec2, isForward bool) (to emu.ScreenLine, ok bool)
- func Jump(m Movable, needle string, isForward bool, isTo bool)
- type Incremental
- func (i *Incremental) Accept()
- func (i *Incremental) Cancel(m Movable)
- func (i *Incremental) Highlight() (line emu.ScreenLine, ok bool)
- func (i *Incremental) IsActive() bool
- func (i *Incremental) IsForward() bool
- func (i *Incremental) Next(m Movable, isForward bool)
- func (i *Incremental) Pattern(m Movable, input string)
- func (i *Incremental) Start(m Movable, isForward bool)
- type LineReader
- type Motion
- type Movable
Constants ¶
This section is empty.
Variables ¶
var EndOfLine = lineMotion(func(line emu.Line) int { return len(line) - 1 })
EndOfLine corresponds to vim's "$".
var EndOfScreenLine = screenLineMotion(func(width int, line emu.ScreenLine) int {
return line.C1 - 1
})
EndOfScreenLine corresponds to vim's `g$`.
var FirstNonBlank = lineMotion(func(line emu.Line) int {
first, _ := line.Whitespace()
return first
})
FirstNonBlank corresponds to vim's "^".
var FirstNonBlankScreen = screenLineMotion(func(width int, line emu.ScreenLine) int {
first, _ := line.Chars.Whitespace()
return line.C0 + first
})
FirstNonBlankScreen corresponds to vim's `g^`.
var LastNonBlank = lineMotion(func(line emu.Line) int {
_, last := line.Whitespace()
return last
})
LastNonBlank corresponds to vim's "g_".
var LastNonBlankScreen = screenLineMotion(func(width int, line emu.ScreenLine) int {
_, last := line.Chars.Whitespace()
return line.C0 + last
})
LastNonBlankScreen corresponds to vim's `g<end>`.
var MiddleOfLine = lineMotion(func(line emu.Line) int { return len(line) / 2 })
MiddleOfLine corresponds to vim's "gM".
var MiddleOfScreenLine = screenLineMotion(func(width int, line emu.ScreenLine) int {
return line.C0 + width/2
})
MiddleOfScreenLine corresponds to vim's `gm`.
var StartOfLine = lineMotion(func(line emu.Line) int {
return 0
})
StartOfLine corresponds to vim's "0".
var StartOfScreenLine = screenLineMotion(func(width int, line emu.ScreenLine) int {
return line.C0
})
StartOfScreenLine corresponds to vim's `g0`.
Functions ¶
func FindNext ¶
func FindNext( m Movable, re *regexp.Regexp, from geom.Vec2, isForward bool, ) (to emu.ScreenLine, ok bool)
FindNext gets the next match of a regex pattern in the given direction.
The origin of the search, `from`, is a coordinate in the reference frame of the Movable and determines where the search will start from. `from.C`, or the initial column of the search, has some special behavior in order to mimic the way vim's incremental search works.
When searching forwards, the cell specified by `from.C` will be _excluded_ from the search. This is to prevent the pattern from matching the current location. In addition, specifically when searching forwards, `from.C = -1` is considered to be valid; this means that no cell will be excluded from the search, which will start from the beginning of the line.
When searching backwards, matches must begin before the cell specified by `from`, but can end after or including `from`. Observe that vim works this way. Similarly, if `from.C` is equal to the length of the line, no cell will be excluded in the search.
Types ¶
type Incremental ¶
type Incremental struct {
// contains filtered or unexported fields
}
Incremental is a state machine that implements vim/emacs style incremental searching for a Movable.
func NewIncremental ¶
func NewIncremental() *Incremental
func (*Incremental) Accept ¶
func (i *Incremental) Accept()
Accept confirms the motion and stores the pattern. This is equivalent to pressing enter when searching incrementally in vim.
func (*Incremental) Cancel ¶
func (i *Incremental) Cancel(m Movable)
Cancel stops searching incrementally and returns to the origin.
func (*Incremental) Highlight ¶
func (i *Incremental) Highlight() (line emu.ScreenLine, ok bool)
func (*Incremental) IsActive ¶
func (i *Incremental) IsActive() bool
IsActive returns true if the user is currently entering a search pattern.
func (*Incremental) IsForward ¶
func (i *Incremental) IsForward() bool
IsForward returns true if the user is currently searching forward.
func (*Incremental) Next ¶
func (i *Incremental) Next(m Movable, isForward bool)
Next jumps to the next instance of the accepted pattern in the direction of the search. `isForward` is relative to the direction of the original search; if the original search was backwards, `isForward=true` means that the search will go backwards.
func (*Incremental) Pattern ¶
func (i *Incremental) Pattern(m Movable, input string)
Pattern takes a new pattern and jumps to the closest instance of it after the origin in the direction of the search.
func (*Incremental) Start ¶
func (i *Incremental) Start(m Movable, isForward bool)
Start initializes the incremental search by saving the original cursor location and direction.
type LineReader ¶
type LineReader struct {
// contains filtered or unexported fields
}
An io.RuneReader that provides a sequence of runes corresponding to the cells in an emu.Line.