blob: 32db5a73d63fcd569e7e91791177b7533eebddc8 [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001" Vim filetype plugin file
2" Language: Debian Changelog
3" Maintainer: Michael Piefel <piefel@informatik.hu-berlin.de>
4" Last Change: 23 March 2004
5
6if exists("g:did_changelog_ftplugin")
7 finish
8endif
9
10" Don't load another plugin (this is global)
11let 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?
16function <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
24endfunction
25
26" Returns email address, from $DEBEMAIL, $EMAIL or debianemail.
27function <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
37endfunction
38
39" Returns date in RFC822 format.
40function <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
46endfunction
47
48function <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
56endfunction
57
58function <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
69endfunction
70
71" These functions implement the menus
72function 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()
94endfunction
95
96function 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!
110endfunction
111
112function 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
120endfunction
121
122function Distribution(dist)
123 call setline(1, substitute(getline(1), ") [[:lower:] ]*;", ") " . a:dist . ";", ""))
124endfunction
125
126function Urgency(urg)
127 call setline(1, substitute(getline(1), "urgency=.*$", "urgency=" . a:urg, ""))
128endfunction
129
130function <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
139endfunction
140
141function Unfinalise()
142 call <SID>UnfinaliseMenu()
143 normal 1G
144 call search("^ -- ")
145 call setline(".", " -- ")
146endfunction
147
148function <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
157endfunction
158
159function Finalise()
160 call <SID>FinaliseMenu()
161 normal 1G
162 call search("^ -- ")
163 call setline(".", " -- " . <SID>FullName() . " <" . <SID>Email() . "> " . <SID>Date())
164endfunction
165
166
167function <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
195endfunction
196
197augroup changelogMenu
198au BufEnter * if &filetype == "debchangelog" | call <SID>MakeMenu() | endif
199au BufLeave * if &filetype == "debchangelog" | aunmenu Changelog | endif
200augroup END
201
202" Debian changelogs are not supposed to have any other text width,
203" so the user cannot override this setting
204setlocal tw=78
205setlocal comments=f:*
206let b:undo_ftplugin = "setlocal tw< comments<"