Squashed 'vim/bundle/jsx/' changes from c6d0fd7d4..d0ad98cf0
d0ad98cf0 Merge pull request #92 from jambonrose/update-vundle-readme 005c0f6e3 Expand Vundle section in ReadMe. 2bd9126d7 Merge pull request #89 from StoicLoofah/manual-installation-path 3233f48ae update README to provide correct filenames for manual installation b25141d22 Add a syntax element for JSX child blocks 34b6b9994 Merge pull request #75 from ksmithbaylor/patch-1 6d32ac410 Clarify regex comment 2e3292c0e Combine multiline opening tag logic dfa485d5b Remove g:jsx_multiline_opening_tags flag 14a820c5c Add support for multiline opening tags db329e121 Add rules and regulations for filing issues... af0831cc0 Cleanup c68282f41 Merge pull request #11 from jstoja/vundle-install 80dbab758 Avoid conflict w/ Flow generics da9b92b72 Move ftdetect out of after/ fc200a394 Remove legacy jsx-config stuff 9c9a13165 Source formating changes 6d4698f86 Adding the vundle installation line into the README git-subtree-dir: vim/bundle/jsx git-subtree-split: d0ad98cf0e5a01abd5008c0e97775500b88b0bc1
This commit is contained in:
parent
9ee501a1de
commit
b0e35109dd
49
README.md
49
README.md
@ -10,6 +10,30 @@ This bundle requires pangloss's [vim-javascript][2] syntax highlighting.
|
||||
Vim support for inline XML in JS is remarkably similar to the same for PHP,
|
||||
which you can find [here][3].
|
||||
|
||||
Troubleshooting
|
||||
---------------
|
||||
|
||||
If you're experiencing weird highlighting or indenting throughout your JSX
|
||||
code, please file a GitHub issue which includes the following:
|
||||
|
||||
- A brief affirmation that you've read the README and installed the appropriate
|
||||
dependencies.
|
||||
|
||||
- A minimal ~/.vimrc which repros the issue you're having, as well as a
|
||||
screenshot or gif of the issue (a paste is insufficient, since it doesn't
|
||||
show me the specific highlighting or indenting problem). To obtain a minimal
|
||||
~/.vimrc, simply bisect your ~/.vimrc by adding `finish` at various points in
|
||||
the file. (You can likewise bisect your included plugins by selectively
|
||||
including only half of them, then a quarter, etc.).
|
||||
|
||||
Most of the issues filed result from failures to install vim-javascript or
|
||||
conflicts with existing JS syntax or indent files---so failing to indicate that
|
||||
you've ruled those issues out may result in your issue being closed with no
|
||||
comment.
|
||||
|
||||
(Please feel free to disregard all this for feature requests and more
|
||||
corner-case bugs.)
|
||||
|
||||
Usage
|
||||
-----
|
||||
|
||||
@ -42,6 +66,26 @@ The recommended installation method is via [Pathogen][4]. Then simply execute
|
||||
cd ~/.vim/bundle
|
||||
git clone https://github.com/mxw/vim-jsx.git
|
||||
|
||||
(You can install [vim-javascript][2] in an analogous manner.)
|
||||
|
||||
### Vundle
|
||||
|
||||
You can also add vim-jsx using [Vundle][5]---just add the following lines to
|
||||
your `~/.vimrc`:
|
||||
|
||||
Plugin 'pangloss/vim-javascript'
|
||||
Plugin 'mxw/vim-jsx'
|
||||
|
||||
To install from within vim, use the commands below.
|
||||
|
||||
:so ~/.vimrc
|
||||
:PluginInstall
|
||||
|
||||
Alternatively, use the command below to install the plugins from the command
|
||||
line.
|
||||
|
||||
vim +PluginInstall +qall
|
||||
|
||||
### Manual Installation
|
||||
|
||||
If you have no `~/.vim/after` directory, you can download the tarball or zip
|
||||
@ -52,12 +96,13 @@ directly into their respective destinations. If you have existing after syntax
|
||||
or indent files for Javascript, you'll probably want to do something like
|
||||
|
||||
mkdir -p ~/.vim/after/syntax/javascript
|
||||
cp path/to/vim-jsx/after/syntax/javascript.vim ~/.vim/after/syntax/javascript/javascript.vim
|
||||
cp path/to/vim-jsx/after/syntax/jsx.vim ~/.vim/after/syntax/javascript/jsx.vim
|
||||
mkdir -p ~/.vim/after/indent/javascript
|
||||
cp path/to/vim-jsx/after/indent/javascript.vim ~/.vim/after/indent/javascript/javascript.vim
|
||||
cp path/to/vim-jsx/after/indent/jsx.vim ~/.vim/after/indent/javascript/jsx.vim
|
||||
|
||||
|
||||
[1]: http://facebook.github.io/react/ "React"
|
||||
[2]: https://github.com/pangloss/vim-javascript "pangloss: vim-javascript"
|
||||
[3]: https://github.com/mxw/vim-xhp "mxw: vim-xhp"
|
||||
[4]: https://github.com/tpope/vim-pathogen "tpope: vim-pathogen"
|
||||
[5]: https://github.com/VundleVim/Vundle "VundleVim: Vundle"
|
||||
|
||||
@ -7,13 +7,6 @@
|
||||
"
|
||||
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
||||
|
||||
" Do nothing if we don't find the @jsx pragma (and we care).
|
||||
exec 'source '.fnameescape(expand('<sfile>:p:h:h').'/jsx-config.vim')
|
||||
if g:jsx_pragma_required && !b:jsx_pragma_found | finish | endif
|
||||
|
||||
" Do nothing if we don't have the .jsx extension (and we care).
|
||||
if g:jsx_ext_required && !exists('b:jsx_ext_found') | finish | endif
|
||||
|
||||
" Prologue; load in XML indentation.
|
||||
if exists('b:did_indent')
|
||||
let s:did_indent=b:did_indent
|
||||
@ -31,8 +24,8 @@ setlocal indentkeys=0{,0},0),0],0\,,!^F,o,O,e
|
||||
" XML indentkeys
|
||||
setlocal indentkeys+=*<Return>,<>>,<<>,/
|
||||
|
||||
" Self-closing tag regex.
|
||||
let s:sctag = '^\s*\/>\s*;\='
|
||||
" Multiline end tag regex (line beginning with '>' or '/>')
|
||||
let s:endtag = '^\s*\/\?>\s*;\='
|
||||
|
||||
" Get all syntax types at the beginning of a given line.
|
||||
fu! SynSOL(lnum)
|
||||
@ -81,13 +74,13 @@ fu! GetJsxIndent()
|
||||
if (SynXMLish(prevsyn) || SynJSXBlockEnd(prevsyn)) && SynXMLishAny(cursyn)
|
||||
let ind = XmlIndentGet(v:lnum, 0)
|
||||
|
||||
" Align '/>' with '<' for multiline self-closing tags.
|
||||
if getline(v:lnum) =~? s:sctag
|
||||
" Align '/>' and '>' with '<' for multiline tags.
|
||||
if getline(v:lnum) =~? s:endtag
|
||||
let ind = ind - &sw
|
||||
endif
|
||||
|
||||
" Then correct the indentation of any JSX following '/>'.
|
||||
if getline(v:lnum - 1) =~? s:sctag
|
||||
" Then correct the indentation of any JSX following '/>' or '>'.
|
||||
if getline(v:lnum - 1) =~? s:endtag
|
||||
let ind = ind + &sw
|
||||
endif
|
||||
else
|
||||
|
||||
@ -1,33 +0,0 @@
|
||||
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
||||
" Vimscript file
|
||||
"
|
||||
" Set up a bunch of configuration variables.
|
||||
"
|
||||
" Also check (if desired) whether or not the @jsx pragma is correctly included
|
||||
" in '%'. Set the result in b:jsx_pragma_found.
|
||||
"
|
||||
" Language: JSX (JavaScript)
|
||||
" Maintainer: Max Wang <mxawng@gmail.com>
|
||||
"
|
||||
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
||||
|
||||
" Only check once.
|
||||
if exists('b:jsx_pragma_found')
|
||||
finish
|
||||
endif
|
||||
|
||||
" Whether the .jsx extension is required to enable JSX syntax/indent.
|
||||
if !exists('g:jsx_ext_required')
|
||||
let g:jsx_ext_required = 1
|
||||
endif
|
||||
|
||||
" Whether the @jsx pragma is required to enable JSX syntax/indent.
|
||||
if !exists('g:jsx_pragma_required')
|
||||
let g:jsx_pragma_required = 0
|
||||
endif
|
||||
if !g:jsx_pragma_required | finish | endif
|
||||
|
||||
" Look for the @jsx pragma. It must be included in a docblock comment before
|
||||
" anything else in the file (except whitespace).
|
||||
let s:jsx_pragma_pattern = '\%^\_s*\/\*\*\%(\_.\%(\*\/\)\@!\)*@jsx\_.\{-}\*\/'
|
||||
let b:jsx_pragma_found = search(s:jsx_pragma_pattern, 'npw')
|
||||
@ -9,13 +9,6 @@
|
||||
"
|
||||
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
||||
|
||||
" Do nothing if we don't find the @jsx pragma (and we care).
|
||||
exec 'source '.fnameescape(expand('<sfile>:p:h:h').'/jsx-config.vim')
|
||||
if g:jsx_pragma_required && !b:jsx_pragma_found | finish | endif
|
||||
|
||||
" Do nothing if we don't have the .jsx extension (and we care).
|
||||
if g:jsx_ext_required && !exists('b:jsx_ext_found') | finish | endif
|
||||
|
||||
" Prologue; load in XML syntax.
|
||||
if exists('b:current_syntax')
|
||||
let s:current_syntax=b:current_syntax
|
||||
@ -26,22 +19,43 @@ if exists('s:current_syntax')
|
||||
let b:current_syntax=s:current_syntax
|
||||
endif
|
||||
|
||||
" Officially, vim-jsx depends on the pangloss/vim-javascript syntax package
|
||||
" (and is tested against it exclusively). However, in practice, we make some
|
||||
" effort towards compatibility with other packages.
|
||||
"
|
||||
" These are the plugin-to-syntax-element correspondences:
|
||||
"
|
||||
" - pangloss/vim-javascript: jsBlock, jsExpression
|
||||
" - jelera/vim-javascript-syntax: javascriptBlock
|
||||
" - othree/yajs.vim: javascriptNoReserved
|
||||
|
||||
|
||||
" JSX attributes should color as JS. Note the trivial end pattern; we let
|
||||
" jsBlock take care of ending the region.
|
||||
syn region xmlString contained start=+{+ end=++ contains=jsBlock,javascriptBlock
|
||||
|
||||
" JSX child blocks behave just like JSX attributes, except that (a) they are
|
||||
" syntactically distinct, and (b) they need the syn-extend argument, or else
|
||||
" nested XML end-tag patterns may end the outer jsxRegion.
|
||||
syn region jsxChild contained start=+{+ end=++ contains=jsBlock,javascriptBlock
|
||||
\ extend
|
||||
|
||||
" Highlight JSX regions as XML; recursively match.
|
||||
syn region jsxRegion contains=@XMLSyntax,jsxRegion,jsBlock,javascriptBlock
|
||||
\ start=+<\@<!<\z([a-zA-Z][a-zA-Z0-9:\-.]*\)+
|
||||
"
|
||||
" Note that we prohibit JSX tags from having a < or word character immediately
|
||||
" preceding it, to avoid conflicts with, respectively, the left shift operator
|
||||
" and generic Flow type annotations (http://flowtype.org/).
|
||||
syn region jsxRegion
|
||||
\ contains=@XMLSyntax,jsxRegion,jsxChild,jsBlock,javascriptBlock
|
||||
\ start=+\%(<\|\w\)\@<!<\z([a-zA-Z][a-zA-Z0-9:\-.]*\)+
|
||||
\ skip=+<!--\_.\{-}-->+
|
||||
\ end=+</\z1\_\s\{-}>+
|
||||
\ end=+/>+
|
||||
\ keepend
|
||||
\ extend
|
||||
|
||||
" JSX attributes should color as JS. Note the trivial end pattern; we let
|
||||
" jsBlock take care of ending the region.
|
||||
syn region xmlString contained start=+{+ end=++ contains=jsBlock,javascriptBlock
|
||||
|
||||
" Add jsxRegion to the lowest-level JS syntax cluster.
|
||||
syn cluster jsExpression add=jsxRegion
|
||||
|
||||
" Allow jsxRegion to contain reserved words.
|
||||
" See: https://github.com/othree/yajs.vim
|
||||
syn cluster javascriptNoReserved add=jsxRegion
|
||||
|
||||
@ -6,8 +6,24 @@
|
||||
"
|
||||
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
||||
|
||||
exec 'source '.fnameescape(expand('<sfile>:p:h:h').'/jsx-config.vim')
|
||||
" Whether the .jsx extension is required.
|
||||
if !exists('g:jsx_ext_required')
|
||||
let g:jsx_ext_required = 1
|
||||
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
|
||||
" Look for the @jsx pragma. It must be included in a docblock comment before
|
||||
" anything else in the file (except whitespace).
|
||||
let s:jsx_pragma_pattern = '\%^\_s*\/\*\*\%(\_.\%(\*\/\)\@!\)*@jsx\_.\{-}\*\/'
|
||||
let b:jsx_pragma_found = search(s:jsx_pragma_pattern, 'npw')
|
||||
endif
|
||||
|
||||
" Whether to set the JSX filetype on *.js files.
|
||||
fu! <SID>EnableJSX()
|
||||
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
|
||||
Loading…
Reference in New Issue
Block a user