if !has("python")echo "vim has to be compiled with +python to run this"finishendifif exists('g:loaded_stackview_plugin')finishendif" the rest of plugin VimL code goes herelet g:loaded_stackview_plugin = 1let s:plugin_root_dir = fnamemodify(resolve(expand('<sfile>:p')), ':h')python << EOFimport sysfrom os.path import normpath, joinimport vimplugin_root_dir = vim.eval('s:plugin_root_dir')python_root_dir = normpath(join(plugin_root_dir, '..', 'python'))sys.path.insert(0, python_root_dir)from gdbmi_utils import *EOFlet StackView_title = "__StackView_List__"let s:StackView_bufnum = 0let StackViewTagNameFG ='#43beef'let StackViewTagFocusFG ='#2e8b57'"FUNCTION: s:bufInWindows(bnum)"Determine the number of windows open to this buffer number."Care of Yegappan Lakshman. Thanks!""Args:"bnum: the subject buffers buffer numberfunction! s:bufInWindows(bnum)let cnt = 0let winnum = 1while 1let bufnum = winbufnr(winnum)if bufnum < 0breakendifif bufnum == a:bnumlet cnt = cnt + 1endiflet winnum = winnum + 1endwhilereturn cntendfunction"FUNCTION: s:isWindowUsable(winnumber)"Returns 1 if opening a file from the tree in the given window requires it to"be split""Args:"winnumber: the number of the window in questionfunction! s:isWindowUsable(winnumber)"gotta split if theres only one window (i.e. the NERD tree)if winnr("$") == 1return 0endiflet oldwinnr = winnr()exec a:winnumber . "wincmd p"let specialWindow = getbufvar("%", '&buftype') != '' || getwinvar('%', '&previewwindow')let modified = &modifiedexec oldwinnr . "wincmd p""if its a special window e.g. quickfix or another explorer plugin then we"have to splitif specialWindowreturn 0endifif &hiddenreturn 1endifreturn !modified || s:bufInWindows(winbufnr(a:winnumber)) >= 2endfunction"FUNCTION: s:firstNormalWindow()"find the window number of the first normal windowfunction! s:firstNormalWindow()let i = 1while i <= winnr("$")let bnum = winbufnr(i)if bnum != -1 && getbufvar(bnum, '&buftype') == ''\ && !getwinvar(i, '&previewwindow')return iendiflet i += 1endwhilereturn -1endfunction" StackView_Open_Window" Create a new window. If it is already open, clear itfunction! s:StackView_Open_Window()" Cleanup the window listing, if the window is openlet winnum = bufwinnr(g:StackView_title)if winnum != -1" Jump to the existing windowif winnr() != winnumexe winnum . 'wincmd w'endifelse" If the tag listing temporary buffer already exists, then reuse it." Otherwise create a new bufferlet bufnum = bufnr(g:StackView_title)if bufnum == -1" Create a new bufferlet wcmd = g:StackView_titleelse" Edit the existing bufferlet wcmd = '+buffer' . bufnumendiflet s:StackView_bufnum = bufnum" Create the windowexe 'silent! ' . 'topleft vertical 30 new ' . wcmdendifendfunction" StackView_Cleanup()" Cleanup all the window variables.function! s:StackView_Cleanup()if has('syntax')silent! syntax clear StackViewTitlesilent! syntax clear StackViewTagNamesilent! syntax clear StackViewTagFocusendifmatch noneif exists('b:tlist_wp_count') && b:tlist_wp_count != ''let line_num = 0while line_num < b:tlist_wp_countlet item_index = 0while item_index < b:tlist_fp_{line_num}_countunlet! b:tlist_fp_{line_num}_{item_index}_fullnameunlet! b:tlist_fp_{line_num}_{item_index}_linelet item_index = item_index + 1endwhileunlet! b:tlist_fp_{line_num}_listlet line_num = line_num + 1endwhileendifunlet! b:tlist_wp_startunlet! b:tlist_wp_countunlet! b:tlist_wp_listendfunction" StackView_Init_Window" Set the default options for the windowfunction! s:StackView_Init_Window(filename)" Set report option to a huge value to prevent informations messages" while deleting the lineslet old_report = &reportset report=99999" Mark the buffer as modifiablesetlocal modifiable" Delete the contents of the buffer to the black-hole registersilent! %delete _" Mark the buffer as not modifiablesetlocal nomodifiable" Restore the report optionlet &report = old_report" Clean up all the old variables used for the last filetypecall <SID>StackView_Cleanup()" Mark the buffer as modifiablesetlocal modifiablecall append(0, '" StackView')let txt = fnamemodify(a:filename, ':t') . ' (' .\ fnamemodify(a:filename, ':p:h') . ')'silent! put! =txt" Mark the buffer as not modifiablesetlocal nomodifiable" Highlight the commentsif has('syntax')syntax match StackViewComment '^" .*'syntax match StackViewFileName '^[^" ].*$'" Colors to highlight comments and titleshighlight clear StackViewCommenthighlight link StackViewComment Commenthighlight clear StackViewTitlehighlight link StackViewTitle Titleif hlexists('MyStackViewFileName')highlight link StackViewFileName MyStackViewFileNameelsehighlight clear StackViewFileNamehighlight default StackViewFileName guibg=Grey ctermbg=darkgray\ guifg=white ctermfg=whiteendifendif" Folding related settingsif has('folding')setlocal foldenablesetlocal foldmethod=manualsetlocal foldcolumn=2setlocal foldtext=v:folddashes.getline(v:foldstart)endif" Mark buffer as scratchsilent! setlocal buftype=nofilesilent! setlocal bufhidden=deletesilent! setlocal noswapfile" Due to a bug in Vim 6.0, the winbufnr() function fails for unlisted" buffers. So if the list buffer is unlisted, multiple list" windows will be opened. This bug is fixed in Vim 6.1 and aboveif v:version >= 601silent! setlocal nobuflistedendifsilent! setlocal nowrap" If the 'number' option is set in the source window, it will affect the" list window. So forcefully disable 'number' option for the list" windowsilent! setlocal nonumbersilent! setlocal winfixwidthsilent! setlocal nospelliabc <buffer>nnoremap <buffer> <silent> <2-LeftMouse> :call <SID>StackView_Jump_To_Tag(0)<CR>endfunctionfunction! s:StackView_Window_Refresh(bkfile)" Mark the buffer as modifiablesetlocal modifiablenormal! ggdG" Mark the buffer as not modifiablesetlocal nomodifiable" Initialize the list windowcall s:StackView_Init_Window(a:bkfile)" List the tags defined in a filecall s:StackView_Explore_File(a:bkfile)endfunction" StackView_Explore_File()" List the tags defined in the specified file in a Vim windowfunction! s:StackView_Explore_File(filename)let bufnum = s:StackView_bufnumlet ftype = fnamemodify(a:filename, ':e')" Check for valid filename and valid filetypeif a:filename == '' || !filereadable(a:filename) || ftype == ''returnendif" Set report option to a huge value to prevent informational messages" while adding lines to the list windowlet old_report = &reportset report=99999" Mark the buffer as modifiablesetlocal modifiableif !exists('b:curr_wp_select')let b:curr_wp_select = 0endifcall LoadConfig(a:filename)silent! put ='focus'let b:tlist_wp_start = line('.')silent! put = b:tlist_wp_list" create a fold for focusif has('folding')let fold_start = b:tlist_wp_startlet fold_end = fold_start + b:tlist_wp_countexe fold_start . ',' . fold_end . 'fold'endif" Syntax highlight the focus namesif has('syntax')exe 'syntax match StackViewTitle /\%' . b:tlist_wp_start . 'l.*/'silent! syntax clear StackViewTagFocussilent! exe 'highlight StackViewTagFocus term=bold ctermfg=Cyan guifg=' . g:StackViewTagFocusFG . ' gui=bold'let l:hl_line = b:tlist_wp_start + b:curr_wp_select + 1silent! exe 'syntax match StackViewTagFocus /\%' . l:hl_line . 'l.*/'endifsilent! put =''let b:tlist_fp_start = line('.') + 1silent! put ='stack_list'silent! put = b:tlist_fp_{b:curr_wp_select}_list" create a fold for stack_listif has('folding')let fold_start = b:tlist_fp_startlet fold_end = fold_start + b:tlist_fp_{b:curr_wp_select}_countexe fold_start . ',' . fold_end . 'fold'endif" Syntax highlight the stack_list namesif has('syntax')exe 'syntax match StackViewTitle /\%' . b:tlist_fp_start . 'l.*/'endifnormal! Gdd" Mark the buffer as not modifiablesetlocal nomodifiable" Restore the report optionlet &report = old_report" Initially open all the foldsif has('folding')silent! %foldopen!endif" Goto the first line in the buffergoreturnendfunction" StackView_Toggle_Window()" Open a StackView windowfunction! s:StackView_Toggle_Window(bkfile)if a:bkfile == ""echo 'Please specify a file[*.bkpt] path!'returnendiflet curline = line('.')" If list window is open then close it.let winnum = bufwinnr(g:StackView_title)if winnum != -1if winnr() == winnum" Already in the list window. Close it and returncloseelse" Goto the list window, close it and then come back to the" original windowlet curbufnr = bufnr('%')exe winnum . 'wincmd w'close" Need to jump back to the original window only if we are not" already in that windowlet winnum = bufwinnr(curbufnr)if winnr() != winnumexe winnum . 'wincmd w'endifendifreturnendif" Open the list windowcall s:StackView_Open_Window()" Initialize the list windowcall s:StackView_Init_Window(a:bkfile)" List the tags defined in a filecall s:StackView_Explore_File(a:bkfile)endfunction" StackView_Jump_To_Tag()" Jump to the location of the current tagfunction! s:StackView_Jump_To_Tag(new_window)" Do not process comment lines and empty lineslet curline = line('.') - 1if curline >= b:tlist_fp_startlet l:tag_num = curline - b:tlist_fp_startlet l:tag_fullname = b:tlist_fp_{b:curr_wp_select}_{l:tag_num}_fullnamelet l:tag_line = b:tlist_fp_{b:curr_wp_select}_{l:tag_num}_linesilent! syntax clear StackViewTagNamesilent! exe 'highlight StackViewTagName term=bold ctermfg=Cyan guifg=' . g:StackViewTagNameFG . ' gui=bold'silent! exe 'syntax match StackViewTagName /\%' . line('.') . 'l.*/'if !s:isWindowUsable(winnr("#"))exec s:firstNormalWindow() . "wincmd w"elsewincmd pendifexec ("edit " . l:tag_fullname)" Jump to the tagsilent call cursor(l:tag_line, 0)elseif curline >= b:tlist_wp_start && curline < b:tlist_wp_start + b:tlist_wp_countlet b:curr_wp_select = curline - b:tlist_wp_startcall s:StackView_Window_Refresh(s:stackview_config_path)elsereturnendifendfunctionfunction! LoadConfig(filename)let s:stackview_config_path = a:filenamepython load_config()endfunctioncommand! -n=? -complete=file StackView :call s:StackView_Toggle_Window('<args>')
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。