update ftplugin/spec.vim, syntax/spec.vim (rhbz#1297746)

This commit is contained in:
Karsten Hopp 2016-04-29 12:13:19 +02:00
parent 3e8bfc8163
commit 50ff73bd48
4 changed files with 456 additions and 1 deletions

210
ftplugin-spec.vim Normal file
View File

@ -0,0 +1,210 @@
" Plugin to update the %changelog section of RPM spec files
" Filename: spec.vim
" Maintainer: Igor Gnatenko i.gnatenko.brain@gmail.com
" Former Maintainer: Gustavo Niemeyer <niemeyer@conectiva.com> (until March 2014)
" Last Change: Mon Jun 01 21:15 MSK 2015 Igor Gnatenko
if exists("b:did_ftplugin")
finish
endif
let b:did_ftplugin = 1
let s:cpo_save = &cpo
set cpo&vim
if !exists("no_plugin_maps") && !exists("no_spec_maps")
if !hasmapto("<Plug>SpecChangelog")
map <buffer> <LocalLeader>c <Plug>SpecChangelog
endif
endif
if !hasmapto("call <SID>SpecChangelog(\"\")<CR>")
noremap <buffer> <unique> <script> <Plug>SpecChangelog :call <SID>SpecChangelog("")<CR>
endif
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:
rpm.delMacro("dist")
spec = rpm.spec(specfile)
headers = spec.sourceHeader
version = headers["Version"]
release = headers["Release"]
vim.command("let ver = " + version)
vim.command("let rel = " + release)
PYEND
endif
endfunction
endif
if !exists("*s:SpecChangelog")
function s:SpecChangelog(format)
if strlen(a:format) == 0
if !exists("g:spec_chglog_format")
let email = input("Name <email address>: ")
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)
if (name == "" && linestr =~? '^Name:')
let nameline = line
let name = substitute(strpart(linestr,5), '^[ ]*\([^ ]\+\)[ ]*$','\1','')
elseif (ver == "" && linestr =~? '^Version:')
let verline = line
let ver = substitute(strpart(linestr,8), '^[ ]*\([^ ]\+\)[ ]*$','\1','')
elseif (rel == "" && linestr =~? '^Release:')
let relline = line
let rel = substitute(strpart(linestr,8), '^[ ]*\([^ ]\+\)[ ]*$','\1','')
elseif (linestr =~? '^%changelog')
let chgline = line
execute line
break
endif
let line = line+1
endwhile
if (nameline != -1 && verline != -1 && relline != -1)
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
call s:GetRelVer()
if (chgline == -1)
let option = confirm("Can't find %changelog. Create one? ","&End of file\n&Here\n&Cancel",3)
if (option == 1)
call append(line("$"),"")
call append(line("$"),"%changelog")
execute line("$")
let chgline = line(".")
elseif (option == 2)
call append(line("."),"%changelog")
normal j
chgline = line(".")
endif
endif
if (chgline != -1)
let tmptime = v:lc_time
language time C
let parsed_format = "* ".strftime(format)." - ".ver."-".rel
execute "language time" tmptime
let release_info = "+ ".name."-".ver."-".rel
let wrong_format = 0
let wrong_release = 0
let insert_line = 0
if (getline(chgline+1) != parsed_format)
let wrong_format = 1
endif
if (include_release_info && getline(chgline+2) != release_info)
let wrong_release = 1
endif
if (wrong_format || wrong_release)
if (include_release_info && !wrong_release && !exists("g:spec_chglog_never_increase_release"))
let option = confirm("Increase release? ","&Yes\n&No",1)
if (option == 1)
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)
if (start == -1)
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)
if (end == -1)
let ret = ret . strpart(a:str, start)
break
endif
let varname = strpart(a:str, start+2, end-(start+2))
execute a:strline
let definestr = "^[ \t]*%(?:global|define)[ \t]\\+" . varname . "[ \t]\\+\\(.*\\)$"
let linenum = search(definestr, "bW")
if (linenum != -1)
let ret = ret . substitute(getline(linenum), definestr, "\\1", "")
else
let ret = ret . strpart(str, start, end+1-start)
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 =
\ '^Name:^%description:^%clean:^%(?:auto)?setup:^%build:^%install:^%files:' .
\ '^%package:^%preun:^%postun:^%changelog'
let &cpo = s:cpo_save
unlet s:cpo_save
let b:undo_ftplugin = "unlet! b:match_ignorecase b:match_words"

236
syntax-spec.vim Normal file
View File

@ -0,0 +1,236 @@
" Filename: spec.vim
" Purpose: Vim syntax file
" Language: SPEC: Build/install scripts for Linux RPM packages
" Maintainer: Igor Gnatenko i.gnatenko.brain@gmail.com
" Former Maintainer: Donovan Rebbechi elflord@panix.com (until March 2014)
" Last Change: Sat Apr 9 15:30 2016 Filip Szymański
" For version 5.x: Clear all syntax items
" For version 6.x: Quit when a syntax file was already loaded
if version < 600
syntax clear
elseif exists("b:current_syntax")
finish
endif
syn sync minlines=1000
syn match specSpecialChar contained '[][!$()\\|>^;:{}]'
syn match specColon contained ':'
syn match specPercent contained '%'
syn match specVariables contained '\$\h\w*' contains=specSpecialVariablesNames,specSpecialChar
syn match specVariables contained '\${\w*}' contains=specSpecialVariablesNames,specSpecialChar
syn match specMacroIdentifier contained '%\h\w*' contains=specMacroNameLocal,specMacroNameOther,specPercent
syn match specMacroIdentifier contained '%{\w*}' contains=specMacroNameLocal,specMacroNameOther,specPercent,specSpecialChar
syn match specSpecialVariables contained '\$[0-9]\|\${[0-9]}'
syn match specCommandOpts contained '\s\(-\w\+\|--\w[a-zA-Z_-]\+\)'ms=s+1
syn match specComment '^\s*#.*$'
syn case match
"matches with no highlight
syn match specNoNumberHilite 'X11\|X11R6\|[a-zA-Z]*\.\d\|[a-zA-Z][-/]\d'
syn match specManpageFile '[a-zA-Z]\.1'
"Day, Month and most used license acronyms
syn keyword specLicense contained GPL LGPL BSD MIT GNU
syn keyword specWeekday contained Mon Tue Wed Thu Fri Sat Sun
syn keyword specMonth contained Jan Feb Mar Apr Jun Jul Aug Sep Oct Nov Dec
syn keyword specMonth contained January February March April May June July August September October November December
"#, @, www
syn match specNumber '\(^-\=\|[ \t]-\=\|-\)[0-9.-]*[0-9]'
syn match specEmail contained "<\=\<[A-Za-z0-9_.-]\+@\([A-Za-z0-9_-]\+\.\)\+[A-Za-z]\+\>>\="
syn match specURL contained '\<\(\(https\{0,1}\|ftp\)://\|\(www[23]\{0,1}\.\|ftp\.\)\)[A-Za-z0-9._/~:,#-]\+\>'
syn match specURLMacro contained '\<\(\(https\{0,1}\|ftp\)://\|\(www[23]\{0,1}\.\|ftp\.\)\)[A-Za-z0-9._/~:,#%{}-]\+\>' contains=specMacroIdentifier
"TODO take specSpecialVariables out of the cluster for the sh* contains (ALLBUT)
"Special system directories
syn match specListedFilesPrefix contained '/\(usr\|local\|opt\|X11R6\|X11\)/'me=e-1
syn match specListedFilesBin contained '/s\=bin/'me=e-1
syn match specListedFilesLib contained '/\(lib\|include\)/'me=e-1
syn match specListedFilesDoc contained '/\(man\d*\|doc\|info\)\>'
syn match specListedFilesEtc contained '/etc/'me=e-1
syn match specListedFilesShare contained '/share/'me=e-1
syn cluster specListedFiles contains=specListedFilesBin,specListedFilesLib,specListedFilesDoc,specListedFilesEtc,specListedFilesShare,specListedFilesPrefix,specVariables,specSpecialChar
"specComands
syn match specConfigure contained '\./configure'
syn match specTarCommand contained '\<tar\s\+[cxvpzIf]\{,5}\s*'
syn keyword specCommandSpecial contained root
syn keyword specCommand contained make xmkmf mkdir chmod ln find sed rm strip moc echo grep ls rm mv mkdir install cp pwd cat tail then else elif cd gzip rmdir ln eval export touch
syn cluster specCommands contains=specCommand,specTarCommand,specConfigure,specCommandSpecial
"frequently used rpm env vars
syn keyword specSpecialVariablesNames contained RPM_BUILD_ROOT RPM_BUILD_DIR RPM_SOURCE_DIR RPM_OPT_FLAGS LDFLAGS CC CC_FLAGS CPPNAME CFLAGS CXX CXXFLAGS CPPFLAGS
"valid macro names from /usr/lib/rpm/macros
syn keyword specMacroNameOther contained buildroot buildsubdir distribution disturl ix86 name nil optflags perl_sitearch release requires_eq vendor version
syn match specMacroNameOther contained '\<\(PATCH\|SOURCE\)\d*\>'
"valid _macro names from /usr/lib/rpm/macros
syn keyword specMacroNameLocal contained _arch _binary_payload _bindir _build _build_alias _build_cpu _builddir _build_os _buildshell _buildsubdir _build_vendor _bzip2bin _datadir _dbpath _dbpath_rebuild _defaultdocdir _docdir _excludedocs _exec_prefix _fixgroup _fixowner _fixperms _ftpport _ftpproxy _gpg_path _gzipbin _host _host_alias _host_cpu _host_os _host_vendor _httpport _httpproxy _includedir _infodir _install_langs _install_script_path _instchangelog _langpatt _lib _libdir _libexecdir _localstatedir _mandir _netsharedpath _oldincludedir _os _pgpbin _pgp_path _prefix _preScriptEnvironment _provides _rpmdir _rpmfilename _sbindir _sharedstatedir _signature _sourcedir _source_payload _specdir _srcrpmdir _sysconfdir _target _target_alias _target_cpu _target_os _target_platform _target_vendor _timecheck _tmppath _topdir _usr _usrsrc _var _vendor
"------------------------------------------------------------------------------
" here's is all the spec sections definitions: PreAmble, Description, Package,
" Scripts, Files and Changelog
"One line macros - valid in all ScriptAreas
"tip: remember do include new items on specScriptArea's skip section
syn region specSectionMacroArea oneline matchgroup=specSectionMacro start='^%\(define\|global\|patch\d*\|setup\|autosetup\|autopatch\|configure\|GNUconfigure\|find_lang\|make_build\|makeinstall\|make_install\|include\)\>' end='$' contains=specCommandOpts,specMacroIdentifier
syn region specSectionMacroBracketArea oneline matchgroup=specSectionMacro start='^%{\(configure\|GNUconfigure\|find_lang\|make_build\|makeinstall\|make_install\)}' end='$' contains=specCommandOpts,specMacroIdentifier
"%% Files Section %%
"TODO %config valid parameters: missingok\|noreplace
"TODO %verify valid parameters: \(not\)\= \(md5\|atime\|...\)
syn region specFilesArea matchgroup=specSection start='^%[Ff][Ii][Ll][Ee][Ss]\>' skip='%\(attrib\|defattr\|attr\|dir\|config\|docdir\|doc\|lang\|verify\|ghost\)\>' end='^%[a-zA-Z]'me=e-2 contains=specFilesOpts,specFilesDirective,@specListedFiles,specComment,specCommandSpecial,specMacroIdentifier
"tip: remember to include new itens in specFilesArea above
syn match specFilesDirective contained '%\(attrib\|defattr\|attr\|dir\|config\|docdir\|doc\|lang\|verify\|ghost\)\>'
"valid options for certain section headers
syn match specDescriptionOpts contained '\s-[ln]\s*\a'ms=s+1,me=e-1
syn match specPackageOpts contained '\s-n\s*\w'ms=s+1,me=e-1
syn match specFilesOpts contained '\s-f\s*\w'ms=s+1,me=e-1
syn case ignore
"%% PreAmble Section %%
"Copyright and Serial were deprecated by License and Epoch
syn region specPreAmbleDeprecated oneline matchgroup=specError start='^\(Copyright\|Serial\)' end='$' contains=specEmail,specURL,specURLMacro,specLicense,specColon,specVariables,specSpecialChar,specMacroIdentifier
syn region specPreAmble oneline matchgroup=specCommand start='^\(Prereq\|Summary\|Name\|Version\|Packager\|Requires\|Recommends\|Suggests\|Supplements\|Enhances\|Icon\|URL\|Source\d*\|Patch\d*\|Prefix\|Packager\|Group\|License\|Release\|BuildRoot\|Distribution\|Vendor\|Provides\|ExclusiveArch\|ExcludeArch\|ExclusiveOS\|Obsoletes\|BuildArch\|BuildArchitectures\|BuildRequires\|BuildConflicts\|BuildPreReq\|Conflicts\|AutoRequires\|AutoReq\|AutoReqProv\|AutoProv\|Epoch\)' end='$' contains=specEmail,specURL,specURLMacro,specLicense,specColon,specVariables,specSpecialChar,specMacroIdentifier
"%% Description Section %%
syn region specDescriptionArea matchgroup=specSection start='^%description' end='^%'me=e-1 contains=specDescriptionOpts,specEmail,specURL,specNumber,specMacroIdentifier,specComment
"%% Package Section %%
syn region specPackageArea matchgroup=specSection start='^%package' end='^%'me=e-1 contains=specPackageOpts,specPreAmble,specComment
"%% Scripts Section %%
syn region specScriptArea matchgroup=specSection start='^%\(prep\|build\|install\|clean\|pre\|postun\|preun\|post\|posttrans\)\>' skip='^%{\|^%\(define\|patch\d*\|configure\|GNUconfigure\|setup\|autosetup\|autopatch\|find_lang\|make_build\|makeinstall\|make_install\)\>' end='^%'me=e-1 contains=specSpecialVariables,specVariables,@specCommands,specVariables,shDo,shFor,shCaseEsac,specNoNumberHilite,specCommandOpts,shComment,shIf,specSpecialChar,specMacroIdentifier,specSectionMacroArea,specSectionMacroBracketArea,shOperator,shQuote1,shQuote2
"%% Changelog Section %%
syn region specChangelogArea matchgroup=specSection start='^%changelog' end='^%'me=e-1 contains=specEmail,specURL,specWeekday,specMonth,specNumber,specComment,specLicense
"------------------------------------------------------------------------------
"here's the shell syntax for all the Script Sections
syn case match
"sh-like comment stile, only valid in script part
syn match shComment contained '#.*$'
syn region shQuote1 contained matchgroup=shQuoteDelim start=+'+ skip=+\\'+ end=+'+ contains=specMacroIdentifier
syn region shQuote2 contained matchgroup=shQuoteDelim start=+"+ skip=+\\"+ end=+"+ contains=specVariables,specMacroIdentifier
syn match shOperator contained '[><|!&;]\|[!=]='
syn region shDo transparent matchgroup=specBlock start="\<do\>" end="\<done\>" contains=ALLBUT,shFunction,shDoError,shCase,specPreAmble,@specListedFiles
syn region specIf matchgroup=specBlock start="%ifosf\|%ifos\|%ifnos\|%ifarch\|%ifnarch\|%else" end='%endif' contains=ALLBUT, specIfError, shCase
syn region shIf transparent matchgroup=specBlock start="\<if\>" end="\<fi\>" contains=ALLBUT,shFunction,shIfError,shCase,@specListedFiles
syn region shFor matchgroup=specBlock start="\<for\>" end="\<in\>" contains=ALLBUT,shFunction,shInError,shCase,@specListedFiles
syn region shCaseEsac transparent matchgroup=specBlock start="\<case\>" matchgroup=NONE end="\<in\>"me=s-1 contains=ALLBUT,shFunction,shCaseError,@specListedFiles nextgroup=shCaseEsac
syn region shCaseEsac matchgroup=specBlock start="\<in\>" end="\<esac\>" contains=ALLBUT,shFunction,shCaseError,@specListedFilesBin
syn region shCase matchgroup=specBlock contained start=")" end=";;" contains=ALLBUT,shFunction,shCaseError,shCase,@specListedFiles
syn sync match shDoSync grouphere shDo "\<do\>"
syn sync match shDoSync groupthere shDo "\<done\>"
syn sync match shIfSync grouphere shIf "\<if\>"
syn sync match shIfSync groupthere shIf "\<fi\>"
syn sync match specIfSync grouphere specIf "%ifarch\|%ifos\|%ifnos"
syn sync match specIfSync groupthere specIf "%endIf"
syn sync match shForSync grouphere shFor "\<for\>"
syn sync match shForSync groupthere shFor "\<in\>"
syn sync match shCaseEsacSync grouphere shCaseEsac "\<case\>"
syn sync match shCaseEsacSync groupthere shCaseEsac "\<esac\>"
" Define the default highlighting.
" For version 5.7 and earlier: only when not done already
" For version 5.8 and later: only when an item doesn't have highlighting yet
if version >= 508 || !exists("did_spec_syntax_inits")
if version < 508
let did_spec_syntax_inits = 1
command -nargs=+ HiLink hi link <args>
else
command -nargs=+ HiLink hi def link <args>
endif
"main types color definitions
HiLink specSection Structure
HiLink specSectionMacro Macro
HiLink specWWWlink PreProc
HiLink specOpts Operator
"yes, it's ugly, but white is sooo cool
if &background == "dark"
hi def specGlobalMacro ctermfg=white
else
HiLink specGlobalMacro Identifier
endif
"sh colors
HiLink shComment Comment
HiLink shIf Statement
HiLink shOperator Special
HiLink shQuote1 String
HiLink shQuote2 String
HiLink shQuoteDelim Statement
"spec colors
HiLink specBlock Function
HiLink specColon Special
HiLink specCommand Statement
HiLink specCommandOpts specOpts
HiLink specCommandSpecial Special
HiLink specComment Comment
HiLink specConfigure specCommand
HiLink specDate String
HiLink specDescriptionOpts specOpts
HiLink specEmail specWWWlink
HiLink specError Error
HiLink specFilesDirective specSectionMacro
HiLink specFilesOpts specOpts
HiLink specLicense String
HiLink specMacroNameLocal specGlobalMacro
HiLink specMacroNameOther specGlobalMacro
HiLink specManpageFile NONE
HiLink specMonth specDate
HiLink specNoNumberHilite NONE
HiLink specNumber Number
HiLink specPackageOpts specOpts
HiLink specPercent Special
HiLink specSpecialChar Special
HiLink specSpecialVariables specGlobalMacro
HiLink specSpecialVariablesNames specGlobalMacro
HiLink specTarCommand specCommand
HiLink specURL specWWWlink
HiLink specURLMacro specWWWlink
HiLink specVariables Identifier
HiLink specWeekday specDate
HiLink specListedFilesBin Statement
HiLink specListedFilesDoc Statement
HiLink specListedFilesEtc Statement
HiLink specListedFilesLib Statement
HiLink specListedFilesPrefix Statement
HiLink specListedFilesShare Statement
delcommand HiLink
endif
let b:current_syntax = "spec"
" vim: ts=8

View File

@ -42,6 +42,8 @@ popd
cp -f vim-upstream/dist/README.patches README.patches
cp -f vim-upstream/dist/vim-${UPSTREAMMAJOR}-${LASTPLFILLED}.tar.bz2 .
wget https://raw.githubusercontent.com/ignatenkobrain/vim-spec-plugin/master/ftplugin/spec.vim -O ftplugin-spec.vim
wget https://raw.githubusercontent.com/ignatenkobrain/vim-spec-plugin/master/syntax/spec.vim -O syntax-spec.vim
if [ $CHANGES -ne 0 ]; then
CHLOG="* $DATE Karsten Hopp <karsten@redhat.com> $UPSTREAMMAJOR"
$debug sed -i -e "/Release: /cRelease: 1%{?dist}" $SPEC

View File

@ -21,7 +21,7 @@ Summary: The VIM editor
URL: http://www.vim.org/
Name: vim
Version: %{baseversion}.%{patchlevel}
Release: 1%{?dist}
Release: 2%{?dist}
License: Vim
Group: Applications/Editors
Source0: ftp://ftp.vim.org/pub/vim/unix/vim-%{baseversion}-%{patchlevel}.tar.bz2
@ -39,6 +39,8 @@ Source13: vim-spell-files.tar.bz2
%endif
Source14: spec-template
Source15: spec-template.new
Source16: ftplugin-spec.vim
Source17: syntax-spec.vim
Patch2002: vim-7.0-fixkeys.patch
Patch2003: vim-6.2-specsyntax.patch
@ -330,6 +332,8 @@ cp -f %{SOURCE15} %{buildroot}/%{_datadir}/%{name}/vimfiles/template.spec
%else
cp -f %{SOURCE14} %{buildroot}/%{_datadir}/%{name}/vimfiles/template.spec
%endif
cp -f %{SOURCE16} %{buildroot}/%{_datadir}/%{name}/%{vimdir}/ftplugin/spec.vim
cp -f %{SOURCE17} %{buildroot}/%{_datadir}/%{name}/%{vimdir}/syntax/spec.vim
cp runtime/doc/uganda.txt LICENSE
# Those aren't Linux info files but some binary files for Amiga:
rm -f README*.info
@ -756,6 +760,9 @@ rm -rf %{buildroot}
%{_datadir}/icons/hicolor/*/apps/*
%changelog
* Mon Apr 25 2016 Karsten Hopp <karsten@redhat.com> - 7.4.1320-2
- update ftplugin/spec.vim, syntax/spec.vim (rhbz#1297746)
* Mon Feb 15 2016 Karsten Hopp <karsten@redhat.com> 7.4.1320-1
- patchlevel 1320