diff --git a/cmd/micro/initlua.go b/cmd/micro/initlua.go index a166b1fd..665ed37e 100644 --- a/cmd/micro/initlua.go +++ b/cmd/micro/initlua.go @@ -28,6 +28,8 @@ func LuaImport(pkg string) *lua.LTable { return luaImportMicroShell() case "micro/buffer": return luaImportMicroBuffer() + case "micro/config": + return luaImportMicroConfig() case "micro/util": return luaImportMicroUtil() default: @@ -43,7 +45,20 @@ func luaImportMicro() *lua.LTable { 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, "SetStatusInfoFn", luar.New(ulua.L, display.SetStatusInfoFnLua)) - // ulua.L.SetField(pkg, "TryBindKey", luar.New(ulua.L, action.TryBindKey)) + + return pkg +} + +func luaImportMicroConfig() *lua.LTable { + pkg := ulua.L.NewTable() + + ulua.L.SetField(pkg, "MakeCommand", luar.New(ulua.L, action.LuaMakeCommand)) + ulua.L.SetField(pkg, "FileComplete", luar.New(ulua.L, buffer.FileComplete)) + ulua.L.SetField(pkg, "HelpComplete", luar.New(ulua.L, action.HelpComplete)) + ulua.L.SetField(pkg, "OptionComplete", luar.New(ulua.L, action.OptionComplete)) + ulua.L.SetField(pkg, "OptionValueComplete", luar.New(ulua.L, action.OptionValueComplete)) + ulua.L.SetField(pkg, "NoComplete", luar.New(ulua.L, nil)) + ulua.L.SetField(pkg, "TryBindKey", luar.New(ulua.L, action.TryBindKey)) return pkg } diff --git a/internal/action/command.go b/internal/action/command.go index 0cff15bf..67f25546 100644 --- a/internal/action/command.go +++ b/internal/action/command.go @@ -10,8 +10,12 @@ import ( "strings" "unicode/utf8" + luar "layeh.com/gopher-luar" + + 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/shell" "github.com/zyedidia/micro/internal/util" @@ -63,16 +67,29 @@ func InitCommands() { // MakeCommand is a function to easily create new commands // This can be called by plugins in Lua so that plugins can define their own commands -// func MakeCommand(name, function string, completions ...Completion) { -// action := commandActions[function] -// // if _, ok := commandActions[function]; !ok { -// // If the user seems to be binding a function that doesn't exist -// // We hope that it's a lua function that exists and bind it to that -// // action = LuaFunctionCommand(function) -// // } -// -// commands[name] = Command{action, completions} -// } +func LuaMakeCommand(name, function string, completer buffer.Completer) { + action := LuaFunctionCommand(function) + commands[name] = Command{action, completer} +} + +// LuaFunctionCommand returns a normal function +// so that a command can be bound to a lua function +func LuaFunctionCommand(fn string) func(*BufPane, []string) { + luaFn := strings.Split(fn, ".") + plName, plFn := luaFn[0], luaFn[1] + pl := config.FindPlugin(plName) + return func(bp *BufPane, args []string) { + var luaArgs []lua.LValue + luaArgs = append(luaArgs, luar.New(ulua.L, bp)) + for _, v := range args { + luaArgs = append(luaArgs, luar.New(ulua.L, v)) + } + _, err := pl.Call(plFn, luaArgs...) + if err != nil { + screen.TermMessage(err) + } + } +} // CommandEditAction returns a bindable function that opens a prompt with // the given string and executes the command when the user presses @@ -456,7 +473,6 @@ func (h *BufPane) SetLocalCmd(args []string) { if err != nil { InfoBar.Error(err) } - } // ShowCmd shows the value of the given option diff --git a/internal/config/plugin.go b/internal/config/plugin.go index dffad485..e3f2e42b 100644 --- a/internal/config/plugin.go +++ b/internal/config/plugin.go @@ -95,9 +95,7 @@ func (p *Plugin) Load() error { return err } p.Loaded = true - if _, ok := GlobalSettings[p.Name]; !ok { - AddOption(p.Name, true) - } + RegisterGlobalOption(p.Name, true) } return nil } diff --git a/internal/config/runtime.go b/internal/config/runtime.go index 905b354b..baa0e43f 100644 --- a/internal/config/runtime.go +++ b/internal/config/runtime.go @@ -1071,7 +1071,7 @@ func runtimePluginsFtoptionsFtoptionsLua() (*asset, error) { return a, nil } -var _runtimePluginsLinterLinterLua = "\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xac\x58\x7b\x8f\xdb\xb8\x11\xff\xdf\x9f\x62\x20\x54\x80\x14\x4b\x5a\xb4\xe8\x5f\x02\x8c\x22\x6d\x73\x45\x8b\x5c\x52\x60\xd3\x07\x90\xe4\x0a\x5a\x1a\xd9\xbc\xa5\x48\x95\xa4\xec\x75\x17\xf9\xee\xc5\x90\x94\x4c\xf9\xb1\xbd\xb6\x67\xc0\xe2\x43\xf3\x9e\x1f\xc9\xa1\x84\x6a\x98\x00\x3d\x4a\xcb\x7b\x84\x0d\xf0\x7e\x50\xda\x66\x49\x98\x49\xf2\x95\xa7\xe8\xb8\xc0\x81\xd9\x7d\x44\x42\xc3\x87\x69\x7e\x26\x34\x7b\x14\x22\xa2\xea\x79\xa3\xd5\x83\x9b\x9d\x69\xb6\x63\xd7\xa1\xbe\x22\xf2\xd3\x33\x95\x9b\xbc\x24\x4a\xf2\x55\x78\x2d\xb8\xb4\xa8\x0d\x6c\xe0\xe5\xdb\x6a\x55\x96\xd0\x68\x64\x16\x0d\xb0\xf0\x0a\x50\x5a\x7d\x2a\xa0\x61\x42\x40\xa7\x55\x0f\x47\x6e\xf7\x5c\x02\x93\xc0\x25\xb7\x9c\x09\xfe\x2f\x66\xb9\x92\xd0\x8d\xb2\xa1\x4e\x01\x52\x59\x92\xd5\x72\x8d\x8d\x15\x27\x60\x76\xa2\x05\xa1\x58\x0b\x14\x94\x55\x59\x12\x8d\x64\x3d\xd6\xee\x09\xaa\x03\xbb\xc7\xa0\x97\xde\x51\x58\xec\x69\xc0\x7a\xee\x81\x55\xd0\xec\xb1\x79\x82\x4e\x69\x1a\x8c\x26\x66\x68\xfa\xb6\x86\x9e\x71\x39\x19\x3f\x68\xd5\xa0\x31\x60\xf7\x64\x82\x01\x7c\xc6\x66\xb4\xd8\x12\x31\xd3\x3b\x53\xd3\x73\xec\x51\x5a\x43\xd2\x06\x66\x5c\x7b\x36\x63\x92\x40\x0c\xf4\x23\x7d\x69\x47\x34\x1a\x29\xfa\x81\xb8\x19\xb5\x46\x69\x9d\x9d\xce\x99\x05\x7d\x7b\x97\xde\x47\x48\xe9\xd3\xcc\x84\x5a\x2b\xdd\x29\xdd\x33\x5b\xc3\x5e\x1d\xbd\x59\xda\x60\x64\xd4\x43\xa3\xfa\x81\x8b\xc8\x3f\x35\xda\x61\xb4\x93\xd2\xb4\xf3\x11\x2b\x20\x15\x35\xf1\x20\xc8\xb1\xdf\xa2\x2e\x20\xed\x6b\xaf\xe2\xe1\xc8\xb4\xe4\x72\x07\x3d\x1a\xc3\x76\x4e\xb7\x32\x44\x6d\x2c\x65\xe2\xe3\x23\x45\x8d\x9b\x29\x0e\xdc\x80\x19\x07\xc2\x10\xb6\xa0\x34\x8c\x32\x1a\xca\x49\xb3\x1a\x08\x00\x4c\x90\xc9\xac\x2f\xa0\xc5\x8e\x8d\xc2\xd6\xf0\xf9\x2b\x91\x1c\xf7\xdc\x22\x69\xa8\xc1\xec\xd5\x28\x5a\xe7\xd4\xc7\x47\xaf\x75\x8b\xc0\x60\x2b\x58\xf3\xe4\x86\x59\xab\x08\x48\xb4\xac\xe2\x84\xb8\xc4\xef\xd1\x10\x9f\xc9\x9d\xd9\x1a\xd8\x59\x34\x64\x4a\x8a\xd3\x7f\xe6\x7a\xd5\xdc\x8e\x09\x83\x90\x05\x23\x67\x9b\x1c\x63\xab\x7a\x66\x9b\xfd\xc2\x85\x19\x9f\x5b\x04\xa7\x70\xd0\x48\x91\x61\x6e\x21\x8d\x0c\x06\x66\x2d\x6a\x49\xd9\x74\xdc\x6e\x15\x91\x34\xe2\x66\x8d\x1d\xc3\xee\x40\x42\x0a\xf2\x28\x12\x1e\x5c\x70\x6e\xb1\xc6\xf2\x03\xb3\x08\xca\xad\x40\x7c\x66\x8d\xf5\x12\x7f\xaa\x4f\x1a\xff\x39\x72\x8d\x31\x6b\xbe\x9a\x96\x2e\xf4\xec\x09\xdf\x3b\x7d\x19\x21\xb2\x88\x8c\x6a\xfa\xb6\x70\x8b\xa6\x88\x41\x5a\x80\x32\xc5\x39\xfa\xc5\x14\x9e\x7c\x45\xc6\xf0\x6e\xda\x61\x3e\x93\xb8\xaf\xb0\xd9\x80\xe4\x82\xdc\x92\x8e\x80\x7e\x17\x14\xb4\x13\xdd\x7c\x55\xcd\x51\xde\xcc\x66\xdd\xa1\x6c\xfa\x16\x36\x64\xf1\x9d\xf7\xe4\x06\x6c\x9c\x37\x77\x28\x22\x17\x61\x13\x3b\x7c\x87\x5e\x91\x3c\x65\x28\x75\x77\xed\x3f\x63\x74\x13\xe1\x55\x69\x9f\x9a\x3b\x4c\x21\x9e\xb0\x99\x22\xbb\x64\x40\xd9\xae\xe8\x7f\x4e\xa1\xc6\x5e\x1d\xe2\x24\xfa\x54\x5c\x46\x59\x72\x71\xc1\x48\x5b\x74\x16\x88\xdd\xe1\xd0\xe2\x41\x8e\xee\x1c\x4a\x1e\x5a\x3c\x3c\xd0\x20\x99\xf2\x1a\xce\xb6\xea\x0f\x1f\x3f\x3e\x52\x5a\x93\x23\x97\xad\x3a\x9a\x64\x99\xdc\x48\xc6\x87\xbf\xbc\x4f\x66\x9b\x5d\x27\x42\x5b\xb2\x6b\x9a\xa4\x80\xc4\x3d\x7c\xff\x25\x29\x3b\x73\x92\x96\x3d\x97\x84\x7d\x7a\x51\xfe\x8d\x09\xe1\x3b\xf8\x6c\x35\xa3\x6e\xda\x25\xdf\x5c\x53\xa7\xa2\x4e\xdb\x75\x5d\xad\x6b\x48\xfb\x24\xbf\xab\x62\xbd\x7e\x45\x49\x52\x1a\xdb\x6e\x9a\xf5\xfa\x97\xbf\xfe\xff\x35\xb6\x7d\x4b\x0c\xfe\xe1\xfa\x2f\x49\xd9\x28\xa1\xf4\x46\x75\x9d\x13\xab\x4a\xd7\x1c\xfd\x93\xbb\xa6\x59\x68\x49\xb3\x54\xa4\xf9\x2b\x6e\xa9\xed\xc8\x85\xd3\xb1\x53\xf3\xf3\x25\x99\x67\x4b\x1a\x87\x44\x9c\x0d\xbf\x27\x8c\x80\x12\xcb\x0a\xe3\x97\x6b\xb7\x6f\x4b\xf8\x91\x1d\x98\x73\x80\x3a\x53\x1b\x42\xed\xcc\x49\xdb\xab\x20\xfa\x05\x76\x4f\xa0\xd9\x07\x93\x48\x92\x69\x34\x1f\xfc\x68\x9a\x8f\x4d\xf3\xc7\x5d\x2a\x8a\x6a\x5d\xdc\x16\x27\xb8\x45\xcd\x2c\x92\x88\x8b\x7e\xc8\xcf\x75\x8e\x7b\x7a\xf3\xad\xf0\xeb\xae\x00\xab\x47\xbc\x21\x78\x64\xae\x36\x71\xc2\x46\x16\x9a\x69\xea\x25\x29\x4b\xa9\x7c\xf2\x6f\x82\xe8\xb6\xb5\x92\x93\xee\x65\xf3\x92\xcc\x7a\xca\x92\xf6\x90\xef\x46\x21\xfe\xcc\xec\xde\xf8\x29\x63\x5b\x35\x5a\xdf\xa7\x10\x99\x3a\x80\x6d\xd6\x59\xa5\xa2\x80\xb4\x5d\x57\xb7\x95\x36\x82\xc9\x1d\x31\xa8\xed\x8f\x48\x27\x0e\xfa\xa0\x3c\x37\x7a\x94\xde\x80\x89\xe2\x67\x5e\xa2\xc3\xa9\x13\xec\x09\x9d\x23\xc3\xc9\xee\x95\xf4\xbd\x79\xf6\x02\x86\x55\x59\xff\xe6\xb6\xa4\xfe\x34\x9c\x96\x52\xc2\xcc\x85\x84\x7b\x76\x4c\xcb\x20\xb6\x62\x5e\x0a\x65\xe9\x2b\xae\xd2\x9f\x09\x1b\x57\xa1\xb1\xad\x40\x1f\x74\x8d\x54\x19\x99\x8d\x54\xd7\x48\xbf\xa9\xce\xec\xbb\xde\x69\xf3\x25\xbe\xeb\xf8\x99\x9f\xbc\xec\xcc\x91\xdb\xce\x65\xc9\x1c\x79\x67\x97\xe9\x72\x53\x37\x70\x7d\x4e\x05\x51\xb5\x4c\x1f\xb9\xa4\xf7\xb7\x01\x7e\xa1\xa2\xb9\x6d\x5e\x24\x50\x70\x39\x3e\xdf\x97\x77\x62\xbd\xf3\x35\x6e\xa3\x10\xfb\xd8\xba\xc8\x33\x6d\xa6\xe8\xde\xd0\xe7\x03\xb2\x3c\xcc\x1a\x25\x2d\xe3\xd2\x64\xbe\x2a\x41\x81\x54\xe5\x7b\x1b\xa8\x18\x7c\x2a\xe0\x00\x5c\xc2\xc0\xb8\xf6\x44\x39\xb4\x6a\x3e\xb6\x78\x07\x07\x3a\xd5\x02\xdf\xf2\x4c\xa3\x9f\x46\x3b\x52\x3d\xa7\xc7\xf3\xc1\x4d\x16\xc4\x6d\xa0\xf1\x87\xf5\xc5\x21\x3d\xca\x10\x85\xed\xd8\xc5\x67\x6e\x47\xc5\xc1\x76\xec\xea\xef\xb8\xc0\x4f\xa7\x01\x17\x27\xb2\xbb\x5f\xb8\xf7\x15\xad\xf7\xf8\xac\xe6\x3a\x94\x45\x74\x91\xac\x7e\xcf\x75\x46\x83\x7c\x75\xd7\x63\x57\x0e\x2c\x9c\x9e\x2c\x98\x0a\x0e\xb2\x65\x03\x87\xea\xaa\xd8\xa2\xe8\xcc\x85\xc9\x55\x68\xce\x02\x8c\xd5\x5c\xee\x2a\x37\xcc\x3a\x5b\x44\xb2\xf2\x45\xd4\x2e\x4c\xd8\x33\x43\x45\xc5\x39\x89\x87\x8a\xaa\xcc\xb8\xe4\xc8\x63\x63\xe8\x9a\xe0\x79\x98\x6c\xe1\x10\x15\x5a\xaf\x18\xb7\x2c\xba\xa6\x9c\x05\x89\x67\x69\x24\xfb\x7f\x96\x38\x0f\x42\x02\x98\xde\x9d\x53\x70\x70\x65\xe8\x22\x03\xf4\xf3\xd3\x9f\x9f\xbe\xfa\x02\xb5\xde\x99\x71\x9b\x25\x69\x4a\x3b\xb8\x4b\xe9\x3c\x43\xe7\x68\xcb\xf5\x9d\x50\xf2\x6e\x36\xed\xca\x66\xca\x3e\x21\xaf\x70\xa8\xa8\x5c\x69\xef\xf5\x52\x1b\x55\xbb\xf9\x4d\x70\x2f\xb1\xac\xe4\x23\x3b\x60\xb6\x1d\xc2\x0a\xe7\x8d\x56\xd5\x7b\xb5\xcb\x92\xc7\xb7\x7f\x7d\x17\xb6\xaa\x08\xf0\x43\xf5\xdb\x09\xf3\xaf\xac\x90\xb3\x89\x1e\xaa\xf7\x2e\x20\x5e\x10\xad\x98\xdf\x09\x64\xfa\x7b\x7f\x9d\x9d\x00\x1e\xf0\xef\xb6\xd5\xea\x4f\x6a\xfb\x38\xb0\xa3\xcc\x22\x49\x49\x12\xfe\x9e\xbe\x52\xf2\xdd\xb3\x2b\x04\x16\xaa\x17\xfa\x2e\xbd\x27\x86\xcc\x9f\x07\xaf\xb1\x5d\xc4\xe6\xe3\x87\x77\x7f\xff\xe3\xa7\xe4\x72\xde\xcb\x89\xd7\x3c\x15\x34\x74\xb9\x30\x83\x88\xf4\x24\x5f\x64\x12\x9c\x0b\x5f\x9f\x70\x87\xcf\xcb\xab\xca\x02\x3a\x49\x56\x55\x65\x9e\x9c\xd1\xe3\xb6\xdc\x2c\x6d\xd7\xf1\x64\xef\x29\x69\x6e\xde\x38\xfe\x51\xb8\x9a\x8a\x4b\xe0\xf3\xde\x81\x4b\xdc\x96\x25\x7c\xd2\xbc\xf7\xb7\x1a\x33\xb0\x66\x71\x9b\xa1\x2d\x8b\x9a\xda\x6f\x04\xc9\x0f\xa9\x79\x43\x3a\x52\xf3\xe6\x17\xc9\x62\x21\x87\x0d\xa3\xe3\xb2\x75\x5a\x0a\xef\x56\x7e\x03\xc1\xf3\x7e\xe8\xc2\x8d\x05\xf4\x66\x77\xb9\xe5\xc4\x22\x16\xdc\xbc\x83\x2d\x33\x48\x77\xa1\x6c\xda\x4c\x73\xda\xec\xe6\x59\xb7\xd2\xae\xd5\x9e\x55\x6f\xbd\x3e\xff\xb9\xad\xfa\x80\xc7\x80\xbc\xb7\xf6\x3d\x97\x98\x4d\x10\xe8\xcd\xae\x00\xab\xfc\xf7\x17\x67\x50\x5e\x4c\x4c\xdf\x7f\x7a\x47\xc9\xca\xaf\x34\x10\x9a\xdf\xb6\x6d\x90\x98\x91\xaa\x25\x51\xbc\x5b\xdd\x5f\x98\x1e\x31\xc6\xea\x02\x0c\x0e\xf9\x02\x2c\x66\x14\xf6\x7c\xd7\x5e\x42\x28\x4b\xb2\xcf\x3f\xa4\xe6\xab\x43\x86\x87\x52\x36\x0b\x20\x44\x20\x6b\xf6\x84\x07\x63\x75\xbd\xf3\xa1\x0e\x79\x8a\x30\x61\xe9\xc4\xae\xb8\x34\xa8\x6d\xe6\x15\x16\x8e\x33\xbf\x75\x48\x7a\x82\x0b\x07\x96\xd9\x88\x2c\x35\x38\xb8\x5b\xe9\x7f\x7b\x1b\x0d\x7c\x5f\xbe\x24\x0b\x1b\xbc\x50\xf7\x11\x72\x46\x90\x5b\x11\x1e\x5f\x49\x56\xbd\x49\xa0\xaa\x1c\x7b\x55\x41\x92\x67\xd5\x9b\xdc\x15\x23\xbf\x4a\x16\x1b\x99\xfb\x8a\x47\x52\xff\x1d\x00\x00\xff\xff\x9f\x7b\x2f\x98\x12\x16\x00\x00" +var _runtimePluginsLinterLinterLua = "\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xac\x58\xeb\x8f\xa4\xb8\x11\xff\x3e\x7f\x85\x85\x82\x04\x3b\xc0\x28\x51\x3e\x21\xb5\xa2\xcb\xe6\x2e\x52\xb4\x8f\x48\xb3\x51\x3e\xec\xee\x45\x6e\x28\xba\x7d\x63\x6c\x62\x9b\xee\xe9\x8c\xf6\x7f\x8f\xaa\x6c\xc0\xf4\x63\x6e\xf3\x18\x69\xb0\x31\xf5\xf8\xd5\xcb\x2e\xb7\xd4\x0d\x97\xcc\x8c\xca\x89\x1e\xd8\x86\x89\x7e\xd0\xc6\x65\x49\x58\x49\xf2\x3b\x4f\xd1\x09\x09\x03\x77\xfb\x88\x04\x5f\x1f\xa6\xf5\x99\xd0\xee\x41\xca\x88\xaa\x17\x8d\xd1\x0f\xb4\x3a\xd3\x6c\xc7\xae\x03\x73\x41\xe4\x97\x67\xaa\x46\xab\x4e\xec\x2e\xa8\xfc\x72\x92\xdf\x05\x32\x29\x94\x03\x63\xd9\x86\xbd\x7c\xbb\xbb\x2b\x4b\xd6\x18\xe0\x0e\x2c\xe3\xe1\x13\x03\xe5\xcc\xa9\x60\x0d\x97\x92\x75\x46\xf7\xec\x28\xdc\x5e\x28\xc6\x15\x13\x4a\x38\xc1\xa5\xf8\x17\x77\x42\x2b\xd6\x8d\xaa\xc1\x49\xc1\x94\x76\x28\xab\x15\x06\x1a\x27\x4f\x8c\xbb\x89\x96\x49\xcd\x5b\x86\xce\xb9\x2b\x4b\xa4\x51\xbc\x87\x9a\x9e\x4c\x77\xcc\xed\x21\xe8\xc5\x6f\xe8\x1e\x77\x1a\xa0\x9e\x67\xcc\x69\xd6\xec\xa1\x79\x62\x9d\x36\xf8\x32\xda\x98\xa1\xe9\xdb\x9a\xf5\x5c\xa8\x09\xfc\x60\x74\x03\xd6\x32\xb7\x47\x08\x96\xc1\x33\x34\xa3\x83\x16\x89\xb9\xd9\xd9\x1a\x9f\x63\x0f\xca\x59\x94\x36\x70\x4b\xe3\x02\x63\x92\x80\x0c\xf8\x87\xfa\xd2\x0e\x69\x0c\x60\x14\x02\x71\x33\x1a\x03\xca\x11\x4e\x32\x66\x45\xdf\xde\xa4\xf7\x1e\xd2\xe6\x34\x33\x81\x31\xda\x74\xda\xf4\xdc\xd5\x6c\xaf\x8f\x1e\x96\xb1\x10\x81\x7a\x68\x74\x3f\x08\x19\xd9\xa7\x47\x37\x8c\x6e\x52\x9a\x76\xde\x63\x05\x4b\x65\x8d\x3c\xc0\xd4\xd8\x6f\xc1\x14\x2c\xed\x6b\xaf\xe2\xe1\xc8\x8d\x12\x6a\xc7\x7a\xb0\x96\xef\x48\xb7\xb6\x48\x6d\x1d\x46\xe2\xe3\x23\x7a\x4d\xd8\xc9\x0f\xc2\x32\x3b\x0e\x98\x4a\xd0\x32\x6d\xd8\xa8\xa2\x57\x35\x69\xd6\x03\x26\x00\x97\x08\x99\xf7\x05\x6b\xa1\xe3\xa3\x74\x35\xfb\xfc\x15\x49\x8e\x7b\xe1\x00\x35\xd4\xcc\xee\xf5\x28\x5b\x32\xea\xe3\xa3\xd7\xba\x05\xc6\xd9\x56\xf2\xe6\x89\x5e\xb3\x56\x63\x22\x61\x79\xc5\x01\xa1\xc0\xef\xc1\x22\x9f\xcd\x09\xb6\x61\x7c\x11\xcd\x32\xad\xe4\xe9\xd7\xb9\x5e\x85\xdb\x71\x69\x81\x65\x01\xe4\x8c\x89\x18\x5b\xdd\x73\xd7\xec\x57\x26\xcc\xf9\xb9\x05\x46\x0a\x07\x03\xe8\x19\x4e\x85\x34\x72\x36\x70\xe7\xc0\x28\x8c\x26\x71\x53\x15\xa1\x34\xe4\xe6\x8d\x1b\xc3\x2e\x81\x42\x0a\xb4\x28\x12\x1e\x4c\x20\xb3\x78\xe3\xc4\x81\x3b\x60\x9a\x2a\x10\x9e\x79\xe3\xbc\xc4\xef\xb5\xc9\xc0\x3f\x47\x61\x20\x66\xcd\xef\xa6\xd2\x65\x3d\x7f\x82\x77\xa4\x2f\xc3\x8c\x2c\x22\x50\x4d\xdf\x16\x54\x34\x45\x9c\xa4\x05\xd3\xb6\x58\xbc\x5f\x4c\xee\xc9\xef\x10\x8c\xe8\xa6\x1d\xe6\x33\x8a\xfb\xca\x36\x1b\xa6\x84\x44\xb3\x14\x11\xe0\xdf\x19\x05\xee\x44\x57\x3f\x55\xb3\x97\x37\x33\xac\x1b\x94\x4d\xdf\xb2\x0d\x22\xbe\xf1\x1d\xcd\x60\x1b\xb2\xe6\x06\x45\x64\x22\xdb\xc4\x06\xdf\xa0\xd7\x28\x4f\x5b\x0c\xdd\x4d\xfc\x4b\x8e\x6e\xa2\x7c\xd5\xc6\x87\xe6\x06\x53\xf0\x27\xdb\x4c\x9e\x5d\x33\x80\x6a\xef\xf0\x7f\x09\xa1\x81\x5e\x1f\xe2\x20\xfa\x50\x9c\x7b\x59\x09\x79\xc6\x88\x5b\x74\x16\x88\xe9\x70\x68\xe1\xa0\x46\x3a\x8f\x92\x87\x16\x0e\x0f\xf8\x92\x4c\x71\x0d\x67\x5c\xf5\xe7\x8f\x1f\x1f\x31\xac\xc9\x51\xa8\x56\x1f\x6d\xb2\x0e\x6e\x24\xe3\xc3\xdf\xde\x25\x33\x66\x9a\x44\xd9\x96\xec\x9a\x26\x29\x58\x42\x0f\x3f\x7f\x49\xca\xce\x9e\x94\xe3\xcf\x25\xe6\x3e\x7e\x28\xff\xce\xa5\xf4\x13\x78\x76\x86\xe3\x34\xed\x92\x6f\x34\xd4\xa9\xac\xd3\xf6\xbe\xae\xee\x6b\x96\xf6\x49\x7e\x53\xc5\xfd\xfd\x2b\x4a\x92\xd2\xba\x76\xd3\xdc\xdf\xff\xf6\xf7\xff\xbb\xc6\xb6\x6f\x91\xc1\x3f\x68\xfe\x92\x94\x8d\x96\xda\x6c\x74\xd7\x91\x58\x5d\xd2\x70\xf4\x4f\x41\x43\xb3\xd2\x92\x66\xa9\x4c\xf3\x57\xcc\xd2\xdb\x51\x48\xd2\xb1\xd3\xf3\xf3\x25\x99\x57\x4b\x7c\x0f\x81\x58\x80\xdf\x12\x86\x89\x12\xcb\x0a\xef\x2f\x97\x66\x5f\x97\xf0\x0b\x3f\x70\x32\x00\x27\xd3\x18\x5c\x4d\x70\xd2\xf6\xc2\x89\xbe\xc0\x6e\x09\xb4\xfb\x00\x09\x25\xd9\xc6\x88\xc1\xbf\x4d\xeb\x31\x34\x7f\xdc\xa5\xb2\xa8\xee\x8b\xeb\xe2\xa4\x70\x60\xb8\x03\x14\x71\x36\x0f\xf1\xb9\x8c\x71\x8f\x5f\xbe\x15\xbe\xee\x0a\xe6\xcc\x08\x57\x04\x8f\x9c\x7a\x13\x12\x36\xf2\x30\x4c\x4b\x2f\x49\x59\x2a\xed\x83\x7f\x35\x89\xae\xa3\x55\x02\x75\xaf\x87\x97\x64\xd6\x53\x96\xb8\x87\xfc\x34\x4a\xf9\x57\xee\xf6\xd6\x2f\x59\xd7\xea\xd1\xf9\x39\xba\xc8\xd6\x21\xd9\x66\x9d\x55\x2a\x0b\x96\xb6\xf7\xd5\x75\xa5\x8d\xe4\x6a\x87\x0c\x7a\xfb\x0b\xe0\x89\x03\xde\x29\xcf\x8d\x19\x95\x07\x30\x51\xfc\x9f\x4b\x74\x38\x75\x92\x3f\x01\x19\x32\x9c\xdc\x5e\x2b\x3f\x9b\x57\xcf\xd2\xb0\x2a\xeb\x3f\x5c\x97\xd4\x9f\x86\xd3\x5a\x4a\x58\x39\x93\x70\x0b\xc7\x54\x06\x31\x8a\xb9\x14\xca\xd2\x77\x5c\xa5\x3f\x13\x36\xd4\xa1\xf1\xad\x04\xef\x74\x03\xd8\x19\xd9\x8d\xd2\x97\x99\x7e\x55\x9d\xdd\x77\x3d\x69\xf3\xad\x3e\x4d\xfc\xca\x77\x97\x9d\x3d\x0a\xd7\x51\x94\xec\x51\x74\x6e\x1d\x2e\x5a\xba\x92\xd7\x4b\x28\x90\xaa\xe5\xe6\x28\x14\x7e\xbf\x9e\xe0\x67\x2a\x9a\xeb\xf0\x22\x81\x52\xa8\xf1\xf9\xb6\xbc\x13\xef\xc9\xd6\x78\x8c\x5c\xec\x7d\x4b\x9e\xe7\xc6\x4e\xde\xbd\xa2\xcf\x3b\x84\xc4\xfb\xfb\x4d\xf5\x9e\x3f\xc1\x5b\xdd\xf7\x5c\xb5\x58\xf0\x3e\x92\xfe\x04\xac\x70\x78\x4b\x7b\x71\x20\xfe\xa0\xdf\xea\x7e\x90\xe0\x20\x3f\x3b\x11\x03\x69\xb6\x1d\x3c\xf8\xed\x50\x3f\xf2\x03\x84\x43\xd2\x8c\x2a\x58\xb2\x1d\xaa\x3f\x8e\xdd\x39\x77\xa3\x95\xe3\x42\xd9\xcc\x37\x46\x20\x01\x2f\x1a\x9e\x17\xfb\xd1\xa7\x82\x1d\x98\x50\x6c\xe0\xc2\x78\xa2\x9c\xb5\x7a\x3e\x39\x45\xc7\x0e\x78\xb0\x06\xbe\xf5\xb1\x4a\xfa\xc1\x8d\xd8\x52\x9a\x71\xe9\x1d\x10\x41\x3c\x06\x1a\xdf\x2f\x9c\xf5\x09\x0b\x7c\xc4\xbe\x1c\xfb\x1d\xf6\x27\xdb\xb1\xab\x7f\x12\x12\x3e\x9d\x06\x58\x35\x05\x74\xc5\xa1\xef\x15\x6e\x39\x71\xbb\x20\x4c\xe8\xcc\xf0\x4e\x5b\xfd\x49\x98\x0c\x5f\x42\x64\xae\x59\x4c\x1d\xc9\xca\xe8\x09\xc1\xd4\xf3\x20\x96\x0d\x3b\x54\x17\xfd\x1e\x7a\x67\xee\x8d\x2e\x5c\xb3\x08\xb0\xce\x08\xb5\xab\xe8\x35\xeb\x5c\x11\xc9\xca\x57\x5e\x3b\x83\xb0\xe7\x16\xfb\x9a\x25\x88\x87\x0a\x1b\xdd\xb8\xeb\xc9\x63\x30\x78\x53\xf1\x3c\x5c\xb5\xec\x10\xf5\x7a\xaf\x80\x5b\xf7\x7d\x53\xcc\x82\xc4\x45\x1a\xca\xfe\xaf\x25\xce\x2f\x21\x00\xdc\xec\x96\x10\x1c\xa8\x13\x5e\x45\x00\xff\xfc\xf2\xe7\xa7\xaf\xbe\x47\xae\x77\x76\xdc\x66\x49\x9a\xe2\x21\x42\x21\x9d\x57\xb0\x8c\x5a\x61\x6e\xb8\x52\x74\x33\xb4\x0b\xcc\x18\x7d\xcc\xbc\x82\xb2\xa2\xa2\xdb\x85\xd7\x8b\x63\xd4\x70\xe7\x57\x93\x7b\x9d\xcb\x5a\x51\x5d\x4e\x75\x7a\x59\x99\xbf\x52\x0b\x0b\x18\x9f\x94\xb7\x6e\x3b\x61\x1b\x18\xbb\xfa\xad\x04\x6e\xde\xfb\xbb\xb3\xcd\xc2\xde\x32\xed\x42\xb4\x8b\x57\x7f\xd1\xdb\xc7\x81\x1f\x55\x16\xc9\x4a\x92\xf0\x1f\x36\x23\xad\x7e\x7c\xa6\xbe\x63\xa5\x7c\xa5\xf1\xdc\x52\x64\xc8\xfc\xf1\xf3\x1a\xdb\x92\xca\xd8\x11\xe1\xed\xc4\x0e\x32\xe2\x4c\xbe\xa8\x09\x6e\xf8\x19\x0b\x76\xf0\xbc\xbe\xeb\xac\x02\x9f\x64\x55\x55\xe6\xc9\x12\x7b\xda\xb3\xb3\xb4\xbd\x8f\x17\x7b\x4f\x89\x6b\x73\xd9\xff\xa3\xa0\xa6\x4c\x28\x26\xe6\xca\x87\x75\xd6\x95\x25\xfb\x64\x44\xef\xaf\x45\x76\xe0\xcd\xea\x3a\x84\x1b\x0e\x0e\xb5\x2f\xe3\xe4\xe7\xd4\xbe\x41\x1d\xa9\x7d\xf3\x9b\x64\x55\x86\xa1\xdc\x3b\xa1\x5a\xd2\x52\x78\xb3\xf2\x2b\xf9\x37\xef\x66\xe4\x40\x28\x58\x6f\x77\xe7\x1b\x46\x2c\x62\xc5\x2d\x3a\xb6\xe5\x16\xf0\x32\x95\x4d\x5b\x61\x8e\x5b\xd5\xbc\x4a\x75\x72\xa9\x76\x51\xbd\xf5\xfa\xfc\xef\x76\xd5\x07\x38\x86\x6c\xfa\xc1\xbd\x13\x0a\xe6\x94\x22\x5c\x05\x73\xda\xff\x84\x43\x90\xf2\x62\x62\x7b\xff\xe9\x47\x0c\x57\x7e\xa1\x03\x73\xf4\x87\xb6\x0d\x32\x33\x54\xb6\x26\x8a\x77\x9b\xdb\x85\xe5\x73\xc6\x3a\x53\x30\x0b\x43\xbe\x4a\x17\x3b\x4a\xb7\x5c\xd7\xd7\x49\x94\x25\xd9\xe7\x9f\x53\xfb\x95\x72\xc3\x27\x53\x36\x0b\xc0\x9c\x00\xde\xec\x31\x23\xac\x33\xf5\xce\x3b\x3b\x44\x2a\xca\x0a\x87\x87\x7e\x25\x94\x05\xe3\x32\xaf\xb0\x20\xce\xfc\xda\x21\xe7\x09\xce\x0c\x58\xc7\x23\x42\x6a\x61\xa0\x8b\xed\x7f\x7a\xa1\x0d\x7c\x5f\xbe\x24\x2b\x0c\x5e\x28\xfd\x8e\x39\xe7\x10\xd5\x84\xcf\xb0\x24\xab\xde\x24\xac\xaa\x88\xbd\xaa\x58\x92\x67\xd5\x9b\x9c\xfa\x99\xdf\x25\xab\xed\x89\x7e\x08\x44\xa9\xff\x0e\x00\x00\xff\xff\xb6\x46\x5d\xee\x5d\x16\x00\x00" func runtimePluginsLinterLinterLuaBytes() ([]byte, error) { return bindataRead( diff --git a/internal/config/settings.go b/internal/config/settings.go index a775a1c0..7a7df05a 100644 --- a/internal/config/settings.go +++ b/internal/config/settings.go @@ -114,12 +114,35 @@ func WriteSettings(filename string) error { return err } -// AddOption creates a new option. This is meant to be called by plugins to add options. -func AddOption(name string, value interface{}) error { - GlobalSettings[name] = value - err := WriteSettings(ConfigDir + "/settings.json") - if err != nil { - return errors.New("Error writing settings.json file: " + err.Error()) +// RegisterCommonOption creates a new option. This is meant to be called by plugins to add options. +func RegisterCommonOption(name string, defaultvalue interface{}) error { + if v, ok := GlobalSettings[name]; !ok { + defaultCommonSettings[name] = defaultvalue + GlobalSettings[name] = defaultvalue + err := WriteSettings(ConfigDir + "/settings.json") + if err != nil { + return errors.New("Error writing settings.json file: " + err.Error()) + } + } else { + defaultCommonSettings[name] = v + } + return nil +} + +func RegisterLocalOption(name string, defaultvalue interface{}) { + defaultLocalSettings[name] = defaultvalue +} + +func RegisterGlobalOption(name string, defaultvalue interface{}) error { + if v, ok := GlobalSettings[name]; !ok { + defaultGlobalSettings[name] = defaultvalue + GlobalSettings[name] = defaultvalue + err := WriteSettings(ConfigDir + "/settings.json") + if err != nil { + return errors.New("Error writing settings.json file: " + err.Error()) + } + } else { + defaultGlobalSettings[name] = v } return nil } @@ -129,42 +152,40 @@ func GetGlobalOption(name string) interface{} { return GlobalSettings[name] } -func DefaultCommonSettings() map[string]interface{} { - return map[string]interface{}{ - "autoindent": true, - "autosave": false, - "basename": false, - "colorcolumn": float64(0), - "cursorline": true, - "encoding": "utf-8", - "eofnewline": false, - "fastdirty": true, - "fileformat": "unix", - "ignorecase": false, - "indentchar": " ", - "keepautoindent": false, - "matchbrace": false, - "matchbraceleft": false, - "rmtrailingws": false, - "ruler": true, - "savecursor": false, - "saveundo": false, - "scrollbar": false, - "scrollmargin": float64(3), - "scrollspeed": float64(2), - "smartpaste": true, - "softwrap": false, - "splitbottom": true, - "splitright": true, - "statusformatl": "$(filename) $(modified)($(line),$(col)) $(opt:filetype) $(opt:fileformat) $(opt:encoding)", - "statusformatr": "$(bind:ToggleKeyMenu): show bindings, $(bind:ToggleHelp): toggle help", - "statusline": true, - "syntax": true, - "tabmovement": false, - "tabsize": float64(4), - "tabstospaces": false, - "useprimary": true, - } +var defaultCommonSettings = map[string]interface{}{ + "autoindent": true, + "autosave": false, + "basename": false, + "colorcolumn": float64(0), + "cursorline": true, + "encoding": "utf-8", + "eofnewline": false, + "fastdirty": true, + "fileformat": "unix", + "ignorecase": false, + "indentchar": " ", + "keepautoindent": false, + "matchbrace": false, + "matchbraceleft": false, + "rmtrailingws": false, + "ruler": true, + "savecursor": false, + "saveundo": false, + "scrollbar": false, + "scrollmargin": float64(3), + "scrollspeed": float64(2), + "smartpaste": true, + "softwrap": false, + "splitbottom": true, + "splitright": true, + "statusformatl": "$(filename) $(modified)($(line),$(col)) $(opt:filetype) $(opt:fileformat) $(opt:encoding)", + "statusformatr": "$(bind:ToggleKeyMenu): show bindings, $(bind:ToggleHelp): toggle help", + "statusline": true, + "syntax": true, + "tabmovement": false, + "tabsize": float64(4), + "tabstospaces": false, + "useprimary": true, } func GetInfoBarOffset() int { @@ -178,41 +199,64 @@ func GetInfoBarOffset() int { return offset } +var defaultGlobalSettings = map[string]interface{}{ + "colorscheme": "default", + "infobar": true, + "keymenu": false, + "mouse": true, + "savehistory": true, + "sucmd": "sudo", + "termtitle": false, +} + // DefaultGlobalSettings returns the default global settings for micro // Note that colorscheme is a global only option func DefaultGlobalSettings() map[string]interface{} { - common := DefaultCommonSettings() - common["colorscheme"] = "default" - common["infobar"] = true - common["keymenu"] = false - common["mouse"] = true - common["pluginchannels"] = []string{"https://raw.githubusercontent.com/micro-editor/plugin-channel/master/channel.json"} - common["pluginrepos"] = []string{} - common["savehistory"] = true - common["sucmd"] = "sudo" - common["termtitle"] = false - return common + globalsettings := make(map[string]interface{}) + for k, v := range defaultCommonSettings { + globalsettings[k] = v + } + for k, v := range defaultGlobalSettings { + globalsettings[k] = v + } + return globalsettings } // LocalSettings is a list of the local only settings var LocalSettings = []string{"filetype", "readonly"} +var defaultLocalSettings = map[string]interface{}{ + "filetype": "unknown", + "readonly": false, +} + // DefaultLocalSettings returns the default local settings // Note that filetype is a local only option func DefaultLocalSettings() map[string]interface{} { - common := DefaultCommonSettings() - common["filetype"] = "unknown" - common["readonly"] = false - return common + localsettings := make(map[string]interface{}) + for k, v := range defaultCommonSettings { + localsettings[k] = v + } + for k, v := range defaultLocalSettings { + localsettings[k] = v + } + return localsettings } +// DefaultAllSettings returns a map of all settings and their +// default values (both local and global settings) func DefaultAllSettings() map[string]interface{} { - global := DefaultGlobalSettings() - local := DefaultLocalSettings() - for k, v := range global { - local[k] = v + allsettings := make(map[string]interface{}) + for k, v := range defaultCommonSettings { + allsettings[k] = v } - return local + for k, v := range defaultGlobalSettings { + allsettings[k] = v + } + for k, v := range defaultLocalSettings { + allsettings[k] = v + } + return allsettings } func GetNativeValue(option string, realValue interface{}, value string) (interface{}, error) { diff --git a/runtime/plugins/linter/linter.lua b/runtime/plugins/linter/linter.lua index 46be745b..f7c093e9 100644 --- a/runtime/plugins/linter/linter.lua +++ b/runtime/plugins/linter/linter.lua @@ -2,7 +2,7 @@ local runtime = import("runtime") local filepath = import("path/filepath") local shell = import("micro/shell") local buffer = import("micro/buffer") -local micro = import("micro") +local config = import("micro/config") local linters = {} @@ -66,6 +66,13 @@ function init() makeLinter("switfc", "swift", "xcrun", {"swiftc", "%f"}, "%f:%l:%d+:.+: %m", {"darwin"}, true) makeLinter("switfc", "swiftc", {"%f"}, "%f:%l:%d+:.+: %m", {"linux"}, true) makeLinter("yaml", "yaml", "yamllint", {"--format", "parsable", "%f"}, "%f:%l:%d+:.+ %m") + + config.MakeCommand("lint", "linter.lintCmd", config.NoComplete) +end + +function lintCmd(bp) + bp:Save() + runLinter(bp.Buf) end function contains(list, element) @@ -107,7 +114,6 @@ function runLinter(buf) end function onSave(bp) - micro.Log("SAVE") runLinter(bp.Buf) return false end @@ -119,8 +125,6 @@ function lint(buf, linter, cmd, args, errorformat) end function onExit(output, buf, linter, errorformat) - micro.Log("ONEXIT") - micro.Log(output) local lines = split(output, "\n") local regex = errorformat:gsub("%%f", "(..-)"):gsub("%%l", "(%d+)"):gsub("%%m", "(.+)")