|
|
第7行: |
第7行: |
| [[Image:Vim marks.PNG|vim marks]] | | [[Image:Vim marks.PNG|vim marks]] |
|
| |
|
| " ---------------------------------------------------------------------<br>" put on one sign<br>fun! Place_sign()
| |
|
| |
|
| if !exists("s:Cs_sign_number")<br> let s:Cs_sign_number = 1<br> endif
| |
|
| |
|
| if s:Cs_sign_number > 99<br> echo "Sorry, you only can use these marks less 100!"<br> return -1<br> else<br> let s:Cs_sign_number = (s:mylist[len(s:mylist) - 1][0] * 1) + 1<br> endif
| | <br> |
| | |
| let vLn = "".line(".")<br> let vFileName = expand("%:p")
| |
| | |
| let vFlagNum = (s:Cs_sign_number < 10 ? "0" . s:Cs_sign_number : s:Cs_sign_number)<br> let newItem = [vFlagNum,vLn,vFileName]<br> let vIndex = s:Check_list(newItem)
| |
| | |
| if vIndex > -1<br> call s:Remove_sign(vIndex)<br> else<br> silent! exe 'sign define CS' . vFlagNum . ' text='. vFlagNum .' texthl=ErrorMsg'<br> silent! exe 'sign place ' . vFlagNum . ' line=' . vLn . ' name=CS'. vFlagNum . ' file=' . vFileName
| |
| | |
| "let s:Cs_sign_number = s:Cs_sign_number + 1<br> let s:mylist = s:mylist + [newItem]<br> " record the last index.<br> let s:myIndex = len(s:mylist) - 1<br> let s:deleteFlag = 0<br> endif<br> "echo s:mylist<br>endfun
| |
| | |
| " ---------------------------------------------------------------------<br>" Remove all signs<br>fun! Remove_all_signs()
| |
| | |
| silent! exe 'sign unplace *'<br> if len(s:mylist) > 1<br> let i = remove(s:mylist, 1, -1)<br> let s:Cs_sign_number = 1<br> endif<br> "echo s:mylist<br>endfun
| |
| | |
| " ---------------------------------------------------------------------<br>" Goto prev sign:<br>fun! Goto_prev_sign()
| |
| | |
| if len(s:mylist) > 1<br> if s:deleteFlag == 0<br> let s:myIndex = s:myIndex - 1<br> endif<br> let s:deleteFlag = 0
| |
| | |
| if s:myIndex <= 0<br> let s:myIndex = len(s:mylist) - 1<br> endif<br> call s:Sign_jump(s:mylist[s:myIndex])<br> endif<br>endfun
| |
| | |
| " ---------------------------------------------------------------------<br>" Goto next sign:<br>fun! Goto_next_sign()
| |
| | |
| let s:deleteFlag = 0<br> if len(s:mylist) > 1<br> let s:myIndex = s:myIndex + 1<br> if ((s:myIndex >= len(s:mylist)) || (s:myIndex == 1))<br> let s:myIndex = 1<br> endif<br> call s:Sign_jump(s:mylist[s:myIndex])<br> endif<br>endfun<br>" ---------------------------------------------------------------------<br>" Save_signs_to_file<br>fun! Save_signs_to_file()
| |
| | |
| call s:Get_signs_file_name()<br> let tempList = []<br> for item in s:mylist<br> let tempList = tempList + [item[0] . "#" . item[1]. "#" . item[2]]<br> endfor<br> let writeFlag = writefile(tempList, s:outputFileName)
| |
| | |
| endfun<br>" ---------------------------------------------------------------------<br>" Load_signs_from_file<br>fun! Load_signs_from_file()
| |
| | |
| call s:Get_signs_file_name()<br> if filereadable(s:outputFileName)<br> let tempList = [[]]<br> let iflag = 0<br> for line in readfile(s:outputFileName)<br> let first = stridx(line, "#", 0)<br> let second = stridx(line, "#", first + 1)<br> if iflag != 0<br> let tempList = tempList + [[strpart(line, 0, first), strpart(line, first + 1, second - first - 1), strpart(line, second + 1)]]<br> else<br> let tempList = [[strpart(line, 0, first), strpart(line, first + 1, second - first - 1), strpart(line, second + 1)]]<br> endif<br> let iflag = 1<br> endfor<br> let s:mylist = tempList<br> endif
| |
| | |
| call s:Flash_signs()
| |
| | |
| "echo s:mylist<br>endfun
| |
| | |
| " ---------------------------------------------------------------------<br>fun! s:Get_signs_file_name()
| |
| | |
| if exists("g:Signs_file_path_corey")<br> let s:outputFileName = g:Signs_file_path_corey . "_DO_NOT_DELETE_IT"<br> endif<br>endfun
| |
| | |
| " ---------------------------------------------------------------------<br>" Remove one sign<br>fun! s:Remove_sign(aIndex)
| |
| | |
| if len(s:mylist) > 1<br> silent! exe 'sign unplace ' .s:mylist[a:aIndex][0] . ' file=' . s:mylist[a:aIndex][2]
| |
| | |
| " record the before item<br> let s:tmplist = s:mylist[a:aIndex - 1]
| |
| | |
| let i = remove(s:mylist, a:aIndex)
| |
| | |
| " record the current index.<br> let s:myIndex = s:Check_list(s:tmplist)<br> let s:deleteFlag = 1<br> "echo s:mylist<br> endif<br>endfun
| |
| | |
| " ---------------------------------------------------------------------<br>fun! s:Flash_signs()
| |
| | |
| silent! exe 'sign unplace *'<br> if len(s:mylist) > 1<br> for item in s:mylist<br> silent! exe 'sign define CS' . item[0] . ' text='. item[0] .' texthl=ErrorMsg'<br> silent! exe 'sign place ' . item[0] . ' line=' . item[1] . ' name=CS'. item[0] . ' file=' . item[2]<br> endfor<br> endif<br> let s:Cs_sign_number = s:mylist[len(s:mylist) - 1][0] * 1 + 1 <br> "let s:myIndex = 1 ##you don't need reset the pointer<br>endfun
| |
| | |
| " ---------------------------------------------------------------------<br>" if line number and file name both same, return the aitem's index of s:mylist<br>" else return -1<br>" index 0 of s:mylist is the output message in the record file.<br>fun! s:Check_list(aItem)
| |
| | |
| let vResult = -1<br> let index = 0
| |
| | |
| for item in s:mylist<br> " file name is ignoring case<br> if ((s:Compare(item[1], a:aItem[1]) == 1) && (s:Compare(item[2],a:aItem[2]) == 1))<br> return index<br> endif<br> let index = index + 1<br> endfor
| |
| | |
| return vResult<br>endfun
| |
| | |
| " ---------------------------------------------------------------------<br>" Move_sign<br>fun! Move_sign()
| |
| | |
| let s:tempItem = ["","",""]<br> let vRLn = "".line(".")<br> let vRFileName = expand("%:p")
| |
| | |
| let s:tempItem[1] = vRLn<br> let s:tempItem[2] = vRFileName<br> "echo s:tempItem<br> let vRIndex = s:Check_list(s:tempItem)
| |
| | |
| if (s:remarkItem[0] ==# "REMARK" )<br> if vRIndex > 0<br> silent! exe 'sign define CS' . s:mylist[vRIndex][0] . ' text='. s:mylist[vRIndex][0] .' texthl=Search'<br> silent! exe 'sign place ' . s:mylist[vRIndex][0] . ' line=' . vRLn . ' name=CS'. s:mylist[vRIndex][0] . ' file=' . vRFileName<br> let s:remarkItem = s:mylist[vRIndex]<br> let s:myIndex = vRIndex<br> "echo s:remarkItem<br> endif<br> else<br> let pionter = s:Check_list(s:remarkItem)<br> "echo vRIndex ."|" .pionter<br> if ((vRIndex < 0) && (pionter > 0))<br> silent! exe 'sign unplace ' .s:remarkItem[0] . ' file=' . s:remarkItem[2]<br> "silent! exe 'sign undefine' .s:remarkItem[0]<br> silent! exe 'sign define CS' . s:remarkItem[0] . ' text='. s:remarkItem[0] .' texthl=ErrorMsg'<br> silent! exe 'sign place ' . s:remarkItem[0] . ' line=' . vRLn . ' name=CS' . s:remarkItem[0] . ' file=' . vRFileName<br> let s:mylist[pionter][1] = vRLn<br> let s:mylist[pionter][2] = vRFileName<br> "echo s:mylist[pionter]<br> let s:myIndex = pionter<br> let s:remarkItem = ["REMARK","SEARCH","FLAG"]<br> endif<br> endif<br>endfun
| |
| | |
| " -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*<br>" all of them used for the jump.<br>fun! s:Sign_jump(aSignItem)<br> let bufferExits = s:GetTabpage(a:aSignItem)
| |
| | |
| if bufferExits > 0<br> silent! exe 'tabn ' . bufferExits<br> silent! exe 'sign jump '. a:aSignItem[0] . ' file='. a:aSignItem[2]<br> else<br> call s:Open_file(a:aSignItem[2])<br> silent! exe 'sign place ' . a:aSignItem[0] . ' line=' . a:aSignItem[1] . ' name=CS'. a:aSignItem[0] . ' file=' . a:aSignItem[2]<br> silent! exe 'sign jump '. a:aSignItem[0] . ' file='. a:aSignItem[2]<br> endif
| |
| | |
| endfun
| |
| | |
| " ---------------------------------------------------------------------<br>" GetTabpage<br>fun! s:GetTabpage(aSignItem)
| |
| | |
| let bufname = expand("%:p")<br> if s:Compare(bufname,a:aSignItem[2]) == 1<br> return tabpagenr()<br> endif
| |
| | |
| let i = 0
| |
| | |
| while i < tabpagenr('$')
| |
| | |
| if i == 0<br> silent! exe 'tabfirst'<br> else<br> silent! exe 'tabnext'<br> endif<br> let bufname = expand("%:p")
| |
| | |
| if s:Compare(bufname,a:aSignItem[2]) == 1<br> return i + 1<br> endif
| |
| | |
| let i = i + 1<br> endwhile
| |
| | |
| return -1<br>endfun<br>" ---------------------------------------------------------------------<br>" compare<br>fun! s:Compare(a1,a2)<br> if s:win32Flag == 1 <br> if a:a1 ==? a:a2<br> return 1<br> endif<br> else<br> if a:a1 ==# a:a2<br> return 1<br> endif<br> endif<br> return 0<br>endfun<br>" ---------------------------------------------------------------------<br>" open file<br><br>
| |