On Sep 7, 7:32 am, Jacky Liu <[email protected]> wrote:
>
> Now I'm thinking that maybe just :drop to the target file and let :tag
> do the rest would be OK, this way the tag stack would be updated too,
> and should make the following <Ctrl-t> indeed the other way round --
> just :drop back and :pop.
>

Oh, good call.

New implementation, still untested:

        nnoremap! <Ctrl-]> :call <SID>SmartTagSearch()<CR>

        let g:last_tag_file = [];

         function! s:SmartTagSearch()
             " get the first tag hit for the word under the cursor
             let searchstr = expand("<cword>")
             let firsttag = taglist(searchstr)[0]
             " save off the current file in case we need it again
             call add(g:last_tag_file, expand("%:p"))
             " jump to the file containing the tag (in existing window
if possible)
             execute 'drop' fnameescape(firsttag.filename)
             " jump to the tag itself
             execute 'tag' searchstr
         endfunction

        nnoremap! <Ctrl-T> :call <SID>SmartTagReturn()<CR>

         function! s:SmartTagReturn()
             if (empty(g:last_tag_file))
                 return
             endif
             " jump to the file containing the pre-tag position (in
existing window if possible)
             execute 'drop' remove(g:last_tag_file, -1)
             " jump to the pre-tag position itself
             pop
         endfunction


Note these will need an update, to handle a count. Currently they do
not handle a count correctly. In fact, they will fail entirely with a
count due to the auto-insertion of the count when you press (or map) :
in normal mode.

:he v:count and :he v:count1 should be of interest for this.

-- 
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

Reply via email to