Mercurial > vim
annotate runtime/ftplugin/spec.vim @ 19969:b07672d13ff9 v8.2.0540
patch 8.2.0540: regexp and other code not tested
Commit: https://github.com/vim/vim/commit/004a6781b3cf15ca5dd632c38cc09bb3b253d1f8
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Apr 11 17:09:31 2020 +0200
patch 8.2.0540: regexp and other code not tested
Problem: Regexp and other code not tested.
Solution: Add more tests. (Yegappan Lakshmanan, closes https://github.com/vim/vim/issues/5904)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 11 Apr 2020 17:15:06 +0200 |
parents | ecb621205ed1 |
children | d4c7b3e9cd17 |
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) | |
76 if (name == "" && linestr =~? '^Name:') | |
77 let nameline = line | |
78 let name = substitute(strpart(linestr,5), '^[ ]*\([^ ]\+\)[ ]*$','\1','') | |
79 elseif (ver == "" && linestr =~? '^Version:') | |
80 let verline = line | |
81 let ver = substitute(strpart(linestr,8), '^[ ]*\([^ ]\+\)[ ]*$','\1','') | |
82 elseif (rel == "" && linestr =~? '^Release:') | |
83 let relline = line | |
84 let rel = substitute(strpart(linestr,8), '^[ ]*\([^ ]\+\)[ ]*$','\1','') | |
85 elseif (linestr =~? '^%changelog') | |
86 let chgline = line | |
87 execute line | |
88 break | |
89 endif | |
90 let line = line+1 | |
91 endwhile | |
92 if (nameline != -1 && verline != -1 && relline != -1) | |
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 | |
7 | 103 if (chgline == -1) |
104 let option = confirm("Can't find %changelog. Create one? ","&End of file\n&Here\n&Cancel",3) | |
105 if (option == 1) | |
106 call append(line("$"),"") | |
107 call append(line("$"),"%changelog") | |
108 execute line("$") | |
109 let chgline = line(".") | |
110 elseif (option == 2) | |
111 call append(line("."),"%changelog") | |
112 normal j | |
113 chgline = line(".") | |
114 endif | |
115 endif | |
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 | |
125 if (getline(chgline+1) != parsed_format) | |
126 let wrong_format = 1 | |
127 endif | |
128 if (include_release_info && getline(chgline+2) != release_info) | |
129 let wrong_release = 1 | |
130 endif | |
131 if (wrong_format || wrong_release) | |
132 if (include_release_info && !wrong_release && !exists("g:spec_chglog_never_increase_release")) | |
133 let option = confirm("Increase release? ","&Yes\n&No",1) | |
134 if (option == 1) | |
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) | |
174 if (start == -1) | |
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) | |
180 if (end == -1) | |
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 | |
9227
ecb621205ed1
commit https://github.com/vim/vim/commit/82af8710bf8d1caeeceafb1370a052cb7d92f076
Christian Brabandt <cb@256bit.org>
parents:
6823
diff
changeset
|
186 let definestr = "^[ \t]*%(?:global|define)[ \t]\\+" . varname . "[ \t]\\+\\(.*\\)$" |
7 | 187 let linenum = search(definestr, "bW") |
188 if (linenum != -1) | |
189 let ret = ret . substitute(getline(linenum), definestr, "\\1", "") | |
190 else | |
191 let ret = ret . strpart(str, start, end+1-start) | |
192 endif | |
193 endwhile | |
194 return ret | |
195 endfunction | |
196 endif | |
197 | |
198 " The following lines, along with the macros/matchit.vim plugin, | |
199 " make it easy to navigate the different sections of a spec file | |
200 " with the % key (thanks to Max Ischenko). | |
201 | |
202 let b:match_ignorecase = 0 | |
203 let b:match_words = | |
9227
ecb621205ed1
commit https://github.com/vim/vim/commit/82af8710bf8d1caeeceafb1370a052cb7d92f076
Christian Brabandt <cb@256bit.org>
parents:
6823
diff
changeset
|
204 \ '^Name:^%description:^%clean:^%(?:auto)?setup:^%build:^%install:^%files:' . |
7 | 205 \ '^%package:^%preun:^%postun:^%changelog' |
206 | |
3237 | 207 let &cpo = s:cpo_save |
208 unlet s:cpo_save | |
209 | |
3410
94601b379f38
Updated runtime files. Add Dutch translations.
Bram Moolenaar <bram@vim.org>
parents:
3237
diff
changeset
|
210 let b:undo_ftplugin = "unlet! b:match_ignorecase b:match_words" |