Skip to content

Commit 3c38fe5

Browse files
authored
Custom mapping prefix (#330)
1 parent 07d0e00 commit 3c38fe5

File tree

5 files changed

+76
-37
lines changed

5 files changed

+76
-37
lines changed

DOCS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ Using the example above, setting this variable to `{'MYTAG'}`, second and third
481481
## Mappings
482482

483483
Mappings try to mimic some of the Orgmode mappings, but since Orgmode uses `CTRL + c` as a modifier most of the time, we have to take a different route.
484-
When possible, instead of `CTRL + C`, prefix `<Leader>o` is used.
484+
When possible, instead of `CTRL + C`, prefix `<Leader>o` is used. This is customizable via the `mappings.prefix` setting.
485485

486486
To disable all mappings, just pass `disable_all = true` to mappings settings:
487487
```lua

lua/orgmode/config/defaults.lua

Lines changed: 37 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,10 @@ return {
5151
},
5252
mappings = {
5353
disable_all = false,
54+
prefix = '<Leader>o',
5455
global = {
55-
org_agenda = '<Leader>oa',
56-
org_capture = '<Leader>oc',
56+
org_agenda = '<prefix>a',
57+
org_capture = '<prefix>c',
5758
},
5859
agenda = {
5960
org_agenda_later = 'f',
@@ -69,80 +70,80 @@ return {
6970
org_agenda_goto_date = 'J',
7071
org_agenda_redo = 'r',
7172
org_agenda_todo = 't',
72-
org_agenda_clock_goto = '<leader>oxj',
73-
org_agenda_set_effort = '<leader>oxe',
73+
org_agenda_clock_goto = '<prefix>xj',
74+
org_agenda_set_effort = '<prefix>xe',
7475
org_agenda_clock_in = 'I',
7576
org_agenda_clock_out = 'O',
7677
org_agenda_clock_cancel = 'X',
7778
org_agenda_clockreport_mode = 'R',
78-
org_agenda_priority = '<leader>o,',
79+
org_agenda_priority = '<prefix>,',
7980
org_agenda_priority_up = '+',
8081
org_agenda_priority_down = '-',
81-
org_agenda_toggle_archive_tag = '<Leader>oA',
82-
org_agenda_set_tags = '<Leader>ot',
83-
org_agenda_deadline = '<Leader>oid',
84-
org_agenda_schedule = '<Leader>ois',
82+
org_agenda_toggle_archive_tag = '<prefix>A',
83+
org_agenda_set_tags = '<prefix>t',
84+
org_agenda_deadline = '<prefix>id',
85+
org_agenda_schedule = '<prefix>is',
8586
org_agenda_filter = '/',
8687
org_agenda_show_help = 'g?',
8788
},
8889
capture = {
8990
org_capture_finalize = '<C-c>',
90-
org_capture_refile = '<Leader>or',
91-
org_capture_kill = '<Leader>ok',
91+
org_capture_refile = '<prefix>r',
92+
org_capture_kill = '<prefix>k',
9293
org_capture_show_help = 'g?',
9394
},
9495
org = {
95-
org_refile = '<Leader>or',
96+
org_refile = '<prefix>r',
9697
org_timestamp_up_day = '<S-UP>',
9798
org_timestamp_down_day = '<S-DOWN>',
9899
org_timestamp_up = '<C-a>',
99100
org_timestamp_down = '<C-x>',
100101
org_change_date = 'cid',
101-
org_priority = '<Leader>o,',
102+
org_priority = '<prefix>,',
102103
org_priority_up = 'ciR',
103104
org_priority_down = 'cir',
104105
org_todo = 'cit',
105106
org_todo_prev = 'ciT',
106107
org_toggle_checkbox = '<C-Space>',
107-
org_toggle_heading = '<Leader>o*',
108-
org_open_at_point = '<Leader>oo',
109-
org_edit_special = [[<Leader>o']],
108+
org_toggle_heading = '<prefix>*',
109+
org_open_at_point = '<prefix>o',
110+
org_edit_special = [[<prefix>']],
110111
org_cycle = '<TAB>',
111112
org_global_cycle = '<S-TAB>',
112-
org_archive_subtree = '<Leader>o$',
113-
org_set_tags_command = '<Leader>ot',
114-
org_toggle_archive_tag = '<Leader>oA',
113+
org_archive_subtree = '<prefix>$',
114+
org_set_tags_command = '<prefix>t',
115+
org_toggle_archive_tag = '<prefix>A',
115116
org_do_promote = '<<',
116117
org_do_demote = '>>',
117118
org_promote_subtree = '<s',
118119
org_demote_subtree = '>s',
119120
org_meta_return = '<Leader><CR>', -- Add heading, item or row
120121
org_return = '<CR>',
121-
org_insert_heading_respect_content = '<Leader>oih', -- Add new headling after current heading block with same level
122-
org_insert_todo_heading = '<Leader>oiT', -- Add new todo headling right after current heading with same level
123-
org_insert_todo_heading_respect_content = '<Leader>oit', -- Add new todo headling after current heading block on same level
124-
org_move_subtree_up = '<Leader>oK',
125-
org_move_subtree_down = '<Leader>oJ',
126-
org_export = '<Leader>oe',
122+
org_insert_heading_respect_content = '<prefix>ih', -- Add new headling after current heading block with same level
123+
org_insert_todo_heading = '<prefix>iT', -- Add new todo headling right after current heading with same level
124+
org_insert_todo_heading_respect_content = '<prefix>it', -- Add new todo headling after current heading block on same level
125+
org_move_subtree_up = '<prefix>K',
126+
org_move_subtree_down = '<prefix>J',
127+
org_export = '<prefix>e',
127128
org_next_visible_heading = '}',
128129
org_previous_visible_heading = '{',
129130
org_forward_heading_same_level = ']]',
130131
org_backward_heading_same_level = '[[',
131132
outline_up_heading = 'g{',
132-
org_deadline = '<Leader>oid',
133-
org_schedule = '<Leader>ois',
134-
org_time_stamp = '<Leader>oi.',
135-
org_time_stamp_inactive = '<Leader>oi!',
136-
org_clock_in = '<Leader>oxi',
137-
org_clock_out = '<Leader>oxo',
138-
org_clock_cancel = '<leader>oxq',
139-
org_clock_goto = '<leader>oxj',
140-
org_set_effort = '<leader>oxe',
133+
org_deadline = '<prefix>id',
134+
org_schedule = '<prefix>is',
135+
org_time_stamp = '<prefix>i.',
136+
org_time_stamp_inactive = '<prefix>i!',
137+
org_clock_in = '<prefix>xi',
138+
org_clock_out = '<prefix>xo',
139+
org_clock_cancel = '<prefix>xq',
140+
org_clock_goto = '<prefix>xj',
141+
org_set_effort = '<prefix>xe',
141142
org_show_help = 'g?',
142143
},
143144
edit_src = {
144-
org_edit_src_abort = '<Leader>ok',
145-
org_edit_src_save = '<Leader>ow',
145+
org_edit_src_abort = '<prefix>k',
146+
org_edit_src_save = '<prefix>w',
146147
org_edit_src_show_help = 'g?',
147148
},
148149
text_objects = {

lua/orgmode/config/init.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,10 @@ function Config:setup_mappings(category, bufnr)
191191
opts.buffer = bufnr
192192
end
193193

194+
if self.opts.mappings.prefix then
195+
opts.prefix = self.opts.mappings.prefix
196+
end
197+
194198
for name, map_entry in pairs(map_entries) do
195199
map_entry:attach(default_mappings[name], user_mappings[name], opts)
196200
end

lua/orgmode/config/mappings/map_entry.lua

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,16 @@ function MapEntry:attach(default_mapping, user_mapping, opts)
8585

8686
local map_opts = vim.tbl_extend('force', self.opts, opts or {})
8787

88+
local prefix = ''
89+
if map_opts.prefix then
90+
prefix = map_opts.prefix
91+
map_opts.prefix = nil
92+
end
93+
8894
for _, map in ipairs(mapping) do
95+
if prefix ~= '' then
96+
map = map:gsub('<prefix>', prefix)
97+
end
8998
vim.keymap.set(self.modes, map, self.handler, map_opts)
9099
if self.type == 'operator' then
91100
vim.keymap.set('o', map, (':normal v%s<CR>'):format(map), map_opts)

tests/plenary/ui/mappings_spec.lua

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1624,4 +1624,29 @@ describe('Mappings', function()
16241624
'- [ ] checkbox item',
16251625
}, vim.api.nvim_buf_get_lines(0, 0, 6, false))
16261626
end)
1627+
1628+
it('should respect custom mapping prefix', function()
1629+
config:extend({
1630+
mappings = {
1631+
prefix = '<Leader>f',
1632+
},
1633+
})
1634+
1635+
helpers.load_file_content({
1636+
'* DONE top level todo :WORK:',
1637+
'content for top level todo',
1638+
})
1639+
assert.are.same({
1640+
'* DONE top level todo :WORK:',
1641+
'content for top level todo',
1642+
}, vim.api.nvim_buf_get_lines(0, 0, 2, false))
1643+
vim.fn.cursor(3, 1)
1644+
vim.cmd([[norm ,fit]])
1645+
assert.are.same({
1646+
'* DONE top level todo :WORK:',
1647+
'content for top level todo',
1648+
'',
1649+
'* TODO ',
1650+
}, vim.api.nvim_buf_get_lines(0, 0, 4, false))
1651+
end)
16271652
end)

0 commit comments

Comments
 (0)