- if strings.HasPrefix(action, "command:") {
- action = strings.SplitN(action, ":", 2)[1]
- BufKeyStrings[k] = action
- BufKeyBindings[k] = CommandAction(action)
- } else if strings.HasPrefix(action, "command-edit:") {
- action = strings.SplitN(action, ":", 2)[1]
- BufKeyStrings[k] = action
- BufKeyBindings[k] = CommandEditAction(action)
- } else if strings.HasPrefix(action, "lua:") {
- action = strings.SplitN(action, ":", 2)[1]
- BufKeyStrings[k] = action
- BufKeyBindings[k] = LuaAction(action)
- } else if f, ok := BufKeyActions[action]; ok {
- BufKeyStrings[k] = action
- BufKeyBindings[k] = f
- } else {
- screen.TermMessage("Error:", action, "does not exist")
+ BufKeyStrings[k] = action
+ var actionfns []func(*BufPane) bool
+ var names []string
+ var types []byte
+ for i := 0; ; i++ {
+ if action == "" {
+ break
+ }
+
+ // TODO: fix problem when complex bindings have these
+ // characters (escape them?)
+ idx := strings.IndexAny(action, "&|,")
+ a := action
+ if idx >= 0 {
+ a = action[:idx]
+ types = append(types, action[idx])
+ action = action[idx+1:]
+ } else {
+ types = append(types, ' ')
+ action = ""
+ }
+
+ var afn func(*BufPane) bool
+ if strings.HasPrefix(a, "command:") {
+ a = strings.SplitN(a, ":", 2)[1]
+ afn = CommandAction(a)
+ names = append(names, "")
+ } else if strings.HasPrefix(a, "command-edit:") {
+ a = strings.SplitN(a, ":", 2)[1]
+ afn = CommandEditAction(a)
+ names = append(names, "")
+ } else if strings.HasPrefix(a, "lua:") {
+ a = strings.SplitN(a, ":", 2)[1]
+ afn = LuaAction(a)
+ if afn == nil {
+ screen.TermMessage("Lua Error:", a, "does not exist")
+ continue
+ }
+ split := strings.SplitN(a, ".", 2)
+ if len(split) > 1 {
+ a = strings.Title(split[0]) + strings.Title(split[1])
+ } else {
+ a = strings.Title(a)
+ }
+
+ names = append(names, a)
+ } else if f, ok := BufKeyActions[a]; ok {
+ afn = f
+ names = append(names, a)
+ } else {
+ screen.TermMessage("Error:", a, "does not exist")
+ continue
+ }
+ actionfns = append(actionfns, afn)
+ }
+ BufKeyBindings[k] = func(h *BufPane) bool {
+ cursors := h.Buf.GetCursors()
+ success := true
+ for i, a := range actionfns {
+ for j, c := range cursors {
+ h.Buf.SetCurCursor(c.Num)
+ h.Cursor = c
+ if i == 0 || (success && types[i-1] == '&') || (!success && types[i-1] == '|') || (types[i-1] == ',') {
+ success = h.execAction(a, names[i], j)
+ } else {
+ break
+ }
+ }
+ }
+ return true