Last active
December 23, 2015 10:49
-
-
Save lirenlin/6623917 to your computer and use it in GitHub Desktop.
Generate ChangeLog file from diff file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| " File: C_from_D.vim | |
| " Author: Renlin Li | |
| " Version: 0.01 | |
| " Description: Generate a simple ChangeLog template from a diff file. | |
| " | |
| if exists('loaded_genCL') | |
| finish | |
| endif | |
| let loaded_genCL = 1 | |
| if !exists(':genCL') | |
| command GenCL call ScanPatch() | |
| endif | |
| fun! ScanPatch() | |
| if !(exists("g:CLauthor")) | |
| let g:CLauthor="YOUR NAME" | |
| endif | |
| if !(exists("g:CLemail")) | |
| let g:CLemail="YOUR EMAIL" | |
| endif | |
| if !(exists("g:CLfolder")) | |
| let g:CLfolder="gcc" | |
| endif | |
| let date=strftime("%Y-%m-%d") | |
| "let fileName="" | |
| "let funcName="" | |
| let fileList=[] | |
| let funcList=[] | |
| let tempList=[] | |
| let i = 1 | |
| while i <= line('$') | |
| let line = getline(i) | |
| let i=i+1 | |
| let fileName = matchstr(line, '^diff --git a\zs.\+\ze\sb.\+$') | |
| let fileName = strpart( fileName, len(g:CLfolder)+2) | |
| if fileName != "" | |
| if len(tempList) != 0 | |
| call add(funcList, tempList) | |
| let tempList=[] | |
| endif | |
| call add(fileList, fileName) | |
| continue | |
| endif | |
| let funcName = "" | |
| let found = matchstr(line, '^@@.\+@@') | |
| if found != "" | |
| let funcName = matchstr(line, '^@@.\+@@\s\zs.\+\ze\s(.\+$') | |
| if funcName == "" | |
| let funcName = matchstr(line, '^@@.\+@@\s\zs.\+\ze$') | |
| if funcName == "" | |
| let funcName = " " | |
| endif | |
| endif | |
| endif | |
| if funcName != "" | |
| " Check if function already in the list | |
| let exist=0 | |
| for element in tempList | |
| if element == funcName | |
| let exist=1 | |
| break | |
| endif | |
| endfor | |
| if exist == 0 | |
| call add(tempList, funcName) | |
| endif | |
| endif | |
| endwhile | |
| call add(funcList, tempList) | |
| "echo len(funcList) len(fileList) | |
| if len(fileList) == 0 | |
| echoh ErrorMsg | echo "OOps, nothing can be generated, | |
| \ is this a real patch file?" | echoh None | |
| else | |
| let header= "\n". g:CLfolder . "/ChangeLog:\n\n" | |
| let header= header . date . ' ' | |
| let header= header . g:CLauthor . ' ' | |
| let header= header . '<' . g:CLemail . ">\n\n" | |
| let body="" | |
| let i = 0 | |
| for fileName in fileList | |
| let body = body . "\t* " . fileName . " (" . funcList[i][0] . "): \n" | |
| for funcName in funcList[i][1:] | |
| let body = body . "\t(" . funcName . "): \n" | |
| endfor | |
| let i = i + 1 | |
| endfor | |
| let ChangeLog = header . body | |
| let bufName="ChangeLog--reserved" | |
| let bufExists=0 | |
| for b in range(1, bufnr('$')) | |
| if bufName == bufname(b) | |
| let bufExists=1 | |
| break | |
| endif | |
| endfor | |
| if bufExists | |
| "if bufloaded(bufName) | |
| " execute "normal! 1,$d" | |
| "else | |
| " execute "vertical sb ".bufName | |
| "endif | |
| execute "bd ".bufName | |
| endif | |
| vnew | |
| execute "setl noai nocin nosi inde=" | |
| execute 'set bt=nofile' | |
| execute 'f '. bufName | |
| call Refresh_minibufexpl_if() | |
| execute "normal! Go".ChangeLog | |
| "execute "normal! gg=G" | |
| call setpos('.',[0,1,1]) | |
| execute 'set filetype=changelog' | |
| endif | |
| endfun | |
| fun! Refresh_minibufexpl_if() | |
| if exists('g:loaded_minibufexplorer') | |
| execute "MBEToggle" | |
| execute "MBEToggle" | |
| endif | |
| endfun |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment