diff --git a/README.md b/README.md index 8384149..c327231 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,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 100+ times faster** than the 125 packages it consists of. +- It **installs and updates 100+ times faster** than the 126 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`). @@ -97,7 +97,7 @@ If you need full functionality of any plugin, please use it directly with your p - [json5](https://github.com/GutenYe/json5.vim) (syntax) - [json](https://github.com/elzr/vim-json) (syntax, indent, ftplugin) - [jst](https://github.com/briancollins/vim-jst) (syntax, indent) -- [jsx](https://github.com/mxw/vim-jsx) (after) +- [jsx](https://github.com/amadeus/vim-jsx) (syntax, indent, ftplugin) - [julia](https://github.com/JuliaEditorSupport/julia-vim) (syntax, indent, autoload, ftplugin) - [kotlin](https://github.com/udalov/kotlin-vim) (syntax, indent, ftplugin) - [latex](https://github.com/LaTeX-Box-Team/LaTeX-Box) (syntax, indent, ftplugin) @@ -166,6 +166,7 @@ If you need full functionality of any plugin, please use it directly with your p - [vm](https://github.com/lepture/vim-velocity) (syntax, indent) - [vue](https://github.com/posva/vim-vue) (syntax, indent, ftplugin) - [xls](https://github.com/vim-scripts/XSLT-syntax) (syntax) +- [xml](https://github.com/amadeus/vim-xml) (syntax) - [yaml](https://github.com/stephpy/vim-yaml) (syntax, ftplugin) - [yard](https://github.com/sheerun/vim-yardoc) (syntax) diff --git a/after/ftplugin/jsx.vim b/after/ftplugin/jsx.vim index 1217382..e1d689a 100644 --- a/after/ftplugin/jsx.vim +++ b/after/ftplugin/jsx.vim @@ -13,11 +13,19 @@ endif " modified from html.vim if exists("loaded_matchit") let b:match_ignorecase = 0 - let s:jsx_match_words = '(:),\[:\],{:},<:>,' . - \ '<\@<=\([^/][^ \t>]*\)[^>]*\%(/\@\|$\):<\@<=/\1>' - let b:match_words = exists('b:match_words') - \ ? b:match_words . ',' . s:jsx_match_words - \ : s:jsx_match_words + let s:jsx_match_words = '<\([a-zA-Z0-9.]\+\)\(>\|$\|\s\):<\/\1>' + + if !exists('b:loaded_jsx_match_words') + let b:loaded_jsx_match_words = 0 + endif + + if b:loaded_jsx_match_words == 0 + let b:match_words = exists('b:match_words') + \ ? b:match_words . ',' . s:jsx_match_words + \ : s:jsx_match_words + endif + + let b:loaded_jsx_match_words = 1 endif setlocal suffixesadd+=.jsx diff --git a/after/syntax/jsx.vim b/after/syntax/jsx.vim index 7991184..ac4dd61 100644 --- a/after/syntax/jsx.vim +++ b/after/syntax/jsx.vim @@ -62,6 +62,20 @@ syn region jsxRegion \ keepend \ extend +" Shorthand fragment support +" +" Note that since the main jsxRegion contains @XMLSyntax, we cannot simply +" adjust the regex above since @XMLSyntax will highlight the opening `<` as an +" XMLError. Instead we create a new group with the same name that does not +" include @XMLSyntax and instead uses matchgroup to get the same highlighting. +syn region jsxRegion + \ contains=@Spell,jsxRegion,jsxChild,jsBlock,javascriptBlock + \ matchgroup=xmlTag + \ start=/<>/ + \ end=/<\/>/ + \ keepend + \ extend + " Add jsxRegion to the lowest-level JS syntax cluster. syn cluster jsExpression add=jsxRegion diff --git a/build b/build index 2f25c54..9b55a01 100755 --- a/build +++ b/build @@ -205,7 +205,7 @@ PACKS=" json5:GutenYe/json5.vim json:elzr/vim-json jst:briancollins/vim-jst - jsx:mxw/vim-jsx:_ALL + jsx:amadeus/vim-jsx julia:JuliaEditorSupport/julia-vim kotlin:udalov/kotlin-vim latex:LaTeX-Box-Team/LaTeX-Box @@ -273,6 +273,7 @@ PACKS=" vifm:vifm/vifm.vim vm:lepture/vim-velocity vue:posva/vim-vue + xml:amadeus/vim-xml xls:vim-scripts/XSLT-syntax yaml:stephpy/vim-yaml yard:sheerun/vim-yardoc diff --git a/ftdetect/polyglot.vim b/ftdetect/polyglot.vim index a996ad4..5dc3b47 100644 --- a/ftdetect/polyglot.vim +++ b/ftdetect/polyglot.vim @@ -568,7 +568,7 @@ endif if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'jsx') == -1 augroup filetypedetect - " jsx, from javascript.vim in mxw/vim-jsx:_ALL + " jsx, from javascript.vim in amadeus/vim-jsx """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " Vim ftdetect file " @@ -577,20 +577,27 @@ if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'jsx') == -1 " """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" -" Whether the .jsx extension is required. -if !exists('g:jsx_ext_required') - let g:jsx_ext_required = 0 -endif - -" Whether the @jsx pragma is required. -if !exists('g:jsx_pragma_required') - let g:jsx_pragma_required = 0 -endif - let s:jsx_pragma_pattern = '\%^\_s*\/\*\*\%(\_.\%(\*\/\)\@!\)*@jsx\_.\{-}\*\/' +" if g:jsx_check_react_import == 1 +" parse the first line of js file (skipping comments). When it has a 'react' +" importation, we guess the user writes jsx +" endif +let s:jsx_prevalent_pattern = + \ '\v\C%^\_s*%(%(//.*\_$|/\*\_.{-}\*/)@>\_s*)*%(import\s+\k+\s+from\s+|%(\l+\s+)=\k+\s*\=\s*require\s*\(\s*)[`"'']react>' + " Whether to set the JSX filetype on *.js files. fu! EnableJSX() + " Whether the .jsx extension is required. + if !exists('g:jsx_ext_required') + let g:jsx_ext_required = 0 + endif + + " Whether the @jsx pragma is required. + if !exists('g:jsx_pragma_required') + let g:jsx_pragma_required = 0 + endif + if g:jsx_pragma_required && !exists('b:jsx_ext_found') " Look for the @jsx pragma. It must be included in a docblock comment " before anything else in the file (except whitespace). @@ -598,7 +605,10 @@ fu! EnableJSX() endif if g:jsx_pragma_required && !b:jsx_pragma_found | return 0 | endif - if g:jsx_ext_required && !exists('b:jsx_ext_found') | return 0 | endif + if g:jsx_ext_required && !exists('b:jsx_ext_found') && + \ !(get(g:,'jsx_check_react_import') && search(s:jsx_prevalent_pattern, 'nw')) + return 0 + endif return 1 endfu diff --git a/syntax/xml.vim b/syntax/xml.vim new file mode 100644 index 0000000..2e5c092 --- /dev/null +++ b/syntax/xml.vim @@ -0,0 +1,352 @@ +if exists('g:polyglot_disabled') && index(g:polyglot_disabled, 'xml') != -1 + finish +endif + +" Vim syntax file +" Language: XML +" Maintainer: Amadeus Demarzi http://github.com/amadeus +" Author and previous maintainers: +" Johannes Zellner +" Paul Siegmann +" Last Change: 2017 May 17 +" License: MIT +" Filenames: *.xml + +" CONFIGURATION: +" syntax folding can be turned on by +" +" let g:xml_syntax_folding = 1 +" +" before the syntax file gets loaded (e.g. in ~/.vimrc). +" This might slow down syntax highlighting significantly, +" especially for large files. +" +" CREDITS: +" The original version was derived by Paul Siegmann from +" Claudio Fleiner's html.vim. +" +" REFERENCES: +" [1] http://www.w3.org/TR/2000/REC-xml-20001006 +" [2] http://www.w3.org/XML/1998/06/xmlspec-report-19980910.htm +" +" as pointed out according to reference [1] +" +" 2.3 Common Syntactic Constructs +" [4] NameChar ::= Letter | Digit | '.' | '-' | '_' | ':' | CombiningChar | Extender +" [5] Name ::= (Letter | '_' | ':') (NameChar)* +" +" NOTE: +" 1) empty tag delimiters "/>" inside attribute values (strings) +" confuse syntax highlighting. +" 2) for large files, folding can be pretty slow, especially when +" loading a file the first time and viewoptions contains 'folds' +" so that folds of previous sessions are applied. +" Don't use 'foldmethod=syntax' in this case. + + +" Quit when a syntax file was already loaded +if exists("b:current_syntax") + finish +endif + +let s:xml_cpo_save = &cpo +set cpo&vim + +syn case match + +" mark illegal characters +syn match xmlError "[<&]" + +" strings (inside tags) aka VALUES +" +" EXAMPLE: +" +" +" ^^^^^^^ +syn region xmlString contained start=+"+ end=+"+ contains=xmlEntity,@Spell display +syn region xmlString contained start=+'+ end=+'+ contains=xmlEntity,@Spell display + + +" punctuation (within attributes) e.g. +" ^ ^ +" syn match xmlAttribPunct +[-:._]+ contained display +syn match xmlAttribPunct +[:.]+ contained display + +" no highlighting for xmlEqual (xmlEqual has no highlighting group) +syn match xmlEqual +=+ display + + +" attribute, everything before the '=' +" +" PROVIDES: @xmlAttribHook +" +" EXAMPLE: +" +" +" ^^^^^^^^^^^^^ +" +syn match xmlAttrib + \ +[-'"<]\@1\%(['"]\@!\|$\)+ + \ contained + \ contains=xmlAttribPunct,@xmlAttribHook + \ display + + +" namespace spec +" +" PROVIDES: @xmlNamespaceHook +" +" EXAMPLE: +" +" +" ^^^ +" +if exists("g:xml_namespace_transparent") +syn match xmlNamespace + \ +\(<\|"':]\+[:]\@=+ + \ contained + \ contains=@xmlNamespaceHook + \ transparent + \ display +else +syn match xmlNamespace + \ +\(<\|"':]\+[:]\@=+ + \ contained + \ contains=@xmlNamespaceHook + \ display +endif + + +" tag name +" +" PROVIDES: @xmlTagHook +" +" EXAMPLE: +" +" +" ^^^ +" +syn match xmlTagName + \ +\%(<\|"']\++ + \ contained + \ contains=xmlNamespace,xmlAttribPunct,@xmlTagHook + \ display + + +if exists('g:xml_syntax_folding') + + " start tag + " use matchgroup=xmlTag to skip over the leading '<' + " + " PROVIDES: @xmlStartTagHook + " + " EXAMPLE: + " + " + " s^^^^^^^^^^^^^^^e + " + syn region xmlTag + \ matchgroup=xmlTag start=+<[^ /!?<>"']\@=+ + \ matchgroup=xmlTag end=+>+ + \ contained + \ contains=xmlError,xmlTagName,xmlAttrib,xmlEqual,xmlString,@xmlStartTagHook + + + " highlight the end tag + " + " PROVIDES: @xmlTagHook + " (should we provide a separate @xmlEndTagHook ?) + " + " EXAMPLE: + " + " + " ^^^^^^ + " + syn region xmlEndTag + \ matchgroup=xmlTag start=+"']\@=+ + \ matchgroup=xmlTag end=+>+ + \ contained + \ contains=xmlTagName,xmlNamespace,xmlAttribPunct,@xmlTagHook + + " tag elements with syntax-folding. + " NOTE: NO HIGHLIGHTING -- highlighting is done by contained elements + " + " PROVIDES: @xmlRegionHook + " + " EXAMPLE: + " + " + " + " + " + " some data + " + " + syn region xmlRegion + \ start=+<\z([^ /!?<>"']\+\)+ + \ skip=++ + \ end=++ + \ end=+/>+ + \ fold + \ contains=xmlTag,xmlEndTag,xmlCdata,xmlRegion,xmlComment,xmlEntity,xmlProcessing,@xmlRegionHook,@Spell + \ keepend + \ extend + +else + + " no syntax folding: + " - contained attribute removed + " - xmlRegion not defined + " + syn region xmlTag + \ matchgroup=xmlTag start=+<[^ /!?<>"']\@=+ + \ matchgroup=xmlTag end=+>+ + \ contains=xmlError,xmlTagName,xmlAttrib,xmlEqual,xmlString,@xmlStartTagHook + + syn region xmlEndTag + \ matchgroup=xmlTag start=+"']\@=+ + \ matchgroup=xmlTag end=+>+ + \ contains=xmlTagName,xmlNamespace,xmlAttribPunct,@xmlTagHook + +endif + + +" &entities; compare with dtd +syn match xmlEntity "&[^; \t]*;" contains=xmlEntityPunct +syn match xmlEntityPunct contained "[&.;]" + +if exists('g:xml_syntax_folding') + + " The real comments (this implements the comments as defined by xml, + " but not all xml pages actually conform to it. Errors are flagged. + syn region xmlComment + \ start=++ + \ contains=xmlCommentStart,xmlCommentError + \ extend + \ fold + +else + + " no syntax folding: + " - fold attribute removed + " + syn region xmlComment + \ start=++ + \ contains=xmlCommentStart,xmlCommentError + \ extend + +endif + +syn match xmlCommentStart contained "+ + \ contains=xmlCdataStart,xmlCdataEnd,@xmlCdataHook,@Spell + \ keepend + \ extend + +" using the following line instead leads to corrupt folding at CDATA regions +" syn match xmlCdata ++ contains=xmlCdataStart,xmlCdataEnd,@xmlCdataHook +syn match xmlCdataStart ++ contained + + +" Processing instructions +" This allows "?>" inside strings -- good idea? +syn region xmlProcessing matchgroup=xmlProcessingDelim start="" contains=xmlAttrib,xmlEqual,xmlString + + +if exists('g:xml_syntax_folding') + + " DTD -- we use dtd.vim here + syn region xmlDocType matchgroup=xmlDocTypeDecl + \ start="" + \ fold + \ contains=xmlDocTypeKeyword,xmlInlineDTD,xmlString +else + + " no syntax folding: + " - fold attribute removed + " + syn region xmlDocType matchgroup=xmlDocTypeDecl + \ start="" + \ contains=xmlDocTypeKeyword,xmlInlineDTD,xmlString + +endif + +syn keyword xmlDocTypeKeyword contained DOCTYPE PUBLIC SYSTEM +syn region xmlInlineDTD contained matchgroup=xmlDocTypeDecl start="\[" end="]" contains=@xmlDTD +syn include @xmlDTD syntax/dtd.vim +unlet b:current_syntax + + +" synchronizing +" TODO !!! to be improved !!! + +syn sync match xmlSyncDT grouphere xmlDocType +\_.\(+ + +if exists('g:xml_syntax_folding') + syn sync match xmlSync grouphere xmlRegion +\_.\(<[^ /!?<>"']\+\)\@=+ + " syn sync match xmlSync grouphere xmlRegion "<[^ /!?<>"']*>" + syn sync match xmlSync groupthere xmlRegion +"']\+>+ +endif + +syn sync minlines=100 + + +" The default highlighting. +hi def link xmlTodo Todo +hi def link xmlTag Function +hi def link xmlTagName Function +hi def link xmlEndTag Identifier +if !exists("g:xml_namespace_transparent") + hi def link xmlNamespace Tag +endif +hi def link xmlEntity Statement +hi def link xmlEntityPunct Type + +hi def link xmlAttribPunct Comment +hi def link xmlAttrib Type + +hi def link xmlString String +hi def link xmlComment Comment +hi def link xmlCommentStart xmlComment +hi def link xmlCommentPart Comment +hi def link xmlCommentError Error +hi def link xmlError Error + +hi def link xmlProcessingDelim Comment +hi def link xmlProcessing Type + +hi def link xmlCdata String +hi def link xmlCdataCdata Statement +hi def link xmlCdataStart Type +hi def link xmlCdataEnd Type + +hi def link xmlDocTypeDecl Function +hi def link xmlDocTypeKeyword Statement +hi def link xmlInlineDTD Function + +let b:current_syntax = "xml" + +let &cpo = s:xml_cpo_save +unlet s:xml_cpo_save + +" vim: ts=8