Skip to content

help for a small plugin (I do not grok ANYTHING of lua) #3904

@evanescente-ondine

Description

@evanescente-ondine

Hi,
I do not know if this is the right place to ask, but I am in need of a small plugin to insert a string and place the cursor at a certain place, to help with improving my Hugo workflow.
Problem is I don't know anything about Lua and frankly I can't go into it, even if I wanted.
I'd like to associate, say alt+a to pasting
{{<keys "" >}}
and having the cursor placed between the quotation marks.
AI produced this slop:

local micro = import("micro")
local config = import("micro/config")
function insertKeys(bp)
    local cursor = bp:Cursor()
    local line = cursor.Loc.Y
    local col = cursor.Loc.X
    local textToInsert = '{{<keys "" >}}'
    bp.Buf:Insert(textToInsert, line, col)
    cursor:SetLoc(col + #textToInsert - 3, line)
end
function init()
    config.MakeCommand("insertkeys", insertKeys, config.NoComplete)
    -- config.TryBindKey("Alt-o", "lua:insertkeys", false)
end

But it's obviously BS, causing the error

Lua API error: keysplugin:5: attempt to call a non-function object
stack traceback:
	keysplugin:5: in main chunk
	[G]: ?

It shouldn't be complicated, I'd be very grateful if you helped me.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions