@@ -52,27 +52,64 @@ command! ErlangTags call VimErlangTags()
5252
5353" Execute the given tag lookup for current word, where 'iskeyword' is
5454" temporarily set such that modules, records, and macros are included.
55- function ! s: GoToErlangTag (cmd)
56- let orig_isk = &isk
57- set isk += :,#,?
55+ "
56+ " Accepts a count as an optional second parameter which will be the window
57+ " height for split or preview commands like 'stag', 'ptjump', etc., or the
58+ " match index to jump to for 'tag'.
59+ function ! s: GoToErlangTag (cmd, ... )
60+ let orig_isk = &l: isk
61+ setl isk += :,#,?
5862 let ident = expand (' <cword>' )
59- let &isk = orig_isk
63+ let &l: isk = orig_isk
64+
65+ " With no count arg or zero count, we can execute directly
66+ if a: 0 == 0 || a: 1 == 0
67+ execute a: cmd ident
68+ else
69+ let cnt = a: 1
70+
71+ if a: cmd == # ' tag'
72+ execute cnt a: cmd ident
73+ elseif a: cmd = ~# ' ^s'
74+ let cmd = ' split +' . a: cmd [1 :] . ' \ ' . ident
75+ execute cnt cmd
76+ elseif a: cmd = ~# ' ^p'
77+ " :pedit has a cursor movement bug that we work around with a mark
78+ " http://bit.ly/1F59kWA :-( Affects YouCompleteMe users, for one.
79+ normal ! m `
80+
81+ let cmd = ' pedit +' . a: cmd [1 :] . ' \ ' . ident
82+ call s: ExecWithPreviewHeight (cmd, cnt)
6083
61- execute a: cmd ident
84+ normal ! ``
85+ endif
86+ endif
87+ endfunction
88+
89+ " Because :pedit can't take height as count like :split does, ugh why.
90+ function ! s: ExecWithPreviewHeight (cmd, height)
91+ let orig_height = &previewheight
92+ let &previewheight = a: height
93+ execute a: cmd
94+ let &previewheight = orig_height
6295endfunction
6396
6497function ! VimErlangTagsDefineMappings ()
65- nnoremap <buffer> <c-]> :<C-U> call <SID> GoToErlangTag('tag')<cr>
66- nnoremap <buffer> g<LeftMouse> :<C-U> call <SID> GoToErlangTag('tag')<cr>
67- nnoremap <buffer> <c-LeftMouse> :<C-U> call <SID> GoToErlangTag('tag')<cr>
98+ " Count is index of match to jump to, as with :tag
99+ nnoremap <buffer> <c-]> :<C-U> call <SID> GoToErlangTag('tag', v:count1)<cr>
100+ nnoremap <buffer> g<LeftMouse> :<C-U> call <SID> GoToErlangTag('tag', v:count1)<cr>
101+ nnoremap <buffer> <c-LeftMouse> :<C-U> call <SID> GoToErlangTag('tag', v:count1)<cr>
102+
68103 nnoremap <buffer> g] :<C-U> call <SID> GoToErlangTag('tselect')<cr>
69104 nnoremap <buffer> g<c-]> :<C-U> call <SID> GoToErlangTag('tjump')<cr>
70- nnoremap <buffer> <c-w><c-]> :<C-U> call <SID> GoToErlangTag('stag')<cr>
71- nnoremap <buffer> <c-w> ] :<C-U> call <SID> GoToErlangTag('stag')<cr>
72- nnoremap <buffer> <c-w> g] :<C-U> call <SID> GoToErlangTag('stselect')<cr>
73- nnoremap <buffer> <c-w> g<c-]> :<C-U> call <SID> GoToErlangTag('stjump')<cr>
74- nnoremap <buffer> <c-w> } :<C-U> call <SID> GoToErlangTag('ptag')<cr>
75- nnoremap <buffer> <c-w> g} :<C-U> call <SID> GoToErlangTag('ptjump')<cr>
105+
106+ " Count is window height for split and preview mappings
107+ nnoremap <buffer> <c-w><c-]> :<C-U> call <SID> GoToErlangTag('stag', v:count)<cr>
108+ nnoremap <buffer> <c-w> ] :<C-U> call <SID> GoToErlangTag('stag', v:count)<cr>
109+ nnoremap <buffer> <c-w> g] :<C-U> call <SID> GoToErlangTag('stselect', v:count)<cr>
110+ nnoremap <buffer> <c-w> g<c-]> :<C-U> call <SID> GoToErlangTag('stjump', v:count)<cr>
111+ nnoremap <buffer> <c-w> } :<C-U> call <SID> GoToErlangTag('ptag', v:count)<cr>
112+ nnoremap <buffer> <c-w> g} :<C-U> call <SID> GoToErlangTag('ptjump', v:count)<cr>
76113endfunction
77114
78115" vim:set expandtab sw = 4 ts = 4 :
0 commit comments