Skip to content

Commit b8057f2

Browse files
authored
refactor: use a more modern writing style to simplify code (zyedidia#3834)
Signed-off-by: deepdring <[email protected]>
1 parent 094b02d commit b8057f2

File tree

24 files changed

+98
-100
lines changed

24 files changed

+98
-100
lines changed

internal/action/actions.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2083,14 +2083,14 @@ func (h *BufPane) LastSplit() bool {
20832083
return true
20842084
}
20852085

2086-
var curmacro []interface{}
2086+
var curmacro []any
20872087
var recordingMacro bool
20882088

20892089
// ToggleMacro toggles recording of a macro
20902090
func (h *BufPane) ToggleMacro() bool {
20912091
recordingMacro = !recordingMacro
20922092
if recordingMacro {
2093-
curmacro = []interface{}{}
2093+
curmacro = []any{}
20942094
InfoBar.Message("Recording")
20952095
} else {
20962096
InfoBar.Message("Stopped recording")

internal/action/bindings.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func createBindingsIfNotExist(fname string) {
3636

3737
// InitBindings intializes the bindings map by reading from bindings.json
3838
func InitBindings() {
39-
var parsed map[string]interface{}
39+
var parsed map[string]any
4040

4141
filename := filepath.Join(config.ConfigDir, "bindings.json")
4242
createBindingsIfNotExist(filename)
@@ -66,7 +66,7 @@ func InitBindings() {
6666
switch val := v.(type) {
6767
case string:
6868
BindKey(k, val, Binder["buffer"])
69-
case map[string]interface{}:
69+
case map[string]any:
7070
bind, ok := Binder[k]
7171
if !ok || bind == nil {
7272
screen.TermMessage(fmt.Sprintf("%s is not a valid pane type", k))
@@ -265,7 +265,7 @@ func eventsEqual(e1 Event, e2 Event) bool {
265265
// Returns true if the keybinding already existed and a possible error
266266
func TryBindKey(k, v string, overwrite bool) (bool, error) {
267267
var e error
268-
var parsed map[string]interface{}
268+
var parsed map[string]any
269269

270270
filename := filepath.Join(config.ConfigDir, "bindings.json")
271271
createBindingsIfNotExist(filename)
@@ -318,7 +318,7 @@ func TryBindKey(k, v string, overwrite bool) (bool, error) {
318318
// UnbindKey removes the binding for a key from the bindings.json file
319319
func UnbindKey(k string) error {
320320
var e error
321-
var parsed map[string]interface{}
321+
var parsed map[string]any
322322

323323
filename := filepath.Join(config.ConfigDir, "bindings.json")
324324
createBindingsIfNotExist(filename)

internal/action/bufpane.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616
"github.com/zyedidia/micro/v2/internal/util"
1717
)
1818

19-
type BufAction interface{}
19+
type BufAction any
2020

2121
// BufKeyAction represents an action bound to a key.
2222
type BufKeyAction func(*BufPane) bool
@@ -324,7 +324,7 @@ func (h *BufPane) ResizePane(size int) {
324324
// error if there is one and returns the aggregate boolean response.
325325
// The bufpane is passed as the first argument to the callbacks,
326326
// optional args are passed as the next arguments.
327-
func (h *BufPane) PluginCB(cb string, args ...interface{}) bool {
327+
func (h *BufPane) PluginCB(cb string, args ...any) bool {
328328
largs := []lua.LValue{luar.New(ulua.L, h)}
329329
for _, a := range args {
330330
largs = append(largs, luar.New(ulua.L, a))

internal/action/command.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,7 @@ func (h *BufPane) NewTabCmd(args []string) {
569569
}
570570
}
571571

572-
func doSetGlobalOptionNative(option string, nativeValue interface{}) error {
572+
func doSetGlobalOptionNative(option string, nativeValue any) error {
573573
if reflect.DeepEqual(config.GlobalSettings[option], nativeValue) {
574574
return nil
575575
}
@@ -628,7 +628,7 @@ func doSetGlobalOptionNative(option string, nativeValue interface{}) error {
628628
return nil
629629
}
630630

631-
func SetGlobalOptionNative(option string, nativeValue interface{}) error {
631+
func SetGlobalOptionNative(option string, nativeValue any) error {
632632
if err := config.OptionIsValid(option, nativeValue); err != nil {
633633
return err
634634
}
@@ -737,7 +737,7 @@ func (h *BufPane) ShowCmd(args []string) {
737737
return
738738
}
739739

740-
var option interface{}
740+
var option any
741741
if opt, ok := h.Buf.Settings[args[0]]; ok {
742742
option = opt
743743
} else if opt, ok := config.GlobalSettings[args[0]]; ok {

internal/action/infocomplete.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ func OptionValueComplete(b *buffer.Buffer) ([]string, []string) {
193193
inputOpt = strings.TrimSpace(inputOpt)
194194
var suggestions []string
195195
// localSettings := config.DefaultLocalSettings()
196-
var optionVal interface{}
196+
var optionVal any
197197
for k, option := range config.GlobalSettings {
198198
if k == inputOpt {
199199
optionVal = option

internal/action/terminal_supported.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const TermEmuSupported = true
1414
// if wait is true it will wait for the user to exit by pressing enter once the executable has terminated
1515
// if getOutput is true it will redirect the stdout of the process to a pipe which will be passed to the
1616
// callback which is a function that takes a string and a list of optional user arguments
17-
func RunTermEmulator(h *BufPane, input string, wait bool, getOutput bool, callback func(out string, userargs []interface{}), userargs []interface{}) error {
17+
func RunTermEmulator(h *BufPane, input string, wait bool, getOutput bool, callback func(out string, userargs []any), userargs []any) error {
1818
args, err := shellquote.Split(input)
1919
if err != nil {
2020
return err

internal/action/terminal_unsupported.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ import "errors"
88
const TermEmuSupported = false
99

1010
// RunTermEmulator returns an error for unsupported systems (non-unix systems
11-
func RunTermEmulator(input string, wait bool, getOutput bool, callback func(out string, userargs []interface{}), userargs []interface{}) error {
11+
func RunTermEmulator(input string, wait bool, getOutput bool, callback func(out string, userargs []any), userargs []any) error {
1212
return errors.New("Unsupported operating system")
1313
}

internal/buffer/buffer.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ type SharedBuffer struct {
8282
toStdout bool
8383

8484
// Settings customized by the user
85-
Settings map[string]interface{}
85+
Settings map[string]any
8686
// LocalSettings customized by the user for this buffer only
8787
LocalSettings map[string]bool
8888

@@ -236,7 +236,7 @@ type Buffer struct {
236236
// is properly updated when needed. This is a workaround for the fact that
237237
// the buffer module cannot directly call the display's API (it would mean
238238
// a circular dependency between packages).
239-
OptionCallback func(option string, nativeValue interface{})
239+
OptionCallback func(option string, nativeValue any)
240240

241241
// The display module registers its own GetVisualX function for getting
242242
// the correct visual x location of a cursor when softwrap is used.

internal/buffer/message.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ func (b *Buffer) ClearAllMessages() {
8484
}
8585

8686
type Messager interface {
87-
Message(msg ...interface{})
87+
Message(msg ...any)
8888
}
8989

9090
var prompt Messager

internal/buffer/settings.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func (b *Buffer) ReloadSettings(reloadFiletype bool) {
5959
}
6060
}
6161

62-
func (b *Buffer) DoSetOptionNative(option string, nativeValue interface{}) {
62+
func (b *Buffer) DoSetOptionNative(option string, nativeValue any) {
6363
oldValue := b.Settings[option]
6464
if reflect.DeepEqual(oldValue, nativeValue) {
6565
return
@@ -138,7 +138,7 @@ func (b *Buffer) DoSetOptionNative(option string, nativeValue interface{}) {
138138
b.doCallbacks(option, oldValue, nativeValue)
139139
}
140140

141-
func (b *Buffer) SetOptionNative(option string, nativeValue interface{}) error {
141+
func (b *Buffer) SetOptionNative(option string, nativeValue any) error {
142142
if err := config.OptionIsValid(option, nativeValue); err != nil {
143143
return err
144144
}
@@ -163,7 +163,7 @@ func (b *Buffer) SetOption(option, value string) error {
163163
return b.SetOptionNative(option, nativeValue)
164164
}
165165

166-
func (b *Buffer) doCallbacks(option string, oldValue interface{}, newValue interface{}) {
166+
func (b *Buffer) doCallbacks(option string, oldValue any, newValue any) {
167167
if b.OptionCallback != nil {
168168
b.OptionCallback(option, newValue)
169169
}

0 commit comments

Comments
 (0)