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