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 ¶
- func IsWhitespace(r rune) bool
- type Buffer
- func (buffer *Buffer) Align(rows map[int][]int) map[int][]int
- func (buffer *Buffer) Append(line ...Line)
- func (buffer *Buffer) BracketMatch(row, col, end_row int) (int, int, error)
- func (buffer *Buffer) DeepDup() Buffer
- func (buffer *Buffer) DeleteChars(count int, rows map[int][]int, indent ...int) map[int][]int
- func (buffer *Buffer) DeleteNewlines(rowsMap map[int][]int) map[int][]int
- func (buffer *Buffer) DeleteRow(row int)
- func (buffer *Buffer) Dup() Buffer
- func (buffer *Buffer) Equals(buffer2 *Buffer) bool
- func (buffer *Buffer) GetIndent() (string, bool)
- func (buffer *Buffer) GetRow(row int) Line
- func (buffer *Buffer) InclSlice(row1, row2 int) *Buffer
- func (buffer *Buffer) IndentByStr(str string, startRow, endRow int)
- func (buffer *Buffer) InsertAfter(row int, lines ...Line)
- func (buffer *Buffer) InsertChar(ch rune, rows map[int][]int) map[int][]int
- func (buffer *Buffer) InsertNewlines(rowMap map[int][]int) map[int][]int
- func (buffer *Buffer) InsertStr(str string, rows map[int][]int) map[int][]int
- func (buffer *Buffer) Justify(startRow, endRow, lineLen int, comStrs []string) error
- func (buffer *Buffer) Length() int
- func (buffer *Buffer) Lines() []Line
- func (buffer *Buffer) MergeRows(row int) error
- func (buffer *Buffer) ReplaceBuffer(newBuffer Buffer)
- func (buffer *Buffer) ReplaceLine(line Line, row int)
- func (buffer *Buffer) ReplaceLines(lines []Line, minRow, maxRow int)
- func (buffer *Buffer) ReplaceWord(searchTerm, replaceTerm string, row, col int)
- func (buffer *Buffer) RowLength(row int) int
- func (buffer *Buffer) RowSlice(row, startCol, endCol int) Line
- func (buffer *Buffer) Search(searchTerm string, cursor Cursor, loop bool) (int, int, error)
- func (buffer *Buffer) SetRow(row int, line Line) error
- func (buffer *Buffer) StrSlab(row1, row2, col1, col2, tabwidth int) []string
- func (buffer *Buffer) ToString(newline string) string
- func (buffer *Buffer) Unalign(rows map[int][]int) map[int][]int
- type Cursor
- type Line
- func (line *Line) BracketMatch(start, end rune, idx, dir, count int) (int, int)
- func (line *Line) Chars() []rune
- func (line Line) CommonStart(other Line) Line
- func (line *Line) CompressPriorSpaces(cols []int) []int
- func (line *Line) DeleteBkwd(count int, cols ...int) []int
- func (line *Line) DeleteFwd(count int, cols ...int) []int
- func (line Line) Dup() Line
- func (line *Line) GetChar(k int) rune
- func (line *Line) InsertStr(str string, cols ...int) []int
- func (line Line) Length() int
- func (line *Line) PrevNextWord(col, incr int) int
- func (line *Line) RegexMatch(pattern string) (bool, error)
- func (line Line) RemoveLeadingWhitespace() Line
- func (line Line) RemoveTrailingWhitespace() Line
- func (line Line) Search(term string, start, end int) (int, int)
- func (line Line) SearchAll(term string, start, end int) []int
- func (line *Line) SetChar(k int, c rune) error
- func (line Line) Slice(startCol, endCol int) Line
- func (line Line) StrSlice(startCol, endCol int, tabwidth int) string
- func (line Line) TabCursorPos(col int, tabwidth int) int
- func (line Line) Tabs2spaces(tabwidth int) Line
- func (line Line) ToString() string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsWhitespace ¶ added in v0.4.2
Types ¶
type Buffer ¶
type Buffer struct {
// contains filtered or unexported fields
}
Buffer is an array of Line objects.
func MakeBuffer ¶
MakeBuffer takes in a slice os strings and creates a slice of Line objects.
func MakeSplitBuffer ¶
MakeSplitBuffer creates a buffer from a long string by splitting the string at a certain length.
func (*Buffer) BracketMatch ¶ added in v0.5.0
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) DeleteChars ¶ added in v0.6.0
DeleteChars deletes count characters at each position in the rows map.
func (*Buffer) DeleteNewlines ¶ added in v0.6.0
DeleteNewlines deletes the newline chars at the start of each row specified.
func (*Buffer) Dup ¶
Dup creates a new buffer with the same lines. The lines are shallow copies of the original lines.
func (*Buffer) Equals ¶
Equals returns true if the two buffers are: - the same length, and - each line has the same string serialization
func (*Buffer) GetIndent ¶
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) IndentByStr ¶ added in v0.7.0
insert the indentation string at the start of each line.
func (*Buffer) InsertAfter ¶
InsertAfter inserts a set of lines after the specified row in the buffer.
func (*Buffer) InsertChar ¶ added in v0.6.0
func (*Buffer) InsertNewlines ¶ added in v0.6.0
InsertNewlines splits lines at cursors.
func (*Buffer) InsertStr ¶ added in v0.6.0
InsertStr inserts the specified string into each position in the rows map.
func (*Buffer) Lines ¶
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) ReplaceBuffer ¶
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 ¶
ReplaceLine replaces the line at the specified row.
func (*Buffer) ReplaceLines ¶
ReplaceLines replaces the lines from minRow to maxRow with lines.
func (*Buffer) ReplaceWord ¶
Replace replaces occurrences of a string within a line.
func (*Buffer) Search ¶
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) StrSlab ¶
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.
type Line ¶
type Line struct {
// contains filtered or unexported fields
}
func (*Line) BracketMatch ¶ added in v0.5.0
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) CommonStart ¶
CommonStart returns the sub-line that is common between a set of lines.
func (*Line) CompressPriorSpaces ¶ added in v0.4.2
func (*Line) DeleteBkwd ¶ added in v0.6.0
DeleteBkwd deletes n characters starting at the cursor and going to the left.
func (*Line) DeleteFwd ¶ added in v0.6.0
DeleteFwd deletes n characters starting at the cursor and going to the right.
func (*Line) InsertStr ¶ added in v0.6.0
InsertStr inserts a string into a set of positions within a line. Return the new cursor positions.
func (*Line) PrevNextWord ¶ added in v0.4.3
PrevNextWord returns the column position of the next/previous word from the current column position.
func (*Line) RegexMatch ¶ added in v0.7.0
Check if a line matches a regex pattern.
func (Line) RemoveLeadingWhitespace ¶ added in v0.7.0
func (Line) RemoveTrailingWhitespace ¶
func (Line) Search ¶
Search returns the start/end positions for a search term. A -1 indicates no match.
func (Line) SearchAll ¶ added in v0.6.0
SearchAll returns a list of the start positions for search term matches.
func (Line) TabCursorPos ¶ added in v0.5.0
Expand tabs to spaces and return the cursor position.