From 1e5cbd4caa32d1730df2a81b77da06397140506c Mon Sep 17 00:00:00 2001 From: Arjan van der Gaag Date: Thu, 26 Feb 2015 15:51:52 +0100 Subject: [PATCH] Squashed 'home/.vim/bundle/vim-jsx/' changes from d6bb935..efb24f4 efb24f4 Merge pull request #24 from ingara/master faf509a Escape filename when sourcing config file e7784d1 Fix ext detection in syntax 6118a4d Enable JSX syntax/indent for .jsx files git-subtree-dir: home/.vim/bundle/vim-jsx git-subtree-split: efb24f487f4a61f9113fa4b2b64fe3ab5a030500 --- README.md | 15 +++++++++++++++ after/ftdetect/javascript.vim | 10 ++++++++++ after/indent/javascript.vim | 7 +++++-- after/{jsx-pragma.vim => jsx-config.vim} | 15 +++++++++++---- after/syntax/javascript.vim | 7 +++++-- 5 files changed, 46 insertions(+), 8 deletions(-) create mode 100644 after/ftdetect/javascript.vim rename after/{jsx-pragma.vim => jsx-config.vim} (64%) diff --git a/README.md b/README.md index 311454f..9362651 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,21 @@ 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]. +Usage +----- + +By default, JSX syntax highlighting and indenting will be enabled only for +files with the `.jsx` extension. If you would like JSX in `.js` files, add + + let g:jsx_ext_required = 0 + +to your .vimrc or somewhere in your include path. If you wish to restrict JSX +to files with the pre-v0.12 `@jsx React.DOM` pragma, add + + let g:jsx_pragma_required = 1 + +to your .vimrc or somewhere in your include path. + Installation ------------ diff --git a/after/ftdetect/javascript.vim b/after/ftdetect/javascript.vim new file mode 100644 index 0000000..7cd1f9d --- /dev/null +++ b/after/ftdetect/javascript.vim @@ -0,0 +1,10 @@ +""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" +" Vim ftdetect file +" +" Language: JSX (JavaScript) +" Maintainer: Max Wang +" +""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" + +autocmd BufNewFile,BufRead *.jsx let b:jsx_ext_found = 1 +autocmd BufNewFile,BufRead *.jsx set filetype=javascript diff --git a/after/indent/javascript.vim b/after/indent/javascript.vim index 2507fdc..d0b4d4e 100644 --- a/after/indent/javascript.vim +++ b/after/indent/javascript.vim @@ -7,10 +7,13 @@ " """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" -" Do nothing if we don't find the @jsx pragma. -exec 'source '.expand(':p:h:h').'/jsx-pragma.vim' +" Do nothing if we don't find the @jsx pragma (and we care). +exec 'source '.fnameescape(expand(':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 diff --git a/after/jsx-pragma.vim b/after/jsx-config.vim similarity index 64% rename from after/jsx-pragma.vim rename to after/jsx-config.vim index e230966..a1d4cbe 100644 --- a/after/jsx-pragma.vim +++ b/after/jsx-config.vim @@ -1,8 +1,10 @@ """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " Vimscript file " -" Check whether or not the @jsx pragma is correctly included in '%'. -" Set the result in b:jsx_pragma_found. +" 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 @@ -14,9 +16,14 @@ 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 = 1 +if !exists('g:jsx_pragma_required') + let g:jsx_pragma_required = 0 endif if !g:jsx_pragma_required | finish | endif diff --git a/after/syntax/javascript.vim b/after/syntax/javascript.vim index b76de9a..5bebc94 100644 --- a/after/syntax/javascript.vim +++ b/after/syntax/javascript.vim @@ -9,10 +9,13 @@ " """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" -" Do nothing if we don't find the @jsx pragma. -exec 'source '.expand(':p:h:h').'/jsx-pragma.vim' +" Do nothing if we don't find the @jsx pragma (and we care). +exec 'source '.fnameescape(expand(':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