Skip to content

Commit c04d099

Browse files
authored
Merge pull request pangloss#501 from pangloss/develop
Develop -> Master
2 parents d70bb4e + f90113a commit c04d099

File tree

6 files changed

+235
-145
lines changed

6 files changed

+235
-145
lines changed

README.md

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,24 +35,37 @@ And install it:
3535

3636
## Configuration Variables
3737

38-
The following variables control certain syntax highlighting features. You can
39-
add them to your `.vimrc` to enable/disable their features.
38+
The following variables control certain syntax highlighting plugins. You can
39+
add them to your `.vimrc` to enable their features.
40+
41+
-----------------
42+
43+
```
44+
let g:javascript_plugin_jsdoc = 1
45+
```
46+
47+
Enables syntax highlighting for [JSDocs](http://usejsdoc.org/).
48+
49+
Default Value: 0
50+
51+
-----------------
4052

4153
```
42-
let g:javascript_enable_domhtmlcss = 1
54+
let g:javascript_plugin_ngdoc = 1
4355
```
4456

45-
Enables HTML/CSS syntax highlighting in your JavaScript file.
57+
Enables some additional syntax highlighting for NGDocs. Requires JSDoc plugin
58+
to be enabled as well.
4659

4760
Default Value: 0
4861

4962
-----------------
5063

5164
```
52-
let g:javascript_ignore_javaScriptdoc = 1
65+
let g:javascript_plugin_flow = 1
5366
```
5467

55-
Disables JSDoc syntax highlighting
68+
Enables syntax highlighting for [Flow](https://flowtype.org/).
5669

5770
Default Value: 0
5871

extras/flow.vim

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
syntax region jsFlowTypeStatement start=/type/ end=/=/ oneline skipwhite skipempty nextgroup=jsFlowTypeObject
2+
syntax region jsFlowDeclareBlock start=/declare/ end=/[;\n]/ oneline contains=jsFlow,jsFlowDeclareKeyword,jsFlowStorageClass
3+
syntax region jsFlow start=/:/ end=/\%(\%([),=;\n]\|{\%(.*}\)\@!\|\%({.*}\)\@<=\s*{\)\@=\|void\)/ contains=@jsFlowCluster oneline skipwhite skipempty nextgroup=jsFuncBlock
4+
syntax region jsFlowReturn contained start=/:/ end=/\%(\S\s*\%({\)\@=\|\n\)/ contains=@jsFlowCluster oneline skipwhite skipempty nextgroup=jsFuncBlock keepend
5+
syntax region jsFlowTypeObject contained start=/{/ end=/}/ skipwhite skipempty nextgroup=jsFunctionBlock extend
6+
syntax region jsFlowObject contained matchgroup=jsFlowNoise start=/{/ end=/}/ oneline contains=@jsFlowCluster
7+
syntax region jsFlowArray contained matchgroup=jsFlowNoise start=/\[/ end=/\]/ oneline contains=@jsFlowCluster
8+
syntax keyword jsFlowDeclareKeyword contained declare
9+
syntax keyword jsFlowType contained boolean number string null void any mixed JSON array function object Array
10+
syntax match jsFlowClassProperty contained /\<[0-9a-zA-Z_$]*\>:\@=/ skipwhite skipempty nextgroup=jsFlow
11+
syntax match jsFlowNoise contained /[:;,<>]/
12+
syntax cluster jsFlowCluster contains=jsFlowType,jsFlowArray,jsFlowObject,jsFlowNoise
13+
syntax keyword jsFlowStorageClass contained const var let
14+
syntax region jsFlowParenRegion contained start=/:\s*(/ end=/)\%(\s*:\)\@=/ oneline contains=@jsFlowCluster skipwhite skipempty nextgroup=jsObjectValue
15+
syntax region jsFlowClass contained matchgroup=jsFlowNoise start=/</ end=/>/ oneline contains=@jsFlowCluster skipwhite skipempty nextgroup=jsClassBlock
16+
17+
if version >= 508 || !exists("did_javascript_syn_inits")
18+
if version < 508
19+
let did_javascript_syn_inits = 1
20+
command -nargs=+ HiLink hi link <args>
21+
else
22+
command -nargs=+ HiLink hi def link <args>
23+
endif
24+
HiLink jsFlow PreProc
25+
HiLink jsFlowReturn PreProc
26+
HiLink jsFlowArray PreProc
27+
HiLink jsFlowDeclareBlock PreProc
28+
HiLink jsFlowObject PreProc
29+
HiLink jsFlowParenRegion PreProc
30+
HiLink jsFlowClass PreProc
31+
HiLink jsFlowClassProperty jsClassProperty
32+
HiLink jsFlowType Type
33+
HiLink jsFlowDeclareKeyword Type
34+
HiLink jsFlowNoise Noise
35+
delcommand HiLink
36+
endif

extras/jsdoc.vim

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
"" syntax coloring for javadoc comments (HTML)
2+
syntax region jsComment matchgroup=jsComment start="/\*\s*" end="\*/" contains=jsDocTags,jsCommentTodo,jsCvsTag,@jsHtml,@Spell fold
3+
4+
" tags containing a param
5+
syntax match jsDocTags contained "@\(alias\|api\|augments\|borrows\|class\|constructs\|default\|defaultvalue\|emits\|exception\|exports\|extends\|fires\|kind\|link\|listens\|member\|member[oO]f\|mixes\|module\|name\|namespace\|requires\|template\|throws\|var\|variation\|version\)\>" skipwhite nextgroup=jsDocParam
6+
" tags containing type and param
7+
syntax match jsDocTags contained "@\(arg\|argument\|cfg\|param\|property\|prop\)\>" skipwhite nextgroup=jsDocType
8+
" tags containing type but no param
9+
syntax match jsDocTags contained "@\(callback\|define\|enum\|external\|implements\|this\|type\|typedef\|return\|returns\)\>" skipwhite nextgroup=jsDocTypeNoParam
10+
" tags containing references
11+
syntax match jsDocTags contained "@\(lends\|see\|tutorial\)\>" skipwhite nextgroup=jsDocSeeTag
12+
" other tags (no extra syntax)
13+
syntax match jsDocTags contained "@\(abstract\|access\|accessor\|author\|classdesc\|constant\|const\|constructor\|copyright\|deprecated\|desc\|description\|dict\|event\|example\|file\|file[oO]verview\|final\|function\|global\|ignore\|inheritDoc\|inner\|instance\|interface\|license\|localdoc\|method\|mixin\|nosideeffects\|override\|overview\|preserve\|private\|protected\|public\|readonly\|since\|static\|struct\|todo\|summary\|undocumented\|virtual\)\>"
14+
15+
syntax region jsDocType contained matchgroup=jsDocTypeBrackets start="{" end="}" contains=jsDocTypeRecord oneline skipwhite nextgroup=jsDocParam
16+
syntax match jsDocType contained "\%(#\|\"\|\w\|\.\|:\|\/\)\+" skipwhite nextgroup=jsDocParam
17+
syntax region jsDocTypeRecord contained start=/{/ end=/}/ contains=jsDocTypeRecord extend
18+
syntax region jsDocTypeRecord contained start=/\[/ end=/\]/ contains=jsDocTypeRecord extend
19+
syntax region jsDocTypeNoParam contained start="{" end="}" oneline
20+
syntax match jsDocTypeNoParam contained "\%(#\|\"\|\w\|\.\|:\|\/\)\+"
21+
syntax match jsDocParam contained "\%(#\|\$\|-\|'\|\"\|{.\{-}}\|\w\|\.\|:\|\/\|\[.{-}]\|=\)\+"
22+
syntax region jsDocSeeTag contained matchgroup=jsDocSeeTag start="{" end="}" contains=jsDocTags
23+
24+
if version >= 508 || !exists("did_javascript_syn_inits")
25+
if version < 508
26+
let did_javascript_syn_inits = 1
27+
command -nargs=+ HiLink hi link <args>
28+
else
29+
command -nargs=+ HiLink hi def link <args>
30+
endif
31+
HiLink jsDocTags Special
32+
HiLink jsDocSeeTag Function
33+
HiLink jsDocType Type
34+
HiLink jsDocTypeBrackets jsDocType
35+
HiLink jsDocTypeRecord jsDocType
36+
HiLink jsDocTypeNoParam Type
37+
HiLink jsDocParam Label
38+
delcommand HiLink
39+
endif

extras/ngdoc.vim

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
syntax match jsDocTags contained /@\(link\|method[oO]f\|ngdoc\|ng[iI]nject\|restrict\)/ nextgroup=jsDocParam skipwhite
2+
syntax match jsDocType contained "\%(#\|\$\|\w\|\"\|-\|\.\|:\|\/\)\+" nextgroup=jsDocParam skipwhite
3+
syntax match jsDocParam contained "\%(#\|\$\|\w\|\"\|-\|\.\|:\|{\|}\|\/\|\[\|]\|=\)\+"

indent/javascript.vim

Lines changed: 73 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ setlocal nosmartindent
1717
setlocal indentexpr=GetJavascriptIndent()
1818
setlocal formatexpr=Fixedgq(v:lnum,v:count)
1919
setlocal indentkeys=0{,0},0),0],0\,*<Return>,:,!^F,o,O,e
20-
setlocal cinoptions+=j1,J1
20+
setlocal cinoptions+=j1,J1,c1
2121

2222
" Only define the function once.
2323
if exists("*GetJavascriptIndent")
@@ -140,7 +140,7 @@ function s:GetMSL(lnum, in_one_line_scope)
140140
" Start on the line we're at and use its indent.
141141
let msl = a:lnum
142142
let lnum = s:PrevNonBlankNonString(a:lnum - 1)
143-
while lnum > 0
143+
while lnum > 0 && !s:Match(msl,s:line_pre . '[])}]')
144144
" If we have a continuation line, or we're in a string, use line as MSL.
145145
" Otherwise, terminate search as we have found our MSL already.
146146
let line = getline(lnum)
@@ -312,6 +312,7 @@ function GetJavascriptIndent()
312312
" 3.1. Setup {{{1
313313
" ----------
314314
" Set up variables for restoring position in file. Could use v:lnum here.
315+
" Avoid use of line('.')/col('.') type functions as the curpos can change
315316
let vcol = col('.')
316317

317318
" 3.2. Work on the current line {{{1
@@ -334,7 +335,7 @@ function GetJavascriptIndent()
334335
if line !~ '^\%(\/\*\|\s*\/\/\)' && s:IsInComment(v:lnum, 1)
335336
return cindent(v:lnum)
336337
endif
337-
338+
338339
" single opening bracket will assume you want a c style of indenting
339340
if s:Match(v:lnum, s:line_pre . '{' . s:line_term) && !s:Match(lnum,s:block_regex) &&
340341
\ !s:Match(lnum,s:comma_last)
@@ -343,7 +344,11 @@ function GetJavascriptIndent()
343344

344345
" cindent each line which has a switch label
345346
if (line =~ s:expr_case)
346-
return cindent(v:lnum)
347+
let s:cpo_switch = &cpo
348+
set cpo+=%
349+
let ind = cindent(v:lnum)
350+
let &cpo = s:cpo_switch
351+
return ind
347352
endif
348353

349354
" If we got a closing bracket on an empty line, find its match and indent
@@ -359,8 +364,8 @@ function GetJavascriptIndent()
359364
continue
360365
end
361366
if parlnum > 0
362-
let ind = s:InMultiVarStatement(parlnum, 0, 0)|| s:LineHasOpeningBrackets(parlnum) !~ '2'
363-
\ ? indent(parlnum) : indent(s:GetMSL(parlnum, 0))
367+
let ind = s:InMultiVarStatement(parlnum, 0, 0)|| s:LineHasOpeningBrackets(parlnum) !~ '2' ?
368+
\ indent(parlnum) : indent(s:GetMSL(parlnum, 0))
364369
endif
365370
endwhile
366371
return ind
@@ -369,7 +374,8 @@ function GetJavascriptIndent()
369374

370375
" If line starts with an operator...
371376
if (line =~ s:operator_first)
372-
if (s:Match(lnum, s:operator_first) || s:Match(lnum, s:line_pre . '[])}]'))
377+
if (s:Match(lnum, s:operator_first) || (s:Match(lnum, s:line_pre . '[])}]') &&
378+
\ !(s:Match(v:lnum,s:line_pre . '\.') && s:Match(lnum, ')' . s:line_term))))
373379
" and so does previous line, don't indent
374380
return indent(lnum)
375381
end
@@ -411,7 +417,7 @@ function GetJavascriptIndent()
411417
" If the line is empty and the previous nonblank line was a multi-line
412418
" comment, use that comment's indent. Deduct one char to account for the
413419
" space in ' */'.
414-
if line =~ '^\s*$' && getline(prevline) !~ '\%(\%(^\s*\/\/\|\/\*\).*\)\@<!\*\/' &&
420+
if line =~ '^\s*$' && getline(prevline) =~ '\%(\%(^\s*\/\/\|\/\*\).*\)\@<!\*\/' &&
415421
\ s:IsInComment(prevline, 1)
416422
return indent(prevline) - 1
417423
endif
@@ -428,16 +434,16 @@ function GetJavascriptIndent()
428434
return 0
429435
endif
430436

431-
" foo('foo',
432-
" bar('bar', function() {
433-
" hi();
434-
" })
435-
" );
437+
" foo('foo',
438+
" bar('bar', function() {
439+
" hi();
440+
" })
441+
" );
436442

437-
" function (a, b, c, d,
438-
" e, f, g) {
439-
" console.log('inner');
440-
" }
443+
" function (a, b, c, d,
444+
" e, f, g) {
445+
" console.log('inner');
446+
" }
441447
" If the previous line ended with a block opening, add a level of indent.
442448
if s:Match(lnum, s:block_regex)
443449
return s:InMultiVarStatement(lnum, 0, 0) || s:LineHasOpeningBrackets(lnum) !~ '2' ?
@@ -449,15 +455,16 @@ function GetJavascriptIndent()
449455
let ind = indent(lnum)
450456
" If the previous line contained an opening bracket, and we are still in it,
451457
" add indent depending on the bracket type.
452-
if s:Match(lnum, '\%([[({]\)\|\%([^\t \])}][})\]]\)')
458+
if s:Match(lnum, '[[({})\]]')
453459
let counts = s:LineHasOpeningBrackets(lnum)
454460
if counts =~ '2'
455-
call cursor(lnum,matchend(s:RemoveTrailingComments(line), '.\+\zs[])}]'))
461+
call cursor(lnum,matchend(s:RemoveTrailingComments(line), '.*\zs[])}]'))
456462
while s:lookForParens('(\|{\|\[', ')\|}\|\]', 'bW', 0) == lnum
457463
call cursor(lnum, matchend(s:RemoveTrailingComments(strpart(line,0,col('.'))), '.*\zs[])}]'))
458464
endwhile
459-
if line('.') < lnum && !s:InMultiVarStatement(line('.'),0,0)
460-
return indent(s:GetMSL(line('.'), 0))
465+
let cur = line('.')
466+
if cur < lnum && !s:InMultiVarStatement(cur,0,0)
467+
return indent(s:GetMSL(cur, 0))
461468
end
462469
elseif counts =~ '1' || s:Onescope(lnum)
463470
return ind + s:sw()
@@ -500,64 +507,64 @@ let &cpo = s:cpo_save
500507
unlet s:cpo_save
501508
" gq{{{2
502509
function! Fixedgq(lnum, count)
503-
let l:tw = &tw ? &tw : 80;
510+
let l:tw = &tw ? &tw : 80;
504511

505-
let l:count = a:count
506-
let l:first_char = indent(a:lnum) + 1
512+
let l:count = a:count
513+
let l:first_char = indent(a:lnum) + 1
507514

508-
if mode() == 'i' " gq was not pressed, but tw was set
509-
return 1
510-
endif
515+
if mode() == 'i' " gq was not pressed, but tw was set
516+
return 1
517+
endif
511518

512-
" This gq is only meant to do code with strings, not comments
513-
if s:IsInComment(a:lnum, l:first_char)
514-
return 1
515-
endif
519+
" This gq is only meant to do code with strings, not comments
520+
if s:IsInComment(a:lnum, l:first_char)
521+
return 1
522+
endif
516523

517-
if len(getline(a:lnum)) < l:tw && l:count == 1 " No need for gq
518-
return 1
519-
endif
524+
if len(getline(a:lnum)) < l:tw && l:count == 1 " No need for gq
525+
return 1
526+
endif
520527

521-
" Put all the lines on one line and do normal spliting after that
522-
if l:count > 1
523-
while l:count > 1
524-
let l:count -= 1
525-
normal J
526-
endwhile
527-
endif
528+
" Put all the lines on one line and do normal spliting after that
529+
if l:count > 1
530+
while l:count > 1
531+
let l:count -= 1
532+
normal J
533+
endwhile
534+
endif
528535

529-
let l:winview = winsaveview()
536+
let l:winview = winsaveview()
530537

531-
call cursor(a:lnum, l:tw + 1)
532-
let orig_breakpoint = searchpairpos(' ', '', '\.', 'bcW', '', a:lnum)
533-
call cursor(a:lnum, l:tw + 1)
534-
let breakpoint = searchpairpos(' ', '', '\.', 'bcW', s:skip_expr, a:lnum)
538+
call cursor(a:lnum, l:tw + 1)
539+
let orig_breakpoint = searchpairpos(' ', '', '\.', 'bcW', '', a:lnum)
540+
call cursor(a:lnum, l:tw + 1)
541+
let breakpoint = searchpairpos(' ', '', '\.', 'bcW', s:skip_expr, a:lnum)
535542

536-
" No need for special treatment, normal gq handles edgecases better
537-
if breakpoint[1] == orig_breakpoint[1]
538-
call winrestview(l:winview)
539-
return 1
540-
endif
543+
" No need for special treatment, normal gq handles edgecases better
544+
if breakpoint[1] == orig_breakpoint[1]
545+
call winrestview(l:winview)
546+
return 1
547+
endif
541548

542-
" Try breaking after string
543-
if breakpoint[1] <= indent(a:lnum)
544-
call cursor(a:lnum, l:tw + 1)
545-
let breakpoint = searchpairpos('\.', '', ' ', 'cW', s:skip_expr, a:lnum)
546-
endif
549+
" Try breaking after string
550+
if breakpoint[1] <= indent(a:lnum)
551+
call cursor(a:lnum, l:tw + 1)
552+
let breakpoint = searchpairpos('\.', '', ' ', 'cW', s:skip_expr, a:lnum)
553+
endif
547554

548555

549-
if breakpoint[1] != 0
550-
call feedkeys("r\<CR>")
551-
else
552-
let l:count = l:count - 1
553-
endif
556+
if breakpoint[1] != 0
557+
call feedkeys("r\<CR>")
558+
else
559+
let l:count = l:count - 1
560+
endif
554561

555-
" run gq on new lines
556-
if l:count == 1
557-
call feedkeys("gqq")
558-
endif
562+
" run gq on new lines
563+
if l:count == 1
564+
call feedkeys("gqq")
565+
endif
559566

560-
return 0
567+
return 0
561568
endfunction
562569
"}}}
563570
" vim: foldmethod=marker:foldlevel=1

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy