Skip to content

Develop -> Master #395

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 52 commits into from
Apr 25, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
5fea23e
fast attempt for issues with multiple declarations
Apr 1, 2016
2931086
line following arrow indentation
bounceme Apr 10, 2016
6858535
Merge pull request #357 from bounceme/develop
amadeus Apr 11, 2016
7f5c7b8
Merge pull request #367 from bounceme/patch-1
amadeus Apr 11, 2016
f286f94
Fix lambda definitions in class definitions
amadeus Apr 9, 2016
2881bba
Merge pull request #366 from amadeus/arrow-functions-in-class
amadeus Apr 11, 2016
734cdfc
Improve one line scope
bounceme Apr 12, 2016
f13009e
Adding [ and ] to jsFuncArgDestructuring
amadeus Apr 14, 2016
c8ac1c8
Merge pull request #377 from amadeus/add-brackets-to-destructuring
amadeus Apr 18, 2016
17fa18c
simplifies the parentheses handling
bounceme Apr 16, 2016
989deba
Merge pull request #379 from bounceme/patch-11
amadeus Apr 19, 2016
7d371dd
Fixing comments in ES6 Class declarations
amadeus Apr 19, 2016
2adca53
Merge pull request #384 from amadeus/fix-comments-in-class-declaration
amadeus Apr 19, 2016
3208fc5
Operator first support,including ternary,dot etc.
bounceme Apr 20, 2016
dd95ac2
Merge pull request #385 from bounceme/patch-14
amadeus Apr 20, 2016
992b76d
Temporarily disabled jsArrowFuncArgs with parens
amadeus Apr 18, 2016
c4725ca
Merge pull request #380 from amadeus/temporary-fix-for-arrow-func-args
amadeus Apr 20, 2016
16673ac
Adding a license note to the README
amadeus Apr 20, 2016
cc5a971
Merge pull request #387 from amadeus/add-license
amadeus Apr 20, 2016
d388b88
Merge pull request #373 from bounceme/patch-8
amadeus Apr 20, 2016
6cb0c96
old changes reset
Apr 21, 2016
ff62d63
#324
bounceme Apr 21, 2016
5b7445e
Merge pull request #390 from bounceme/patch-16
amadeus Apr 22, 2016
20b0eb6
Merge pull request #370 from bounceme/patch-6
amadeus Apr 22, 2016
b9feef0
Improved lambda argument handling
amadeus Apr 18, 2016
48263c8
Merge pull request #388 from amadeus/lambda-experiments
amadeus Apr 22, 2016
a607a7d
spanning multiple lines detection
bounceme Apr 21, 2016
e9f6a4d
Merge pull request #389 from bounceme/patch-15
amadeus Apr 23, 2016
1da09b6
Move jsDocTag @file to a different jsDocTag group
amadeus Apr 22, 2016
3e13731
Merge pull request #394 from amadeus/fix-341
amadeus Apr 24, 2016
af37b22
[-+] not by another
bounceme Apr 24, 2016
c5250b3
Merge pull request #396 from pangloss/bounceme-patch-1
amadeus Apr 24, 2016
f7cec8c
Fixing bizarre jsDocParam bug
amadeus Apr 22, 2016
c438302
Merge pull request #392 from amadeus/fix-jsdocparam
amadeus Apr 24, 2016
e74d758
Refactored README.md
amadeus Apr 24, 2016
2f0b1d2
Removing deprecated folding logic
amadeus Apr 24, 2016
48067d6
Add code folding documentation
amadeus Apr 24, 2016
a51d0f3
Update javascript.vim
bounceme Apr 24, 2016
af08aae
Merge pull request #398 from amadeus/last-minute-tweaks
amadeus Apr 24, 2016
d7a5869
Merge pull request #399 from pangloss/bounceme-patch-1
amadeus Apr 24, 2016
1c75d8a
Fix JSDoc record matching
amadeus Apr 24, 2016
9ece5d5
Merge pull request #397 from amadeus/fix-jsdoc-records
amadeus Apr 25, 2016
a7f2216
Optimize JSNoise and JSOperator regexes
amadeus Apr 22, 2016
01ecaf9
Removing deprecated selectors
amadeus Apr 22, 2016
f7d2207
Optimized jsGlobalObjects
amadeus Apr 22, 2016
33eb9fe
Optimized jsArrowFuncArgs selector
amadeus Apr 22, 2016
508c1a3
Remove syntax sync clear
amadeus Apr 22, 2016
3a4991e
Improved jsTaggedTemplate performance
amadeus Apr 22, 2016
842b0ce
Improved performance of jsRegexpString
amadeus Apr 22, 2016
c2bc4c7
Limiting jsRegexpString look behinds
amadeus Apr 24, 2016
09fde19
Merge pull request #391 from amadeus/performance-improvements
amadeus Apr 25, 2016
4b6f9c5
Bumping version number to v1.0.0
amadeus Apr 25, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 54 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,68 +1,75 @@
# vim-javascript v0.10.0
# vim-javascript v1.0.0

JavaScript bundle for vim, this bundle provides syntax and indent plugins.
JavaScript bundle for vim, this bundle provides syntax highlighting and
improved indentation.

## A Quick Note on Regexes

Vim 7.4 was released recently, and unfortunately broke how this plugin
handles regexes. There was no real easy way for us to fix this unless we
completely rewrote how regexes work.
## Installation

Good News: There was a recent update to Vim 7.4 that fixes this issue.
### Install with [Vundle](https://github.com/gmarik/vundle)

Make sure you are at least using Vim 7.4, with patches 1-7.
Add to vimrc:

If you are stuck on an older version of Vim 7.4 with no way to update,
then simply perform the following commands to fix your current buffer:
Plugin 'pangloss/vim-javascript'

```
:set regexpengine=1
:syntax enable
```
And install it:

## Installation
:so ~/.vimrc
:PluginInstall

### Install with [Vundle](https://github.com/gmarik/vundle)
### Install with [vim-plug](https://github.com/junegunn/vim-plug)

Add to vimrc:

Plugin 'pangloss/vim-javascript'
Plug 'pangloss/vim-javascript'

And install it:

:so ~/.vimrc
:PluginInstall
:PlugInstall

### Install with [pathogen](https://github.com/tpope/vim-pathogen)

cd ~/.vim/bundle
git clone https://github.com/pangloss/vim-javascript.git

## Configuration

## Configuration Variables

The following variables control certain syntax highlighting features. You can
add them to your `.vimrc` to enable/disable their features.

#### javascript_enable_domhtmlcss
```
let g:javascript_enable_domhtmlcss = 1
```

Enables HTML/CSS syntax highlighting in your JavaScript file.

Default Value: 0

#### b:javascript_fold
-----------------

Enables JavaScript code folding.
```
let g:javascript_ignore_javaScriptdoc = 1
```

Default Value: 1
Disables JSDoc syntax highlighting

Default Value: 0

#### javascript_ignore_javaScriptdoc
-----------------

Disables JSDoc syntax highlighting
```
set foldmethod=syntax
```

Default Value: 0
Enables code folding based on our syntax file.

Please note this can have a dramatic effect on performance and because it is a
global vim option, we do not set it ourselves.

#### Concealing Characters

## Concealing Characters

You can customize concealing characters by defining one or more of the following
variables:
Expand All @@ -78,6 +85,7 @@ variables:
let g:javascript_conceal_super = "Ω"
let g:javascript_conceal_arrow_function = "⇒"


## Contributing

This project uses the [git
Expand All @@ -88,6 +96,24 @@ the price of admission is 1 pull request. Please follow the general code style
guides (read the code) and in your pull request explain the reason for the
proposed change and how it is valuable.

## Bug report

## Bug Reports

Report a bug on [GitHub Issues](https://github.com/pangloss/vim-javascript/issues).


## A Quick Note on Regexes

Vim 7.4 with patches LESS than 1-7 exhibits a bug that broke how we handle
javascript regexes. Please update to a newer version or run the following
commands to fix:

```
:set regexpengine=1
:syntax enable
```


## License

Distributed under the same terms as Vim itself. See `:help license`.
109 changes: 90 additions & 19 deletions indent/javascript.vim
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ endif
let s:js_keywords = '^\s*\(break\|catch\|const\|continue\|debugger\|delete\|do\|else\|finally\|for\|function\|if\|in\|instanceof\|let\|new\|return\|switch\|this\|throw\|try\|typeof\|var\|void\|while\|with\)'
let s:expr_case = '^\s*\(case\s\+[^\:]*\|default\)\s*:\s*'
" Regex of syntax group names that are or delimit string or are comments.
let s:syng_strcom = 'string\|regex\|comment\c'
let s:syng_strcom = '\%(\%(template\)\@<!string\|regex\|comment\)\c'

" Regex of syntax group names that are or delimit template strings
let s:syng_template = 'template\c'

" Regex of syntax group names that are strings.
let s:syng_string = 'regex\c'
Expand All @@ -60,25 +63,24 @@ let s:skip_expr = "synIDattr(synID(line('.'),col('.'),1),'name') =~ '".s:syng_st
let s:line_term = '\s*\%(\%(\/\/\).*\)\=$'

" Regex that defines continuation lines, not including (, {, or [.
let s:continuation_regex = '\%([\\*+/.:]\|\%(<%\)\@<![=-]\|\W[|&?]\|||\|&&\|[^=]=[^=].*,\)' . s:line_term
let s:continuation_regex = '\%([\\*/.:]\|+\@<!+\|-\@<!-\|\%(<%\)\@<!=\|\W[|&?]\|||\|&&\|[^=]=[^=>].*,\)' . s:line_term

" Regex that defines continuation lines.
" TODO: this needs to deal with if ...: and so on
let s:msl_regex = s:continuation_regex.'|'.s:expr_case
let s:msl_regex = s:continuation_regex.'\|'.s:expr_case

let s:one_line_scope_regex = '\%(\<else\>\|\<\%(if\|for\|while\)\>\s*(.*)\)' . s:line_term
let s:one_line_scope_regex = '\%(\%(\<else\>\|\<\%(if\|for\|while\)\>\s*(\%([^()]*\|[^()]*(\%([^()]*\|[^()]*(\%([^()]*\|[^()]*([^()]*)[^()]*\))[^()]*\))[^()]*\))\)\|=>\)' . s:line_term

" Regex that defines blocks.
let s:block_regex = '\%([{[]\)\s*\%(|\%([*@]\=\h\w*,\=\s*\)\%(,\s*[*@]\=\h\w*\)*|\)\=' . s:line_term
let s:block_regex = '\%([{([]\)\s*\%(|\%([*@]\=\h\w*,\=\s*\)\%(,\s*[*@]\=\h\w*\)*|\)\=' . s:line_term

let s:operator_first = '^\s*\%([*/.:?]\|\([-+]\)\1\@!\|||\|&&\)'

let s:var_stmt = '^\s*(const\|let\|var)'
let s:var_stmt = '^\s*\%(const\|let\|var\)'

let s:comma_first = '^\s*,'
let s:comma_last = ',\s*$'

let s:ternary = '^\s\+[?|:]'
let s:ternary_q = '^\s\+?'

let s:case_indent = s:sw()
let s:case_indent_after = s:sw()
let s:m = matchlist(&cinoptions, ':\(.\)')
Expand All @@ -102,6 +104,11 @@ function s:IsInString(lnum, col)
return synIDattr(synID(a:lnum, a:col, 1), 'name') =~ s:syng_string
endfunction

" Check if the character at lnum:col is inside a template string.
function s:IsInTempl(lnum, col)
return synIDattr(synID(a:lnum, a:col, 1), 'name') =~ s:syng_template
endfunction

" Check if the character at lnum:col is inside a multi-line comment.
function s:IsInMultilineComment(lnum, col)
return !s:IsLineComment(a:lnum, a:col) && synIDattr(synID(a:lnum, a:col, 1), 'name') =~ s:syng_multiline
Expand All @@ -120,13 +127,13 @@ function s:PrevNonBlankNonString(lnum)
" Go in and out of blocks comments as necessary.
" If the line isn't empty (with opt. comment) or in a string, end search.
let line = getline(lnum)
if line =~ '/\*'
if s:IsInMultilineComment(lnum, matchend(line, '/\*') - 1)
if in_block
let in_block = 0
else
break
endif
elseif !in_block && line =~ '\*/'
elseif !in_block && s:IsInMultilineComment(lnum, matchend(line, '\*/') - 1)
let in_block = 1
elseif !in_block && line !~ '^\s*\%(//\).*$' && !(s:IsInStringOrComment(lnum, 1) && s:IsInStringOrComment(lnum, strlen(line)))
break
Expand All @@ -146,9 +153,21 @@ function s:GetMSL(lnum, in_one_line_scope)
" Otherwise, terminate search as we have found our MSL already.
let line = getline(lnum)
let col = match(line, s:msl_regex) + 1
let line2 = getline(msl)
let col2 = matchend(line2, ')')
if (col > 0 && !s:IsInStringOrComment(lnum, col)) || s:IsInString(lnum, strlen(line))
let msl = lnum

" if there are more closing brackets, continue from the line which has the matching opening bracket
elseif col2 > 0 && !s:IsInStringOrComment(msl, col2) && s:LineHasOpeningBrackets(msl)[0] == '2' && !a:in_one_line_scope
call cursor(msl, 1)
if searchpair('(', '', ')', 'bW', s:skip_expr) > 0
let lnum = line('.')
let msl = lnum
endif

else

" Don't use lines that are part of a one line scope as msl unless the
" flag in_one_line_scope is set to 1
"
Expand All @@ -159,7 +178,7 @@ function s:GetMSL(lnum, in_one_line_scope)
if msl_one_line == 0
break
endif
endif
end
let lnum = s:PrevNonBlankNonString(lnum - 1)
endwhile
return msl
Expand Down Expand Up @@ -240,7 +259,7 @@ function s:LineHasOpeningBrackets(lnum)
endif
let pos = match(line, '[][(){}]', pos + 1)
endwhile
return (open_0 > 0) . (open_2 > 0) . (open_4 > 0)
return (open_0 > 0 ? 1 : (open_0 == 0 ? 0 : 2)) . (open_2 > 0) . (open_4 > 0)
endfunction

function s:Match(lnum, regex)
Expand Down Expand Up @@ -378,12 +397,45 @@ function GetJavascriptIndent()
return indent(prevline) + s:case_indent_after
endif

if (line =~ s:ternary)
if (getline(prevline) =~ s:ternary_q)
" If line starts with an operator...
if (s:Match(v:lnum, s:operator_first))
if (s:Match(prevline, s:operator_first))
" and so does previous line, don't indent
return indent(prevline)
else
end
let counts = s:LineHasOpeningBrackets(prevline)
if counts[0] == '2'
call cursor(prevline, 1)
" Search for the opening tag
let mnum = searchpair('(', '', ')', 'bW', s:skip_expr)
if mnum > 0 && s:Match(mnum, s:operator_first)
return indent(mnum)
end
elseif counts[0] != '1' && counts[1] != '1' && counts[2] != '1'
" otherwise, indent 1 level
return indent(prevline) + s:sw()
end
" If previous line starts with an operator...
elseif s:Match(prevline, s:operator_first) && !s:Match(prevline, s:comma_last) && !s:Match(prevline, '};\=' . s:line_term)
let counts = s:LineHasOpeningBrackets(prevline)
if counts[0] == '2' && counts[1] == '1'
call cursor(prevline, 1)
" Search for the opening tag
let mnum = searchpair('(', '', ')', 'bW', s:skip_expr)
if mnum > 0 && !s:Match(mnum, s:operator_first)
return indent(mnum) + s:sw()
end
elseif counts[0] != '1' && counts[1] != '1' && counts[2] != '1'
return indent(prevline) - s:sw()
end
end

if getline(prevline) =~ '^\s*`$' && s:IsInTempl(v:lnum, 1)
if line !~ '^\s*`$'
return indent(prevline) + s:sw()
endif
elseif line =~ '^\s*`$' && s:IsInTempl(prevline, 1)
return indent(prevline) - s:sw()
endif

" If we are in a multi-line comment, cindent does the right thing.
Expand Down Expand Up @@ -438,17 +490,36 @@ function GetJavascriptIndent()
if line =~ '[[({]'
let counts = s:LineHasOpeningBrackets(lnum)
if counts[0] == '1' && searchpair('(', '', ')', 'bW', s:skip_expr) > 0
if col('.') + 1 == col('$')
if col('.') + 1 == col('$') || line =~ s:one_line_scope_regex
return ind + s:sw()
else
return virtcol('.')
endif
elseif counts[1] == '1' || counts[2] == '1'
elseif counts[1] == '1' || counts[2] == '1' && counts[0] != '2'
return ind + s:sw()
else
call cursor(v:lnum, vcol)
end
endif
elseif line =~ '.\+};\=' . s:line_term
call cursor(lnum, 1)
" Search for the opening tag
let mnum = searchpair('{', '', '}', 'bW', s:skip_expr)
if mnum > 0
return indent(s:GetMSL(mnum, 0))
end
elseif line =~ '.\+);\=' || line =~ s:comma_last
let counts = s:LineHasOpeningBrackets(lnum)
if counts[0] == '2'
call cursor(lnum, 1)
" Search for the opening tag
let mnum = searchpair('(', '', ')', 'bW', s:skip_expr)
if mnum > 0
return indent(s:GetMSL(mnum, 0))
end
elseif line !~ s:var_stmt
return indent(prevline)
end
end

" 3.4. Work on the MSL line. {{{2
" --------------------------
Expand Down
Loading