annotate runtime/ftplugin/spec.vim @ 3237:91e53bcb7946

Updated runtime files.
author Bram Moolenaar <bram@vim.org>
date Fri, 30 Dec 2011 13:11:27 +0100
parents 3fc0f57ecb91
children 94601b379f38
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1 " Plugin to update the %changelog section of RPM spec files
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2 " Filename: spec.vim
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3 " Maintainer: Gustavo Niemeyer <niemeyer@conectiva.com>
3237
91e53bcb7946 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 7
diff changeset
4 " Last Change: 2011 Dec 25 by Thilo Six
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6 if exists("b:did_ftplugin")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7 finish
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9 let b:did_ftplugin = 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
10
3237
91e53bcb7946 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 7
diff changeset
11 let s:cpo_save = &cpo
91e53bcb7946 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 7
diff changeset
12 set cpo&vim
91e53bcb7946 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 7
diff changeset
13
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
14 if !exists("no_plugin_maps") && !exists("no_spec_maps")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
15 if !hasmapto("<Plug>SpecChangelog")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
16 map <buffer> <LocalLeader>c <Plug>SpecChangelog
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
17 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
18 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
19
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
20 noremap <buffer> <unique> <script> <Plug>SpecChangelog :call <SID>SpecChangelog("")<CR>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
21
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
22 if !exists("*s:SpecChangelog")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
23 function s:SpecChangelog(format)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
24 if strlen(a:format) == 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
25 if !exists("g:spec_chglog_format")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
26 let email = input("Email address: ")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
27 let g:spec_chglog_format = "%a %b %d %Y " . l:email
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
28 echo "\r"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
29 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
30 let format = g:spec_chglog_format
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
31 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
32 if !exists("g:spec_chglog_format")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
33 let g:spec_chglog_format = a:format
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
34 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
35 let format = a:format
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
36 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
37 let line = 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
38 let name = ""
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
39 let ver = ""
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
40 let rel = ""
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
41 let nameline = -1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
42 let verline = -1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
43 let relline = -1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
44 let chgline = -1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
45 while (line <= line("$"))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
46 let linestr = getline(line)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
47 if (name == "" && linestr =~? '^Name:')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
48 let nameline = line
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
49 let name = substitute(strpart(linestr,5), '^[ ]*\([^ ]\+\)[ ]*$','\1','')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
50 elseif (ver == "" && linestr =~? '^Version:')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
51 let verline = line
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
52 let ver = substitute(strpart(linestr,8), '^[ ]*\([^ ]\+\)[ ]*$','\1','')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
53 elseif (rel == "" && linestr =~? '^Release:')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
54 let relline = line
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
55 let rel = substitute(strpart(linestr,8), '^[ ]*\([^ ]\+\)[ ]*$','\1','')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
56 elseif (linestr =~? '^%changelog')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
57 let chgline = line
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
58 execute line
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
59 break
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
60 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
61 let line = line+1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
62 endwhile
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
63 if (nameline != -1 && verline != -1 && relline != -1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
64 let include_release_info = exists("g:spec_chglog_release_info")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
65 let name = s:ParseRpmVars(name, nameline)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
66 let ver = s:ParseRpmVars(ver, verline)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
67 let rel = s:ParseRpmVars(rel, relline)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
68 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
69 let include_release_info = 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
70 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
71 if (chgline == -1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
72 let option = confirm("Can't find %changelog. Create one? ","&End of file\n&Here\n&Cancel",3)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
73 if (option == 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
74 call append(line("$"),"")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
75 call append(line("$"),"%changelog")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
76 execute line("$")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
77 let chgline = line(".")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
78 elseif (option == 2)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
79 call append(line("."),"%changelog")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
80 normal j
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
81 chgline = line(".")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
82 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
83 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
84 if (chgline != -1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
85 let parsed_format = "* ".strftime(format)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
86 let release_info = "+ ".name."-".ver."-".rel
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
87 let wrong_format = 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
88 let wrong_release = 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
89 let insert_line = 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
90 if (getline(chgline+1) != parsed_format)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
91 let wrong_format = 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
92 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
93 if (include_release_info && getline(chgline+2) != release_info)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
94 let wrong_release = 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
95 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
96 if (wrong_format || wrong_release)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
97 if (include_release_info && !wrong_release && !exists("g:spec_chglog_never_increase_release"))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
98 let option = confirm("Increase release? ","&Yes\n&No",1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
99 if (option == 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
100 execute relline
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
101 normal 
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
102 let rel = substitute(strpart(getline(relline),8), '^[ ]*\([^ ]\+\)[ ]*$','\1','')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
103 let release_info = "+ ".name."-".ver."-".rel
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
104 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
105 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
106 let n = 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
107 call append(chgline+n, parsed_format)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
108 if include_release_info
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
109 let n = n + 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
110 call append(chgline+n, release_info)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
111 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
112 let n = n + 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
113 call append(chgline+n,"- ")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
114 let n = n + 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
115 call append(chgline+n,"")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
116 let insert_line = chgline+n
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
117 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
118 let line = chgline
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
119 if !exists("g:spec_chglog_prepend")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
120 while !(getline(line+2) =~ '^\( *\|\*.*\)$')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
121 let line = line+1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
122 endwhile
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
123 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
124 call append(line+1,"- ")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
125 let insert_line = line+2
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
126 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
127 execute insert_line
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
128 startinsert!
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
129 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
130 endfunction
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
131 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
132
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
133 if !exists("*s:ParseRpmVars")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
134 function s:ParseRpmVars(str, strline)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
135 let end = -1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
136 let ret = ""
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
137 while (1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
138 let start = match(a:str, "\%{", end+1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
139 if (start == -1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
140 let ret = ret . strpart(a:str, end+1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
141 break
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
142 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
143 let ret = ret . strpart(a:str, end+1, start-(end+1))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
144 let end = match(a:str, "}", start)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
145 if (end == -1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
146 let ret = ret . strpart(a:str, start)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
147 break
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
148 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
149 let varname = strpart(a:str, start+2, end-(start+2))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
150 execute a:strline
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
151 let definestr = "^[ \t]*%define[ \t]\\+" . varname . "[ \t]\\+\\(.*\\)$"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
152 let linenum = search(definestr, "bW")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
153 if (linenum != -1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
154 let ret = ret . substitute(getline(linenum), definestr, "\\1", "")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
155 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
156 let ret = ret . strpart(str, start, end+1-start)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
157 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
158 endwhile
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
159 return ret
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
160 endfunction
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
161 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
162
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
163 " The following lines, along with the macros/matchit.vim plugin,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
164 " make it easy to navigate the different sections of a spec file
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
165 " with the % key (thanks to Max Ischenko).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
166
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
167 let b:match_ignorecase = 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
168 let b:match_words =
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
169 \ '^Name:^%description:^%clean:^%setup:^%build:^%install:^%files:' .
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
170 \ '^%package:^%preun:^%postun:^%changelog'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
171
3237
91e53bcb7946 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 7
diff changeset
172 let &cpo = s:cpo_save
91e53bcb7946 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 7
diff changeset
173 unlet s:cpo_save
91e53bcb7946 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 7
diff changeset
174