buffer

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: May 14, 2018 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package buffer provides a single editable text buffer. The text is stored as a slice of Lines (split on line-endings). A Line is a wrapper around a slice of runes.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsWhitespace added in v0.4.2

func IsWhitespace(r rune) bool

Types

type Buffer

type Buffer struct {
	// contains filtered or unexported fields
}

Buffer is an array of Line objects.

func MakeBuffer

func MakeBuffer(stringBuf []string) Buffer

MakeBuffer takes in a slice os strings and creates a slice of Line objects.

func MakeSplitBuffer

func MakeSplitBuffer(bigString string, lineLen int) Buffer

MakeSplitBuffer creates a buffer from a long string by splitting the string at a certain length.

func (*Buffer) Align added in v0.6.0

func (buffer *Buffer) Align(rows map[int][]int) map[int][]int

Align inserts spaces into cursor positions to align them.

func (*Buffer) Append

func (buffer *Buffer) Append(line ...Line)

Append appends a new line on to the buffer.

func (*Buffer) BracketMatch added in v0.5.0

func (buffer *Buffer) BracketMatch(row, col, end_row int) (int, int, error)

BracketMatch looks for matching partner rune in a set of lines.

row, col         where to start the search from
end_row          last row to search

func (*Buffer) DeepDup

func (buffer *Buffer) DeepDup() Buffer

DeepDup creates a new buffer with copies of the lines.

func (*Buffer) DeleteChars added in v0.6.0

func (buffer *Buffer) DeleteChars(count int, rows map[int][]int, indent ...int) map[int][]int

DeleteChars deletes count characters at each position in the rows map.

func (*Buffer) DeleteNewlines added in v0.6.0

func (buffer *Buffer) DeleteNewlines(rowsMap map[int][]int) map[int][]int

DeleteNewlines deletes the newline chars at the start of each row specified.

func (*Buffer) DeleteRow

func (buffer *Buffer) DeleteRow(row int)

DeleteRow deletes the specified row from the buffer.

func (*Buffer) Dup

func (buffer *Buffer) Dup() Buffer

Dup creates a new buffer with the same lines. The lines are shallow copies of the original lines.

func (*Buffer) Equals

func (buffer *Buffer) Equals(buffer2 *Buffer) bool

Equals returns true if the two buffers are: - the same length, and - each line has the same string serialization

func (*Buffer) GetIndent

func (buffer *Buffer) GetIndent() (string, bool)

GetIndent estimates the indentation string of the buffer. It also returns a bool indicating that the indentation is clean (true) or mixed (false).

func (*Buffer) GetRow

func (buffer *Buffer) GetRow(row int) Line

GetRow returns the Line at the specified row index.

func (*Buffer) InclSlice

func (buffer *Buffer) InclSlice(row1, row2 int) *Buffer

InclSlice returns a slice of the buffer, inclusive of the endpoints.

func (*Buffer) IndentByStr added in v0.7.0

func (buffer *Buffer) IndentByStr(str string, startRow, endRow int)

insert the indentation string at the start of each line.

func (*Buffer) InsertAfter

func (buffer *Buffer) InsertAfter(row int, lines ...Line)

InsertAfter inserts a set of lines after the specified row in the buffer.

func (*Buffer) InsertChar added in v0.6.0

func (buffer *Buffer) InsertChar(ch rune, rows map[int][]int) map[int][]int

func (*Buffer) InsertNewlines added in v0.6.0

func (buffer *Buffer) InsertNewlines(rowMap map[int][]int) map[int][]int

InsertNewlines splits lines at cursors.

func (*Buffer) InsertStr added in v0.6.0

func (buffer *Buffer) InsertStr(str string, rows map[int][]int) map[int][]int

InsertStr inserts the specified string into each position in the rows map.

func (*Buffer) Justify added in v0.7.0

func (buffer *Buffer) Justify(startRow, endRow, lineLen int, comStrs []string) error

func (*Buffer) Length

func (buffer *Buffer) Length() int

Length returns the number of lines in the buffer.

func (*Buffer) Lines

func (buffer *Buffer) Lines() []Line

Lines returns the slice of lines that the buffer contains. The slice is a "deep copy" of the buffer's internal Line slice.

func (*Buffer) MergeRows added in v0.6.0

func (buffer *Buffer) MergeRows(row int) error

MergeRows merges the current row into the previous.

func (*Buffer) ReplaceBuffer

func (buffer *Buffer) ReplaceBuffer(newBuffer Buffer)

ReplaceBuffer replaces the content (lines) with the content from another buffer. If the buffer got shorter, then just copy over the lines. Otherwise, check each line for equality, and only replace if changed.

func (*Buffer) ReplaceLine

func (buffer *Buffer) ReplaceLine(line Line, row int)

ReplaceLine replaces the line at the specified row.

func (*Buffer) ReplaceLines

func (buffer *Buffer) ReplaceLines(lines []Line, minRow, maxRow int)

ReplaceLines replaces the lines from minRow to maxRow with lines.

func (*Buffer) ReplaceWord

func (buffer *Buffer) ReplaceWord(searchTerm, replaceTerm string, row, col int)

Replace replaces occurrences of a string within a line.

func (*Buffer) RowLength

func (buffer *Buffer) RowLength(row int) int

RowLength returns the length of the given row.

func (*Buffer) RowSlice

func (buffer *Buffer) RowSlice(row, startCol, endCol int) Line

RowSlice returns a Line containing a subset of the line at 'row'.

func (*Buffer) Search

func (buffer *Buffer) Search(searchTerm string, cursor Cursor, loop bool) (int, int, error)

Search searches for a string within the buffer. The 'loop' toggle says to loop around to the start of the file when searching.

func (*Buffer) SetRow

func (buffer *Buffer) SetRow(row int, line Line) error

SetRow replaces the line at the specified row index.

func (*Buffer) StrSlab

func (buffer *Buffer) StrSlab(row1, row2, col1, col2, tabwidth int) []string

StrSlab returns a slice of strings corresponding to a "slab" of text which is an offset subset of the buffer. Specify the start and end rows, and start and end columns. Also specify the tab width, because all tabs are converted to spaces.

func (*Buffer) ToCorpus added in v0.7.0

func (buffer *Buffer) ToCorpus(row, col int) string

ToCorpus concatenates the buffer into one long string. Specify the row col of the cursor to remove the current token. Used for autocomplete.

func (*Buffer) ToString

func (buffer *Buffer) ToString(newline string) string

ToString concatenates the buffer into one long string. Specify the newline character to insert between Lines.

func (*Buffer) Unalign added in v0.6.0

func (buffer *Buffer) Unalign(rows map[int][]int) map[int][]int

Unalign removes redundant whitespace preceding each cursor..

type Cursor added in v0.6.2

type Cursor interface {
	Row() int
	Col() int
}

Cursor is any object which returns a row/col position.

type Line

type Line struct {
	// contains filtered or unexported fields
}

func MakeLine

func MakeLine(str string) Line

func (*Line) BracketMatch added in v0.5.0

func (line *Line) BracketMatch(start, end rune, idx, dir, count int) (int, int)

BracketMatch looks for matching partner rune in a line.

start, end       pair of runes, such as '(' and ')'
idx              where to start the search from
dir              1 or -1
count            current level of bracketing (for continuation lines)

Returns (idx, count); count == 0 means the closing bracket has been found.

func (*Line) Chars

func (line *Line) Chars() []rune

func (Line) CommonStart

func (line Line) CommonStart(other Line) Line

CommonStart returns the sub-line that is common between a set of lines.

func (*Line) CompressPriorSpaces added in v0.4.2

func (line *Line) CompressPriorSpaces(cols []int) []int

func (*Line) DeleteBkwd added in v0.6.0

func (line *Line) DeleteBkwd(count int, cols ...int) []int

DeleteBkwd deletes n characters starting at the cursor and going to the left.

func (*Line) DeleteFwd added in v0.6.0

func (line *Line) DeleteFwd(count int, cols ...int) []int

DeleteFwd deletes n characters starting at the cursor and going to the right.

func (Line) Dup

func (line Line) Dup() Line

Dup returns a new Line with the same content.

func (*Line) GetChar

func (line *Line) GetChar(k int) rune

func (*Line) InsertStr added in v0.6.0

func (line *Line) InsertStr(str string, cols ...int) []int

InsertStr inserts a string into a set of positions within a line. Return the new cursor positions.

func (Line) Length

func (line Line) Length() int

func (*Line) PrevNextWord added in v0.4.3

func (line *Line) PrevNextWord(col, incr int) int

PrevNextWord returns the column position of the next/previous word from the current column position.

func (*Line) RegexMatch added in v0.7.0

func (line *Line) RegexMatch(pattern string) (bool, error)

Check if a line matches a regex pattern.

func (Line) RemoveLeadingWhitespace added in v0.7.0

func (line Line) RemoveLeadingWhitespace() Line

func (Line) RemoveTrailingWhitespace

func (line Line) RemoveTrailingWhitespace() Line

func (Line) Search

func (line Line) Search(term string, start, end int) (int, int)

Search returns the start/end positions for a search term. A -1 indicates no match.

func (Line) SearchAll added in v0.6.0

func (line Line) SearchAll(term string, start, end int) []int

SearchAll returns a list of the start positions for search term matches.

func (*Line) SetChar

func (line *Line) SetChar(k int, c rune) error

func (Line) Slice

func (line Line) Slice(startCol, endCol int) Line

func (Line) StrSlice

func (line Line) StrSlice(startCol, endCol int, tabwidth int) string

func (Line) TabCursorPos added in v0.5.0

func (line Line) TabCursorPos(col int, tabwidth int) int

Expand tabs to spaces and return the cursor position.

func (Line) Tabs2spaces

func (line Line) Tabs2spaces(tabwidth int) Line

func (Line) ToCorpus added in v0.7.0

func (line Line) ToCorpus(col int) string

ToCorpus converts a Line into a string without the current token..

func (Line) ToString

func (line Line) ToString() string

ToString converts a Line into a string.

Jump to

Keyboard shortcuts

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