MCPcopy
hub / github.com/micro-editor/micro / BufMapEvent

Function BufMapEvent

internal/action/bufpane.go:92–188  ·  view source on GitHub ↗

BufMapEvent maps an event to an action

(k Event, action string)

Source from the content-addressed store, hash-verified

90
91// BufMapEvent maps an event to an action
92func BufMapEvent(k Event, action string) {
93 config.Bindings["buffer"][k.Name()] = action
94
95 var actionfns []BufAction
96 var names []string
97 var types []byte
98 for i := 0; ; i++ {
99 if action == "" {
100 break
101 }
102
103 idx := util.IndexAnyUnquoted(action, "&|,")
104 a := action
105 if idx >= 0 {
106 a = action[:idx]
107 types = append(types, action[idx])
108 action = action[idx+1:]
109 } else {
110 types = append(types, ' ')
111 action = ""
112 }
113
114 var afn BufAction
115 if strings.HasPrefix(a, "command:") {
116 a = strings.SplitN(a, ":", 2)[1]
117 afn = CommandAction(a)
118 names = append(names, "")
119 } else if strings.HasPrefix(a, "command-edit:") {
120 a = strings.SplitN(a, ":", 2)[1]
121 afn = CommandEditAction(a)
122 names = append(names, "")
123 } else if strings.HasPrefix(a, "lua:") {
124 a = strings.SplitN(a, ":", 2)[1]
125 afn = LuaAction(a, k)
126 if afn == nil {
127 screen.TermMessage("Lua Error:", a, "does not exist")
128 continue
129 }
130 split := strings.SplitN(a, ".", 2)
131 if len(split) > 1 {
132 a = strings.Title(split[0]) + strings.Title(split[1])
133 } else {
134 a = strings.Title(a)
135 }
136
137 names = append(names, a)
138 } else if f, ok := BufKeyActions[a]; ok {
139 afn = f
140 names = append(names, a)
141 } else if f, ok := BufMouseActions[a]; ok {
142 afn = f
143 names = append(names, a)
144 } else {
145 screen.TermMessage("Error in bindings: action", a, "does not exist")
146 continue
147 }
148 actionfns = append(actionfns, afn)
149 }

Callers

nothing calls this directly

Calls 15

IndexAnyUnquotedFunction · 0.92
TermMessageFunction · 0.92
CommandActionFunction · 0.85
CommandEditActionFunction · 0.85
LuaActionFunction · 0.85
MainTabFunction · 0.85
BufKeyActionGeneralFunction · 0.85
BufMouseActionGeneralFunction · 0.85
GetCursorsMethod · 0.80
SetCurCursorMethod · 0.80
execActionMethod · 0.80
GetActiveCursorMethod · 0.80

Tested by

no test coverage detected