lines module, when called splits a string into lines.
require'lines'(text) -> table of lines
sub-modules include several data structures with more performant
mechanisms to insert/remove/etc based on real-world workloads
(i.e. editor, parser, etc)
Diffing module and command
Example command:
lines.diff{'file/path1.txt', 'file/path2.txt'}
Note: the arguments can be a string (path) or list of lines.
Types: Diff
Functions
Line-based diff.
The default algorithm uses patience diff. Special thanks to:
https://blog.jcoglan.com/2017/09/19/the-patience-diff-algorithm
The basic algorithm on before/after line lists:
- skip unchanged lines on both top and bottom
- find unique lines in both sets and "align" them with
using "longest increasing sequence"
- repeat for each aligned section
Example:
io.fmt(Diff(linesA, linesB))
Fields:
- .bbase, aka original lines
- .cchange, aka new lines
- .dilen of noc/rem/add
- .nocnochange range (in both)
- .remremoved from b
- .addadded from c
Methods
- fn map(d, nocFn, chgFn)
iterate through nochange and change blocks, calling the functions for each
- nocFn(baseStart, numUnchanged, changeStart, numUnchanged)
- chgFn(baseStart, numRemoved, changeStart, numAdded)
Note that the num removed/added will be nil if none were added/removed.
Methods
- fn set(name)
Create a parser spec record. These have the fields kind and name
and must define the parse method.
- fn get(name)
Create a parser spec record. These have the fields kind and name
and must define the parse method.
- fn write
- fn flush()
- fn extend(r, l) -> r
- fn icopy(r)
Fields:
Methods
- fn flush()
- fn close()
- fn icopy(g) -> list
- fn load(T, f, close) -> Gap?, err?
Load gap from file, which can be a path.
returns nil, err on error
- fn get(g, l)
- fn set(g, i, v)
- fn inset(g, i, values, rmlen) -> rm?
See lines.inset for documentation.
- fn extend(g, l)
- fn setGap(g, l)
set the gap to the line number, making l == #g.bot.
- fn write(g, ...)
- fn dumpf
Fields:
Methods
- fn create(T, ...) -> icreate(T, 3, ...)
- fn reload(fi) -> IFile?, errmsg?
Reload IFile from path.
- fn load(T, ...) -> iload(T, 3, ...)
- fn flush(fi) -> fi.f:flush()
- fn close(fi)
- fn closed(fi) -> bool
- fn getbytes(fi, i)
get bytes. If index out of bounds return nil.
Panic if there are read errors.
- fn get(u3, i)
get value at index
- fn setbytes(fi, i, v)
- fn set(u3, i, v)
set value at index
- fn move(fi, to, mvFn) -> fi
Move the IFile's path to to.
mv must be of type fn(from, to). If not provided,
civix.mv will be used.
This can be done on both closed and opened files.
The IFile will re-open on the new file regardless of the
previous state.
- fn reader(fi) -> IFile?, err?
Get a new read-only instance with an independent file-descriptor.
Warning: currently the reader's len will be static, so this should
be mostly used for temporary cases. This might be changed in
the future.
- fn extend(r, l) -> r
- fn icopy(r)
Fields:
Methods
Fields:
- .lfindexed file
- .datslist of Slc | Gap
- .lensrolling sum of dat lengths
Methods
- fn get(ef, i) -> line
Get line at index
- fn write(ef, ...) -> self?, errmsg?
- fn set(ef, i, v)
Set line at index.
- fn reader(ef)
Return a read-only view of the EdFile which shares the
associated data structures.
- fn flush(ef) -> ef.lf:flush()
Flush the .lf member (which can only be extended).
To write all data to disk use :dumpf()
- fn close(ef) -> ef.lf:close()
Note: this does NOT necessarily flush what you expect.
- fn dumpf(ef, f)
Dump EdFile to file or path
- fn extend(ef, values)
appends to lf for extend when possible.
- fn inset(ef, i, values, rmlen) -> rm?
insert into EdFile's dats.
- fn icopy(r)
utilities for file loading of lines.
Functions
- fn forceLoadIdx(f, idxpath)
Can be usd instead of loadIdx to force a reload of the index,
ignoring modification times/etc.
This is useful in some situtations where stat is not available.
- fn loadIdx(f, idxpath, fmode, reindex) -> idxFile
load or reindex the file at path to/from idxpath.
module with helper methods for moving a cursor
around a lines-like 2D grid.
Functions
- fn decDistance(s, e) -> int
decrease distance (start -> end) by 1
- fn lcLe(l, c, l2, c2) -> bool
return whether l.c is <= l2.c2
- fn lcGe(l, c, l2, c2) -> bool
return whether l.c is >= l2.c2
- fn topLeft(l, c, l2, c2) -> (l, c)
return the top-left of two points
- fn lcWithin(l, c, l1, c1, l2, c2) -> bool
- fn wordKind(ch) -> ws|sym|let
- fn pathKind(ch) -> ws|sym|path
- fn forword(s, begin, getKind) -> int
Go forward to find the start of the next word
- fn backword(s, end_, getKind) -> int
Go backward to find the start of this (or previous) word
- fn getRange(s, i, getKind) -> si,ei
get the range[si,ei
of whatever is at
s[i