Skip to content

Commit 41a8ce5

Browse files
Merge branch 'LockConfig' into dev
2 parents 7fec36d + 6bbee89 commit 41a8ce5

File tree

6 files changed

+37
-3
lines changed

6 files changed

+37
-3
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
> - [Adding Jumping to opening and closing brace logic and actions #3384](https://github.com/zyedidia/micro/pull/3384)
1515
> - [Adding auto complete support for multi cursors #3442](https://github.com/zyedidia/micro/pull/3442)
1616
> - [Fixing comment plugin not using user settings when overriding default setting #3424](https://github.com/zyedidia/micro/pull/3424)
17+
> - [Add the ability lock settings.json and bindings.json for plugins #3618](https://github.com/zyedidia/micro/pull/3618)
1718
>
1819
> To see the diff between this and upstream master, click [here](https://github.com/zyedidia/micro/compare/master...Neko-Box-Coder:micro-dev:dev)
1920

cmd/micro/initlua.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func luaImportMicroConfig() *lua.LTable {
7373
ulua.L.SetField(pkg, "OptionComplete", luar.New(ulua.L, action.OptionComplete))
7474
ulua.L.SetField(pkg, "OptionValueComplete", luar.New(ulua.L, action.OptionValueComplete))
7575
ulua.L.SetField(pkg, "NoComplete", luar.New(ulua.L, nil))
76-
ulua.L.SetField(pkg, "TryBindKey", luar.New(ulua.L, action.TryBindKey))
76+
ulua.L.SetField(pkg, "TryBindKey", luar.New(ulua.L, action.TryBindKeyPlug))
7777
ulua.L.SetField(pkg, "Reload", luar.New(ulua.L, action.ReloadConfig))
7878
ulua.L.SetField(pkg, "AddRuntimeFileFromMemory", luar.New(ulua.L, config.PluginAddRuntimeFileFromMemory))
7979
ulua.L.SetField(pkg, "AddRuntimeFilesFromDirectory", luar.New(ulua.L, config.PluginAddRuntimeFilesFromDirectory))
@@ -88,8 +88,8 @@ func luaImportMicroConfig() *lua.LTable {
8888
ulua.L.SetField(pkg, "RegisterCommonOption", luar.New(ulua.L, config.RegisterCommonOptionPlug))
8989
ulua.L.SetField(pkg, "RegisterGlobalOption", luar.New(ulua.L, config.RegisterGlobalOptionPlug))
9090
ulua.L.SetField(pkg, "GetGlobalOption", luar.New(ulua.L, config.GetGlobalOption))
91-
ulua.L.SetField(pkg, "SetGlobalOption", luar.New(ulua.L, action.SetGlobalOption))
92-
ulua.L.SetField(pkg, "SetGlobalOptionNative", luar.New(ulua.L, action.SetGlobalOptionNative))
91+
ulua.L.SetField(pkg, "SetGlobalOption", luar.New(ulua.L, action.SetGlobalOptionPlug))
92+
ulua.L.SetField(pkg, "SetGlobalOptionNative", luar.New(ulua.L, action.SetGlobalOptionNativePlug))
9393
ulua.L.SetField(pkg, "ConfigDir", luar.New(ulua.L, config.ConfigDir))
9494

9595
return pkg

internal/action/bindings.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,13 @@ func eventsEqual(e1 Event, e2 Event) bool {
256256
return e1 == e2
257257
}
258258

259+
func TryBindKeyPlug(k, v string, overwrite bool) (bool, error) {
260+
if l, ok := config.GlobalSettings["lockbindings"]; ok && l.(bool) {
261+
return false, errors.New("bindings.json file locked by user for all plugins")
262+
}
263+
return TryBindKey(k, v, overwrite)
264+
}
265+
259266
// TryBindKey tries to bind a key by writing to config.ConfigDir/bindings.json
260267
// Returns true if the keybinding already existed and a possible error
261268
func TryBindKey(k, v string, overwrite bool) (bool, error) {

internal/action/command.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -657,6 +657,13 @@ func doSetGlobalOptionNative(option string, nativeValue interface{}) error {
657657
return nil
658658
}
659659

660+
func SetGlobalOptionNativePlug(option string, nativeValue interface{}) error {
661+
if l, ok := config.GlobalSettings["locksettings"]; ok && l.(bool) {
662+
return errors.New("settings.json file locked by user for all plugins")
663+
}
664+
return SetGlobalOptionNative(option, nativeValue)
665+
}
666+
660667
func SetGlobalOptionNative(option string, nativeValue interface{}) error {
661668
if err := config.OptionIsValid(option, nativeValue); err != nil {
662669
return err
@@ -683,6 +690,13 @@ func SetGlobalOptionNative(option string, nativeValue interface{}) error {
683690
return config.WriteSettings(filepath.Join(config.ConfigDir, "settings.json"))
684691
}
685692

693+
func SetGlobalOptionPlug(option, value string) error {
694+
if l, ok := config.GlobalSettings["locksettings"]; ok && l.(bool) {
695+
return errors.New("settings.json file locked by user for all plugins")
696+
}
697+
return SetGlobalOption(option, value)
698+
}
699+
686700
func SetGlobalOption(option, value string) error {
687701
if _, ok := config.GlobalSettings[option]; !ok {
688702
return config.ErrInvalidOption

internal/config/settings.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ var DefaultGlobalOnlySettings = map[string]interface{}{
117117
"helpsplit": "hsplit",
118118
"infobar": true,
119119
"keymenu": false,
120+
"lockbindings": false,
121+
"locksettings": false,
120122
"mouse": true,
121123
"multiopen": "tab",
122124
"parsecursor": false,

runtime/help/options.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,16 @@ Here are the available options:
237237

238238
default value: `false`
239239

240+
* `lockbindings`: Disable plugins to modify the `bindings.json` in your config
241+
directory.
242+
243+
default value: `false`
244+
245+
* `locksettings`: Disable plugins to modify the `settings.json` in your config
246+
directory.
247+
248+
default value: `false`
249+
240250
* `matchbrace`: show matching braces for '()', '{}', '[]' when the cursor
241251
is on a brace character or (if `matchbraceleft` is enabled) next to it.
242252

0 commit comments

Comments
 (0)