robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
86b2751cad
master
1" Plugin to update the %changelog section of RPM spec files 2" Filename: spec.vim 3" Maintainer: Igor Gnatenko i.gnatenko.brain@gmail.com 4" Former Maintainer: Gustavo Niemeyer <niemeyer@conectiva.com> (until March 2014) 5" Last Change: 2015 Jun 01 6" Update by Zdenek Dohnal, 2022 May 17 7" 2024 Sep 10 by Vim Project: add epoch support for spec changelog, #15537 8" 2024 Oct 07 by Vim Project: add comment support, #15817 9" 2026 May 25 by Vim Project: drop the python GetRelVer() func 10 11if exists ( "b:did_ftplugin" ) 12finish 13endif 14let b: did_ftplugin = 1 15 16let s: cpo_save = & cpo 17set cpo & vim 18 19setlocal comments = b:# 20setlocal commentstring = #\ %s 21 22let b: undo_ftplugin = "setlocal comments< commentstring<" 23 24if ! exists ( "no_plugin_maps" ) && ! exists ( "no_spec_maps" ) 25if ! hasmapto ( "<Plug>SpecChangelog" ) 26map <buffer> < LocalLeader > c< Plug > SpecChangelog 27endif 28endif 29 30if ! hasmapto ( "call <SID>SpecChangelog(\"\")<CR>" ) 31noremap <buffer> <unique> <script> < Plug > SpecChangelog :call< SID > SpecChangelog("")< CR > 32endif 33 34if ! exists ( "*s:SpecChangelog" ) 35function s: SpecChangelog ( format ) 36if strlen ( a: format ) == 0 37if ! exists ( "g:spec_chglog_format" ) 38let = input ( "Name <email address>: " ) 39let g: spec_chglog_format = "%a %b %d %Y " . l: echo "\r" 41endif 42let format = g: spec_chglog_format 43else 44if ! exists ( "g:spec_chglog_format" ) 45let g: spec_chglog_format = a: format 46endif 47let format = a: format 48endif 49let line = 0 50let name = "" 51let epoch = "" 52let ver = "" 53let rel = "" 54let nameline = -1 55let epochline = -1 56let verline = -1 57let relline = -1 58let chgline = -1 59while ( line <= line ( "$" )) 60let linestr = getline ( line ) 61if name == "" && linestr =~? '^Name:' 62let nameline = line 63let name = substitute ( strpart ( linestr , 5 ), '^[ ]*\([^ ]\+\)[ ]*$' , '\1' , '' ) 64elseif epoch == "" && linestr =~? '^Epoch:' 65let epochline = line 66let epoch = substitute ( strpart ( linestr , 6 ), '^[ ]*\([^ ]\+\)[ ]*$' , '\1' , '' ) 67elseif ver == "" && linestr =~? '^Version:' 68let verline = line 69let ver = substitute ( strpart ( linestr , 8 ), '^[ ]*\([^ ]\+\)[ ]*$' , '\1' , '' ) 70elseif rel == "" && linestr =~? '^Release:' 71let relline = line 72let rel = substitute ( strpart ( linestr , 8 ), '^[ ]*\([^ ]\+\)[ ]*$' , '\1' , '' ) 73elseif linestr =~? '^%changelog' 74let chgline = line 75execute line 76break 77endif 78let line = line + 1 79endwhile 80if nameline != -1 && verline != -1 && relline != -1 81let include_release_info = exists ( "g:spec_chglog_release_info" ) 82let name = s: ParseRpmVars ( name , nameline ) 83let epoch = s: ParseRpmVars ( epoch , epochline ) 84let ver = s: ParseRpmVars ( ver , verline ) 85let rel = s: ParseRpmVars ( rel , relline ) 86else 87let include_release_info = 0 88endif 89 90if chgline == -1 91let option = confirm ( "Can't find %changelog. Create one? " , "&End of file\n&Here\n&Cancel" , 3 ) 92if option == 1 93call append ( line ( "$" ), "" ) 94call append ( line ( "$" ), "%changelog" ) 95execute line ( "$" ) 96let chgline = line ( "." ) 97elseif option == 2 98call append ( line ( "." ), "%changelog" ) 99normal j 100let chgline = line ( "." ) 101endif 102endif 103if chgline != -1 104let tmptime = v: lc_time 105language time C 106if strlen ( epoch ) 107let ver = epoch . ":" . ver 108endif 109let parsed_format = "* " . strftime ( format ) . " - " . ver . "-" . rel 110execute "language time" tmptime 111let release_info = "+ " . name . "-" . ver . "-" . rel 112let wrong_format = 0 113let wrong_release = 0 114let insert_line = 0 115if getline ( chgline + 1 ) != parsed_format 116let wrong_format = 1 117endif 118if include_release_info && getline ( chgline + 2 ) != release_info 119let wrong_release = 1 120endif 121if wrong_format || wrong_release 122if include_release_info && ! wrong_release && ! exists ( "g:spec_chglog_never_increase_release" ) 123let option = confirm ( "Increase release? " , "&Yes\n&No" , 1 ) 124if option == 1 125execute relline 126normal 127 let rel = substitute ( strpart ( getline ( relline ), 8 ), '^[ ]*\([^ ]\+\)[ ]*$' , '\1' , '' ) 128let release_info = "+ " . name . "-" . ver . "-" . rel 129endif 130endif 131let n = 0 132call append ( chgline + n , parsed_format ) 133if include_release_info 134let n = n + 1 135call append ( chgline + n , release_info ) 136endif 137let n = n + 1 138call append ( chgline + n , "- " ) 139let n = n + 1 140call append ( chgline + n , "" ) 141let insert_line = chgline + n 142else 143let line = chgline 144if ! exists ( "g:spec_chglog_prepend" ) 145while ! ( getline ( line + 2 ) =~ '^\( *\|\*.*\)$' ) 146let line = line + 1 147endwhile 148endif 149call append ( line + 1 , "- " ) 150let insert_line = line + 2 151endif 152execute insert_line 153startinsert ! 154endif 155endfunction 156endif 157 158if ! exists ( "*s:ParseRpmVars" ) 159function s: ParseRpmVars ( str , strline ) 160let end = -1 161let ret = "" 162while ( 1 ) 163let start = match ( a: str , "\%{" , end + 1 ) 164if start == -1 165let ret = ret . strpart ( a: str , end + 1 ) 166break 167endif 168let ret = ret . strpart ( a: str , end + 1 , start - ( end + 1 )) 169let end = match ( a: str , "}" , start ) 170if end == -1 171let ret = ret . strpart ( a: str , start ) 172break 173endif 174let varname = strpart ( a: str , start + 2 , end - ( start + 2 )) 175execute a: strline 176let definestr = "^[ \t]*%\\(define\\|global\\)[ \t]\\+" . varname . "[ \t]\\+\\(.*\\)$" 177let linenum = search ( definestr , "bW" ) 178if linenum != 0 179let ret = ret . substitute ( getline ( linenum ), definestr , "\\2" , "" ) 180endif 181endwhile 182return ret 183endfunction 184endif 185 186" The following lines, along with the matchit.vim plugin, 187" make it easy to navigate the different sections of a spec file 188" with the % key (thanks to Max Ischenko). 189 190let b: match_ignorecase = 0 191let b: match_words = 192 \'^Name:^%description:^%clean:^%(?:auto)?setup:^%build:^%install:^%files:' . 193 \'^%package:^%preun:^%postun:^%changelog' 194 195let & cpo = s: cpo_save 196unlet s: cpo_save 197 198let b: undo_ftplugin ..= " | unlet! b:match_ignorecase b:match_words"