blob: 350010105ade1d44636dc5047efa77e5e19b7cf4 [file] [log] [blame]
Bram Moolenaarf193fff2006-04-27 00:02:13 +00001" Vim filetype plugin file (GUI menu and folding)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002" Language: Debian Changelog
3" Maintainer: Michael Piefel <piefel@informatik.hu-berlin.de>
Bram Moolenaarf193fff2006-04-27 00:02:13 +00004" Stefano Zacchiroli <zack@debian.org>
Bram Moolenaar25e2c9e2006-04-27 21:40:34 +00005" Last Change: 27 April 2006
Bram Moolenaarf193fff2006-04-27 00:02:13 +00006" License: GNU GPL, version 2.1 or later
Bram Moolenaar071d4272004-06-13 20:20:40 +00007
8if exists("g:did_changelog_ftplugin")
9 finish
10endif
11
12" Don't load another plugin (this is global)
13let g:did_changelog_ftplugin = 1
14
Bram Moolenaarf193fff2006-04-27 00:02:13 +000015" {{{1 GUI menu
16
Bram Moolenaar071d4272004-06-13 20:20:40 +000017" Helper functions returning various data.
18" Returns full name, either from $DEBFULLNAME or debianfullname.
19" TODO Is there a way to determine name from anywhere else?
20function <SID>FullName()
21 if exists("$DEBFULLNAME")
22 return $DEBFULLNAME
23 elseif exists("g:debianfullname")
24 return g:debianfullname
25 else
26 return "Your Name"
27 endif
28endfunction
29
30" Returns email address, from $DEBEMAIL, $EMAIL or debianemail.
31function <SID>Email()
32 if exists("$DEBEMAIL")
33 return $DEBEMAIL
34 elseif exists("$EMAIL")
35 return $EMAIL
36 elseif exists("g:debianemail")
Bram Moolenaarae5bce12005-08-15 21:41:48 +000037 return g:debianemail
Bram Moolenaar071d4272004-06-13 20:20:40 +000038 else
39 return "your@email.address"
40 endif
41endfunction
42
43" Returns date in RFC822 format.
44function <SID>Date()
45 let savelang = v:lc_time
46 execute "language time C"
47 let dateandtime = strftime("%a, %d %b %Y %X %z")
48 execute "language time " . savelang
49 return dateandtime
50endfunction
51
52function <SID>WarnIfNotUnfinalised()
53 if match(getline("."), " -- [[:alpha:]][[:alnum:].]")!=-1
54 echohl WarningMsg
55 echo "The entry has not been unfinalised before editing."
56 echohl None
57 return 1
58 endif
59 return 0
60endfunction
61
62function <SID>Finalised()
63 let savelinenum = line(".")
64 normal 1G
65 call search("^ -- ")
66 if match(getline("."), " -- [[:alpha:]][[:alnum:].]")!=-1
67 let returnvalue = 1
68 else
69 let returnvalue = 0
70 endif
71 execute savelinenum
72 return returnvalue
73endfunction
74
75" These functions implement the menus
76function NewVersion()
77 " The new entry is unfinalised and shall be changed
78 amenu disable Changelog.New\ Version
79 amenu enable Changelog.Add\ Entry
80 amenu enable Changelog.Close\ Bug
81 amenu enable Changelog.Set\ Distribution
82 amenu enable Changelog.Set\ Urgency
83 amenu disable Changelog.Unfinalise
84 amenu enable Changelog.Finalise
85 call append(0, substitute(getline(1),'-\([[:digit:]]\+\))', '-Ü\1)', ''))
86 call append(1, "")
87 call append(2, "")
88 call append(3, " -- ")
89 call append(4, "")
90 call Distribution("unstable")
91 call Urgency("low")
92 normal 1G
93 call search(")")
94 normal h
95 normal 
96 call setline(1, substitute(getline(1),'-Ü\([[:digit:]]\+\))', '-\1)', ''))
97 call AddEntry()
98endfunction
99
100function AddEntry()
101 normal 1G
102 call search("^ -- ")
103 normal kk
104 call append(".", " * ")
105 normal jjj
106 let warn=<SID>WarnIfNotUnfinalised()
107 normal kk
108 if warn
109 echohl MoreMsg
110 call input("Hit ENTER")
111 echohl None
112 endif
113 startinsert!
114endfunction
115
116function CloseBug()
117 normal 1G
118 call search("^ -- ")
119 let warn=<SID>WarnIfNotUnfinalised()
120 normal kk
121 call append(".", " * (closes: #" . input("Bug number to close: ") . ")")
122 normal j^ll
123 startinsert
124endfunction
125
126function Distribution(dist)
127 call setline(1, substitute(getline(1), ") [[:lower:] ]*;", ") " . a:dist . ";", ""))
128endfunction
129
130function Urgency(urg)
131 call setline(1, substitute(getline(1), "urgency=.*$", "urgency=" . a:urg, ""))
132endfunction
133
134function <SID>UnfinaliseMenu()
135 " This means the entry shall be changed
136 amenu disable Changelog.New\ Version
137 amenu enable Changelog.Add\ Entry
138 amenu enable Changelog.Close\ Bug
139 amenu enable Changelog.Set\ Distribution
140 amenu enable Changelog.Set\ Urgency
141 amenu disable Changelog.Unfinalise
142 amenu enable Changelog.Finalise
143endfunction
144
145function Unfinalise()
146 call <SID>UnfinaliseMenu()
147 normal 1G
148 call search("^ -- ")
149 call setline(".", " -- ")
150endfunction
151
152function <SID>FinaliseMenu()
153 " This means the entry should not be changed anymore
154 amenu enable Changelog.New\ Version
155 amenu disable Changelog.Add\ Entry
156 amenu disable Changelog.Close\ Bug
157 amenu disable Changelog.Set\ Distribution
158 amenu disable Changelog.Set\ Urgency
159 amenu enable Changelog.Unfinalise
160 amenu disable Changelog.Finalise
161endfunction
162
163function Finalise()
164 call <SID>FinaliseMenu()
165 normal 1G
166 call search("^ -- ")
167 call setline(".", " -- " . <SID>FullName() . " <" . <SID>Email() . "> " . <SID>Date())
168endfunction
169
170
171function <SID>MakeMenu()
172 amenu &Changelog.&New\ Version :call NewVersion()<CR>
173 amenu Changelog.&Add\ Entry :call AddEntry()<CR>
174 amenu Changelog.&Close\ Bug :call CloseBug()<CR>
175 menu Changelog.-sep- <nul>
176
177 amenu Changelog.Set\ &Distribution.&unstable :call Distribution("unstable")<CR>
178 amenu Changelog.Set\ Distribution.&frozen :call Distribution("frozen")<CR>
179 amenu Changelog.Set\ Distribution.&stable :call Distribution("stable")<CR>
180 menu Changelog.Set\ Distribution.-sep- <nul>
181 amenu Changelog.Set\ Distribution.frozen\ unstable :call Distribution("frozen unstable")<CR>
182 amenu Changelog.Set\ Distribution.stable\ unstable :call Distribution("stable unstable")<CR>
183 amenu Changelog.Set\ Distribution.stable\ frozen :call Distribution("stable frozen")<CR>
184 amenu Changelog.Set\ Distribution.stable\ frozen\ unstable :call Distribution("stable frozen unstable")<CR>
185
186 amenu Changelog.Set\ &Urgency.&low :call Urgency("low")<CR>
187 amenu Changelog.Set\ Urgency.&medium :call Urgency("medium")<CR>
188 amenu Changelog.Set\ Urgency.&high :call Urgency("high")<CR>
189
190 menu Changelog.-sep- <nul>
191 amenu Changelog.U&nfinalise :call Unfinalise()<CR>
192 amenu Changelog.&Finalise :call Finalise()<CR>
193
194 if <SID>Finalised()
195 call <SID>FinaliseMenu()
196 else
197 call <SID>UnfinaliseMenu()
198 endif
199endfunction
200
201augroup changelogMenu
202au BufEnter * if &filetype == "debchangelog" | call <SID>MakeMenu() | endif
203au BufLeave * if &filetype == "debchangelog" | aunmenu Changelog | endif
204augroup END
205
Bram Moolenaarf193fff2006-04-27 00:02:13 +0000206" }}}
207" {{{1 folding
208
209setlocal foldmethod=expr
Bram Moolenaar25e2c9e2006-04-27 21:40:34 +0000210setlocal foldexpr=GetDebChangelogFold(v:lnum)
Bram Moolenaarf193fff2006-04-27 00:02:13 +0000211setlocal foldtext=DebChangelogFoldText()
212
213" look for an author name searching backward from a given line number
214function! s:getAuthor(lnum)
215 let line = getline(a:lnum)
216 let backsteps = 0
217 while line !~ '^ --'
218 let backsteps += 1
219 let line = getline(a:lnum - backsteps)
220 endwhile
221 let author = substitute(line, '^ --\s*\([^<]\+\)\s*.*', '\1', '')
222 return author
223endfunction
224
225function! DebChangelogFoldText()
226 if v:folddashes == '-' " changelog entry fold
227 return foldtext() . ' -- ' . s:getAuthor(v:foldend) . ' '
228 endif
229 return foldtext()
230endfunction
231
232function! GetDebChangelogFold(lnum)
233 let line = getline(a:lnum)
234 if line =~ '^\w\+'
235 return '>1' " beginning of a changelog entry
236 endif
237 if line =~ '^\s\+\[.*\]'
238 return '>2' " beginning of an author-specific chunk
239 endif
240 if line =~ '^ --'
241 return '1'
242 endif
243 return '='
244endfunction
245
246" }}}
247
Bram Moolenaar25e2c9e2006-04-27 21:40:34 +0000248" Debian changelogs are not supposed to have any other text width,
249" so the user cannot override this setting
250setlocal tw=78
251setlocal comments=f:*
252
253" Clean unloading
254let b:undo_ftplugin = "setlocal tw< comments< foldmethod< foldexpr< foldtext<"
255
Bram Moolenaarf193fff2006-04-27 00:02:13 +0000256" vim: set foldmethod=marker: