@@ -208,8 +208,24 @@ function Config:setup_mappings(category)
208
208
209
209
for name , lhs in pairs (self .opts .mappings [category ]) do
210
210
if mappings [category ] and mappings [category ][name ] and lhs then
211
+ -- lhs
212
+ local keys = {}
213
+ if type (lhs ) == ' string' or vim .tbl_islist (lhs ) then
214
+ -- no mode specified, default to normal-mode
215
+ keys [' n' ] = lhs
216
+ else
217
+ keys = lhs
218
+ end
219
+ -- rhs
211
220
local map = {}
212
- if type (mappings [category ][name ]) == ' table' and not vim .tbl_islist (mappings [category ][name ]) then
221
+ if not type (mappings [category ][name ]) == ' table' or vim .tbl_islist (mappings [category ][name ]) then
222
+ -- no mode specified, default to normal-mode
223
+ map [' n' ] = {}
224
+ map [' n' ][' action' ] = vim .tbl_map (function (i )
225
+ return string.format (' "%s"' , i )
226
+ end , mappings [category ][name ])
227
+ map [' n' ][' opts' ] = {}
228
+ else
213
229
-- multi-mode mapping
214
230
for mode , mapping in pairs (mappings [category ][name ]) do
215
231
map [mode ] = {}
@@ -228,33 +244,24 @@ function Config:setup_mappings(category)
228
244
map [mode ][' opts' ] = {}
229
245
end
230
246
end
231
- else
232
- -- single-mode defaults to normal-mode
233
- map [' n' ] = {}
234
- map [' n' ][' action' ] = vim .tbl_map (function (i )
235
- return string.format (' "%s"' , i )
236
- end , mappings [category ][name ])
237
- map [' n' ][' opts' ] = {}
238
247
end
239
-
240
- local keys = {}
241
- if type (lhs ) == ' string' then
242
- keys [' n' ] = lhs
243
- else
244
- keys = lhs
245
- end
246
-
248
+ -- register mappings
247
249
for mode , key in pairs (keys ) do
248
- local mapping = map [mode ] or false
249
- if mapping then
250
- local action = table.concat (mapping [' action' ], ' ,' )
251
- utils .buf_keymap (
252
- 0 ,
253
- mode ,
254
- key ,
255
- string.format (' <cmd>lua require("orgmode").action(%s)<CR>' , action ),
256
- mapping [' opts' ]
257
- )
250
+ if type (key ) == ' string' then
251
+ key = { key }
252
+ end
253
+ for _ , k in pairs (key ) do
254
+ local mapping = map [mode ] or false
255
+ if mapping then
256
+ local action = table.concat (mapping [' action' ], ' ,' )
257
+ utils .buf_keymap (
258
+ 0 ,
259
+ mode ,
260
+ k ,
261
+ string.format (' <cmd>lua require("orgmode").action(%s)<CR>' , action ),
262
+ mapping [' opts' ]
263
+ )
264
+ end
258
265
end
259
266
end
260
267
end
0 commit comments