docs: add hilbish.editor interface docs

docs-refactor
sammyette 2022-12-14 21:28:09 -04:00
parent 0357141fbc
commit 9a42d399f0
Signed by: sammyette
GPG Key ID: 904FC49417B44DCD
3 changed files with 54 additions and 0 deletions

View File

@ -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.

View File

@ -6,6 +6,10 @@ import (
rt "github.com/arnodel/golua/runtime" 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 { func editorLoader(rtm *rt.Runtime) *rt.Table {
exports := map[string]util.LuaExport{ exports := map[string]util.LuaExport{
"insert": {editorInsert, 1, false}, "insert": {editorInsert, 1, false},
@ -20,6 +24,9 @@ func editorLoader(rtm *rt.Runtime) *rt.Table {
return mod return mod
} }
// #interface editor
// insert(text)
// Inserts text into the line.
func editorInsert(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) { func editorInsert(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
if err := c.Check1Arg(); err != nil { if err := c.Check1Arg(); err != nil {
return nil, err return nil, err
@ -35,6 +42,9 @@ func editorInsert(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
return c.Next(), nil 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) { func editorSetRegister(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
if err := c.Check1Arg(); err != nil { if err := c.Check1Arg(); err != nil {
return nil, err return nil, err
@ -55,6 +65,9 @@ func editorSetRegister(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
return c.Next(), nil 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) { func editorGetRegister(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
if err := c.Check1Arg(); err != nil { if err := c.Check1Arg(); err != nil {
return nil, err 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 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) { func editorGetLine(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
buf := lr.rl.GetLine() buf := lr.rl.GetLine()

View File

@ -22,6 +22,18 @@ function hilbish.completions.call(name, query, ctx, fields) end
--- You can check the completions doc for more info. --- You can check the completions doc for more info.
function hilbish.completions.handler(line, pos) end 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` --- Sets an alias of `cmd` to `orig`
--- @param cmd string --- @param cmd string
--- @param orig string --- @param orig string