package core type BufferOptions struct { // tabstop expandtab } type Buffer struct { // Buffer data Id int // File data Filename string Filetype string Lines []string // Flags (not used yet) Modified bool Loaded bool Listed bool // Options BufferOptions // UndoTree TODO: This will be big } // ================================================== // Helper methods // ================================================== // Buffer.Line: Get the line at an index. Returns an empty string if the index // is out of bounds. func (b *Buffer) Line(idx int) string { if idx < 0 || idx >= len(b.Lines) { return "" } return b.Lines[idx] } // Buffer.SetLine: Set the content of the line at an index. Does nothing if the // index is out of bounds. func (b *Buffer) SetLine(idx int, content string) { if idx >= 0 && idx < len(b.Lines) { b.Lines[idx] = content } } // Buffer.InsertLine: Insert a line with content at an index. The index is clamped // to valid bounds (0 to len(Lines)). The new line is inserted before the line at // the given index. func (b *Buffer) InsertLine(idx int, content string) { if idx < 0 { idx = 0 } if idx > len(b.Lines) { idx = len(b.Lines) } b.Lines = append(b.Lines[:idx], append([]string{content}, b.Lines[idx:]...)...) } // Buffer.DeleteLine: Delete a line at an index. Does nothing if the index is out // of bounds. func (b *Buffer) DeleteLine(idx int) { if idx >= 0 && idx < len(b.Lines) { b.Lines = append(b.Lines[:idx], b.Lines[idx+1:]...) } } // Buffer.LineCount: Get the number of lines in the buffer. func (b *Buffer) LineCount() int { return len(b.Lines) } // ================================================== // Setters // ================================================== // Buffer.SetFilename: Set the filename associated with this buffer. This is // typically the path to the file on disk that this buffer represents. func (b *Buffer) SetFilename(filename string) { b.Filename = filename } // Buffer.SetFiletype: Set the filetype of this buffer. The filetype is used // for syntax highlighting and other language-specific features. func (b *Buffer) SetFiletype(filetype string) { b.Filetype = filetype } // Buffer.SetLines: Replace all lines in the buffer with the provided lines. // This is useful when loading a file or resetting buffer content. func (b *Buffer) SetLines(lines []string) { b.Lines = lines } // Buffer.SetModified: Set the modified flag for this buffer. A modified buffer // has unsaved changes that differ from the file on disk. func (b *Buffer) SetModified(modified bool) { b.Modified = modified } // Buffer.SetLoaded: Set the loaded flag for this buffer. A loaded buffer has // its content in memory, while an unloaded buffer exists only as metadata. func (b *Buffer) SetLoaded(loaded bool) { b.Loaded = loaded } // Buffer.SetListed: Set the listed flag for this buffer. A listed buffer appears // in buffer lists (like :ls), while an unlisted buffer is hidden from normal // buffer navigation. func (b *Buffer) SetListed(listed bool) { b.Listed = listed }