Mercurial > vim
annotate runtime/ftplugin/spec.vim @ 24581:4cb7be47fa3d
Added tag v8.2.2829 for changeset 87ff80c08e4bc75f2ff4a702928b31bd061c1000
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Mon, 03 May 2021 20:15:05 +0200 |
parents | fab58304f77d |
children | 9c221ad9634a |
rev | line source |
---|---|
7 | 1 " Plugin to update the %changelog section of RPM spec files |
2 " Filename: spec.vim | |
5697 | 3 " Maintainer: Igor Gnatenko i.gnatenko.brain@gmail.com |
4 " Former Maintainer: Gustavo Niemeyer <niemeyer@conectiva.com> (until March 2014) | |
6823 | 5 " Last Change: Mon Jun 01 21:15 MSK 2015 Igor Gnatenko |
7 | 6 |
7 if exists("b:did_ftplugin") | |
8 finish | |
9 endif | |
10 let b:did_ftplugin = 1 | |
11 | |
3237 | 12 let s:cpo_save = &cpo |
13 set cpo&vim | |
14 | |
7 | 15 if !exists("no_plugin_maps") && !exists("no_spec_maps") |
16 if !hasmapto("<Plug>SpecChangelog") | |
17 map <buffer> <LocalLeader>c <Plug>SpecChangelog | |
18 endif | |
19 endif | |
20 | |
6647 | 21 if !hasmapto("call <SID>SpecChangelog(\"\")<CR>") |
22 noremap <buffer> <unique> <script> <Plug>SpecChangelog :call <SID>SpecChangelog("")<CR> | |
23 endif | |
7 | 24 |
6823 | 25 if !exists("*s:GetRelVer") |
26 function! s:GetRelVer() | |
27 if has('python') | |
28 python << PYEND | |
29 import sys, datetime, shutil, tempfile | |
30 import vim | |
31 | |
32 try: | |
33 import rpm | |
34 except ImportError: | |
35 pass | |
36 else: | |
37 specfile = vim.current.buffer.name | |
38 if specfile: | |
9227
ecb621205ed1
commit https://github.com/vim/vim/commit/82af8710bf8d1caeeceafb1370a052cb7d92f076
Christian Brabandt <cb@256bit.org>
parents:
6823
diff
changeset
|
39 rpm.delMacro("dist") |
6823 | 40 spec = rpm.spec(specfile) |
9227
ecb621205ed1
commit https://github.com/vim/vim/commit/82af8710bf8d1caeeceafb1370a052cb7d92f076
Christian Brabandt <cb@256bit.org>
parents:
6823
diff
changeset
|
41 headers = spec.sourceHeader |
ecb621205ed1
commit https://github.com/vim/vim/commit/82af8710bf8d1caeeceafb1370a052cb7d92f076
Christian Brabandt <cb@256bit.org>
parents:
6823
diff
changeset
|
42 version = headers["Version"] |
ecb621205ed1
commit https://github.com/vim/vim/commit/82af8710bf8d1caeeceafb1370a052cb7d92f076
Christian Brabandt <cb@256bit.org>
parents:
6823
diff
changeset
|
43 release = headers["Release"] |
6823 | 44 vim.command("let ver = " + version) |
45 vim.command("let rel = " + release) | |
46 PYEND | |
47 endif | |
48 endfunction | |
49 endif | |
50 | |
7 | 51 if !exists("*s:SpecChangelog") |
52 function s:SpecChangelog(format) | |
53 if strlen(a:format) == 0 | |
54 if !exists("g:spec_chglog_format") | |
6823 | 55 let email = input("Name <email address>: ") |
7 | 56 let g:spec_chglog_format = "%a %b %d %Y " . l:email |
57 echo "\r" | |
58 endif | |
59 let format = g:spec_chglog_format | |
60 else | |
61 if !exists("g:spec_chglog_format") | |
62 let g:spec_chglog_format = a:format | |
63 endif | |
64 let format = a:format | |
65 endif | |
66 let line = 0 | |
67 let name = "" | |
68 let ver = "" | |
69 let rel = "" | |
70 let nameline = -1 | |
71 let verline = -1 | |
72 let relline = -1 | |
73 let chgline = -1 | |
74 while (line <= line("$")) | |
75 let linestr = getline(line) | |
23305 | 76 if name == "" && linestr =~? '^Name:' |
7 | 77 let nameline = line |
78 let name = substitute(strpart(linestr,5), '^[ ]*\([^ ]\+\)[ ]*$','\1','') | |
23305 | 79 elseif ver == "" && linestr =~? '^Version:' |
7 | 80 let verline = line |
81 let ver = substitute(strpart(linestr,8), '^[ ]*\([^ ]\+\)[ ]*$','\1','') | |
23305 | 82 elseif rel == "" && linestr =~? '^Release:' |
7 | 83 let relline = line |
84 let rel = substitute(strpart(linestr,8), '^[ ]*\([^ ]\+\)[ ]*$','\1','') | |
23305 | 85 elseif linestr =~? '^%changelog' |
7 | 86 let chgline = line |
87 execute line | |
88 break | |
89 endif | |
90 let line = line+1 | |
91 endwhile | |
23305 | 92 if nameline != -1 && verline != -1 && relline != -1 |
7 | 93 let include_release_info = exists("g:spec_chglog_release_info") |
94 let name = s:ParseRpmVars(name, nameline) | |
95 let ver = s:ParseRpmVars(ver, verline) | |
96 let rel = s:ParseRpmVars(rel, relline) | |
97 else | |
98 let include_release_info = 0 | |
99 endif | |
6823 | 100 |
101 call s:GetRelVer() | |
102 | |
23305 | 103 if chgline == -1 |
7 | 104 let option = confirm("Can't find %changelog. Create one? ","&End of file\n&Here\n&Cancel",3) |
23305 | 105 if option == 1 |
7 | 106 call append(line("$"),"") |
107 call append(line("$"),"%changelog") | |
108 execute line("$") | |
109 let chgline = line(".") | |
23305 | 110 elseif option == 2 |
7 | 111 call append(line("."),"%changelog") |
112 normal j | |
23305 | 113 let chgline = line(".") |
7 | 114 endif |
115 endif | |
23305 | 116 if chgline != -1 |
9227
ecb621205ed1
commit https://github.com/vim/vim/commit/82af8710bf8d1caeeceafb1370a052cb7d92f076
Christian Brabandt <cb@256bit.org>
parents:
6823
diff
changeset
|
117 let tmptime = v:lc_time |
ecb621205ed1
commit https://github.com/vim/vim/commit/82af8710bf8d1caeeceafb1370a052cb7d92f076
Christian Brabandt <cb@256bit.org>
parents:
6823
diff
changeset
|
118 language time C |
6823 | 119 let parsed_format = "* ".strftime(format)." - ".ver."-".rel |
9227
ecb621205ed1
commit https://github.com/vim/vim/commit/82af8710bf8d1caeeceafb1370a052cb7d92f076
Christian Brabandt <cb@256bit.org>
parents:
6823
diff
changeset
|
120 execute "language time" tmptime |
7 | 121 let release_info = "+ ".name."-".ver."-".rel |
122 let wrong_format = 0 | |
123 let wrong_release = 0 | |
124 let insert_line = 0 | |
23305 | 125 if getline(chgline+1) != parsed_format |
7 | 126 let wrong_format = 1 |
127 endif | |
23305 | 128 if include_release_info && getline(chgline+2) != release_info |
7 | 129 let wrong_release = 1 |
130 endif | |
23305 | 131 if wrong_format || wrong_release |
132 if include_release_info && !wrong_release && !exists("g:spec_chglog_never_increase_release") | |
7 | 133 let option = confirm("Increase release? ","&Yes\n&No",1) |
23305 | 134 if option == 1 |
7 | 135 execute relline |
136 normal | |
137 let rel = substitute(strpart(getline(relline),8), '^[ ]*\([^ ]\+\)[ ]*$','\1','') | |
138 let release_info = "+ ".name."-".ver."-".rel | |
139 endif | |
140 endif | |
141 let n = 0 | |
142 call append(chgline+n, parsed_format) | |
143 if include_release_info | |
144 let n = n + 1 | |
145 call append(chgline+n, release_info) | |
146 endif | |
147 let n = n + 1 | |
148 call append(chgline+n,"- ") | |
149 let n = n + 1 | |
150 call append(chgline+n,"") | |
151 let insert_line = chgline+n | |
152 else | |
153 let line = chgline | |
154 if !exists("g:spec_chglog_prepend") | |
155 while !(getline(line+2) =~ '^\( *\|\*.*\)$') | |
156 let line = line+1 | |
157 endwhile | |
158 endif | |
159 call append(line+1,"- ") | |
160 let insert_line = line+2 | |
161 endif | |
162 execute insert_line | |
163 startinsert! | |
164 endif | |
165 endfunction | |
166 endif | |
167 | |
168 if !exists("*s:ParseRpmVars") | |
169 function s:ParseRpmVars(str, strline) | |
170 let end = -1 | |
171 let ret = "" | |
172 while (1) | |
173 let start = match(a:str, "\%{", end+1) | |
23305 | 174 if start == -1 |
7 | 175 let ret = ret . strpart(a:str, end+1) |
176 break | |
177 endif | |
178 let ret = ret . strpart(a:str, end+1, start-(end+1)) | |
179 let end = match(a:str, "}", start) | |
23305 | 180 if end == -1 |
7 | 181 let ret = ret . strpart(a:str, start) |
182 break | |
183 endif | |
184 let varname = strpart(a:str, start+2, end-(start+2)) | |
185 execute a:strline | |
22171 | 186 let definestr = "^[ \t]*%\\(define\\|global\\)[ \t]\\+".varname."[ \t]\\+\\(.*\\)$" |
7 | 187 let linenum = search(definestr, "bW") |
23305 | 188 if linenum != 0 |
22171 | 189 let ret = ret . substitute(getline(linenum), definestr, "\\2", "") |
7 | 190 endif |
191 endwhile | |
192 return ret | |
193 endfunction | |
194 endif | |
195 | |
196 " The following lines, along with the macros/matchit.vim plugin, | |
197 " make it easy to navigate the different sections of a spec file | |
198 " with the % key (thanks to Max Ischenko). | |
199 | |
200 let b:match_ignorecase = 0 | |
201 let b:match_words = | |
9227
ecb621205ed1
commit https://github.com/vim/vim/commit/82af8710bf8d1caeeceafb1370a052cb7d92f076
Christian Brabandt <cb@256bit.org>
parents:
6823
diff
changeset
|
202 \ '^Name:^%description:^%clean:^%(?:auto)?setup:^%build:^%install:^%files:' . |
7 | 203 \ '^%package:^%preun:^%postun:^%changelog' |
204 | |
3237 | 205 let &cpo = s:cpo_save |
206 unlet s:cpo_save | |
207 | |
3410
94601b379f38
Updated runtime files. Add Dutch translations.
Bram Moolenaar <bram@vim.org>
parents:
3237
diff
changeset
|
208 let b:undo_ftplugin = "unlet! b:match_ignorecase b:match_words" |