| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  |  | " Plugin to update the %changelog section of RPM spec files | 
					
						
							|  |  |  |  | " Filename: spec.vim | 
					
						
							| 
									
										
										
										
											2014-03-08 18:38:28 +01:00
										 |  |  |  | " Maintainer: Igor Gnatenko i.gnatenko.brain@gmail.com | 
					
						
							|  |  |  |  | " Former Maintainer: Gustavo Niemeyer <niemeyer@conectiva.com> (until March 2014) | 
					
						
							| 
									
										
										
										
											2015-06-09 19:44:55 +02:00
										 |  |  |  | " Last Change: Mon Jun 01 21:15 MSK 2015 Igor Gnatenko | 
					
						
							| 
									
										
										
										
											2022-05-21 13:08:16 +01:00
										 |  |  |  | " Update by Zdenek Dohnal, 2022 May 17 | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | if exists("b:did_ftplugin") | 
					
						
							|  |  |  |  | 	finish | 
					
						
							|  |  |  |  | endif | 
					
						
							|  |  |  |  | let b:did_ftplugin = 1 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-30 13:11:27 +01:00
										 |  |  |  | let s:cpo_save = &cpo | 
					
						
							|  |  |  |  | set cpo&vim | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  |  | if !exists("no_plugin_maps") && !exists("no_spec_maps") | 
					
						
							|  |  |  |  | 	if !hasmapto("<Plug>SpecChangelog") | 
					
						
							|  |  |  |  | 		map <buffer> <LocalLeader>c <Plug>SpecChangelog | 
					
						
							|  |  |  |  | 	endif | 
					
						
							|  |  |  |  | endif | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-07 20:27:04 +00:00
										 |  |  |  | if !hasmapto("call <SID>SpecChangelog(\"\")<CR>") | 
					
						
							|  |  |  |  |        noremap <buffer> <unique> <script> <Plug>SpecChangelog :call <SID>SpecChangelog("")<CR> | 
					
						
							| 
									
										
										
										
											2015-02-28 13:11:45 +01:00
										 |  |  |  | endif | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-09 19:44:55 +02:00
										 |  |  |  | if !exists("*s:GetRelVer") | 
					
						
							|  |  |  |  | 	function! s:GetRelVer() | 
					
						
							|  |  |  |  | 		if has('python') | 
					
						
							|  |  |  |  | python << PYEND | 
					
						
							|  |  |  |  | import sys, datetime, shutil, tempfile | 
					
						
							|  |  |  |  | import vim | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | try: | 
					
						
							|  |  |  |  |     import rpm | 
					
						
							|  |  |  |  | except ImportError: | 
					
						
							|  |  |  |  |     pass | 
					
						
							|  |  |  |  | else: | 
					
						
							|  |  |  |  |     specfile = vim.current.buffer.name | 
					
						
							|  |  |  |  |     if specfile: | 
					
						
							| 
									
										
										
										
											2016-06-04 20:20:29 +02:00
										 |  |  |  |         rpm.delMacro("dist") | 
					
						
							| 
									
										
										
										
											2015-06-09 19:44:55 +02:00
										 |  |  |  |         spec = rpm.spec(specfile) | 
					
						
							| 
									
										
										
										
											2016-06-04 20:20:29 +02:00
										 |  |  |  |         headers = spec.sourceHeader | 
					
						
							|  |  |  |  |         version = headers["Version"] | 
					
						
							|  |  |  |  |         release = headers["Release"] | 
					
						
							| 
									
										
										
										
											2022-05-21 13:08:16 +01:00
										 |  |  |  |         vim.command("let ver = '" + version + "'") | 
					
						
							|  |  |  |  |         vim.command("let rel = '" + release + "'") | 
					
						
							| 
									
										
										
										
											2015-06-09 19:44:55 +02:00
										 |  |  |  | PYEND | 
					
						
							|  |  |  |  | 		endif | 
					
						
							|  |  |  |  | 	endfunction | 
					
						
							|  |  |  |  | endif | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  |  | if !exists("*s:SpecChangelog") | 
					
						
							|  |  |  |  | 	function s:SpecChangelog(format) | 
					
						
							|  |  |  |  | 		if strlen(a:format) == 0 | 
					
						
							|  |  |  |  | 			if !exists("g:spec_chglog_format") | 
					
						
							| 
									
										
										
										
											2015-06-09 19:44:55 +02:00
										 |  |  |  | 				let email = input("Name <email address>: ") | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  |  | 				let g:spec_chglog_format = "%a %b %d %Y " . l:email | 
					
						
							|  |  |  |  | 				echo "\r" | 
					
						
							|  |  |  |  | 			endif | 
					
						
							|  |  |  |  | 			let format = g:spec_chglog_format | 
					
						
							|  |  |  |  | 		else | 
					
						
							|  |  |  |  | 			if !exists("g:spec_chglog_format") | 
					
						
							|  |  |  |  | 				let g:spec_chglog_format = a:format | 
					
						
							|  |  |  |  | 			endif | 
					
						
							|  |  |  |  | 			let format = a:format | 
					
						
							|  |  |  |  | 		endif | 
					
						
							|  |  |  |  | 		let line = 0 | 
					
						
							|  |  |  |  | 		let name = "" | 
					
						
							|  |  |  |  | 		let ver = "" | 
					
						
							|  |  |  |  | 		let rel = "" | 
					
						
							|  |  |  |  | 		let nameline = -1 | 
					
						
							|  |  |  |  | 		let verline = -1 | 
					
						
							|  |  |  |  | 		let relline = -1 | 
					
						
							|  |  |  |  | 		let chgline = -1 | 
					
						
							|  |  |  |  | 		while (line <= line("$")) | 
					
						
							|  |  |  |  | 			let linestr = getline(line) | 
					
						
							| 
									
										
										
										
											2020-12-23 13:56:35 +01:00
										 |  |  |  | 			if name == "" && linestr =~? '^Name:' | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  |  | 				let nameline = line | 
					
						
							|  |  |  |  | 				let name = substitute(strpart(linestr,5), '^[	 ]*\([^ 	]\+\)[		]*$','\1','') | 
					
						
							| 
									
										
										
										
											2020-12-23 13:56:35 +01:00
										 |  |  |  | 			elseif ver == "" && linestr =~? '^Version:' | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  |  | 				let verline = line | 
					
						
							|  |  |  |  | 				let ver = substitute(strpart(linestr,8), '^[	 ]*\([^ 	]\+\)[		]*$','\1','') | 
					
						
							| 
									
										
										
										
											2020-12-23 13:56:35 +01:00
										 |  |  |  | 			elseif rel == "" && linestr =~? '^Release:' | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  |  | 				let relline = line | 
					
						
							|  |  |  |  | 				let rel = substitute(strpart(linestr,8), '^[	 ]*\([^ 	]\+\)[		]*$','\1','') | 
					
						
							| 
									
										
										
										
											2020-12-23 13:56:35 +01:00
										 |  |  |  | 			elseif linestr =~? '^%changelog' | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  |  | 				let chgline = line | 
					
						
							|  |  |  |  | 				execute line | 
					
						
							|  |  |  |  | 				break | 
					
						
							|  |  |  |  | 			endif | 
					
						
							|  |  |  |  | 			let line = line+1 | 
					
						
							|  |  |  |  | 		endwhile | 
					
						
							| 
									
										
										
										
											2020-12-23 13:56:35 +01:00
										 |  |  |  | 		if nameline != -1 && verline != -1 && relline != -1 | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  |  | 			let include_release_info = exists("g:spec_chglog_release_info") | 
					
						
							|  |  |  |  | 			let name = s:ParseRpmVars(name, nameline) | 
					
						
							|  |  |  |  | 			let ver = s:ParseRpmVars(ver, verline) | 
					
						
							|  |  |  |  | 			let rel = s:ParseRpmVars(rel, relline) | 
					
						
							|  |  |  |  | 		else | 
					
						
							|  |  |  |  | 			let include_release_info = 0 | 
					
						
							|  |  |  |  | 		endif | 
					
						
							| 
									
										
										
										
											2015-06-09 19:44:55 +02:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 		call s:GetRelVer() | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-23 13:56:35 +01:00
										 |  |  |  | 		if chgline == -1 | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  |  | 			let option = confirm("Can't find %changelog. Create one? ","&End of file\n&Here\n&Cancel",3) | 
					
						
							| 
									
										
										
										
											2020-12-23 13:56:35 +01:00
										 |  |  |  | 			if option == 1 | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  |  | 				call append(line("$"),"") | 
					
						
							|  |  |  |  | 				call append(line("$"),"%changelog") | 
					
						
							|  |  |  |  | 				execute line("$") | 
					
						
							|  |  |  |  | 				let chgline = line(".") | 
					
						
							| 
									
										
										
										
											2020-12-23 13:56:35 +01:00
										 |  |  |  | 			elseif option == 2 | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  |  | 				call append(line("."),"%changelog") | 
					
						
							|  |  |  |  | 				normal j | 
					
						
							| 
									
										
										
										
											2020-12-23 13:56:35 +01:00
										 |  |  |  | 				let chgline = line(".") | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  |  | 			endif | 
					
						
							|  |  |  |  | 		endif | 
					
						
							| 
									
										
										
										
											2020-12-23 13:56:35 +01:00
										 |  |  |  | 		if chgline != -1 | 
					
						
							| 
									
										
										
										
											2016-06-04 20:20:29 +02:00
										 |  |  |  | 			let tmptime = v:lc_time | 
					
						
							|  |  |  |  | 			language time C | 
					
						
							| 
									
										
										
										
											2015-06-09 19:44:55 +02:00
										 |  |  |  | 			let parsed_format = "* ".strftime(format)." - ".ver."-".rel | 
					
						
							| 
									
										
										
										
											2016-06-04 20:20:29 +02:00
										 |  |  |  | 			execute "language time" tmptime | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  |  | 			let release_info = "+ ".name."-".ver."-".rel | 
					
						
							|  |  |  |  | 			let wrong_format = 0 | 
					
						
							|  |  |  |  | 			let wrong_release = 0 | 
					
						
							|  |  |  |  | 			let insert_line = 0 | 
					
						
							| 
									
										
										
										
											2020-12-23 13:56:35 +01:00
										 |  |  |  | 			if getline(chgline+1) != parsed_format | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  |  | 				let wrong_format = 1 | 
					
						
							|  |  |  |  | 			endif | 
					
						
							| 
									
										
										
										
											2020-12-23 13:56:35 +01:00
										 |  |  |  | 			if include_release_info && getline(chgline+2) != release_info | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  |  | 				let wrong_release = 1 | 
					
						
							|  |  |  |  | 			endif | 
					
						
							| 
									
										
										
										
											2020-12-23 13:56:35 +01:00
										 |  |  |  | 			if wrong_format || wrong_release | 
					
						
							|  |  |  |  | 				if include_release_info && !wrong_release && !exists("g:spec_chglog_never_increase_release") | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  |  | 					let option = confirm("Increase release? ","&Yes\n&No",1) | 
					
						
							| 
									
										
										
										
											2020-12-23 13:56:35 +01:00
										 |  |  |  | 					if option == 1 | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  |  | 						execute relline | 
					
						
							|  |  |  |  | 						normal  | 
					
						
							|  |  |  |  | 						let rel = substitute(strpart(getline(relline),8), '^[	 ]*\([^ 	]\+\)[		]*$','\1','') | 
					
						
							|  |  |  |  | 						let release_info = "+ ".name."-".ver."-".rel | 
					
						
							|  |  |  |  | 					endif | 
					
						
							|  |  |  |  | 				endif | 
					
						
							|  |  |  |  | 				let n = 0 | 
					
						
							|  |  |  |  | 				call append(chgline+n, parsed_format) | 
					
						
							|  |  |  |  | 				if include_release_info | 
					
						
							|  |  |  |  | 					let n = n + 1 | 
					
						
							|  |  |  |  | 					call append(chgline+n, release_info) | 
					
						
							|  |  |  |  | 				endif | 
					
						
							|  |  |  |  | 				let n = n + 1 | 
					
						
							|  |  |  |  | 				call append(chgline+n,"- ") | 
					
						
							|  |  |  |  | 				let n = n + 1 | 
					
						
							|  |  |  |  | 				call append(chgline+n,"") | 
					
						
							|  |  |  |  | 				let insert_line = chgline+n | 
					
						
							|  |  |  |  | 			else | 
					
						
							|  |  |  |  | 				let line = chgline | 
					
						
							|  |  |  |  | 				if !exists("g:spec_chglog_prepend") | 
					
						
							|  |  |  |  | 					while !(getline(line+2) =~ '^\( *\|\*.*\)$') | 
					
						
							|  |  |  |  | 						let line = line+1 | 
					
						
							|  |  |  |  | 					endwhile | 
					
						
							|  |  |  |  | 				endif | 
					
						
							|  |  |  |  | 				call append(line+1,"- ") | 
					
						
							|  |  |  |  | 				let insert_line = line+2 | 
					
						
							|  |  |  |  | 			endif | 
					
						
							|  |  |  |  | 			execute insert_line | 
					
						
							|  |  |  |  | 			startinsert! | 
					
						
							|  |  |  |  | 		endif | 
					
						
							|  |  |  |  | 	endfunction | 
					
						
							|  |  |  |  | endif | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | if !exists("*s:ParseRpmVars") | 
					
						
							|  |  |  |  |     function s:ParseRpmVars(str, strline) | 
					
						
							|  |  |  |  | 	let end = -1 | 
					
						
							|  |  |  |  | 	let ret = "" | 
					
						
							|  |  |  |  | 	while (1) | 
					
						
							|  |  |  |  | 		let start = match(a:str, "\%{", end+1) | 
					
						
							| 
									
										
										
										
											2020-12-23 13:56:35 +01:00
										 |  |  |  | 		if start == -1 | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  |  | 			let ret = ret . strpart(a:str, end+1) | 
					
						
							|  |  |  |  | 			break | 
					
						
							|  |  |  |  | 		endif | 
					
						
							|  |  |  |  | 		let ret = ret . strpart(a:str, end+1, start-(end+1)) | 
					
						
							|  |  |  |  | 		let end = match(a:str, "}", start) | 
					
						
							| 
									
										
										
										
											2020-12-23 13:56:35 +01:00
										 |  |  |  | 		if end == -1 | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  |  | 			let ret = ret . strpart(a:str, start) | 
					
						
							|  |  |  |  | 			break | 
					
						
							|  |  |  |  | 		endif | 
					
						
							|  |  |  |  | 		let varname = strpart(a:str, start+2, end-(start+2)) | 
					
						
							|  |  |  |  | 		execute a:strline | 
					
						
							| 
									
										
										
										
											2020-09-07 22:18:52 +02:00
										 |  |  |  | 		let definestr = "^[ \t]*%\\(define\\|global\\)[ \t]\\+".varname."[ \t]\\+\\(.*\\)$" | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  |  | 		let linenum = search(definestr, "bW") | 
					
						
							| 
									
										
										
										
											2020-12-23 13:56:35 +01:00
										 |  |  |  | 		if linenum != 0 | 
					
						
							| 
									
										
										
										
											2020-09-07 22:18:52 +02:00
										 |  |  |  | 			let ret = ret .  substitute(getline(linenum), definestr, "\\2", "") | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  |  | 		endif | 
					
						
							|  |  |  |  | 	endwhile | 
					
						
							|  |  |  |  | 	return ret | 
					
						
							|  |  |  |  |     endfunction | 
					
						
							|  |  |  |  | endif | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | " The following lines, along with the macros/matchit.vim plugin, | 
					
						
							|  |  |  |  | " make it easy to navigate the different sections of a spec file | 
					
						
							|  |  |  |  | " with the % key (thanks to Max Ischenko). | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | let b:match_ignorecase = 0 | 
					
						
							|  |  |  |  | let b:match_words = | 
					
						
							| 
									
										
										
										
											2016-06-04 20:20:29 +02:00
										 |  |  |  |   \ '^Name:^%description:^%clean:^%(?:auto)?setup:^%build:^%install:^%files:' . | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  |  |   \ '^%package:^%preun:^%postun:^%changelog' | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-30 13:11:27 +01:00
										 |  |  |  | let &cpo = s:cpo_save | 
					
						
							|  |  |  |  | unlet s:cpo_save | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-11 15:57:40 +01:00
										 |  |  |  | let b:undo_ftplugin = "unlet! b:match_ignorecase b:match_words" |