Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add fast way for displaying the prev or next def

1. Add the fast way for displaying the previous or next definition in
the jump list. The new feature is similar with the commands called cprev
and cnext for operating the Quickfix list.
2. Fix a bug when clicking the default prompt line in the Source
Explorer window.
  • Loading branch information...
commit e60dca26510e3ef2984aecf2c908f001034ebcdf 1 parent a8abf2f
@wesleyche authored
Showing with 127 additions and 20 deletions.
  1. +127 −20 plugin/srcexpl.vim
View
147 plugin/srcexpl.vim
@@ -8,8 +8,8 @@
" Jonathan Lai <laiks.jonathan@gmail.com> "
" Homepage: http://www.vim.org/scripts/script.php?script_id=2179 "
" GitHub: https://github.com/wesleyche/SrcExpl "
-" Version: 5.1 "
-" Last Change: September 16th, 2012 "
+" Version: 5.2 "
+" Last Change: March 12th, 2013 "
" Licence: This program is free software; you can redistribute it and / or "
" modify it under the terms of the GNU General Public License as "
" published by the Free Software Foundation; either version 2, or "
@@ -38,7 +38,7 @@
" |~ \___________\||~ .-------------. | |~ \____________\||
" |~ |~ \______________\| |~ |
" +-__Tag_List__---+-demo.c----------------------------------+-_NERD_tree_-----+
-" |Source Explorer v5.1 .-----------------. |
+" |Source Explorer v5.2 .-----------------. |
" |~ | Source Explorer |\ |
" |~ .-----------------. | |
" |~ \__________________\| |
@@ -89,6 +89,12 @@
" // Set "<F12>" key for updating the tags file artificially "
" let g:SrcExpl_updateTagsKey = "<F12>"
" "
+" // Set "<F3>" key for displaying the previous definition in the jump list "
+" let g:SrcExpl_prevDefKey = "<F3>"
+" "
+" // Set "<F4>" key for displaying the next definition in the jump list "
+" let g:SrcExpl_nextDefKey = "<F4>"
+" "
" Just_change_above_of_them_by_yourself:-) "
" "
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
@@ -189,6 +195,16 @@ if !exists('g:SrcExpl_updateTagsKey')
let g:SrcExpl_updateTagsKey = ''
endif
+" User interface to display the previous definition in the jump list
+if !exists('g:SrcExpl_prevDefKey')
+ let g:SrcExpl_prevDefKey = ''
+endif
+
+" User interface to display the next definition in the jump list
+if !exists('g:SrcExpl_nextDefKey')
+ let g:SrcExpl_nextDefKey = ''
+endif
+
" }}}
" Global variables {{{
@@ -200,7 +216,7 @@ let g:SrcExpl_markList = []
let s:SrcExpl_pluginName = 'Source Explorer'
" Plugin version
-let s:SrcExpl_pluginVer = 5.1
+let s:SrcExpl_pluginVer = 5.2
" Buffer name
let s:SrcExpl_bufName = 'Source_Explorer'
@@ -222,6 +238,26 @@ let s:SrcExpl_isRunning = 0
" }}}
+" SrcExpl_PrevDef() {{{
+
+" Display the previous definition in the jump list
+
+function! g:SrcExpl_PrevDef()
+
+ call <SID>SrcExpl_JumpDef(1)
+
+endfunction " }}}
+
+" SrcExpl_NextDef() {{{
+
+" Display the next definition in the jump list
+
+function! g:SrcExpl_NextDef()
+
+ call <SID>SrcExpl_JumpDef(2)
+
+endfunction " }}}
+
" SrcExpl_GetVer() {{{
" Gets the Source Explorer version
@@ -356,8 +392,7 @@ endfunction " }}}
function! g:SrcExpl_Jump()
- " Only do the operation on the Source Explorer
- " window is valid
+ " Only do the operation on the Source Explorer window is valid
if !<SID>SrcExpl_WinActive()
return -1
endif
@@ -388,7 +423,7 @@ function! g:SrcExpl_Jump()
" We got multiple definitions
if s:SrcExpl_status == 2
" Select the exact one and jump to its context
- call <SID>SrcExpl_SelToJump()
+ call <SID>SrcExpl_SelToJump(0)
" Set the mark for recording the current position
call <SID>SrcExpl_SetMarkList()
return 0
@@ -463,6 +498,25 @@ function! g:SrcExpl_Refresh()
endfunction " }}}
+" SrcExpl_JumpDef() {{{
+
+" Display the previous or next definition in the jump list
+
+function! <SID>SrcExpl_JumpDef(dir)
+
+ " Multiple definitions
+ if s:SrcExpl_status == 2
+ " Select the exact one and jump to its context
+ call <SID>SrcExpl_SelToJump(a:dir)
+ " Set the mark for recording the current position
+ call <SID>SrcExpl_SetMarkList()
+ " One definition or local definition
+ elseif s:SrcExpl_status == 1 || s:SrcExpl_status == 3
+ call <SID>SrcExpl_ReportErr("No more definitions")
+ endif
+
+endfunction " }}}
+
" SrcExpl_Debug() {{{
" Log the supplied debug information along with the time
@@ -799,8 +853,9 @@ endfunction " }}}
" Select one of multi-definitions, and jump to there
-function! <SID>SrcExpl_SelToJump()
+function! <SID>SrcExpl_SelToJump(dir)
+ let l:error = 0
let l:index = 0
let l:fpath = ""
let l:excmd = ""
@@ -811,8 +866,36 @@ function! <SID>SrcExpl_SelToJump()
call <SID>SrcExpl_WinGo()
endif
- " Get the item data that the user selected just now
- let l:list = getline(".")
+ if a:dir == 1 " pref def
+ if line(".") <= 2
+ let l:error = 2
+ else
+ call cursor(line(".") - 1, 1)
+ let l:list = getline(".")
+ endif
+ elseif a:dir == 2 " next def
+ let l:temp = line(".") + 1
+ if line(".") == 1 " avoid head
+ call cursor(l:temp, 1)
+ let l:list = getline(".")
+ else
+ call cursor(l:temp, 1)
+ if l:temp == line(".")
+ let l:list = getline(".")
+ else " exceed the defs' max
+ let l:error = 1
+ endif
+ endif
+ else " normal click
+ let l:list = getline(".")
+ endif
+
+ if l:error != 0
+ silent! exe s:SrcExpl_editWin . "wincmd w"
+ call <SID>SrcExpl_ReportErr("No more definitions")
+ return
+ endif
+
" Traverse the prompt string until get the file path
while !((l:list[l:index] == ']') &&
\ (l:list[l:index + 1] == ':'))
@@ -838,7 +921,7 @@ function! <SID>SrcExpl_SelToJump()
" Offset
let l:index += 3
- " Get the EX command string
+ " Get the Ex command string
while l:list[l:index] != ''
let l:excmd = l:excmd . l:list[l:index]
let l:index += 1
@@ -849,12 +932,12 @@ function! <SID>SrcExpl_SelToJump()
" Open the file containing the definition context
exe "edit " . l:fpath
- " Modify the EX Command to locate the tag exactly
+ " Modify the Ex Command to locate the tag exactly
let l:expr = substitute(l:excmd, '/^', '/^\\C', 'g')
let l:expr = substitute(l:expr, '\*', '\\\*', 'g')
let l:expr = substitute(l:expr, '\[', '\\\[', 'g')
let l:expr = substitute(l:expr, '\]', '\\\]', 'g')
- " Use EX Command to Jump to the exact position of the definition
+ " Use Ex Command to jump to the exact position of the definition
silent! exe l:expr
" Match the symbol
@@ -945,7 +1028,7 @@ function! <SID>SrcExpl_ListMultiDefs(list, len)
" Delete all lines in buffer
1,$d _
" Get the tags dictionary array
- " Begin build the Jump List for exploring the tags
+ " Begin build the jump list for exploring the tags
put! = '[Jump List]: '. s:SrcExpl_symbol . ' (' . a:len . ') '
" Match the symbol
call <SID>SrcExpl_MatchExpr()
@@ -964,16 +1047,16 @@ function! <SID>SrcExpl_ListMultiDefs(list, len)
" We should avoid the './' or '.\' in the whole file path
if l:dict['filename'][0] == '.'
put! ='[File Path]: ' . l:path . l:dict['filename'][2:]
- \ . ' ' . '[EX Command]: ' . l:dict['cmd']
+ \ . ' ' . '[Ex Command]: ' . l:dict['cmd']
else
" Generated by 'ctags --sort=foldcase -R .'
if len(l:path) == 0
put! ='[File Path]: ' . l:path . l:dict['filename']
- \ . ' ' . '[EX Command]: ' . l:dict['cmd']
+ \ . ' ' . '[Ex Command]: ' . l:dict['cmd']
" Generated by 'ctags -L cscope.files'
else
put! ='[File Path]: ' . l:dict['filename']
- \ . ' ' . '[EX Command]: ' . l:dict['cmd']
+ \ . ' ' . '[Ex Command]: ' . l:dict['cmd']
endif
endif
" Traversal finished
@@ -1014,12 +1097,12 @@ function! <SID>SrcExpl_ViewOneDef(fpath, excmd)
" Indeed back to the Source Explorer active window
if <SID>SrcExpl_WinActive()
- " Modify the EX Command to locate the tag exactly
+ " Modify the Ex Command to locate the tag exactly
let l:expr = substitute(a:excmd, '/^', '/^\\C', 'g')
let l:expr = substitute(l:expr, '\*', '\\\*', 'g')
let l:expr = substitute(l:expr, '\[', '\\\[', 'g')
let l:expr = substitute(l:expr, '\]', '\\\]', 'g')
- " Execute EX command according to the parameter
+ " Execute Ex command according to the parameter
silent! exe l:expr
" Match the symbol
@@ -1030,7 +1113,7 @@ function! <SID>SrcExpl_ViewOneDef(fpath, excmd)
call <SID>SrcExpl_SetCurrMark()
" Not highlight the word that had been searched.
- " Because execute EX command will active a search event
+ " Because execute Ex command will active a search event
let l:hlsearch = &hlsearch
set nohlsearch
" Refresh all the screen
@@ -1060,6 +1143,8 @@ function! <SID>SrcExpl_TagSth(expr)
let l:len = len(l:list)
else
call <SID>SrcExpl_WinPrompt(s:SrcExpl_pluginName . ' v' . string(s:SrcExpl_pluginVer))
+ " Should be regarded as 'no definition'
+ let s:SrcExpl_status = 0
return
endif
@@ -1268,6 +1353,18 @@ function! <SID>SrcExpl_CleanUp()
exe "nunmap " . g:SrcExpl_updateTagsKey
endif
+ " Unmap the prev-def key
+ if maparg(g:SrcExpl_prevDefKey, 'n') ==
+ \ ":call g:SrcExpl_PrevDef()<CR>"
+ exe "nunmap " . g:SrcExpl_prevDefKey
+ endif
+
+ " Unmap the next-def key
+ if maparg(g:SrcExpl_nextDefKey, 'n') ==
+ \ ":call g:SrcExpl_NextDef()<CR>"
+ exe "nunmap " . g:SrcExpl_nextDefKey
+ endif
+
" Unload the autocmd group
silent! autocmd! SrcExpl_AutoCmd
@@ -1345,6 +1442,16 @@ function! <SID>SrcExpl_Init()
\ " :call g:SrcExpl_UpdateTags()<CR>"
endif
+ if g:SrcExpl_prevDefKey != ""
+ exe "nnoremap " . g:SrcExpl_prevDefKey .
+ \ " :call g:SrcExpl_PrevDef()<CR>"
+ endif
+
+ if g:SrcExpl_nextDefKey != ""
+ exe "nnoremap " . g:SrcExpl_nextDefKey .
+ \ " :call g:SrcExpl_NextDef()<CR>"
+ endif
+
" Then we set the routine function when the event happens
augroup SrcExpl_AutoCmd
autocmd!
Please sign in to comment.
Something went wrong with that request. Please try again.