summaryrefslogtreecommitdiffstats
path: root/after
diff options
context:
space:
mode:
authorAdam Stankiewicz <sheerun@sher.pl>2016-07-30 13:18:40 +0200
committerAdam Stankiewicz <sheerun@sher.pl>2016-07-30 13:18:40 +0200
commit81deccef65e6dd8fe145cd5fb8fd349db3b28192 (patch)
tree866fd3a1c463e02afc6cd5240691c35d09f836b3 /after
parent3019afa721b893ebfe130eb4f955bc4c0c20ec23 (diff)
downloadvim-polyglot-2.12.1.tar.gz
vim-polyglot-2.12.1.zip
Updatev2.12.1
Diffstat (limited to 'after')
-rw-r--r--after/ftplugin/javascript.vim12
-rw-r--r--after/ftplugin/jsx.vim1
-rw-r--r--after/indent/jsx.vim55
-rw-r--r--after/syntax/jsx.vim2
4 files changed, 52 insertions, 18 deletions
diff --git a/after/ftplugin/javascript.vim b/after/ftplugin/javascript.vim
new file mode 100644
index 00000000..e5324c1b
--- /dev/null
+++ b/after/ftplugin/javascript.vim
@@ -0,0 +1,12 @@
+if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'javascript') == -1
+
+" Vim filetype plugin file
+" Language: JavaScript
+" Maintainer: vim-javascript community
+" URL: https://github.com/pangloss/vim-javascript
+
+setlocal iskeyword+=$ suffixesadd+=.js
+
+let b:undo_ftplugin .= ' | setlocal iskeyword< suffixesadd<'
+
+endif
diff --git a/after/ftplugin/jsx.vim b/after/ftplugin/jsx.vim
index 76b0a327..fc76b19e 100644
--- a/after/ftplugin/jsx.vim
+++ b/after/ftplugin/jsx.vim
@@ -5,7 +5,6 @@ if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'jsx') == -1
"
" Language: JSX (JavaScript)
" Maintainer: Max Wang <mxawng@gmail.com>
-" Depends: pangloss/vim-javascript
"
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
diff --git a/after/indent/jsx.vim b/after/indent/jsx.vim
index e5fdb45d..dc244d81 100644
--- a/after/indent/jsx.vim
+++ b/after/indent/jsx.vim
@@ -5,10 +5,12 @@ if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'jsx') == -1
"
" Language: JSX (JavaScript)
" Maintainer: Max Wang <mxawng@gmail.com>
-" Depends: pangloss/vim-javascript
"
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
+" Save the current JavaScript indentexpr.
+let b:jsx_js_indentexpr = &indentexpr
+
" Prologue; load in XML indentation.
if exists('b:did_indent')
let s:did_indent=b:did_indent
@@ -51,19 +53,31 @@ fu! SynXMLish(syns)
return SynAttrXMLish(get(a:syns, -1))
endfu
-" Check if a synstack has any XMLish attribute.
-fu! SynXMLishAny(syns)
- for synattr in a:syns
- if SynAttrXMLish(synattr)
- return 1
- endif
- endfor
- return 0
-endfu
-
" Check if a synstack denotes the end of a JSX block.
fu! SynJSXBlockEnd(syns)
- return get(a:syns, -1) == 'jsBraces' && SynAttrXMLish(get(a:syns, -2))
+ return get(a:syns, -1) =~ '\%(js\|javascript\)Braces' &&
+ \ SynAttrXMLish(get(a:syns, -2))
+endfu
+
+" Determine how many jsxRegions deep a synstack is.
+fu! SynJSXDepth(syns)
+ return len(filter(copy(a:syns), 'v:val ==# "jsxRegion"'))
+endfu
+
+" Check whether `cursyn' continues the same jsxRegion as `prevsyn'.
+fu! SynJSXContinues(cursyn, prevsyn)
+ let curdepth = SynJSXDepth(a:cursyn)
+ let prevdepth = SynJSXDepth(a:prevsyn)
+
+ " In most places, we expect the nesting depths to be the same between any
+ " two consecutive positions within a jsxRegion (e.g., between a parent and
+ " child node, between two JSX attributes, etc.). The exception is between
+ " sibling nodes, where after a completed element (with depth N), we return
+ " to the parent's nesting (depth N - 1). This case is easily detected,
+ " since it is the only time when the top syntax element in the synstack is
+ " jsxRegion---specifically, the jsxRegion corresponding to the parent.
+ return prevdepth == curdepth ||
+ \ (prevdepth == curdepth + 1 && get(a:cursyn, -1) ==# 'jsxRegion')
endfu
" Cleverly mix JS and XML indentation.
@@ -71,9 +85,12 @@ fu! GetJsxIndent()
let cursyn = SynSOL(v:lnum)
let prevsyn = SynEOL(v:lnum - 1)
- " Use XML indenting if the syntax at the end of the previous line was either
- " JSX or was the closing brace of a jsBlock whose parent syntax was JSX.
- if (SynXMLish(prevsyn) || SynJSXBlockEnd(prevsyn)) && SynXMLishAny(cursyn)
+ " Use XML indenting iff:
+ " - the syntax at the end of the previous line was either JSX or was the
+ " closing brace of a jsBlock whose parent syntax was JSX; and
+ " - the current line continues the same jsxRegion as the previous line.
+ if (SynXMLish(prevsyn) || SynJSXBlockEnd(prevsyn)) &&
+ \ SynJSXContinues(cursyn, prevsyn)
let ind = XmlIndentGet(v:lnum, 0)
" Align '/>' and '>' with '<' for multiline tags.
@@ -86,7 +103,13 @@ fu! GetJsxIndent()
let ind = ind + &sw
endif
else
- let ind = GetJavascriptIndent()
+ if len(b:jsx_js_indentexpr)
+ " Invoke the base JS package's custom indenter. (For vim-javascript,
+ " e.g., this will be GetJavascriptIndent().)
+ let ind = eval(b:jsx_js_indentexpr)
+ else
+ let ind = cindent(v:lnum)
+ endif
endif
return ind
diff --git a/after/syntax/jsx.vim b/after/syntax/jsx.vim
index de544a37..a8ca0aea 100644
--- a/after/syntax/jsx.vim
+++ b/after/syntax/jsx.vim
@@ -48,7 +48,7 @@ syn region jsxChild contained start=+{+ end=++ contains=jsBlock,javascriptBlock
" 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
+ \ contains=@Spell,@XMLSyntax,jsxRegion,jsxChild,jsBlock,javascriptBlock
\ start=+\%(<\|\w\)\@<!<\z([a-zA-Z][a-zA-Z0-9:\-.]*\)+
\ skip=+<!--\_.\{-}-->+
\ end=+</\z1\_\s\{-}>+