Update ftoptions and statusline plugin configuration options

This commit is contained in:
Zachary Yedidia 2019-07-28 16:28:04 -07:00
parent 23a76e1381
commit 576036f251
4 changed files with 82 additions and 37 deletions

View file

@ -7,8 +7,10 @@ import (
luar "layeh.com/gopher-luar"
"github.com/zyedidia/micro/internal/action"
"github.com/zyedidia/micro/internal/display"
ulua "github.com/zyedidia/micro/internal/lua"
"github.com/zyedidia/micro/internal/screen"
"github.com/zyedidia/micro/internal/shell"
)
func init() {
@ -17,9 +19,12 @@ func init() {
}
func LuaImport(pkg string) *lua.LTable {
if pkg == "micro" {
switch pkg {
case "micro":
return luaImportMicro()
} else {
case "micro/shell":
return luaImportMicroShell()
default:
return ulua.Import(pkg)
}
}
@ -31,7 +36,19 @@ func luaImportMicro() *lua.LTable {
ulua.L.SetField(pkg, "TermError", luar.New(ulua.L, screen.TermError))
ulua.L.SetField(pkg, "InfoBar", luar.New(ulua.L, action.GetInfoBar))
ulua.L.SetField(pkg, "Log", luar.New(ulua.L, log.Println))
ulua.L.SetField(pkg, "TryBindKey", luar.New(ulua.L, action.TryBindKey))
ulua.L.SetField(pkg, "SetStatusInfoFn", luar.New(ulua.L, display.SetStatusInfoFnLua))
// ulua.L.SetField(pkg, "TryBindKey", luar.New(ulua.L, action.TryBindKey))
return pkg
}
func luaImportMicroShell() *lua.LTable {
pkg := ulua.L.NewTable()
ulua.L.SetField(pkg, "ExecCommand", luar.New(ulua.L, shell.ExecCommand))
ulua.L.SetField(pkg, "RunCommand", luar.New(ulua.L, shell.RunCommand))
ulua.L.SetField(pkg, "RunBackgroundShell", luar.New(ulua.L, shell.RunBackgroundShell))
ulua.L.SetField(pkg, "RunInteractiveShell", luar.New(ulua.L, shell.RunInteractiveShell))
return pkg
}

View file

@ -1051,7 +1051,7 @@ func runtimePluginsAutocloseAutocloseLua() (*asset, error) {
return a, nil
}
var _runtimePluginsFtoptionsFtoptionsLua = "\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x94\x51\xb1\x6a\xc3\x30\x10\xdd\xf5\x15\x87\xa6\x04\x4a\x86\x76\xf6\xd0\x2e\x1d\x33\x04\xba\x94\x0e\xaa\x7d\x17\x1f\x95\xef\x84\x75\x6e\xf0\xdf\x17\x29\x4e\x42\x29\x0e\xf4\xa6\xd3\x7b\x4f\xef\xe9\x21\x26\x78\x45\xdb\x27\x63\x95\x8d\x27\xd3\xba\x65\xbf\x85\xa6\x01\xe1\x08\xd6\xa3\x38\x00\x80\xe7\xae\xfb\x2b\x7b\x00\x1b\x27\xdc\x3a\x94\xce\x39\x9a\xa4\x2d\x30\xa8\xbc\x31\x9e\xf6\x09\x65\xf3\xcd\x78\xda\xd6\xfb\x4c\x20\x6a\x6b\x69\xd7\x98\x32\x23\xda\x34\x9e\x8f\xd5\xb8\x2c\x51\xdb\x10\x81\x0c\x1a\x28\x9e\xbb\x97\x89\x76\x07\x34\x63\x39\xe6\x77\x4f\x1c\xd1\xe6\x84\xfe\xc3\x5d\xc2\x8a\xb4\x01\x7f\x54\x0f\x3a\x56\x70\x41\x86\xf0\x85\x45\xef\x7f\x87\x1e\x6e\x0f\xb3\xf0\x99\x4d\x73\x0a\x2d\x96\x8a\x5e\x89\xfc\xb9\x04\xc6\x8c\x37\x6f\xe2\xdc\x5f\xdd\x97\x59\xa8\x34\x5b\xaf\x72\x97\x7c\xbc\xcb\x3e\xad\xb0\x73\x18\xe2\x0a\x25\x3c\xfc\xa3\x93\x5c\x2a\x49\x57\xbf\xef\x27\x00\x00\xff\xff\xe7\xc7\xa0\xb2\x0a\x02\x00\x00"
var _runtimePluginsFtoptionsFtoptionsLua = "\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x94\xcf\xb1\x0e\x82\x40\x0c\x06\xe0\x9d\xa7\x68\x6e\x82\xc4\x49\x37\x12\x16\x07\x57\x06\x7d\x81\x3b\x6c\xe5\xe2\xd1\x5e\xb8\x32\xf0\xf6\x86\x13\x75\x82\xc4\x26\x5d\xfa\x25\xfd\xf3\xd3\xc4\x9d\x7a\x61\x10\x3e\x4f\x44\x38\xb6\x11\xb9\x74\x55\x01\x00\x10\xa4\xb3\x01\x48\xa1\x01\x57\x5f\x7c\xc0\xdb\x1c\xb1\xac\x8a\x8c\x9e\xb2\x34\x60\x1e\x62\x40\xc6\x7c\x5c\x2f\x83\x7d\x22\xf9\x80\x06\xb4\x47\xce\xb2\x8c\xab\xaf\xa8\x6d\x5c\xf2\x4a\xa3\xd6\x25\x95\x14\x6d\x87\xc9\x1c\xc0\x08\x91\x79\xc7\x62\x48\xf8\xfb\x4e\x3e\xf5\xdf\xff\xeb\xac\x14\x67\xed\x85\x77\xf1\xb8\xab\xa7\x0d\x9d\xed\x10\x36\x88\xfd\xf0\x57\x2b\xfe\x94\xe2\x7b\xb1\xec\x2b\x00\x00\xff\xff\x55\x1f\xb6\x5b\x71\x01\x00\x00"
func runtimePluginsFtoptionsFtoptionsLuaBytes() ([]byte, error) {
return bindataRead(

View file

@ -6,11 +6,16 @@ import (
"path"
"regexp"
"strconv"
"strings"
"unicode/utf8"
luar "layeh.com/gopher-luar"
runewidth "github.com/mattn/go-runewidth"
lua "github.com/yuin/gopher-lua"
"github.com/zyedidia/micro/internal/buffer"
"github.com/zyedidia/micro/internal/config"
ulua "github.com/zyedidia/micro/internal/lua"
"github.com/zyedidia/micro/internal/screen"
"github.com/zyedidia/micro/internal/util"
)
@ -25,31 +30,59 @@ type StatusLine struct {
win *BufWindow
}
var statusInfo = map[string]func(*buffer.Buffer) string{
"filename": func(b *buffer.Buffer) string {
if b.Settings["basename"].(bool) {
return path.Base(b.GetName())
}
return b.GetName()
},
"line": func(b *buffer.Buffer) string {
return strconv.Itoa(b.GetActiveCursor().Y + 1)
},
"col": func(b *buffer.Buffer) string {
return strconv.Itoa(b.GetActiveCursor().X + 1)
},
"modified": func(b *buffer.Buffer) string {
if b.Modified() {
return "+ "
}
return ""
},
}
func SetStatusInfoFnLua(s string, fn string) {
luaFn := strings.Split(fn, ".")
plName, plFn := luaFn[0], luaFn[1]
var pl *config.Plugin
for _, p := range config.Plugins {
if p.Name == plName {
pl = p
break
}
}
statusInfo[s] = func(b *buffer.Buffer) string {
if pl == nil {
return ""
}
val, err := pl.Call(plFn, luar.New(ulua.L, b))
if err == nil {
if v, ok := val.(lua.LString); !ok {
screen.TermMessage(plFn, "should return a string")
return ""
} else {
return string(v)
}
}
return ""
}
}
// TODO: plugin modify status line formatter
// NewStatusLine returns a statusline bound to a window
func NewStatusLine(win *BufWindow) *StatusLine {
s := new(StatusLine)
s.Info = map[string]func(*buffer.Buffer) string{
"filename": func(b *buffer.Buffer) string {
if b.Settings["basename"].(bool) {
return path.Base(b.GetName())
}
return b.GetName()
},
"line": func(b *buffer.Buffer) string {
return strconv.Itoa(b.GetActiveCursor().Y + 1)
},
"col": func(b *buffer.Buffer) string {
return strconv.Itoa(b.GetActiveCursor().X + 1)
},
"modified": func(b *buffer.Buffer) string {
if b.Modified() {
return "+ "
}
return ""
},
}
s.win = win
return s
}
@ -121,7 +154,10 @@ func (s *StatusLine) Display() {
}
return []byte("null")
} else {
return []byte(s.Info[string(name)](s.win.Buf))
if fn, ok := statusInfo[string(name)]; ok {
return []byte(fn(s.win.Buf))
}
return []byte{}
}
}

View file

@ -1,23 +1,15 @@
if GetOption("ftoptions") == nil then
AddOption("ftoptions", true)
end
function onViewOpen(view)
if not GetOption("ftoptions") then
return
end
local ft = view.Buf.Settings["filetype"]
function onBufferOpen(b)
local ft = b:FileType()
if ft == "go" or
ft == "makefile" then
SetOption("tabstospaces", "off")
b:SetOption("tabstospaces", "off")
elseif ft == "fish" or
ft == "python" or
ft == "python2" or
ft == "python3" or
ft == "yaml" or
ft == "nim" then
SetOption("tabstospaces", "on")
b:SetOption("tabstospaces", "on")
end
end