7
|
1 " Vim filetype plugin file
|
|
2 " Language: Debian Changelog
|
|
3 " Maintainer: Michael Piefel <piefel@informatik.hu-berlin.de>
|
|
4 " Last Change: 23 March 2004
|
|
5
|
|
6 if exists("g:did_changelog_ftplugin")
|
|
7 finish
|
|
8 endif
|
|
9
|
|
10 " Don't load another plugin (this is global)
|
|
11 let g:did_changelog_ftplugin = 1
|
|
12
|
|
13 " Helper functions returning various data.
|
|
14 " Returns full name, either from $DEBFULLNAME or debianfullname.
|
|
15 " TODO Is there a way to determine name from anywhere else?
|
|
16 function <SID>FullName()
|
|
17 if exists("$DEBFULLNAME")
|
|
18 return $DEBFULLNAME
|
|
19 elseif exists("g:debianfullname")
|
|
20 return g:debianfullname
|
|
21 else
|
|
22 return "Your Name"
|
|
23 endif
|
|
24 endfunction
|
|
25
|
|
26 " Returns email address, from $DEBEMAIL, $EMAIL or debianemail.
|
|
27 function <SID>Email()
|
|
28 if exists("$DEBEMAIL")
|
|
29 return $DEBEMAIL
|
|
30 elseif exists("$EMAIL")
|
|
31 return $EMAIL
|
|
32 elseif exists("g:debianemail")
|
|
33 return g:debianfullemail
|
|
34 else
|
|
35 return "your@email.address"
|
|
36 endif
|
|
37 endfunction
|
|
38
|
|
39 " Returns date in RFC822 format.
|
|
40 function <SID>Date()
|
|
41 let savelang = v:lc_time
|
|
42 execute "language time C"
|
|
43 let dateandtime = strftime("%a, %d %b %Y %X %z")
|
|
44 execute "language time " . savelang
|
|
45 return dateandtime
|
|
46 endfunction
|
|
47
|
|
48 function <SID>WarnIfNotUnfinalised()
|
|
49 if match(getline("."), " -- [[:alpha:]][[:alnum:].]")!=-1
|
|
50 echohl WarningMsg
|
|
51 echo "The entry has not been unfinalised before editing."
|
|
52 echohl None
|
|
53 return 1
|
|
54 endif
|
|
55 return 0
|
|
56 endfunction
|
|
57
|
|
58 function <SID>Finalised()
|
|
59 let savelinenum = line(".")
|
|
60 normal 1G
|
|
61 call search("^ -- ")
|
|
62 if match(getline("."), " -- [[:alpha:]][[:alnum:].]")!=-1
|
|
63 let returnvalue = 1
|
|
64 else
|
|
65 let returnvalue = 0
|
|
66 endif
|
|
67 execute savelinenum
|
|
68 return returnvalue
|
|
69 endfunction
|
|
70
|
|
71 " These functions implement the menus
|
|
72 function NewVersion()
|
|
73 " The new entry is unfinalised and shall be changed
|
|
74 amenu disable Changelog.New\ Version
|
|
75 amenu enable Changelog.Add\ Entry
|
|
76 amenu enable Changelog.Close\ Bug
|
|
77 amenu enable Changelog.Set\ Distribution
|
|
78 amenu enable Changelog.Set\ Urgency
|
|
79 amenu disable Changelog.Unfinalise
|
|
80 amenu enable Changelog.Finalise
|
|
81 call append(0, substitute(getline(1),'-\([[:digit:]]\+\))', '-Ü\1)', ''))
|
|
82 call append(1, "")
|
|
83 call append(2, "")
|
|
84 call append(3, " -- ")
|
|
85 call append(4, "")
|
|
86 call Distribution("unstable")
|
|
87 call Urgency("low")
|
|
88 normal 1G
|
|
89 call search(")")
|
|
90 normal h
|
|
91 normal
|
|
92 call setline(1, substitute(getline(1),'-Ü\([[:digit:]]\+\))', '-\1)', ''))
|
|
93 call AddEntry()
|
|
94 endfunction
|
|
95
|
|
96 function AddEntry()
|
|
97 normal 1G
|
|
98 call search("^ -- ")
|
|
99 normal kk
|
|
100 call append(".", " * ")
|
|
101 normal jjj
|
|
102 let warn=<SID>WarnIfNotUnfinalised()
|
|
103 normal kk
|
|
104 if warn
|
|
105 echohl MoreMsg
|
|
106 call input("Hit ENTER")
|
|
107 echohl None
|
|
108 endif
|
|
109 startinsert!
|
|
110 endfunction
|
|
111
|
|
112 function CloseBug()
|
|
113 normal 1G
|
|
114 call search("^ -- ")
|
|
115 let warn=<SID>WarnIfNotUnfinalised()
|
|
116 normal kk
|
|
117 call append(".", " * (closes: #" . input("Bug number to close: ") . ")")
|
|
118 normal j^ll
|
|
119 startinsert
|
|
120 endfunction
|
|
121
|
|
122 function Distribution(dist)
|
|
123 call setline(1, substitute(getline(1), ") [[:lower:] ]*;", ") " . a:dist . ";", ""))
|
|
124 endfunction
|
|
125
|
|
126 function Urgency(urg)
|
|
127 call setline(1, substitute(getline(1), "urgency=.*$", "urgency=" . a:urg, ""))
|
|
128 endfunction
|
|
129
|
|
130 function <SID>UnfinaliseMenu()
|
|
131 " This means the entry shall be changed
|
|
132 amenu disable Changelog.New\ Version
|
|
133 amenu enable Changelog.Add\ Entry
|
|
134 amenu enable Changelog.Close\ Bug
|
|
135 amenu enable Changelog.Set\ Distribution
|
|
136 amenu enable Changelog.Set\ Urgency
|
|
137 amenu disable Changelog.Unfinalise
|
|
138 amenu enable Changelog.Finalise
|
|
139 endfunction
|
|
140
|
|
141 function Unfinalise()
|
|
142 call <SID>UnfinaliseMenu()
|
|
143 normal 1G
|
|
144 call search("^ -- ")
|
|
145 call setline(".", " -- ")
|
|
146 endfunction
|
|
147
|
|
148 function <SID>FinaliseMenu()
|
|
149 " This means the entry should not be changed anymore
|
|
150 amenu enable Changelog.New\ Version
|
|
151 amenu disable Changelog.Add\ Entry
|
|
152 amenu disable Changelog.Close\ Bug
|
|
153 amenu disable Changelog.Set\ Distribution
|
|
154 amenu disable Changelog.Set\ Urgency
|
|
155 amenu enable Changelog.Unfinalise
|
|
156 amenu disable Changelog.Finalise
|
|
157 endfunction
|
|
158
|
|
159 function Finalise()
|
|
160 call <SID>FinaliseMenu()
|
|
161 normal 1G
|
|
162 call search("^ -- ")
|
|
163 call setline(".", " -- " . <SID>FullName() . " <" . <SID>Email() . "> " . <SID>Date())
|
|
164 endfunction
|
|
165
|
|
166
|
|
167 function <SID>MakeMenu()
|
|
168 amenu &Changelog.&New\ Version :call NewVersion()<CR>
|
|
169 amenu Changelog.&Add\ Entry :call AddEntry()<CR>
|
|
170 amenu Changelog.&Close\ Bug :call CloseBug()<CR>
|
|
171 menu Changelog.-sep- <nul>
|
|
172
|
|
173 amenu Changelog.Set\ &Distribution.&unstable :call Distribution("unstable")<CR>
|
|
174 amenu Changelog.Set\ Distribution.&frozen :call Distribution("frozen")<CR>
|
|
175 amenu Changelog.Set\ Distribution.&stable :call Distribution("stable")<CR>
|
|
176 menu Changelog.Set\ Distribution.-sep- <nul>
|
|
177 amenu Changelog.Set\ Distribution.frozen\ unstable :call Distribution("frozen unstable")<CR>
|
|
178 amenu Changelog.Set\ Distribution.stable\ unstable :call Distribution("stable unstable")<CR>
|
|
179 amenu Changelog.Set\ Distribution.stable\ frozen :call Distribution("stable frozen")<CR>
|
|
180 amenu Changelog.Set\ Distribution.stable\ frozen\ unstable :call Distribution("stable frozen unstable")<CR>
|
|
181
|
|
182 amenu Changelog.Set\ &Urgency.&low :call Urgency("low")<CR>
|
|
183 amenu Changelog.Set\ Urgency.&medium :call Urgency("medium")<CR>
|
|
184 amenu Changelog.Set\ Urgency.&high :call Urgency("high")<CR>
|
|
185
|
|
186 menu Changelog.-sep- <nul>
|
|
187 amenu Changelog.U&nfinalise :call Unfinalise()<CR>
|
|
188 amenu Changelog.&Finalise :call Finalise()<CR>
|
|
189
|
|
190 if <SID>Finalised()
|
|
191 call <SID>FinaliseMenu()
|
|
192 else
|
|
193 call <SID>UnfinaliseMenu()
|
|
194 endif
|
|
195 endfunction
|
|
196
|
|
197 augroup changelogMenu
|
|
198 au BufEnter * if &filetype == "debchangelog" | call <SID>MakeMenu() | endif
|
|
199 au BufLeave * if &filetype == "debchangelog" | aunmenu Changelog | endif
|
|
200 augroup END
|
|
201
|
|
202 " Debian changelogs are not supposed to have any other text width,
|
|
203 " so the user cannot override this setting
|
|
204 setlocal tw=78
|
|
205 setlocal comments=f:*
|
|
206 let b:undo_ftplugin = "setlocal tw< comments<"
|