1 " Vim filetype plugin file (GUI menu and folding)
2 " Language: Debian Changelog
3 " Maintainer: Michael Piefel <piefel@informatik.hu-berlin.de>
4 " Stefano Zacchiroli <zack@debian.org>
5 " Last Change: $LastChangedDate: 2006-08-24 23:41:26 +0200 (gio, 24 ago 2006) $
6 " License: GNU GPL, version 2.0 or later
7 " URL: http://svn.debian.org/wsvn/pkg-vim/trunk/runtime/ftplugin/debchangelog.vim?op=file&rev=0&sc=0
9 if exists("b:did_ftplugin")
14 " {{{1 Local settings (do on every load)
15 setlocal foldmethod=expr
16 setlocal foldexpr=GetDebChangelogFold(v:lnum)
17 setlocal foldtext=DebChangelogFoldText()
19 " Debian changelogs are not supposed to have any other text width,
20 " so the user cannot override this setting
25 let b:undo_ftplugin = "setlocal tw< comments< foldmethod< foldexpr< foldtext<"
28 if exists("g:did_changelog_ftplugin")
32 " Don't load another plugin (this is global)
33 let g:did_changelog_ftplugin = 1
37 " Helper functions returning various data.
38 " Returns full name, either from $DEBFULLNAME or debianfullname.
39 " TODO Is there a way to determine name from anywhere else?
40 function <SID>FullName()
41 if exists("$DEBFULLNAME")
43 elseif exists("g:debianfullname")
44 return g:debianfullname
50 " Returns email address, from $DEBEMAIL, $EMAIL or debianemail.
52 if exists("$DEBEMAIL")
54 elseif exists("$EMAIL")
56 elseif exists("g:debianemail")
59 return "your@email.address"
63 " Returns date in RFC822 format.
65 let savelang = v:lc_time
66 execute "language time C"
67 let dateandtime = strftime("%a, %d %b %Y %X %z")
68 execute "language time " . savelang
72 function <SID>WarnIfNotUnfinalised()
73 if match(getline("."), " -- [[:alpha:]][[:alnum:].]")!=-1
75 echo "The entry has not been unfinalised before editing."
82 function <SID>Finalised()
83 let savelinenum = line(".")
86 if match(getline("."), " -- [[:alpha:]][[:alnum:].]")!=-1
95 " These functions implement the menus
97 " The new entry is unfinalised and shall be changed
98 amenu disable Changelog.New\ Version
99 amenu enable Changelog.Add\ Entry
100 amenu enable Changelog.Close\ Bug
101 amenu enable Changelog.Set\ Distribution
102 amenu enable Changelog.Set\ Urgency
103 amenu disable Changelog.Unfinalise
104 amenu enable Changelog.Finalise
105 call append(0, substitute(getline(1), '-\([[:digit:]]\+\))', '-$$\1)', ''))
108 call append(3, " -- ")
110 call Distribution("unstable")
116 call setline(1, substitute(getline(1), '-\$\$', '-', ''))
125 call append(".", " * ")
127 let warn=<SID>WarnIfNotUnfinalised()
131 call input("Hit ENTER")
140 let warn=<SID>WarnIfNotUnfinalised()
142 call append(".", " * (closes: #" . input("Bug number to close: ") . ")")
147 function Distribution(dist)
148 call setline(1, substitute(getline(1), ") [[:lower:] ]*;", ") " . a:dist . ";", ""))
151 function Urgency(urg)
152 call setline(1, substitute(getline(1), "urgency=.*$", "urgency=" . a:urg, ""))
155 function <SID>UnfinaliseMenu()
156 " This means the entry shall be changed
157 amenu disable Changelog.New\ Version
158 amenu enable Changelog.Add\ Entry
159 amenu enable Changelog.Close\ Bug
160 amenu enable Changelog.Set\ Distribution
161 amenu enable Changelog.Set\ Urgency
162 amenu disable Changelog.Unfinalise
163 amenu enable Changelog.Finalise
166 function Unfinalise()
167 call <SID>UnfinaliseMenu()
170 call setline(".", " -- ")
173 function <SID>FinaliseMenu()
174 " This means the entry should not be changed anymore
175 amenu enable Changelog.New\ Version
176 amenu disable Changelog.Add\ Entry
177 amenu disable Changelog.Close\ Bug
178 amenu disable Changelog.Set\ Distribution
179 amenu disable Changelog.Set\ Urgency
180 amenu enable Changelog.Unfinalise
181 amenu disable Changelog.Finalise
185 call <SID>FinaliseMenu()
188 call setline(".", " -- " . <SID>FullName() . " <" . <SID>Email() . "> " . <SID>Date())
192 function <SID>MakeMenu()
193 amenu &Changelog.&New\ Version :call NewVersion()<CR>
194 amenu Changelog.&Add\ Entry :call AddEntry()<CR>
195 amenu Changelog.&Close\ Bug :call CloseBug()<CR>
196 menu Changelog.-sep- <nul>
198 amenu Changelog.Set\ &Distribution.&unstable :call Distribution("unstable")<CR>
199 amenu Changelog.Set\ Distribution.&frozen :call Distribution("frozen")<CR>
200 amenu Changelog.Set\ Distribution.&stable :call Distribution("stable")<CR>
201 menu Changelog.Set\ Distribution.-sep- <nul>
202 amenu Changelog.Set\ Distribution.frozen\ unstable :call Distribution("frozen unstable")<CR>
203 amenu Changelog.Set\ Distribution.stable\ unstable :call Distribution("stable unstable")<CR>
204 amenu Changelog.Set\ Distribution.stable\ frozen :call Distribution("stable frozen")<CR>
205 amenu Changelog.Set\ Distribution.stable\ frozen\ unstable :call Distribution("stable frozen unstable")<CR>
207 amenu Changelog.Set\ &Urgency.&low :call Urgency("low")<CR>
208 amenu Changelog.Set\ Urgency.&medium :call Urgency("medium")<CR>
209 amenu Changelog.Set\ Urgency.&high :call Urgency("high")<CR>
211 menu Changelog.-sep- <nul>
212 amenu Changelog.U&nfinalise :call Unfinalise()<CR>
213 amenu Changelog.&Finalise :call Finalise()<CR>
216 call <SID>FinaliseMenu()
218 call <SID>UnfinaliseMenu()
222 augroup changelogMenu
223 au BufEnter * if &filetype == "debchangelog" | call <SID>MakeMenu() | endif
224 au BufLeave * if &filetype == "debchangelog" | aunmenu Changelog | endif
230 " look for an author name in the [zonestart zoneend] lines searching backward
231 function! s:getAuthor(zonestart, zoneend)
232 let linepos = a:zoneend
233 while linepos >= a:zonestart
234 let line = getline(linepos)
236 return substitute(line, '^ --\s*\([^<]\+\)\s*.*', '\1', '')
243 function! DebChangelogFoldText()
244 if v:folddashes == '-' " changelog entry fold
245 return foldtext() . ' -- ' . s:getAuthor(v:foldstart, v:foldend) . ' '
250 function! GetDebChangelogFold(lnum)
251 let line = getline(a:lnum)
253 return '>1' " beginning of a changelog entry
255 if line =~ '^\s\+\[.*\]'
256 return '>2' " beginning of an author-specific chunk
264 foldopen! " unfold the entry the cursor is on (usually the first one)
268 " vim: set foldmethod=marker: