From 9a42d399f02b13eda74cdf91c3cbeae6eeaa830e Mon Sep 17 00:00:00 2001 From: sammyette Date: Wed, 14 Dec 2022 21:28:09 -0400 Subject: [PATCH] docs: add hilbish.editor interface docs --- docs/api/hilbish/hilbish.editor.md | 26 ++++++++++++++++++++++++++ editor.go | 16 ++++++++++++++++ emmyLuaDocs/hilbish.lua | 12 ++++++++++++ 3 files changed, 54 insertions(+) create mode 100644 docs/api/hilbish/hilbish.editor.md diff --git a/docs/api/hilbish/hilbish.editor.md b/docs/api/hilbish/hilbish.editor.md new file mode 100644 index 0000000..bb0f257 --- /dev/null +++ b/docs/api/hilbish/hilbish.editor.md @@ -0,0 +1,26 @@ +--- +title: Interface hilbish.editor +description: interactions for Hilbish's line reader +layout: doc +menu: + docs: + parent: "API" +--- + +## Introduction +The hilbish.editor interface provides functions to +directly interact with the line editor in use. + +## Functions +### getLine() +Returns the current input line. + +### getVimRegister(register) +Returns the text that is at the register. + +### insert(text) +Inserts text into the line. + +### setVimRegister(register, text) +Sets the vim register at `register` to hold the passed text. + diff --git a/editor.go b/editor.go index 868f458..4331dd9 100644 --- a/editor.go +++ b/editor.go @@ -6,6 +6,10 @@ import ( rt "github.com/arnodel/golua/runtime" ) +// #interface editor +// interactions for Hilbish's line reader +// The hilbish.editor interface provides functions to +// directly interact with the line editor in use. func editorLoader(rtm *rt.Runtime) *rt.Table { exports := map[string]util.LuaExport{ "insert": {editorInsert, 1, false}, @@ -20,6 +24,9 @@ func editorLoader(rtm *rt.Runtime) *rt.Table { return mod } +// #interface editor +// insert(text) +// Inserts text into the line. func editorInsert(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) { if err := c.Check1Arg(); err != nil { return nil, err @@ -35,6 +42,9 @@ func editorInsert(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) { return c.Next(), nil } +// #interface editor +// setVimRegister(register, text) +// Sets the vim register at `register` to hold the passed text. func editorSetRegister(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) { if err := c.Check1Arg(); err != nil { return nil, err @@ -55,6 +65,9 @@ func editorSetRegister(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) { return c.Next(), nil } +// #interface editor +// getVimRegister(register) +// Returns the text that is at the register. func editorGetRegister(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) { if err := c.Check1Arg(); err != nil { return nil, err @@ -70,6 +83,9 @@ func editorGetRegister(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) { return c.PushingNext1(t.Runtime, rt.StringValue(string(buf))), nil } +// #interface editor +// getLine() +// Returns the current input line. func editorGetLine(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) { buf := lr.rl.GetLine() diff --git a/emmyLuaDocs/hilbish.lua b/emmyLuaDocs/hilbish.lua index ef417f0..7a6930d 100644 --- a/emmyLuaDocs/hilbish.lua +++ b/emmyLuaDocs/hilbish.lua @@ -22,6 +22,18 @@ function hilbish.completions.call(name, query, ctx, fields) end --- You can check the completions doc for more info. function hilbish.completions.handler(line, pos) end +--- Returns the current input line. +function hilbish.editor.getLine() end + +--- Returns the text that is at the register. +function hilbish.editor.getVimRegister(register) end + +--- Inserts text into the line. +function hilbish.editor.insert(text) end + +--- Sets the vim register at `register` to hold the passed text. +function hilbish.editor.setVimRegister(register, text) end + --- Sets an alias of `cmd` to `orig` --- @param cmd string --- @param orig string