diff --git a/cmd/micro/micro.go b/cmd/micro/micro.go index 26ab46ef..caccd976 100644 --- a/cmd/micro/micro.go +++ b/cmd/micro/micro.go @@ -195,7 +195,6 @@ func main() { LoadSyntaxFiles() // Load the help files LoadHelp() - LoadPlugins() buf := NewBuffer(string(input), filename) @@ -219,6 +218,10 @@ func main() { L.SetGlobal("view", luar.New(L, view)) L.SetGlobal("settings", luar.New(L, &settings)) L.SetGlobal("messenger", luar.New(L, messenger)) + L.SetGlobal("GetOption", luar.New(L, GetOption)) + L.SetGlobal("AddOption", luar.New(L, AddOption)) + + LoadPlugins() for { // Display everything diff --git a/cmd/micro/settings.go b/cmd/micro/settings.go index 2e409f54..b0818db8 100644 --- a/cmd/micro/settings.go +++ b/cmd/micro/settings.go @@ -55,6 +55,20 @@ 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{}) { + settings[name] = value + err := WriteSettings(configDir + "/settings.json") + if err != nil { + TermMessage("Error writing settings.json file: " + err.Error()) + } +} + +// GetOption returns the specified option. This is meant to be called by plugins to add options. +func GetOption(name string) interface{} { + return settings[name] +} + // DefaultSettings returns the default settings for micro func DefaultSettings() map[string]interface{} { return map[string]interface{}{ @@ -64,8 +78,6 @@ func DefaultSettings() map[string]interface{} { "syntax": true, "tabsToSpaces": false, "ruler": true, - "gofmt": false, - "goimports": false, } } diff --git a/runtime/help/help.md b/runtime/help/help.md index 1832c8cc..eb550ae2 100644 --- a/runtime/help/help.md +++ b/runtime/help/help.md @@ -195,20 +195,7 @@ Here are the options that you can set: default value: `on` -* `gofmt`: Run `gofmt` whenever the file is saved (this only applies to `.go` - files) - - default value: `off` - -* `goimports`: run `goimports` whenever the file is saved (this only applies - to `.go` files) - - default value: `off` - Any option you set in the editor will be saved to the file ~/.config/micro/settings.json so, in effect, your configuration file will be created for you. If you'd like to take your configuration with you to another machine, simply copy the settings.json to the other machine. - -In the future, the `gofmt` and `goimports` will be refactored using a plugin -system. However, currently they make it easier to program micro in micro. diff --git a/runtime/plugins/go/go.lua b/runtime/plugins/go/go.lua index 3500e8da..4b2fcd8e 100644 --- a/runtime/plugins/go/go.lua +++ b/runtime/plugins/go/go.lua @@ -1,8 +1,15 @@ +if GetOption("goimports") == nil then + AddOption("goimports", false) +end +if GetOption("gofmt") == nil then + AddOption("gofmt", true) +end + function go_onSave() if view.Buf.Filetype == "Go" then - if settings.GoImports then + if GetOption("goimports") then go_goimports() - elseif settings.GoFmt then + elseif GetOption("gofmt") then go_gofmt() end go_build()