mirror of
https://github.com/zyedidia/micro.git
synced 2026-02-06 15:10:27 +09:00
Add ByteOffset and ToCharPos to plugin API
This commit is contained in:
@@ -28,6 +28,18 @@ func ToCharPos(start Loc, buf *Buffer) int {
|
||||
return loc
|
||||
}
|
||||
|
||||
// ByteOffset is just like ToCharPos except it counts bytes instead of runes
|
||||
func ByteOffset(pos Loc, buf *Buffer) int {
|
||||
x, y := pos.X, pos.Y
|
||||
loc := 0
|
||||
for i := 0; i < y; i++ {
|
||||
// + 1 for the newline
|
||||
loc += len(buf.Line(i)) + 1
|
||||
}
|
||||
loc += len(buf.Line(y)[:x])
|
||||
return loc
|
||||
}
|
||||
|
||||
// Loc stores a location
|
||||
type Loc struct {
|
||||
X, Y int
|
||||
|
||||
@@ -335,6 +335,8 @@ func main() {
|
||||
L.SetGlobal("JoinPaths", luar.New(L, filepath.Join))
|
||||
L.SetGlobal("configDir", luar.New(L, configDir))
|
||||
L.SetGlobal("Reload", luar.New(L, LoadAll))
|
||||
L.SetGlobal("ByteOffset", luar.New(L, ByteOffset))
|
||||
L.SetGlobal("ToCharPos", luar.New(L, ToCharPos))
|
||||
|
||||
// Used for asynchronous jobs
|
||||
L.SetGlobal("JobStart", luar.New(L, JobStart))
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -86,6 +86,10 @@ as Go's GOOS variable, so `darwin`, `windows`, `linux`, `freebsd`...)
|
||||
`waitToClose` bool only applies if `interactive` is true and means that it should wait before
|
||||
returning to the editor.
|
||||
|
||||
* `ToCharPos(loc Loc, buf *Buffer) int`: returns the character position of a given x, y location.
|
||||
|
||||
* `ByteOffset(loc Loc, buf *Buffer) int`: exactly like `ToCharPos` except it it counts bytes instead of runes.
|
||||
|
||||
* `JobStart(cmd string, onStdout, onStderr, onExit string, userargs ...string)`:
|
||||
Starts running the given shell command in the background. `onStdout` `onStderr` and `onExit`
|
||||
are callbacks to lua functions which will be called when the given actions happen
|
||||
|
||||
Reference in New Issue
Block a user