From eacf785f5adcfb0b25988a0d0b8d05298033cb0c Mon Sep 17 00:00:00 2001 From: Adam Stankiewicz Date: Tue, 23 Apr 2019 11:43:40 +0200 Subject: [PATCH] Add svg plugin, closes #388 --- README.md | 4 +- build | 2 + indent/svg.vim | 109 ++++++++++++++++++++++++++++++++++++ syntax/svg.vim | 149 +++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 263 insertions(+), 1 deletion(-) create mode 100644 indent/svg.vim create mode 100644 syntax/svg.vim diff --git a/README.md b/README.md index 8aef1da..500c2ca 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ A collection of language packs for Vim. > One to rule them all, one to find them, one to bring them all and in the darkness bind them. - It **won't affect your startup time**, as scripts are loaded only on demand\*. -- It **installs and updates 120+ times faster** than the 133 packages it consists of. +- It **installs and updates 120+ times faster** than the 135 packages it consists of. - Solid syntax and indentation support (other features skipped). Only the best language packs. - All unnecessary files are ignored (like enormous documentation from php support). - No support for esoteric languages, only most popular ones (modern too, like `slim`). @@ -156,6 +156,8 @@ If you need full functionality of any plugin, please use it directly with your p - [smt2](https://github.com/bohlender/vim-smt2) (syntax, autoload, ftplugin) - [solidity](https://github.com/tomlion/vim-solidity) (syntax, indent, ftplugin) - [stylus](https://github.com/wavded/vim-stylus) (syntax, indent, ftplugin) +- [svg-indent](https://github.com/jasonshell/vim-svg-indent) (indent) +- [svg](https://github.com/vim-scripts/svg.vim) (syntax) - [swift](https://github.com/keith/swift.vim) (syntax, indent, ftplugin) - [sxhkd](https://github.com/baskerville/vim-sxhkdrc) (syntax) - [systemd](https://github.com/wgwoods/vim-systemd-syntax) (syntax) diff --git a/build b/build index baa1ed1..b69e9be 100755 --- a/build +++ b/build @@ -264,6 +264,8 @@ PACKS=" smt2:bohlender/vim-smt2 solidity:tomlion/vim-solidity stylus:wavded/vim-stylus + svg-indent:jasonshell/vim-svg-indent + svg:vim-scripts/svg.vim swift:keith/swift.vim sxhkd:baskerville/vim-sxhkdrc systemd:wgwoods/vim-systemd-syntax diff --git a/indent/svg.vim b/indent/svg.vim new file mode 100644 index 0000000..8e22f3b --- /dev/null +++ b/indent/svg.vim @@ -0,0 +1,109 @@ +if exists('g:polyglot_disabled') && index(g:polyglot_disabled, 'svg-indent') != -1 + finish +endif + +" Vim indent file +" +" Language: svg +" Maintainer: Jason Shell +" Last Change: 2015 Sep 23 +" Notes: 1) will be confused by unbalanced tags in comments + +" Only load this indent file when no other was loaded. +if exists('b:did_indent') + finish +endif +let b:did_indent = 1 +let s:keepcpo= &cpo +set cpo&vim + +" [-- local settings (must come before aborting the script) --] +setlocal indentexpr=SvgIndentGet(v:lnum,1) +setlocal indentkeys=o,O,*,<>>,<<>,/,{,} + +if !exists('b:svg_indent_open') + let b:svg_indent_open = '.\{-}<\a' + " pre tag, e.g.
+ " let b:svg_indent_open = '.\{-}<[/]\@!\(address\)\@!' +endif + +if !exists('b:svg_indent_close') + let b:svg_indent_close = '.\{-} + " let b:svg_indent_close = '.\{-}SvgIndentWithPattern(line, pat) + let s = substitute('x'.a:line, a:pat, "\1", 'g') + return strlen(substitute(s, "[^\1].*$", '', '')) +endfun + +" [-- check if it's svg --] +fun! SvgIndentSynCheck(lnum) + if '' != &syntax + let syn1 = synIDattr(synID(a:lnum, 1, 1), 'name') + let syn2 = synIDattr(synID(a:lnum, strlen(getline(a:lnum)) - 1, 1), 'name') + if '' != syn1 && syn1 !~ 'svg' && '' != syn2 && syn2 !~ 'svg' + " don't indent pure non-xml code + return 0 + + " elseif syn1 =~ '^xmlComment' && syn2 =~ '^xmlComment' + elseif syn1 =~ '^svgComment' && syn2 =~ '^svgComment' + " indent comments specially + return -1 + endif + endif + return 1 +endfun + +" [-- return the sum of indents of a:lnum --] +fun! SvgIndentSum(lnum, style, add) + let line = getline(a:lnum) + if a:style == match(line, '^\s*SvgIndentWithPattern(line, b:svg_indent_open) + \ - SvgIndentWithPattern(line, b:svg_indent_close) + \ - SvgIndentWithPattern(line, '.\{-}/>'))) + a:add + else + return a:add + endif +endfun + +fun! SvgIndentGet(lnum, use_syntax_check) + " Find a non-empty line above the current line. + let lnum = prevnonblank(a:lnum - 1) + + " Hit the start of the file, use zero indent. + if lnum == 0 + return 0 + endif + + if a:use_syntax_check + let check_lnum = SvgIndentSynCheck(lnum) + let check_alnum = SvgIndentSynCheck(a:lnum) + if 0 == check_lnum || 0 == check_alnum + return indent(a:lnum) + elseif -1 == check_lnum || -1 == check_alnum + return -1 + endif + endif + + let ind = SvgIndentSum(lnum, -1, indent(lnum)) + let ind = SvgIndentSum(a:lnum, 0, ind) + + return ind +endfun + +let &cpo = s:keepcpo +unlet s:keepcpo diff --git a/syntax/svg.vim b/syntax/svg.vim new file mode 100644 index 0000000..5321516 --- /dev/null +++ b/syntax/svg.vim @@ -0,0 +1,149 @@ +if exists('g:polyglot_disabled') && index(g:polyglot_disabled, 'svg') != -1 + finish +endif + +" Vim syntax file +" Language: SVG +" Filenames: *.svg +" Maintainer: Michal Gorny +" Last_change: 2006-03-23 + +if !exists("main_syntax") + if exists("b:current_syntax") + finish + endif + let main_syntax = 'svg' +endif + +if main_syntax == 'svg' + runtime! syntax/xml.vim + syn cluster xmlTagHook add=svgElement + syn cluster xmlAttribHook add=svgAttr + syn match xmlDecl /\<\(/ containedin=xmlProcessing contained + syn keyword xmlDeclAttr version encoding standalone containedin=xmlProcessing contained + syn keyword xmlDeclAttr alternate charset media href title type containedin=xmlProcessing contained +else + syn cluster xhtmlTagHook add=svgElement + syn cluster xhtmlAttribHook add=svgAttr +endif + +syn case match + +" SVG elements +syn match svgElement contained /\[^:]/me=e-1 +syn keyword svgElement contained altGlyph altGlyphDef altGlyphItem animate +syn keyword svgElement contained animateColor animateMotion animateTransform +syn keyword svgElement contained circle clipPath cursor defs desc ellipse +syn keyword svgElement contained feBlend feColorMatrix feComponentTransfer +syn keyword svgElement contained feComposite feConvolveMatrix feDiffuseLighting +syn keyword svgElement contained feDisplacementMap feDistantLight feFlood +syn keyword svgElement contained feFuncA feFuncB feFuncG feFuncR feGaussianBlur +syn keyword svgElement contained feImage feMerge feMergeNode feMorphology +syn keyword svgElement contained feOffset fePointLight feSpecularLighting +syn keyword svgElement contained feSpotLight feTile feTurbulence filter +syn keyword svgElement contained foreignObject glyph glyphRef hkern image line +syn keyword svgElement contained linearGradient marker mask metadata mpath path +syn keyword svgElement contained pattern polygon polyline radialGradient rect +syn keyword svgElement contained script set stop style switch symbol text +syn keyword svgElement contained textPath title tref tspan use view vkern +syn match svgElement contained /\<\(font\|font-face\)\>[^-]/me=e-1 +syn match svgElement contained /\/ +syn match svgElement contained /\<\(color-profile\|definition-src\)\>/ +syn match svgElement contained /\/ +syn match svgElement contained /\<\(a\|g\)\>[^:]/me=e-1 + +" SVG 1.0 attributes +syn keyword svgAttr contained accumulate additive alphabetic amplitude ascent attributeName attributeType azimuth baseFrequency bbox begin bias by +syn keyword svgAttr contained calcMode class clipPathUnits contentScriptType contentStyleType cursor cx cy d descent diffuseConstant direction display +syn keyword svgAttr contained divisor dur dx dy edgeMode elevation end exponent externalResourcesRequired filter filterRes filterUnits format from fx fy +syn keyword svgAttr contained g1 g2 glyphRef gradientTransform gradientUnits hanging height id ideographic in in2 intercept k k1 k2 k3 k4 kernelMatrix +syn keyword svgAttr contained kernelUnitLength kerning keyPoints keySplines keyTimes lang lengthAdjust limitingConeAngle local markerHeight markerUnits +syn keyword svgAttr contained markerWidth mask maskContentUnits maskUnits mathematical max media method min mode name numOctaves offset opacity operator +syn keyword svgAttr contained order orient orientation origin overflow path pathLength patternContentUnits patternTransform patternUnits points pointsAtX +syn keyword svgAttr contained pointsAtY pointsAtZ preserveAlpha preserveAspectRatio primitiveUnits r radius refX refY repeatCount repeatDur +syn keyword svgAttr contained requiredExtensions requiredFeatures restart result rotate rx ry scale seed slope spacing specularConstant specularExponent +syn keyword svgAttr contained spreadMethod startOffset stdDeviation stemh stemv stitchTiles string style surfaceScale systemLanguage tableValues target +syn keyword svgAttr contained targetX targetY textLength title to transform type u1 u2 values version viewBox viewTarget visibility width widths x x1 x2 +syn keyword svgAttr contained xChannelSelector y y1 y2 yChannelSelector z zoomAndPan +syn match svgAttr contained /\[^:]/me=e-1 +syn match svgAttr contained /\<\(clip\|color\|fill\)\>[^-]/me=e-1 +syn match svgAttr contained /\<\(stroke\|unicode\)\>[^-]/me=e-1 +syn match svgAttr contained /\<\(color-interpolation\|font-size\)\>[^-]/me=e-1 +syn match svgAttr contained /\<\(\accent-height\|alignment-baseline\|arabic-form\|baseline-shift\|cap-height\|clip-\(path\|rule\)\|dominant-baseline\)\>/ +syn match svgAttr contained /\<\(color-\(interpolation-filters\|profile\|rendering\)\|enable-background\|fill-\(opacity\|rule\)\)\>/ +syn match svgAttr contained /\<\(flood-\(color\|opacity\)\|font-\(family\|size-adjust\|stretch\|style\|variant\|weight\)\|image-rendering\)\>/ +syn match svgAttr contained /\<\(glyph-\(name\|orientation-\(horizontal\|vertical\)\)\|horiz-\(adv-x\|origin-\(x\|y\)\)\)\>/ +syn match svgAttr contained /\<\(letter-spacing\|lighting-color\|marker-\(end\|mid\|start\)\|overline-\(position\|thickness\)\|panose-1\)\>/ +syn match svgAttr contained /\<\(pointer-events\|rendering-intent\|shape-rendering\|stop-\(color\|opacity\)\|strikethrough-\(position\|thickness\)\)\>/ +syn match svgAttr contained /\<\(text-\(anchor\|decoration\|rendering\)\|stroke-\(dasharray\|dashoffset\|linecap\|linejoin\|miterlimit\|opacity\|width\)\)\>/ +syn match svgAttr contained /\<\(underline-\(position\|thickness\)\|unicode-\(bidi\|range\)\|units-per-em\|writing-mode\|x-height\)\>/ +syn match svgAttr contained /\(vert-\(adv-y\|origin-\(x\|y\)\)\|v-\(alphabetic\|hanging\|ideographic\|mathematical\)\|word-spacing\)\>/ +syn match svgAttr contained /\<\(xlink:\)\@<=\(actuate\|arcrole\|href\)\>/ +syn match svgAttr contained /\<\(xlink:\)\@<=\(role\|show\|title\|type\)\>/ +syn match svgAttr contained /\<\(xml:\)\@<=\(base\|lang\|space\)\>/ +syn match svgAttr contained /\<\(xmlns:\)\@<=xlink\>/ +" Events attributes +if exists("svg_no_events_rendering") + syn match svgEventAttr contained /\/ + if main_syntax == 'svg' + syn cluster xmlAttribHook add=svgEventAttr + else + syn cluster xhtmlAttribHook add=svgEventAttr + endif +endif + +" Attribute new in SVG 1.1 +syn keyword svgAttr contained baseProfile + +" Embedded ECMAScript (JavaScript) +if main_syntax == 'svg' + syn include @svgJavaScript syntax/javascript.vim + unlet b:current_syntax + syn region javaScript start=+]*[^/]>+ keepend end=++me=s-1 contains=@svgJavaScript,svgScriptTag + syn region svgScriptTag contained start=++ contains=xmlTagName,xmlString,xmlAttrib +endif + +" Events attributes rendering +if !exists("svg_no_events_rendering") + syn region svgEvent contained start=+\