" ############################################################################# " ### Documentation ########################################################### " ############################################################################# " File: changelog.vim " Version: 1.01 " Summary: A function adding a ChangeLog entry. " Author: David Necas (Yeti) " Maintainer: Tim Skirvin " License: This Vim script is in the public domain. " URL: http://trific.ath.cx/Ftp/vim/scripts/changelog.vim " http://www.killfile.org/~tskirvin/uberconfig/vim/changelog.vim " " Do :ChangeLog inside a function you've just changed. The next 'ChangeLog' " file up in the directory tree from where you're working is opened and worked " with. Customizations: " " Set your name and e-mail in .vimrc: " let changelog_maintainer_name = "Me " " " Set function name matching regex for particular filetype: " let b:changelog_function_re = "^\\s*sub\\s*" " let b:changelog_function_re = "^\\s*\\(def\\|class\\)\\s*" " let b:changelog_function_re = "^\\(procedure\\|function\\)\\s\\+" " ... " The default is "^" appropriate for C, "" switches function names off. " " Main outstanding bug: the ChangeLog must not start with an actual entry! " There needs to be a blank line or some text or something, because the search " function won't spot something in the first line; it'll look for the second " instance, if there is one. Oh well. " ############################################################################# " ### Functions ############################################################### " ############################################################################# function! s:ChangeLog() " Save the old value of 'expandtab', so we can restore it later let val = &g:et set noexpandtab " Maintainer's name, try to guess when undefined if !exists('g:changelog_maintainer_name') echoerr 'changelog_maintainer_name not defined! guessing...' let node=substitute(system('hostname -f'), "\n", '', 'g') let usrinfo=system('grep ^`id -un`: /etc/passwd') let login=matchstr(usrinfo,'^\w\+') let t=matchend(usrinfo,'\w\+:[^:]\+:\d\+:\d\+:') let name=matchstr(usrinfo,'[^:]\+',t) let g:changelog_maintainer_name=name.' <'.login.'@'.node.'>' endif " Find current function name let l=line('.') let c=col('.') if exists('b:changelog_function_re') if strlen(b:changelog_function_re) == 0 let re='' else let re=b:changelog_function_re.'\w\+\s*[({]' endif else let re='^\w\+\s*[({]' endif if strlen(re) > 0 && search(re, 'bW') > 0 let foo=matchstr(getline('.'),'\w\+\(\s*[({]\)\@=') call cursor(l,c) if strlen(foo) > 0 let foo=' ('.foo.')' endif else let foo='' endif " Find and open the ChangeLog let f=expand('%:p:h') while strlen(f)>1 && !filewritable(f.'/ChangeLog') let f=fnamemodify(f,':h') endwhile let rf=strpart(expand('%:p'),strlen(f)+1) " Relativize filename let f=f.'/ChangeLog' if !filewritable(f) echoerr "Cannot find ChangeLog in parent directories" return endif execute "split ".f " Figure out the time format if exists('g:changelog_time_format') let timefmt=g:changelog_time_format else " Try to emulate date(1) output while being fairly portable (incl. Win32) let timefmt="%a %b %d %H:%M:%S %Z %Y" endif let datestring = strftime(timefmt) let string = strftime(timefmt).' '.g:changelog_maintainer_name " Add the entry call cursor(1,1) " FIXME: If changelog_time_format changes, this should change too " call search('^\u\l\l \u\l\l \+\d\+ \d\d:\d\d:\d\d ', 'W') if search(string) call cursor(line('.')+1,0) call append('.',' * '.rf.foo.':') " Note the real TAB call cursor(line('.')+1,10000) else if ! search(datestring) call cursor(1,1) call search('^\u\l\l \u\l\l \+\d\+ \d\d:\d\d:\d\d ', 'W') else call cursor(1,1) endif call cursor(line('.')-1,0) call append('.','') call append('.',' ') " Note the real TAB call append('.',' * '.rf.foo.':') " Note the real TAB call append('.','') call append('.',string) call cursor(line('.')+3,10000) endif " call search('^\d\d\d\d\-\d\d\-\d\d ', 'W') " Restore the old expandtab if val==1 set expandtab endif endfunction " ############################################################################# " ### main #################################################################### " ############################################################################# command! -nargs=0 ChangeLog call ChangeLog() " ############################################################################# " ### Version Log ############################################################# " ############################################################################# " # 1.0 Fri 08 Oct 12:12:12 CST 2004 yeti " ### Initial version I found on the web; I made up the version number. " # 1.0.2 Mon 18 Apr 09:36:39 CDT 2005 tskirvin " ### Better matches ChangeLog standards (real tabs, etc). Documented in my " ### standard style. Uses the timestamp format for searching. Adds new " ### entries to the current date if possible.