Documentation
¶
Overview ¶
Package buffer holds the editable text and cursor for a single file.
The buffer is intentionally simple (a slice of rune-lines) so the interesting parts — command dispatch, keymaps and the out-of-process plugin protocol — stay readable. Every mutating operation bumps Version; plugin edits carry the version they were computed against so the core can reject stale writes (the same document-versioning idea LSP uses).
Index ¶
- type Buffer
- func (b *Buffer) AppendLine(s string)
- func (b *Buffer) BeginningOfBuffer()
- func (b *Buffer) BeginningOfLine()
- func (b *Buffer) ClearMark()
- func (b *Buffer) DeleteBackward()
- func (b *Buffer) DeleteForward()
- func (b *Buffer) DeleteRange(from, to Point) string
- func (b *Buffer) Dirty() bool
- func (b *Buffer) EOL() string
- func (b *Buffer) EndOfBuffer()
- func (b *Buffer) EndOfLine()
- func (b *Buffer) ExchangePointAndMark()
- func (b *Buffer) Insert(s string)
- func (b *Buffer) KillLine() string
- func (b *Buffer) Line(i int) []rune
- func (b *Buffer) LineCount() int
- func (b *Buffer) MarkActive() bool
- func (b *Buffer) MovePoint(dl, dc int)
- func (b *Buffer) Name() string
- func (b *Buffer) OffsetToPoint(off int) Point
- func (b *Buffer) Path() string
- func (b *Buffer) Point() Point
- func (b *Buffer) PointToOffset(p Point) int
- func (b *Buffer) Region() (from, to Point, ok bool)
- func (b *Buffer) Replace(from, to Point, s string)
- func (b *Buffer) ReplaceRange(base int, from, to Point, s string) bool
- func (b *Buffer) Restore(s Snapshot)
- func (b *Buffer) Revert(path string) error
- func (b *Buffer) Save() error
- func (b *Buffer) SetEOL(eol string)
- func (b *Buffer) SetLine(i int, s string)
- func (b *Buffer) SetMark()
- func (b *Buffer) SetPath(path string)
- func (b *Buffer) SetPoint(p Point)
- func (b *Buffer) SetText(s string)
- func (b *Buffer) Snapshot() Snapshot
- func (b *Buffer) Text() string
- func (b *Buffer) TextIfWithin(limit int) (string, bool)
- func (b *Buffer) TextInRange(from, to Point) string
- func (b *Buffer) TrimTrailingWhitespace(from, to int) int
- func (b *Buffer) Version() int
- type Point
- type Snapshot
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Buffer ¶
type Buffer struct {
// contains filtered or unexported fields
}
Buffer is one open file's text plus a cursor.
func (*Buffer) AppendLine ¶
AppendLine appends s (which may contain newlines) as new line(s) at the end of the buffer. Used for the *messages* log.
func (*Buffer) BeginningOfBuffer ¶
func (b *Buffer) BeginningOfBuffer()
BeginningOfBuffer moves point to the very start.
func (*Buffer) BeginningOfLine ¶
func (b *Buffer) BeginningOfLine()
BeginningOfLine moves the cursor to column 0 (C-a).
func (*Buffer) DeleteBackward ¶
func (b *Buffer) DeleteBackward()
DeleteBackward removes the rune before the cursor (backspace).
func (*Buffer) DeleteForward ¶
func (b *Buffer) DeleteForward()
DeleteForward removes the rune under the cursor (C-d).
func (*Buffer) DeleteRange ¶
DeleteRange removes the text between two (unordered) points, leaves point at the start, and returns what was removed.
func (*Buffer) EndOfBuffer ¶
func (b *Buffer) EndOfBuffer()
EndOfBuffer moves point to the very end.
func (*Buffer) EndOfLine ¶
func (b *Buffer) EndOfLine()
EndOfLine moves the cursor to end of the current line (C-e).
func (*Buffer) ExchangePointAndMark ¶
func (b *Buffer) ExchangePointAndMark()
ExchangePointAndMark swaps point and mark (Emacs C-x C-x).
func (*Buffer) KillLine ¶
KillLine deletes from the cursor to end of line (or joins the next line if already at end), returning the killed text (C-k).
func (*Buffer) MarkActive ¶
MarkActive reports whether a region is active.
func (*Buffer) MovePoint ¶
MovePoint shifts the cursor by dl lines and dc columns, clamping to bounds.
func (*Buffer) OffsetToPoint ¶
OffsetToPoint converts a whole-buffer rune offset back to a point.
func (*Buffer) PointToOffset ¶
PointToOffset returns the rune offset of a point into the whole buffer text.
func (*Buffer) Region ¶
Region returns the active region as an ordered [from,to] pair; ok is false when no mark is set.
func (*Buffer) Replace ¶
Replace replaces the text between two (unordered) points with s, leaving point at the start. It is used to apply LSP text edits.
func (*Buffer) ReplaceRange ¶
ReplaceRange is used by plugins: it replaces the text between two points with s, but only if base matches the current version. It returns false on a stale edit so the plugin can re-read and retry.
func (*Buffer) Revert ¶
Revert reloads the buffer from path, keeping point (clamped) and marking the buffer unmodified. Used for auto-revert when the file changed on disk.
func (*Buffer) SetEOL ¶
SetEOL sets the line ending used on save and marks the buffer modified so the change is written out. The in-memory text stays LF-normalized.
func (*Buffer) SetMark ¶
func (b *Buffer) SetMark()
SetMark plants the mark at point and activates the region.
func (*Buffer) SetText ¶
SetText replaces the whole buffer content and moves point to the start. Used for generated/results buffers.
func (*Buffer) TextIfWithin ¶
TextIfWithin returns the whole buffer text and true when it holds at most limit runes. For a larger buffer it returns ("", false) after a bounded scan (it never builds the string), so callers such as syntax highlighting can skip expensive whole-buffer work on very large files cheaply.
func (*Buffer) TextInRange ¶
TextInRange returns the text between two (unordered) points.
func (*Buffer) TrimTrailingWhitespace ¶
TrimTrailingWhitespace removes trailing spaces/tabs from each line in the inclusive range [from,to] and returns how many lines changed.