mirror of
https://github.com/zyedidia/micro.git
synced 2026-02-04 14:10:23 +09:00
Changing behavior for TryBindKey() for lua to not write to bindings.json
This commit is contained in:
@@ -73,7 +73,7 @@ func luaImportMicroConfig() *lua.LTable {
|
||||
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))
|
||||
ulua.L.SetField(pkg, "TryBindKey", luar.New(ulua.L, action.TryBindKeyPlug))
|
||||
ulua.L.SetField(pkg, "Reload", luar.New(ulua.L, action.ReloadConfig))
|
||||
ulua.L.SetField(pkg, "AddRuntimeFileFromMemory", luar.New(ulua.L, config.PluginAddRuntimeFileFromMemory))
|
||||
ulua.L.SetField(pkg, "AddRuntimeFilesFromDirectory", luar.New(ulua.L, config.PluginAddRuntimeFilesFromDirectory))
|
||||
|
||||
@@ -261,9 +261,14 @@ func eventsEqual(e1 Event, e2 Event) bool {
|
||||
return e1 == e2
|
||||
}
|
||||
|
||||
// TryBindKeyPlug tries to bind a key for the plugin without writing to bindings.json.
|
||||
func TryBindKeyPlug(k, v string, overwrite bool) (bool, error) {
|
||||
return TryBindKey(k, v, overwrite, false)
|
||||
}
|
||||
|
||||
// TryBindKey tries to bind a key by writing to config.ConfigDir/bindings.json
|
||||
// Returns true if the keybinding already existed and a possible error
|
||||
func TryBindKey(k, v string, overwrite bool) (bool, error) {
|
||||
// Returns true if the keybinding already existed or is binded successfully and a possible error
|
||||
func TryBindKey(k, v string, overwrite bool, writeToFile bool) (bool, error) {
|
||||
var e error
|
||||
var parsed map[string]any
|
||||
|
||||
@@ -310,7 +315,12 @@ func TryBindKey(k, v string, overwrite bool) (bool, error) {
|
||||
|
||||
txt, _ := json.MarshalIndent(parsed, "", " ")
|
||||
txt = append(txt, '\n')
|
||||
return true, writeFile(filename, txt)
|
||||
|
||||
if writeToFile {
|
||||
return true, writeFile(filename, txt)
|
||||
} else {
|
||||
return true, nil
|
||||
}
|
||||
}
|
||||
return false, e
|
||||
}
|
||||
|
||||
@@ -844,7 +844,7 @@ func (h *BufPane) BindCmd(args []string) {
|
||||
return
|
||||
}
|
||||
|
||||
_, err := TryBindKey(parseKeyArg(args[0]), args[1], true)
|
||||
_, err := TryBindKey(parseKeyArg(args[0]), args[1], true, true)
|
||||
if err != nil {
|
||||
if errors.Is(err, util.ErrOverwrite) {
|
||||
screen.TermMessage(err)
|
||||
|
||||
@@ -174,11 +174,10 @@ The packages and their contents are listed below (in Go type signatures):
|
||||
values afterwards
|
||||
- `NoComplete`: no autocompletion suggestions
|
||||
|
||||
- `TryBindKey(k, v string, overwrite bool) (bool, error)`: bind the key
|
||||
`k` to the string `v` in the `bindings.json` file. If `overwrite` is
|
||||
true, this will overwrite any existing binding to key `k`. Returns true
|
||||
if the binding was made, and a possible error (for example writing to
|
||||
`bindings.json` can cause an error).
|
||||
- `TryBindKey(k, v string, overwrite bool) (bool, error)`:
|
||||
bind the key `k` to the string `v`. If `overwrite` is true, this will
|
||||
overwrite any existing binding to key `k`.
|
||||
Returns true if the binding was made, and a possible error.
|
||||
|
||||
- `Reload()`: reload configuration files.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user