BufMapEvent maps an event to an action
(k Event, action string)
| 90 | |
| 91 | // BufMapEvent maps an event to an action |
| 92 | func 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 | } |
nothing calls this directly
no test coverage detected