
Microのプラグイン開発、画面分割についてで新たに追加したペイン(Pane)に読み込み専用等の設定を追加してみます。
~/.config/micro/plug/sample/sample.lua
VERSION = "0.0.1"
local micro = import("micro")
local config = import("micro/config")
local buffer = import("micro/buffer")
local currentPane = nil
function init()
config.MakeCommand("vs", fn, config.NoComplete)
end
function fn()
local buf, err = buffer.NewBuffer("hello new pane", "new pane")
micro.CurPane():VSplitIndex(buf, false)
-- micro.CurPane()を何度も参照する必要があるため、変数に入れておく
currentPane = micro.CurPane()
currentPane.Buf.Type.Readonly = true
end
currentPane = micro.CurPane() currentPane.Buf.Type.Readonly = true
現在開いているペインに紐づいているバッファ(Buf)のタイプ(Type)にReadonlyのパラメータがあり、ここをtrueにすることで、新規で追加したペインに出力されている文字列の変更が禁止されます。
Readonlyの他に指定できるパラメータはBufTypeに記載があります。
BufType以外でもペインの設定を変えることが出来、
VERSION = "0.0.1"
local micro = import("micro")
local config = import("micro/config")
local buffer = import("micro/buffer")
local currentPane = nil
function init()
config.MakeCommand("vs", fn, config.NoComplete)
end
function fn()
local buf, err = buffer.NewBuffer("hello new pane", "new pane")
micro.CurPane():VSplitIndex(buf, false)
-- micro.CurPane()を何度も参照する必要があるため、変数に入れておく
currentPane = micro.CurPane()
currentPane.Buf.Type.Readonly = true
-- 文字列出力時、文字列の長さがペインの幅よりも長い場合は折り返す
currentPane.Buf:SetOptionNative("softwrap", true)
end
SetOptionNativeメソッドで指定できます。
第一引数の文字列はmicro/internal/config/settings.go at master · zyedidia/microのdefaultCommonSettings変数に格納されている値の設定を行うことが出来ます。