2 " Summary: A function adding a ChangeLog entry.
3 " Author: David Necas (Yeti) <yeti@physics.muni.cz>
4 " URL: http://trific.ath.cx/Ftp/vim/scripts/changelog.vim
5 " License: This Vim script is in the public domain.
7 " Usage: Do :ChangeLog inside a function you've just changed.
9 " Set your name and e-mail in .vimrc:
10 " let changelog_maintainer_name = "Me <me@example.net>"
11 " Set function name matching regex for particular filetype:
12 " let b:changelog_function_re = "^\\s*sub\\s*"
13 " let b:changelog_function_re = "^\\s*\\(def\\|class\\)\\s*"
14 " let b:changelog_function_re = "^\\(procedure\\|function\\)\\s\\+"
16 " The default is "^" appropriate for C, "" switches function names off.
18 command! -nargs=0 ChangeLog call <SID>ChangeLog()
19 function! s:ChangeLog()
20 " Maintainer's name, try to guess when undefined
21 if !exists('g:changelog_maintainer_name')
22 echoerr 'changelog_maintainer_name not defined! guessing...'
23 let node=substitute(system('hostname -f'), "\n", '', 'g')
24 let usrinfo=system('grep ^`id -un`: /etc/passwd')
25 let login=matchstr(usrinfo,'^\w\+')
26 let t=matchend(usrinfo,'\w\+:[^:]\+:\d\+:\d\+:')
27 let name=matchstr(usrinfo,'[^:]\+',t)
28 let g:changelog_maintainer_name=name.' <'.login.'@'.node.'>'
30 " Find current function name
33 if exists('b:changelog_function_re')
34 if strlen(b:changelog_function_re) == 0
37 let re=b:changelog_function_re.'\w\+\s*[({]'
42 if strlen(re) > 0 && search(re, 'bW') > 0
43 let foo=matchstr(getline('.'),'\w\+\(\s*[({]\)\@=')
51 " Find and open the ChangeLog
53 while strlen(f)>1 && !filewritable(f.'/ChangeLog')
54 let f=fnamemodify(f,':h')
56 let rf=strpart(expand('%:p'),strlen(f)+1) " Relativize filename
59 echoerr "Cannot find ChangeLog in parent directories"
65 " FIXME: If changelog_time_format changes, this should change too
66 call search('^\u\l\l \u\l\l \+\d\+ \d\d:\d\d:\d\d ', 'W')
67 call cursor(line('.')-1,0)
69 call append('.',' ') " Some people may want a TAB here
70 if exists('g:changelog_time_format')
71 let timefmt=g:changelog_time_format
73 " Try to emulate date(1) output while being fairly portable (incl. Win32)
74 let timefmt="%a %b %d %H:%M:%S %Z %Y"
76 call append('.',' * '.rf.foo.':') " Some people may want a TAB here
77 call append('.',strftime(timefmt).' '.g:changelog_maintainer_name)
78 call cursor(line('.')+3,10000)