Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

better javascript (still not ideal, but meh)

  • Loading branch information...
commit dddc9b6b77415f252d80f833add8e92d910e7c69 1 parent 61cec1e
@isaacs authored
Showing with 43 additions and 36 deletions.
  1. +4 −6 indent/javascript.vim
  2. +39 −30 syntax/javascript.vim
View
10 indent/javascript.vim
@@ -33,15 +33,13 @@ set cpo&vim
" ============
" Regex of syntax group names that are or delimit string or are comments.
-let s:syng_strcom = '\<javaScript\%(RegexpString\|CommentTodo\|LineComment\|Comment\|DocComment\)\>'
+let s:syng_strcom = 'javaScript\%(String\|RegexpString\|CommentTodo\|LineComment\|Comment\|DocComment\)'
" Regex of syntax group names that are strings.
-let s:syng_string =
- \ '\<javaScript\%(RegexpString\)\>'
+let s:syng_string = 'javaScript\%(RegexpString\)'
" Regex of syntax group names that are strings or documentation.
-let s:syng_stringdoc =
- \'\<javaScriptDocComment\>'
+let s:syng_stringdoc = 'javaScriptDocComment'
" Expression used to check whether we should skip a match with searchpair().
let s:skip_expr = "synIDattr(synID(line('.'),col('.'),1),'name') =~ '".s:syng_strcom."'"
@@ -167,7 +165,7 @@ function s:IndentWithContinuation(lnum, ind, width)
" TODO: the || s:IsInString() thing worries me a bit.
if p_lnum != lnum
if s:Match(p_lnum,s:continuation_regex)||s:IsInString(p_lnum,strlen(line))
- return a:ind + a:width
+ return a:ind
endif
endif
View
69 syntax/javascript.vim
@@ -1,10 +1,10 @@
" Vim syntax file
" Language: JavaScript
" Maintainer: Yi Zhao (ZHAOYI) <zzlinux AT hotmail DOT com>
-" Last Change By: Darrick Wiebe
-" Last Change: August 25, 2010
-" Version: 0.7.8
-" Changes: Disambiguate regex strings and mathematical statements
+" Last Change By: Marc Harter
+" Last Change: February 18, 2011
+" Version: 0.7.9
+" Changes: Updates JSDoc syntax
"
" TODO:
" - Add the HTML syntax inside the JSDoc
@@ -19,10 +19,10 @@ if !exists("main_syntax")
endif
"" Drop fold if it set but VIM doesn't support it.
-"let b:javascript_fold='true'
-"if version < 600 " Don't support the old version
-" unlet! b:javascript_fold
-"endif
+let b:javascript_fold='true'
+if version < 600 " Don't support the old version
+ unlet! b:javascript_fold
+endif
"" dollar sigh is permittd anywhere in an identifier
setlocal iskeyword+=$
@@ -32,11 +32,12 @@ syntax sync fromstart
"" JavaScript comments
syntax keyword javaScriptCommentTodo TODO FIXME XXX TBD contained
syntax region javaScriptLineComment start=+\/\/+ end=+$+ keepend contains=javaScriptCommentTodo,@Spell
+syntax region javaScriptEnvComment start="\%^#!" end="$" display
syntax region javaScriptLineComment start=+^\s*\/\/+ skip=+\n\s*\/\/+ end=+$+ keepend contains=javaScriptCommentTodo,@Spell fold
syntax region javaScriptCvsTag start="\$\cid:" end="\$" oneline contained
syntax region javaScriptComment start="/\*" end="\*/" contains=javaScriptCommentTodo,javaScriptCvsTag,@Spell fold
-"" JSDoc support start
+"" JSDoc / JSDoc Toolkit
if !exists("javascript_ignore_javaScriptdoc")
syntax case ignore
@@ -44,11 +45,23 @@ if !exists("javascript_ignore_javaScriptdoc")
"syntax include @javaHtml <sfile>:p:h/html.vim
"unlet b:current_syntax
- syntax region javaScriptDocComment matchgroup=javaScriptComment start="/\*\*\s*$" end="\*/" contains=javaScriptDocTags,javaScriptCommentTodo,javaScriptCvsTag,@javaScriptHtml,@Spell fold
- syntax match javaScriptDocTags contained "@\(param\|argument\|requires\|exception\|throws\|type\|class\|extends\|see\|link\|member\|module\|method\|title\|namespace\|optional\|default\|base\|file\)\>" nextgroup=javaScriptDocParam,javaScriptDocSeeTag skipwhite
- syntax match javaScriptDocTags contained "@\(beta\|deprecated\|description\|fileoverview\|author\|license\|version\|returns\=\|constructor\|private\|protected\|final\|ignore\|addon\|exec\)\>"
- syntax match javaScriptDocParam contained "\%(#\|\w\|\.\|:\|\/\)\+"
- syntax region javaScriptDocSeeTag contained matchgroup=javaScriptDocSeeTag start="{" end="}" contains=javaScriptDocTags
+ syntax region javaScriptDocComment matchgroup=javaScriptComment start="/\*\*\s*" end="\*/" contains=javaScriptDocTags,javaScriptCommentTodo,javaScriptCvsTag,@javaScriptHtml,@Spell fold
+
+ " tags containing a param
+ syntax match javaScriptDocTags contained "@\(augments\|base\|borrows\|class\|constructs\|default\|exception\|exports\|extends\|file\|member\|memberOf\|module\|name\|namespace\|optional\|requires\|title\|throws\|version\)\>" nextgroup=javaScriptDocParam skipwhite
+ " tags containing type and param
+ syntax match javaScriptDocTags contained "@\(argument\|param\|property\)\>" nextgroup=javaScriptDocType skipwhite
+ " tags containing type but no param
+ syntax match javaScriptDocTags contained "@\(type\|return\|returns\)\>" nextgroup=javaScriptDocTypeNoParam skipwhite
+ " tags containing references
+ syntax match javaScriptDocTags contained "@\(lends\|link\|see\)\>" nextgroup=javaScriptDocSeeTag skipwhite
+ " other tags (no extra syntax)
+ syntax match javaScriptDocTags contained "@\(access\|addon\|alias\|author\|beta\|constant\|constructor\|copyright\|deprecated\|description\|event\|example\|exec\|field\|fileOverview\|fileoverview\|function\|global\|ignore\|inner\|license\|overview\|private\|protected\|project\|public\|readonly\|since\|static\)\>"
+
+ syntax match javaScriptDocType contained "\%(#\|\"\|{\|}\|\w\|\.\|:\|\/\)\+" nextgroup=javaScriptDocParam skipwhite
+ syntax match javaScriptDocTypeNoParam contained "\%(#\|\"\|{\|}\|\w\|\.\|:\|\/\)\+"
+ syntax match javaScriptDocParam contained "\%(#\|\"\|{\|}\|\w\|\.\|:\|\/\)\+"
+ syntax region javaScriptDocSeeTag contained matchgroup=javaScriptDocSeeTag start="{" end="}" contains=javaScriptDocTags
syntax case match
endif "" JSDoc end
@@ -59,7 +72,8 @@ syntax case match
syntax match javaScriptSpecial "\\\d\d\d\|\\x\x\{2\}\|\\u\x\{4\}\|\\."
syntax region javaScriptStringD start=+"+ skip=+\\\\\|\\$"+ end=+"+ contains=javaScriptSpecial,@htmlPreproc
syntax region javaScriptStringS start=+'+ skip=+\\\\\|\\$'+ end=+'+ contains=javaScriptSpecial,@htmlPreproc
-syntax region javaScriptRegexpString start=+\(\([)\]"']\|\d\|\w\)\s*\)\@<!/\(\*\|/\)\@!+ skip=+\\\\\|\\/+ end=+/[gim]\{,3}+ contains=javaScriptSpecial,@htmlPreproc oneline
+syntax region javaScriptRegexpCharClass start=+\[\]\|\[^\]\|\[+ end=+\]+ contained
+syntax region javaScriptRegexpString start=+\(\(\(return\|case\)\s\+\)\@<=\|\(\([)\]"']\|\d\|\w\)\s*\)\@<!\)/\(\*\|/\)\@!+ skip=+\\\\\|\\/+ end=+/[gim]\{,3}+ contains=javaScriptSpecial,javaScriptRegexpCharClass,@htmlPreproc oneline
syntax match javaScriptNumber /\<-\=\d\+L\=\>\|\<0[xX]\x\+\>/
syntax match javaScriptFloat /\<-\=\%(\d\+\.\d\+\|\d\+\.\|\.\d\+\)\%([eE][+-]\=\d\+\)\=\>/
syntax match javaScriptLabel /\(?\s*\)\@<!\<\w\+\(\s*:\)\@=/
@@ -69,10 +83,11 @@ syntax keyword javaScriptPrototype prototype
"" Programm Keywords
syntax keyword javaScriptSource import export
-syntax keyword javaScriptType const this undefined var void yield
+syntax keyword javaScriptType const undefined var void yield
syntax keyword javaScriptOperator delete new in instanceof let typeof
syntax keyword javaScriptBoolean true false
syntax keyword javaScriptNull null
+syntax keyword javaScriptThis this
"" Statement Keywords
syntax keyword javaScriptConditional if else
@@ -84,7 +99,7 @@ syntax keyword javaScriptGlobalObjects Array Boolean Date Function Infinity Jav
syntax keyword javaScriptExceptions Error EvalError RangeError ReferenceError SyntaxError TypeError URIError
-syntax keyword javaScriptFutureKeys abstract enum int short boolean export interface static byte extends long super char final native synchronized class float package throws const goto private transient debugger implements protected volatile double import public
+syntax keyword javaScriptFutureKeys abstract enum int short boolean export interface static byte extends long super char final native synchronized class float package throws goto private transient debugger implements protected volatile double import public
"" DOM/HTML/CSS specified things
@@ -136,7 +151,7 @@ endif "DOM/HTML/CSS
"" Code blocks
-syntax cluster javaScriptAll contains=javaScriptComment,javaScriptLineComment,javaScriptDocComment,javaScriptStringD,javaScriptStringS,javaScriptRegexpString,javaScriptNumber,javaScriptFloat,javaScriptLabel,javaScriptSource,javaScriptType,javaScriptOperator,javaScriptBoolean,javaScriptNull,javaScriptFunction,javaScriptConditional,javaScriptRepeat,javaScriptBranch,javaScriptStatement,javaScriptGlobalObjects,javaScriptExceptions,javaScriptFutureKeys,javaScriptDomErrNo,javaScriptDomNodeConsts,javaScriptHtmlEvents,javaScriptDotNotation
+syntax cluster javaScriptAll contains=javaScriptComment,javaScriptLineComment,javaScriptDocComment,javaScriptStringD,javaScriptStringS,javaScriptRegexpString,javaScriptNumber,javaScriptFloat,javaScriptLabel,javaScriptSource,javaScriptThis,javaScriptType,javaScriptOperator,javaScriptBoolean,javaScriptNull,javaScriptFunction,javaScriptConditional,javaScriptRepeat,javaScriptBranch,javaScriptStatement,javaScriptGlobalObjects,javaScriptExceptions,javaScriptFutureKeys,javaScriptDomErrNo,javaScriptDomNodeConsts,javaScriptHtmlEvents,javaScriptDotNotation
syntax region javaScriptBracket matchgroup=javaScriptBracket transparent start="\[" end="\]" contains=@javaScriptAll,javaScriptParensErrB,javaScriptParensErrC,javaScriptBracket,javaScriptParen,javaScriptBlock,@htmlPreproc
syntax region javaScriptParen matchgroup=javaScriptParen transparent start="(" end=")" contains=@javaScriptAll,javaScriptParensErrA,javaScriptParensErrC,javaScriptParen,javaScriptBracket,javaScriptBlock,@htmlPreproc
syntax region javaScriptBlock matchgroup=javaScriptBlock transparent start="{" end="}" contains=@javaScriptAll,javaScriptParensErrA,javaScriptParensErrB,javaScriptParen,javaScriptBracket,javaScriptBlock,@htmlPreproc
@@ -159,19 +174,8 @@ if exists("b:javascript_fold")
syntax match javaScriptOpAssign /=\@<!=/ nextgroup=javaScriptFuncBlock skipwhite skipempty
syntax region javaScriptFuncName contained matchgroup=javaScriptFuncName start=/\%(\$\|\w\)*\s*(/ end=/)/ contains=javaScriptLineComment,javaScriptComment nextgroup=javaScriptFuncBlock skipwhite skipempty
syntax region javaScriptFuncBlock contained matchgroup=javaScriptFuncBlock start="{" end="}" contains=@javaScriptAll,javaScriptParensErrA,javaScriptParensErrB,javaScriptParen,javaScriptBracket,javaScriptBlock fold
-
- if &l:filetype=='javascript' && !&diff
- " Fold setting
- " Redefine the foldtext (to show a JS function outline) and foldlevel
- " only if the entire buffer is JavaScript, but not if JavaScript syntax
- " is embedded in another syntax (e.g. HTML).
- setlocal foldmethod=syntax
- setlocal foldlevel=4
- endif
else
syntax keyword javaScriptFunction function
- setlocal foldmethod<
- setlocal foldlevel<
endif
" Define the default highlighting.
@@ -186,15 +190,19 @@ if version >= 508 || !exists("did_javascript_syn_inits")
endif
HiLink javaScriptComment Comment
HiLink javaScriptLineComment Comment
+ HiLink javaScriptEnvComment PreProc
HiLink javaScriptDocComment Comment
HiLink javaScriptCommentTodo Todo
HiLink javaScriptCvsTag Function
HiLink javaScriptDocTags Special
HiLink javaScriptDocSeeTag Function
- HiLink javaScriptDocParam Function
+ HiLink javaScriptDocType Type
+ HiLink javaScriptDocTypeNoParam Type
+ HiLink javaScriptDocParam Label
HiLink javaScriptStringS String
HiLink javaScriptStringD String
HiLink javaScriptRegexpString String
+ HiLink javaScriptRegexpCharClass Character
HiLink javaScriptCharacter Character
HiLink javaScriptPrototype Type
HiLink javaScriptConditional Conditional
@@ -209,6 +217,7 @@ if version >= 508 || !exists("did_javascript_syn_inits")
HiLink javaScriptParensErrC Error
HiLink javaScriptOperator Operator
HiLink javaScriptType Type
+ HiLink javaScriptThis Type
HiLink javaScriptNull Type
HiLink javaScriptNumber Number
HiLink javaScriptFloat Number
Please sign in to comment.
Something went wrong with that request. Please try again.