Skip to content

Commit cb4237b

Browse files
committed
Support different descriptions for same mapping on different modes.
- fixes #13
1 parent c45bb1a commit cb4237b

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

plugin/follow-my-lead.vim

+5-5
Original file line numberDiff line numberDiff line change
@@ -50,24 +50,24 @@ endfunction
5050
function! FMLParseMapping(mapping_line)
5151
let pattern = '\V\^\(\a\| \)\s\+' . s:fml_escaped_leader . '\(\S\+\)\s\+\%(*\| \)\%(@\| \)\(\.\+\)'
5252
let groups = matchlist(a:mapping_line, pattern)
53-
return { 'mode': groups[1], 'lhs': groups[2], 'rhs': groups[3] }
53+
return { 'id': substitute(groups[1] . '_' . groups[2], ' ', '', ''), 'mode': groups[1], 'lhs': groups[2], 'rhs': groups[3] }
5454
endfunction
5555

5656
function! FMLAddDescription(src, mappings)
5757
let src_lines = readfile(glob(a:src))
5858
let lines_with_index = map(deepcopy(src_lines), '[v:key, v:val]')
59-
let comments_by_lhs = {}
59+
let comments_by_id = {}
6060
for [idx, line] in lines_with_index
61-
let lhs = matchlist(line, '\c\m^\a*map.*<leader>\(\S\+\)')
61+
let lhs = matchlist(line, '\c\m^\(\a*\)map.*<leader>\(\S\+\)')
6262
if(!empty(lhs))
6363
let prev_line = src_lines[idx - 1]
6464
let comment = matchlist(prev_line, '^"\s*\(.*\)')
6565
if(!empty(comment))
66-
let comments_by_lhs[lhs[1]] = comment[1]
66+
let comments_by_id[lhs[1] . '_' . lhs[2]] = comment[1]
6767
endif
6868
endif
6969
endfor
70-
return map(a:mappings, 'has_key(comments_by_lhs, v:val.lhs) ? extend(v:val, {"desc": comments_by_lhs[v:val.lhs]}) : v:val')
70+
return map(a:mappings, 'has_key(comments_by_id, v:val.id) ? extend(v:val, {"desc": comments_by_id[v:val.id]}) : v:val')
7171
endfunction
7272

7373
function! FMLFormatMappings(source, mappings)

0 commit comments

Comments
 (0)