mirror of
https://github.com/zyedidia/micro.git
synced 2026-03-25 18:07:07 +09:00
Make setting options global
This commit is contained in:
@@ -165,12 +165,14 @@ func NewTab(args []string) {
|
|||||||
|
|
||||||
// Set sets an option
|
// Set sets an option
|
||||||
func Set(args []string) {
|
func Set(args []string) {
|
||||||
// Set an option and we have to set it for every view
|
if len(args) < 2 {
|
||||||
for _, tab := range tabs {
|
return
|
||||||
for _, view := range tab.views {
|
|
||||||
SetOption(view, args)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
option := strings.TrimSpace(args[0])
|
||||||
|
value := strings.TrimSpace(args[1])
|
||||||
|
|
||||||
|
SetOption(option, value)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bind creates a new keybinding
|
// Bind creates a new keybinding
|
||||||
|
|||||||
@@ -262,6 +262,7 @@ func main() {
|
|||||||
L.SetGlobal("messenger", luar.New(L, messenger))
|
L.SetGlobal("messenger", luar.New(L, messenger))
|
||||||
L.SetGlobal("GetOption", luar.New(L, GetOption))
|
L.SetGlobal("GetOption", luar.New(L, GetOption))
|
||||||
L.SetGlobal("AddOption", luar.New(L, AddOption))
|
L.SetGlobal("AddOption", luar.New(L, AddOption))
|
||||||
|
L.SetGlobal("SetOption", luar.New(L, SetOption))
|
||||||
L.SetGlobal("BindKey", luar.New(L, BindKey))
|
L.SetGlobal("BindKey", luar.New(L, BindKey))
|
||||||
L.SetGlobal("MakeCommand", luar.New(L, MakeCommand))
|
L.SetGlobal("MakeCommand", luar.New(L, MakeCommand))
|
||||||
L.SetGlobal("CurView", luar.New(L, CurView))
|
L.SetGlobal("CurView", luar.New(L, CurView))
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"reflect"
|
"reflect"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// The options that the user can set
|
// The options that the user can set
|
||||||
@@ -90,12 +89,8 @@ func DefaultSettings() map[string]interface{} {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SetOption prompts the user to set an option and checks that the response is valid
|
// SetOption prompts the user to set an option and checks that the response is valid
|
||||||
func SetOption(view *View, args []string) {
|
func SetOption(option, value string) {
|
||||||
filename := configDir + "/settings.json"
|
filename := configDir + "/settings.json"
|
||||||
if len(args) == 2 {
|
|
||||||
option := strings.TrimSpace(args[0])
|
|
||||||
value := strings.TrimSpace(args[1])
|
|
||||||
|
|
||||||
if _, ok := settings[option]; !ok {
|
if _, ok := settings[option]; !ok {
|
||||||
messenger.Error(option + " is not a valid option")
|
messenger.Error(option + " is not a valid option")
|
||||||
return
|
return
|
||||||
@@ -122,11 +117,25 @@ func SetOption(view *View, args []string) {
|
|||||||
|
|
||||||
if option == "colorscheme" {
|
if option == "colorscheme" {
|
||||||
LoadSyntaxFiles()
|
LoadSyntaxFiles()
|
||||||
|
for _, tab := range tabs {
|
||||||
|
for _, view := range tab.views {
|
||||||
view.Buf.UpdateRules()
|
view.Buf.UpdateRules()
|
||||||
|
if settings["syntax"].(bool) {
|
||||||
|
view.matches = Match(view)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if option == "statusline" {
|
if option == "statusline" {
|
||||||
|
for _, tab := range tabs {
|
||||||
|
for _, view := range tab.views {
|
||||||
view.ToggleStatusLine()
|
view.ToggleStatusLine()
|
||||||
|
if settings["syntax"].(bool) {
|
||||||
|
view.matches = Match(view)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
err := WriteSettings(filename)
|
err := WriteSettings(filename)
|
||||||
@@ -134,7 +143,4 @@ func SetOption(view *View, args []string) {
|
|||||||
messenger.Error("Error writing to settings.json: " + err.Error())
|
messenger.Error("Error writing to settings.json: " + err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
messenger.Error("No value given")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user