Is there a way to run a plugin command on startup? #4078
-
|
I want to run This is what I tried with my init.lua: but it returns making me think that import("micro/config") returns |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
That error message is not from the init.lua you posted (the error is about To run a command on startup you could use the local micro = import("micro")
function postinit()
local bp = micro.CurPane()
bp:HandleCommand("vivifyMaybe")
endBut I think what you actually meant is to run it every time you open a file (not just on startup). You could use local buffer = import("micro/buffer")
function onBufPaneOpen(bp)
-- only run in normal bufpanes (ignore help, log, info, scratch, raw)
if bp.Buf.Type.Kind == buffer.BTDefault then
bp:HandleCommand("vivifyMaybe")
end
endTo run some code any time a file is opened you would want to use the local buffer = import("micro/buffer")
local shell = import("micro/shell")
function vivifyOpen(buf)
local currentLine = buf:GetActiveCursor().Loc.Y + 1
shell.ExecCommand("viv", string.format("%s:%d", buf.AbsPath, currentLine))
end
function onBufferOpen(buf)
if buf.Type.Kind == buffer.BTDefault then
vivifyOpen(buf)
end
end |
Beta Was this translation helpful? Give feedback.
That error message is not from the init.lua you posted (the error is about
configbeing nil when callingconfig.MakeCommandon line 2, but in your init.luaconfigis defined and it's not called on line 2).To run a command on startup you could use the
postinitcallback andmicro.CurPane()to get a handle to currentBufPane:But I think what you actually meant is to run it every time you open a file (not just on startup). You could use
onBufPaneOpen, but then you won't catch events where you open a different file in the same pane with theopencommand: