annotate runtime/ftplugin/spec.vim @ 1807:a66c40578675 v7.2.105

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