sam

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2022 License: BSD-3-Clause, MIT Imports: 3 Imported by: 2

Documentation

Index

Constants

View Source
const (
	DeleteType ElogType = iota
	InsertType
	FilenameType
	Wsequence     = "warning: changes out of sequence"
	WsequenceDire = "warning: changes out of sequence, edit result probably wrong"
	Delete        = 'd'
	Insert        = 'i'
	Filename      = 'f'
	Null          = '-'
	Replace       = 'r'
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Elog

type Elog struct {
	Log []ElogOperation
	// contains filtered or unexported fields
}

Elog is a log of changes made by editing commands. Three reasons for this: 1) We want addresses in commands to apply to old file, not file-in-change. 2) It's difficult to track changes correctly as things move, e.g. ,x m$ 3) This gives an opportunity to optimize by merging adjacent changes. It's a little bit like the Undo/Redo log in Files, but Point 3) argues for a separate implementation. To do this well, we use Replace as well as Insert and Delete

There is a significant assumption that the log has increasing q0s. The log is then played back backwards to apply the changes to the text. Out-of-order edits are warned about.

func MakeElog

func MakeElog() Elog

func (*Elog) Apply

func (e *Elog) Apply(t Texter)

Apply plays back the log, from back to front onto the given text. Unlike the C version, this does not mark the file - that should happen at a higher level.

func (*Elog) Delete

func (e *Elog) Delete(q0, q1 int) error

func (*Elog) Empty

func (e *Elog) Empty() bool

func (*Elog) Insert

func (e *Elog) Insert(q0 int, r []rune) error

func (*Elog) Replace

func (e *Elog) Replace(q0, q1 int, r []rune) error

func (*Elog) Reset

func (e *Elog) Reset()

func (*Elog) Term

func (e *Elog) Term()

type ElogOperation

type ElogOperation struct {
	T ElogType // Delete, Insert, Filename
	// contains filtered or unexported fields
}

type ElogType

type ElogType byte

type TextBuffer

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

TextBuffer implements Texter around a buffer.

func NewTextBuffer

func NewTextBuffer(q0 int, q1 int, buf []rune) *TextBuffer

NewTextBuffer is a constructor for texter.TextBuffer.

func (TextBuffer) Constrain

func (t TextBuffer) Constrain(q0, q1 int) (p0, p1 int)

func (*TextBuffer) Delete

func (t *TextBuffer) Delete(q0, q1 int, tofile bool)

func (*TextBuffer) Insert

func (t *TextBuffer) Insert(q0 int, r []rune, tofile bool)

func (*TextBuffer) Nc

func (t *TextBuffer) Nc() int

func (*TextBuffer) Q0

func (t *TextBuffer) Q0() int

func (*TextBuffer) Q1

func (t *TextBuffer) Q1() int

func (*TextBuffer) ReadB

func (t *TextBuffer) ReadB(q int, r []rune) (n int, err error)

func (*TextBuffer) ReadC

func (t *TextBuffer) ReadC(q int) rune

func (*TextBuffer) SetQ0

func (t *TextBuffer) SetQ0(q0 int)

func (*TextBuffer) SetQ1

func (t *TextBuffer) SetQ1(q1 int)

type Texter

type Texter interface {
	Constrain(q0, q1 int) (p0, p1 int)
	Delete(q0, q1 int, tofile bool)
	Insert(q0 int, r []rune, tofile bool)
	Q0() int // Selection start
	SetQ0(int)
	Q1() int // End of selelection
	SetQ1(int)
	// TODO(rjk): Please call this Nr().
	Nc() int
	// TODO(rjk): Rename this to Read
	ReadB(q int, r []rune) (n int, err error)
	ReadC(q int) rune
}

Texter abstracts the buffering side of Text, allowing testing of Elog Apply TODO(flux): This is probably lame and will get re-done when I understand how Text stores its text. TODO(rjk): Make this into a streaming interface.

Jump to

Keyboard shortcuts

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