text

package
v0.3.5 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2024 License: BSD-3-Clause Imports: 25 Imported by: 1

Documentation

Index

Constants

View Source
const (
	// ReplaceMatchCase is used for MatchCase arg in ReplaceText method
	ReplaceMatchCase = true

	// ReplaceNoMatchCase is used for MatchCase arg in ReplaceText method
	ReplaceNoMatchCase = false
)
View Source
const (
	// IgnoreCase is passed to search functions to indicate case should be ignored
	IgnoreCase = true

	// UseCase is passed to search functions to indicate case is relevant
	UseCase = false
)

Variables

View Source
var SearchContext = 30

SearchContext is how much text to include on either side of the search match

View Source
var UndoGroupDelay = 250 * time.Millisecond

UndoGroupDelay is the amount of time above which a new group is started, for grouping undo events

View Source
var UndoTrace = false

UndoTrace; set to true to get a report of undo actions

Functions

func ApplyOneDiff

func ApplyOneDiff(op difflib.OpCode, bedit *[]string, aorig []string, blmap []int)

ApplyOneDiff applies given diff operator to given "B" lines using original "A" lines and given b line map

func BytesToLineStrings

func BytesToLineStrings(txt []byte, addNewLn bool) []string

BytesToLineStrings returns []string lines from []byte input. If addNewLn is true, each string line has a \n appended at end.

func CountWordsLines

func CountWordsLines(reader io.Reader) (words, lines int)

CountWordsLines counts the number of words (aka Fields, space-separated strings) and lines given io.Reader input

func CountWordsLinesRegion

func CountWordsLinesRegion(src [][]rune, reg Region) (words, lines int)

CountWordsLinesRegion counts the number of words (aka Fields, space-separated strings) and lines in given region of source (lines = 1 + End.Ln - Start.Ln)

func DiffLinesUnified

func DiffLinesUnified(astr, bstr []string, context int, afile, adate, bfile, bdate string) []byte

DiffLinesUnified computes the diff between two string arrays (one string per line), returning a unified diff with given amount of context (default of 3 will be used if -1), with given file names and modification dates.

func DiffOpReverse

func DiffOpReverse(op difflib.OpCode) difflib.OpCode

func DiffOpString

func DiffOpString(op difflib.OpCode) string

func FileBytes

func FileBytes(fpath string) ([]byte, error)

FileBytes returns the bytes of given file.

func FileRegionBytes

func FileRegionBytes(fpath string, stLn, edLn int, preComments bool, lnBack int) []byte

FileRegionBytes returns the bytes of given file within given start / end lines, either of which might be 0 (in which case full file is returned). If preComments is true, it also automatically includes any comments that might exist just prior to the start line if stLn is > 0, going back a maximum of lnBack lines.

func KnownComments

func KnownComments(fpath string) (comLn, comSt, comEd string)

KnownComments returns the comment strings for supported file types, and returns the standard C-style comments otherwise.

func PreCommentStart

func PreCommentStart(lns [][]byte, stLn int, comLn, comSt, comEd string, lnBack int) int

PreCommentStart returns the starting line for comment line(s) that just precede the given stLn line number within the given lines of bytes, using the given line-level and block start / end comment chars. returns stLn if nothing found. Only looks back a total of lnBack lines.

func StringLinesToByteLines

func StringLinesToByteLines(str []string) [][]byte

StringLinesToByteLines returns [][]byte lines from []string lines

Types

type AdjustPosDel

type AdjustPosDel int

AdjustPosDel determines what to do with positions within deleted region

const (
	// AdjustPosDelErr means return a PosErr when in deleted region
	AdjustPosDelErr AdjustPosDel = iota

	// AdjustPosDelStart means return start of deleted region
	AdjustPosDelStart

	// AdjustPosDelEnd means return end of deleted region
	AdjustPosDelEnd
)

these are options for what to do with positions within deleted region for the AdjustPos function

type DiffSelectData

type DiffSelectData struct {
	// original text
	Orig []string

	// edits applied
	Edit []string

	// mapping of original line numbers (index) to edited line numbers,
	// accounting for the edits applied so far
	LineMap []int

	// Undos: stack of diffs applied
	Undos Diffs

	// undo records
	EditUndo [][]string

	// undo records for ALineMap
	LineMapUndo [][]int
}

DiffSelectData contains data for one set of text

func (*DiffSelectData) SaveUndo

func (ds *DiffSelectData) SaveUndo(op difflib.OpCode)

func (*DiffSelectData) SetStringLines

func (ds *DiffSelectData) SetStringLines(s []string)

SetStringLines sets the data from given lines of strings The Orig is set directly and Edit is cloned if the input will be modified during the processing, call slices.Clone first

func (*DiffSelectData) Undo

func (ds *DiffSelectData) Undo() bool

type DiffSelected

type DiffSelected struct {
	A DiffSelectData
	B DiffSelectData

	// Diffs are the diffs between A and B
	Diffs Diffs
}

DiffSelected supports the incremental application of selected diffs between two files (either A -> B or B <- A), with Undo

func NewDiffSelected

func NewDiffSelected(astr, bstr []string) *DiffSelected

func (*DiffSelected) AtoB

func (ds *DiffSelected) AtoB(idx int)

AtoB applies given diff index from A to B

func (*DiffSelected) BtoA

func (ds *DiffSelected) BtoA(idx int)

BtoA applies given diff index from B to A

func (*DiffSelected) SetStringLines

func (ds *DiffSelected) SetStringLines(astr, bstr []string)

SetStringLines sets the data from given lines of strings

type Diffs

type Diffs []difflib.OpCode

Diffs are raw differences between text, in terms of lines, reporting a sequence of operations that would convert one buffer (a) into the other buffer (b). Each operation is either an 'r' (replace), 'd' (delete), 'i' (insert) or 'e' (equal).

func DiffLines

func DiffLines(astr, bstr []string) Diffs

DiffLines computes the diff between two string arrays (one string per line), reporting a sequence of operations that would convert buffer a into buffer b. Each operation is either an 'r' (replace), 'd' (delete), 'i' (insert) or 'e' (equal). Everything is line-based (0, offset).

func (Diffs) DiffForLine

func (di Diffs) DiffForLine(line int) (int, difflib.OpCode)

func (Diffs) Reverse

func (di Diffs) Reverse() Diffs

Reverse returns the reverse-direction diffs, switching a vs. b

func (Diffs) String

func (di Diffs) String() string

String satisfies the Stringer interface

func (Diffs) ToPatch

func (dif Diffs) ToPatch(bstr []string) Patch

ToPatch creates a Patch list from given Diffs output from DiffLines and the b strings from which the needed lines of source are copied. ApplyPatch with this on the a strings will result in the b strings. The resulting Patch is independent of bstr slice.

type Edit

type Edit struct {

	// region for the edit (start is same for previous and current, end is in original pre-delete text for a delete, and in new lines data for an insert.  Also contains the Time stamp for this edit.
	Reg Region

	// text deleted or inserted -- in lines.  For Rect this is just for the spanning character distance per line, times number of lines.
	Text [][]rune

	// optional grouping number, for grouping edits in Undo for example
	Group int

	// action is either a deletion or an insertion
	Delete bool

	// this is a rectangular region with upper left corner = Reg.Start and lower right corner = Reg.End -- otherwise it is for the full continuous region.
	Rect bool
}

Edit describes an edit action to a buffer -- this is the data passed via signals to viewers of the buffer. Actions are only deletions and insertions (a change is a sequence of those, given normal editing processes). The textview.Buf always reflects the current state *after* the edit.

func (*Edit) AdjustPos

func (te *Edit) AdjustPos(pos lexer.Pos, del AdjustPosDel) lexer.Pos

AdjustPos adjusts the given text position as a function of the edit. if the position was within a deleted region of text, del determines what is returned

func (*Edit) AdjustPosIfAfterTime

func (te *Edit) AdjustPosIfAfterTime(pos lexer.Pos, t time.Time, del AdjustPosDel) lexer.Pos

AdjustPosIfAfterTime checks the time stamp and IfAfterTime, it adjusts the given text position as a function of the edit del determines what to do with positions within a deleted region either move to start or end of the region, or return an error.

func (*Edit) AdjustReg

func (te *Edit) AdjustReg(reg Region) Region

AdjustReg adjusts the given text region as a function of the edit, including checking that the timestamp on the region is after the edit time, if the region has a valid Time stamp (otherwise always does adjustment). If the starting position is within a deleted region, it is moved to the end of the deleted region, and if the ending position was within a deleted region, it is moved to the start. If the region becomes empty, RegionNil will be returned.

func (*Edit) Clone

func (te *Edit) Clone() *Edit

Clone returns a clone of the edit record.

func (*Edit) CopyFrom

func (te *Edit) CopyFrom(cp *Edit)

Copy copies from other Edit

func (*Edit) ToBytes

func (te *Edit) ToBytes() []byte

ToBytes returns the Text of this edit record to a byte string, with newlines at end of each line -- nil if Text is empty

type Lines

type Lines struct {
	// Options are the options for how text editing and viewing works.
	Options Options

	// Highlighter does the syntax highlighting markup, and contains the
	// parameters thereof, such as the language and style.
	Highlighter highlighting.Highlighter

	// Undos is the undo manager.
	Undos Undo

	// Markup is the marked-up version of the edited text lines, after being run
	// through the syntax highlighting process. This is what is actually rendered.
	// You MUST access it only under a Lock()!
	Markup [][]byte

	// ParseState is the parsing state information for the file.
	ParseState parse.FileStates

	// ChangedFunc is called whenever the text content is changed.
	// The changed flag is always updated on changes, but this can be
	// used for other flags or events that need to be tracked. The
	// Lock is off when this is called.
	ChangedFunc func()

	// MarkupDoneFunc is called when the offline markup pass is done
	// so that the GUI can be updated accordingly.  The lock is off
	// when this is called.
	MarkupDoneFunc func()

	// use Lock(), Unlock() directly for overall mutex on any content updates
	sync.Mutex
	// contains filtered or unexported fields
}

Lines manages multi-line text, with original source text encoded as bytes and runes, and a corresponding markup representation with syntax highlighting and other HTML-encoded text markup on top of the raw text. The markup is updated in a separate goroutine for efficiency. Everything is protected by an overall sync.Mutex and safe to concurrent access, and thus nothing is exported and all access is through protected accessor functions. In general, all unexported methods do NOT lock, and all exported methods do.

func (*Lines) AddTag

func (ls *Lines) AddTag(ln, st, ed int, tag token.Tokens)

AddTag adds a new custom tag for given line, at given position.

func (*Lines) AddTagEdit

func (ls *Lines) AddTagEdit(tbe *Edit, tag token.Tokens)

AddTagEdit adds a new custom tag for given line, using Edit for location.

func (*Lines) AdjustRegion

func (ls *Lines) AdjustRegion(reg Region) Region

AdjustRegion adjusts given text region for any edits that have taken place since time stamp on region (using the Undo stack). If region was wholly within a deleted region, then RegionNil will be returned -- otherwise it is clipped appropriately as function of deletes.

func (*Lines) AdjustedTags

func (ls *Lines) AdjustedTags(ln int) lexer.Line

AdjustedTags updates tag positions for edits, for given line and returns the new tags

func (*Lines) AdjustedTagsLine

func (ls *Lines) AdjustedTagsLine(tags lexer.Line, ln int) lexer.Line

AdjustedTagsLine updates tag positions for edits, for given list of tags, associated with given line of text.

func (*Lines) AppendTextLineMarkup

func (ls *Lines) AppendTextLineMarkup(text []byte, markup []byte) *Edit

AppendTextLineMarkup appends one line of new text to end of lines, using insert, and appending a LF at the end of the line if it doesn't already have one. User-supplied markup is used. Returns the edit region.

func (*Lines) AppendTextMarkup

func (ls *Lines) AppendTextMarkup(text []byte, markup []byte) *Edit

AppendTextMarkup appends new text to end of lines, using insert, returns edit, and uses supplied markup to render it, for preformatted output.

func (*Lines) AutoIndent

func (ls *Lines) AutoIndent(ln int) (tbe *Edit, indLev, chPos int)

autoIndent indents given line to the level of the prior line, adjusted appropriately if the current line starts with one of the given un-indent strings, or the prior line ends with one of the given indent strings. Returns any edit that took place (could be nil), along with the auto-indented level and character position for the indent of the current line.

func (*Lines) AutoIndentRegion

func (ls *Lines) AutoIndentRegion(start, end int)

AutoIndentRegion does auto-indent over given region; end is *exclusive*.

func (*Lines) BraceMatch

func (ls *Lines) BraceMatch(r rune, st lexer.Pos) (en lexer.Pos, found bool)

BraceMatch finds the brace, bracket, or parens that is the partner of the one passed to function.

func (*Lines) Bytes

func (ls *Lines) Bytes() []byte

Bytes returns the current text lines as a slice of bytes, with an additional line feed at the end, per POSIX standards.

func (*Lines) CommentRegion

func (ls *Lines) CommentRegion(start, end int)

CommentRegion inserts comment marker on given lines; end is *exclusive*.

func (*Lines) CountWordsLinesRegion

func (ls *Lines) CountWordsLinesRegion(reg Region) (words, lines int)

func (*Lines) DeleteText

func (ls *Lines) DeleteText(st, ed lexer.Pos) *Edit

DeleteText is the primary method for deleting text from the lines. It deletes region of text between start and end positions. Sets the timestamp on resulting Edit to now. An Undo record is automatically saved depending on Undo.Off setting.

func (*Lines) DeleteTextRect

func (ls *Lines) DeleteTextRect(st, ed lexer.Pos) *Edit

DeleteTextRect deletes rectangular region of text between start, end defining the upper-left and lower-right corners of a rectangle. Fails if st.Ch >= ed.Ch. Sets the timestamp on resulting Edit to now. An Undo record is automatically saved depending on Undo.Off setting.

func (*Lines) DiffBuffers

func (ls *Lines) DiffBuffers(ob *Lines) Diffs

DiffBuffers computes the diff between this buffer and the other buffer, reporting a sequence of operations that would convert this buffer (a) into the other buffer (b). Each operation is either an 'r' (replace), 'd' (delete), 'i' (insert) or 'e' (equal). Everything is line-based (0, offset).

func (*Lines) EmacsUndoSave

func (ls *Lines) EmacsUndoSave()

EmacsUndoSave is called by View at end of latest set of undo commands. If EmacsUndo mode is active, saves the current UndoStack to the regular Undo stack at the end, and moves undo to the very end -- undo is a constant stream.

func (*Lines) EndPos

func (ls *Lines) EndPos() lexer.Pos

EndPos returns the ending position at end of lines.

func (*Lines) HiTagAtPos

func (ls *Lines) HiTagAtPos(pos lexer.Pos) (*lexer.Lex, int)

HiTagAtPos returns the highlighting (markup) lexical tag at given position using current Markup tags, and index, -- could be nil if none or out of range.

func (*Lines) HiTags

func (ls *Lines) HiTags(ln int) lexer.Line

HiTags returns the highlighting tags for given line, nil if invalid

func (*Lines) InComment

func (ls *Lines) InComment(pos lexer.Pos) bool

InComment returns true if the given text position is within a commented region.

func (*Lines) InLitString

func (ls *Lines) InLitString(pos lexer.Pos) bool

InLitString returns true if position is in a string literal.

func (*Lines) InTokenCode

func (ls *Lines) InTokenCode(pos lexer.Pos) bool

InTokenCode returns true if position is in a Keyword, Name, Operator, or Punctuation. This is useful for turning off spell checking in docs

func (*Lines) InTokenSubCat

func (ls *Lines) InTokenSubCat(pos lexer.Pos, subCat token.Tokens) bool

InTokenSubCat returns true if the given text position is marked with lexical type in given SubCat sub-category.

func (*Lines) IndentLine

func (ls *Lines) IndentLine(ln, ind int) *Edit

IndentLine indents line by given number of tab stops, using tabs or spaces, for given tab size (if using spaces) -- either inserts or deletes to reach target. Returns edit record for any change.

func (*Lines) InsertText

func (ls *Lines) InsertText(st lexer.Pos, text []byte) *Edit

InsertText is the primary method for inserting text, at given starting position. Sets the timestamp on resulting Edit to now. An Undo record is automatically saved depending on Undo.Off setting.

func (*Lines) InsertTextRect

func (ls *Lines) InsertTextRect(tbe *Edit) *Edit

InsertTextRect inserts a rectangle of text defined in given Edit record, (e.g., from RegionRect or DeleteRect). Returns a copy of the Edit record with an updated timestamp. An Undo record is automatically saved depending on Undo.Off setting.

func (*Lines) IsChanged

func (ls *Lines) IsChanged() bool

IsChanged reports whether any edits have been applied to text

func (*Lines) IsValidLine

func (ls *Lines) IsValidLine(ln int) bool

IsValidLine returns true if given line number is in range.

func (*Lines) JoinParaLines

func (ls *Lines) JoinParaLines(startLine, endLine int)

JoinParaLines merges sequences of lines with hard returns forming paragraphs, separated by blank lines, into a single line per paragraph, within the given line regions; endLine is *inclusive*.

func (*Lines) LexObjPathString

func (ls *Lines) LexObjPathString(ln int, lx *lexer.Lex) string

LexObjPathString returns the string at given lex, and including prior lex-tagged regions that include sequences of PunctSepPeriod and NameTag which are used for object paths -- used for e.g., debugger to pull out variable expressions that can be evaluated.

func (*Lines) Line

func (ls *Lines) Line(ln int) []rune

Line returns a (copy of) specific line of runes.

func (*Lines) LineBytes

func (ls *Lines) LineBytes(ln int) []byte

LineBytes returns a (copy of) specific line of bytes.

func (*Lines) LineChar

func (ls *Lines) LineChar(ln, ch int) rune

LineChar returns rune at given line and character position. returns a 0 if character position is not valid

func (*Lines) LineLen

func (ls *Lines) LineLen(ln int) int

LineLen returns the length of the given line, in runes.

func (*Lines) MarkupLines

func (ls *Lines) MarkupLines(st, ed int) bool

MarkupLines generates markup of given range of lines. end is *inclusive* line. Called after edits, under Lock(). returns true if all lines were marked up successfully.

func (*Lines) NumLines

func (ls *Lines) NumLines() int

NumLines returns the number of lines.

func (*Lines) PatchFromBuffer

func (ls *Lines) PatchFromBuffer(ob *Lines, diffs Diffs) bool

PatchFromBuffer patches (edits) using content from other, according to diff operations (e.g., as generated from DiffBufs).

func (*Lines) ReMarkup

func (ls *Lines) ReMarkup()

ReMarkup starts a background task of redoing the markup

func (*Lines) Redo

func (ls *Lines) Redo() []*Edit

Redo redoes next group of items on the undo stack, and returns all the edits performed.

func (*Lines) Region

func (ls *Lines) Region(st, ed lexer.Pos) *Edit

Region returns a Edit representation of text between start and end positions. returns nil if not a valid region. sets the timestamp on the Edit to now.

func (*Lines) RegionRect

func (ls *Lines) RegionRect(st, ed lexer.Pos) *Edit

RegionRect returns a Edit representation of text between start and end positions as a rectangle, returns nil if not a valid region. sets the timestamp on the Edit to now.

func (*Lines) RemoveTag

func (ls *Lines) RemoveTag(pos lexer.Pos, tag token.Tokens) (reg lexer.Lex, ok bool)

RemoveTag removes tag (optionally only given tag if non-zero) at given position if it exists. returns tag.

func (*Lines) ReplaceText

func (ls *Lines) ReplaceText(delSt, delEd, insPos lexer.Pos, insTxt string, matchCase bool) *Edit

ReplaceText does DeleteText for given region, and then InsertText at given position (typically same as delSt but not necessarily). if matchCase is true, then the lexer.MatchCase function is called to match the case (upper / lower) of the new inserted text to that of the text being replaced. returns the Edit for the inserted text. An Undo record is automatically saved depending on Undo.Off setting.

func (*Lines) Search

func (ls *Lines) Search(find []byte, ignoreCase, lexItems bool) (int, []Match)

Search looks for a string (no regexp) within buffer, with given case-sensitivity, returning number of occurrences and specific match position list. Column positions are in runes.

func (*Lines) SearchRegexp

func (ls *Lines) SearchRegexp(re *regexp.Regexp) (int, []Match)

SearchRegexp looks for a string (regexp) within buffer, returning number of occurrences and specific match position list. Column positions are in runes.

func (*Lines) SetChanged

func (ls *Lines) SetChanged(changed bool)

SetChanged sets the changed flag to given value (e.g., when file saved)

func (*Lines) SetFileExt

func (ls *Lines) SetFileExt(ext string)

SetFileExt sets syntax highlighting and other parameters based on the given file extension (without the . prefix), for cases where an actual file with fileinfo.FileInfo is not available.

func (*Lines) SetFileInfo

func (ls *Lines) SetFileInfo(info *fileinfo.FileInfo)

SetFileInfo sets the syntax highlighting and other parameters based on the type of file specified by given fileinfo.FileInfo.

func (*Lines) SetHighlighting

func (ls *Lines) SetHighlighting(style core.HighlightingName)

SetHighlighting sets the highlighting style.

func (*Lines) SetLanguage

func (ls *Lines) SetLanguage(ftyp fileinfo.Known)

SetFileType sets the syntax highlighting and other parameters based on the given fileinfo.Known file type

func (*Lines) SetTags

func (ls *Lines) SetTags(ln int, tags lexer.Line)

SetTags tags for given line.

func (*Lines) SetText

func (ls *Lines) SetText(text []byte)

SetText sets the text to the given bytes (makes a copy). Pass nil to initialize an empty buffer.

func (*Lines) SetTextLines

func (ls *Lines) SetTextLines(lns [][]byte)

SetTextLines sets linesBytes from given lines of bytes, making a copy and removing any trailing \r carriage returns, to standardize.

func (*Lines) SpacesToTabs

func (ls *Lines) SpacesToTabs(start, end int)

SpacesToTabs replaces tabs with spaces over given region; end is *exclusive*

func (*Lines) StartDelayedReMarkup

func (ls *Lines) StartDelayedReMarkup()

StartDelayedReMarkup starts a timer for doing markup after an interval.

func (*Lines) StopDelayedReMarkup

func (ls *Lines) StopDelayedReMarkup()

StopDelayedReMarkup stops timer for doing markup after an interval

func (*Lines) Strings

func (ls *Lines) Strings(addNewLine bool) []string

strings returns the current text as []string array. If addNewLine is true, each string line has a \n appended at end.

func (*Lines) TabsToSpaces

func (ls *Lines) TabsToSpaces(start, end int)

TabsToSpaces replaces tabs with spaces over given region; end is *exclusive*.

func (*Lines) Undo

func (ls *Lines) Undo() []*Edit

Undo undoes next group of items on the undo stack, and returns all the edits performed.

func (*Lines) ValidPos

func (ls *Lines) ValidPos(pos lexer.Pos) lexer.Pos

ValidPos returns a position that is in a valid range.

type Match

type Match struct {

	// region surrounding the match -- column positions are in runes, not bytes
	Reg Region

	// text surrounding the match, at most FileSearchContext on either side (within a single line)
	Text []byte
}

Match records one match for search within file, positions in runes

func NewMatch

func NewMatch(rn []rune, st, ed, ln int) Match

NewMatch returns a new Match entry for given rune line with match starting at st and ending before ed, on given line

func Search(reader io.Reader, find []byte, ignoreCase bool) (int, []Match)

Search looks for a string (no regexp) from an io.Reader input stream, using given case-sensitivity. Returns number of occurrences and specific match position list. Column positions are in runes.

func SearchByteLinesRegexp

func SearchByteLinesRegexp(src [][]byte, re *regexp.Regexp) (int, []Match)

SearchByteLinesRegexp looks for a regexp within lines of bytes, with given case-sensitivity returning number of occurrences and specific match position list. Column positions are in runes.

func SearchFile

func SearchFile(filename string, find []byte, ignoreCase bool) (int, []Match)

SearchFile looks for a string (no regexp) within a file, in a case-sensitive way, returning number of occurrences and specific match position list -- column positions are in runes.

func SearchFileRegexp

func SearchFileRegexp(filename string, re *regexp.Regexp) (int, []Match)

SearchFileRegexp looks for a string (using regexp) within a file, returning number of occurrences and specific match position list -- column positions are in runes.

func SearchLexItems

func SearchLexItems(src [][]rune, lexs []lexer.Line, find []byte, ignoreCase bool) (int, []Match)

SearchLexItems looks for a string (no regexp), as entire lexically tagged items, with given case-sensitivity returning number of occurrences and specific match position list. Column positions are in runes.

func SearchRegexp

func SearchRegexp(reader io.Reader, re *regexp.Regexp) (int, []Match)

SearchRegexp looks for a string (using regexp) from an io.Reader input stream. Returns number of occurrences and specific match position list. Column positions are in runes.

func SearchRuneLines

func SearchRuneLines(src [][]rune, find []byte, ignoreCase bool) (int, []Match)

SearchRuneLines looks for a string (no regexp) within lines of runes, with given case-sensitivity returning number of occurrences and specific match position list. Column positions are in runes.

type Options

type Options struct {

	// editor settings from core settings
	core.EditorSettings

	// character(s) that start a single-line comment; if empty then multi-line comment syntax will be used
	CommentLine string

	// character(s) that start a multi-line comment or one that requires both start and end
	CommentStart string

	// character(s) that end a multi-line comment or one that requires both start and end
	CommentEnd string
}

Options contains options for [texteditor.Buffer]s. It contains everything necessary to customize editing of a certain text file.

func (*Options) CommentStrings

func (tb *Options) CommentStrings() (comst, comed string)

CommentStrings returns the comment start and end strings, using line-based CommentLn first if set and falling back on multi-line / general purpose start / end syntax

func (*Options) ConfigKnown

func (tb *Options) ConfigKnown(sup fileinfo.Known) bool

ConfigKnown configures options based on the supported language info in parse. Returns true if supported.

func (*Options) IndentChar

func (tb *Options) IndentChar() indent.Character

IndentChar returns the indent character based on SpaceIndent option

type Patch

type Patch []*PatchRec

Patch is a collection of patch records needed to turn original a buffer into b

func (Patch) Apply

func (pt Patch) Apply(astr []string) []string

Apply applies given Patch to given file as list of strings this does no checking except range checking so it won't crash so if input string is not appropriate for given Patch, results may be nonsensical.

func (Patch) NumBlines

func (pt Patch) NumBlines() int

NumBlines returns the total number of Blines source code in the patch

type PatchRec

type PatchRec struct {

	// diff operation: 'r', 'd', 'i', 'e'
	Op difflib.OpCode

	// lines from B buffer needed for 'r' and 'i' operations
	Blines []string
}

PatchRec is a self-contained record of a DiffLines result that contains the source lines of the b buffer needed to patch a into b

type Region

type Region struct {

	// starting position
	Start lexer.Pos

	// ending position: line number is *inclusive* but character position is *exclusive* (-1)
	End lexer.Pos

	// time when region was set -- needed for updating locations in the text based on time stamp (using efficient non-pointer time)
	Time nptime.Time
}

Region represents a text region as a start / end position, and includes a Time stamp for when the region was created as valid positions into the textview.Buf. The character end position is an *exclusive* position (i.e., the region ends at the character just prior to that character) but the lines are always *inclusive* (i.e., it is the actual line, not the next line).

var RegionNil Region

RegionNil is the empty (zero) text region -- all zeros

func NewRegion

func NewRegion(stLn, stCh, edLn, edCh int) Region

NewRegion creates a new text region using separate line and char values for start and end, and also sets the time stamp to now

func NewRegionLen

func NewRegionLen(start lexer.Pos, len int) Region

NewRegionLen makes a new Region from a starting point and a length along same line

func NewRegionPos

func NewRegionPos(st, ed lexer.Pos) Region

NewRegionPos creates a new text region using position values and also sets the time stamp to now

func (*Region) Age

func (tr *Region) Age() time.Duration

Age returns the time interval from time.Now

func (*Region) Ago

func (tr *Region) Ago(t time.Time) time.Duration

Ago returns how long ago this Region's time stamp is relative to given time.

func (*Region) Contains

func (tr *Region) Contains(ln int) bool

Contains returns true if line is within region

func (*Region) FromString

func (tr *Region) FromString(link string) bool

FromString decodes text region from a string representation of form: [#]LxxCxx-LxxCxx -- used in e.g., URL links -- returns true if successful

func (*Region) IsAfterTime

func (tr *Region) IsAfterTime(t time.Time) bool

IsAfterTime reports if this region's time stamp is after given time value if region Time stamp has not been set, it always returns true

func (*Region) IsNil

func (tr *Region) IsNil() bool

IsNil checks if the region is empty, because the start is after or equal to the end

func (*Region) IsSameLine

func (tr *Region) IsSameLine() bool

IsSameLine returns true if region starts and ends on the same line

func (*Region) Since

func (tr *Region) Since(earlier *Region) time.Duration

Since returns the time interval between this Region's time stamp and that of the given earlier region's stamp.

func (*Region) TimeNow

func (tr *Region) TimeNow()

TimeNow grabs the current time as the edit time

type Undo

type Undo struct {

	// if true, saving and using undos is turned off (e.g., inactive buffers)
	Off bool

	// undo stack of edits
	Stack []*Edit

	// undo stack of *undo* edits -- added to whenever an Undo is done -- for emacs-style undo
	UndoStack []*Edit

	// undo position in stack
	Pos int

	// group counter
	Group int

	// mutex protecting all updates
	Mu sync.Mutex `json:"-" xml:"-"`
}

Undo is the textview.Buf undo manager

func (*Undo) AdjustRegion

func (un *Undo) AdjustRegion(reg Region) Region

AdjustRegion adjusts given text region for any edits that have taken place since time stamp on region (using the Undo stack). If region was wholly within a deleted region, then RegionNil will be returned -- otherwise it is clipped appropriately as function of deletes.

func (*Undo) NewGroup

func (un *Undo) NewGroup()

NewGroup increments the Group counter so subsequent undos will be grouped separately

func (*Undo) RedoNext

func (un *Undo) RedoNext() *Edit

RedoNext returns the current item on Stack for Redo, and increments the position returns nil if at end of stack.

func (*Undo) RedoNextIfGroup

func (un *Undo) RedoNextIfGroup(gp int) *Edit

RedoNextIfGroup returns the current item on Stack for Redo if it is same group and increments the position. returns nil if at end of stack.

func (*Undo) Reset

func (un *Undo) Reset()

Reset clears all undo records

func (*Undo) Save

func (un *Undo) Save(tbe *Edit)

Save saves given edit to undo stack, with current group marker unless timer interval exceeds UndoGroupDelay since last item.

func (*Undo) SaveUndo

func (un *Undo) SaveUndo(tbe *Edit)

SaveUndo saves given edit to UndoStack (stack of undoes that have have undone..) for emacs mode.

func (*Undo) UndoPop

func (un *Undo) UndoPop() *Edit

UndoPop pops the top item off of the stack for use in Undo. returns nil if none.

func (*Undo) UndoPopIfGroup

func (un *Undo) UndoPopIfGroup(gp int) *Edit

UndoPopIfGroup pops the top item off of the stack if it is the same as given group

func (*Undo) UndoStackSave

func (un *Undo) UndoStackSave()

UndoStackSave if EmacsUndo mode is active, saves the UndoStack to the regular Undo stack, at the end, and moves undo to the very end. Undo is a constant stream..

Jump to

Keyboard shortcuts

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