844
|
1 " Vim filetype plugin file (GUI menu and folding)
|
7
|
2 " Language: Debian Changelog
|
|
3 " Maintainer: Michael Piefel <piefel@informatik.hu-berlin.de>
|
844
|
4 " Stefano Zacchiroli <zack@debian.org>
|
848
|
5 " Last Change: $LastChangedDate: 2006-04-28 12:15:12 -0400 (ven, 28 apr 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
|
|
8
|
|
9 if exists("b:did_ftplugin")
|
|
10 finish
|
|
11 endif
|
|
12 let b:did_ftplugin = 1
|
|
13
|
|
14 " {{{1 Local settings (do on every load)
|
|
15 setlocal foldmethod=expr
|
|
16 setlocal foldexpr=GetDebChangelogFold(v:lnum)
|
|
17 setlocal foldtext=DebChangelogFoldText()
|
|
18
|
|
19 " Debian changelogs are not supposed to have any other text width,
|
|
20 " so the user cannot override this setting
|
|
21 setlocal tw=78
|
|
22 setlocal comments=f:*
|
|
23
|
|
24 " Clean unloading
|
|
25 let b:undo_ftplugin = "setlocal tw< comments< foldmethod< foldexpr< foldtext<"
|
|
26 " }}}1
|
7
|
27
|
|
28 if exists("g:did_changelog_ftplugin")
|
|
29 finish
|
|
30 endif
|
|
31
|
|
32 " Don't load another plugin (this is global)
|
|
33 let g:did_changelog_ftplugin = 1
|
|
34
|
844
|
35 " {{{1 GUI menu
|
|
36
|
7
|
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")
|
|
42 return $DEBFULLNAME
|
|
43 elseif exists("g:debianfullname")
|
|
44 return g:debianfullname
|
|
45 else
|
|
46 return "Your Name"
|
|
47 endif
|
|
48 endfunction
|
|
49
|
|
50 " Returns email address, from $DEBEMAIL, $EMAIL or debianemail.
|
|
51 function <SID>Email()
|
|
52 if exists("$DEBEMAIL")
|
|
53 return $DEBEMAIL
|
|
54 elseif exists("$EMAIL")
|
|
55 return $EMAIL
|
|
56 elseif exists("g:debianemail")
|
481
|
57 return g:debianemail
|
7
|
58 else
|
|
59 return "your@email.address"
|
|
60 endif
|
|
61 endfunction
|
|
62
|
|
63 " Returns date in RFC822 format.
|
|
64 function <SID>Date()
|
|
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
|
|
69 return dateandtime
|
|
70 endfunction
|
|
71
|
|
72 function <SID>WarnIfNotUnfinalised()
|
|
73 if match(getline("."), " -- [[:alpha:]][[:alnum:].]")!=-1
|
|
74 echohl WarningMsg
|
|
75 echo "The entry has not been unfinalised before editing."
|
|
76 echohl None
|
|
77 return 1
|
|
78 endif
|
|
79 return 0
|
|
80 endfunction
|
|
81
|
|
82 function <SID>Finalised()
|
|
83 let savelinenum = line(".")
|
|
84 normal 1G
|
|
85 call search("^ -- ")
|
|
86 if match(getline("."), " -- [[:alpha:]][[:alnum:].]")!=-1
|
|
87 let returnvalue = 1
|
|
88 else
|
|
89 let returnvalue = 0
|
|
90 endif
|
|
91 execute savelinenum
|
|
92 return returnvalue
|
|
93 endfunction
|
|
94
|
|
95 " These functions implement the menus
|
|
96 function NewVersion()
|
|
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
|
848
|
105 call append(0, substitute(getline(1), '-\([[:digit:]]\+\))', '-$$\1)', ''))
|
7
|
106 call append(1, "")
|
|
107 call append(2, "")
|
|
108 call append(3, " -- ")
|
|
109 call append(4, "")
|
|
110 call Distribution("unstable")
|
|
111 call Urgency("low")
|
|
112 normal 1G
|
|
113 call search(")")
|
|
114 normal h
|
|
115 normal
|
848
|
116 call setline(1, substitute(getline(1), '-\$\$', '-', ''))
|
|
117 normal zo
|
7
|
118 call AddEntry()
|
|
119 endfunction
|
|
120
|
|
121 function AddEntry()
|
|
122 normal 1G
|
|
123 call search("^ -- ")
|
|
124 normal kk
|
|
125 call append(".", " * ")
|
|
126 normal jjj
|
|
127 let warn=<SID>WarnIfNotUnfinalised()
|
|
128 normal kk
|
|
129 if warn
|
|
130 echohl MoreMsg
|
|
131 call input("Hit ENTER")
|
|
132 echohl None
|
|
133 endif
|
|
134 startinsert!
|
|
135 endfunction
|
|
136
|
|
137 function CloseBug()
|
|
138 normal 1G
|
|
139 call search("^ -- ")
|
|
140 let warn=<SID>WarnIfNotUnfinalised()
|
|
141 normal kk
|
|
142 call append(".", " * (closes: #" . input("Bug number to close: ") . ")")
|
|
143 normal j^ll
|
|
144 startinsert
|
|
145 endfunction
|
|
146
|
|
147 function Distribution(dist)
|
|
148 call setline(1, substitute(getline(1), ") [[:lower:] ]*;", ") " . a:dist . ";", ""))
|
|
149 endfunction
|
|
150
|
|
151 function Urgency(urg)
|
|
152 call setline(1, substitute(getline(1), "urgency=.*$", "urgency=" . a:urg, ""))
|
|
153 endfunction
|
|
154
|
|
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
|
|
164 endfunction
|
|
165
|
|
166 function Unfinalise()
|
|
167 call <SID>UnfinaliseMenu()
|
|
168 normal 1G
|
|
169 call search("^ -- ")
|
|
170 call setline(".", " -- ")
|
|
171 endfunction
|
|
172
|
|
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
|
|
182 endfunction
|
|
183
|
|
184 function Finalise()
|
|
185 call <SID>FinaliseMenu()
|
|
186 normal 1G
|
|
187 call search("^ -- ")
|
|
188 call setline(".", " -- " . <SID>FullName() . " <" . <SID>Email() . "> " . <SID>Date())
|
|
189 endfunction
|
|
190
|
|
191
|
|
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>
|
|
197
|
|
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>
|
|
206
|
|
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>
|
|
210
|
|
211 menu Changelog.-sep- <nul>
|
|
212 amenu Changelog.U&nfinalise :call Unfinalise()<CR>
|
|
213 amenu Changelog.&Finalise :call Finalise()<CR>
|
|
214
|
|
215 if <SID>Finalised()
|
|
216 call <SID>FinaliseMenu()
|
|
217 else
|
|
218 call <SID>UnfinaliseMenu()
|
|
219 endif
|
|
220 endfunction
|
|
221
|
|
222 augroup changelogMenu
|
|
223 au BufEnter * if &filetype == "debchangelog" | call <SID>MakeMenu() | endif
|
|
224 au BufLeave * if &filetype == "debchangelog" | aunmenu Changelog | endif
|
|
225 augroup END
|
|
226
|
844
|
227 " }}}
|
|
228 " {{{1 folding
|
|
229
|
|
230 " look for an author name searching backward from a given line number
|
|
231 function! s:getAuthor(lnum)
|
|
232 let line = getline(a:lnum)
|
|
233 let backsteps = 0
|
|
234 while line !~ '^ --'
|
|
235 let backsteps += 1
|
|
236 let line = getline(a:lnum - backsteps)
|
|
237 endwhile
|
|
238 let author = substitute(line, '^ --\s*\([^<]\+\)\s*.*', '\1', '')
|
|
239 return author
|
|
240 endfunction
|
|
241
|
|
242 function! DebChangelogFoldText()
|
|
243 if v:folddashes == '-' " changelog entry fold
|
|
244 return foldtext() . ' -- ' . s:getAuthor(v:foldend) . ' '
|
|
245 endif
|
|
246 return foldtext()
|
|
247 endfunction
|
|
248
|
|
249 function! GetDebChangelogFold(lnum)
|
|
250 let line = getline(a:lnum)
|
|
251 if line =~ '^\w\+'
|
|
252 return '>1' " beginning of a changelog entry
|
|
253 endif
|
|
254 if line =~ '^\s\+\[.*\]'
|
|
255 return '>2' " beginning of an author-specific chunk
|
|
256 endif
|
|
257 if line =~ '^ --'
|
|
258 return '1'
|
|
259 endif
|
|
260 return '='
|
|
261 endfunction
|
|
262
|
|
263 " }}}
|
|
264
|
|
265 " vim: set foldmethod=marker:
|