Documentation ¶
Index ¶
- Constants
- Variables
- func ApplyOneDiff(op difflib.OpCode, bedit *[]string, aorig []string, blmap []int)
- func BytesToLineStrings(txt []byte, addNewLn bool) []string
- func CountWordsLines(reader io.Reader) (words, lines int)
- func CountWordsLinesRegion(src [][]rune, reg Region) (words, lines int)
- func DiffLinesUnified(astr, bstr []string, context int, afile, adate, bfile, bdate string) []byte
- func DiffOpReverse(op difflib.OpCode) difflib.OpCode
- func DiffOpString(op difflib.OpCode) string
- func FileBytes(fpath string) ([]byte, error)
- func FileRegionBytes(fpath string, stLn, edLn int, preComments bool, lnBack int) []byte
- func KnownComments(fpath string) (comLn, comSt, comEd string)
- func PreCommentStart(lns [][]byte, stLn int, comLn, comSt, comEd string, lnBack int) int
- func ReCaseString(str string, c Cases) string
- func StringLinesToByteLines(str []string) [][]byte
- type AdjustPosDel
- type Cases
- func (i Cases) Desc() string
- func (i Cases) Int64() int64
- func (i Cases) IsValid() bool
- func (i Cases) MarshalText() ([]byte, error)
- func (i *Cases) SetInt64(in int64)
- func (i *Cases) SetString(s string) error
- func (i Cases) String() string
- func (i *Cases) UnmarshalText(text []byte) error
- func (i Cases) Values() []enums.Enum
- type DiffSelData
- type DiffSelected
- type Diffs
- type Edit
- type Match
- func NewMatch(rn []rune, st, ed, ln int) Match
- func Search(reader io.Reader, find []byte, ignoreCase bool) (int, []Match)
- func SearchByteLinesRegexp(src [][]byte, re *regexp.Regexp) (int, []Match)
- func SearchFile(filename string, find []byte, ignoreCase bool) (int, []Match)
- func SearchFileRegexp(filename string, re *regexp.Regexp) (int, []Match)
- func SearchLexItems(src [][]rune, lexs []lex.Line, find []byte, ignoreCase bool) (int, []Match)
- func SearchRegexp(reader io.Reader, re *regexp.Regexp) (int, []Match)
- func SearchRuneLines(src [][]rune, find []byte, ignoreCase bool) (int, []Match)
- type Opts
- type Patch
- type PatchRec
- type Region
- func (tr *Region) AgeMSec() int
- func (tr *Region) AgoMSec(t time.Time) int
- func (tr *Region) Contains(ln int) bool
- func (tr *Region) FromString(link string) bool
- func (tr *Region) IsAfterTime(t time.Time) bool
- func (tr *Region) IsNil() bool
- func (tr *Region) IsSameLine() bool
- func (tr *Region) SinceMSec(earlier *Region) int
- func (tr *Region) TimeNow()
- type Undo
- func (un *Undo) AdjustPos(pos lex.Pos, t time.Time, del AdjustPosDel) lex.Pos
- func (un *Undo) AdjustReg(reg Region) Region
- func (un *Undo) NewGroup()
- func (un *Undo) RedoNext() *Edit
- func (un *Undo) RedoNextIfGroup(gp int) *Edit
- func (un *Undo) Reset()
- func (un *Undo) Save(tbe *Edit)
- func (un *Undo) SaveUndo(tbe *Edit)
- func (un *Undo) UndoPop() *Edit
- func (un *Undo) UndoPopIfGroup(gp int) *Edit
- func (un *Undo) UndoStackSave()
Constants ¶
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 ¶
var SearchContext = 30
SearchContext is how much text to include on either side of the search match
var UndoGroupDelayMSec = 250
UndoGroupDelayMSec is number of milliseconds above which a new group is started, for grouping undo events
var UndoTrace = false
UndoTrace -- set to true to get a report of undo actions
Functions ¶
func ApplyOneDiff ¶
ApplyOneDiff applies given diff operator to given "B" lines using original "A" lines and given b line map
func BytesToLineStrings ¶
BytesToLineStrings returns []string lines from []byte input. If addNewLn is true, each string line has a \n appended at end.
func CountWordsLines ¶
CountWordsLines counts the number of words (aka Fields, space-separated strings) and lines given io.Reader input
func CountWordsLinesRegion ¶
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 ¶
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 DiffOpString ¶
func FileRegionBytes ¶
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 ¶
KnownComments returns the comment strings for supported file types, and returns the standard C-style comments otherwise.
func PreCommentStart ¶
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 ReCaseString ¶
ReCaseString changes the case of the string according to the given case type.
func StringLinesToByteLines ¶
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 Cases ¶
type Cases int32 //enums:enum
Cases are different cases -- Lower, Upper, Camel, etc
const ( LowerCase Cases = iota UpperCase // CamelCase is init-caps CamelCase // LowerCamelCase has first letter lower-case LowerCamelCase // SnakeCase is snake_case -- lower with underbars SnakeCase // UpperSnakeCase is SNAKE_CASE -- upper with underbars UpperSnakeCase // KebabCase is kebab-case -- lower with -'s KebabCase )
const CasesN Cases = 7
CasesN is the highest valid value for type Cases, plus one.
func CasesValues ¶
func CasesValues() []Cases
CasesValues returns all possible values for the type Cases.
func (Cases) MarshalText ¶
MarshalText implements the encoding.TextMarshaler interface.
func (*Cases) SetString ¶
SetString sets the Cases value from its string representation, and returns an error if the string is invalid.
func (*Cases) UnmarshalText ¶
UnmarshalText implements the encoding.TextUnmarshaler interface.
type DiffSelData ¶
type DiffSelData 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 }
DiffSelData contains data for one set of text
func (*DiffSelData) SaveUndo ¶
func (ds *DiffSelData) SaveUndo(op difflib.OpCode)
func (*DiffSelData) SetStringLines ¶
func (ds *DiffSelData) 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 (*DiffSelData) Undo ¶
func (ds *DiffSelData) Undo() bool
type DiffSelected ¶
type DiffSelected struct { A DiffSelData B DiffSelData // 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 ¶
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 ¶
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).
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 ¶
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 ¶
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 ¶
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.
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 ¶
NewMatch returns a new Match entry for given rune line with match starting at st and ending before ed, on given line
func Search ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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.
type Opts ¶
type Opts struct { // editor prefs from gogi prefs gi.EditorPrefs // character(s) that start a single-line comment -- if empty then multi-line comment syntax will be used CommentLn string // character(s) that start a multi-line comment or one that requires both start and end CommentSt string // character(s) that end a multi-line comment or one that requires both start and end CommentEd string }
Opts contains options for textview.Bufs Contains everything necessary to conditionalize editing of a given text file.
func (*Opts) CommentStrs ¶
CommentStrs 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 (*Opts) ConfigKnown ¶
ConfigKnown configures options based on the supported language info in GoPi returns true if supported
func (*Opts) IndentChar ¶
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
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 lex.Pos // ending position: line number is *inclusive* but character position is *exclusive* (-1) End lex.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 ¶
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 ¶
NewRegionLen makes a new Region from a starting point and a length along same line
func NewRegionPos ¶
NewRegionPos creates a new text region using position values and also sets the time stamp to now
func (*Region) AgoMSec ¶
AgoMSec returns how long ago this Region's time stamp is relative to given time, in milliseconds.
func (*Region) FromString ¶
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 ¶
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 ¶
IsNil checks if the region is empty, because the start is after or equal to the end
func (*Region) IsSameLine ¶
IsSameLine returns true if region starts and ends on the same line
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) AdjustPos ¶
AdjustPos adjusts given text position, which was recorded at given time for any edits that have taken place since that time (using the Undo stack). 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 (*Undo) AdjustReg ¶
AdjustReg 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 ¶
RedoNext returns the current item on Stack for Redo, and increments the position returns nil if at end of stack.
func (*Undo) RedoNextIfGroup ¶
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) Save ¶
Save saves given edit to undo stack, with current group marker unless timer interval exceeds UndoGroupDelayMSec since last item.
func (*Undo) SaveUndo ¶
SaveUndo saves given edit to UndoStack (stack of undoes that have have undone..) for emacs mode.
func (*Undo) UndoPop ¶
UndoPop pops the top item off of the stack for use in Undo. returns nil if none.
func (*Undo) UndoPopIfGroup ¶
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..