NEWS/Changelog for previous commit.
[fvwm.git] / utils / changelog.vim
blob81aace515aff91a3ad2fb38b93a738d10791d6c1
1 " File: changelog.vim
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.
6 " Version: 2004-10-08
7 " Usage: Do :ChangeLog inside a function you've just changed.
8 " Customization:
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\\+"
15 "   ...
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.'>'
29   endif
30   " Find current function name
31   let l=line('.')
32   let c=col('.')
33   if exists('b:changelog_function_re')
34     if strlen(b:changelog_function_re) == 0
35       let re=''
36     else
37       let re=b:changelog_function_re.'\w\+\s*[({]'
38     endif
39   else
40     let re='^\w\+\s*[({]'
41   endif
42   if strlen(re) > 0 && search(re, 'bW') > 0
43     let foo=matchstr(getline('.'),'\w\+\(\s*[({]\)\@=')
44     call cursor(l,c)
45     if strlen(foo) > 0
46       let foo=' ('.foo.')'
47     endif
48   else
49     let foo=''
50   endif
51   " Find and open the ChangeLog
52   let f=expand('%:p:h')
53   while strlen(f)>1 && !filewritable(f.'/ChangeLog')
54     let f=fnamemodify(f,':h')
55   endwhile
56   let rf=strpart(expand('%:p'),strlen(f)+1)  " Relativize filename
57   let f=f.'/ChangeLog'
58   if !filewritable(f)
59     echoerr "Cannot find ChangeLog in parent directories"
60     return
61   endif
62   execute "split ".f
63   " Add the entry
64   call cursor(1,1)
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)
68   call append('.','')
69   call append('.','      ')    " Some people may want a TAB here
70   if exists('g:changelog_time_format')
71     let timefmt=g:changelog_time_format
72   else
73     " Try to emulate date(1) output while being fairly portable (incl. Win32)
74     let timefmt="%a %b %d %H:%M:%S %Z %Y"
75   endif
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)
79 endfunction