mirror of
https://github.com/amix/vimrc
synced 2025-07-17 17:15:01 +08:00
@ -1,136 +0,0 @@
|
||||
Typescript Syntax for Vim
|
||||
=========================
|
||||
|
||||
Syntax file and other settings for [TypeScript](http://typescriptlang.org). The
|
||||
syntax file is taken from this [blog
|
||||
post](https://docs.microsoft.com/en-us/archive/blogs/interoperability/sublime-text-vi-emacs-typescript-enabled).
|
||||
|
||||
Checkout [Tsuquyomi](https://github.com/Quramy/tsuquyomi) for omni-completion
|
||||
and other features for TypeScript editing.
|
||||
|
||||
Install
|
||||
-------
|
||||
|
||||
From Vim 8 onward, the plugin can be installed as simply as (Unix/Mac):
|
||||
```
|
||||
git clone https://github.com/leafgarland/typescript-vim.git ~/.vim/pack/typescript/start/typescript-vim
|
||||
```
|
||||
|
||||
On Windows/Powershell, use the following:
|
||||
```
|
||||
git clone https://github.com/leafgarland/typescript-vim.git $home/vimfiles/pack/typescript/start/typescript-vim
|
||||
```
|
||||
|
||||
For older versions of Vim, the simplest way to install is via a Vim add-in manager such as
|
||||
[Plug](https://github.com/junegunn/vim-plug),
|
||||
[Vundle](https://github.com/gmarik/vundle) or
|
||||
[Pathogen](https://github.com/tpope/vim-pathogen/).
|
||||
|
||||
_See the [Installation Wiki](https://github.com/leafgarland/typescript-vim/wiki/Installation)_
|
||||
|
||||
### Pathogen
|
||||
|
||||
```
|
||||
git clone https://github.com/leafgarland/typescript-vim.git ~/.vim/bundle/typescript-vim
|
||||
```
|
||||
|
||||
If you want to install manually then you need to copy the files from this
|
||||
repository into your vim path, see the vim docs for [:help
|
||||
runtimepath](http://vimdoc.sourceforge.net/htmldoc/options.html#'runtimepath')
|
||||
for more information. This might be as simple as copying the files and
|
||||
directories to `~/.vim/` but it depends on your Vim install and operating
|
||||
system.
|
||||
|
||||
Usage
|
||||
-----
|
||||
|
||||
Once the files are installed the syntax highlighting and other settings will be
|
||||
automatically enabled anytime you edit a `.ts` file.
|
||||
|
||||
Indenting
|
||||
---------
|
||||
|
||||
This plugin includes a custom indenter (based on [pangloss/vim-javascript's
|
||||
indenter](https://github.com/pangloss/vim-javascript/blob/master/indent/javascript.vim)),
|
||||
it works pretty well but there are cases where it fails. If these bother you or
|
||||
want to use other indent settings you can disable it by setting a flag in your
|
||||
`.vimrc`:
|
||||
|
||||
```vim
|
||||
let g:typescript_indent_disable = 1
|
||||
```
|
||||
|
||||
If you want the indenter to automatically indent chained method calls as you type.
|
||||
|
||||
```typescript
|
||||
something
|
||||
.foo()
|
||||
.bar();
|
||||
```
|
||||
|
||||
Then add something like `setlocal indentkeys+=0.` to your `.vimrc`, see `:help
|
||||
'indentkeys'` in vim for more information.
|
||||
|
||||
If you use the `=` operator to re-indent code it will always indent
|
||||
chained method calls - this can be disabled by changing the regex the
|
||||
indent script uses to identify indented lines. In this case removing '.'
|
||||
from the regex means that it wont indent lines starting with '.'. Note,
|
||||
this is not ideal as the regex may change making your setting out of date.
|
||||
|
||||
```vim
|
||||
let g:typescript_opfirst='\%([<>=,?^%|*/&]\|\([-:+]\)\1\@!\|!=\|in\%(stanceof\)\=\>\)'
|
||||
```
|
||||
|
||||
Compiler settings
|
||||
-----------------
|
||||
|
||||
This plugin contains compiler settings to set `makeprg` and `errorformat`.
|
||||
The compiler settings enable you to call the `tsc` compiler directly from Vim
|
||||
and display any errors or warnings in Vim's QuickFix window.
|
||||
|
||||
To run the compiler, enter `:make`, this will run `tsc` against the last saved
|
||||
version of your currently edited file.
|
||||
|
||||
The default for `makeprg` is `tsc $* %`. You can enter other compiler options into your `:make`
|
||||
command line and they will be inserted in place of `$*`.
|
||||
|
||||
There are options to change the compiler name and to insert default options.
|
||||
|
||||
```vim
|
||||
let g:typescript_compiler_binary = 'tsc'
|
||||
let g:typescript_compiler_options = ''
|
||||
```
|
||||
|
||||
These options will be passed to the binary as command arguments. For example,
|
||||
if `g:typescript_compiler_binary = 'tsc'` and `g:typescript_compiler_options = '--lib es6'`,
|
||||
`l:makeprg` will be: `tsc --lib es6 $* %`.
|
||||
|
||||
You can completely override this plugin's compiler settings with something like
|
||||
this in your `.vimrc`, where you can set makeprg to whatever you want.
|
||||
|
||||
```vim
|
||||
autocmd FileType typescript :set makeprg=tsc
|
||||
```
|
||||
|
||||
Note, this plugin's compiler settings are not used by Syntastic which has its own
|
||||
way of changing the options. See https://github.com/scrooloose/syntastic#faqargs.
|
||||
|
||||
You can use something like this in your `.vimrc` to make the QuickFix
|
||||
window automatically appear if `:make` has any errors.
|
||||
|
||||
```vim
|
||||
autocmd QuickFixCmdPost [^l]* nested cwindow
|
||||
autocmd QuickFixCmdPost l* nested lwindow
|
||||
```
|
||||
|
||||
Syntax highlighting
|
||||
-------------------
|
||||
|
||||
Syntax highlighting for TypeScript can be customized by following variables.
|
||||
|
||||
- `g:typescript_ignore_typescriptdoc`: When this variable is defined, doccomments will not be
|
||||
highlighted.
|
||||
- `g:typescript_ignore_browserwords`: When this variable is set to `1`, browser API names such as
|
||||
`window` or `document` will not be highlighted. (default to `0`)
|
||||
|
||||

|
@ -1,30 +0,0 @@
|
||||
if exists("current_compiler")
|
||||
finish
|
||||
endif
|
||||
let current_compiler = "typescript"
|
||||
|
||||
if !exists("g:typescript_compiler_binary")
|
||||
let g:typescript_compiler_binary = "tsc"
|
||||
endif
|
||||
|
||||
if !exists("g:typescript_compiler_options")
|
||||
let g:typescript_compiler_options = ""
|
||||
endif
|
||||
|
||||
if exists(":CompilerSet") != 2
|
||||
command! -nargs=* CompilerSet setlocal <args>
|
||||
endif
|
||||
|
||||
let s:cpo_save = &cpo
|
||||
set cpo-=C
|
||||
|
||||
execute 'CompilerSet makeprg='
|
||||
\ . escape(g:typescript_compiler_binary, ' ')
|
||||
\ . '\ '
|
||||
\ . escape(g:typescript_compiler_options, ' ')
|
||||
\ . '\ $*\ %'
|
||||
|
||||
CompilerSet errorformat=%+A\ %#%f\ %#(%l\\\,%c):\ %m,%C%m
|
||||
|
||||
let &cpo = s:cpo_save
|
||||
unlet s:cpo_save
|
@ -1 +0,0 @@
|
||||
runtime! compiler/typescript.vim
|
@ -1,4 +0,0 @@
|
||||
" use `set filetype` to override default filetype=xml for *.ts files
|
||||
autocmd BufNewFile,BufRead *.ts set filetype=typescript
|
||||
" use `setfiletype` to not override any other plugins like ianks/vim-tsx
|
||||
autocmd BufNewFile,BufRead *.tsx setfiletype typescript
|
@ -1,21 +0,0 @@
|
||||
if exists("b:did_ftplugin")
|
||||
finish
|
||||
endif
|
||||
let b:did_ftplugin = 1
|
||||
|
||||
let s:cpo_save = &cpo
|
||||
set cpo-=C
|
||||
|
||||
compiler typescript
|
||||
setlocal commentstring=//\ %s
|
||||
|
||||
" Set 'formatoptions' to break comment lines but not other lines,
|
||||
" " and insert the comment leader when hitting <CR> or using "o".
|
||||
setlocal formatoptions-=t formatoptions+=croql
|
||||
|
||||
setlocal suffixesadd+=.ts,.tsx
|
||||
|
||||
let b:undo_ftplugin = "setl fo< ofu< com< cms<"
|
||||
|
||||
let &cpo = s:cpo_save
|
||||
unlet s:cpo_save
|
@ -1 +0,0 @@
|
||||
runtime! ftplugin/typescript.vim
|
@ -1,360 +0,0 @@
|
||||
" Vim indent file
|
||||
" Language: Typescript
|
||||
" Acknowledgement: Almost direct copy from https://github.com/pangloss/vim-javascript
|
||||
|
||||
" Only load this indent file when no other was loaded.
|
||||
if exists('b:did_indent') || get(g:, 'typescript_indent_disable', 0)
|
||||
finish
|
||||
endif
|
||||
let b:did_indent = 1
|
||||
|
||||
" Now, set up our indentation expression and keys that trigger it.
|
||||
setlocal indentexpr=GetTypescriptIndent()
|
||||
setlocal autoindent nolisp nosmartindent
|
||||
setlocal indentkeys+=0],0)
|
||||
|
||||
let b:undo_indent = 'setlocal indentexpr< smartindent< autoindent< indentkeys<'
|
||||
|
||||
" Only define the function once.
|
||||
if exists('*GetTypescriptIndent')
|
||||
finish
|
||||
endif
|
||||
|
||||
let s:cpo_save = &cpo
|
||||
set cpo&vim
|
||||
|
||||
" Get shiftwidth value
|
||||
if exists('*shiftwidth')
|
||||
function s:sw()
|
||||
return shiftwidth()
|
||||
endfunction
|
||||
else
|
||||
function s:sw()
|
||||
return &sw
|
||||
endfunction
|
||||
endif
|
||||
|
||||
" searchpair() wrapper
|
||||
if has('reltime')
|
||||
function s:GetPair(start,end,flags,skip,time,...)
|
||||
return searchpair('\m'.a:start,'','\m'.a:end,a:flags,a:skip,max([prevnonblank(v:lnum) - 2000,0] + a:000),a:time)
|
||||
endfunction
|
||||
else
|
||||
function s:GetPair(start,end,flags,skip,...)
|
||||
return searchpair('\m'.a:start,'','\m'.a:end,a:flags,a:skip,max([prevnonblank(v:lnum) - 1000,get(a:000,1)]))
|
||||
endfunction
|
||||
endif
|
||||
|
||||
" Regex of syntax group names that are or delimit string or are comments.
|
||||
let s:syng_strcom = 'string\|comment\|regex\|special\|doc\|template\%(braces\)\@!'
|
||||
let s:syng_str = 'string\|template\|special'
|
||||
let s:syng_com = 'comment\|doc'
|
||||
" Expression used to check whether we should skip a match with searchpair().
|
||||
let s:skip_expr = "synIDattr(synID(line('.'),col('.'),0),'name') =~? '".s:syng_strcom."'"
|
||||
|
||||
function s:skip_func()
|
||||
if !s:free || search('\m`\|\${\|\*\/','nW',s:looksyn)
|
||||
let s:free = !eval(s:skip_expr)
|
||||
let s:looksyn = line('.')
|
||||
return !s:free
|
||||
endif
|
||||
let s:looksyn = line('.')
|
||||
return getline('.') =~ '\%<'.col('.').'c\/.\{-}\/\|\%>'.col('.').'c[''"]\|\\$' &&
|
||||
\ eval(s:skip_expr)
|
||||
endfunction
|
||||
|
||||
function s:alternatePair(stop)
|
||||
let pos = getpos('.')[1:2]
|
||||
while search('\m[][(){}]','bW',a:stop)
|
||||
if !s:skip_func()
|
||||
let idx = stridx('])}',s:looking_at())
|
||||
if idx + 1
|
||||
if s:GetPair(['\[','(','{'][idx], '])}'[idx],'bW','s:skip_func()',2000,a:stop) <= 0
|
||||
break
|
||||
endif
|
||||
else
|
||||
return
|
||||
endif
|
||||
endif
|
||||
endwhile
|
||||
call call('cursor',pos)
|
||||
endfunction
|
||||
|
||||
function s:save_pos(f,...)
|
||||
let l:pos = getpos('.')[1:2]
|
||||
let ret = call(a:f,a:000)
|
||||
call call('cursor',l:pos)
|
||||
return ret
|
||||
endfunction
|
||||
|
||||
function s:syn_at(l,c)
|
||||
return synIDattr(synID(a:l,a:c,0),'name')
|
||||
endfunction
|
||||
|
||||
function s:looking_at()
|
||||
return getline('.')[col('.')-1]
|
||||
endfunction
|
||||
|
||||
function s:token()
|
||||
return s:looking_at() =~ '\k' ? expand('<cword>') : s:looking_at()
|
||||
endfunction
|
||||
|
||||
function s:previous_token()
|
||||
let l:n = line('.')
|
||||
if (s:looking_at() !~ '\k' || search('\m\<','cbW')) && search('\m\S','bW')
|
||||
if (getline('.')[col('.')-2:col('.')-1] == '*/' || line('.') != l:n &&
|
||||
\ getline('.') =~ '\%<'.col('.').'c\/\/') && s:syn_at(line('.'),col('.')) =~? s:syng_com
|
||||
while search('\m\/\ze[/*]','cbW')
|
||||
if !search('\m\S','bW')
|
||||
break
|
||||
elseif s:syn_at(line('.'),col('.')) !~? s:syng_com
|
||||
return s:token()
|
||||
endif
|
||||
endwhile
|
||||
else
|
||||
return s:token()
|
||||
endif
|
||||
endif
|
||||
return ''
|
||||
endfunction
|
||||
|
||||
function s:others(p)
|
||||
return "((line2byte(line('.')) + col('.')) <= ".(line2byte(a:p[0]) + a:p[1]).") || ".s:skip_expr
|
||||
endfunction
|
||||
|
||||
function s:tern_skip(p)
|
||||
return s:GetPair('{','}','nbW',s:others(a:p),200,a:p[0]) > 0
|
||||
endfunction
|
||||
|
||||
function s:tern_col(p)
|
||||
return s:GetPair('?',':\@<!::\@!','nbW',s:others(a:p)
|
||||
\ .' || s:tern_skip('.string(a:p).')',200,a:p[0]) > 0
|
||||
endfunction
|
||||
|
||||
function s:label_col()
|
||||
let pos = getpos('.')[1:2]
|
||||
let [s:looksyn,s:free] = pos
|
||||
call s:alternatePair(0)
|
||||
if s:save_pos('s:IsBlock')
|
||||
let poss = getpos('.')[1:2]
|
||||
return call('cursor',pos) || !s:tern_col(poss)
|
||||
elseif s:looking_at() == ':'
|
||||
return !s:tern_col([0,0])
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" configurable regexes that define continuation lines, not including (, {, or [.
|
||||
let s:opfirst = '^' . get(g:,'typescript_opfirst',
|
||||
\ '\%([<>=,?^%|*/&]\|\([-.:+]\)\1\@!\|!=\|in\%(stanceof\)\=\>\)')
|
||||
let s:continuation = get(g:,'typescript_continuation',
|
||||
\ '\%([-+<>=,.~!?/*^%|&:]\|\<\%(typeof\|delete\|void\|in\|instanceof\)\)') . '$'
|
||||
|
||||
function s:continues(ln,con)
|
||||
return !cursor(a:ln, match(' '.a:con,s:continuation)) &&
|
||||
\ eval( (['s:syn_at(line("."),col(".")) !~? "regex"'] +
|
||||
\ repeat(['getline(".")[col(".")-2] != tr(s:looking_at(),">","=")'],3) +
|
||||
\ repeat(['s:previous_token() != "."'],5) + [1])[
|
||||
\ index(split('/ > - + typeof in instanceof void delete'),s:token())])
|
||||
endfunction
|
||||
|
||||
" get the line of code stripped of comments and move cursor to the last
|
||||
" non-comment char.
|
||||
function s:Trim(ln)
|
||||
call cursor(a:ln+1,1)
|
||||
call s:previous_token()
|
||||
return strpart(getline('.'),0,col('.'))
|
||||
endfunction
|
||||
|
||||
" Find line above 'lnum' that isn't empty or in a comment
|
||||
function s:PrevCodeLine(lnum)
|
||||
let l:n = prevnonblank(a:lnum)
|
||||
while l:n
|
||||
if getline(l:n) =~ '^\s*\/[/*]'
|
||||
if (stridx(getline(l:n),'`') > 0 || getline(l:n-1)[-1:] == '\') &&
|
||||
\ s:syn_at(l:n,1) =~? s:syng_str
|
||||
return l:n
|
||||
endif
|
||||
let l:n = prevnonblank(l:n-1)
|
||||
elseif getline(l:n) =~ '\([/*]\)\1\@![/*]' && s:syn_at(l:n,1) =~? s:syng_com
|
||||
let l:n = s:save_pos('eval',
|
||||
\ 'cursor('.l:n.',1) + search(''\m\/\*'',"bW")')
|
||||
else
|
||||
return l:n
|
||||
endif
|
||||
endwhile
|
||||
endfunction
|
||||
|
||||
" Check if line 'lnum' has a balanced amount of parentheses.
|
||||
function s:Balanced(lnum)
|
||||
let l:open = 0
|
||||
let l:line = getline(a:lnum)
|
||||
let pos = match(l:line, '[][(){}]', 0)
|
||||
while pos != -1
|
||||
if s:syn_at(a:lnum,pos + 1) !~? s:syng_strcom
|
||||
let l:open += match(' ' . l:line[pos],'[[({]')
|
||||
if l:open < 0
|
||||
return
|
||||
endif
|
||||
endif
|
||||
let pos = match(l:line, '[][(){}]', pos + 1)
|
||||
endwhile
|
||||
return !l:open
|
||||
endfunction
|
||||
|
||||
function s:OneScope(lnum)
|
||||
let pline = s:Trim(a:lnum)
|
||||
let kw = 'else do'
|
||||
if pline[-1:] == ')' && s:GetPair('(', ')', 'bW', s:skip_expr, 100) > 0
|
||||
call s:previous_token()
|
||||
let kw = 'for if let while with'
|
||||
if index(split('await each'),s:token()) + 1
|
||||
call s:previous_token()
|
||||
let kw = 'for'
|
||||
endif
|
||||
endif
|
||||
return pline[-2:] == '=>' || index(split(kw),s:token()) + 1 &&
|
||||
\ s:save_pos('s:previous_token') != '.'
|
||||
endfunction
|
||||
|
||||
" returns braceless levels started by 'i' and above lines * &sw. 'num' is the
|
||||
" lineNr which encloses the entire context, 'cont' if whether line 'i' + 1 is
|
||||
" a continued expression, which could have started in a braceless context
|
||||
function s:iscontOne(i,num,cont)
|
||||
let [l:i, l:num, bL] = [a:i, a:num + !a:num, 0]
|
||||
let pind = a:num ? indent(l:num) + s:W : 0
|
||||
let ind = indent(l:i) + (a:cont ? 0 : s:W)
|
||||
while l:i >= l:num && (ind > pind || l:i == l:num)
|
||||
if indent(l:i) < ind && s:OneScope(l:i)
|
||||
let bL += s:W
|
||||
let l:i = line('.')
|
||||
elseif !a:cont || bL || ind < indent(a:i)
|
||||
break
|
||||
endif
|
||||
let ind = min([ind, indent(l:i)])
|
||||
let l:i = s:PrevCodeLine(l:i - 1)
|
||||
endwhile
|
||||
return bL
|
||||
endfunction
|
||||
|
||||
" https://github.com/sweet-js/sweet.js/wiki/design#give-lookbehind-to-the-reader
|
||||
function s:IsBlock()
|
||||
if s:looking_at() == '{'
|
||||
let l:n = line('.')
|
||||
let char = s:previous_token()
|
||||
if match(s:stack,'xml\|jsx') + 1 && s:syn_at(line('.'),col('.')-1) =~? 'xml\|jsx'
|
||||
return char != '{'
|
||||
elseif char =~ '\k'
|
||||
return index(split('return const let import export yield default delete var await void typeof throw case new in instanceof')
|
||||
\ ,char) < (line('.') != l:n) || s:previous_token() == '.'
|
||||
elseif char == '>'
|
||||
return getline('.')[col('.')-2] == '=' || s:syn_at(line('.'),col('.')) =~? '^jsflow'
|
||||
elseif char == ':'
|
||||
return getline('.')[col('.')-2] != ':' && s:label_col()
|
||||
elseif char == '/'
|
||||
return s:syn_at(line('.'),col('.')) =~? 'regex'
|
||||
endif
|
||||
return char !~ '[=~!<*,?^%|&([]' &&
|
||||
\ (char !~ '[-+]' || l:n != line('.') && getline('.')[col('.')-2] == char)
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function GetTypescriptIndent()
|
||||
let b:js_cache = get(b:,'js_cache',[0,0,0])
|
||||
" Get the current line.
|
||||
call cursor(v:lnum,1)
|
||||
let l:line = getline('.')
|
||||
" use synstack as it validates syn state and works in an empty line
|
||||
let s:stack = synstack(v:lnum,1)
|
||||
let syns = synIDattr(get(s:stack,-1),'name')
|
||||
|
||||
" start with strings,comments,etc.
|
||||
if syns =~? s:syng_com
|
||||
if l:line =~ '^\s*\*'
|
||||
return cindent(v:lnum)
|
||||
elseif l:line !~ '^\s*\/[/*]'
|
||||
return -1
|
||||
endif
|
||||
elseif syns =~? s:syng_str && l:line !~ '^[''"]'
|
||||
if b:js_cache[0] == v:lnum - 1 && s:Balanced(v:lnum-1)
|
||||
let b:js_cache[0] = v:lnum
|
||||
endif
|
||||
return -1
|
||||
endif
|
||||
let l:lnum = s:PrevCodeLine(v:lnum - 1)
|
||||
if !l:lnum
|
||||
return
|
||||
endif
|
||||
|
||||
let l:line = substitute(l:line,'^\s*','','')
|
||||
if l:line[:1] == '/*'
|
||||
let l:line = substitute(l:line,'^\%(\/\*.\{-}\*\/\s*\)*','','')
|
||||
endif
|
||||
if l:line =~ '^\/[/*]'
|
||||
let l:line = ''
|
||||
endif
|
||||
|
||||
" the containing paren, bracket, curly, or closing '>'.
|
||||
" Many hacks for performance
|
||||
let idx = index([']',')','}','>'],l:line[0])
|
||||
if b:js_cache[0] >= l:lnum && b:js_cache[0] < v:lnum &&
|
||||
\ (b:js_cache[0] > l:lnum || s:Balanced(l:lnum))
|
||||
call call('cursor',b:js_cache[1:])
|
||||
else
|
||||
let [s:looksyn, s:free, top] = [v:lnum - 1, 1, (!indent(l:lnum) &&
|
||||
\ s:syn_at(l:lnum,1) !~? s:syng_str) * l:lnum]
|
||||
if idx + 1
|
||||
call s:GetPair(['\[','(','{'][idx],'])}'[idx],'bW','s:skip_func()',2000,top)
|
||||
elseif getline(v:lnum) !~ '^\S' && syns =~? 'block'
|
||||
call s:GetPair('{','}','bW','s:skip_func()',2000,top)
|
||||
else
|
||||
call s:alternatePair(top)
|
||||
endif
|
||||
endif
|
||||
|
||||
let b:js_cache = [v:lnum] + (line('.') == v:lnum ? [0,0] : getpos('.')[1:2])
|
||||
let num = b:js_cache[1]
|
||||
|
||||
let [s:W, isOp, bL, switch_offset] = [s:sw(),0,0,0]
|
||||
if !num || s:IsBlock()
|
||||
let ilnum = line('.')
|
||||
let pline = s:save_pos('s:Trim',l:lnum)
|
||||
if num && s:looking_at() == ')' && s:GetPair('(', ')', 'bW', s:skip_expr, 100) > 0
|
||||
let num = ilnum == num ? line('.') : num
|
||||
if idx < 0 && s:previous_token() ==# 'switch' && s:previous_token() != '.'
|
||||
if &cino !~ ':'
|
||||
let switch_offset = s:W
|
||||
else
|
||||
let cinc = matchlist(&cino,'.*:\zs\(-\)\=\(\d*\)\(\.\d\+\)\=\(s\)\=\C')
|
||||
let switch_offset = max([cinc[0] is '' ? 0 : (cinc[1].1) *
|
||||
\ ((strlen(cinc[2].cinc[3]) ? str2nr(cinc[2].str2nr(cinc[3][1])) : 10) *
|
||||
\ (cinc[4] is '' ? 1 : s:W)) / 10, -indent(num)])
|
||||
endif
|
||||
if pline[-1:] != '.' && l:line =~# '^\%(default\|case\)\>'
|
||||
return indent(num) + switch_offset
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
if idx < 0 && pline !~ '[{;]$'
|
||||
if pline =~# ':\@<!:$'
|
||||
call cursor(l:lnum,strlen(pline))
|
||||
let isOp = s:tern_col(b:js_cache[1:2]) * s:W
|
||||
else
|
||||
let isOp = (l:line =~# s:opfirst || s:continues(l:lnum,pline)) * s:W
|
||||
endif
|
||||
let bL = s:iscontOne(l:lnum,b:js_cache[1],isOp)
|
||||
let bL -= (bL && l:line[0] == '{') * s:W
|
||||
endif
|
||||
endif
|
||||
|
||||
" main return
|
||||
if idx + 1 || l:line[:1] == '|}'
|
||||
return indent(num)
|
||||
elseif num
|
||||
return indent(num) + s:W + switch_offset + bL + isOp
|
||||
endif
|
||||
return bL + isOp
|
||||
endfunction
|
||||
|
||||
let &cpo = s:cpo_save
|
||||
unlet s:cpo_save
|
||||
|
@ -1 +0,0 @@
|
||||
runtime! indent/typescript.vim
|
@ -1,342 +0,0 @@
|
||||
" Vim syntax file
|
||||
" Language: typescript
|
||||
" Author: MicroSoft Open Technologies Inc.
|
||||
" Version: 0.1
|
||||
" Credits: Zhao Yi, Claudio Fleiner, Scott Shattuck, Jose Elera Campana
|
||||
|
||||
if !exists("main_syntax")
|
||||
if version < 600
|
||||
syntax clear
|
||||
elseif exists("b:current_syntax")
|
||||
finish
|
||||
endif
|
||||
let main_syntax = "typescript"
|
||||
endif
|
||||
|
||||
" Drop fold if it set but vim doesn't support it.
|
||||
if version < 600 && exists("typescript_fold")
|
||||
unlet typescript_fold
|
||||
endif
|
||||
|
||||
"" dollar sign is permitted anywhere in an identifier
|
||||
setlocal iskeyword+=$
|
||||
|
||||
syntax sync fromstart
|
||||
|
||||
"" syntax coloring for Node.js shebang line
|
||||
syn match shebang "^#!.*/bin/env\s\+node\>"
|
||||
hi link shebang Comment
|
||||
|
||||
"" typescript comments"{{{
|
||||
syn keyword typescriptCommentTodo TODO FIXME XXX TBD contained
|
||||
syn match typescriptLineComment "\/\/.*" contains=@Spell,typescriptCommentTodo,typescriptRef
|
||||
syn match typescriptRefComment /\/\/\/<\(reference\|amd-\(dependency\|module\)\)\s\+.*\/>$/ contains=typescriptRefD,typescriptRefS
|
||||
syn region typescriptRefD start=+"+ skip=+\\\\\|\\"+ end=+"\|$+
|
||||
syn region typescriptRefS start=+'+ skip=+\\\\\|\\'+ end=+'\|$+
|
||||
|
||||
syn match typescriptCommentSkip "^[ \t]*\*\($\|[ \t]\+\)"
|
||||
syn region typescriptComment start="/\*" end="\*/" contains=@Spell,typescriptCommentTodo extend
|
||||
"}}}
|
||||
"" JSDoc support start"{{{
|
||||
if !exists("typescript_ignore_typescriptdoc")
|
||||
syntax case ignore
|
||||
|
||||
" syntax coloring for JSDoc comments (HTML)
|
||||
"unlet b:current_syntax
|
||||
|
||||
syntax region typescriptDocComment start="/\*\*\s*$" end="\*/" contains=typescriptDocTags,typescriptCommentTodo,typescriptCvsTag,@typescriptHtml,@Spell fold extend
|
||||
syntax match typescriptDocTags contained "@\(param\|argument\|requires\|exception\|throws\|type\|class\|extends\|see\|link\|member\|module\|method\|title\|namespace\|optional\|default\|base\|file\|returns\=\)\>" nextgroup=typescriptDocParam,typescriptDocSeeTag skipwhite
|
||||
syntax match typescriptDocTags contained "@\(beta\|deprecated\|description\|fileoverview\|author\|license\|version\|constructor\|private\|protected\|final\|ignore\|addon\|exec\)\>"
|
||||
syntax match typescriptDocParam contained "\%(#\|\w\|\.\|:\|\/\)\+"
|
||||
syntax region typescriptDocSeeTag contained matchgroup=typescriptDocSeeTag start="{" end="}" contains=typescriptDocTags
|
||||
|
||||
syntax case match
|
||||
endif "" JSDoc end
|
||||
"}}}
|
||||
syntax case match
|
||||
|
||||
"" Syntax in the typescript code"{{{
|
||||
syn match typescriptSpecial "\\\d\d\d\|\\x\x\{2\}\|\\u\x\{4\}" contained containedin=typescriptStringD,typescriptStringS,typescriptStringB display
|
||||
syn region typescriptStringD start=+"+ skip=+\\\\\|\\"+ end=+"\|$+ contains=typescriptSpecial,@htmlPreproc extend
|
||||
syn region typescriptStringS start=+'+ skip=+\\\\\|\\'+ end=+'\|$+ contains=typescriptSpecial,@htmlPreproc extend
|
||||
syn region typescriptStringB start=+`+ skip=+\\\\\|\\`+ end=+`+ contains=typescriptInterpolation,typescriptSpecial,@htmlPreproc extend
|
||||
|
||||
syn region typescriptInterpolation matchgroup=typescriptInterpolationDelimiter
|
||||
\ start=/${/ end=/}/ contained
|
||||
\ contains=@typescriptExpression
|
||||
|
||||
syn match typescriptNumber "-\=\<\d[0-9_]*L\=\>" display
|
||||
syn match typescriptNumber "-\=\<0[xX][0-9a-fA-F][0-9a-fA-F_]*\>" display
|
||||
syn match typescriptNumber "-\=\<0[bB][01][01_]*\>" display
|
||||
syn match typescriptNumber "-\=\<0[oO]\o[0-7_]*\>" display
|
||||
syn region typescriptRegexpString start=+/[^/*]+me=e-1 skip=+\\\\\|\\/+ end=+/[gimsuy]\{0,2\}\s*$+ end=+/[gimsuy]\{0,2\}\s*[;.,)\]}]+me=e-1 contains=@htmlPreproc oneline
|
||||
" syntax match typescriptSpecial "\\\d\d\d\|\\x\x\{2\}\|\\u\x\{4\}\|\\."
|
||||
" syntax region typescriptStringD start=+"+ skip=+\\\\\|\\$"+ end=+"+ contains=typescriptSpecial,@htmlPreproc
|
||||
" syntax region typescriptStringS start=+'+ skip=+\\\\\|\\$'+ end=+'+ contains=typescriptSpecial,@htmlPreproc
|
||||
" syntax region typescriptRegexpString start=+/\(\*\|/\)\@!+ skip=+\\\\\|\\/+ end=+/[gimsuy]\{,3}+ contains=typescriptSpecial,@htmlPreproc oneline
|
||||
" syntax match typescriptNumber /\<-\=\d\+L\=\>\|\<0[xX]\x\+\>/
|
||||
syntax match typescriptFloat /\<-\=\%(\d[0-9_]*\.\d[0-9_]*\|\d[0-9_]*\.\|\.\d[0-9]*\)\%([eE][+-]\=\d[0-9_]*\)\=\>/
|
||||
" syntax match typescriptLabel /\(?\s*\)\@<!\<\w\+\(\s*:\)\@=/
|
||||
|
||||
syn match typescriptDecorators /@\([_$a-zA-Z][_$a-zA-Z0-9]*\.\)*[_$a-zA-Z][_$a-zA-Z0-9]*\>/
|
||||
"}}}
|
||||
"" typescript Prototype"{{{
|
||||
syntax keyword typescriptPrototype contained prototype
|
||||
"}}}
|
||||
" DOM, Browser and Ajax Support {{{
|
||||
""""""""""""""""""""""""
|
||||
if get(g:, 'typescript_ignore_browserwords', 0)
|
||||
syntax keyword typescriptBrowserObjects window navigator screen history location
|
||||
|
||||
syntax keyword typescriptDOMObjects document event HTMLElement Anchor Area Base Body Button Form Frame Frameset Image Link Meta Option Select Style Table TableCell TableRow Textarea
|
||||
syntax keyword typescriptDOMMethods contained createTextNode createElement insertBefore replaceChild removeChild appendChild hasChildNodes cloneNode normalize isSupported hasAttributes getAttribute setAttribute removeAttribute getAttributeNode setAttributeNode removeAttributeNode getElementsByTagName hasAttribute getElementById adoptNode close compareDocumentPosition createAttribute createCDATASection createComment createDocumentFragment createElementNS createEvent createExpression createNSResolver createProcessingInstruction createRange createTreeWalker elementFromPoint evaluate getBoxObjectFor getElementsByClassName getSelection getUserData hasFocus importNode
|
||||
syntax keyword typescriptDOMProperties contained nodeName nodeValue nodeType parentNode childNodes firstChild lastChild previousSibling nextSibling attributes ownerDocument namespaceURI prefix localName tagName
|
||||
|
||||
syntax keyword typescriptAjaxObjects XMLHttpRequest
|
||||
syntax keyword typescriptAjaxProperties contained readyState responseText responseXML statusText
|
||||
syntax keyword typescriptAjaxMethods contained onreadystatechange abort getAllResponseHeaders getResponseHeader open send setRequestHeader
|
||||
|
||||
syntax keyword typescriptPropietaryObjects ActiveXObject
|
||||
syntax keyword typescriptPropietaryMethods contained attachEvent detachEvent cancelBubble returnValue
|
||||
|
||||
syntax keyword typescriptHtmlElemProperties contained className clientHeight clientLeft clientTop clientWidth dir href id innerHTML lang length offsetHeight offsetLeft offsetParent offsetTop offsetWidth scrollHeight scrollLeft scrollTop scrollWidth style tabIndex target title
|
||||
|
||||
syntax keyword typescriptEventListenerKeywords contained blur click focus mouseover mouseout load item
|
||||
|
||||
syntax keyword typescriptEventListenerMethods contained scrollIntoView addEventListener dispatchEvent removeEventListener preventDefault stopPropagation
|
||||
endif
|
||||
" }}}
|
||||
"" Programm Keywords"{{{
|
||||
syntax keyword typescriptSource import export from as
|
||||
syntax keyword typescriptIdentifier arguments this void
|
||||
syntax keyword typescriptStorageClass let var const
|
||||
syntax keyword typescriptOperator delete new instanceof typeof
|
||||
syntax keyword typescriptBoolean true false
|
||||
syntax keyword typescriptNull null undefined
|
||||
syntax keyword typescriptMessage alert confirm prompt status
|
||||
syntax keyword typescriptGlobal self top parent
|
||||
syntax keyword typescriptDeprecated escape unescape all applets alinkColor bgColor fgColor linkColor vlinkColor xmlEncoding
|
||||
"}}}
|
||||
"" Statement Keywords"{{{
|
||||
syntax keyword typescriptConditional if else switch
|
||||
syntax keyword typescriptRepeat do while for in of
|
||||
syntax keyword typescriptBranch break continue yield await
|
||||
syntax keyword typescriptLabel case default async readonly
|
||||
syntax keyword typescriptStatement return with
|
||||
|
||||
syntax keyword typescriptGlobalObjects Array Boolean Date Function Infinity JSON Math Number NaN Object Packages RegExp String Symbol netscape ArrayBuffer BigInt64Array BigUint64Array Float32Array Float64Array Int16Array Int32Array Int8Array Uint16Array Uint32Array Uint8Array Uint8ClampedArray Buffer Collator DataView DateTimeFormat Intl Iterator Map Set WeakMap WeakSet NumberFormat ParallelArray Promise Proxy Reflect Uint8ClampedArray WebAssembly console document fetch window
|
||||
syntax keyword typescriptGlobalNodeObjects module exports global process __dirname __filename
|
||||
|
||||
syntax keyword typescriptExceptions try catch throw finally Error EvalError RangeError ReferenceError SyntaxError TypeError URIError
|
||||
|
||||
syntax keyword typescriptReserved constructor declare as interface module abstract enum int short 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 type namespace from get set keyof
|
||||
"}}}
|
||||
"" typescript/DOM/HTML/CSS specified things"{{{
|
||||
|
||||
" typescript Objects"{{{
|
||||
syn match typescriptFunction "(super\s*|constructor\s*)" contained nextgroup=typescriptVars
|
||||
syn region typescriptVars start="(" end=")" contained contains=typescriptParameters transparent keepend
|
||||
syn match typescriptParameters "([a-zA-Z0-9_?.$][\w?.$]*)\s*:\s*([a-zA-Z0-9_?.$][\w?.$]*)" contained skipwhite
|
||||
"}}}
|
||||
" DOM2 Objects"{{{
|
||||
syntax keyword typescriptType DOMImplementation DocumentFragment Node NodeList NamedNodeMap CharacterData Attr Element Text Comment CDATASection DocumentType Notation Entity EntityReference ProcessingInstruction void any string boolean number symbol never object unknown
|
||||
syntax keyword typescriptExceptions DOMException
|
||||
"}}}
|
||||
" DOM2 CONSTANT"{{{
|
||||
syntax keyword typescriptDomErrNo INDEX_SIZE_ERR DOMSTRING_SIZE_ERR HIERARCHY_REQUEST_ERR WRONG_DOCUMENT_ERR INVALID_CHARACTER_ERR NO_DATA_ALLOWED_ERR NO_MODIFICATION_ALLOWED_ERR NOT_FOUND_ERR NOT_SUPPORTED_ERR INUSE_ATTRIBUTE_ERR INVALID_STATE_ERR SYNTAX_ERR INVALID_MODIFICATION_ERR NAMESPACE_ERR INVALID_ACCESS_ERR
|
||||
syntax keyword typescriptDomNodeConsts ELEMENT_NODE ATTRIBUTE_NODE TEXT_NODE CDATA_SECTION_NODE ENTITY_REFERENCE_NODE ENTITY_NODE PROCESSING_INSTRUCTION_NODE COMMENT_NODE DOCUMENT_NODE DOCUMENT_TYPE_NODE DOCUMENT_FRAGMENT_NODE NOTATION_NODE
|
||||
"}}}
|
||||
" HTML events and internal variables"{{{
|
||||
syntax case ignore
|
||||
syntax keyword typescriptHtmlEvents onblur onclick oncontextmenu ondblclick onfocus onkeydown onkeypress onkeyup onmousedown onmousemove onmouseout onmouseover onmouseup onresize onload onsubmit
|
||||
syntax case match
|
||||
"}}}
|
||||
|
||||
" Follow stuff should be highligh within a special context
|
||||
" While it can't be handled with context depended with Regex based highlight
|
||||
" So, turn it off by default
|
||||
if exists("typescript_enable_domhtmlcss")
|
||||
|
||||
" DOM2 things"{{{
|
||||
syntax match typescriptDomElemAttrs contained /\%(nodeName\|nodeValue\|nodeType\|parentNode\|childNodes\|firstChild\|lastChild\|previousSibling\|nextSibling\|attributes\|ownerDocument\|namespaceURI\|prefix\|localName\|tagName\)\>/
|
||||
syntax match typescriptDomElemFuncs contained /\%(insertBefore\|replaceChild\|removeChild\|appendChild\|hasChildNodes\|cloneNode\|normalize\|isSupported\|hasAttributes\|getAttribute\|setAttribute\|removeAttribute\|getAttributeNode\|setAttributeNode\|removeAttributeNode\|getElementsByTagName\|getAttributeNS\|setAttributeNS\|removeAttributeNS\|getAttributeNodeNS\|setAttributeNodeNS\|getElementsByTagNameNS\|hasAttribute\|hasAttributeNS\)\>/ nextgroup=typescriptParen skipwhite
|
||||
"}}}
|
||||
" HTML things"{{{
|
||||
syntax match typescriptHtmlElemAttrs contained /\%(className\|clientHeight\|clientLeft\|clientTop\|clientWidth\|dir\|id\|innerHTML\|lang\|length\|offsetHeight\|offsetLeft\|offsetParent\|offsetTop\|offsetWidth\|scrollHeight\|scrollLeft\|scrollTop\|scrollWidth\|style\|tabIndex\|title\)\>/
|
||||
syntax match typescriptHtmlElemFuncs contained /\%(blur\|click\|focus\|scrollIntoView\|addEventListener\|dispatchEvent\|removeEventListener\|item\)\>/ nextgroup=typescriptParen skipwhite
|
||||
"}}}
|
||||
" CSS Styles in typescript"{{{
|
||||
syntax keyword typescriptCssStyles contained color font fontFamily fontSize fontSizeAdjust fontStretch fontStyle fontVariant fontWeight letterSpacing lineBreak lineHeight quotes rubyAlign rubyOverhang rubyPosition
|
||||
syntax keyword typescriptCssStyles contained textAlign textAlignLast textAutospace textDecoration textIndent textJustify textJustifyTrim textKashidaSpace textOverflowW6 textShadow textTransform textUnderlinePosition
|
||||
syntax keyword typescriptCssStyles contained unicodeBidi whiteSpace wordBreak wordSpacing wordWrap writingMode
|
||||
syntax keyword typescriptCssStyles contained bottom height left position right top width zIndex
|
||||
syntax keyword typescriptCssStyles contained border borderBottom borderLeft borderRight borderTop borderBottomColor borderLeftColor borderTopColor borderBottomStyle borderLeftStyle borderRightStyle borderTopStyle borderBottomWidth borderLeftWidth borderRightWidth borderTopWidth borderColor borderStyle borderWidth borderCollapse borderSpacing captionSide emptyCells tableLayout
|
||||
syntax keyword typescriptCssStyles contained margin marginBottom marginLeft marginRight marginTop outline outlineColor outlineStyle outlineWidth padding paddingBottom paddingLeft paddingRight paddingTop
|
||||
syntax keyword typescriptCssStyles contained listStyle listStyleImage listStylePosition listStyleType
|
||||
syntax keyword typescriptCssStyles contained background backgroundAttachment backgroundColor backgroundImage backgroundPosition backgroundPositionX backgroundPositionY backgroundRepeat
|
||||
syntax keyword typescriptCssStyles contained clear clip clipBottom clipLeft clipRight clipTop content counterIncrement counterReset cssFloat cursor direction display filter layoutGrid layoutGridChar layoutGridLine layoutGridMode layoutGridType
|
||||
syntax keyword typescriptCssStyles contained marks maxHeight maxWidth minHeight minWidth opacity MozOpacity overflow overflowX overflowY verticalAlign visibility zoom cssText
|
||||
syntax keyword typescriptCssStyles contained scrollbar3dLightColor scrollbarArrowColor scrollbarBaseColor scrollbarDarkShadowColor scrollbarFaceColor scrollbarHighlightColor scrollbarShadowColor scrollbarTrackColor
|
||||
"}}}
|
||||
endif "DOM/HTML/CSS
|
||||
|
||||
" Highlight ways"{{{
|
||||
syntax match typescriptDotNotation "\." nextgroup=typescriptPrototype,typescriptDomElemAttrs,typescriptDomElemFuncs,typescriptDOMMethods,typescriptDOMProperties,typescriptHtmlElemAttrs,typescriptHtmlElemFuncs,typescriptHtmlElemProperties,typescriptAjaxProperties,typescriptAjaxMethods,typescriptPropietaryMethods,typescriptEventListenerMethods skipwhite skipnl
|
||||
syntax match typescriptDotNotation "\.style\." nextgroup=typescriptCssStyles
|
||||
"}}}
|
||||
|
||||
"" end DOM/HTML/CSS specified things""}}}
|
||||
|
||||
|
||||
"" Code blocks
|
||||
syntax cluster typescriptAll contains=typescriptComment,typescriptLineComment,typescriptDocComment,typescriptStringD,typescriptStringS,typescriptStringB,typescriptRegexpString,typescriptNumber,typescriptFloat,typescriptDecorators,typescriptLabel,typescriptSource,typescriptType,typescriptOperator,typescriptBoolean,typescriptNull,typescriptFuncKeyword,typescriptConditional,typescriptGlobal,typescriptRepeat,typescriptBranch,typescriptStatement,typescriptGlobalObjects,typescriptMessage,typescriptIdentifier,typescriptStorageClass,typescriptExceptions,typescriptReserved,typescriptDeprecated,typescriptDomErrNo,typescriptDomNodeConsts,typescriptHtmlEvents,typescriptDotNotation,typescriptBrowserObjects,typescriptDOMObjects,typescriptAjaxObjects,typescriptPropietaryObjects,typescriptDOMMethods,typescriptHtmlElemProperties,typescriptDOMProperties,typescriptEventListenerKeywords,typescriptEventListenerMethods,typescriptAjaxProperties,typescriptAjaxMethods,typescriptFuncArg,typescriptGlobalNodeObjects
|
||||
|
||||
if main_syntax == "typescript"
|
||||
syntax sync clear
|
||||
syntax sync ccomment typescriptComment minlines=200
|
||||
" syntax sync match typescriptHighlight grouphere typescriptBlock /{/
|
||||
endif
|
||||
|
||||
syntax keyword typescriptFuncKeyword function
|
||||
"syntax region typescriptFuncDef start="function" end="\(.*\)" contains=typescriptFuncKeyword,typescriptFuncArg keepend
|
||||
"syntax match typescriptFuncArg "\(([^()]*)\)" contains=typescriptParens,typescriptFuncComma contained
|
||||
"syntax match typescriptFuncComma /,/ contained
|
||||
" syntax region typescriptFuncBlock contained matchgroup=typescriptFuncBlock start="{" end="}" contains=@typescriptAll,typescriptParensErrA,typescriptParensErrB,typescriptParen,typescriptBracket,typescriptBlock fold
|
||||
|
||||
syn match typescriptBraces "[{}\[\]]"
|
||||
syn match typescriptParens "[()]"
|
||||
syn match typescriptEndColons "[;,]"
|
||||
syn match typescriptLogicSymbols "\(&&\)\|\(||\)\|\(!\)"
|
||||
syn match typescriptOpSymbols "=\{1,3}\|!==\|!=\|<\|>\|>=\|<=\|++\|+=\|--\|-="
|
||||
|
||||
" typescriptFold Function {{{
|
||||
|
||||
" function! typescriptFold()
|
||||
|
||||
" skip curly braces inside RegEx's and comments
|
||||
syn region foldBraces start=/{/ skip=/\(\/\/.*\)\|\(\/.*\/\)/ end=/}/ transparent fold keepend extend
|
||||
|
||||
" setl foldtext=FoldText()
|
||||
" endfunction
|
||||
|
||||
" au FileType typescript call typescriptFold()
|
||||
|
||||
" }}}
|
||||
|
||||
" Define the default highlighting.
|
||||
" For version 5.7 and earlier: only when not done already by this script
|
||||
" For version 5.8 and later: only when an item doesn't have highlighting yet
|
||||
" For version 8.1.1486 and later: only when not done already by this script (need to override vim's new typescript support)
|
||||
if version >= 508 || !exists("did_typescript_syn_inits")
|
||||
if version < 508 || has('patch-8.1.1486')
|
||||
let did_typescript_syn_inits = 1
|
||||
command -nargs=+ HiLink hi link <args>
|
||||
else
|
||||
command -nargs=+ HiLink hi def link <args>
|
||||
endif
|
||||
|
||||
"typescript highlighting
|
||||
HiLink typescriptParameters Operator
|
||||
HiLink typescriptSuperBlock Operator
|
||||
|
||||
HiLink typescriptEndColons Exception
|
||||
HiLink typescriptOpSymbols Operator
|
||||
HiLink typescriptLogicSymbols Boolean
|
||||
HiLink typescriptBraces Function
|
||||
HiLink typescriptParens Operator
|
||||
HiLink typescriptComment Comment
|
||||
HiLink typescriptLineComment Comment
|
||||
HiLink typescriptRefComment Include
|
||||
HiLink typescriptRefS String
|
||||
HiLink typescriptRefD String
|
||||
HiLink typescriptDocComment Comment
|
||||
HiLink typescriptCommentTodo Todo
|
||||
HiLink typescriptCvsTag Function
|
||||
HiLink typescriptDocTags Special
|
||||
HiLink typescriptDocSeeTag Function
|
||||
HiLink typescriptDocParam Function
|
||||
HiLink typescriptStringS String
|
||||
HiLink typescriptStringD String
|
||||
HiLink typescriptStringB String
|
||||
HiLink typescriptInterpolationDelimiter Delimiter
|
||||
HiLink typescriptRegexpString String
|
||||
HiLink typescriptGlobal Constant
|
||||
HiLink typescriptCharacter Character
|
||||
HiLink typescriptPrototype Type
|
||||
HiLink typescriptConditional Conditional
|
||||
HiLink typescriptBranch Conditional
|
||||
HiLink typescriptIdentifier Identifier
|
||||
HiLink typescriptStorageClass StorageClass
|
||||
HiLink typescriptRepeat Repeat
|
||||
HiLink typescriptStatement Statement
|
||||
HiLink typescriptFuncKeyword Keyword
|
||||
HiLink typescriptMessage Keyword
|
||||
HiLink typescriptDeprecated Exception
|
||||
HiLink typescriptError Error
|
||||
HiLink typescriptParensError Error
|
||||
HiLink typescriptParensErrA Error
|
||||
HiLink typescriptParensErrB Error
|
||||
HiLink typescriptParensErrC Error
|
||||
HiLink typescriptReserved Keyword
|
||||
HiLink typescriptOperator Operator
|
||||
HiLink typescriptType Type
|
||||
HiLink typescriptNull Type
|
||||
HiLink typescriptNumber Number
|
||||
HiLink typescriptFloat Number
|
||||
HiLink typescriptDecorators Special
|
||||
HiLink typescriptBoolean Boolean
|
||||
HiLink typescriptLabel Label
|
||||
HiLink typescriptSpecial Special
|
||||
HiLink typescriptSource Special
|
||||
HiLink typescriptGlobalObjects Special
|
||||
HiLink typescriptGlobalNodeObjects Special
|
||||
HiLink typescriptExceptions Special
|
||||
|
||||
HiLink typescriptDomErrNo Constant
|
||||
HiLink typescriptDomNodeConsts Constant
|
||||
HiLink typescriptDomElemAttrs Label
|
||||
HiLink typescriptDomElemFuncs PreProc
|
||||
|
||||
HiLink typescriptHtmlElemAttrs Label
|
||||
HiLink typescriptHtmlElemFuncs PreProc
|
||||
|
||||
HiLink typescriptCssStyles Label
|
||||
|
||||
" Ajax Highlighting
|
||||
HiLink typescriptBrowserObjects Constant
|
||||
|
||||
HiLink typescriptDOMObjects Constant
|
||||
HiLink typescriptDOMMethods Function
|
||||
HiLink typescriptDOMProperties Special
|
||||
|
||||
HiLink typescriptAjaxObjects Constant
|
||||
HiLink typescriptAjaxMethods Function
|
||||
HiLink typescriptAjaxProperties Special
|
||||
|
||||
HiLink typescriptFuncDef Title
|
||||
HiLink typescriptFuncArg Special
|
||||
HiLink typescriptFuncComma Operator
|
||||
|
||||
HiLink typescriptHtmlEvents Special
|
||||
HiLink typescriptHtmlElemProperties Special
|
||||
|
||||
HiLink typescriptEventListenerKeywords Keyword
|
||||
|
||||
HiLink typescriptNumber Number
|
||||
HiLink typescriptPropietaryObjects Constant
|
||||
|
||||
delcommand HiLink
|
||||
endif
|
||||
|
||||
" Define the htmltypescript for HTML syntax html.vim
|
||||
"syntax clear htmltypescript
|
||||
"syntax clear typescriptExpression
|
||||
syntax cluster htmltypescript contains=@typescriptAll,typescriptBracket,typescriptParen,typescriptBlock,typescriptParenError
|
||||
syntax cluster typescriptExpression contains=@typescriptAll,typescriptBracket,typescriptParen,typescriptBlock,typescriptParenError,@htmlPreproc
|
||||
|
||||
let b:current_syntax = "typescript"
|
||||
if main_syntax == 'typescript'
|
||||
unlet main_syntax
|
||||
endif
|
||||
|
||||
" vim: ts=4
|
@ -1 +0,0 @@
|
||||
runtime! syntax/typescript.vim
|
Binary file not shown.
Before Width: | Height: | Size: 19 KiB |
@ -1,4 +0,0 @@
|
||||
.*.sw[a-z]
|
||||
.*.un~
|
||||
doc/tags
|
||||
|
@ -1,54 +0,0 @@
|
||||
All files except:
|
||||
|
||||
ftdetect/vim-literate-coffeescript.vim
|
||||
indent/litcoffee.vim
|
||||
syntax/litcoffee.vim
|
||||
test/test.coffee.md
|
||||
test/test.litcoffee
|
||||
test/test.png
|
||||
|
||||
Issued under WTFPL:
|
||||
|
||||
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
||||
Version 2, December 2004
|
||||
|
||||
Copyright (C) 2010 to 2014 Mick Koch <mick@kochm.co>
|
||||
|
||||
Everyone is permitted to copy and distribute verbatim or modified
|
||||
copies of this license document, and changing it is allowed as long
|
||||
as the name is changed.
|
||||
|
||||
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. You just DO WHAT THE FUCK YOU WANT TO.
|
||||
|
||||
|
||||
These files issed under this license:
|
||||
|
||||
ftdetect/vim-literate-coffeescript.vim
|
||||
indent/litcoffee.vim
|
||||
syntax/litcoffee.vim
|
||||
test/test.coffee.md
|
||||
test/test.litcoffee
|
||||
test/test.png
|
||||
|
||||
Copyright (c) 2013 Michael Smith
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
@ -1,25 +0,0 @@
|
||||
REF = HEAD
|
||||
VERSION = $(shell git describe --always $(REF))
|
||||
|
||||
ARCHIVE = vim-coffee-script-$(VERSION).zip
|
||||
ARCHIVE_DIRS = after autoload compiler doc ftdetect ftplugin indent syntax
|
||||
|
||||
# Don't do anything by default.
|
||||
all:
|
||||
|
||||
# Make vim.org zipball.
|
||||
archive:
|
||||
git archive $(REF) -o $(ARCHIVE) -- $(ARCHIVE_DIRS)
|
||||
|
||||
# Remove zipball.
|
||||
clean:
|
||||
-rm -f $(ARCHIVE)
|
||||
|
||||
# Build the list of syntaxes for @coffeeAll.
|
||||
coffeeAll:
|
||||
@grep -E 'syn (match|region)' syntax/coffee.vim |\
|
||||
grep -v 'contained' |\
|
||||
awk '{print $$3}' |\
|
||||
uniq
|
||||
|
||||
.PHONY: all archive clean hash coffeeAll
|
@ -1,22 +0,0 @@
|
||||
### Version 003 (October 10, 2014)
|
||||
|
||||
Almost 3 years' worth of fixes and (hopefully) improvements.
|
||||
|
||||
### Version 002 (December 5, 2011)
|
||||
|
||||
Added binary numbers (0b0101) and fixed some bugs (#9, #62, #63, #65).
|
||||
|
||||
### Version 001 (October 18, 2011)
|
||||
|
||||
Removed deprecated `coffee_folding` option, added `coffee_compile_vert` option,
|
||||
split out compiler, fixed indentation and syntax bugs, and added Haml support
|
||||
and omnicompletion.
|
||||
|
||||
- The coffee compiler is now a proper vim compiler that can be loaded with
|
||||
`:compiler coffee`.
|
||||
- The `coffee_compile_vert` option can now be set to split the CoffeeCompile
|
||||
buffer vertically by default.
|
||||
- CoffeeScript is now highlighted inside the `:coffeescript` filter in Haml.
|
||||
- Omnicompletion (`:help compl-omni`) now uses JavaScript's dictionary to
|
||||
complete words.
|
||||
- We now have a fancy version number.
|
@ -1,591 +0,0 @@
|
||||
This project adds [CoffeeScript] support to vim. It covers syntax, indenting,
|
||||
compiling, and more.
|
||||
|
||||

|
||||
|
||||
[CoffeeScript]: http://coffeescript.org/
|
||||
|
||||
## Table of Contents
|
||||
|
||||
- Installation
|
||||
- [Requirements](#requirements)
|
||||
- [Install using Pathogen](#install-using-pathogen)
|
||||
- [Install using Vundle](#install-using-vundle)
|
||||
- [Install from a Zip File](#install-from-a-zip-file)
|
||||
- Coffee Commands
|
||||
- [Compile to JavaScript](#compile-to-javascript)
|
||||
- [Compile CoffeeScript Snippets](#coffeecompile-compile-coffeescript-snippets)
|
||||
- [Live Preview Compiling](#coffeewatch-live-preview-compiling)
|
||||
- [Run CoffeeScript Snippets](#coffeerun-run-coffeescript-snippets)
|
||||
- [Lint your CoffeeScript](#coffeelint-lint-your-coffeescript)
|
||||
- Extras
|
||||
- [Literate CoffeeScript](#literate-coffeescript)
|
||||
- [CoffeeScript in HTML](#coffeescript-in-html)
|
||||
- [CoffeeScript in Haml](#coffeescript-in-haml)
|
||||
- Configuration
|
||||
- [Custom Autocmds](#custom-autocmds)
|
||||
- [Configuration Variables](#configuration-variables)
|
||||
- [Configure Syntax Highlighting](#configure-syntax-highlighting)
|
||||
- [Tune Vim for CoffeeScript](#tune-vim-for-coffeescript)
|
||||
|
||||
## Requirements
|
||||
|
||||
- vim 7.4 or later
|
||||
- coffee 1.2.0 or later
|
||||
|
||||
## Install using Pathogen
|
||||
|
||||
This project uses rolling releases based on git commits, so pathogen is a
|
||||
natural fit for it. If you're already using pathogen, you can skip to step 4.
|
||||
|
||||
1. Install [pathogen.vim] into `~/.vim/autoload/` (see [pathogen's
|
||||
readme][install-pathogen] for more information.)
|
||||
|
||||
[pathogen.vim]: http://www.vim.org/scripts/script.php?script_id=2332
|
||||
[install-pathogen]: https://github.com/tpope/vim-pathogen#installation
|
||||
|
||||
2. Enable pathogen in your vimrc. Here's a bare-minimum vimrc that enables
|
||||
all the features of `vim-coffee-script`:
|
||||
|
||||
```vim
|
||||
call pathogen#infect()
|
||||
syntax enable
|
||||
filetype plugin indent on
|
||||
```
|
||||
|
||||
If you already have a vimrc built up, just make sure it contains these calls,
|
||||
in this order.
|
||||
|
||||
3. Create the directory `~/.vim/bundle/`:
|
||||
|
||||
mkdir ~/.vim/bundle
|
||||
|
||||
4. Clone the `vim-coffee-script` repo into `~/.vim/bundle/`:
|
||||
|
||||
git clone https://github.com/kchmck/vim-coffee-script.git ~/.vim/bundle/vim-coffee-script/
|
||||
|
||||
Updating takes two steps:
|
||||
|
||||
1. Change into `~/.vim/bundle/vim-coffee-script/`:
|
||||
|
||||
cd ~/.vim/bundle/vim-coffee-script
|
||||
|
||||
2. Pull in the latest changes:
|
||||
|
||||
git pull
|
||||
|
||||
## Install using Vundle
|
||||
|
||||
1. [Install Vundle] into `~/.vim/bundle/`.
|
||||
|
||||
[Install Vundle]: https://github.com/gmarik/vundle#quick-start
|
||||
|
||||
2. Configure your vimrc for Vundle. Here's a bare-minimum vimrc that enables all
|
||||
the features of `vim-coffee-script`:
|
||||
|
||||
|
||||
```vim
|
||||
set nocompatible
|
||||
filetype off
|
||||
|
||||
set rtp+=~/.vim/bundle/vundle/
|
||||
call vundle#rc()
|
||||
|
||||
Plugin 'kchmck/vim-coffee-script'
|
||||
|
||||
syntax enable
|
||||
filetype plugin indent on
|
||||
```
|
||||
|
||||
If you're adding Vundle to a built-up vimrc, just make sure all these calls
|
||||
are in there and that they occur in this order.
|
||||
|
||||
3. Open vim and run `:PluginInstall`.
|
||||
|
||||
To update, open vim and run `:PluginInstall!` (notice the bang!)
|
||||
|
||||
## Install from a Zip File
|
||||
|
||||
1. Download the latest zip file from [vim.org][zip].
|
||||
|
||||
2. Extract the archive into `~/.vim/`:
|
||||
|
||||
unzip -od ~/.vim/ ARCHIVE.zip
|
||||
|
||||
This should create the files `~/.vim/autoload/coffee.vim`,
|
||||
`~/.vim/compiler/coffee.vim`, etc.
|
||||
|
||||
You can update the plugin using the same steps.
|
||||
|
||||
[zip]: http://www.vim.org/scripts/script.php?script_id=3590
|
||||
|
||||
## Compile to JavaScript
|
||||
|
||||
A `coffee` wrapper for use with `:make` is enabled automatically for coffee
|
||||
files if no other compiler is loaded. To enable it manually, run
|
||||
|
||||
:compiler coffee
|
||||
|
||||
The `:make` command is then configured to use the `coffee` compiler and
|
||||
recognize its errors. I've included a quick reference here but be sure to check
|
||||
out [`:help :make`][make] for a full reference of the command.
|
||||
|
||||

|
||||
|
||||

|
||||
|
||||
[make]: http://vimdoc.sourceforge.net/htmldoc/quickfix.html#:make_makeprg
|
||||
|
||||
Consider the full signature of a `:make` call as
|
||||
|
||||
:[silent] make[!] [COFFEE-OPTIONS]...
|
||||
|
||||
By default `:make` shows all compiler output and jumps to the first line
|
||||
reported as an error. Compiler output can be hidden with a leading `:silent`:
|
||||
|
||||
:silent make
|
||||
|
||||
Line-jumping can be turned off by adding a bang:
|
||||
|
||||
:make!
|
||||
|
||||
`COFFEE-OPTIONS` given to `:make` are passed along to `coffee` (see also
|
||||
[`coffee_make_options`](#coffee_make_options)):
|
||||
|
||||
:make --bare --output /some/dir
|
||||
|
||||
See the [full table of options](http://coffeescript.org/#usage) for a
|
||||
list of all the options that `coffee` recognizes.
|
||||
|
||||
*Configuration*: [`coffee_compiler`](#coffee_compiler),
|
||||
[`coffee_make_options`](#coffee_make_options)
|
||||
|
||||
#### The quickfix window
|
||||
|
||||
Compiler errors are added to the [quickfix] list by `:make`, but the quickfix
|
||||
window isn't automatically shown. The [`:cwindow`][cwindow] command will pop up
|
||||
the quickfix window if there are any errors:
|
||||
|
||||
:make
|
||||
:cwindow
|
||||
|
||||
This is usually the desired behavior, so you may want to add an autocmd to your
|
||||
vimrc to do this automatically:
|
||||
|
||||
autocmd QuickFixCmdPost * nested cwindow | redraw!
|
||||
|
||||
The `redraw!` command is needed to fix a redrawing quirk in terminal vim, but
|
||||
can removed for gVim.
|
||||
|
||||
[quickfix]: http://vimdoc.sourceforge.net/htmldoc/quickfix.html#quickfix
|
||||
[cwindow]: http://vimdoc.sourceforge.net/htmldoc/quickfix.html#:cwindow
|
||||
|
||||
#### Recompile on write
|
||||
|
||||
To recompile a file when it's written, add a `BufWritePost` autocmd to your
|
||||
vimrc:
|
||||
|
||||
autocmd BufWritePost *.coffee silent make!
|
||||
|
||||
#### Cake and Cakefiles
|
||||
|
||||
A `cake` compiler is also available with the call
|
||||
|
||||
:compiler cake
|
||||
|
||||
You can then use `:make` as above to run your Cakefile and capture any `coffee`
|
||||
errors:
|
||||
|
||||
:silent make build
|
||||
|
||||
It runs within the current directory, so make sure you're in the directory of
|
||||
your Cakefile before calling it.
|
||||
|
||||
*Configuration*: [`coffee_cake`](#coffee_cake),
|
||||
[`coffee_cake_options`](#coffee_cake_options)
|
||||
|
||||
## CoffeeCompile: Compile CoffeeScript Snippets
|
||||
|
||||
CoffeeCompile shows how the current file or a snippet of CoffeeScript is
|
||||
compiled to JavaScript.
|
||||
|
||||
:[RANGE] CoffeeCompile [vert[ical]] [WINDOW-SIZE]
|
||||
|
||||
Calling `:CoffeeCompile` without a range compiles the whole file:
|
||||
|
||||

|
||||
|
||||

|
||||
|
||||
Calling it with a range, like in visual mode, compiles only the selected snippet
|
||||
of CoffeeScript:
|
||||
|
||||

|
||||
|
||||

|
||||
|
||||
Each file gets its own CoffeeCompile buffer, and the same buffer is used for all
|
||||
future calls of `:CoffeeCompile` on that file. It can be quickly closed by
|
||||
hitting `q` in normal mode.
|
||||
|
||||
Using `vert` opens the CoffeeCompile buffer vertically instead of horizontally
|
||||
(see also [`coffee_compile_vert`](#coffee_compile_vert)):
|
||||
|
||||
:CoffeeCompile vert
|
||||
|
||||
By default the CoffeeCompile buffer splits the source buffer in half, but this
|
||||
can be overridden by passing in a `WINDOW-SIZE`:
|
||||
|
||||
:CoffeeCompile 4
|
||||
|
||||
*Configuration*: [`coffee_compiler`](#coffee_compiler`),
|
||||
[`coffee_compile_vert`](#coffee_compile_vert)
|
||||
|
||||
#### Quick syntax checking
|
||||
|
||||
If compiling a snippet results in a compiler error, CoffeeCompile adds that
|
||||
error to the [quickfix] list.
|
||||
|
||||
[quickfix]: http://vimdoc.sourceforge.net/htmldoc/quickfix.html#quickfix
|
||||
|
||||

|
||||
|
||||

|
||||
|
||||
You can use this to quickly check the syntax of a snippet.
|
||||
|
||||
## CoffeeWatch: Live Preview Compiling
|
||||
|
||||
CoffeeWatch emulates using the Try CoffeeScript preview box on the [CoffeeScript
|
||||
homepage][CoffeeScript].
|
||||
|
||||

|
||||
|
||||

|
||||
|
||||
CoffeeWatch takes the same options as CoffeeCompile:
|
||||
|
||||
:CoffeeWatch [vert[ical]] [WINDOW-SIZE]
|
||||
|
||||
After a source buffer is watched, leaving insert mode or saving the file fires
|
||||
off a recompile of the CoffeeScript:
|
||||
|
||||

|
||||
|
||||

|
||||
|
||||
You can force recompilation by calling `:CoffeeWatch`.
|
||||
|
||||
To get synchronized scrolling of the source buffer and CoffeeWatch buffer, set
|
||||
[`'scrollbind'`](http://vimdoc.sourceforge.net/htmldoc/options.html#'scrollbind')
|
||||
on each:
|
||||
|
||||
:setl scrollbind
|
||||
|
||||
*Configuration*: [`coffee_compiler`](#coffee_compiler),
|
||||
[`coffee_watch_vert`](#coffee_watch_vert)
|
||||
|
||||
## CoffeeRun: Run CoffeeScript Snippets
|
||||
|
||||
CoffeeRun compiles the current file or selected snippet and runs the resulting
|
||||
JavaScript.
|
||||
|
||||

|
||||
|
||||

|
||||
|
||||
The command has two forms:
|
||||
|
||||
:CoffeeRun [PROGRAM-OPTIONS]...
|
||||
|
||||
This form applies when no `RANGE` is given or when the given range is `1,$`
|
||||
(first line to last line). It allows passing `PROGRAM-OPTIONS` to your compiled
|
||||
program. The filename is passed directly to `coffee` so you must save the file
|
||||
for your changes to take effect.
|
||||
|
||||
:RANGE CoffeeRun [COFFEE-OPTIONS]...
|
||||
|
||||
This form applies with all other ranges. It compiles and runs the lines within
|
||||
the given `RANGE` and any extra `COFFEE-OPTIONS` are passed to `coffee`.
|
||||
|
||||
*Configuration*: [`coffee_compiler`](#coffee_compiler),
|
||||
[`coffee_run_vert`](#coffee_run_vert)
|
||||
|
||||
## CoffeeLint: Lint your CoffeeScript
|
||||
|
||||
CoffeeLint runs [coffeelint](http://www.coffeelint.org/) (version 1.4.0 or later
|
||||
required) on the current file and adds any issues to the [quickfix] list.
|
||||
|
||||

|
||||
|
||||

|
||||
|
||||
:[RANGE] CoffeeLint[!] [COFFEELINT-OPTIONS]... [ | cwindow]
|
||||
|
||||
If a `RANGE` is given, only those lines are piped to `coffeelint`. Options given
|
||||
in `COFFEELINT-OPTIONS` are passed to `coffeelint` (see also
|
||||
[`coffee_lint_options`](#coffee_lint_options)):
|
||||
|
||||
:CoffeeLint -f lint.json
|
||||
|
||||
It behaves very similar to `:make`, described [above](#compile-to-javascript).
|
||||
|
||||
:CoffeeLint! | cwindow
|
||||
|
||||
*Configuration*: [`coffee_linter`](#coffee_linter),
|
||||
[`coffee_lint_options`](#coffee_lint_options)
|
||||
|
||||
## Literate CoffeeScript
|
||||
|
||||
Literate CoffeeScript syntax and indent support is now built in! The `Coffee`
|
||||
commands detect when they're running on a litcoffee file and pass the
|
||||
`--literate` flag to their respective tools.
|
||||
|
||||
Literate CoffeeScript syntax and indent support was written by @mintplant
|
||||
(Michael Smith). A standalone repo
|
||||
[exists](https://github.com/jwhitley/vim-literate-coffeescript), but you'll
|
||||
need to copy the `ftplugin/litcoffee.vim` file or set up an autocmd to get the
|
||||
`Coffee` commands to be automatically loaded for litcoffee files.
|
||||
|
||||
## CoffeeScript in HTML
|
||||
|
||||
CoffeeScript is highlighted and indented within
|
||||
|
||||
```html
|
||||
<script type="text/coffeescript">
|
||||
</script>
|
||||
```
|
||||
|
||||
blocks in html files.
|
||||
|
||||
## CoffeeScript in Haml
|
||||
|
||||
CoffeeScript is highlighted within the `:coffeescript` filter in haml files:
|
||||
|
||||
```haml
|
||||
:coffeescript
|
||||
console.log "hullo"
|
||||
```
|
||||
|
||||
At this time, coffee indenting doesn't work in these blocks.
|
||||
|
||||
## Custom Autocmds
|
||||
|
||||
You can [define commands][autocmd-explain] to be ran automatically on these
|
||||
custom events.
|
||||
|
||||
In all cases, the name of the command running the event (`CoffeeCompile`,
|
||||
`CoffeeWatch`, or `CoffeeRun`) is matched by the [`{pat}`][autocmd] argument.
|
||||
You can match all commands with a `*` or only specific commands by separating
|
||||
them with a comma: `CoffeeCompile,CoffeeWatch`.
|
||||
|
||||
[autocmd-explain]: http://vimdoc.sourceforge.net/htmldoc/usr_40.html#40.3
|
||||
[autocmd]: http://vimdoc.sourceforge.net/htmldoc/autocmd.html#:autocmd
|
||||
|
||||
#### CoffeeBufNew
|
||||
|
||||
CoffeeBufNew is ran when a new scratch buffer is created. It's called from the
|
||||
new buffer, so it can be used to do additional set up.
|
||||
|
||||
```vim
|
||||
augroup CoffeeBufNew
|
||||
autocmd User * set wrap
|
||||
augroup END
|
||||
```
|
||||
|
||||
*Used By*: CoffeeCompile, CoffeeWatch, CoffeeRun
|
||||
|
||||
#### CoffeeBufUpdate
|
||||
|
||||
CoffeeBufUpdate is ran when a scratch buffer is updated with output from
|
||||
`coffee`. It's called from the scratch buffer, so it can be used to alter the
|
||||
compiled output.
|
||||
|
||||
```vim
|
||||
" Switch back to the source buffer after updating.
|
||||
augroup CoffeeBufUpdate
|
||||
autocmd User CoffeeCompile,CoffeeRun exec bufwinnr(b:coffee_src_buf) 'wincmd w'
|
||||
augroup END
|
||||
```
|
||||
|
||||
For example, to strip off the "Generated by" comment on the first line, put this
|
||||
in your vimrc:
|
||||
|
||||
```vim
|
||||
function! s:RemoveGeneratedBy()
|
||||
" If there was an error compiling, there's no comment to remove.
|
||||
if v:shell_error
|
||||
return
|
||||
endif
|
||||
|
||||
" Save cursor position.
|
||||
let pos = getpos('.')
|
||||
|
||||
" Remove first line.
|
||||
set modifiable
|
||||
1 delete _
|
||||
set nomodifiable
|
||||
|
||||
" Restore cursor position.
|
||||
call setpos('.', pos)
|
||||
endfunction
|
||||
|
||||
augroup CoffeeBufUpdate
|
||||
autocmd User CoffeeCompile,CoffeeWatch call s:RemoveGeneratedBy()
|
||||
augroup END
|
||||
```
|
||||
|
||||
*Used By*: CoffeeCompile, CoffeeWatch, CoffeeRun
|
||||
|
||||
## Configuration Variables
|
||||
|
||||
This is the full list of configuration variables available, with example
|
||||
settings and default values. Use these in your vimrc to control the default
|
||||
behavior.
|
||||
|
||||
#### coffee\_indent\_keep\_current
|
||||
|
||||
By default, the indent function matches the indent of the previous line if it
|
||||
doesn't find a reason to indent or outdent. To change this behavior so it
|
||||
instead keeps the [current indent of the cursor][98], use
|
||||
|
||||
let coffee_indent_keep_current = 1
|
||||
|
||||
[98]: https://github.com/kchmck/vim-coffee-script/pull/98
|
||||
|
||||
*Default*: `unlet coffee_indent_keep_current`
|
||||
|
||||
Note that if you change this after a coffee file has been loaded, you'll have to
|
||||
reload the indent script for the change to take effect:
|
||||
|
||||
unlet b:did_indent | runtime indent/coffee.vim
|
||||
|
||||
#### coffee\_compiler
|
||||
|
||||
Path to the `coffee` executable used by the `Coffee` commands:
|
||||
|
||||
let coffee_compiler = '/usr/bin/coffee'
|
||||
|
||||
*Default*: `'coffee'` (search `$PATH` for executable)
|
||||
|
||||
#### coffee\_make\_options
|
||||
|
||||
Options to pass to `coffee` with `:make`:
|
||||
|
||||
let coffee_make_options = '--bare'
|
||||
|
||||
*Default*: `''` (nothing)
|
||||
|
||||
Note that `coffee_make_options` is embedded into `'makeprg'`, so `:compiler
|
||||
coffee` must be ran after changing `coffee_make_options` for the changes to take
|
||||
effect.
|
||||
|
||||
#### coffee\_cake
|
||||
|
||||
Path to the `cake` executable:
|
||||
|
||||
let coffee_cake = '/opt/bin/cake'
|
||||
|
||||
*Default*: `'cake'` (search `$PATH` for executable)
|
||||
|
||||
#### coffee\_cake\_options
|
||||
|
||||
Options to pass to `cake` with `:make`:
|
||||
|
||||
let coffee_cake_options = 'build'
|
||||
|
||||
*Default*: `''` (nothing)
|
||||
|
||||
#### coffee\_linter
|
||||
|
||||
Path to the `coffeelint` executable:
|
||||
|
||||
let coffee_linter = '/opt/bin/coffeelint'
|
||||
|
||||
*Default*: `'coffeelint'` (search `$PATH` for executable)
|
||||
|
||||
#### coffee\_lint\_options
|
||||
|
||||
Options to pass to `coffeelint`:
|
||||
|
||||
let coffee_lint_options = '-f lint.json'
|
||||
|
||||
*Default*: `''` (nothing)
|
||||
|
||||
#### coffee\_compile\_vert
|
||||
|
||||
Open the CoffeeCompile buffer with a vertical split instead of a horizontal
|
||||
one:
|
||||
|
||||
let coffee_compile_vert = 1
|
||||
|
||||
*Default*: `unlet coffee_compile_vert`
|
||||
|
||||
#### coffee\_watch\_vert
|
||||
|
||||
Open the CoffeeWatch buffer with a vertical split instead of a horizontal
|
||||
one:
|
||||
|
||||
let coffee_watch_vert = 1
|
||||
|
||||
*Default*: `unlet coffee_watch_vert`
|
||||
|
||||
#### coffee\_run\_vert
|
||||
|
||||
Open the CoffeeRun buffer with a vertical split instead of a horizontal
|
||||
one:
|
||||
|
||||
let coffee_run_vert = 1
|
||||
|
||||
*Default*: `unlet coffee_run_vert`
|
||||
|
||||
## Configure Syntax Highlighting
|
||||
|
||||
Add these lines to your vimrc to disable the relevant syntax group.
|
||||
|
||||
#### Disable trailing whitespace error
|
||||
|
||||
Trailing whitespace is highlighted as an error by default. This can be disabled
|
||||
with:
|
||||
|
||||
hi link coffeeSpaceError NONE
|
||||
|
||||
#### Disable trailing semicolon error
|
||||
|
||||
Trailing semicolons are considered an error (for help transitioning from
|
||||
JavaScript.) This can be disabled with:
|
||||
|
||||
hi link coffeeSemicolonError NONE
|
||||
|
||||
#### Disable reserved words error
|
||||
|
||||
Reserved words like `function` and `var` are highlighted as an error where
|
||||
they're not allowed in CoffeeScript. This can be disabled with:
|
||||
|
||||
hi link coffeeReservedError NONE
|
||||
|
||||
## Tune Vim for CoffeeScript
|
||||
|
||||
Changing these core settings can make vim more CoffeeScript friendly.
|
||||
|
||||
#### Fold by indentation
|
||||
|
||||
Folding by indentation works well for CoffeeScript functions and classes:
|
||||
|
||||

|
||||
|
||||
To fold by indentation in CoffeeScript files, add this line to your vimrc:
|
||||
|
||||
autocmd BufNewFile,BufReadPost *.coffee setl foldmethod=indent nofoldenable
|
||||
|
||||
With this, folding is disabled by default but can be quickly toggled per-file
|
||||
by hitting `zi`. To enable folding by default, remove `nofoldenable`:
|
||||
|
||||
autocmd BufNewFile,BufReadPost *.coffee setl foldmethod=indent
|
||||
|
||||
#### Two-space indentation
|
||||
|
||||
To get standard two-space indentation in CoffeeScript files, add this line to
|
||||
your vimrc:
|
||||
|
||||
autocmd BufNewFile,BufReadPost *.coffee setl shiftwidth=2 expandtab
|
@ -1,44 +0,0 @@
|
||||
Thanks to all bug reporters, and special thanks to those who have contributed
|
||||
code:
|
||||
|
||||
Brian Egan (brianegan):
|
||||
Initial compiling support
|
||||
|
||||
Ches Martin (ches):
|
||||
Initial vim docs
|
||||
|
||||
Chris Hoffman (cehoffman):
|
||||
Add new keywoards from, to, and do
|
||||
Highlight the - in negative integers
|
||||
Add here regex highlighting, increase fold level for here docs
|
||||
|
||||
David Wilhelm (bigfish):
|
||||
CoffeeRun command
|
||||
|
||||
Jay Adkisson (jayferd):
|
||||
Support for eco templates
|
||||
|
||||
Karl Guertin (grayrest)
|
||||
Cakefiles are coffeescript
|
||||
|
||||
Maciej Konieczny (narfdotpl):
|
||||
Fix funny typo
|
||||
|
||||
Matt Sacks (mattsa):
|
||||
Javascript omni-completion
|
||||
coffee_compile_vert option
|
||||
|
||||
Nick Stenning (nickstenning):
|
||||
Fold by indentation for coffeescript
|
||||
|
||||
Simon Lipp (sloonz):
|
||||
Trailing spaces are not error on lines containing only spaces
|
||||
|
||||
Stéphan Kochen (stephank):
|
||||
Initial HTML CoffeeScript highlighting
|
||||
|
||||
Sven Felix Oberquelle (Svelix):
|
||||
Haml CoffeeScript highlighting
|
||||
|
||||
Wei Dai (clvv):
|
||||
Fix the use of Vim built-in make command.
|
@ -1 +0,0 @@
|
||||
- Don't highlight bad operator combinations
|
@ -1,33 +0,0 @@
|
||||
" Language: CoffeeScript
|
||||
" Maintainer: Mick Koch <mick@kochm.co>
|
||||
" URL: http://github.com/kchmck/vim-coffee-script
|
||||
" License: WTFPL
|
||||
|
||||
" Load the coffee and html indent functions.
|
||||
silent! unlet b:did_indent
|
||||
runtime indent/coffee.vim
|
||||
let s:coffeeIndentExpr = &l:indentexpr
|
||||
|
||||
" Load html last so it can overwrite coffee settings.
|
||||
silent! unlet b:did_indent
|
||||
runtime indent/html.vim
|
||||
let s:htmlIndentExpr = &l:indentexpr
|
||||
|
||||
" Inject our wrapper indent function.
|
||||
setlocal indentexpr=GetCoffeeHtmlIndent(v:lnum)
|
||||
|
||||
function! GetCoffeeHtmlIndent(curlinenum)
|
||||
" See if we're inside a coffeescript block.
|
||||
let scriptlnum = searchpair('<script [^>]*type=[''"]\?text/coffeescript[''"]\?[^>]*>', '',
|
||||
\ '</script>', 'bWn')
|
||||
let prevlnum = prevnonblank(a:curlinenum)
|
||||
|
||||
" If we're in the script block and the previous line isn't the script tag
|
||||
" itself, use coffee indenting.
|
||||
if scriptlnum && scriptlnum != prevlnum
|
||||
exec 'return ' s:coffeeIndentExpr
|
||||
endif
|
||||
|
||||
" Otherwise use html indenting.
|
||||
exec 'return ' s:htmlIndentExpr
|
||||
endfunction
|
@ -1,23 +0,0 @@
|
||||
" Language: CoffeeScript
|
||||
" Maintainer: Sven Felix Oberquelle <Svelix.Github@gmail.com>
|
||||
" URL: http://github.com/kchmck/vim-coffee-script
|
||||
" License: WTFPL
|
||||
|
||||
|
||||
if exists('b:current_syntax')
|
||||
let s:current_syntax_save = b:current_syntax
|
||||
endif
|
||||
|
||||
" Inherit coffee from html so coffeeComment isn't redefined and given higher
|
||||
" priority than hamlInterpolation.
|
||||
syn cluster hamlCoffeescript contains=@htmlCoffeeScript
|
||||
syn region hamlCoffeescriptFilter matchgroup=hamlFilter
|
||||
\ start="^\z(\s*\):coffee\z(script\)\?\s*$"
|
||||
\ end="^\%(\z1 \| *$\)\@!"
|
||||
\ contains=@hamlCoffeeScript,hamlInterpolation
|
||||
\ keepend
|
||||
|
||||
if exists('s:current_syntax_save')
|
||||
let b:current_syntax = s:current_syntax_save
|
||||
unlet s:current_syntax_save
|
||||
endif
|
@ -1,20 +0,0 @@
|
||||
" Language: CoffeeScript
|
||||
" Maintainer: Mick Koch <mick@kochm.co>
|
||||
" URL: http://github.com/kchmck/vim-coffee-script
|
||||
" License: WTFPL
|
||||
|
||||
if exists('b:current_syntax')
|
||||
let s:current_syntax_save = b:current_syntax
|
||||
endif
|
||||
|
||||
" Syntax highlighting for text/coffeescript script tags
|
||||
syn include @htmlCoffeeScript syntax/coffee.vim
|
||||
syn region coffeeScript start=#<script [^>]*type=['"]\?text/coffeescript['"]\?[^>]*>#
|
||||
\ end=#</script>#me=s-1 keepend
|
||||
\ contains=@htmlCoffeeScript,htmlScriptTag,@htmlPreproc
|
||||
\ containedin=htmlHead
|
||||
|
||||
if exists('s:current_syntax_save')
|
||||
let b:current_syntax = s:current_syntax_save
|
||||
unlet s:current_syntax_save
|
||||
endif
|
@ -1,54 +0,0 @@
|
||||
" Language: CoffeeScript
|
||||
" Maintainer: Mick Koch <mick@kochm.co>
|
||||
" URL: http://github.com/kchmck/vim-coffee-script
|
||||
" License: WTFPL
|
||||
|
||||
" Set up some common global/buffer variables.
|
||||
function! coffee#CoffeeSetUpVariables()
|
||||
" Path to coffee executable
|
||||
if !exists('g:coffee_compiler')
|
||||
let g:coffee_compiler = 'coffee'
|
||||
endif
|
||||
|
||||
" Options passed to coffee with make
|
||||
if !exists('g:coffee_make_options')
|
||||
let g:coffee_make_options = ''
|
||||
endif
|
||||
|
||||
" Path to cake executable
|
||||
if !exists('g:coffee_cake')
|
||||
let g:coffee_cake = 'cake'
|
||||
endif
|
||||
|
||||
" Extra options passed to cake
|
||||
if !exists('g:coffee_cake_options')
|
||||
let g:coffee_cake_options = ''
|
||||
endif
|
||||
|
||||
" Path to coffeelint executable
|
||||
if !exists('g:coffee_linter')
|
||||
let g:coffee_linter = 'coffeelint'
|
||||
endif
|
||||
|
||||
" Options passed to CoffeeLint
|
||||
if !exists('g:coffee_lint_options')
|
||||
let g:coffee_lint_options = ''
|
||||
endif
|
||||
|
||||
" Pass the litcoffee flag to tools in this buffer if a litcoffee file is open.
|
||||
" Let the variable be overwritten so it can be updated if a different filetype
|
||||
" is set.
|
||||
if &filetype == 'litcoffee'
|
||||
let b:coffee_litcoffee = '--literate'
|
||||
else
|
||||
let b:coffee_litcoffee = ''
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! coffee#CoffeeSetUpErrorFormat()
|
||||
CompilerSet errorformat=Error:\ In\ %f\\,\ %m\ on\ line\ %l,
|
||||
\Error:\ In\ %f\\,\ Parse\ error\ on\ line\ %l:\ %m,
|
||||
\SyntaxError:\ In\ %f\\,\ %m,
|
||||
\%f:%l:%c:\ error:\ %m,
|
||||
\%-G%.%#
|
||||
endfunction
|
@ -1,15 +0,0 @@
|
||||
" Language: CoffeeScript
|
||||
" Maintainer: Mick Koch <mick@kochm.co>
|
||||
" URL: http://github.com/kchmck/vim-coffee-script
|
||||
" License: WTFPL
|
||||
|
||||
if exists('current_compiler')
|
||||
finish
|
||||
endif
|
||||
|
||||
let current_compiler = 'cake'
|
||||
call coffee#CoffeeSetUpVariables()
|
||||
|
||||
exec 'CompilerSet makeprg=' . escape(g:coffee_cake . ' ' .
|
||||
\ g:coffee_cake_options . ' $*', ' ')
|
||||
call coffee#CoffeeSetUpErrorFormat()
|
@ -1,82 +0,0 @@
|
||||
" Language: CoffeeScript
|
||||
" Maintainer: Mick Koch <mick@kochm.co>
|
||||
" URL: http://github.com/kchmck/vim-coffee-script
|
||||
" License: WTFPL
|
||||
|
||||
" All this is needed to support compiling filenames with spaces, quotes, and
|
||||
" such. The filename is escaped and embedded into the `makeprg` setting.
|
||||
"
|
||||
" Because of this, `makeprg` must be updated on every file rename. And because
|
||||
" of that, `CompilerSet` can't be used because it doesn't exist when the
|
||||
" rename autocmd is ran. So, we have to do some checks to see whether `compiler`
|
||||
" was called locally or globally, and respect that in the rest of the script.
|
||||
|
||||
if exists('current_compiler')
|
||||
finish
|
||||
endif
|
||||
|
||||
let current_compiler = 'coffee'
|
||||
call coffee#CoffeeSetUpVariables()
|
||||
|
||||
" Pattern to check if coffee is the compiler
|
||||
let s:pat = '^' . current_compiler
|
||||
|
||||
" Get a `makeprg` for the current filename.
|
||||
function! s:GetMakePrg()
|
||||
return g:coffee_compiler .
|
||||
\ ' -c' .
|
||||
\ ' ' . b:coffee_litcoffee .
|
||||
\ ' ' . g:coffee_make_options .
|
||||
\ ' $*' .
|
||||
\ ' ' . fnameescape(expand('%'))
|
||||
endfunction
|
||||
|
||||
" Set `makeprg` and return 1 if coffee is still the compiler, else return 0.
|
||||
function! s:SetMakePrg()
|
||||
if &l:makeprg =~ s:pat
|
||||
let &l:makeprg = s:GetMakePrg()
|
||||
elseif &g:makeprg =~ s:pat
|
||||
let &g:makeprg = s:GetMakePrg()
|
||||
else
|
||||
return 0
|
||||
endif
|
||||
|
||||
return 1
|
||||
endfunction
|
||||
|
||||
" Set a dummy compiler so we can check whether to set locally or globally.
|
||||
exec 'CompilerSet makeprg=' . current_compiler
|
||||
" Then actually set the compiler.
|
||||
call s:SetMakePrg()
|
||||
call coffee#CoffeeSetUpErrorFormat()
|
||||
|
||||
function! s:CoffeeMakeDeprecated(bang, args)
|
||||
echoerr 'CoffeeMake is deprecated! Please use :make instead, its behavior ' .
|
||||
\ 'is identical.'
|
||||
sleep 5
|
||||
exec 'make' . a:bang a:args
|
||||
endfunction
|
||||
|
||||
" Compile the current file.
|
||||
command! -bang -bar -nargs=* CoffeeMake
|
||||
\ call s:CoffeeMakeDeprecated(<q-bang>, <q-args>)
|
||||
|
||||
" Set `makeprg` on rename since we embed the filename in the setting.
|
||||
augroup CoffeeUpdateMakePrg
|
||||
autocmd!
|
||||
|
||||
" Update `makeprg` if coffee is still the compiler, else stop running this
|
||||
" function.
|
||||
function! s:UpdateMakePrg()
|
||||
if !s:SetMakePrg()
|
||||
autocmd! CoffeeUpdateMakePrg
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" Set autocmd locally if compiler was set locally.
|
||||
if &l:makeprg =~ s:pat
|
||||
autocmd BufWritePre,BufFilePost <buffer> call s:UpdateMakePrg()
|
||||
else
|
||||
autocmd BufWritePre,BufFilePost call s:UpdateMakePrg()
|
||||
endif
|
||||
augroup END
|
@ -1,4 +0,0 @@
|
||||
Please see the project readme for up-to-date docs:
|
||||
https://github.com/kchmck/vim-coffee-script
|
||||
|
||||
vim:tw=78:ts=8:ft=help:norl:
|
@ -1,18 +0,0 @@
|
||||
" Language: CoffeeScript
|
||||
" Maintainer: Mick Koch <mick@kochm.co>
|
||||
" URL: http://github.com/kchmck/vim-coffee-script
|
||||
" License: WTFPL
|
||||
|
||||
autocmd BufNewFile,BufRead *.coffee set filetype=coffee
|
||||
autocmd BufNewFile,BufRead *Cakefile set filetype=coffee
|
||||
autocmd BufNewFile,BufRead *.coffeekup,*.ck set filetype=coffee
|
||||
autocmd BufNewFile,BufRead *._coffee set filetype=coffee
|
||||
autocmd BufNewFile,BufRead *.cson set filetype=coffee
|
||||
|
||||
function! s:DetectCoffee()
|
||||
if getline(1) =~ '^#!.*\<coffee\>'
|
||||
set filetype=coffee
|
||||
endif
|
||||
endfunction
|
||||
|
||||
autocmd BufNewFile,BufRead * call s:DetectCoffee()
|
@ -1,8 +0,0 @@
|
||||
" Language: Literate CoffeeScript
|
||||
" Maintainer: Michael Smith <michael@diglumi.com>
|
||||
" URL: https://github.com/mintplant/vim-literate-coffeescript
|
||||
" License: MIT
|
||||
|
||||
autocmd BufNewFile,BufRead *.litcoffee set filetype=litcoffee
|
||||
autocmd BufNewFile,BufRead *.coffee.md set filetype=litcoffee
|
||||
|
@ -1,405 +0,0 @@
|
||||
" Language: CoffeeScript
|
||||
" Maintainer: Mick Koch <mick@kochm.co>
|
||||
" URL: http://github.com/kchmck/vim-coffee-script
|
||||
" License: WTFPL
|
||||
|
||||
if exists('b:did_ftplugin')
|
||||
finish
|
||||
endif
|
||||
|
||||
let b:did_ftplugin = 1
|
||||
call coffee#CoffeeSetUpVariables()
|
||||
|
||||
setlocal formatoptions-=t formatoptions+=croql
|
||||
setlocal comments=:# commentstring=#\ %s
|
||||
setlocal omnifunc=javascriptcomplete#CompleteJS
|
||||
setlocal suffixesadd+=.coffee
|
||||
|
||||
" Create custom augroups.
|
||||
augroup CoffeeBufUpdate | augroup END
|
||||
augroup CoffeeBufNew | augroup END
|
||||
|
||||
" Enable coffee compiler if a compiler isn't set already.
|
||||
if !len(&l:makeprg)
|
||||
compiler coffee
|
||||
endif
|
||||
|
||||
" Switch to the window for buf.
|
||||
function! s:SwitchWindow(buf)
|
||||
exec bufwinnr(a:buf) 'wincmd w'
|
||||
endfunction
|
||||
|
||||
" Create a new scratch buffer and return the bufnr of it. After the function
|
||||
" returns, vim remains in the scratch buffer so more set up can be done.
|
||||
function! s:ScratchBufBuild(src, vert, size)
|
||||
if a:size <= 0
|
||||
if a:vert
|
||||
let size = winwidth(bufwinnr(a:src)) / 2
|
||||
else
|
||||
let size = winheight(bufwinnr(a:src)) / 2
|
||||
endif
|
||||
endif
|
||||
|
||||
if a:vert
|
||||
vertical belowright new
|
||||
exec 'vertical resize' size
|
||||
else
|
||||
belowright new
|
||||
exec 'resize' size
|
||||
endif
|
||||
|
||||
setlocal bufhidden=wipe buftype=nofile nobuflisted noswapfile nomodifiable
|
||||
nnoremap <buffer> <silent> q :hide<CR>
|
||||
|
||||
return bufnr('%')
|
||||
endfunction
|
||||
|
||||
" Replace buffer contents with text and delete the last empty line.
|
||||
function! s:ScratchBufUpdate(buf, text)
|
||||
" Move to the scratch buffer.
|
||||
call s:SwitchWindow(a:buf)
|
||||
|
||||
" Double check we're in the scratch buffer before overwriting.
|
||||
if bufnr('%') != a:buf
|
||||
throw 'unable to change to scratch buffer'
|
||||
endif
|
||||
|
||||
setlocal modifiable
|
||||
silent exec '% delete _'
|
||||
silent put! =a:text
|
||||
silent exec '$ delete _'
|
||||
setlocal nomodifiable
|
||||
endfunction
|
||||
|
||||
" Parse the output of coffee into a qflist entry for src buffer.
|
||||
function! s:ParseCoffeeError(output, src, startline)
|
||||
" Coffee error is always on first line?
|
||||
let match = matchlist(a:output,
|
||||
\ '^\(\f\+\|\[stdin\]\):\(\d\):\(\d\): error: \(.\{-}\)' . "\n")
|
||||
|
||||
if !len(match)
|
||||
return
|
||||
endif
|
||||
|
||||
" Consider the line number from coffee as relative and add it to the beginning
|
||||
" line number of the range the command was called on, then subtract one for
|
||||
" zero-based relativity.
|
||||
call setqflist([{'bufnr': a:src, 'lnum': a:startline + str2nr(match[2]) - 1,
|
||||
\ 'type': 'E', 'col': str2nr(match[3]), 'text': match[4]}], 'r')
|
||||
endfunction
|
||||
|
||||
" Reset source buffer variables.
|
||||
function! s:CoffeeCompileResetVars()
|
||||
" Variables defined in source buffer:
|
||||
" b:coffee_compile_buf: bufnr of output buffer
|
||||
" Variables defined in output buffer:
|
||||
" b:coffee_src_buf: bufnr of source buffer
|
||||
" b:coffee_compile_pos: previous cursor position in output buffer
|
||||
|
||||
let b:coffee_compile_buf = -1
|
||||
endfunction
|
||||
|
||||
function! s:CoffeeWatchResetVars()
|
||||
" Variables defined in source buffer:
|
||||
" b:coffee_watch_buf: bufnr of output buffer
|
||||
" Variables defined in output buffer:
|
||||
" b:coffee_src_buf: bufnr of source buffer
|
||||
" b:coffee_watch_pos: previous cursor position in output buffer
|
||||
|
||||
let b:coffee_watch_buf = -1
|
||||
endfunction
|
||||
|
||||
function! s:CoffeeRunResetVars()
|
||||
" Variables defined in CoffeeRun source buffer:
|
||||
" b:coffee_run_buf: bufnr of output buffer
|
||||
" Variables defined in CoffeeRun output buffer:
|
||||
" b:coffee_src_buf: bufnr of source buffer
|
||||
" b:coffee_run_pos: previous cursor position in output buffer
|
||||
|
||||
let b:coffee_run_buf = -1
|
||||
endfunction
|
||||
|
||||
" Clean things up in the source buffers.
|
||||
function! s:CoffeeCompileClose()
|
||||
" Switch to the source buffer if not already in it.
|
||||
silent! call s:SwitchWindow(b:coffee_src_buf)
|
||||
call s:CoffeeCompileResetVars()
|
||||
endfunction
|
||||
|
||||
function! s:CoffeeWatchClose()
|
||||
silent! call s:SwitchWindow(b:coffee_src_buf)
|
||||
silent! autocmd! CoffeeAuWatch * <buffer>
|
||||
call s:CoffeeWatchResetVars()
|
||||
endfunction
|
||||
|
||||
function! s:CoffeeRunClose()
|
||||
silent! call s:SwitchWindow(b:coffee_src_buf)
|
||||
call s:CoffeeRunResetVars()
|
||||
endfunction
|
||||
|
||||
" Compile the lines between startline and endline and put the result into buf.
|
||||
function! s:CoffeeCompileToBuf(buf, startline, endline)
|
||||
let src = bufnr('%')
|
||||
let input = join(getline(a:startline, a:endline), "\n")
|
||||
|
||||
" Coffee doesn't like empty input.
|
||||
if !len(input)
|
||||
" Function should still return within output buffer.
|
||||
call s:SwitchWindow(a:buf)
|
||||
return
|
||||
endif
|
||||
|
||||
" Pipe lines into coffee.
|
||||
let output = system(g:coffee_compiler .
|
||||
\ ' -scb' .
|
||||
\ ' ' . b:coffee_litcoffee .
|
||||
\ ' 2>&1', input)
|
||||
|
||||
" Paste output into output buffer.
|
||||
call s:ScratchBufUpdate(a:buf, output)
|
||||
|
||||
" Highlight as JavaScript if there were no compile errors.
|
||||
if v:shell_error
|
||||
call s:ParseCoffeeError(output, src, a:startline)
|
||||
setlocal filetype=
|
||||
else
|
||||
" Clear the quickfix list.
|
||||
call setqflist([], 'r')
|
||||
setlocal filetype=javascript
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" Peek at compiled CoffeeScript in a scratch buffer. We handle ranges like this
|
||||
" to prevent the cursor from being moved (and its position saved) before the
|
||||
" function is called.
|
||||
function! s:CoffeeCompile(startline, endline, args)
|
||||
if a:args =~ '\<watch\>'
|
||||
echoerr 'CoffeeCompile watch is deprecated! Please use CoffeeWatch instead'
|
||||
sleep 5
|
||||
call s:CoffeeWatch(a:args)
|
||||
return
|
||||
endif
|
||||
|
||||
" Switch to the source buffer if not already in it.
|
||||
silent! call s:SwitchWindow(b:coffee_src_buf)
|
||||
|
||||
" Bail if not in source buffer.
|
||||
if !exists('b:coffee_compile_buf')
|
||||
return
|
||||
endif
|
||||
|
||||
" Build the output buffer if it doesn't exist.
|
||||
if bufwinnr(b:coffee_compile_buf) == -1
|
||||
let src = bufnr('%')
|
||||
|
||||
let vert = exists('g:coffee_compile_vert') || a:args =~ '\<vert\%[ical]\>'
|
||||
let size = str2nr(matchstr(a:args, '\<\d\+\>'))
|
||||
|
||||
" Build the output buffer and save the source bufnr.
|
||||
let buf = s:ScratchBufBuild(src, vert, size)
|
||||
let b:coffee_src_buf = src
|
||||
|
||||
" Set the buffer name.
|
||||
exec 'silent! file [CoffeeCompile ' . src . ']'
|
||||
|
||||
" Clean up the source buffer when the output buffer is closed.
|
||||
autocmd BufWipeout <buffer> call s:CoffeeCompileClose()
|
||||
" Save the cursor when leaving the output buffer.
|
||||
autocmd BufLeave <buffer> let b:coffee_compile_pos = getpos('.')
|
||||
|
||||
" Run user-defined commands on new buffer.
|
||||
silent doautocmd CoffeeBufNew User CoffeeCompile
|
||||
|
||||
" Switch back to the source buffer and save the output bufnr. This also
|
||||
" triggers BufLeave above.
|
||||
call s:SwitchWindow(src)
|
||||
let b:coffee_compile_buf = buf
|
||||
endif
|
||||
|
||||
" Fill the scratch buffer.
|
||||
call s:CoffeeCompileToBuf(b:coffee_compile_buf, a:startline, a:endline)
|
||||
" Reset cursor to previous position.
|
||||
call setpos('.', b:coffee_compile_pos)
|
||||
|
||||
" Run any user-defined commands on the scratch buffer.
|
||||
silent doautocmd CoffeeBufUpdate User CoffeeCompile
|
||||
endfunction
|
||||
|
||||
" Update the scratch buffer and switch back to the source buffer.
|
||||
function! s:CoffeeWatchUpdate()
|
||||
call s:CoffeeCompileToBuf(b:coffee_watch_buf, 1, '$')
|
||||
call setpos('.', b:coffee_watch_pos)
|
||||
silent doautocmd CoffeeBufUpdate User CoffeeWatch
|
||||
call s:SwitchWindow(b:coffee_src_buf)
|
||||
endfunction
|
||||
|
||||
" Continually compile a source buffer.
|
||||
function! s:CoffeeWatch(args)
|
||||
silent! call s:SwitchWindow(b:coffee_src_buf)
|
||||
|
||||
if !exists('b:coffee_watch_buf')
|
||||
return
|
||||
endif
|
||||
|
||||
if bufwinnr(b:coffee_watch_buf) == -1
|
||||
let src = bufnr('%')
|
||||
|
||||
let vert = exists('g:coffee_watch_vert') || a:args =~ '\<vert\%[ical]\>'
|
||||
let size = str2nr(matchstr(a:args, '\<\d\+\>'))
|
||||
|
||||
let buf = s:ScratchBufBuild(src, vert, size)
|
||||
let b:coffee_src_buf = src
|
||||
|
||||
exec 'silent! file [CoffeeWatch ' . src . ']'
|
||||
|
||||
autocmd BufWipeout <buffer> call s:CoffeeWatchClose()
|
||||
autocmd BufLeave <buffer> let b:coffee_watch_pos = getpos('.')
|
||||
|
||||
silent doautocmd CoffeeBufNew User CoffeeWatch
|
||||
|
||||
call s:SwitchWindow(src)
|
||||
let b:coffee_watch_buf = buf
|
||||
endif
|
||||
|
||||
" Make sure only one watch autocmd is defined on this buffer.
|
||||
silent! autocmd! CoffeeAuWatch * <buffer>
|
||||
|
||||
augroup CoffeeAuWatch
|
||||
autocmd InsertLeave <buffer> call s:CoffeeWatchUpdate()
|
||||
autocmd BufWritePost <buffer> call s:CoffeeWatchUpdate()
|
||||
augroup END
|
||||
|
||||
call s:CoffeeWatchUpdate()
|
||||
endfunction
|
||||
|
||||
" Run a snippet of CoffeeScript between startline and endline.
|
||||
function! s:CoffeeRun(startline, endline, args)
|
||||
silent! call s:SwitchWindow(b:coffee_src_buf)
|
||||
|
||||
if !exists('b:coffee_run_buf')
|
||||
return
|
||||
endif
|
||||
|
||||
if bufwinnr(b:coffee_run_buf) == -1
|
||||
let src = bufnr('%')
|
||||
|
||||
let buf = s:ScratchBufBuild(src, exists('g:coffee_run_vert'), 0)
|
||||
let b:coffee_src_buf = src
|
||||
|
||||
exec 'silent! file [CoffeeRun ' . src . ']'
|
||||
|
||||
autocmd BufWipeout <buffer> call s:CoffeeRunClose()
|
||||
autocmd BufLeave <buffer> let b:coffee_run_pos = getpos('.')
|
||||
|
||||
silent doautocmd CoffeeBufNew User CoffeeRun
|
||||
|
||||
call s:SwitchWindow(src)
|
||||
let b:coffee_run_buf = buf
|
||||
endif
|
||||
|
||||
if a:startline == 1 && a:endline == line('$')
|
||||
let output = system(g:coffee_compiler .
|
||||
\ ' ' . b:coffee_litcoffee .
|
||||
\ ' ' . fnameescape(expand('%')) .
|
||||
\ ' ' . a:args)
|
||||
else
|
||||
let input = join(getline(a:startline, a:endline), "\n")
|
||||
|
||||
if !len(input)
|
||||
return
|
||||
endif
|
||||
|
||||
let output = system(g:coffee_compiler .
|
||||
\ ' -s' .
|
||||
\ ' ' . b:coffee_litcoffee .
|
||||
\ ' ' . a:args, input)
|
||||
endif
|
||||
|
||||
call s:ScratchBufUpdate(b:coffee_run_buf, output)
|
||||
call setpos('.', b:coffee_run_pos)
|
||||
|
||||
silent doautocmd CoffeeBufUpdate User CoffeeRun
|
||||
endfunction
|
||||
|
||||
" Run coffeelint on a file, and add any errors between startline and endline
|
||||
" to the quickfix list.
|
||||
function! s:CoffeeLint(startline, endline, bang, args)
|
||||
let input = join(getline(a:startline, a:endline), "\n")
|
||||
|
||||
if !len(input)
|
||||
return
|
||||
endif
|
||||
|
||||
let output = system(g:coffee_linter .
|
||||
\ ' -s --reporter csv' .
|
||||
\ ' ' . b:coffee_litcoffee .
|
||||
\ ' ' . g:coffee_lint_options .
|
||||
\ ' ' . a:args .
|
||||
\ ' 2>&1', input)
|
||||
|
||||
" Convert output into an array and strip off the csv header.
|
||||
let lines = split(output, "\n")[1:]
|
||||
let buf = bufnr('%')
|
||||
let qflist = []
|
||||
|
||||
for line in lines
|
||||
let match = matchlist(line, '^stdin,\(\d\+\),\d*,\(error\|warn\),\(.\+\)$')
|
||||
|
||||
" Ignore unmatched lines.
|
||||
if !len(match)
|
||||
continue
|
||||
endif
|
||||
|
||||
" The 'type' will result in either 'E' or 'W'.
|
||||
call add(qflist, {'bufnr': buf, 'lnum': a:startline + str2nr(match[1]) - 1,
|
||||
\ 'type': toupper(match[2][0]), 'text': match[3]})
|
||||
endfor
|
||||
|
||||
" Replace the quicklist with our items.
|
||||
call setqflist(qflist, 'r')
|
||||
|
||||
" If not given a bang, jump to first error.
|
||||
if !len(a:bang)
|
||||
silent! cc 1
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" Complete arguments for Coffee* commands.
|
||||
function! s:CoffeeComplete(cmd, cmdline, cursor)
|
||||
let args = ['vertical']
|
||||
|
||||
" If no partial command, return all possibilities.
|
||||
if !len(a:cmd)
|
||||
return args
|
||||
endif
|
||||
|
||||
let pat = '^' . a:cmd
|
||||
|
||||
for arg in args
|
||||
if arg =~ pat
|
||||
return [arg]
|
||||
endif
|
||||
endfor
|
||||
endfunction
|
||||
|
||||
" Set initial state variables if they don't exist
|
||||
if !exists('b:coffee_compile_buf')
|
||||
call s:CoffeeCompileResetVars()
|
||||
endif
|
||||
|
||||
if !exists('b:coffee_watch_buf')
|
||||
call s:CoffeeWatchResetVars()
|
||||
endif
|
||||
|
||||
if !exists('b:coffee_run_buf')
|
||||
call s:CoffeeRunResetVars()
|
||||
endif
|
||||
|
||||
command! -buffer -range=% -bar -nargs=* -complete=customlist,s:CoffeeComplete
|
||||
\ CoffeeCompile call s:CoffeeCompile(<line1>, <line2>, <q-args>)
|
||||
command! -buffer -bar -nargs=* -complete=customlist,s:CoffeeComplete
|
||||
\ CoffeeWatch call s:CoffeeWatch(<q-args>)
|
||||
command! -buffer -range=% -bar -nargs=* CoffeeRun
|
||||
\ call s:CoffeeRun(<line1>, <line2>, <q-args>)
|
||||
command! -buffer -range=% -bang -bar -nargs=* CoffeeLint
|
||||
\ call s:CoffeeLint(<line1>, <line2>, <q-bang>, <q-args>)
|
@ -1 +0,0 @@
|
||||
runtime ftplugin/coffee.vim
|
@ -1,428 +0,0 @@
|
||||
" Language: CoffeeScript
|
||||
" Maintainer: Mick Koch <mick@kochm.co>
|
||||
" URL: http://github.com/kchmck/vim-coffee-script
|
||||
" License: WTFPL
|
||||
|
||||
if exists('b:did_indent')
|
||||
finish
|
||||
endif
|
||||
|
||||
let b:did_indent = 1
|
||||
|
||||
setlocal autoindent
|
||||
setlocal indentexpr=GetCoffeeIndent(v:lnum)
|
||||
" Make sure GetCoffeeIndent is run when these are typed so they can be
|
||||
" indented or outdented.
|
||||
setlocal indentkeys+=0],0),0.,=else,=when,=catch,=finally
|
||||
|
||||
" If no indenting or outdenting is needed, either keep the indent of the cursor
|
||||
" (use autoindent) or match the indent of the previous line.
|
||||
if exists('g:coffee_indent_keep_current')
|
||||
let s:DEFAULT_LEVEL = '-1'
|
||||
else
|
||||
let s:DEFAULT_LEVEL = 'indent(prevnlnum)'
|
||||
endif
|
||||
|
||||
" Only define the function once.
|
||||
if exists('*GetCoffeeIndent')
|
||||
finish
|
||||
endif
|
||||
|
||||
" Keywords that begin a block
|
||||
let s:BEGIN_BLOCK_KEYWORD = '\C^\%(if\|unless\|else\|for\|while\|until\|'
|
||||
\ . 'loop\|switch\|when\|try\|catch\|finally\|'
|
||||
\ . 'class\)\>\%(\s*:\)\@!'
|
||||
|
||||
" An expression that uses the result of a statement
|
||||
let s:COMPOUND_EXPRESSION = '\C\%([^-]-\|[^+]+\|[^/]/\|[:=*%&|^<>]\)\s*'
|
||||
\ . '\%(if\|unless\|for\|while\|until\|loop\|switch\|'
|
||||
\ . 'try\|class\)\>'
|
||||
|
||||
" Combine the two above
|
||||
let s:BEGIN_BLOCK = s:BEGIN_BLOCK_KEYWORD . '\|' . s:COMPOUND_EXPRESSION
|
||||
|
||||
" Operators that begin a block but also count as a continuation
|
||||
let s:BEGIN_BLOCK_OP = '[([{:=]$'
|
||||
|
||||
" Begins a function block
|
||||
let s:FUNCTION = '[-=]>$'
|
||||
|
||||
" Operators that continue a line onto the next line
|
||||
let s:CONTINUATION_OP = '\C\%(\<\%(is\|isnt\|and\|or\)\>\|'
|
||||
\ . '[^-]-\|[^+]+\|[^-=]>\|[^.]\.\|[<*/%&|^,]\)$'
|
||||
|
||||
" Ancestor operators that prevent continuation indenting
|
||||
let s:CONTINUATION = s:CONTINUATION_OP . '\|' . s:BEGIN_BLOCK_OP
|
||||
|
||||
" A closing bracket by itself on a line followed by a continuation
|
||||
let s:BRACKET_CONTINUATION = '^\s*[}\])]\s*' . s:CONTINUATION_OP
|
||||
|
||||
" A continuation dot access
|
||||
let s:DOT_ACCESS = '^\.'
|
||||
|
||||
" Keywords that break out of a block
|
||||
let s:BREAK_BLOCK_OP = '\C^\%(return\|break\|continue\|throw\)\>'
|
||||
|
||||
" A condition attached to the end of a statement
|
||||
let s:POSTFIX_CONDITION = '\C\S\s\+\zs\<\%(if\|unless\|when\|while\|until\)\>'
|
||||
|
||||
" A then contained in brackets
|
||||
let s:CONTAINED_THEN = '\C[(\[].\{-}\<then\>.\{-\}[)\]]'
|
||||
|
||||
" An else with a condition attached
|
||||
let s:ELSE_COND = '\C^\s*else\s\+\<\%(if\|unless\)\>'
|
||||
|
||||
" A single-line else statement (without a condition attached)
|
||||
let s:SINGLE_LINE_ELSE = '\C^else\s\+\%(\<\%(if\|unless\)\>\)\@!'
|
||||
|
||||
" Pairs of starting and ending keywords, with an initial pattern to match
|
||||
let s:KEYWORD_PAIRS = [
|
||||
\ ['\C^else\>', '\C\<\%(if\|unless\|when\|else\s\+\%(if\|unless\)\)\>',
|
||||
\ '\C\<else\>'],
|
||||
\ ['\C^catch\>', '\C\<try\>', '\C\<catch\>'],
|
||||
\ ['\C^finally\>', '\C\<try\>', '\C\<finally\>']
|
||||
\]
|
||||
|
||||
" Pairs of starting and ending brackets
|
||||
let s:BRACKET_PAIRS = {']': '\[', '}': '{', ')': '('}
|
||||
|
||||
" Max lines to look back for a match
|
||||
let s:MAX_LOOKBACK = 50
|
||||
|
||||
" Syntax names for strings
|
||||
let s:SYNTAX_STRING = 'coffee\%(String\|AssignString\|Embed\|Regex\|Heregex\|'
|
||||
\ . 'Heredoc\)'
|
||||
|
||||
" Syntax names for comments
|
||||
let s:SYNTAX_COMMENT = 'coffee\%(Comment\|BlockComment\|HeregexComment\)'
|
||||
|
||||
" Syntax names for strings and comments
|
||||
let s:SYNTAX_STRING_COMMENT = s:SYNTAX_STRING . '\|' . s:SYNTAX_COMMENT
|
||||
|
||||
" Compatibility code for shiftwidth() as recommended by the docs, but modified
|
||||
" so there isn't as much of a penalty if shiftwidth() exists.
|
||||
if exists('*shiftwidth')
|
||||
let s:ShiftWidth = function('shiftwidth')
|
||||
else
|
||||
function! s:ShiftWidth()
|
||||
return &shiftwidth
|
||||
endfunction
|
||||
endif
|
||||
|
||||
" Get the linked syntax name of a character.
|
||||
function! s:SyntaxName(lnum, col)
|
||||
return synIDattr(synID(a:lnum, a:col, 1), 'name')
|
||||
endfunction
|
||||
|
||||
" Check if a character is in a comment.
|
||||
function! s:IsComment(lnum, col)
|
||||
return s:SyntaxName(a:lnum, a:col) =~ s:SYNTAX_COMMENT
|
||||
endfunction
|
||||
|
||||
" Check if a character is in a string.
|
||||
function! s:IsString(lnum, col)
|
||||
return s:SyntaxName(a:lnum, a:col) =~ s:SYNTAX_STRING
|
||||
endfunction
|
||||
|
||||
" Check if a character is in a comment or string.
|
||||
function! s:IsCommentOrString(lnum, col)
|
||||
return s:SyntaxName(a:lnum, a:col) =~ s:SYNTAX_STRING_COMMENT
|
||||
endfunction
|
||||
|
||||
" Search a line for a regex until one is found outside a string or comment.
|
||||
function! s:SearchCode(lnum, regex)
|
||||
" Start at the first column and look for an initial match (including at the
|
||||
" cursor.)
|
||||
call cursor(a:lnum, 1)
|
||||
let pos = search(a:regex, 'c', a:lnum)
|
||||
|
||||
while pos
|
||||
if !s:IsCommentOrString(a:lnum, col('.'))
|
||||
return 1
|
||||
endif
|
||||
|
||||
" Move to the match and continue searching (don't accept matches at the
|
||||
" cursor.)
|
||||
let pos = search(a:regex, '', a:lnum)
|
||||
endwhile
|
||||
|
||||
return 0
|
||||
endfunction
|
||||
|
||||
" Search for the nearest previous line that isn't a comment.
|
||||
function! s:GetPrevNormalLine(startlnum)
|
||||
let curlnum = a:startlnum
|
||||
|
||||
while curlnum
|
||||
let curlnum = prevnonblank(curlnum - 1)
|
||||
|
||||
" Return the line if the first non-whitespace character isn't a comment.
|
||||
if !s:IsComment(curlnum, indent(curlnum) + 1)
|
||||
return curlnum
|
||||
endif
|
||||
endwhile
|
||||
|
||||
return 0
|
||||
endfunction
|
||||
|
||||
function! s:SearchPair(startlnum, lookback, skip, open, close)
|
||||
" Go to the first column so a:close will be matched even if it's at the
|
||||
" beginning of the line.
|
||||
call cursor(a:startlnum, 1)
|
||||
return searchpair(a:open, '', a:close, 'bnW', a:skip, max([1, a:lookback]))
|
||||
endfunction
|
||||
|
||||
" Skip if a match
|
||||
" - is in a string or comment
|
||||
" - is a single-line statement that isn't immediately
|
||||
" adjacent
|
||||
" - has a postfix condition and isn't an else statement or compound
|
||||
" expression
|
||||
function! s:ShouldSkip(startlnum, lnum, col)
|
||||
return s:IsCommentOrString(a:lnum, a:col) ||
|
||||
\ s:SearchCode(a:lnum, '\C\<then\>') && a:startlnum - a:lnum > 1 ||
|
||||
\ s:SearchCode(a:lnum, s:POSTFIX_CONDITION) &&
|
||||
\ getline(a:lnum) !~ s:ELSE_COND &&
|
||||
\ !s:SearchCode(a:lnum, s:COMPOUND_EXPRESSION)
|
||||
endfunction
|
||||
|
||||
" Search for the nearest and farthest match for a keyword pair.
|
||||
function! s:SearchMatchingKeyword(startlnum, open, close)
|
||||
let skip = 's:ShouldSkip(' . a:startlnum . ", line('.'), line('.'))"
|
||||
|
||||
" Search for the nearest match.
|
||||
let nearestlnum = s:SearchPair(a:startlnum, a:startlnum - s:MAX_LOOKBACK,
|
||||
\ skip, a:open, a:close)
|
||||
|
||||
if !nearestlnum
|
||||
return []
|
||||
endif
|
||||
|
||||
" Find the nearest previous line with indent less than or equal to startlnum.
|
||||
let ind = indent(a:startlnum)
|
||||
let lookback = s:GetPrevNormalLine(a:startlnum)
|
||||
|
||||
while lookback && indent(lookback) > ind
|
||||
let lookback = s:GetPrevNormalLine(lookback)
|
||||
endwhile
|
||||
|
||||
" Search for the farthest match. If there are no other matches, then the
|
||||
" nearest match is also the farthest one.
|
||||
let matchlnum = nearestlnum
|
||||
|
||||
while matchlnum
|
||||
let lnum = matchlnum
|
||||
let matchlnum = s:SearchPair(matchlnum, lookback, skip, a:open, a:close)
|
||||
endwhile
|
||||
|
||||
return [nearestlnum, lnum]
|
||||
endfunction
|
||||
|
||||
" Strip a line of a trailing comment and surrounding whitespace.
|
||||
function! s:GetTrimmedLine(lnum)
|
||||
" Try to find a comment starting at the first column.
|
||||
call cursor(a:lnum, 1)
|
||||
let pos = search('#', 'c', a:lnum)
|
||||
|
||||
" Keep searching until a comment is found or search returns 0.
|
||||
while pos
|
||||
if s:IsComment(a:lnum, col('.'))
|
||||
break
|
||||
endif
|
||||
|
||||
let pos = search('#', '', a:lnum)
|
||||
endwhile
|
||||
|
||||
if !pos
|
||||
" No comment was found so use the whole line.
|
||||
let line = getline(a:lnum)
|
||||
else
|
||||
" Subtract 1 to get to the column before the comment and another 1 for
|
||||
" column indexing -> zero-based indexing.
|
||||
let line = getline(a:lnum)[:col('.') - 2]
|
||||
endif
|
||||
|
||||
return substitute(substitute(line, '^\s\+', '', ''),
|
||||
\ '\s\+$', '', '')
|
||||
endfunction
|
||||
|
||||
" Get the indent policy when no special rules are used.
|
||||
function! s:GetDefaultPolicy(curlnum)
|
||||
" Check whether equalprg is being ran on existing lines.
|
||||
if strlen(getline(a:curlnum)) == indent(a:curlnum)
|
||||
" If not indenting an existing line, use the default policy.
|
||||
return s:DEFAULT_LEVEL
|
||||
else
|
||||
" Otherwise let autoindent determine what to do with an existing line.
|
||||
return '-1'
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! GetCoffeeIndent(curlnum)
|
||||
" Get the previous non-blank line (may be a comment.)
|
||||
let prevlnum = prevnonblank(a:curlnum - 1)
|
||||
|
||||
" Bail if there's no code before.
|
||||
if !prevlnum
|
||||
return -1
|
||||
endif
|
||||
|
||||
" Bail if inside a multiline string.
|
||||
if s:IsString(a:curlnum, 1)
|
||||
let prevnlnum = prevlnum
|
||||
exec 'return' s:GetDefaultPolicy(a:curlnum)
|
||||
endif
|
||||
|
||||
" Get the code part of the current line.
|
||||
let curline = s:GetTrimmedLine(a:curlnum)
|
||||
" Get the previous non-comment line.
|
||||
let prevnlnum = s:GetPrevNormalLine(a:curlnum)
|
||||
|
||||
" Check if the current line is the closing bracket in a bracket pair.
|
||||
if has_key(s:BRACKET_PAIRS, curline[0])
|
||||
" Search for a matching opening bracket.
|
||||
let matchlnum = s:SearchPair(a:curlnum, a:curlnum - s:MAX_LOOKBACK,
|
||||
\ "s:IsCommentOrString(line('.'), col('.'))",
|
||||
\ s:BRACKET_PAIRS[curline[0]], curline[0])
|
||||
|
||||
if matchlnum
|
||||
" Match the indent of the opening bracket.
|
||||
return indent(matchlnum)
|
||||
else
|
||||
" No opening bracket found (bad syntax), so bail.
|
||||
exec 'return' s:GetDefaultPolicy(a:curlnum)
|
||||
endif
|
||||
endif
|
||||
|
||||
" Check if the current line is the closing keyword in a keyword pair.
|
||||
for pair in s:KEYWORD_PAIRS
|
||||
if curline =~ pair[0]
|
||||
" Find the nearest and farthest matches within the same indent level.
|
||||
let matches = s:SearchMatchingKeyword(a:curlnum, pair[1], pair[2])
|
||||
|
||||
if len(matches)
|
||||
" Don't force indenting/outdenting as long as line is already lined up
|
||||
" with a valid match
|
||||
return max([min([indent(a:curlnum), indent(matches[0])]),
|
||||
\ indent(matches[1])])
|
||||
else
|
||||
" No starting keyword found (bad syntax), so bail.
|
||||
exec 'return' s:GetDefaultPolicy(a:curlnum)
|
||||
endif
|
||||
endif
|
||||
endfor
|
||||
|
||||
" Check if the current line is a `when` and not the first in a switch block.
|
||||
if curline =~ '\C^when\>' && !s:SearchCode(prevnlnum, '\C\<switch\>')
|
||||
" Look back for a `when`.
|
||||
while prevnlnum
|
||||
if getline(prevnlnum) =~ '\C^\s*when\>'
|
||||
" Indent to match the found `when`, but don't force indenting (for when
|
||||
" indenting nested switch blocks.)
|
||||
return min([indent(a:curlnum), indent(prevnlnum)])
|
||||
endif
|
||||
|
||||
let prevnlnum = s:GetPrevNormalLine(prevnlnum)
|
||||
endwhile
|
||||
|
||||
" No matching `when` found (bad syntax), so bail.
|
||||
exec 'return' s:GetDefaultPolicy(a:curlnum)
|
||||
endif
|
||||
|
||||
" If the previous line is a comment, use its indentation, but don't force
|
||||
" indenting.
|
||||
if prevlnum != prevnlnum
|
||||
return min([indent(a:curlnum), indent(prevlnum)])
|
||||
endif
|
||||
|
||||
let prevline = s:GetTrimmedLine(prevnlnum)
|
||||
|
||||
" Always indent after these operators.
|
||||
if prevline =~ s:BEGIN_BLOCK_OP
|
||||
return indent(prevnlnum) + s:ShiftWidth()
|
||||
endif
|
||||
|
||||
" Indent if the previous line starts a function block, but don't force
|
||||
" indenting if the line is non-blank (for empty function bodies.)
|
||||
if prevline =~ s:FUNCTION
|
||||
if strlen(getline(a:curlnum)) > indent(a:curlnum)
|
||||
return min([indent(prevnlnum) + s:ShiftWidth(), indent(a:curlnum)])
|
||||
else
|
||||
return indent(prevnlnum) + s:ShiftWidth()
|
||||
endif
|
||||
endif
|
||||
|
||||
" Check if continuation indenting is needed. If the line ends in a slash, make
|
||||
" sure it isn't a regex.
|
||||
if prevline =~ s:CONTINUATION_OP &&
|
||||
\ !(prevline =~ '/$' && s:IsString(prevnlnum, col([prevnlnum, '$']) - 1))
|
||||
" Don't indent if the continuation follows a closing bracket.
|
||||
if prevline =~ s:BRACKET_CONTINUATION
|
||||
exec 'return' s:GetDefaultPolicy(a:curlnum)
|
||||
endif
|
||||
|
||||
let prevprevnlnum = s:GetPrevNormalLine(prevnlnum)
|
||||
|
||||
" Don't indent if not the first continuation.
|
||||
if prevprevnlnum && s:GetTrimmedLine(prevprevnlnum) =~ s:CONTINUATION
|
||||
exec 'return' s:GetDefaultPolicy(a:curlnum)
|
||||
endif
|
||||
|
||||
" Continuation indenting seems to vary between programmers, so if the line
|
||||
" is non-blank, don't override the indentation
|
||||
if strlen(getline(a:curlnum)) > indent(a:curlnum)
|
||||
exec 'return' s:GetDefaultPolicy(a:curlnum)
|
||||
endif
|
||||
|
||||
" Otherwise indent a level.
|
||||
return indent(prevnlnum) + s:ShiftWidth()
|
||||
endif
|
||||
|
||||
" Check if the previous line starts with a keyword that begins a block.
|
||||
if prevline =~ s:BEGIN_BLOCK
|
||||
" Indent if the current line doesn't start with `then` and the previous line
|
||||
" isn't a single-line statement.
|
||||
if curline !~ '\C^\<then\>' && !s:SearchCode(prevnlnum, '\C\<then\>') &&
|
||||
\ prevline !~ s:SINGLE_LINE_ELSE
|
||||
return indent(prevnlnum) + s:ShiftWidth()
|
||||
else
|
||||
exec 'return' s:GetDefaultPolicy(a:curlnum)
|
||||
endif
|
||||
endif
|
||||
|
||||
" Indent a dot access if it's the first.
|
||||
if curline =~ s:DOT_ACCESS
|
||||
if prevline !~ s:DOT_ACCESS
|
||||
return indent(prevnlnum) + s:ShiftWidth()
|
||||
else
|
||||
exec 'return' s:GetDefaultPolicy(a:curlnum)
|
||||
endif
|
||||
endif
|
||||
|
||||
" Outdent if a keyword breaks out of a block as long as it doesn't have a
|
||||
" postfix condition (and the postfix condition isn't a single-line statement.)
|
||||
if prevline =~ s:BREAK_BLOCK_OP
|
||||
if !s:SearchCode(prevnlnum, s:POSTFIX_CONDITION) ||
|
||||
\ s:SearchCode(prevnlnum, '\C\<then\>') &&
|
||||
\ !s:SearchCode(prevnlnum, s:CONTAINED_THEN)
|
||||
" Don't force indenting.
|
||||
return min([indent(a:curlnum), indent(prevnlnum) - s:ShiftWidth()])
|
||||
else
|
||||
exec 'return' s:GetDefaultPolicy(a:curlnum)
|
||||
endif
|
||||
endif
|
||||
|
||||
" Check if inside brackets.
|
||||
let matchlnum = s:SearchPair(a:curlnum, a:curlnum - s:MAX_LOOKBACK,
|
||||
\ "s:IsCommentOrString(line('.'), col('.'))",
|
||||
\ '\[\|(\|{', '\]\|)\|}')
|
||||
|
||||
" If inside brackets, indent relative to the brackets, but don't outdent an
|
||||
" already indented line.
|
||||
if matchlnum
|
||||
return max([indent(a:curlnum), indent(matchlnum) + s:ShiftWidth()])
|
||||
endif
|
||||
|
||||
" No special rules applied, so use the default policy.
|
||||
exec 'return' s:GetDefaultPolicy(a:curlnum)
|
||||
endfunction
|
@ -1,22 +0,0 @@
|
||||
if exists('b:did_indent')
|
||||
finish
|
||||
endif
|
||||
|
||||
runtime! indent/coffee.vim
|
||||
|
||||
let b:did_indent = 1
|
||||
|
||||
setlocal indentexpr=GetLitCoffeeIndent()
|
||||
|
||||
if exists('*GetLitCoffeeIndent')
|
||||
finish
|
||||
endif
|
||||
|
||||
function GetLitCoffeeIndent()
|
||||
if searchpair('^ \|\t', '', '$', 'bWnm') > 0
|
||||
return GetCoffeeIndent(v:lnum)
|
||||
else
|
||||
return -1
|
||||
endif
|
||||
endfunc
|
||||
|
@ -1,221 +0,0 @@
|
||||
" Language: CoffeeScript
|
||||
" Maintainer: Mick Koch <mick@kochm.co>
|
||||
" URL: http://github.com/kchmck/vim-coffee-script
|
||||
" License: WTFPL
|
||||
|
||||
" Bail if our syntax is already loaded.
|
||||
if exists('b:current_syntax') && b:current_syntax == 'coffee'
|
||||
finish
|
||||
endif
|
||||
|
||||
" Include JavaScript for coffeeEmbed.
|
||||
syn include @coffeeJS syntax/javascript.vim
|
||||
silent! unlet b:current_syntax
|
||||
|
||||
" Highlight long strings.
|
||||
syntax sync fromstart
|
||||
|
||||
" These are `matches` instead of `keywords` because vim's highlighting
|
||||
" priority for keywords is higher than matches. This causes keywords to be
|
||||
" highlighted inside matches, even if a match says it shouldn't contain them --
|
||||
" like with coffeeAssign and coffeeDot.
|
||||
syn match coffeeStatement /\<\%(return\|break\|continue\|throw\)\>/ display
|
||||
hi def link coffeeStatement Statement
|
||||
|
||||
syn match coffeeRepeat /\<\%(for\|while\|until\|loop\)\>/ display
|
||||
hi def link coffeeRepeat Repeat
|
||||
|
||||
syn match coffeeConditional /\<\%(if\|else\|unless\|switch\|when\|then\)\>/
|
||||
\ display
|
||||
hi def link coffeeConditional Conditional
|
||||
|
||||
syn match coffeeException /\<\%(try\|catch\|finally\)\>/ display
|
||||
hi def link coffeeException Exception
|
||||
|
||||
syn match coffeeKeyword /\<\%(new\|in\|of\|from\|by\|and\|or\|not\|is\|isnt\|class\|extends\|super\|do\|yield\|debugger\|import\|export\|default\|await\)\>/
|
||||
\ display
|
||||
" The `own` keyword is only a keyword after `for`.
|
||||
syn match coffeeKeyword /\<for\s\+own\>/ contained containedin=coffeeRepeat
|
||||
\ display
|
||||
hi def link coffeeKeyword Keyword
|
||||
|
||||
syn match coffeeOperator /\<\%(instanceof\|typeof\|delete\)\>/ display
|
||||
hi def link coffeeOperator Operator
|
||||
|
||||
" The first case matches symbol operators only if they have an operand before.
|
||||
syn match coffeeExtendedOp /\%(\S\s*\)\@<=[+\-*/%&|\^=!<>?.]\{-1,}\|[-=]>\|--\|++\|:/
|
||||
\ display
|
||||
syn match coffeeExtendedOp /\<\%(and\|or\)=/ display
|
||||
hi def link coffeeExtendedOp coffeeOperator
|
||||
|
||||
" This is separate from `coffeeExtendedOp` to help differentiate commas from
|
||||
" dots.
|
||||
syn match coffeeSpecialOp /[,;]/ display
|
||||
hi def link coffeeSpecialOp SpecialChar
|
||||
|
||||
syn match coffeeBoolean /\<\%(true\|on\|yes\|false\|off\|no\)\>/ display
|
||||
hi def link coffeeBoolean Boolean
|
||||
|
||||
syn match coffeeGlobal /\<\%(null\|undefined\)\>/ display
|
||||
hi def link coffeeGlobal Type
|
||||
|
||||
" A special variable
|
||||
syn match coffeeSpecialVar /\<\%(this\|prototype\|arguments\)\>/ display
|
||||
hi def link coffeeSpecialVar Special
|
||||
|
||||
" An @-variable
|
||||
syn match coffeeSpecialIdent /@\%(\%(\I\|\$\)\%(\i\|\$\)*\)\?/ display
|
||||
hi def link coffeeSpecialIdent Identifier
|
||||
|
||||
" A class-like name that starts with a capital letter
|
||||
syn match coffeeObject /\<\u\w*\>/ display
|
||||
hi def link coffeeObject Structure
|
||||
|
||||
" A constant-like name in SCREAMING_CAPS
|
||||
syn match coffeeConstant /\<\u[A-Z0-9_]\+\>/ display
|
||||
hi def link coffeeConstant Constant
|
||||
|
||||
" A variable name
|
||||
syn cluster coffeeIdentifier contains=coffeeSpecialVar,coffeeSpecialIdent,
|
||||
\ coffeeObject,coffeeConstant
|
||||
|
||||
" A non-interpolated string
|
||||
syn cluster coffeeBasicString contains=@Spell,coffeeEscape
|
||||
" An interpolated string
|
||||
syn cluster coffeeInterpString contains=@coffeeBasicString,coffeeInterp
|
||||
|
||||
" Regular strings
|
||||
syn region coffeeString start=/"/ skip=/\\\\\|\\"/ end=/"/
|
||||
\ contains=@coffeeInterpString
|
||||
syn region coffeeString start=/'/ skip=/\\\\\|\\'/ end=/'/
|
||||
\ contains=@coffeeBasicString
|
||||
hi def link coffeeString String
|
||||
|
||||
" A integer, including a leading plus or minus
|
||||
syn match coffeeNumber /\%(\i\|\$\)\@<![-+]\?\d\+\%(e[+-]\?\d\+\)\?/ display
|
||||
" A hex, binary, or octal number
|
||||
syn match coffeeNumber /\<0[xX]\x\+\>/ display
|
||||
syn match coffeeNumber /\<0[bB][01]\+\>/ display
|
||||
syn match coffeeNumber /\<0[oO][0-7]\+\>/ display
|
||||
syn match coffeeNumber /\<\%(Infinity\|NaN\)\>/ display
|
||||
hi def link coffeeNumber Number
|
||||
|
||||
" A floating-point number, including a leading plus or minus
|
||||
syn match coffeeFloat /\%(\i\|\$\)\@<![-+]\?\d*\.\@<!\.\d\+\%([eE][+-]\?\d\+\)\?/
|
||||
\ display
|
||||
hi def link coffeeFloat Float
|
||||
|
||||
" An error for reserved keywords, taken from the RESERVED array:
|
||||
" http://coffeescript.org/documentation/docs/lexer.html#section-67
|
||||
syn match coffeeReservedError /\<\%(case\|function\|var\|void\|with\|const\|let\|enum\|native\|implements\|interface\|package\|private\|protected\|public\|static\)\>/
|
||||
\ display
|
||||
hi def link coffeeReservedError Error
|
||||
|
||||
" A normal object assignment
|
||||
syn match coffeeObjAssign /@\?\%(\I\|\$\)\%(\i\|\$\)*\s*\ze::\@!/ contains=@coffeeIdentifier display
|
||||
hi def link coffeeObjAssign Identifier
|
||||
|
||||
syn keyword coffeeTodo TODO FIXME XXX contained
|
||||
hi def link coffeeTodo Todo
|
||||
|
||||
syn match coffeeComment /#.*/ contains=@Spell,coffeeTodo
|
||||
hi def link coffeeComment Comment
|
||||
|
||||
syn region coffeeBlockComment start=/####\@!/ end=/###/
|
||||
\ contains=@Spell,coffeeTodo
|
||||
hi def link coffeeBlockComment coffeeComment
|
||||
|
||||
" A comment in a heregex
|
||||
syn region coffeeHeregexComment start=/#/ end=/\ze\/\/\/\|$/ contained
|
||||
\ contains=@Spell,coffeeTodo
|
||||
hi def link coffeeHeregexComment coffeeComment
|
||||
|
||||
" Embedded JavaScript
|
||||
syn region coffeeEmbed matchgroup=coffeeEmbedDelim
|
||||
\ start=/`/ skip=/\\\\\|\\`/ end=/`/ keepend
|
||||
\ contains=@coffeeJS
|
||||
hi def link coffeeEmbedDelim Delimiter
|
||||
|
||||
syn region coffeeInterp matchgroup=coffeeInterpDelim start=/#{/ end=/}/ contained
|
||||
\ contains=@coffeeAll
|
||||
hi def link coffeeInterpDelim PreProc
|
||||
|
||||
" A string escape sequence
|
||||
syn match coffeeEscape /\\\d\d\d\|\\x\x\{2\}\|\\u\x\{4\}\|\\./ contained display
|
||||
hi def link coffeeEscape SpecialChar
|
||||
|
||||
" A regex -- must not follow a parenthesis, number, or identifier, and must not
|
||||
" be followed by a number
|
||||
syn region coffeeRegex start=#\%(\%()\|\%(\i\|\$\)\@<!\d\)\s*\|\i\)\@<!/=\@!\s\@!#
|
||||
\ end=#/[gimy]\{,4}\d\@!#
|
||||
\ oneline contains=@coffeeBasicString,coffeeRegexCharSet
|
||||
syn region coffeeRegexCharSet start=/\[/ end=/]/ contained
|
||||
\ contains=@coffeeBasicString
|
||||
hi def link coffeeRegex String
|
||||
hi def link coffeeRegexCharSet coffeeRegex
|
||||
|
||||
" A heregex
|
||||
syn region coffeeHeregex start=#///# end=#///[gimy]\{,4}#
|
||||
\ contains=@coffeeInterpString,coffeeHeregexComment,
|
||||
\ coffeeHeregexCharSet
|
||||
\ fold
|
||||
syn region coffeeHeregexCharSet start=/\[/ end=/]/ contained
|
||||
\ contains=@coffeeInterpString
|
||||
hi def link coffeeHeregex coffeeRegex
|
||||
hi def link coffeeHeregexCharSet coffeeHeregex
|
||||
|
||||
" Heredoc strings
|
||||
syn region coffeeHeredoc start=/"""/ end=/"""/ contains=@coffeeInterpString
|
||||
\ fold
|
||||
syn region coffeeHeredoc start=/'''/ end=/'''/ contains=@coffeeBasicString
|
||||
\ fold
|
||||
hi def link coffeeHeredoc String
|
||||
|
||||
" An error for trailing whitespace, as long as the line isn't just whitespace
|
||||
syn match coffeeSpaceError /\S\@<=\s\+$/ display
|
||||
hi def link coffeeSpaceError Error
|
||||
|
||||
" An error for trailing semicolons, for help transitioning from JavaScript
|
||||
syn match coffeeSemicolonError /;$/ display
|
||||
hi def link coffeeSemicolonError Error
|
||||
|
||||
" Ignore reserved words in dot accesses.
|
||||
syn match coffeeDotAccess /\.\@<!\.\s*\%(\I\|\$\)\%(\i\|\$\)*/he=s+1 contains=@coffeeIdentifier
|
||||
hi def link coffeeDotAccess coffeeExtendedOp
|
||||
|
||||
" Ignore reserved words in prototype accesses.
|
||||
syn match coffeeProtoAccess /::\s*\%(\I\|\$\)\%(\i\|\$\)*/he=s+2 contains=@coffeeIdentifier
|
||||
hi def link coffeeProtoAccess coffeeExtendedOp
|
||||
|
||||
" This is required for interpolations to work.
|
||||
syn region coffeeCurlies matchgroup=coffeeCurly start=/{/ end=/}/
|
||||
\ contains=@coffeeAll
|
||||
syn region coffeeBrackets matchgroup=coffeeBracket start=/\[/ end=/\]/
|
||||
\ contains=@coffeeAll
|
||||
syn region coffeeParens matchgroup=coffeeParen start=/(/ end=/)/
|
||||
\ contains=@coffeeAll
|
||||
|
||||
" These are highlighted the same as commas since they tend to go together.
|
||||
hi def link coffeeBlock coffeeSpecialOp
|
||||
hi def link coffeeBracket coffeeBlock
|
||||
hi def link coffeeCurly coffeeBlock
|
||||
hi def link coffeeParen coffeeBlock
|
||||
|
||||
" This is used instead of TOP to keep things coffee-specific for good
|
||||
" embedding. `contained` groups aren't included.
|
||||
syn cluster coffeeAll contains=coffeeStatement,coffeeRepeat,coffeeConditional,
|
||||
\ coffeeException,coffeeKeyword,coffeeOperator,
|
||||
\ coffeeExtendedOp,coffeeSpecialOp,coffeeBoolean,
|
||||
\ coffeeGlobal,coffeeSpecialVar,coffeeSpecialIdent,
|
||||
\ coffeeObject,coffeeConstant,coffeeString,
|
||||
\ coffeeNumber,coffeeFloat,coffeeReservedError,
|
||||
\ coffeeObjAssign,coffeeComment,coffeeBlockComment,
|
||||
\ coffeeEmbed,coffeeRegex,coffeeHeregex,
|
||||
\ coffeeHeredoc,coffeeSpaceError,
|
||||
\ coffeeSemicolonError,coffeeDotAccess,
|
||||
\ coffeeProtoAccess,coffeeCurlies,coffeeBrackets,
|
||||
\ coffeeParens
|
||||
|
||||
if !exists('b:current_syntax')
|
||||
let b:current_syntax = 'coffee'
|
||||
endif
|
@ -1,23 +0,0 @@
|
||||
" Language: Literate CoffeeScript
|
||||
" Maintainer: Michael Smith <michael@diglumi.com>
|
||||
" URL: https://github.com/mintplant/vim-literate-coffeescript
|
||||
" License: MIT
|
||||
|
||||
if exists('b:current_syntax') && b:current_syntax == 'litcoffee'
|
||||
finish
|
||||
endif
|
||||
|
||||
syn include @markdown syntax/markdown.vim
|
||||
syn include @coffee syntax/coffee.vim
|
||||
|
||||
" Partition the file into notCoffee and inlineCoffee. Each line will match
|
||||
" exactly one of these regions. notCoffee matches with a zero-width
|
||||
" look-behind.
|
||||
syn region notCoffee start='^\%( \|\t\)\@<!' end='$' contains=@markdown
|
||||
syn region inlineCoffee start='^ \|\t' end='$' contains=@coffee
|
||||
|
||||
" We defined notCoffee as a region so we can highlight every element in it
|
||||
" that doesn't have it's own explicit rule.
|
||||
highlight default link notCoffee Comment
|
||||
|
||||
let b:current_syntax = "litcoffee"
|
@ -1,3 +0,0 @@
|
||||
# Nested curlies
|
||||
" >> #{ == { { { } } } == } << "
|
||||
" >> #{ == { abc: { def: 42 } } == } << "
|
@ -1,90 +0,0 @@
|
||||
# Various operators
|
||||
abc instanceof def
|
||||
typeof abc
|
||||
delete abc
|
||||
abc::def
|
||||
|
||||
abc + def
|
||||
abc - def
|
||||
abc * def
|
||||
abc / def
|
||||
abc % def
|
||||
abc & def
|
||||
abc | def
|
||||
abc ^ def
|
||||
abc >> def
|
||||
abc << def
|
||||
abc >>> def
|
||||
abc ? def
|
||||
abc && def
|
||||
abc and def
|
||||
abc || def
|
||||
abc or def
|
||||
|
||||
abc += def
|
||||
abc -= def
|
||||
abc *= def
|
||||
abc /= def
|
||||
abc %= def
|
||||
abc &= def
|
||||
abc |= def
|
||||
abc ^= def
|
||||
abc >>= def
|
||||
abc <<= def
|
||||
abc >>>= def
|
||||
abc ?= def
|
||||
abc &&= def
|
||||
abc ||= def
|
||||
|
||||
abc and= def
|
||||
abc or= def
|
||||
|
||||
abc.def.ghi
|
||||
abc?.def?.ghi
|
||||
|
||||
abc < def
|
||||
abc > def
|
||||
abc = def
|
||||
abc == def
|
||||
abc != def
|
||||
abc <= def
|
||||
abc >= def
|
||||
|
||||
abc++
|
||||
abc--
|
||||
++abc
|
||||
--abc
|
||||
|
||||
# Nested operators
|
||||
abc[def] = ghi
|
||||
abc[def[ghi: jkl]] = 42
|
||||
@abc[def] = ghi
|
||||
|
||||
abc["#{def = 42}"] = 42
|
||||
abc["#{def.ghi = 42}"] = 42
|
||||
abc["#{def[ghi] = 42}"] = 42
|
||||
abc["#{def['ghi']}"] = 42
|
||||
|
||||
# Object assignments
|
||||
abc =
|
||||
def: 123
|
||||
DEF: 123
|
||||
@def: 123
|
||||
Def: 123
|
||||
'def': 123
|
||||
42: 123
|
||||
|
||||
# Operators shouldn't be highlighted
|
||||
vector=
|
||||
wand=
|
||||
|
||||
abc+++
|
||||
abc---
|
||||
abc ** def
|
||||
abc &&& def
|
||||
abc ^^ def
|
||||
abc ===== def
|
||||
abc <==== def
|
||||
abc >==== def
|
||||
abc +== def
|
||||
abc =^= def
|
@ -1,27 +0,0 @@
|
||||
# Should be an error
|
||||
function = 42
|
||||
var = 42
|
||||
|
||||
# Shouldn't be an error
|
||||
abc.with = 42
|
||||
function: 42
|
||||
var: 42
|
||||
|
||||
# Keywords shouldn't be highlighted
|
||||
abc.function
|
||||
abc.do
|
||||
abc.break
|
||||
abc.true
|
||||
|
||||
abc::function
|
||||
abc::do
|
||||
abc::break
|
||||
abc::true
|
||||
|
||||
abc:: function
|
||||
abc. function
|
||||
|
||||
# Numbers should be highlighted
|
||||
def.42
|
||||
def .42
|
||||
def::42
|
@ -1,117 +0,0 @@
|
||||
The **Scope** class regulates lexical scoping within CoffeeScript. As you
|
||||
generate code, you create a tree of scopes in the same shape as the nested
|
||||
function bodies. Each scope knows about the variables declared within it,
|
||||
and has a reference to its parent enclosing scope. In this way, we know which
|
||||
variables are new and need to be declared with `var`, and which are shared
|
||||
with external scopes.
|
||||
|
||||
Import the helpers we plan to use.
|
||||
|
||||
{extend, last} = require './helpers'
|
||||
|
||||
exports.Scope = class Scope
|
||||
|
||||
The `root` is the top-level **Scope** object for a given file.
|
||||
|
||||
@root: null
|
||||
|
||||
Initialize a scope with its parent, for lookups up the chain,
|
||||
as well as a reference to the **Block** node it belongs to, which is
|
||||
where it should declare its variables, and a reference to the function that
|
||||
it belongs to.
|
||||
|
||||
constructor: (@parent, @expressions, @method) ->
|
||||
@variables = [{name: 'arguments', type: 'arguments'}]
|
||||
@positions = {}
|
||||
Scope.root = this unless @parent
|
||||
|
||||
Adds a new variable or overrides an existing one.
|
||||
|
||||
add: (name, type, immediate) ->
|
||||
return @parent.add name, type, immediate if @shared and not immediate
|
||||
if Object::hasOwnProperty.call @positions, name
|
||||
@variables[@positions[name]].type = type
|
||||
else
|
||||
@positions[name] = @variables.push({name, type}) - 1
|
||||
|
||||
When `super` is called, we need to find the name of the current method we're
|
||||
in, so that we know how to invoke the same method of the parent class. This
|
||||
can get complicated if super is being called from an inner function.
|
||||
`namedMethod` will walk up the scope tree until it either finds the first
|
||||
function object that has a name filled in, or bottoms out.
|
||||
|
||||
namedMethod: ->
|
||||
return @method if @method.name or !@parent
|
||||
@parent.namedMethod()
|
||||
|
||||
Look up a variable name in lexical scope, and declare it if it does not
|
||||
already exist.
|
||||
|
||||
find: (name) ->
|
||||
return yes if @check name
|
||||
@add name, 'var'
|
||||
no
|
||||
|
||||
Reserve a variable name as originating from a function parameter for this
|
||||
scope. No `var` required for internal references.
|
||||
|
||||
parameter: (name) ->
|
||||
return if @shared and @parent.check name, yes
|
||||
@add name, 'param'
|
||||
|
||||
Just check to see if a variable has already been declared, without reserving,
|
||||
walks up to the root scope.
|
||||
|
||||
check: (name) ->
|
||||
!!(@type(name) or @parent?.check(name))
|
||||
|
||||
Generate a temporary variable name at the given index.
|
||||
|
||||
temporary: (name, index) ->
|
||||
if name.length > 1
|
||||
'_' + name + if index > 1 then index - 1 else ''
|
||||
else
|
||||
'_' + (index + parseInt name, 36).toString(36).replace /\d/g, 'a'
|
||||
|
||||
Gets the type of a variable.
|
||||
|
||||
type: (name) ->
|
||||
return v.type for v in @variables when v.name is name
|
||||
null
|
||||
|
||||
If we need to store an intermediate result, find an available name for a
|
||||
compiler-generated variable. `_var`, `_var2`, and so on...
|
||||
|
||||
freeVariable: (name, reserve=true) ->
|
||||
index = 0
|
||||
index++ while @check((temp = @temporary name, index))
|
||||
@add temp, 'var', yes if reserve
|
||||
temp
|
||||
|
||||
Ensure that an assignment is made at the top of this scope
|
||||
(or at the top-level scope, if requested).
|
||||
|
||||
assign: (name, value) ->
|
||||
@add name, {value, assigned: yes}, yes
|
||||
@hasAssignments = yes
|
||||
|
||||
Does this scope have any declared variables?
|
||||
|
||||
hasDeclarations: ->
|
||||
!!@declaredVariables().length
|
||||
|
||||
Return the list of variables first declared in this scope.
|
||||
|
||||
declaredVariables: ->
|
||||
realVars = []
|
||||
tempVars = []
|
||||
for v in @variables when v.type is 'var'
|
||||
(if v.name.charAt(0) is '_' then tempVars else realVars).push v.name
|
||||
realVars.sort().concat tempVars.sort()
|
||||
|
||||
Return the list of assignments that are supposed to be made at the top
|
||||
of this scope.
|
||||
|
||||
assignedVariables: ->
|
||||
"#{v.name} = #{v.type.value}" for v in @variables when v.type.assigned
|
||||
|
@ -1,3 +0,0 @@
|
||||
:coffeescript
|
||||
class Hello
|
||||
# test
|
@ -1,17 +0,0 @@
|
||||
<head>
|
||||
<script type="text/coffeescript">
|
||||
abc = {
|
||||
def: 42
|
||||
}
|
||||
</script>
|
||||
<script type='text/coffeescript'>
|
||||
abc = {
|
||||
def: 42
|
||||
}
|
||||
</script>
|
||||
<script type=text/coffeescript>
|
||||
abc = {
|
||||
def: 42
|
||||
}
|
||||
</script>
|
||||
</head>
|
@ -1,117 +0,0 @@
|
||||
The **Scope** class regulates lexical scoping within CoffeeScript. As you
|
||||
generate code, you create a tree of scopes in the same shape as the nested
|
||||
function bodies. Each scope knows about the variables declared within it,
|
||||
and has a reference to its parent enclosing scope. In this way, we know which
|
||||
variables are new and need to be declared with `var`, and which are shared
|
||||
with external scopes.
|
||||
|
||||
Import the helpers we plan to use.
|
||||
|
||||
{extend, last} = require './helpers'
|
||||
|
||||
exports.Scope = class Scope
|
||||
|
||||
The `root` is the top-level **Scope** object for a given file.
|
||||
|
||||
@root: null
|
||||
|
||||
Initialize a scope with its parent, for lookups up the chain,
|
||||
as well as a reference to the **Block** node it belongs to, which is
|
||||
where it should declare its variables, and a reference to the function that
|
||||
it belongs to.
|
||||
|
||||
constructor: (@parent, @expressions, @method) ->
|
||||
@variables = [{name: 'arguments', type: 'arguments'}]
|
||||
@positions = {}
|
||||
Scope.root = this unless @parent
|
||||
|
||||
Adds a new variable or overrides an existing one.
|
||||
|
||||
add: (name, type, immediate) ->
|
||||
return @parent.add name, type, immediate if @shared and not immediate
|
||||
if Object::hasOwnProperty.call @positions, name
|
||||
@variables[@positions[name]].type = type
|
||||
else
|
||||
@positions[name] = @variables.push({name, type}) - 1
|
||||
|
||||
When `super` is called, we need to find the name of the current method we're
|
||||
in, so that we know how to invoke the same method of the parent class. This
|
||||
can get complicated if super is being called from an inner function.
|
||||
`namedMethod` will walk up the scope tree until it either finds the first
|
||||
function object that has a name filled in, or bottoms out.
|
||||
|
||||
namedMethod: ->
|
||||
return @method if @method.name or !@parent
|
||||
@parent.namedMethod()
|
||||
|
||||
Look up a variable name in lexical scope, and declare it if it does not
|
||||
already exist.
|
||||
|
||||
find: (name) ->
|
||||
return yes if @check name
|
||||
@add name, 'var'
|
||||
no
|
||||
|
||||
Reserve a variable name as originating from a function parameter for this
|
||||
scope. No `var` required for internal references.
|
||||
|
||||
parameter: (name) ->
|
||||
return if @shared and @parent.check name, yes
|
||||
@add name, 'param'
|
||||
|
||||
Just check to see if a variable has already been declared, without reserving,
|
||||
walks up to the root scope.
|
||||
|
||||
check: (name) ->
|
||||
!!(@type(name) or @parent?.check(name))
|
||||
|
||||
Generate a temporary variable name at the given index.
|
||||
|
||||
temporary: (name, index) ->
|
||||
if name.length > 1
|
||||
'_' + name + if index > 1 then index - 1 else ''
|
||||
else
|
||||
'_' + (index + parseInt name, 36).toString(36).replace /\d/g, 'a'
|
||||
|
||||
Gets the type of a variable.
|
||||
|
||||
type: (name) ->
|
||||
return v.type for v in @variables when v.name is name
|
||||
null
|
||||
|
||||
If we need to store an intermediate result, find an available name for a
|
||||
compiler-generated variable. `_var`, `_var2`, and so on...
|
||||
|
||||
freeVariable: (name, reserve=true) ->
|
||||
index = 0
|
||||
index++ while @check((temp = @temporary name, index))
|
||||
@add temp, 'var', yes if reserve
|
||||
temp
|
||||
|
||||
Ensure that an assignment is made at the top of this scope
|
||||
(or at the top-level scope, if requested).
|
||||
|
||||
assign: (name, value) ->
|
||||
@add name, {value, assigned: yes}, yes
|
||||
@hasAssignments = yes
|
||||
|
||||
Does this scope have any declared variables?
|
||||
|
||||
hasDeclarations: ->
|
||||
!!@declaredVariables().length
|
||||
|
||||
Return the list of variables first declared in this scope.
|
||||
|
||||
declaredVariables: ->
|
||||
realVars = []
|
||||
tempVars = []
|
||||
for v in @variables when v.type is 'var'
|
||||
(if v.name.charAt(0) is '_' then tempVars else realVars).push v.name
|
||||
realVars.sort().concat tempVars.sort()
|
||||
|
||||
Return the list of assignments that are supposed to be made at the top
|
||||
of this scope.
|
||||
|
||||
assignedVariables: ->
|
||||
"#{v.name} = #{v.type.value}" for v in @variables when v.type.assigned
|
||||
|
1
sources_non_forked/vim-ruby/.gitignore
vendored
1
sources_non_forked/vim-ruby/.gitignore
vendored
@ -1 +0,0 @@
|
||||
doc/tags
|
@ -1 +0,0 @@
|
||||
--color
|
@ -1,19 +0,0 @@
|
||||
Maintainers:
|
||||
Mark Guzman <segfault@hasno.info>
|
||||
Doug Kearns <dougkearns@gmail.com>
|
||||
Tim Pope <vim@NOSPAMtpope.org>
|
||||
Andrew Radev <andrey.radev@gmail.com>
|
||||
Nikolai Weibull <now@bitwi.se>
|
||||
|
||||
Other contributors:
|
||||
Michael Brailsford <brailsmt@yahoo.com>
|
||||
Sean Flanagan <sdflanagan@ozemail.com.au>
|
||||
Tim Hammerquist <timh@rubyforge.org>
|
||||
Ken Miller <ken.miller@gmail.com>
|
||||
Hugh Sasse <hgs@dmu.ac.uk>
|
||||
Tilman Sauerbeck <tilman@code-monkey.de>
|
||||
Bertram Scharpf <info@bertram-scharpf.de>
|
||||
Gavin Sinclair <gsinclair@gmail.com>
|
||||
Aaron Son <aaronson@uiuc.edu>
|
||||
Ned Konz <ned@bike-nomad.com>
|
||||
Pan Thomakos <pan.thomakos@gmail.com>
|
File diff suppressed because it is too large
Load Diff
@ -1,4 +0,0 @@
|
||||
source 'http://rubygems.org'
|
||||
|
||||
gem 'rspec'
|
||||
gem 'vimrunner'
|
@ -1,28 +0,0 @@
|
||||
GEM
|
||||
remote: http://rubygems.org/
|
||||
specs:
|
||||
diff-lcs (1.3)
|
||||
rspec (3.5.0)
|
||||
rspec-core (~> 3.5.0)
|
||||
rspec-expectations (~> 3.5.0)
|
||||
rspec-mocks (~> 3.5.0)
|
||||
rspec-core (3.5.4)
|
||||
rspec-support (~> 3.5.0)
|
||||
rspec-expectations (3.5.0)
|
||||
diff-lcs (>= 1.2.0, < 2.0)
|
||||
rspec-support (~> 3.5.0)
|
||||
rspec-mocks (3.5.0)
|
||||
diff-lcs (>= 1.2.0, < 2.0)
|
||||
rspec-support (~> 3.5.0)
|
||||
rspec-support (3.5.0)
|
||||
vimrunner (0.3.0)
|
||||
|
||||
PLATFORMS
|
||||
ruby
|
||||
|
||||
DEPENDENCIES
|
||||
rspec
|
||||
vimrunner
|
||||
|
||||
BUNDLED WITH
|
||||
1.13.7
|
@ -1,38 +0,0 @@
|
||||
Installation
|
||||
============
|
||||
|
||||
In general, your favorite method works. Here are some options.
|
||||
|
||||
With pathogen.vim
|
||||
-----------------
|
||||
|
||||
Install [pathogen.vim](https://github.com/tpope/vim-pathogen),
|
||||
then copy and paste:
|
||||
|
||||
git clone git://github.com/vim-ruby/vim-ruby.git ~/.vim/bundle/vim-ruby
|
||||
|
||||
With Vundle
|
||||
-----------
|
||||
|
||||
Install [Vundle](https://github.com/gmarik/vundle), then add the
|
||||
following to your vimrc:
|
||||
|
||||
Bundle 'vim-ruby/vim-ruby'
|
||||
|
||||
With patience
|
||||
-------------
|
||||
|
||||
Wait for an upgrade to Vim and install it. Vim ships with the latest
|
||||
version of vim-ruby at the time of its release. (Remember this when
|
||||
choosing another installation method. The version you download will
|
||||
supersede the version that ships with Vim, so you will now be
|
||||
responsible for keeping it up-to-date.)
|
||||
|
||||
If you're looking for stable releases from a particular version, you can find
|
||||
them in [github](https://github.com/vim-ruby/vim-ruby/releases).
|
||||
|
||||
Manually
|
||||
--------
|
||||
|
||||
[Download](https://github.com/vim-ruby/vim-ruby/archives/master) and
|
||||
extract the relevant files to `~/.vim` (or `$HOME/vimfiles` on Windows).
|
@ -1,243 +0,0 @@
|
||||
This file is no longer maintained. Consult the Git log for newer changes.
|
||||
|
||||
= 2008.07.XX
|
||||
|
||||
== Filetype Detection
|
||||
|
||||
The IRB RC file (.irbrc) is now detected as being a Ruby file.
|
||||
|
||||
|
||||
= 2007.05.07
|
||||
|
||||
== Ruby Syntax Highlighting
|
||||
|
||||
Highlight OPTIMIZE alongside FIXME and TODO.
|
||||
|
||||
Multiline array literals can now be folded.
|
||||
|
||||
== Ruby Filetype Support
|
||||
|
||||
Added mappings for [[, ]], [], ][, [m, ]m, [M, and ]M. The first four bounce
|
||||
between class and module declarations, and the last four between method
|
||||
declarations.
|
||||
|
||||
== eRuby Syntax Highlighting
|
||||
|
||||
Tim Pope has taken over maintenance of the eRuby syntax file. The subtype of
|
||||
the file is now determined dynamically from the filename, rather than being
|
||||
hardwired to HTML. It can be overridden with b:eruby_subtype.
|
||||
|
||||
== eRuby Filetype Support
|
||||
|
||||
Tim Pope has taken over maintenance of the eRuby filetype plugin. Like with
|
||||
the syntax file, the subtype is now determined dynamically.
|
||||
|
||||
== eRuby Indenting
|
||||
|
||||
As with the syntax file and filetype plugin, the subtype is now determined
|
||||
dynamically.
|
||||
|
||||
== Bug Fixes
|
||||
|
||||
Ruby syntax file
|
||||
- when ruby_operators is set, highlight scope and range operators, and don't
|
||||
match '>' in =>'
|
||||
- regexp literals are highlighted after the 'else' keyword
|
||||
- don't match [!=?] as part of a sigil prefixed symbol name
|
||||
- allow text to appear after, and on the same line, as '=begin' in
|
||||
rubyDocumentation regions
|
||||
- highlight %s() ans a symbol, not a string
|
||||
- eliminated some false positves for here docs, symbols, ASCII codes, and
|
||||
conditionals as statement modifiers
|
||||
- added "neus" to regexp flags
|
||||
- Highlight punctuation variables in string interpolation, and flag invalid
|
||||
ones as errors
|
||||
- removed : from rubyOptionalDoLine (falsely matches on symbols)
|
||||
|
||||
Ruby filetype plugin
|
||||
- eliminated some false positives with the matchit patterns
|
||||
|
||||
Ruby indent plugin
|
||||
- ignore instance, class, and global variables named "end"
|
||||
|
||||
|
||||
= 2007.03.02
|
||||
|
||||
== Omni Completion
|
||||
|
||||
Fall back to syntax highlighting completion if Vim lacks the Ruby interface.
|
||||
|
||||
RubyGems is now loaded by default if available.
|
||||
|
||||
Classes are detected using ObjectSpace. Kernel methods are included in method
|
||||
completion.
|
||||
|
||||
Added completion in Rails views. Rails helpers are included. Rails migrations
|
||||
now have completion.
|
||||
|
||||
== Ruby Syntax Highlighting
|
||||
|
||||
Ruby code is highlighted inside interpolation regions.
|
||||
|
||||
Symbols are now highlighted with the Constant highlight group; Constants and
|
||||
class names with the Type highlight group.
|
||||
|
||||
Symbol names specified with a string recognise interpolation and escape
|
||||
sequences.
|
||||
|
||||
Alias statements receive special highlighting similar to other 'definitions'.
|
||||
|
||||
== Ruby Filetype Support
|
||||
|
||||
Matchit support has been improved to include (), {}, and [] in the list of
|
||||
patterns so that these will be appropriately skipped when included in comments.
|
||||
|
||||
ri has been added as the 'keywordprg' and 'balloonexpr' is set to return the
|
||||
output of ri.
|
||||
|
||||
== eRuby Indenting
|
||||
|
||||
Tim Pope has taken over maintenance of the eRuby indent file. Ruby code is now
|
||||
indented appropriately.
|
||||
|
||||
== Bug Fixes
|
||||
|
||||
Ruby syntax file
|
||||
- trailing whitespace is no longer included with the def, class, module
|
||||
keywords.
|
||||
- escaped interpolation regions should now be ignored in all cases.
|
||||
- conditional and loop statements are now highlighted correctly in more
|
||||
locations (where they're used as expressions).
|
||||
|
||||
eRuby syntax file
|
||||
- '-' trim mode block delimiters are now recognised.
|
||||
|
||||
Omni Completion
|
||||
- more robustness; failure to parse buffer no longer errors or prevents
|
||||
completion.
|
||||
|
||||
|
||||
= 2006.07.11
|
||||
|
||||
== Omni Completion
|
||||
|
||||
A new omni completion function is now included which offers IntelliSense-like
|
||||
functionality. See :help ft-ruby-omni for further information.
|
||||
|
||||
Note: This will only work with Vim 7.x, compiled with the Ruby interface
|
||||
(+ruby), and Ruby 1.8.x
|
||||
|
||||
== Ruby Filetype Support
|
||||
|
||||
Matchit support has been improved to include (), {}, and [] in the list of
|
||||
patterns meaning these will be appropriately skipped when included in comments.
|
||||
|
||||
== Ruby Syntax Highlighting
|
||||
|
||||
Operators can now be highlighted by defining the Vim global variable
|
||||
"ruby_operators".
|
||||
|
||||
Multiline comments will now be folded. This can be disabled by defining the
|
||||
"ruby_no_comment_fold" Vim variable.
|
||||
|
||||
== Filetype Detection
|
||||
|
||||
RJS and RXML templates are now detected as being 'filetype=ruby'.
|
||||
|
||||
== FAQ
|
||||
|
||||
There is a new FAQ document included. This is a work in progress and any
|
||||
feedback would be appreciated.
|
||||
|
||||
== Bug Fixes
|
||||
|
||||
Ruby syntax file - if/unless modifiers after a method name ending with [?!=]
|
||||
should now be highlighted correctly.
|
||||
|
||||
|
||||
= 2005.10.07
|
||||
|
||||
== Vim 6.4
|
||||
|
||||
This release is included in Vim 6.4.
|
||||
|
||||
== Bug Fixes
|
||||
|
||||
Ruby filetype plugin - symbols were incorrectly being matched as match_words
|
||||
causing the matchit motion command to jump to an incorrect location in some
|
||||
circumstances.
|
||||
|
||||
|
||||
= 2005.10.05
|
||||
|
||||
== Bug Fixes
|
||||
|
||||
Ruby syntax file - allow for comments directly after module/class/def lines
|
||||
without intervening whitespace (fold markers were breaking syntax highlighting).
|
||||
|
||||
Ruby filetype plugin - improve ordering of 'path' elements.
|
||||
|
||||
eRuby syntax file - make use of ruby_no_expensive local to the buffer.
|
||||
|
||||
|
||||
= 2005.09.24
|
||||
|
||||
== Filetype Detection
|
||||
|
||||
The eruby filetype is now detected solely based on the file's extension. This
|
||||
was being overridden by the scripts.vim detection script.
|
||||
|
||||
Note: Only files ending in *.rhtml are detected as filetype eruby since these
|
||||
are currently assumed to be Ruby embedded in (X)HTML only. Other filetypes
|
||||
could be supported if requested.
|
||||
|
||||
== eRuby Indent File
|
||||
|
||||
There is a new eRuby indent file which simply sources the HTML indent file for
|
||||
now.
|
||||
|
||||
== eRuby Compiler Plugin
|
||||
|
||||
This now supports erb as the default 'makeprg'. To use eruby set the
|
||||
eruby_compiler variable to "eruby" in your .vimrc
|
||||
|
||||
== Test::Unit Compiler Plugin
|
||||
|
||||
This has been improved and should now display messages similar to, though more
|
||||
detailed than, the GUI test runners.
|
||||
|
||||
== Bug Fixes
|
||||
|
||||
A few minor bugs have been fixed in the Ruby syntax and indent files.
|
||||
|
||||
|
||||
= 2005.09.15
|
||||
|
||||
== eRuby Support
|
||||
|
||||
There are new syntax, compiler, and ftplugin files for eRuby. This support is
|
||||
incomplete and we're keen to hear of any problems or suggestions you may have
|
||||
to improve it.
|
||||
|
||||
== Ruby Filetype Support
|
||||
|
||||
The Ruby filetype plugin has been improved to include as many useful settings
|
||||
as possible without intruding too much on an individual user's preferences.
|
||||
Matchit support has been improved, and the following options are now set to
|
||||
appropriate values: comments, commentstring, formatoptions, include,
|
||||
includeexpr, path, and suffixesadd
|
||||
|
||||
== Filetype Detection
|
||||
|
||||
The new ftdetect mechanism of Vim 6.3 is being utilized to enable filetype
|
||||
detection of eRuby files until this is officially added to the next release of
|
||||
Vim.
|
||||
|
||||
== Installation Directories
|
||||
|
||||
The installer script now, where possible, automatically determines both the
|
||||
user and system-wide preferences directory.
|
||||
|
||||
== Bug Fixes
|
||||
|
||||
A large number of bugs have been fixed in the Ruby syntax and indent files.
|
@ -1,63 +0,0 @@
|
||||
## Vim-ruby
|
||||
|
||||
This project contains Vim's runtime files for ruby support. This includes syntax
|
||||
highlighting, indentation, omnicompletion, and various useful tools and mappings.
|
||||
|
||||
## Installation
|
||||
|
||||
See the file [INSTALL.markdown](./INSTALL.markdown) for instructions.
|
||||
|
||||
You might also find useful setup tips in the github wiki:
|
||||
https://github.com/vim-ruby/vim-ruby/wiki/VimRubySupport
|
||||
|
||||
## Usage
|
||||
|
||||
Ideally, vim-ruby should work "correctly" for you out of the box. However, ruby
|
||||
developers have varying preferences, so there are settings that control some of
|
||||
the details. You can get more information on these by using the native `:help`
|
||||
command:
|
||||
|
||||
- [`:help vim-ruby-plugin`](./doc/ft-ruby-plugin.txt): Filetype settings and custom mappings
|
||||
- [`:help vim-ruby-indent`](./doc/ft-ruby-indent.txt): Indentation settings
|
||||
- [`:help vim-ruby-syntax`](./doc/ft-ruby-syntax.txt): Syntax-related tweaks
|
||||
- [`:help vim-ruby-omni`](./doc/ft-ruby-omni.txt): Information and settings for omni completion
|
||||
|
||||
## Issues
|
||||
|
||||
If you have an issue or a feature request, it's recommended to use the github
|
||||
issue tracker: https://github.com/vim-ruby/vim-ruby/issues. Try the search box
|
||||
to look for an existing issue -- it might have already been reported.
|
||||
|
||||
If you don't have a github account or would rather contact us in a different
|
||||
way, you can find emails for individual maintainers in the
|
||||
[CONTRIBUTORS](./CONTRIBUTORS) file. They're also in the comment headers of the
|
||||
project's Vimscript files (`syntax/ruby.vim`, `indent/ruby.vim`, etc) under the
|
||||
label "Maintainer".
|
||||
|
||||
If you're not sure who the most relevant person to contact is for your
|
||||
particular issue, you can send an email to the release coordinator, Doug Kearns
|
||||
(dougkearns at gmail.com).
|
||||
|
||||
## Contributing
|
||||
|
||||
Vim-ruby is a mature project, which is one way of saying it moves slowly and it
|
||||
can be a bit difficult to modify. It's far from impossible, but be warned that
|
||||
issues and PRs may take time to be handled. Partly, it's because we don't want
|
||||
to risk breaking Vim's core ruby support, partly because it takes a lot of time
|
||||
and energy to debug and fix things.
|
||||
|
||||
Contributing a fix for an issue would be very appreciated, even if it's a
|
||||
proof-of-concept to start a conversation. Be warned that we're definitely going
|
||||
to be conservative when considering changes to vim-ruby.
|
||||
|
||||
The code is tested using [RSpec](https://rspec.info/) and
|
||||
[Vimrunner](https://github.com/AndrewRadev/vimrunner). The tests are not
|
||||
exhaustive, but they should cover a wide variety of cases.
|
||||
|
||||
## Project history
|
||||
|
||||
This project began in July 2003, when the current version of Vim was 6.2. It
|
||||
was migrated from CVS in August, 2008.
|
||||
|
||||
If you're curious about individual pre-git changes, you can read some of them
|
||||
in the (unmaintained) [NEWS](./NEWS) and/or [ChangeLog](./ChangeLog) files.
|
@ -1,871 +0,0 @@
|
||||
" Vim completion script
|
||||
" Language: Ruby
|
||||
" Maintainer: Mark Guzman <segfault@hasno.info>
|
||||
" URL: https://github.com/vim-ruby/vim-ruby
|
||||
" Release Coordinator: Doug Kearns <dougkearns@gmail.com>
|
||||
" ----------------------------------------------------------------------------
|
||||
"
|
||||
" Ruby IRB/Complete author: Keiju ISHITSUKA(keiju@ishitsuka.com)
|
||||
" ----------------------------------------------------------------------------
|
||||
|
||||
" {{{ requirement checks
|
||||
|
||||
function! s:ErrMsg(msg)
|
||||
echohl ErrorMsg
|
||||
echo a:msg
|
||||
echohl None
|
||||
endfunction
|
||||
|
||||
if !has('ruby')
|
||||
call s:ErrMsg( "Error: Rubycomplete requires vim compiled with +ruby" )
|
||||
call s:ErrMsg( "Error: falling back to syntax completion" )
|
||||
" lets fall back to syntax completion
|
||||
setlocal omnifunc=syntaxcomplete#Complete
|
||||
finish
|
||||
endif
|
||||
|
||||
if version < 700
|
||||
call s:ErrMsg( "Error: Required vim >= 7.0" )
|
||||
finish
|
||||
endif
|
||||
" }}} requirement checks
|
||||
|
||||
" {{{ configuration failsafe initialization
|
||||
if !exists("g:rubycomplete_rails")
|
||||
let g:rubycomplete_rails = 0
|
||||
endif
|
||||
|
||||
if !exists("g:rubycomplete_classes_in_global")
|
||||
let g:rubycomplete_classes_in_global = 0
|
||||
endif
|
||||
|
||||
if !exists("g:rubycomplete_buffer_loading")
|
||||
let g:rubycomplete_buffer_loading = 0
|
||||
endif
|
||||
|
||||
if !exists("g:rubycomplete_include_object")
|
||||
let g:rubycomplete_include_object = 0
|
||||
endif
|
||||
|
||||
if !exists("g:rubycomplete_include_objectspace")
|
||||
let g:rubycomplete_include_objectspace = 0
|
||||
endif
|
||||
" }}} configuration failsafe initialization
|
||||
|
||||
" {{{ regex patterns
|
||||
|
||||
" Regex that defines the start-match for the 'end' keyword.
|
||||
let s:end_start_regex =
|
||||
\ '\C\%(^\s*\|[=,*/%+\-|;{]\|<<\|>>\|:\s\)\s*\zs' .
|
||||
\ '\<\%(module\|class\|if\|for\|while\|until\|case\|unless\|begin' .
|
||||
\ '\|\%(\K\k*[!?]\?\s\+\)\=def\):\@!\>' .
|
||||
\ '\|\%(^\|[^.:@$]\)\@<=\<do:\@!\>'
|
||||
|
||||
" Regex that defines the middle-match for the 'end' keyword.
|
||||
let s:end_middle_regex = '\<\%(ensure\|else\|\%(\%(^\|;\)\s*\)\@<=\<rescue:\@!\>\|when\|elsif\):\@!\>'
|
||||
|
||||
" Regex that defines the end-match for the 'end' keyword.
|
||||
let s:end_end_regex = '\%(^\|[^.:@$]\)\@<=\<end:\@!\>'
|
||||
|
||||
" }}} regex patterns
|
||||
|
||||
" {{{ vim-side support functions
|
||||
let s:rubycomplete_debug = 0
|
||||
|
||||
function! s:dprint(msg)
|
||||
if s:rubycomplete_debug == 1
|
||||
echom a:msg
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! s:GetBufferRubyModule(name, ...)
|
||||
if a:0 == 1
|
||||
let [snum,enum] = s:GetBufferRubyEntity(a:name, "module", a:1)
|
||||
else
|
||||
let [snum,enum] = s:GetBufferRubyEntity(a:name, "module")
|
||||
endif
|
||||
return snum . '..' . enum
|
||||
endfunction
|
||||
|
||||
function! s:GetBufferRubyClass(name, ...)
|
||||
if a:0 >= 1
|
||||
let [snum,enum] = s:GetBufferRubyEntity(a:name, "class", a:1)
|
||||
else
|
||||
let [snum,enum] = s:GetBufferRubyEntity(a:name, "class")
|
||||
endif
|
||||
return snum . '..' . enum
|
||||
endfunction
|
||||
|
||||
function! s:GetBufferRubySingletonMethods(name)
|
||||
endfunction
|
||||
|
||||
function! s:GetBufferRubyEntity( name, type, ... )
|
||||
let lastpos = getpos(".")
|
||||
let lastline = lastpos
|
||||
if (a:0 >= 1)
|
||||
let lastline = [ 0, a:1, 0, 0 ]
|
||||
call cursor( a:1, 0 )
|
||||
endif
|
||||
|
||||
let stopline = 1
|
||||
|
||||
let crex = '^\s*\<' . a:type . '\>\s*\<' . escape(a:name, '*') . '\>\s*\(<\s*.*\s*\)\?'
|
||||
let [lnum,lcol] = searchpos( crex, 'w' )
|
||||
"let [lnum,lcol] = searchpairpos( crex . '\zs', '', '\(end\|}\)', 'w' )
|
||||
|
||||
if lnum == 0 && lcol == 0
|
||||
call cursor(lastpos[1], lastpos[2])
|
||||
return [0,0]
|
||||
endif
|
||||
|
||||
let curpos = getpos(".")
|
||||
let [enum,ecol] = searchpairpos( s:end_start_regex, s:end_middle_regex, s:end_end_regex, 'W' )
|
||||
call cursor(lastpos[1], lastpos[2])
|
||||
|
||||
if lnum > enum
|
||||
return [0,0]
|
||||
endif
|
||||
" we found a the class def
|
||||
return [lnum,enum]
|
||||
endfunction
|
||||
|
||||
function! s:IsInClassDef()
|
||||
return s:IsPosInClassDef( line('.') )
|
||||
endfunction
|
||||
|
||||
function! s:IsPosInClassDef(pos)
|
||||
let [snum,enum] = s:GetBufferRubyEntity( '.*', "class" )
|
||||
let ret = 'nil'
|
||||
|
||||
if snum < a:pos && a:pos < enum
|
||||
let ret = snum . '..' . enum
|
||||
endif
|
||||
|
||||
return ret
|
||||
endfunction
|
||||
|
||||
function! s:IsInComment(pos)
|
||||
let stack = synstack(a:pos[0], a:pos[1])
|
||||
if !empty(stack)
|
||||
return synIDattr(stack[0], 'name') =~ 'ruby\%(.*Comment\|Documentation\)'
|
||||
else
|
||||
return 0
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! s:GetRubyVarType(v)
|
||||
let stopline = 1
|
||||
let vtp = ''
|
||||
let curpos = getpos('.')
|
||||
let sstr = '^\s*#\s*@var\s*'.escape(a:v, '*').'\>\s\+[^ \t]\+\s*$'
|
||||
let [lnum,lcol] = searchpos(sstr,'nb',stopline)
|
||||
if lnum != 0 && lcol != 0
|
||||
call setpos('.',curpos)
|
||||
let str = getline(lnum)
|
||||
let vtp = substitute(str,sstr,'\1','')
|
||||
return vtp
|
||||
endif
|
||||
call setpos('.',curpos)
|
||||
let ctors = '\(now\|new\|open\|get_instance'
|
||||
if exists('g:rubycomplete_rails') && g:rubycomplete_rails == 1 && s:rubycomplete_rails_loaded == 1
|
||||
let ctors = ctors.'\|find\|create'
|
||||
else
|
||||
endif
|
||||
let ctors = ctors.'\)'
|
||||
|
||||
let fstr = '=\s*\([^ \t]\+.' . ctors .'\>\|[\[{"''/]\|%[xwQqr][(\[{@]\|[A-Za-z0-9@:\-()\.]\+...\?\|lambda\|&\)'
|
||||
let sstr = ''.escape(a:v, '*').'\>\s*[+\-*/]*'.fstr
|
||||
let pos = searchpos(sstr,'bW')
|
||||
while pos != [0,0] && s:IsInComment(pos)
|
||||
let pos = searchpos(sstr,'bW')
|
||||
endwhile
|
||||
if pos != [0,0]
|
||||
let [lnum, col] = pos
|
||||
let str = matchstr(getline(lnum),fstr,col)
|
||||
let str = substitute(str,'^=\s*','','')
|
||||
|
||||
call setpos('.',pos)
|
||||
if str == '"' || str == '''' || stridx(tolower(str), '%q[') != -1
|
||||
return 'String'
|
||||
elseif str == '[' || stridx(str, '%w[') != -1
|
||||
return 'Array'
|
||||
elseif str == '{'
|
||||
return 'Hash'
|
||||
elseif str == '/' || str == '%r{'
|
||||
return 'Regexp'
|
||||
elseif strlen(str) >= 4 && stridx(str,'..') != -1
|
||||
return 'Range'
|
||||
elseif stridx(str, 'lambda') != -1 || str == '&'
|
||||
return 'Proc'
|
||||
elseif strlen(str) > 4
|
||||
let l = stridx(str,'.')
|
||||
return str[0:l-1]
|
||||
end
|
||||
return ''
|
||||
endif
|
||||
call setpos('.',curpos)
|
||||
return ''
|
||||
endfunction
|
||||
|
||||
"}}} vim-side support functions
|
||||
|
||||
"{{{ vim-side completion function
|
||||
function! rubycomplete#Init()
|
||||
execute "ruby VimRubyCompletion.preload_rails"
|
||||
endfunction
|
||||
|
||||
function! rubycomplete#Complete(findstart, base)
|
||||
"findstart = 1 when we need to get the text length
|
||||
if a:findstart
|
||||
let line = getline('.')
|
||||
let idx = col('.')
|
||||
while idx > 0
|
||||
let idx -= 1
|
||||
let c = line[idx-1]
|
||||
if c =~ '\w'
|
||||
continue
|
||||
elseif ! c =~ '\.'
|
||||
let idx = -1
|
||||
break
|
||||
else
|
||||
break
|
||||
endif
|
||||
endwhile
|
||||
|
||||
return idx
|
||||
"findstart = 0 when we need to return the list of completions
|
||||
else
|
||||
let g:rubycomplete_completions = []
|
||||
execute "ruby VimRubyCompletion.get_completions('" . a:base . "')"
|
||||
return g:rubycomplete_completions
|
||||
endif
|
||||
endfunction
|
||||
"}}} vim-side completion function
|
||||
|
||||
"{{{ ruby-side code
|
||||
function! s:DefRuby()
|
||||
ruby << RUBYEOF
|
||||
# {{{ ruby completion
|
||||
|
||||
begin
|
||||
require 'rubygems' # let's assume this is safe...?
|
||||
rescue Exception
|
||||
#ignore?
|
||||
end
|
||||
class VimRubyCompletion
|
||||
# {{{ constants
|
||||
@@debug = false
|
||||
@@ReservedWords = [
|
||||
"BEGIN", "END",
|
||||
"alias", "and",
|
||||
"begin", "break",
|
||||
"case", "class",
|
||||
"def", "defined", "do",
|
||||
"else", "elsif", "end", "ensure",
|
||||
"false", "for",
|
||||
"if", "in",
|
||||
"module",
|
||||
"next", "nil", "not",
|
||||
"or",
|
||||
"redo", "rescue", "retry", "return",
|
||||
"self", "super",
|
||||
"then", "true",
|
||||
"undef", "unless", "until",
|
||||
"when", "while",
|
||||
"yield",
|
||||
]
|
||||
|
||||
@@Operators = [ "%", "&", "*", "**", "+", "-", "/",
|
||||
"<", "<<", "<=", "<=>", "==", "===", "=~", ">", ">=", ">>",
|
||||
"[]", "[]=", "^", ]
|
||||
# }}} constants
|
||||
|
||||
# {{{ buffer analysis magic
|
||||
def load_requires
|
||||
|
||||
custom_paths = VIM::evaluate("get(g:, 'rubycomplete_load_paths', [])")
|
||||
|
||||
if !custom_paths.empty?
|
||||
$LOAD_PATH.concat(custom_paths).uniq!
|
||||
end
|
||||
|
||||
buf = VIM::Buffer.current
|
||||
enum = buf.line_number
|
||||
nums = Range.new( 1, enum )
|
||||
nums.each do |x|
|
||||
|
||||
ln = buf[x]
|
||||
begin
|
||||
if /.*require_relative\s*(.*)$/.match( ln )
|
||||
eval( "require %s" % File.expand_path($1) )
|
||||
elsif /.*require\s*(["'].*?["'])/.match( ln )
|
||||
eval( "require %s" % $1 )
|
||||
end
|
||||
rescue Exception => e
|
||||
dprint e.inspect
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def load_gems
|
||||
fpath = VIM::evaluate("get(g:, 'rubycomplete_gemfile_path', 'Gemfile')")
|
||||
return unless File.file?(fpath) && File.readable?(fpath)
|
||||
want_bundler = VIM::evaluate("get(g:, 'rubycomplete_use_bundler')")
|
||||
parse_file = !want_bundler
|
||||
begin
|
||||
require 'bundler'
|
||||
Bundler.setup
|
||||
Bundler.require
|
||||
rescue Exception
|
||||
parse_file = true
|
||||
end
|
||||
if parse_file
|
||||
File.new(fpath).each_line do |line|
|
||||
begin
|
||||
require $1 if /\s*gem\s*['"]([^'"]+)/.match(line)
|
||||
rescue Exception
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def load_buffer_class(name)
|
||||
dprint "load_buffer_class(%s) START" % name
|
||||
classdef = get_buffer_entity(name, 's:GetBufferRubyClass("%s")')
|
||||
return if classdef == nil
|
||||
|
||||
pare = /^\s*class\s*(.*)\s*<\s*(.*)\s*\n/.match( classdef )
|
||||
load_buffer_class( $2 ) if pare != nil && $2 != name # load parent class if needed
|
||||
|
||||
mixre = /.*\n\s*(include|prepend)\s*(.*)\s*\n/.match( classdef )
|
||||
load_buffer_module( $2 ) if mixre != nil && $2 != name # load mixins if needed
|
||||
|
||||
begin
|
||||
eval classdef
|
||||
rescue Exception
|
||||
VIM::evaluate( "s:ErrMsg( 'Problem loading class \"%s\", was it already completed?' )" % name )
|
||||
end
|
||||
dprint "load_buffer_class(%s) END" % name
|
||||
end
|
||||
|
||||
def load_buffer_module(name)
|
||||
dprint "load_buffer_module(%s) START" % name
|
||||
classdef = get_buffer_entity(name, 's:GetBufferRubyModule("%s")')
|
||||
return if classdef == nil
|
||||
|
||||
begin
|
||||
eval classdef
|
||||
rescue Exception
|
||||
VIM::evaluate( "s:ErrMsg( 'Problem loading module \"%s\", was it already completed?' )" % name )
|
||||
end
|
||||
dprint "load_buffer_module(%s) END" % name
|
||||
end
|
||||
|
||||
def get_buffer_entity(name, vimfun)
|
||||
loading_allowed = VIM::evaluate("exists('g:rubycomplete_buffer_loading') && g:rubycomplete_buffer_loading")
|
||||
return nil if loading_allowed.to_i.zero?
|
||||
return nil if /(\"|\')+/.match( name )
|
||||
buf = VIM::Buffer.current
|
||||
nums = eval( VIM::evaluate( vimfun % name ) )
|
||||
return nil if nums == nil
|
||||
return nil if nums.min == nums.max && nums.min == 0
|
||||
|
||||
dprint "get_buffer_entity START"
|
||||
visited = []
|
||||
clscnt = 0
|
||||
bufname = VIM::Buffer.current.name
|
||||
classdef = ""
|
||||
cur_line = VIM::Buffer.current.line_number
|
||||
while (nums != nil && !(nums.min == 0 && nums.max == 0) )
|
||||
dprint "visited: %s" % visited.to_s
|
||||
break if visited.index( nums )
|
||||
visited << nums
|
||||
|
||||
nums.each do |x|
|
||||
if x != cur_line
|
||||
next if x == 0
|
||||
ln = buf[x]
|
||||
is_const = false
|
||||
if /^\s*(module|class|def|include)\s+/.match(ln) || is_const = /^\s*?[A-Z]([A-z]|[1-9])*\s*?[|]{0,2}=\s*?.+\s*?/.match(ln)
|
||||
clscnt += 1 if /class|module/.match($1)
|
||||
# We must make sure to load each constant only once to avoid errors
|
||||
if is_const
|
||||
ln.gsub!(/\s*?[|]{0,2}=\s*?/, '||=')
|
||||
end
|
||||
#dprint "\$1$1
|
||||
classdef += "%s\n" % ln
|
||||
classdef += "end\n" if /def\s+/.match(ln)
|
||||
dprint ln
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
nm = "%s(::.*)*\", %s, \"" % [ name, nums.last ]
|
||||
nums = eval( VIM::evaluate( vimfun % nm ) )
|
||||
dprint "nm: \"%s\"" % nm
|
||||
dprint "vimfun: %s" % (vimfun % nm)
|
||||
dprint "got nums: %s" % nums.to_s
|
||||
end
|
||||
if classdef.length > 1
|
||||
classdef += "end\n"*clscnt
|
||||
# classdef = "class %s\n%s\nend\n" % [ bufname.gsub( /\/|\\/, "_" ), classdef ]
|
||||
end
|
||||
|
||||
dprint "get_buffer_entity END"
|
||||
dprint "classdef====start"
|
||||
lns = classdef.split( "\n" )
|
||||
lns.each { |x| dprint x }
|
||||
dprint "classdef====end"
|
||||
return classdef
|
||||
end
|
||||
|
||||
def get_var_type( receiver )
|
||||
if /(\"|\')+/.match( receiver )
|
||||
"String"
|
||||
else
|
||||
VIM::evaluate("s:GetRubyVarType('%s')" % receiver)
|
||||
end
|
||||
end
|
||||
|
||||
def dprint( txt )
|
||||
print txt if @@debug
|
||||
end
|
||||
|
||||
def escape_vim_singlequote_string(str)
|
||||
str.to_s.gsub(/'/,"\\'")
|
||||
end
|
||||
|
||||
def get_buffer_entity_list( type )
|
||||
# this will be a little expensive.
|
||||
loading_allowed = VIM::evaluate("exists('g:rubycomplete_buffer_loading') && g:rubycomplete_buffer_loading")
|
||||
allow_aggressive_load = VIM::evaluate("exists('g:rubycomplete_classes_in_global') && g:rubycomplete_classes_in_global")
|
||||
return [] if allow_aggressive_load.to_i.zero? || loading_allowed.to_i.zero?
|
||||
|
||||
buf = VIM::Buffer.current
|
||||
eob = buf.length
|
||||
ret = []
|
||||
rg = 1..eob
|
||||
re = eval( "/^\s*%s\s*([A-Za-z0-9_:-]*)(\s*<\s*([A-Za-z0-9_:-]*))?\s*/" % type )
|
||||
|
||||
rg.each do |x|
|
||||
if re.match( buf[x] )
|
||||
next if type == "def" && eval( VIM::evaluate("s:IsPosInClassDef(%s)" % x) ) != nil
|
||||
ret.push $1
|
||||
end
|
||||
end
|
||||
|
||||
return ret
|
||||
end
|
||||
|
||||
def get_buffer_modules
|
||||
return get_buffer_entity_list( "modules" )
|
||||
end
|
||||
|
||||
def get_buffer_methods
|
||||
return get_buffer_entity_list( "def" )
|
||||
end
|
||||
|
||||
def get_buffer_classes
|
||||
return get_buffer_entity_list( "class" )
|
||||
end
|
||||
|
||||
def load_rails
|
||||
allow_rails = VIM::evaluate("exists('g:rubycomplete_rails') && g:rubycomplete_rails")
|
||||
return if allow_rails.to_i.zero?
|
||||
|
||||
buf_path = VIM::evaluate('expand("%:p")')
|
||||
file_name = VIM::evaluate('expand("%:t")')
|
||||
vim_dir = VIM::evaluate('getcwd()')
|
||||
file_dir = buf_path.gsub( file_name, '' )
|
||||
file_dir.gsub!( /\\/, "/" )
|
||||
vim_dir.gsub!( /\\/, "/" )
|
||||
vim_dir << "/"
|
||||
dirs = [ vim_dir, file_dir ]
|
||||
sdirs = [ "", "./", "../", "../../", "../../../", "../../../../" ]
|
||||
rails_base = nil
|
||||
|
||||
dirs.each do |dir|
|
||||
sdirs.each do |sub|
|
||||
trail = "%s%s" % [ dir, sub ]
|
||||
tcfg = "%sconfig" % trail
|
||||
|
||||
if File.exists?( tcfg )
|
||||
rails_base = trail
|
||||
break
|
||||
end
|
||||
end
|
||||
break if rails_base
|
||||
end
|
||||
|
||||
return if rails_base == nil
|
||||
$:.push rails_base unless $:.index( rails_base )
|
||||
|
||||
bootfile = rails_base + "config/boot.rb"
|
||||
envfile = rails_base + "config/environment.rb"
|
||||
if File.exists?( bootfile ) && File.exists?( envfile )
|
||||
begin
|
||||
require bootfile
|
||||
require envfile
|
||||
begin
|
||||
require 'console_app'
|
||||
require 'console_with_helpers'
|
||||
rescue Exception
|
||||
dprint "Rails 1.1+ Error %s" % $!
|
||||
# assume 1.0
|
||||
end
|
||||
#eval( "Rails::Initializer.run" ) #not necessary?
|
||||
VIM::command('let s:rubycomplete_rails_loaded = 1')
|
||||
dprint "rails loaded"
|
||||
rescue Exception
|
||||
dprint "Rails Error %s" % $!
|
||||
VIM::evaluate( "s:ErrMsg('Error loading rails environment')" )
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def get_rails_helpers
|
||||
allow_rails = VIM::evaluate("exists('g:rubycomplete_rails') && g:rubycomplete_rails")
|
||||
rails_loaded = VIM::evaluate('s:rubycomplete_rails_loaded')
|
||||
return [] if allow_rails.to_i.zero? || rails_loaded.to_i.zero?
|
||||
|
||||
buf_path = VIM::evaluate('expand("%:p")')
|
||||
buf_path.gsub!( /\\/, "/" )
|
||||
path_elm = buf_path.split( "/" )
|
||||
dprint "buf_path: %s" % buf_path
|
||||
types = [ "app", "db", "lib", "test", "components", "script" ]
|
||||
|
||||
i = nil
|
||||
ret = []
|
||||
type = nil
|
||||
types.each do |t|
|
||||
i = path_elm.index( t )
|
||||
break if i
|
||||
end
|
||||
type = path_elm[i]
|
||||
type.downcase!
|
||||
|
||||
dprint "type: %s" % type
|
||||
case type
|
||||
when "app"
|
||||
i += 1
|
||||
subtype = path_elm[i]
|
||||
subtype.downcase!
|
||||
|
||||
dprint "subtype: %s" % subtype
|
||||
case subtype
|
||||
when "views"
|
||||
ret += ActionView::Base.instance_methods
|
||||
ret += ActionView::Base.methods
|
||||
when "controllers"
|
||||
ret += ActionController::Base.instance_methods
|
||||
ret += ActionController::Base.methods
|
||||
when "models"
|
||||
ret += ActiveRecord::Base.instance_methods
|
||||
ret += ActiveRecord::Base.methods
|
||||
end
|
||||
|
||||
when "db"
|
||||
ret += ActiveRecord::ConnectionAdapters::SchemaStatements.instance_methods
|
||||
ret += ActiveRecord::ConnectionAdapters::SchemaStatements.methods
|
||||
end
|
||||
|
||||
return ret
|
||||
end
|
||||
|
||||
def add_rails_columns( cls )
|
||||
allow_rails = VIM::evaluate("exists('g:rubycomplete_rails') && g:rubycomplete_rails")
|
||||
rails_loaded = VIM::evaluate('s:rubycomplete_rails_loaded')
|
||||
return [] if allow_rails.to_i.zero? || rails_loaded.to_i.zero?
|
||||
|
||||
begin
|
||||
eval( "#{cls}.establish_connection" )
|
||||
return [] unless eval( "#{cls}.ancestors.include?(ActiveRecord::Base).to_s" )
|
||||
col = eval( "#{cls}.column_names" )
|
||||
return col if col
|
||||
rescue
|
||||
dprint "add_rails_columns err: (cls: %s) %s" % [ cls, $! ]
|
||||
return []
|
||||
end
|
||||
return []
|
||||
end
|
||||
|
||||
def clean_sel(sel, msg)
|
||||
ret = sel.reject{|x|x.nil?}.uniq
|
||||
ret = ret.grep(/^#{Regexp.quote(msg)}/) if msg != nil
|
||||
ret
|
||||
end
|
||||
|
||||
def get_rails_view_methods
|
||||
allow_rails = VIM::evaluate("exists('g:rubycomplete_rails') && g:rubycomplete_rails")
|
||||
rails_loaded = VIM::evaluate('s:rubycomplete_rails_loaded')
|
||||
return [] if allow_rails.to_i.zero? || rails_loaded.to_i.zero?
|
||||
|
||||
buf_path = VIM::evaluate('expand("%:p")')
|
||||
buf_path.gsub!( /\\/, "/" )
|
||||
pelm = buf_path.split( "/" )
|
||||
idx = pelm.index( "views" )
|
||||
|
||||
return [] unless idx
|
||||
idx += 1
|
||||
|
||||
clspl = pelm[idx].camelize.pluralize
|
||||
cls = clspl.singularize
|
||||
|
||||
ret = []
|
||||
begin
|
||||
ret += eval( "#{cls}.instance_methods" )
|
||||
ret += eval( "#{clspl}Helper.instance_methods" )
|
||||
rescue Exception
|
||||
dprint "Error: Unable to load rails view helpers for %s: %s" % [ cls, $! ]
|
||||
end
|
||||
|
||||
return ret
|
||||
end
|
||||
# }}} buffer analysis magic
|
||||
|
||||
# {{{ main completion code
|
||||
def self.preload_rails
|
||||
a = VimRubyCompletion.new
|
||||
if VIM::evaluate("has('nvim')") == 0
|
||||
require 'thread'
|
||||
Thread.new(a) do |b|
|
||||
begin
|
||||
b.load_rails
|
||||
rescue
|
||||
end
|
||||
end
|
||||
end
|
||||
a.load_rails
|
||||
rescue
|
||||
end
|
||||
|
||||
def self.get_completions(base)
|
||||
b = VimRubyCompletion.new
|
||||
b.get_completions base
|
||||
end
|
||||
|
||||
def get_completions(base)
|
||||
loading_allowed = VIM::evaluate("exists('g:rubycomplete_buffer_loading') && g:rubycomplete_buffer_loading")
|
||||
if loading_allowed.to_i == 1
|
||||
load_requires
|
||||
load_rails
|
||||
end
|
||||
|
||||
want_gems = VIM::evaluate("get(g:, 'rubycomplete_load_gemfile')")
|
||||
load_gems unless want_gems.to_i.zero?
|
||||
|
||||
input = VIM::Buffer.current.line
|
||||
cpos = VIM::Window.current.cursor[1] - 1
|
||||
input = input[0..cpos]
|
||||
input += base
|
||||
input.sub!(/.*[ \t\n\"\\'`><=;|&{(]/, '') # Readline.basic_word_break_characters
|
||||
input.sub!(/self\./, '')
|
||||
input.sub!(/.*((\.\.[\[(]?)|([\[(]))/, '')
|
||||
|
||||
dprint 'input %s' % input
|
||||
message = nil
|
||||
receiver = nil
|
||||
methods = []
|
||||
variables = []
|
||||
classes = []
|
||||
constants = []
|
||||
|
||||
case input
|
||||
when /^(\/[^\/]*\/)\.([^.]*)$/ # Regexp
|
||||
receiver = $1
|
||||
message = Regexp.quote($2)
|
||||
methods = Regexp.instance_methods(true)
|
||||
|
||||
when /^([^\]]*\])\.([^.]*)$/ # Array
|
||||
receiver = $1
|
||||
message = Regexp.quote($2)
|
||||
methods = Array.instance_methods(true)
|
||||
|
||||
when /^([^\}]*\})\.([^.]*)$/ # Proc or Hash
|
||||
receiver = $1
|
||||
message = Regexp.quote($2)
|
||||
methods = Proc.instance_methods(true) | Hash.instance_methods(true)
|
||||
|
||||
when /^(:[^:.]*)$/ # Symbol
|
||||
dprint "symbol"
|
||||
if Symbol.respond_to?(:all_symbols)
|
||||
receiver = $1
|
||||
message = $1.sub( /:/, '' )
|
||||
methods = Symbol.all_symbols.collect{|s| s.id2name}
|
||||
methods.delete_if { |c| c.match( /'/ ) }
|
||||
end
|
||||
|
||||
when /^::([A-Z][^:\.\(]*)?$/ # Absolute Constant or class methods
|
||||
dprint "const or cls"
|
||||
receiver = $1
|
||||
methods = Object.constants.collect{ |c| c.to_s }.grep(/^#{receiver}/)
|
||||
|
||||
when /^(((::)?[A-Z][^:.\(]*)+?)::?([^:.]*)$/ # Constant or class methods
|
||||
receiver = $1
|
||||
message = Regexp.quote($4)
|
||||
dprint "const or cls 2 [recv: \'%s\', msg: \'%s\']" % [ receiver, message ]
|
||||
load_buffer_class( receiver )
|
||||
load_buffer_module( receiver )
|
||||
begin
|
||||
constants = eval("#{receiver}.constants").collect{ |c| c.to_s }.grep(/^#{message}/)
|
||||
methods = eval("#{receiver}.methods").collect{ |m| m.to_s }.grep(/^#{message}/)
|
||||
rescue Exception
|
||||
dprint "exception: %s" % $!
|
||||
constants = []
|
||||
methods = []
|
||||
end
|
||||
|
||||
when /^(:[^:.]+)\.([^.]*)$/ # Symbol
|
||||
dprint "symbol"
|
||||
receiver = $1
|
||||
message = Regexp.quote($2)
|
||||
methods = Symbol.instance_methods(true)
|
||||
|
||||
when /^([0-9_]+(\.[0-9_]+)?(e[0-9]+)?)\.([^.]*)$/ # Numeric
|
||||
dprint "numeric"
|
||||
receiver = $1
|
||||
message = Regexp.quote($4)
|
||||
begin
|
||||
methods = eval(receiver).methods
|
||||
rescue Exception
|
||||
methods = []
|
||||
end
|
||||
|
||||
when /^(\$[^.]*)$/ #global
|
||||
dprint "global"
|
||||
methods = global_variables.grep(Regexp.new(Regexp.quote($1)))
|
||||
|
||||
when /^((\.?[^.]+)+?)\.([^.]*)$/ # variable
|
||||
dprint "variable"
|
||||
receiver = $1
|
||||
message = Regexp.quote($3)
|
||||
load_buffer_class( receiver )
|
||||
|
||||
cv = eval("self.class.constants")
|
||||
vartype = get_var_type( receiver )
|
||||
dprint "vartype: %s" % vartype
|
||||
|
||||
invalid_vartype = ['', "gets"]
|
||||
if !invalid_vartype.include?(vartype)
|
||||
load_buffer_class( vartype )
|
||||
|
||||
begin
|
||||
methods = eval("#{vartype}.instance_methods")
|
||||
variables = eval("#{vartype}.instance_variables")
|
||||
rescue Exception
|
||||
dprint "load_buffer_class err: %s" % $!
|
||||
end
|
||||
elsif (cv).include?(receiver)
|
||||
# foo.func and foo is local var.
|
||||
methods = eval("#{receiver}.methods")
|
||||
vartype = receiver
|
||||
elsif /^[A-Z]/ =~ receiver and /\./ !~ receiver
|
||||
vartype = receiver
|
||||
# Foo::Bar.func
|
||||
begin
|
||||
methods = eval("#{receiver}.methods")
|
||||
rescue Exception
|
||||
end
|
||||
else
|
||||
# func1.func2
|
||||
ObjectSpace.each_object(Module){|m|
|
||||
next if m.name != "IRB::Context" and
|
||||
/^(IRB|SLex|RubyLex|RubyToken)/ =~ m.name
|
||||
methods.concat m.instance_methods(false)
|
||||
}
|
||||
end
|
||||
variables += add_rails_columns( "#{vartype}" ) if vartype && !invalid_vartype.include?(vartype)
|
||||
|
||||
when /^\(?\s*[A-Za-z0-9:^@.%\/+*\(\)]+\.\.\.?[A-Za-z0-9:^@.%\/+*\(\)]+\s*\)?\.([^.]*)/
|
||||
message = $1
|
||||
methods = Range.instance_methods(true)
|
||||
|
||||
when /^\.([^.]*)$/ # unknown(maybe String)
|
||||
message = Regexp.quote($1)
|
||||
methods = String.instance_methods(true)
|
||||
|
||||
else
|
||||
dprint "default/other"
|
||||
inclass = eval( VIM::evaluate("s:IsInClassDef()") )
|
||||
|
||||
if inclass != nil
|
||||
dprint "inclass"
|
||||
classdef = "%s\n" % VIM::Buffer.current[ inclass.min ]
|
||||
found = /^\s*class\s*([A-Za-z0-9_-]*)(\s*<\s*([A-Za-z0-9_:-]*))?\s*\n$/.match( classdef )
|
||||
|
||||
if found != nil
|
||||
receiver = $1
|
||||
message = input
|
||||
load_buffer_class( receiver )
|
||||
begin
|
||||
methods = eval( "#{receiver}.instance_methods" )
|
||||
variables += add_rails_columns( "#{receiver}" )
|
||||
rescue Exception
|
||||
found = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if inclass == nil || found == nil
|
||||
dprint "inclass == nil"
|
||||
methods = get_buffer_methods
|
||||
methods += get_rails_view_methods
|
||||
|
||||
cls_const = Class.constants
|
||||
constants = cls_const.select { |c| /^[A-Z_-]+$/.match( c ) }
|
||||
classes = eval("self.class.constants") - constants
|
||||
classes += get_buffer_classes
|
||||
classes += get_buffer_modules
|
||||
|
||||
include_objectspace = VIM::evaluate("exists('g:rubycomplete_include_objectspace') && g:rubycomplete_include_objectspace")
|
||||
ObjectSpace.each_object(Class) { |cls| classes << cls.to_s } if include_objectspace == "1"
|
||||
message = receiver = input
|
||||
end
|
||||
|
||||
methods += get_rails_helpers
|
||||
methods += Kernel.public_methods
|
||||
end
|
||||
|
||||
include_object = VIM::evaluate("exists('g:rubycomplete_include_object') && g:rubycomplete_include_object")
|
||||
methods = clean_sel( methods, message )
|
||||
methods = (methods-Object.instance_methods) if include_object == "0"
|
||||
rbcmeth = (VimRubyCompletion.instance_methods-Object.instance_methods) # lets remove those rubycomplete methods
|
||||
methods = (methods-rbcmeth)
|
||||
|
||||
variables = clean_sel( variables, message )
|
||||
classes = clean_sel( classes, message ) - ["VimRubyCompletion"]
|
||||
constants = clean_sel( constants, message )
|
||||
|
||||
valid = []
|
||||
valid += methods.collect { |m| { :name => m.to_s, :type => 'm' } }
|
||||
valid += variables.collect { |v| { :name => v.to_s, :type => 'v' } }
|
||||
valid += classes.collect { |c| { :name => c.to_s, :type => 't' } }
|
||||
valid += constants.collect { |d| { :name => d.to_s, :type => 'd' } }
|
||||
valid.sort! { |x,y| x[:name] <=> y[:name] }
|
||||
|
||||
outp = ""
|
||||
|
||||
rg = 0..valid.length
|
||||
rg.step(150) do |x|
|
||||
stpos = 0+x
|
||||
enpos = 150+x
|
||||
valid[stpos..enpos].each { |c| outp += "{'word':'%s','item':'%s','kind':'%s'}," % [ c[:name], c[:name], c[:type] ].map{|x|escape_vim_singlequote_string(x)} }
|
||||
outp.sub!(/,$/, '')
|
||||
|
||||
VIM::command("call extend(g:rubycomplete_completions, [%s])" % outp)
|
||||
outp = ""
|
||||
end
|
||||
end
|
||||
# }}} main completion code
|
||||
|
||||
end # VimRubyCompletion
|
||||
# }}} ruby completion
|
||||
RUBYEOF
|
||||
endfunction
|
||||
|
||||
let s:rubycomplete_rails_loaded = 0
|
||||
|
||||
call s:DefRuby()
|
||||
"}}} ruby-side code
|
||||
|
||||
" vim:tw=78:sw=4:ts=8:et:fdm=marker:ft=vim:norl:
|
@ -1,39 +0,0 @@
|
||||
" Vim compiler file
|
||||
" Language: eRuby
|
||||
" Maintainer: Doug Kearns <dougkearns@gmail.com>
|
||||
" URL: https://github.com/vim-ruby/vim-ruby
|
||||
" Release Coordinator: Doug Kearns <dougkearns@gmail.com>
|
||||
|
||||
if exists("current_compiler")
|
||||
finish
|
||||
endif
|
||||
let current_compiler = "eruby"
|
||||
|
||||
if exists(":CompilerSet") != 2 " older Vim always used :setlocal
|
||||
command -nargs=* CompilerSet setlocal <args>
|
||||
endif
|
||||
|
||||
let s:cpo_save = &cpo
|
||||
set cpo-=C
|
||||
|
||||
if exists("eruby_compiler") && eruby_compiler == "eruby"
|
||||
CompilerSet makeprg=eruby
|
||||
else
|
||||
CompilerSet makeprg=erb
|
||||
endif
|
||||
|
||||
CompilerSet errorformat=
|
||||
\eruby:\ %f:%l:%m,
|
||||
\%+E%f:%l:\ parse\ error,
|
||||
\%W%f:%l:\ warning:\ %m,
|
||||
\%E%f:%l:in\ %*[^:]:\ %m,
|
||||
\%E%f:%l:\ %m,
|
||||
\%-C%\t%\\d%#:%#\ %#from\ %f:%l:in\ %.%#,
|
||||
\%-Z%\t%\\d%#:%#\ %#from\ %f:%l,
|
||||
\%-Z%p^,
|
||||
\%-G%.%#
|
||||
|
||||
let &cpo = s:cpo_save
|
||||
unlet s:cpo_save
|
||||
|
||||
" vim: nowrap sw=2 sts=2 ts=8:
|
@ -1,39 +0,0 @@
|
||||
" Vim compiler file
|
||||
" Language: Rake
|
||||
" Maintainer: Tim Pope <vimNOSPAM@tpope.org>
|
||||
" URL: https://github.com/vim-ruby/vim-ruby
|
||||
" Release Coordinator: Doug Kearns <dougkearns@gmail.com>
|
||||
|
||||
if exists("current_compiler")
|
||||
finish
|
||||
endif
|
||||
let current_compiler = "rake"
|
||||
|
||||
if exists(":CompilerSet") != 2 " older Vim always used :setlocal
|
||||
command -nargs=* CompilerSet setlocal <args>
|
||||
endif
|
||||
|
||||
let s:cpo_save = &cpo
|
||||
set cpo-=C
|
||||
|
||||
CompilerSet makeprg=rake
|
||||
|
||||
CompilerSet errorformat=
|
||||
\%D(in\ %f),
|
||||
\%\\s%#%\\d%#:%#\ %#from\ %f:%l:%m,
|
||||
\%\\s%#%\\d%#:%#\ %#from\ %f:%l:,
|
||||
\%\\s%##\ %f:%l:%m%\\&%.%#%\\D:%\\d%\\+:%.%#,
|
||||
\%\\s%##\ %f:%l%\\&%.%#%\\D:%\\d%\\+,
|
||||
\%\\s%#[%f:%l:\ %#%m%\\&%.%#%\\D:%\\d%\\+:%.%#,
|
||||
\%\\s%#%f:%l:\ %#%m%\\&%.%#%\\D:%\\d%\\+:%.%#,
|
||||
\%\\s%#%f:%l:,
|
||||
\%m\ [%f:%l]:,
|
||||
\%+Erake\ aborted!,
|
||||
\%+EDon't\ know\ how\ to\ build\ task\ %.%#,
|
||||
\%+Einvalid\ option:%.%#,
|
||||
\%+Irake\ %\\S%\\+%\\s%\\+#\ %.%#
|
||||
|
||||
let &cpo = s:cpo_save
|
||||
unlet s:cpo_save
|
||||
|
||||
" vim: nowrap sw=2 sts=2 ts=8:
|
@ -1,35 +0,0 @@
|
||||
" Vim compiler file
|
||||
" Language: RSpec
|
||||
" Maintainer: Tim Pope <vimNOSPAM@tpope.org>
|
||||
" URL: https://github.com/vim-ruby/vim-ruby
|
||||
" Release Coordinator: Doug Kearns <dougkearns@gmail.com>
|
||||
|
||||
if exists("current_compiler")
|
||||
finish
|
||||
endif
|
||||
let current_compiler = "rspec"
|
||||
|
||||
if exists(":CompilerSet") != 2 " older Vim always used :setlocal
|
||||
command -nargs=* CompilerSet setlocal <args>
|
||||
endif
|
||||
|
||||
let s:cpo_save = &cpo
|
||||
set cpo-=C
|
||||
|
||||
CompilerSet makeprg=rspec
|
||||
|
||||
CompilerSet errorformat=
|
||||
\%f:%l:\ %tarning:\ %m,
|
||||
\%E%.%#:in\ `load':\ %f:%l:%m,
|
||||
\%E%f:%l:in\ `%*[^']':\ %m,
|
||||
\%-Z\ \ \ \ \ %\\+\#\ %f:%l:%.%#,
|
||||
\%E\ \ \ \ \ Failure/Error:\ %m,
|
||||
\%E\ \ \ \ \ Failure/Error:,
|
||||
\%C\ \ \ \ \ %m,
|
||||
\%C%\\s%#,
|
||||
\%-G%.%#
|
||||
|
||||
let &cpo = s:cpo_save
|
||||
unlet s:cpo_save
|
||||
|
||||
" vim: nowrap sw=2 sts=2 ts=8:
|
@ -1,44 +0,0 @@
|
||||
" Vim compiler file
|
||||
" Language: Ruby
|
||||
" Function: Syntax check and/or error reporting
|
||||
" Maintainer: Tim Pope <vimNOSPAM@tpope.org>
|
||||
" URL: https://github.com/vim-ruby/vim-ruby
|
||||
" Release Coordinator: Doug Kearns <dougkearns@gmail.com>
|
||||
|
||||
if exists("current_compiler")
|
||||
finish
|
||||
endif
|
||||
let current_compiler = "ruby"
|
||||
|
||||
if exists(":CompilerSet") != 2 " older Vim always used :setlocal
|
||||
command -nargs=* CompilerSet setlocal <args>
|
||||
endif
|
||||
|
||||
let s:cpo_save = &cpo
|
||||
set cpo-=C
|
||||
|
||||
" default settings runs script normally
|
||||
" add '-c' switch to run syntax check only:
|
||||
"
|
||||
" CompilerSet makeprg=ruby\ -c
|
||||
"
|
||||
" or add '-c' at :make command line:
|
||||
"
|
||||
" :make -c %<CR>
|
||||
"
|
||||
CompilerSet makeprg=ruby
|
||||
|
||||
CompilerSet errorformat=
|
||||
\%+E%f:%l:\ parse\ error,
|
||||
\%W%f:%l:\ warning:\ %m,
|
||||
\%E%f:%l:in\ %*[^:]:\ %m,
|
||||
\%E%f:%l:\ %m,
|
||||
\%-C%\t%\\d%#:%#\ %#from\ %f:%l:in\ %.%#,
|
||||
\%-Z%\t%\\d%#:%#\ %#from\ %f:%l,
|
||||
\%-Z%p^,
|
||||
\%-G%.%#
|
||||
|
||||
let &cpo = s:cpo_save
|
||||
unlet s:cpo_save
|
||||
|
||||
" vim: nowrap sw=2 sts=2 ts=8:
|
@ -1,35 +0,0 @@
|
||||
" Vim compiler file
|
||||
" Language: Test::Unit - Ruby Unit Testing Framework
|
||||
" Maintainer: Doug Kearns <dougkearns@gmail.com>
|
||||
" URL: https://github.com/vim-ruby/vim-ruby
|
||||
" Release Coordinator: Doug Kearns <dougkearns@gmail.com>
|
||||
|
||||
if exists("current_compiler")
|
||||
finish
|
||||
endif
|
||||
let current_compiler = "rubyunit"
|
||||
|
||||
if exists(":CompilerSet") != 2 " older Vim always used :setlocal
|
||||
command -nargs=* CompilerSet setlocal <args>
|
||||
endif
|
||||
|
||||
let s:cpo_save = &cpo
|
||||
set cpo-=C
|
||||
|
||||
CompilerSet makeprg=testrb
|
||||
" CompilerSet makeprg=ruby\ -Itest
|
||||
" CompilerSet makeprg=m
|
||||
|
||||
CompilerSet errorformat=\%W\ %\\+%\\d%\\+)\ Failure:,
|
||||
\%C%m\ [%f:%l]:,
|
||||
\%E\ %\\+%\\d%\\+)\ Error:,
|
||||
\%C%m:,
|
||||
\%C\ \ \ \ %f:%l:%.%#,
|
||||
\%C%m,
|
||||
\%Z\ %#,
|
||||
\%-G%.%#
|
||||
|
||||
let &cpo = s:cpo_save
|
||||
unlet s:cpo_save
|
||||
|
||||
" vim: nowrap sw=2 sts=2 ts=8:
|
@ -1,148 +0,0 @@
|
||||
RUBY *ft-ruby-indent*
|
||||
*vim-ruby-indent*
|
||||
|
||||
Ruby: Access modifier indentation |ruby-access-modifier-indentation|
|
||||
Ruby: Block style indentation |ruby-block-style-indentation|
|
||||
Ruby: Assignment style indentation |ruby-assignment-style-indentation|
|
||||
Ruby: Hanging element indentation |ruby-hanging-element-indentation|
|
||||
|
||||
*ruby-access-modifier-indentation*
|
||||
*g:ruby_indent_access_modifier_style*
|
||||
Ruby: Access modifier indentation ~
|
||||
|
||||
Different access modifier indentation styles can be used by setting: >
|
||||
|
||||
:let g:ruby_indent_access_modifier_style = 'normal'
|
||||
:let g:ruby_indent_access_modifier_style = 'indent'
|
||||
:let g:ruby_indent_access_modifier_style = 'outdent'
|
||||
<
|
||||
By default, the "normal" access modifier style is used.
|
||||
|
||||
Access modifier style "normal":
|
||||
>
|
||||
class Indent
|
||||
private :method
|
||||
protected :method
|
||||
private
|
||||
def method; end
|
||||
protected
|
||||
def method; end
|
||||
public
|
||||
def method; end
|
||||
end
|
||||
<
|
||||
Access modifier style "indent":
|
||||
>
|
||||
class Indent
|
||||
private :method
|
||||
protected :method
|
||||
private
|
||||
def method; end
|
||||
protected
|
||||
def method; end
|
||||
public
|
||||
def method; end
|
||||
end
|
||||
<
|
||||
Access modifier style "outdent":
|
||||
>
|
||||
class Indent
|
||||
private :method
|
||||
protected :method
|
||||
private
|
||||
def method; end
|
||||
protected
|
||||
def method; end
|
||||
public
|
||||
def method; end
|
||||
end
|
||||
<
|
||||
*ruby-block-style-indentation*
|
||||
*g:ruby_indent_block_style*
|
||||
Ruby: Block style indentation ~
|
||||
|
||||
Different block indentation styles can be used by setting: >
|
||||
|
||||
:let g:ruby_indent_block_style = 'expression'
|
||||
:let g:ruby_indent_block_style = 'do'
|
||||
<
|
||||
By default, the "do" block indent style is used.
|
||||
|
||||
Block indent style "expression":
|
||||
>
|
||||
first
|
||||
.second do |x|
|
||||
something
|
||||
end
|
||||
<
|
||||
Block indent style "do":
|
||||
>
|
||||
first
|
||||
.second do |x|
|
||||
something
|
||||
end
|
||||
<
|
||||
|
||||
*ruby-assignment-style-indentation*
|
||||
*g:ruby_indent_assignment_style*
|
||||
Ruby: Assignment style indentation ~
|
||||
|
||||
Different styles of indenting assignment for multiline expressions:
|
||||
>
|
||||
:let g:ruby_indent_assignment_style = 'hanging'
|
||||
:let g:ruby_indent_assignment_style = 'variable'
|
||||
<
|
||||
By default, the "hanging" style is used.
|
||||
|
||||
Assignment indent style "hanging":
|
||||
>
|
||||
x = if condition
|
||||
something
|
||||
end
|
||||
<
|
||||
Assignment indent style "variable":
|
||||
>
|
||||
x = if condition
|
||||
something
|
||||
end
|
||||
<
|
||||
|
||||
*ruby-hanging-element-indentation*
|
||||
*g:ruby_indent_hanging_elements*
|
||||
Ruby: Hanging element indentation ~
|
||||
|
||||
Elements of multiline collections -- such as arrays, hashes, and method
|
||||
argument lists -- can have hanging indentation enabled or disabled with the
|
||||
following setting.
|
||||
>
|
||||
:let g:ruby_indent_hanging_elements = 1
|
||||
:let g:ruby_indent_hanging_elements = 0
|
||||
<
|
||||
By default, this setting is "1" (true) meaning that hanging indentation is
|
||||
enabled in some cases.
|
||||
|
||||
Here is an example method call when the setting is true (non-zero):
|
||||
>
|
||||
render('product/show',
|
||||
product: product,
|
||||
on_sale: true,
|
||||
)
|
||||
<
|
||||
And the same method call when the setting is false (zero):
|
||||
>
|
||||
render('product/show',
|
||||
product: product,
|
||||
on_sale: true,
|
||||
)
|
||||
<
|
||||
Note that, even if the setting is turned on, you can still get non-hanging
|
||||
indentation by putting each argument on a separate line:
|
||||
>
|
||||
render(
|
||||
'product/show',
|
||||
product: product,
|
||||
on_sale: true,
|
||||
)
|
||||
<
|
||||
|
||||
vim:tw=78:sw=4:ts=8:ft=help:norl:
|
@ -1,52 +0,0 @@
|
||||
RUBY *ft-ruby-omni*
|
||||
*vim-ruby-omni*
|
||||
|
||||
Completion of Ruby code requires that Vim be built with |+ruby|.
|
||||
|
||||
Ruby completion will parse your buffer on demand in order to provide a list of
|
||||
completions. These completions will be drawn from modules loaded by "require"
|
||||
and modules defined in the current buffer.
|
||||
|
||||
The completions provided by CTRL-X CTRL-O are sensitive to the context:
|
||||
|
||||
CONTEXT COMPLETIONS PROVIDED ~
|
||||
|
||||
1. Not inside a class definition Classes, constants and globals
|
||||
|
||||
2. Inside a class definition Methods or constants defined in the class
|
||||
|
||||
3. After '.', '::' or ':' Methods applicable to the object being
|
||||
dereferenced
|
||||
|
||||
4. After ':' or ':foo' Symbol name (beginning with "foo")
|
||||
|
||||
Notes:
|
||||
- Vim will load/evaluate code in order to provide completions. This may
|
||||
cause some code execution, which may be a concern. This is no longer
|
||||
enabled by default, to enable this feature add >
|
||||
let g:rubycomplete_buffer_loading = 1
|
||||
< - In context 1 above, Vim can parse the entire buffer to add a list of
|
||||
classes to the completion results. This feature is turned off by default,
|
||||
to enable it add >
|
||||
let g:rubycomplete_classes_in_global = 1
|
||||
< to your vimrc
|
||||
- In context 2 above, anonymous classes are not supported.
|
||||
- In context 3 above, Vim will attempt to determine the methods supported by
|
||||
the object.
|
||||
- Vim can detect and load the Rails environment for files within a rails
|
||||
project. The feature is disabled by default, to enable it add >
|
||||
let g:rubycomplete_rails = 1
|
||||
< to your vimrc
|
||||
- Vim can parse a Gemfile, in case gems are being implicitly required. To
|
||||
activate the feature: >
|
||||
let g:rubycomplete_load_gemfile = 1
|
||||
< To specify an alternative path, use: >
|
||||
let g:rubycomplete_gemfile_path = 'Gemfile.aux'
|
||||
< To use Bundler.require instead of parsing the Gemfile, set: >
|
||||
let g:rubycomplete_use_bundler = 1
|
||||
< To use custom paths that should be added to $LOAD_PATH to correctly
|
||||
resolve requires, set: >
|
||||
let g:rubycomplete_load_paths = ["/path/to/code", "./lib/example"]
|
||||
|
||||
|
||||
vim:tw=78:sw=4:ts=8:ft=help:norl:
|
@ -1,81 +0,0 @@
|
||||
RUBY *ft-ruby-plugin*
|
||||
*vim-ruby-plugin*
|
||||
|
||||
|
||||
Ruby: Recommended settings |ruby-recommended|
|
||||
Ruby: Motion commands |ruby-motion|
|
||||
Ruby: Text objects |ruby-text-objects|
|
||||
|
||||
*ruby-recommended*
|
||||
*g:ruby_recommended_style*
|
||||
Ruby: Recommended settings ~
|
||||
|
||||
The `g:ruby_recommended_style` variable activates indentation settings
|
||||
according to the most common ruby convention: two spaces for indentation. It's
|
||||
turned on by default to ensure an unsurprising default experience for most
|
||||
ruby developers.
|
||||
|
||||
If you'd like to enforce your own style, it's possible to apply your own
|
||||
preferences in your own configuration in `after/ftplugin/ruby.vim`. You can
|
||||
also disable the setting by setting the variable to 0:
|
||||
>
|
||||
let g:ruby_recommended_style = 0
|
||||
<
|
||||
|
||||
*ruby-motion*
|
||||
Ruby: Motion commands ~
|
||||
|
||||
Vim provides motions such as |[m| and |]m| for jumping to the start or end of
|
||||
a method definition. Out of the box, these work for curly-bracket languages,
|
||||
but not for Ruby. The vim-ruby plugin enhances these motions, by making them
|
||||
also work on Ruby files.
|
||||
|
||||
*ruby-]m*
|
||||
]m Go to start of next method definition.
|
||||
|
||||
*ruby-]M*
|
||||
]M Go to end of next method definition.
|
||||
|
||||
*ruby-[m*
|
||||
[m Go to start of previous method definition.
|
||||
|
||||
*ruby-[M*
|
||||
[M Go to end of previous method definition.
|
||||
|
||||
*ruby-]]*
|
||||
]] Go to start of next module or class definition.
|
||||
|
||||
*ruby-][*
|
||||
][ Go to end of next module or class definition.
|
||||
|
||||
*ruby-[[*
|
||||
[[ Go to start of previous module or class definition.
|
||||
|
||||
*ruby-[]*
|
||||
[] Go to end of previous module or class definition.
|
||||
|
||||
*ruby-text-objects*
|
||||
Ruby: Text objects ~
|
||||
|
||||
Vim's |text-objects| can be used to select or operate upon regions of text
|
||||
that are defined by structure. The vim-ruby plugin adds text objects for
|
||||
operating on methods and classes.
|
||||
|
||||
*ruby-v_am* *ruby-am*
|
||||
am "a method", select from "def" until matching "end"
|
||||
keyword.
|
||||
|
||||
*ruby-v_im* *ruby-im*
|
||||
im "inner method", select contents of "def"/"end" block,
|
||||
excluding the "def" and "end" themselves.
|
||||
|
||||
*ruby-v_aM* *ruby-aM*
|
||||
aM "a class", select from "class" until matching "end"
|
||||
keyword.
|
||||
|
||||
*ruby-v_iM* *ruby-iM*
|
||||
iM "inner class", select contents of "class"/"end"
|
||||
block, excluding the "class" and "end" themselves.
|
||||
|
||||
|
||||
vim:tw=78:sw=4:ts=8:ft=help:norl:
|
@ -1,119 +0,0 @@
|
||||
RUBY *ruby.vim* *ft-ruby-syntax*
|
||||
*vim-ruby-syntax*
|
||||
|
||||
Ruby: Operator highlighting |ruby_operators|
|
||||
Ruby: Whitespace errors |ruby_space_errors|
|
||||
Ruby: Syntax errors |ruby_syntax_errors|
|
||||
Ruby: Folding |ruby_fold| |ruby_foldable_groups|
|
||||
Ruby: Reducing expensive operations |ruby_no_expensive| |ruby_minlines|
|
||||
Ruby: Spellchecking strings |ruby_spellcheck_strings|
|
||||
|
||||
*ruby_operators*
|
||||
Ruby: Operator highlighting ~
|
||||
|
||||
Operators, and pseudo operators, can be highlighted by defining: >
|
||||
|
||||
:let ruby_operators = 1
|
||||
:let ruby_pseudo_operators = 1
|
||||
<
|
||||
The supported pseudo operators are ., &., ::, *, **, &, <, << and ->.
|
||||
|
||||
*ruby_space_errors*
|
||||
Ruby: Whitespace errors ~
|
||||
|
||||
Whitespace errors can be highlighted by defining "ruby_space_errors": >
|
||||
|
||||
:let ruby_space_errors = 1
|
||||
<
|
||||
This will highlight trailing whitespace and tabs preceded by a space character
|
||||
as errors. This can be refined by defining "ruby_no_trail_space_error" and
|
||||
"ruby_no_tab_space_error" which will ignore trailing whitespace and tabs after
|
||||
spaces respectively.
|
||||
|
||||
*ruby_syntax_errors*
|
||||
Ruby: Syntax errors ~
|
||||
|
||||
Redundant line continuations and predefined global variable look-alikes (such
|
||||
as $# and $-z) can be highlighted as errors by defining:
|
||||
>
|
||||
:let ruby_line_continuation_error = 1
|
||||
:let ruby_global_variable_error = 1
|
||||
<
|
||||
*ruby_fold*
|
||||
Ruby: Folding ~
|
||||
|
||||
Folding can be enabled by defining "ruby_fold": >
|
||||
|
||||
:let ruby_fold = 1
|
||||
<
|
||||
This will set the value of 'foldmethod' to "syntax" locally to the current
|
||||
buffer or window, which will enable syntax-based folding when editing Ruby
|
||||
filetypes.
|
||||
|
||||
*ruby_foldable_groups*
|
||||
Default folding is rather detailed, i.e., small syntax units like "if", "do",
|
||||
"%w[]" may create corresponding fold levels.
|
||||
|
||||
You can set "ruby_foldable_groups" to restrict which groups are foldable: >
|
||||
|
||||
:let ruby_foldable_groups = 'if case %'
|
||||
<
|
||||
The value is a space-separated list of keywords:
|
||||
|
||||
keyword meaning ~
|
||||
-------- ------------------------------------- ~
|
||||
ALL Most block syntax (default)
|
||||
NONE Nothing
|
||||
if "if" or "unless" block
|
||||
def "def" block
|
||||
class "class" block
|
||||
module "module" block
|
||||
do "do" block
|
||||
begin "begin" block
|
||||
case "case" block
|
||||
for "for", "while", "until" loops
|
||||
{ Curly bracket block or hash literal
|
||||
[ Array literal
|
||||
% Literal with "%" notation, e.g.: %w(STRING), %!STRING!
|
||||
/ Regexp
|
||||
string String and shell command output (surrounded by ', ", `)
|
||||
: Symbol
|
||||
# Multiline comment
|
||||
<< Here documents
|
||||
__END__ Source code after "__END__" directive
|
||||
|
||||
NONE and ALL have priority, in that order, over all other folding groups.
|
||||
|
||||
*ruby_no_expensive*
|
||||
Ruby: Reducing expensive operations ~
|
||||
|
||||
By default, the "end" keyword is colorized according to the opening statement
|
||||
of the block it closes. While useful, this feature can be expensive; if you
|
||||
experience slow redrawing (or you are on a terminal with poor color support)
|
||||
you may want to turn it off by defining the "ruby_no_expensive" variable: >
|
||||
|
||||
:let ruby_no_expensive = 1
|
||||
<
|
||||
In this case the same color will be used for all control keywords.
|
||||
|
||||
*ruby_minlines*
|
||||
|
||||
If you do want this feature enabled, but notice highlighting errors while
|
||||
scrolling backwards, which are fixed when redrawing with CTRL-L, try setting
|
||||
the "ruby_minlines" variable to a value larger than 50: >
|
||||
|
||||
:let ruby_minlines = 100
|
||||
<
|
||||
Ideally, this value should be a number of lines large enough to embrace your
|
||||
largest class or module.
|
||||
|
||||
*ruby_spellcheck_strings*
|
||||
Ruby: Spellchecking strings ~
|
||||
|
||||
Ruby syntax will perform spellchecking of strings if you define
|
||||
"ruby_spellcheck_strings": >
|
||||
|
||||
:let ruby_spellcheck_strings = 1
|
||||
<
|
||||
|
||||
vim:tw=78:sw=4:ts=8:ft=help:norl:
|
@ -1,621 +0,0 @@
|
||||
#!/usr/bin/env ruby
|
||||
|
||||
arg = ARGV.pop
|
||||
|
||||
|
||||
# Usage example:
|
||||
#
|
||||
# ./etc/examples/generators/syntax.rb %Q > etc/examples/syntax/Q.rb
|
||||
#
|
||||
# then read the output file with 'foldlevel' 0
|
||||
|
||||
puts "# Generated by `" <<
|
||||
"./etc/examples/generators/syntax.rb #{arg}" <<
|
||||
" > etc/examples/syntax/#{arg.sub('%', '')}.rb" <<
|
||||
"`\n\n"
|
||||
|
||||
|
||||
|
||||
# %Q {{{
|
||||
# Generalized Double Quoted String and Array of Strings and Shell Command Output
|
||||
if arg == '%Q'
|
||||
# Note: %= is not matched here as the beginning of a double quoted string
|
||||
%Q[~`!@\#$%^&*_-+|:;"',.?/].split(//).each do |s|
|
||||
puts <<-END.gsub(/^\s{4}/, '')
|
||||
%#{s}
|
||||
foo
|
||||
\\#{s}
|
||||
\\\\\\#{s}
|
||||
bar
|
||||
#{s}
|
||||
|
||||
|
||||
END
|
||||
end
|
||||
|
||||
%w(Q W x).each do |leading|
|
||||
%Q[~`!@\#$%^&*_-+=|:;"',.?/].split(//).each do |s|
|
||||
puts <<-END.gsub(/^\s{6}/, '')
|
||||
%#{leading}#{s}
|
||||
foo
|
||||
\\#{s}
|
||||
\\\\\\#{s}
|
||||
bar
|
||||
#{s}
|
||||
|
||||
|
||||
END
|
||||
end
|
||||
|
||||
%w({} <> [] ()).each do |pair|
|
||||
puts <<-END.gsub(/^\s{6}/, '')
|
||||
%#{leading}#{pair[0]}
|
||||
foo
|
||||
\\#{pair[1]}
|
||||
\\\\\\#{pair[1]}
|
||||
bar
|
||||
#{pair[1]}
|
||||
|
||||
|
||||
END
|
||||
end
|
||||
|
||||
puts " %#{leading} foo\\ \\\\\\ bar\nbaz \n\n" unless leading == 'W'
|
||||
end
|
||||
end
|
||||
# }}}
|
||||
|
||||
|
||||
|
||||
# %q {{{
|
||||
# Generalized Single Quoted String, Symbol and Array of Strings
|
||||
if arg == '%q'
|
||||
%w(q w s).each do |leading|
|
||||
%Q[~`!@\#$%^&*_-+=|:;"',.?/].split(//).each do |s|
|
||||
puts <<-END.gsub(/^\s{6}/, '')
|
||||
%#{leading}#{s}
|
||||
foo
|
||||
\\#{s}
|
||||
\\\\\\#{s}
|
||||
bar
|
||||
#{s}
|
||||
|
||||
|
||||
END
|
||||
end
|
||||
|
||||
%w({} <> [] ()).each do |pair|
|
||||
puts <<-END.gsub(/^\s{6}/, '')
|
||||
%#{leading}#{pair[0]}
|
||||
foo
|
||||
\\#{pair[1]}
|
||||
\\\\\\#{pair[1]}
|
||||
bar
|
||||
#{pair[1]}
|
||||
|
||||
|
||||
END
|
||||
end
|
||||
|
||||
puts " %#{leading} foo\\ \\\\\\ bar\nbaz \n\n" unless leading == 'w'
|
||||
end
|
||||
end
|
||||
# }}}
|
||||
|
||||
|
||||
|
||||
# %r {{{
|
||||
# Generalized Regular Expression
|
||||
if arg == '%r'
|
||||
%Q[~`!@\#$%^&*_-+=|:;"',.?/].split(//).each do |s|
|
||||
puts <<-END.gsub(/^\s{4}/, '')
|
||||
%r#{s}
|
||||
foo
|
||||
\\#{s}
|
||||
\\\\\\#{s}
|
||||
bar
|
||||
#{s}
|
||||
|
||||
|
||||
END
|
||||
end
|
||||
|
||||
puts " %r foo\\ \\\\\\ bar\nbaz \n\n"
|
||||
|
||||
%w({} <> [] ()).each do |pair|
|
||||
puts <<-END.gsub(/^\s{4}/, '')
|
||||
%r#{pair[0]}
|
||||
foo
|
||||
\\#{pair[1]}
|
||||
\\\\\\#{pair[1]}
|
||||
bar
|
||||
#{pair[1]}
|
||||
|
||||
|
||||
END
|
||||
end
|
||||
end
|
||||
# }}}
|
||||
|
||||
|
||||
|
||||
# %i / %I {{{
|
||||
# Array of Symbols
|
||||
# Array of interpolated Symbols
|
||||
if %w(%i %I).include?(arg)
|
||||
%w(i I).each do |leading|
|
||||
%Q[~`!@\#$%^&*_-+=|:;"',.?/].split(//).each do |s|
|
||||
puts <<-END.gsub(/^\s{6}/, '')
|
||||
%#{leading}#{s}
|
||||
foo
|
||||
\\#{s}
|
||||
\\\\\\#{s}
|
||||
bar
|
||||
#{s}
|
||||
|
||||
|
||||
END
|
||||
end
|
||||
|
||||
%w({} <> [] ()).each do |pair|
|
||||
puts <<-END.gsub(/^\s{6}/, '')
|
||||
%#{leading}#{pair[0]}
|
||||
foo
|
||||
\\#{pair[1]}
|
||||
\\\\\\#{pair[1]}
|
||||
bar
|
||||
#{pair[1]}
|
||||
|
||||
|
||||
END
|
||||
end
|
||||
end
|
||||
end
|
||||
# }}}
|
||||
|
||||
|
||||
|
||||
# string {{{
|
||||
# Normal String and Shell Command Output
|
||||
if arg == 'string'
|
||||
%w(' " `).each do |quote|
|
||||
puts <<-END.gsub(/^\s{4}/, '')
|
||||
#{quote}
|
||||
foo
|
||||
\\#{quote}
|
||||
\\\\\\#{quote}
|
||||
bar
|
||||
#{quote}
|
||||
|
||||
|
||||
END
|
||||
end
|
||||
end
|
||||
# }}}
|
||||
|
||||
|
||||
|
||||
# regex (Normal Regular Expression) {{{
|
||||
if arg == 'regexp'
|
||||
'iomxneus'.split('').unshift('').each do |option|
|
||||
puts "\n# Begin test for option '#{option}' {{{\n\n"
|
||||
|
||||
puts <<-END.gsub(/^\s{4}/, '')
|
||||
/
|
||||
foo
|
||||
\\\/
|
||||
\\\\\\\/
|
||||
bar
|
||||
/#{option}
|
||||
|
||||
|
||||
END
|
||||
|
||||
%w(and or while until unless if elsif when not then else).each do |s|
|
||||
puts <<-END.gsub(/^\s{6}/, '')
|
||||
#{s}/
|
||||
foo
|
||||
\\\/
|
||||
\\\\\\\/
|
||||
bar
|
||||
/#{option}
|
||||
|
||||
|
||||
END
|
||||
end
|
||||
|
||||
%w(; \ ~ = ! | \( & , { [ < > ? : * + -).each do |s|
|
||||
puts <<-END.gsub(/^\s{6}/, '')
|
||||
#{s}/
|
||||
foo
|
||||
\\\/
|
||||
\\\\\\\/
|
||||
bar
|
||||
/#{option}
|
||||
|
||||
|
||||
END
|
||||
end
|
||||
|
||||
[' ', "\t", '=', 'OK'].each do |s|
|
||||
puts <<-END.gsub(/^\s{6}/, '')
|
||||
_foo /#{s}
|
||||
foo
|
||||
\\\/
|
||||
\\\\\\\/
|
||||
bar
|
||||
/#{option}
|
||||
|
||||
|
||||
END
|
||||
end
|
||||
|
||||
puts "# }}} End test for option '#{option}'\n"
|
||||
end
|
||||
|
||||
puts "\n# Test for ternary operation (8c1c484) {{{\n\n"
|
||||
puts 'yo = 4 ? /quack#{3}/ : /quack/'
|
||||
puts "\n# }}} End test for ternary operation\n"
|
||||
end
|
||||
# }}}
|
||||
|
||||
|
||||
|
||||
# symbol {{{
|
||||
# Symbol region
|
||||
if arg == 'symbol'
|
||||
%w(' ").each do |quote|
|
||||
%Q_]})\"':_.split(//).unshift('').each do |s|
|
||||
puts <<-END.gsub(/^\s{6}/, '')
|
||||
#{s}:#{quote}
|
||||
foo
|
||||
\\#{quote}
|
||||
\\\\\\#{quote}
|
||||
bar
|
||||
#{quote}
|
||||
#{" #{s} # close string to ensure next case clean" if %w(' ").include?(s) && s != quote }
|
||||
|
||||
|
||||
END
|
||||
end
|
||||
end
|
||||
end
|
||||
# }}}
|
||||
|
||||
|
||||
|
||||
# heredoc {{{
|
||||
# Here Documents
|
||||
if arg == 'heredoc'
|
||||
puts "\n# Begin of valid cases {{{\n\n"
|
||||
|
||||
%w(' " `).unshift('').each do |quote|
|
||||
puts <<-END.gsub(/^\s{6}/, '')
|
||||
<<#{quote}_LABEL#{quote}.?!, foo
|
||||
bar baz
|
||||
_LABEL
|
||||
\n
|
||||
|
||||
<<-#{quote}_LABEL#{quote}.?!, foo
|
||||
bar baz
|
||||
_LABEL
|
||||
\n
|
||||
|
||||
<<~#{quote}_LABEL#{quote}.?!, foo
|
||||
bar baz
|
||||
_LABEL
|
||||
|
||||
|
||||
END
|
||||
end
|
||||
|
||||
puts "# }}} End of valid cases'\n\n"
|
||||
|
||||
|
||||
puts "\n# Begin of INVALID cases {{{\n\n"
|
||||
|
||||
# NOTE: for simplification, omit test for different quotes " ' `,
|
||||
# they are all invalid anyway
|
||||
|
||||
%w(class ::).each do |s|
|
||||
puts <<-END.gsub(/^\s{6}/, '')
|
||||
#{s}\n <<LABEL
|
||||
foo
|
||||
LABEL
|
||||
|
||||
|
||||
END
|
||||
end
|
||||
|
||||
%Q_]})\"'._.split(//).each do |s|
|
||||
puts <<-END.gsub(/^\s{4}/, '')
|
||||
#{s} <<LABEL
|
||||
foo
|
||||
LABEL
|
||||
#{" #{s} # close to ensure next case clean" if %w(' ").include?(s)}
|
||||
|
||||
END
|
||||
end
|
||||
|
||||
%w(09 aZ _w).each do |s|
|
||||
puts <<-END.gsub(/^\s{6}/, '')
|
||||
#{s}<<LABEL
|
||||
foo
|
||||
LABEL
|
||||
|
||||
|
||||
END
|
||||
end
|
||||
|
||||
%w(' " `).unshift('').each do |quote|
|
||||
puts <<-END.gsub(/^\s{6}/, '')
|
||||
<<LABEL foo<<#{quote}_bar
|
||||
baz
|
||||
LABEL
|
||||
#{" #{quote} # close to ensure next case clean" if %w(' ").include?(quote)}
|
||||
\n
|
||||
|
||||
<<LABEL foo<<-#{quote}_bar
|
||||
baz
|
||||
LABEL
|
||||
#{" #{quote} # close to ensure next case clean" if %w(' ").include?(quote)}
|
||||
|
||||
|
||||
END
|
||||
end
|
||||
|
||||
puts "# }}} End of INVALID cases'\n\n"
|
||||
end
|
||||
# }}}
|
||||
|
||||
|
||||
|
||||
# blocks {{{
|
||||
# simple blocks (def, class, module, do, begin, case)
|
||||
if arg == 'blocks'
|
||||
puts <<-END.gsub(/^\s{4}/, '')
|
||||
def
|
||||
foo
|
||||
def
|
||||
bar
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
END
|
||||
|
||||
%w(class module do begin case).each do |s|
|
||||
puts <<-END.gsub(/^\s{6}/, '')
|
||||
#{s}
|
||||
foo
|
||||
end
|
||||
|
||||
|
||||
END
|
||||
end
|
||||
end
|
||||
# }}}
|
||||
|
||||
|
||||
|
||||
# brackets {{{
|
||||
# curly bracket block and hash literal
|
||||
if arg == 'brackets'
|
||||
puts <<-END.gsub(/^\s{4}/, '')
|
||||
{
|
||||
foo
|
||||
}
|
||||
|
||||
|
||||
END
|
||||
|
||||
%w<_xxx ] } )>.unshift('').each do |s|
|
||||
puts <<-END.gsub(/^\s{6}/, '')
|
||||
#{s}[
|
||||
foo
|
||||
]
|
||||
|
||||
|
||||
END
|
||||
end
|
||||
end
|
||||
# }}}
|
||||
|
||||
|
||||
|
||||
# if {{{
|
||||
# if/else blocks
|
||||
if arg == 'if'
|
||||
%w(if unless).each do |start|
|
||||
puts <<-END.gsub(/^ {6}/, '')
|
||||
#{start} 1
|
||||
foo
|
||||
else
|
||||
bar
|
||||
end
|
||||
|
||||
foo \\
|
||||
#{start} 1
|
||||
foo
|
||||
else
|
||||
bar
|
||||
end
|
||||
|
||||
baz ...= #{start} 1
|
||||
foo
|
||||
else
|
||||
bar
|
||||
end
|
||||
|
||||
|
||||
END
|
||||
|
||||
['?', '!'].each do |mark|
|
||||
puts <<-END.gsub(/^ {8}/, '')
|
||||
42foo#{mark} #{start} 1
|
||||
bar
|
||||
else
|
||||
baz
|
||||
end
|
||||
|
||||
|
||||
END
|
||||
end
|
||||
|
||||
'{:,;([<>~\*%&^|+=-'.split(//).each do |expr|
|
||||
puts <<-END.gsub(/^ {8}/, '')
|
||||
foo #{expr} #{start} 1
|
||||
bar
|
||||
else
|
||||
baz
|
||||
end
|
||||
|
||||
|
||||
END
|
||||
end
|
||||
|
||||
# c7cb532 match correct `end`
|
||||
puts <<-END.gsub(/^ {6}/, '')
|
||||
#{start} 1
|
||||
(1..5).end
|
||||
:: end
|
||||
end
|
||||
|
||||
#{start} 1
|
||||
..end
|
||||
|
||||
|
||||
END
|
||||
|
||||
# INVALID cases
|
||||
puts <<-END.gsub(/^ {6}/, '')
|
||||
not_BOF #{start} 1
|
||||
bar
|
||||
else
|
||||
baz
|
||||
end
|
||||
|
||||
|
||||
END
|
||||
|
||||
['?', '!'].each do |mark|
|
||||
puts <<-END.gsub(/^ {8}/, '')
|
||||
_foo#{mark} #{start} 1
|
||||
bar
|
||||
else
|
||||
baz
|
||||
end
|
||||
|
||||
|
||||
END
|
||||
end
|
||||
end
|
||||
end
|
||||
# }}}
|
||||
|
||||
|
||||
|
||||
# for {{{
|
||||
# rubyRepeatExpression (for, while, until)
|
||||
if arg == 'for'
|
||||
puts <<-END.gsub(/^ {4}/, '')
|
||||
for 1
|
||||
foo
|
||||
end
|
||||
|
||||
|
||||
END
|
||||
|
||||
%w(until while).each do |start|
|
||||
puts <<-END.gsub(/^ {6}/, '')
|
||||
#{start} 1
|
||||
foo
|
||||
end
|
||||
|
||||
|
||||
baz ...= #{start} 1
|
||||
foo
|
||||
end
|
||||
|
||||
|
||||
END
|
||||
|
||||
'{:,;([<>~\*/%&^|+-'.split(//).each do |expr|
|
||||
puts <<-END.gsub(/^ {8}/, '')
|
||||
foo #{expr} #{start} 1
|
||||
bar
|
||||
end
|
||||
|
||||
|
||||
END
|
||||
end
|
||||
|
||||
# INVALID cases
|
||||
puts <<-END.gsub(/^ {6}/, '')
|
||||
not_BOF #{start} 1
|
||||
bar
|
||||
end
|
||||
|
||||
|
||||
END
|
||||
|
||||
['?', '!'].each do |mark|
|
||||
puts <<-END.gsub(/^ {8}/, '')
|
||||
_foo#{mark} #{start} 1
|
||||
bar
|
||||
end
|
||||
|
||||
|
||||
END
|
||||
end
|
||||
end
|
||||
end
|
||||
# }}}
|
||||
|
||||
|
||||
|
||||
# comment {{{
|
||||
if arg == 'comment'
|
||||
puts <<-END.gsub(/^ {4}/, '')
|
||||
# foo
|
||||
# foo
|
||||
# bar
|
||||
|
||||
baz
|
||||
|
||||
|
||||
|
||||
=begin foo bar
|
||||
comment
|
||||
=end baz
|
||||
|
||||
|
||||
END
|
||||
end
|
||||
# }}}
|
||||
|
||||
|
||||
|
||||
# __END__ {{{
|
||||
if arg == '__END__'
|
||||
puts <<-EOF.gsub(/^ {4}/, '')
|
||||
__END__
|
||||
invalid
|
||||
invalid
|
||||
|
||||
|
||||
__END__
|
||||
valid
|
||||
valid
|
||||
|
||||
|
||||
EOF
|
||||
end
|
||||
# }}}
|
||||
|
||||
|
||||
|
||||
puts "#\svim:foldmethod=syntax"
|
||||
|
||||
|
||||
# vim:foldmethod=marker
|
@ -1,16 +0,0 @@
|
||||
[1, [2,
|
||||
[3],
|
||||
3],
|
||||
4]
|
||||
|
||||
[1, [2,
|
||||
3],
|
||||
4]
|
||||
|
||||
[1, {2 =>
|
||||
3},
|
||||
4]
|
||||
|
||||
[1, f(2,
|
||||
3),
|
||||
4]
|
@ -1,42 +0,0 @@
|
||||
" Officially distributed filetypes
|
||||
|
||||
" Support functions {{{
|
||||
function! s:setf(filetype) abort
|
||||
if &filetype !~# '\<'.a:filetype.'\>'
|
||||
let &filetype = a:filetype
|
||||
endif
|
||||
endfunction
|
||||
|
||||
func! s:StarSetf(ft)
|
||||
if expand("<amatch>") !~ g:ft_ignore_pat
|
||||
exe 'setf ' . a:ft
|
||||
endif
|
||||
endfunc
|
||||
" }}}
|
||||
|
||||
" HTML with Ruby - eRuby
|
||||
au BufNewFile,BufRead *.erb,*.rhtml call s:setf('eruby')
|
||||
|
||||
" Interactive Ruby shell
|
||||
au BufNewFile,BufRead .irbrc,irbrc call s:setf('ruby')
|
||||
|
||||
" Ruby
|
||||
au BufNewFile,BufRead *.rb,*.rbw,*.gemspec call s:setf('ruby')
|
||||
|
||||
" Rackup
|
||||
au BufNewFile,BufRead *.ru call s:setf('ruby')
|
||||
|
||||
" Bundler
|
||||
au BufNewFile,BufRead Gemfile call s:setf('ruby')
|
||||
|
||||
" Ruby on Rails
|
||||
au BufNewFile,BufRead *.builder,*.rxml,*.rjs,*.ruby call s:setf('ruby')
|
||||
|
||||
" Rakefile
|
||||
au BufNewFile,BufRead [rR]akefile,*.rake call s:setf('ruby')
|
||||
au BufNewFile,BufRead [rR]akefile* call s:StarSetf('ruby')
|
||||
|
||||
" Rantfile
|
||||
au BufNewFile,BufRead [rR]antfile,*.rant call s:setf('ruby')
|
||||
|
||||
" vim: nowrap sw=2 sts=2 ts=8 noet fdm=marker:
|
@ -1,72 +0,0 @@
|
||||
" All other filetypes
|
||||
|
||||
" Support functions {{{
|
||||
function! s:setf(filetype) abort
|
||||
if &filetype !=# a:filetype
|
||||
let &filetype = a:filetype
|
||||
endif
|
||||
endfunction
|
||||
" }}}
|
||||
|
||||
" Appraisal
|
||||
au BufNewFile,BufRead Appraisals call s:setf('ruby')
|
||||
|
||||
" Autotest
|
||||
au BufNewFile,BufRead .autotest call s:setf('ruby')
|
||||
|
||||
" Axlsx
|
||||
au BufNewFile,BufRead *.axlsx call s:setf('ruby')
|
||||
|
||||
" Buildr Buildfile
|
||||
au BufNewFile,BufRead [Bb]uildfile call s:setf('ruby')
|
||||
|
||||
" Capistrano
|
||||
au BufNewFile,BufRead Capfile,*.cap call s:setf('ruby')
|
||||
|
||||
" Chef
|
||||
au BufNewFile,BufRead Cheffile call s:setf('ruby')
|
||||
au BufNewFile,BufRead Berksfile call s:setf('ruby')
|
||||
|
||||
" CocoaPods
|
||||
au BufNewFile,BufRead Podfile,*.podspec call s:setf('ruby')
|
||||
|
||||
" Guard
|
||||
au BufNewFile,BufRead Guardfile,.Guardfile call s:setf('ruby')
|
||||
|
||||
" Jb
|
||||
au BufNewFile,BufRead *.jb call s:setf('ruby')
|
||||
|
||||
" Jbuilder
|
||||
au BufNewFile,BufRead *.jbuilder call s:setf('ruby')
|
||||
|
||||
" Kitchen Sink
|
||||
au BufNewFile,BufRead KitchenSink call s:setf('ruby')
|
||||
|
||||
" Opal
|
||||
au BufNewFile,BufRead *.opal call s:setf('ruby')
|
||||
|
||||
" Pry config
|
||||
au BufNewFile,BufRead .pryrc call s:setf('ruby')
|
||||
|
||||
" Puppet librarian
|
||||
au BufNewFile,BufRead Puppetfile call s:setf('ruby')
|
||||
|
||||
" Rabl
|
||||
au BufNewFile,BufRead *.rabl call s:setf('ruby')
|
||||
|
||||
" Routefile
|
||||
au BufNewFile,BufRead [rR]outefile call s:setf('ruby')
|
||||
|
||||
" SimpleCov
|
||||
au BufNewFile,BufRead .simplecov call s:setf('ruby')
|
||||
|
||||
" Sorbet RBI files
|
||||
au BufNewFile,BufRead *.rbi call s:setf('ruby')
|
||||
|
||||
" Thor
|
||||
au BufNewFile,BufRead [tT]horfile,*.thor call s:setf('ruby')
|
||||
|
||||
" Vagrant
|
||||
au BufNewFile,BufRead [vV]agrantfile call s:setf('ruby')
|
||||
|
||||
" vim: nowrap sw=2 sts=2 ts=8 noet fdm=marker:
|
@ -1,131 +0,0 @@
|
||||
" Vim filetype plugin
|
||||
" Language: eRuby
|
||||
" Maintainer: Tim Pope <vimNOSPAM@tpope.org>
|
||||
" URL: https://github.com/vim-ruby/vim-ruby
|
||||
" Release Coordinator: Doug Kearns <dougkearns@gmail.com>
|
||||
|
||||
" Only do this when not done yet for this buffer
|
||||
if exists("b:did_ftplugin")
|
||||
finish
|
||||
endif
|
||||
|
||||
let s:save_cpo = &cpo
|
||||
set cpo-=C
|
||||
|
||||
" Define some defaults in case the included ftplugins don't set them.
|
||||
let s:undo_ftplugin = ""
|
||||
let s:browsefilter = "All Files (*.*)\t*.*\n"
|
||||
let s:match_words = ""
|
||||
|
||||
if !exists("g:eruby_default_subtype")
|
||||
let g:eruby_default_subtype = "html"
|
||||
endif
|
||||
|
||||
if &filetype =~ '^eruby\.'
|
||||
let b:eruby_subtype = matchstr(&filetype,'^eruby\.\zs\w\+')
|
||||
elseif !exists("b:eruby_subtype")
|
||||
let s:lines = getline(1)."\n".getline(2)."\n".getline(3)."\n".getline(4)."\n".getline(5)."\n".getline("$")
|
||||
let b:eruby_subtype = matchstr(s:lines,'eruby_subtype=\zs\w\+')
|
||||
if b:eruby_subtype == ''
|
||||
let b:eruby_subtype = matchstr(substitute(expand("%:t"),'\c\%(\.erb\|\.eruby\|\.erubis\|\.example\)\+$','',''),'\.\zs\w\+\%(\ze+\w\+\)\=$')
|
||||
endif
|
||||
if b:eruby_subtype == 'rhtml'
|
||||
let b:eruby_subtype = 'html'
|
||||
elseif b:eruby_subtype == 'rb'
|
||||
let b:eruby_subtype = 'ruby'
|
||||
elseif b:eruby_subtype == 'yml'
|
||||
let b:eruby_subtype = 'yaml'
|
||||
elseif b:eruby_subtype == 'js'
|
||||
let b:eruby_subtype = 'javascript'
|
||||
elseif b:eruby_subtype == 'txt'
|
||||
" Conventional; not a real file type
|
||||
let b:eruby_subtype = 'text'
|
||||
elseif b:eruby_subtype == ''
|
||||
let b:eruby_subtype = g:eruby_default_subtype
|
||||
endif
|
||||
endif
|
||||
|
||||
if exists("b:eruby_subtype") && b:eruby_subtype != '' && b:eruby_subtype !=? 'eruby'
|
||||
exe "runtime! ftplugin/".b:eruby_subtype.".vim ftplugin/".b:eruby_subtype."_*.vim ftplugin/".b:eruby_subtype."/*.vim"
|
||||
else
|
||||
runtime! ftplugin/html.vim ftplugin/html_*.vim ftplugin/html/*.vim
|
||||
endif
|
||||
unlet! b:did_ftplugin
|
||||
|
||||
" Override our defaults if these were set by an included ftplugin.
|
||||
if exists("b:undo_ftplugin")
|
||||
let s:undo_ftplugin = b:undo_ftplugin
|
||||
unlet b:undo_ftplugin
|
||||
endif
|
||||
if exists("b:browsefilter")
|
||||
let s:browsefilter = b:browsefilter
|
||||
unlet b:browsefilter
|
||||
endif
|
||||
if exists("b:match_words")
|
||||
let s:match_words = b:match_words
|
||||
unlet b:match_words
|
||||
endif
|
||||
|
||||
let s:cfilemap = v:version >= 704 ? maparg('<Plug><cfile>', 'c', 0, 1) : {}
|
||||
if !get(s:cfilemap, 'buffer') || !s:cfilemap.expr || s:cfilemap.rhs =~# 'ErubyAtCursor()'
|
||||
let s:cfilemap = {}
|
||||
endif
|
||||
if !has_key(s:cfilemap, 'rhs')
|
||||
let s:cfilemap.rhs = "substitute(&l:inex =~# '\\<v:fname\\>' && len(expand('<cfile>')) ? eval(substitute(&l:inex, '\\<v:fname\\>', '\\=string(expand(\"<cfile>\"))', 'g')) : '', '^$', \"\\022\\006\",'')"
|
||||
endif
|
||||
let s:ctagmap = v:version >= 704 ? maparg('<Plug><ctag>', 'c', 0, 1) : {}
|
||||
if !get(s:ctagmap, 'buffer') || !s:ctagmap.expr || s:ctagmap.rhs =~# 'ErubyAtCursor()'
|
||||
let s:ctagmap = {}
|
||||
endif
|
||||
let s:include = &l:include
|
||||
let s:path = &l:path
|
||||
let s:suffixesadd = &l:suffixesadd
|
||||
|
||||
runtime! ftplugin/ruby.vim ftplugin/ruby_*.vim ftplugin/ruby/*.vim
|
||||
let b:did_ftplugin = 1
|
||||
|
||||
" Combine the new set of values with those previously included.
|
||||
if exists("b:undo_ftplugin")
|
||||
let s:undo_ftplugin = b:undo_ftplugin . " | " . s:undo_ftplugin
|
||||
endif
|
||||
if exists ("b:browsefilter")
|
||||
let s:browsefilter = substitute(b:browsefilter,'\cAll Files (\*\.\*)\t\*\.\*\n','','') . s:browsefilter
|
||||
endif
|
||||
if exists("b:match_words")
|
||||
let s:match_words = b:match_words . ',' . s:match_words
|
||||
endif
|
||||
|
||||
if len(s:include)
|
||||
let &l:include = s:include
|
||||
endif
|
||||
let &l:path = s:path . (s:path =~# ',$\|^$' ? '' : ',') . &l:path
|
||||
let &l:suffixesadd = s:suffixesadd . (s:suffixesadd =~# ',$\|^$' ? '' : ',') . &l:suffixesadd
|
||||
exe 'cmap <buffer><script><expr> <Plug><cfile> ErubyAtCursor() ? ' . maparg('<Plug><cfile>', 'c') . ' : ' . s:cfilemap.rhs
|
||||
exe 'cmap <buffer><script><expr> <Plug><ctag> ErubyAtCursor() ? ' . maparg('<Plug><ctag>', 'c') . ' : ' . get(s:ctagmap, 'rhs', '"\022\027"')
|
||||
unlet s:cfilemap s:ctagmap s:include s:path s:suffixesadd
|
||||
|
||||
" Change the browse dialog on Win32 to show mainly eRuby-related files
|
||||
if has("gui_win32")
|
||||
let b:browsefilter="eRuby Files (*.erb, *.rhtml)\t*.erb;*.rhtml\n" . s:browsefilter
|
||||
endif
|
||||
|
||||
" Load the combined list of match_words for matchit.vim
|
||||
if exists("loaded_matchit")
|
||||
let b:match_words = s:match_words
|
||||
endif
|
||||
|
||||
" TODO: comments=
|
||||
setlocal commentstring=<%#%s%>
|
||||
|
||||
let b:undo_ftplugin = "setl cms< " .
|
||||
\ " | unlet! b:browsefilter b:match_words | " . s:undo_ftplugin
|
||||
|
||||
let &cpo = s:save_cpo
|
||||
unlet s:save_cpo
|
||||
|
||||
function! ErubyAtCursor() abort
|
||||
let groups = map(['erubyBlock', 'erubyComment', 'erubyExpression', 'erubyOneLiner'], 'hlID(v:val)')
|
||||
return !empty(filter(synstack(line('.'), col('.')), 'index(groups, v:val) >= 0'))
|
||||
endfunction
|
||||
|
||||
" vim: nowrap sw=2 sts=2 ts=8:
|
@ -1,436 +0,0 @@
|
||||
" Vim filetype plugin
|
||||
" Language: Ruby
|
||||
" Maintainer: Tim Pope <vimNOSPAM@tpope.org>
|
||||
" URL: https://github.com/vim-ruby/vim-ruby
|
||||
" Release Coordinator: Doug Kearns <dougkearns@gmail.com>
|
||||
|
||||
if (exists("b:did_ftplugin"))
|
||||
finish
|
||||
endif
|
||||
let b:did_ftplugin = 1
|
||||
|
||||
let s:cpo_save = &cpo
|
||||
set cpo&vim
|
||||
|
||||
if has("gui_running") && !has("gui_win32")
|
||||
setlocal keywordprg=ri\ -T\ -f\ bs
|
||||
else
|
||||
setlocal keywordprg=ri
|
||||
endif
|
||||
|
||||
" Matchit support
|
||||
if exists("loaded_matchit") && !exists("b:match_words")
|
||||
let b:match_ignorecase = 0
|
||||
|
||||
let b:match_words =
|
||||
\ '{\|\<\%(if\|unless\|case\|while\|until\|for\|do\|class\|module\|def\|=\@<!begin\)\>=\@!' .
|
||||
\ ':' .
|
||||
\ '\<\%(else\|elsif\|ensure\|when\|rescue\|break\|redo\|next\|retry\)\>' .
|
||||
\ ':' .
|
||||
\ '}\|\%(^\|[^.\:@$=]\)\@<=\<end\:\@!\>' .
|
||||
\ ',^=begin\>:^=end\>,' .
|
||||
\ ',\[:\],(:)'
|
||||
|
||||
let b:match_skip =
|
||||
\ "synIDattr(synID(line('.'),col('.'),0),'name') =~ '" .
|
||||
\ "\\<ruby\\%(String\\|.\+Delimiter\\|Character\\|.\+Escape\\|" .
|
||||
\ "Regexp\\|Interpolation\\|Comment\\|Documentation\\|" .
|
||||
\ "ConditionalModifier\\|RepeatModifier\\|RescueModifier\\|OptionalDo\\|" .
|
||||
\ "MethodName\\|BlockArgument\\|KeywordAsMethod\\|ClassVariable\\|" .
|
||||
\ "InstanceVariable\\|GlobalVariable\\|Symbol\\)\\>'"
|
||||
endif
|
||||
|
||||
setlocal formatoptions-=t formatoptions+=croql
|
||||
|
||||
setlocal include=^\\s*\\<\\(load\\>\\\|require\\>\\\|autoload\\s*:\\=[\"']\\=\\h\\w*[\"']\\=,\\)
|
||||
setlocal suffixesadd=.rb
|
||||
|
||||
if exists("&ofu") && has("ruby")
|
||||
setlocal omnifunc=rubycomplete#Complete
|
||||
endif
|
||||
|
||||
" TODO:
|
||||
"setlocal define=^\\s*def
|
||||
|
||||
setlocal comments=:#
|
||||
setlocal commentstring=#\ %s
|
||||
|
||||
if !exists('g:ruby_version_paths')
|
||||
let g:ruby_version_paths = {}
|
||||
endif
|
||||
|
||||
function! s:query_path(root) abort
|
||||
let code = "print $:.join %q{,}"
|
||||
if &shell =~# 'sh' && empty(&shellxquote)
|
||||
let prefix = 'env PATH='.shellescape($PATH).' '
|
||||
else
|
||||
let prefix = ''
|
||||
endif
|
||||
if &shellxquote == "'"
|
||||
let path_check = prefix.'ruby --disable-gems -e "' . code . '"'
|
||||
else
|
||||
let path_check = prefix."ruby --disable-gems -e '" . code . "'"
|
||||
endif
|
||||
|
||||
let cd = haslocaldir() ? 'lcd' : 'cd'
|
||||
let cwd = fnameescape(getcwd())
|
||||
try
|
||||
exe cd fnameescape(a:root)
|
||||
let path = split(system(path_check),',')
|
||||
exe cd cwd
|
||||
return path
|
||||
finally
|
||||
exe cd cwd
|
||||
endtry
|
||||
endfunction
|
||||
|
||||
function! s:build_path(path) abort
|
||||
let path = join(map(copy(a:path), 'v:val ==# "." ? "" : v:val'), ',')
|
||||
if &g:path !~# '\v^%(\.,)=%(/%(usr|emx)/include,)=,$'
|
||||
let path = substitute(&g:path,',,$',',','') . ',' . path
|
||||
endif
|
||||
return path
|
||||
endfunction
|
||||
|
||||
if !exists('b:ruby_version') && !exists('g:ruby_path') && isdirectory(expand('%:p:h'))
|
||||
let s:version_file = findfile('.ruby-version', '.;')
|
||||
if !empty(s:version_file) && filereadable(s:version_file)
|
||||
let b:ruby_version = get(readfile(s:version_file, '', 1), '')
|
||||
if !has_key(g:ruby_version_paths, b:ruby_version)
|
||||
let g:ruby_version_paths[b:ruby_version] = s:query_path(fnamemodify(s:version_file, ':p:h'))
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
|
||||
if exists("g:ruby_path")
|
||||
let s:ruby_path = type(g:ruby_path) == type([]) ? join(g:ruby_path, ',') : g:ruby_path
|
||||
elseif has_key(g:ruby_version_paths, get(b:, 'ruby_version', ''))
|
||||
let s:ruby_paths = g:ruby_version_paths[b:ruby_version]
|
||||
let s:ruby_path = s:build_path(s:ruby_paths)
|
||||
else
|
||||
if !exists('g:ruby_default_path')
|
||||
if has("ruby") && has("win32")
|
||||
ruby ::VIM::command( 'let g:ruby_default_path = split("%s",",")' % $:.join(%q{,}) )
|
||||
elseif executable('ruby') && !empty($HOME)
|
||||
let g:ruby_default_path = s:query_path($HOME)
|
||||
else
|
||||
let g:ruby_default_path = map(split($RUBYLIB,':'), 'v:val ==# "." ? "" : v:val')
|
||||
endif
|
||||
endif
|
||||
let s:ruby_paths = g:ruby_default_path
|
||||
let s:ruby_path = s:build_path(s:ruby_paths)
|
||||
endif
|
||||
|
||||
if stridx(&l:path, s:ruby_path) == -1
|
||||
let &l:path = s:ruby_path
|
||||
endif
|
||||
if exists('s:ruby_paths') && stridx(&l:tags, join(map(copy(s:ruby_paths),'v:val."/tags"'),',')) == -1
|
||||
let &l:tags = &tags . ',' . join(map(copy(s:ruby_paths),'v:val."/tags"'),',')
|
||||
endif
|
||||
|
||||
if (has("gui_win32") || has("gui_gtk")) && !exists("b:browsefilter")
|
||||
let b:browsefilter = "Ruby Source Files (*.rb)\t*.rb\n" .
|
||||
\ "All Files (*.*)\t*.*\n"
|
||||
endif
|
||||
|
||||
let b:undo_ftplugin = "setl inc= sua= path= tags= fo< com< cms< kp="
|
||||
\."| unlet! b:browsefilter b:match_ignorecase b:match_words b:match_skip"
|
||||
\."| if exists('&ofu') && has('ruby') | setl ofu< | endif"
|
||||
|
||||
if get(g:, 'ruby_recommended_style', 1)
|
||||
setlocal shiftwidth=2 softtabstop=2 expandtab
|
||||
let b:undo_ftplugin .= ' | setl sw< sts< et<'
|
||||
endif
|
||||
|
||||
" To activate, :set ballooneval
|
||||
if exists('+balloonexpr') && get(g:, 'ruby_balloonexpr')
|
||||
setlocal balloonexpr=RubyBalloonexpr()
|
||||
let b:undo_ftplugin .= "| setl bexpr="
|
||||
endif
|
||||
|
||||
function! s:map(mode, flags, map) abort
|
||||
let from = matchstr(a:map, '\S\+')
|
||||
if empty(mapcheck(from, a:mode))
|
||||
exe a:mode.'map' '<buffer>' a:flags a:map
|
||||
let b:undo_ftplugin .= '|sil! '.a:mode.'unmap <buffer> '.from
|
||||
endif
|
||||
endfunction
|
||||
|
||||
cmap <buffer><script><expr> <Plug><ctag> substitute(RubyCursorTag(),'^$',"\022\027",'')
|
||||
cmap <buffer><script><expr> <Plug><cfile> substitute(RubyCursorFile(),'^$',"\022\006",'')
|
||||
let b:undo_ftplugin .= "| sil! cunmap <buffer> <Plug><ctag>| sil! cunmap <buffer> <Plug><cfile>"
|
||||
|
||||
if !exists("g:no_plugin_maps") && !exists("g:no_ruby_maps")
|
||||
nmap <buffer><script> <SID>: :<C-U>
|
||||
nmap <buffer><script> <SID>c: :<C-U><C-R>=v:count ? v:count : ''<CR>
|
||||
|
||||
nnoremap <silent> <buffer> [m :<C-U>call <SID>searchsyn('\<def\>',['rubyDefine'],'b','n')<CR>
|
||||
nnoremap <silent> <buffer> ]m :<C-U>call <SID>searchsyn('\<def\>',['rubyDefine'],'','n')<CR>
|
||||
nnoremap <silent> <buffer> [M :<C-U>call <SID>searchsyn('\<end\>',['rubyDefine'],'b','n')<CR>
|
||||
nnoremap <silent> <buffer> ]M :<C-U>call <SID>searchsyn('\<end\>',['rubyDefine'],'','n')<CR>
|
||||
xnoremap <silent> <buffer> [m :<C-U>call <SID>searchsyn('\<def\>',['rubyDefine'],'b','v')<CR>
|
||||
xnoremap <silent> <buffer> ]m :<C-U>call <SID>searchsyn('\<def\>',['rubyDefine'],'','v')<CR>
|
||||
xnoremap <silent> <buffer> [M :<C-U>call <SID>searchsyn('\<end\>',['rubyDefine'],'b','v')<CR>
|
||||
xnoremap <silent> <buffer> ]M :<C-U>call <SID>searchsyn('\<end\>',['rubyDefine'],'','v')<CR>
|
||||
|
||||
nnoremap <silent> <buffer> [[ :<C-U>call <SID>searchsyn('\<\%(class\<Bar>module\)\>',['rubyModule','rubyClass'],'b','n')<CR>
|
||||
nnoremap <silent> <buffer> ]] :<C-U>call <SID>searchsyn('\<\%(class\<Bar>module\)\>',['rubyModule','rubyClass'],'','n')<CR>
|
||||
nnoremap <silent> <buffer> [] :<C-U>call <SID>searchsyn('\<end\>',['rubyModule','rubyClass'],'b','n')<CR>
|
||||
nnoremap <silent> <buffer> ][ :<C-U>call <SID>searchsyn('\<end\>',['rubyModule','rubyClass'],'','n')<CR>
|
||||
xnoremap <silent> <buffer> [[ :<C-U>call <SID>searchsyn('\<\%(class\<Bar>module\)\>',['rubyModule','rubyClass'],'b','v')<CR>
|
||||
xnoremap <silent> <buffer> ]] :<C-U>call <SID>searchsyn('\<\%(class\<Bar>module\)\>',['rubyModule','rubyClass'],'','v')<CR>
|
||||
xnoremap <silent> <buffer> [] :<C-U>call <SID>searchsyn('\<end\>',['rubyModule','rubyClass'],'b','v')<CR>
|
||||
xnoremap <silent> <buffer> ][ :<C-U>call <SID>searchsyn('\<end\>',['rubyModule','rubyClass'],'','v')<CR>
|
||||
|
||||
let b:undo_ftplugin = b:undo_ftplugin
|
||||
\."| sil! exe 'unmap <buffer> [[' | sil! exe 'unmap <buffer> ]]' | sil! exe 'unmap <buffer> []' | sil! exe 'unmap <buffer> ]['"
|
||||
\."| sil! exe 'unmap <buffer> [m' | sil! exe 'unmap <buffer> ]m' | sil! exe 'unmap <buffer> [M' | sil! exe 'unmap <buffer> ]M'"
|
||||
|
||||
if maparg('im','x') == '' && maparg('im','o') == '' && maparg('am','x') == '' && maparg('am','o') == ''
|
||||
onoremap <silent> <buffer> im :<C-U>call <SID>wrap_i('[m',']M')<CR>
|
||||
onoremap <silent> <buffer> am :<C-U>call <SID>wrap_a('[m',']M')<CR>
|
||||
xnoremap <silent> <buffer> im :<C-U>call <SID>wrap_i('[m',']M')<CR>
|
||||
xnoremap <silent> <buffer> am :<C-U>call <SID>wrap_a('[m',']M')<CR>
|
||||
let b:undo_ftplugin = b:undo_ftplugin
|
||||
\."| sil! exe 'ounmap <buffer> im' | sil! exe 'ounmap <buffer> am'"
|
||||
\."| sil! exe 'xunmap <buffer> im' | sil! exe 'xunmap <buffer> am'"
|
||||
endif
|
||||
|
||||
if maparg('iM','x') == '' && maparg('iM','o') == '' && maparg('aM','x') == '' && maparg('aM','o') == ''
|
||||
onoremap <silent> <buffer> iM :<C-U>call <SID>wrap_i('[[','][')<CR>
|
||||
onoremap <silent> <buffer> aM :<C-U>call <SID>wrap_a('[[','][')<CR>
|
||||
xnoremap <silent> <buffer> iM :<C-U>call <SID>wrap_i('[[','][')<CR>
|
||||
xnoremap <silent> <buffer> aM :<C-U>call <SID>wrap_a('[[','][')<CR>
|
||||
let b:undo_ftplugin = b:undo_ftplugin
|
||||
\."| sil! exe 'ounmap <buffer> iM' | sil! exe 'ounmap <buffer> aM'"
|
||||
\."| sil! exe 'xunmap <buffer> iM' | sil! exe 'xunmap <buffer> aM'"
|
||||
endif
|
||||
|
||||
call s:map('c', '', '<C-R><C-F> <Plug><cfile>')
|
||||
|
||||
cmap <buffer><script><expr> <SID>tagzv &foldopen =~# 'tag' ? '<Bar>norm! zv' : ''
|
||||
call s:map('n', '<silent>', '<C-]> <SID>:exe v:count1."tag <Plug><ctag>"<SID>tagzv<CR>')
|
||||
call s:map('n', '<silent>', 'g<C-]> <SID>:exe "tjump <Plug><ctag>"<SID>tagzv<CR>')
|
||||
call s:map('n', '<silent>', 'g] <SID>:exe "tselect <Plug><ctag>"<SID>tagzv<CR>')
|
||||
call s:map('n', '<silent>', '<C-W>] <SID>:exe v:count1."stag <Plug><ctag>"<SID>tagzv<CR>')
|
||||
call s:map('n', '<silent>', '<C-W><C-]> <SID>:exe v:count1."stag <Plug><ctag>"<SID>tagzv<CR>')
|
||||
call s:map('n', '<silent>', '<C-W>g<C-]> <SID>:exe "stjump <Plug><ctag>"<SID>tagzv<CR>')
|
||||
call s:map('n', '<silent>', '<C-W>g] <SID>:exe "stselect <Plug><ctag>"<SID>tagzv<CR>')
|
||||
call s:map('n', '<silent>', '<C-W>} <SID>:exe v:count1."ptag <Plug><ctag>"<CR>')
|
||||
call s:map('n', '<silent>', '<C-W>g} <SID>:exe "ptjump <Plug><ctag>"<CR>')
|
||||
|
||||
call s:map('n', '<silent>', 'gf <SID>c:find <Plug><cfile><CR>')
|
||||
call s:map('n', '<silent>', '<C-W>f <SID>c:sfind <Plug><cfile><CR>')
|
||||
call s:map('n', '<silent>', '<C-W><C-F> <SID>c:sfind <Plug><cfile><CR>')
|
||||
call s:map('n', '<silent>', '<C-W>gf <SID>c:tabfind <Plug><cfile><CR>')
|
||||
endif
|
||||
|
||||
let &cpo = s:cpo_save
|
||||
unlet s:cpo_save
|
||||
|
||||
if exists("g:did_ruby_ftplugin_functions")
|
||||
finish
|
||||
endif
|
||||
let g:did_ruby_ftplugin_functions = 1
|
||||
|
||||
function! RubyBalloonexpr() abort
|
||||
if !exists('s:ri_found')
|
||||
let s:ri_found = executable('ri')
|
||||
endif
|
||||
if s:ri_found
|
||||
let line = getline(v:beval_lnum)
|
||||
let b = matchstr(strpart(line,0,v:beval_col),'\%(\w\|[:.]\)*$')
|
||||
let a = substitute(matchstr(strpart(line,v:beval_col),'^\w*\%([?!]\|\s*=\)\?'),'\s\+','','g')
|
||||
let str = b.a
|
||||
let before = strpart(line,0,v:beval_col-strlen(b))
|
||||
let after = strpart(line,v:beval_col+strlen(a))
|
||||
if str =~ '^\.'
|
||||
let str = substitute(str,'^\.','#','g')
|
||||
if before =~ '\]\s*$'
|
||||
let str = 'Array'.str
|
||||
elseif before =~ '}\s*$'
|
||||
" False positives from blocks here
|
||||
let str = 'Hash'.str
|
||||
elseif before =~ "[\"'`]\\s*$" || before =~ '\$\d\+\s*$'
|
||||
let str = 'String'.str
|
||||
elseif before =~ '\$\d\+\.\d\+\s*$'
|
||||
let str = 'Float'.str
|
||||
elseif before =~ '\$\d\+\s*$'
|
||||
let str = 'Integer'.str
|
||||
elseif before =~ '/\s*$'
|
||||
let str = 'Regexp'.str
|
||||
else
|
||||
let str = substitute(str,'^#','.','')
|
||||
endif
|
||||
endif
|
||||
let str = substitute(str,'.*\.\s*to_f\s*\.\s*','Float#','')
|
||||
let str = substitute(str,'.*\.\s*to_i\%(nt\)\=\s*\.\s*','Integer#','')
|
||||
let str = substitute(str,'.*\.\s*to_s\%(tr\)\=\s*\.\s*','String#','')
|
||||
let str = substitute(str,'.*\.\s*to_sym\s*\.\s*','Symbol#','')
|
||||
let str = substitute(str,'.*\.\s*to_a\%(ry\)\=\s*\.\s*','Array#','')
|
||||
let str = substitute(str,'.*\.\s*to_proc\s*\.\s*','Proc#','')
|
||||
if str !~ '^\w'
|
||||
return ''
|
||||
endif
|
||||
silent! let res = substitute(system("ri -f rdoc -T \"".str.'"'),'\n$','','')
|
||||
if res =~ '^Nothing known about' || res =~ '^Bad argument:' || res =~ '^More than one method'
|
||||
return ''
|
||||
endif
|
||||
return res
|
||||
else
|
||||
return ""
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! s:searchsyn(pattern, syn, flags, mode) abort
|
||||
let cnt = v:count1
|
||||
norm! m'
|
||||
if a:mode ==# 'v'
|
||||
norm! gv
|
||||
endif
|
||||
let i = 0
|
||||
call map(a:syn, 'hlID(v:val)')
|
||||
while i < cnt
|
||||
let i = i + 1
|
||||
let line = line('.')
|
||||
let col = col('.')
|
||||
let pos = search(a:pattern,'W'.a:flags)
|
||||
while pos != 0 && index(a:syn, s:synid()) < 0
|
||||
let pos = search(a:pattern,'W'.a:flags)
|
||||
endwhile
|
||||
if pos == 0
|
||||
call cursor(line,col)
|
||||
return
|
||||
endif
|
||||
endwhile
|
||||
endfunction
|
||||
|
||||
function! s:synid() abort
|
||||
return synID(line('.'),col('.'),0)
|
||||
endfunction
|
||||
|
||||
function! s:wrap_i(back,forward) abort
|
||||
execute 'norm! k'
|
||||
execute 'norm '.a:forward
|
||||
let line = line('.')
|
||||
execute 'norm '.a:back
|
||||
if line('.') == line - 1
|
||||
return s:wrap_a(a:back,a:forward)
|
||||
endif
|
||||
execute 'norm! jV'
|
||||
execute 'norm '.a:forward
|
||||
execute 'norm! k'
|
||||
endfunction
|
||||
|
||||
function! s:wrap_a(back,forward) abort
|
||||
execute 'norm '.a:forward
|
||||
if line('.') < line('$') && getline(line('.')+1) ==# ''
|
||||
let after = 1
|
||||
endif
|
||||
execute 'norm '.a:back
|
||||
while getline(line('.')-1) =~# '^\s*#' && line('.')
|
||||
-
|
||||
endwhile
|
||||
if exists('after')
|
||||
execute 'norm! V'
|
||||
execute 'norm '.a:forward
|
||||
execute 'norm! j'
|
||||
elseif line('.') > 1 && getline(line('.')-1) =~# '^\s*$'
|
||||
execute 'norm! kV'
|
||||
execute 'norm '.a:forward
|
||||
else
|
||||
execute 'norm! V'
|
||||
execute 'norm '.a:forward
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! RubyCursorIdentifier() abort
|
||||
let asciicode = '\%(\w\|[]})\"'."'".']\)\@<!\%(?\%(\\M-\\C-\|\\C-\\M-\|\\M-\\c\|\\c\\M-\|\\c\|\\C-\|\\M-\)\=\%(\\\o\{1,3}\|\\x\x\{1,2}\|\\\=\S\)\)'
|
||||
let number = '\%(\%(\w\|[]})\"'."'".']\s*\)\@<!-\)\=\%(\<[[:digit:]_]\+\%(\.[[:digit:]_]\+\)\=\%([Ee][[:digit:]_]\+\)\=\>\|\<0[xXbBoOdD][[:xdigit:]_]\+\>\)\|'.asciicode
|
||||
let operator = '\%(\[\]\|<<\|<=>\|[!<>]=\=\|===\=\|[!=]\~\|>>\|\*\*\|\.\.\.\=\|=>\|[~^&|*/%+-]\)'
|
||||
let method = '\%(\.[_a-zA-Z]\w*\s*=>\@!\|\<[_a-zA-Z]\w*\>[?!]\=\)'
|
||||
let global = '$\%([!$&"'."'".'*+,./:;<=>?@\`~]\|-\=\w\+\>\)'
|
||||
let symbolizable = '\%(\%(@@\=\)\w\+\>\|'.global.'\|'.method.'\|'.operator.'\)'
|
||||
let pattern = '\C\s*\%('.number.'\|\%(:\@<!:\)\='.symbolizable.'\)'
|
||||
let [lnum, col] = searchpos(pattern,'bcn',line('.'))
|
||||
let raw = matchstr(getline('.')[col-1 : ],pattern)
|
||||
let stripped = substitute(substitute(raw,'\s\+=$','=',''),'^\s*[:.]\=','','')
|
||||
return stripped == '' ? expand("<cword>") : stripped
|
||||
endfunction
|
||||
|
||||
function! RubyCursorTag() abort
|
||||
return substitute(RubyCursorIdentifier(), '^[$@]*', '', '')
|
||||
endfunction
|
||||
|
||||
function! RubyCursorFile() abort
|
||||
let isfname = &isfname
|
||||
try
|
||||
set isfname+=:
|
||||
let cfile = expand('<cfile>')
|
||||
finally
|
||||
let isfname = &isfname
|
||||
endtry
|
||||
let pre = matchstr(strpart(getline('.'), 0, col('.')-1), '.*\f\@<!')
|
||||
let post = matchstr(strpart(getline('.'), col('.')), '\f\@!.*')
|
||||
if s:synid() ==# hlID('rubyConstant')
|
||||
let cfile = substitute(cfile,'\.\w\+[?!=]\=$','','')
|
||||
let cfile = substitute(cfile,'^::','','')
|
||||
let cfile = substitute(cfile,'::','/','g')
|
||||
let cfile = substitute(cfile,'\(\u\+\)\(\u\l\)','\1_\2', 'g')
|
||||
let cfile = substitute(cfile,'\(\l\|\d\)\(\u\)','\1_\2', 'g')
|
||||
return tolower(cfile) . '.rb'
|
||||
elseif getline('.') =~# '^\s*require_relative\s*\(["'']\).*\1\s*$'
|
||||
let cfile = expand('%:p:h') . '/' . matchstr(getline('.'),'\(["'']\)\zs.\{-\}\ze\1')
|
||||
let cfile .= cfile !~# '\.rb$' ? '.rb' : ''
|
||||
elseif getline('.') =~# '^\s*\%(require[( ]\|load[( ]\|autoload[( ]:\w\+,\)\s*\%(::\)\=File\.expand_path(\(["'']\)\.\./.*\1,\s*__FILE__)\s*$'
|
||||
let target = matchstr(getline('.'),'\(["'']\)\.\.\zs/.\{-\}\ze\1')
|
||||
let cfile = expand('%:p:h') . target
|
||||
let cfile .= cfile !~# '\.rb$' ? '.rb' : ''
|
||||
elseif getline('.') =~# '^\s*\%(require \|load \|autoload :\w\+,\)\s*\(["'']\).*\1\s*$'
|
||||
let cfile = matchstr(getline('.'),'\(["'']\)\zs.\{-\}\ze\1')
|
||||
let cfile .= cfile !~# '\.rb$' ? '.rb' : ''
|
||||
elseif pre.post =~# '\<File.expand_path[( ].*[''"]\{2\}, *__FILE__\>' && cfile =~# '^\.\.'
|
||||
let cfile = expand('%:p:h') . strpart(cfile, 2)
|
||||
else
|
||||
return substitute(cfile, '\C\v^(.*):(\d+)%(:in)=$', '+\2 \1', '')
|
||||
endif
|
||||
let cwdpat = '^\M' . substitute(getcwd(), '[\/]', '\\[\\/]', 'g').'\ze\[\/]'
|
||||
let cfile = substitute(cfile, cwdpat, '.', '')
|
||||
if fnameescape(cfile) !=# cfile
|
||||
return '+ '.fnameescape(cfile)
|
||||
else
|
||||
return cfile
|
||||
endif
|
||||
endfunction
|
||||
|
||||
"
|
||||
" Instructions for enabling "matchit" support:
|
||||
"
|
||||
" 1. Look for the latest "matchit" plugin at
|
||||
"
|
||||
" http://www.vim.org/scripts/script.php?script_id=39
|
||||
"
|
||||
" It is also packaged with Vim, in the $VIMRUNTIME/macros directory.
|
||||
"
|
||||
" 2. Copy "matchit.txt" into a "doc" directory (e.g. $HOME/.vim/doc).
|
||||
"
|
||||
" 3. Copy "matchit.vim" into a "plugin" directory (e.g. $HOME/.vim/plugin).
|
||||
"
|
||||
" 4. Ensure this file (ftplugin/ruby.vim) is installed.
|
||||
"
|
||||
" 5. Ensure you have this line in your $HOME/.vimrc:
|
||||
" filetype plugin on
|
||||
"
|
||||
" 6. Restart Vim and create the matchit documentation:
|
||||
"
|
||||
" :helptags ~/.vim/doc
|
||||
"
|
||||
" Now you can do ":help matchit", and you should be able to use "%" on Ruby
|
||||
" keywords. Try ":echo b:match_words" to be sure.
|
||||
"
|
||||
" Thanks to Mark J. Reed for the instructions. See ":help vimrc" for the
|
||||
" locations of plugin directories, etc., as there are several options, and it
|
||||
" differs on Windows. Email gsinclair@soyabean.com.au if you need help.
|
||||
"
|
||||
|
||||
" vim: nowrap sw=2 sts=2 ts=8:
|
@ -1,110 +0,0 @@
|
||||
" Vim indent file
|
||||
" Language: eRuby
|
||||
" Maintainer: Tim Pope <vimNOSPAM@tpope.org>
|
||||
" URL: https://github.com/vim-ruby/vim-ruby
|
||||
" Release Coordinator: Doug Kearns <dougkearns@gmail.com>
|
||||
|
||||
if exists("b:did_indent")
|
||||
finish
|
||||
endif
|
||||
|
||||
runtime! indent/ruby.vim
|
||||
unlet! b:did_indent
|
||||
setlocal indentexpr=
|
||||
|
||||
if exists("b:eruby_subtype") && b:eruby_subtype != '' && b:eruby_subtype !=# 'eruby'
|
||||
exe "runtime! indent/".b:eruby_subtype.".vim"
|
||||
else
|
||||
runtime! indent/html.vim
|
||||
endif
|
||||
unlet! b:did_indent
|
||||
|
||||
" Force HTML indent to not keep state.
|
||||
let b:html_indent_usestate = 0
|
||||
|
||||
if &l:indentexpr == ''
|
||||
if &l:cindent
|
||||
let &l:indentexpr = 'cindent(v:lnum)'
|
||||
else
|
||||
let &l:indentexpr = 'indent(prevnonblank(v:lnum-1))'
|
||||
endif
|
||||
endif
|
||||
let b:eruby_subtype_indentexpr = &l:indentexpr
|
||||
|
||||
let b:did_indent = 1
|
||||
|
||||
setlocal indentexpr=GetErubyIndent()
|
||||
setlocal indentkeys=o,O,*<Return>,<>>,{,},0),0],o,O,!^F,=end,=else,=elsif,=rescue,=ensure,=when
|
||||
|
||||
" Only define the function once.
|
||||
if exists("*GetErubyIndent")
|
||||
finish
|
||||
endif
|
||||
|
||||
" this file uses line continuations
|
||||
let s:cpo_sav = &cpo
|
||||
set cpo&vim
|
||||
|
||||
function! GetErubyIndent(...)
|
||||
" The value of a single shift-width
|
||||
if exists('*shiftwidth')
|
||||
let sw = shiftwidth()
|
||||
else
|
||||
let sw = &sw
|
||||
endif
|
||||
|
||||
if a:0 && a:1 == '.'
|
||||
let v:lnum = line('.')
|
||||
elseif a:0 && a:1 =~ '^\d'
|
||||
let v:lnum = a:1
|
||||
endif
|
||||
let vcol = col('.')
|
||||
call cursor(v:lnum,1)
|
||||
let inruby = searchpair('<%','','%>','W')
|
||||
call cursor(v:lnum,vcol)
|
||||
if inruby && getline(v:lnum) !~ '^<%\|^\s*[-=]\=%>'
|
||||
let ind = GetRubyIndent(v:lnum)
|
||||
else
|
||||
exe "let ind = ".b:eruby_subtype_indentexpr
|
||||
|
||||
" Workaround for Andy Wokula's HTML indent. This should be removed after
|
||||
" some time, since the newest version is fixed in a different way.
|
||||
if b:eruby_subtype_indentexpr =~# '^HtmlIndent('
|
||||
\ && exists('b:indent')
|
||||
\ && type(b:indent) == type({})
|
||||
\ && has_key(b:indent, 'lnum')
|
||||
" Force HTML indent to not keep state
|
||||
let b:indent.lnum = -1
|
||||
endif
|
||||
endif
|
||||
let lnum = prevnonblank(v:lnum-1)
|
||||
let line = getline(lnum)
|
||||
let cline = getline(v:lnum)
|
||||
if cline =~# '^\s*<%[-=]\=\s*\%(}\|end\|else\|\%(ensure\|rescue\|elsif\|when\).\{-\}\)\s*\%([-=]\=%>\|$\)'
|
||||
let ind = ind - sw
|
||||
endif
|
||||
if line =~# '\S\s*<%[-=]\=\s*\%(}\|end\).\{-\}\s*\%([-=]\=%>\|$\)'
|
||||
let ind = ind - sw
|
||||
endif
|
||||
if line =~# '\%({\|\<do\)\%(\s*|[^|]*|\)\=\s*[-=]\=%>'
|
||||
let ind = ind + sw
|
||||
elseif line =~# '<%[-=]\=\s*\%(module\|class\|def\|if\|for\|while\|until\|else\|elsif\|case\|when\|unless\|begin\|ensure\|rescue\)\>.*%>'
|
||||
let ind = ind + sw
|
||||
endif
|
||||
if line =~# '^\s*<%[=#-]\=\s*$' && cline !~# '^\s*end\>'
|
||||
let ind = ind + sw
|
||||
endif
|
||||
if line !~# '^\s*<%' && line =~# '%>\s*$' && line !~# '^\s*end\>'
|
||||
\ && synID(v:lnum, match(cline, '\S') + 1, 1) != hlID('htmlEndTag')
|
||||
let ind = ind - sw
|
||||
endif
|
||||
if cline =~# '^\s*[-=]\=%>\s*$'
|
||||
let ind = ind - sw
|
||||
endif
|
||||
return ind
|
||||
endfunction
|
||||
|
||||
let &cpo = s:cpo_sav
|
||||
unlet! s:cpo_sav
|
||||
|
||||
" vim:set sw=2 sts=2 ts=8 noet:
|
@ -1,987 +0,0 @@
|
||||
" Vim indent file
|
||||
" Language: Ruby
|
||||
" Maintainer: Andrew Radev <andrey.radev@gmail.com>
|
||||
" Previous Maintainer: Nikolai Weibull <now at bitwi.se>
|
||||
" URL: https://github.com/vim-ruby/vim-ruby
|
||||
" Release Coordinator: Doug Kearns <dougkearns@gmail.com>
|
||||
|
||||
" 0. Initialization {{{1
|
||||
" =================
|
||||
|
||||
" Only load this indent file when no other was loaded.
|
||||
if exists("b:did_indent")
|
||||
finish
|
||||
endif
|
||||
let b:did_indent = 1
|
||||
|
||||
if !exists('g:ruby_indent_access_modifier_style')
|
||||
" Possible values: "normal", "indent", "outdent"
|
||||
let g:ruby_indent_access_modifier_style = 'normal'
|
||||
endif
|
||||
|
||||
if !exists('g:ruby_indent_assignment_style')
|
||||
" Possible values: "variable", "hanging"
|
||||
let g:ruby_indent_assignment_style = 'hanging'
|
||||
endif
|
||||
|
||||
if !exists('g:ruby_indent_block_style')
|
||||
" Possible values: "expression", "do"
|
||||
let g:ruby_indent_block_style = 'do'
|
||||
endif
|
||||
|
||||
if !exists('g:ruby_indent_hanging_elements')
|
||||
" Non-zero means hanging indents are enabled, zero means disabled
|
||||
let g:ruby_indent_hanging_elements = 1
|
||||
endif
|
||||
|
||||
setlocal nosmartindent
|
||||
|
||||
" Now, set up our indentation expression and keys that trigger it.
|
||||
setlocal indentexpr=GetRubyIndent(v:lnum)
|
||||
setlocal indentkeys=0{,0},0),0],!^F,o,O,e,:,.
|
||||
setlocal indentkeys+==end,=else,=elsif,=when,=ensure,=rescue,==begin,==end
|
||||
setlocal indentkeys+==private,=protected,=public
|
||||
|
||||
" Only define the function once.
|
||||
if exists("*GetRubyIndent")
|
||||
finish
|
||||
endif
|
||||
|
||||
let s:cpo_save = &cpo
|
||||
set cpo&vim
|
||||
|
||||
" 1. Variables {{{1
|
||||
" ============
|
||||
|
||||
" Syntax group names that are strings.
|
||||
let s:syng_string =
|
||||
\ ['String', 'Interpolation', 'InterpolationDelimiter', 'StringEscape']
|
||||
|
||||
" Syntax group names that are strings or documentation.
|
||||
let s:syng_stringdoc = s:syng_string + ['Documentation']
|
||||
|
||||
" Syntax group names that are or delimit strings/symbols/regexes or are comments.
|
||||
let s:syng_strcom = s:syng_stringdoc + [
|
||||
\ 'Character',
|
||||
\ 'Comment',
|
||||
\ 'HeredocDelimiter',
|
||||
\ 'PercentRegexpDelimiter',
|
||||
\ 'PercentStringDelimiter',
|
||||
\ 'PercentSymbolDelimiter',
|
||||
\ 'Regexp',
|
||||
\ 'RegexpCharClass',
|
||||
\ 'RegexpDelimiter',
|
||||
\ 'RegexpEscape',
|
||||
\ 'StringDelimiter',
|
||||
\ 'Symbol',
|
||||
\ 'SymbolDelimiter',
|
||||
\ ]
|
||||
|
||||
" Expression used to check whether we should skip a match with searchpair().
|
||||
let s:skip_expr =
|
||||
\ 'index(map('.string(s:syng_strcom).',"hlID(''ruby''.v:val)"), synID(line("."),col("."),1)) >= 0'
|
||||
|
||||
" Regex used for words that, at the start of a line, add a level of indent.
|
||||
let s:ruby_indent_keywords =
|
||||
\ '^\s*\zs\<\%(module\|class\|if\|for' .
|
||||
\ '\|while\|until\|else\|elsif\|case\|when\|unless\|begin\|ensure\|rescue' .
|
||||
\ '\|\%(\K\k*[!?]\?\s\+\)\=def\):\@!\>' .
|
||||
\ '\|\%([=,*/%+-]\|<<\|>>\|:\s\)\s*\zs' .
|
||||
\ '\<\%(if\|for\|while\|until\|case\|unless\|begin\):\@!\>'
|
||||
|
||||
" Def without an end clause: def method_call(...) = <expression>
|
||||
let s:ruby_endless_def = '\<def\s\+\k\+[!?]\=\%((.*)\|\s\)\s*='
|
||||
|
||||
" Regex used for words that, at the start of a line, remove a level of indent.
|
||||
let s:ruby_deindent_keywords =
|
||||
\ '^\s*\zs\<\%(ensure\|else\|rescue\|elsif\|when\|end\):\@!\>'
|
||||
|
||||
" Regex that defines the start-match for the 'end' keyword.
|
||||
"let s:end_start_regex = '\%(^\|[^.]\)\<\%(module\|class\|def\|if\|for\|while\|until\|case\|unless\|begin\|do\)\>'
|
||||
" TODO: the do here should be restricted somewhat (only at end of line)?
|
||||
let s:end_start_regex =
|
||||
\ '\C\%(^\s*\|[=,*/%+\-|;{]\|<<\|>>\|:\s\)\s*\zs' .
|
||||
\ '\<\%(module\|class\|if\|for\|while\|until\|case\|unless\|begin' .
|
||||
\ '\|\%(\K\k*[!?]\?\s\+\)\=def\):\@!\>' .
|
||||
\ '\|\%(^\|[^.:@$]\)\@<=\<do:\@!\>'
|
||||
|
||||
" Regex that defines the middle-match for the 'end' keyword.
|
||||
let s:end_middle_regex = '\<\%(ensure\|else\|\%(\%(^\|;\)\s*\)\@<=\<rescue:\@!\>\|when\|elsif\):\@!\>'
|
||||
|
||||
" Regex that defines the end-match for the 'end' keyword.
|
||||
let s:end_end_regex = '\%(^\|[^.:@$]\)\@<=\<end:\@!\>'
|
||||
|
||||
" Expression used for searchpair() call for finding a match for an 'end' keyword.
|
||||
function! s:EndSkipExpr()
|
||||
if eval(s:skip_expr)
|
||||
return 1
|
||||
elseif expand('<cword>') == 'do'
|
||||
\ && getline(".") =~ '^\s*\<\(while\|until\|for\):\@!\>'
|
||||
return 1
|
||||
elseif getline('.') =~ s:ruby_endless_def
|
||||
return 1
|
||||
elseif getline('.') =~ '\<def\s\+\k\+[!?]\=([^)]*$'
|
||||
" Then it's a `def method(` with a possible `) =` later
|
||||
call search('\<def\s\+\k\+\zs(', 'W', line('.'))
|
||||
normal! %
|
||||
return getline('.') =~ ')\s*='
|
||||
else
|
||||
return 0
|
||||
endif
|
||||
endfunction
|
||||
|
||||
let s:end_skip_expr = function('s:EndSkipExpr')
|
||||
|
||||
" Regex that defines continuation lines, not including (, {, or [.
|
||||
let s:non_bracket_continuation_regex =
|
||||
\ '\%([\\.,:*/%+]\|\<and\|\<or\|\%(<%\)\@<![=-]\|:\@<![^[:alnum:]:][|&?]\|||\|&&\)\s*\%(#.*\)\=$'
|
||||
|
||||
" Regex that defines continuation lines.
|
||||
let s:continuation_regex =
|
||||
\ '\%(%\@<![({[\\.,:*/%+]\|\<and\|\<or\|\%(<%\)\@<![=-]\|:\@<![^[:alnum:]:][|&?]\|||\|&&\)\s*\%(#.*\)\=$'
|
||||
|
||||
" Regex that defines continuable keywords
|
||||
let s:continuable_regex =
|
||||
\ '\C\%(^\s*\|[=,*/%+\-|;{]\|<<\|>>\|:\s\)\s*\zs' .
|
||||
\ '\<\%(if\|for\|while\|until\|unless\):\@!\>'
|
||||
|
||||
" Regex that defines bracket continuations
|
||||
let s:bracket_continuation_regex = '%\@<!\%([({[]\)\s*\%(#.*\)\=$'
|
||||
|
||||
" Regex that defines dot continuations
|
||||
let s:dot_continuation_regex = '%\@<!\.\s*\%(#.*\)\=$'
|
||||
|
||||
" Regex that defines backslash continuations
|
||||
let s:backslash_continuation_regex = '%\@<!\\\s*$'
|
||||
|
||||
" Regex that defines end of bracket continuation followed by another continuation
|
||||
let s:bracket_switch_continuation_regex = '^\([^(]\+\zs).\+\)\+'.s:continuation_regex
|
||||
|
||||
" Regex that defines the first part of a splat pattern
|
||||
let s:splat_regex = '[[,(]\s*\*\s*\%(#.*\)\=$'
|
||||
|
||||
" Regex that describes all indent access modifiers
|
||||
let s:access_modifier_regex = '\C^\s*\%(public\|protected\|private\)\s*\%(#.*\)\=$'
|
||||
|
||||
" Regex that describes the indent access modifiers (excludes public)
|
||||
let s:indent_access_modifier_regex = '\C^\s*\%(protected\|private\)\s*\%(#.*\)\=$'
|
||||
|
||||
" Regex that defines blocks.
|
||||
"
|
||||
" Note that there's a slight problem with this regex and s:continuation_regex.
|
||||
" Code like this will be matched by both:
|
||||
"
|
||||
" method_call do |(a, b)|
|
||||
"
|
||||
" The reason is that the pipe matches a hanging "|" operator.
|
||||
"
|
||||
let s:block_regex =
|
||||
\ '\%(\<do:\@!\>\|%\@<!{\)\s*\%(|[^|]*|\)\=\s*\%(#.*\)\=$'
|
||||
|
||||
let s:block_continuation_regex = '^\s*[^])}\t ].*'.s:block_regex
|
||||
|
||||
" Regex that describes a leading operator (only a method call's dot for now)
|
||||
let s:leading_operator_regex = '^\s*\%(&\=\.\)'
|
||||
|
||||
" 2. GetRubyIndent Function {{{1
|
||||
" =========================
|
||||
|
||||
function! GetRubyIndent(...) abort
|
||||
" 2.1. Setup {{{2
|
||||
" ----------
|
||||
|
||||
let indent_info = {}
|
||||
|
||||
" The value of a single shift-width
|
||||
if exists('*shiftwidth')
|
||||
let indent_info.sw = shiftwidth()
|
||||
else
|
||||
let indent_info.sw = &sw
|
||||
endif
|
||||
|
||||
" For the current line, use the first argument if given, else v:lnum
|
||||
let indent_info.clnum = a:0 ? a:1 : v:lnum
|
||||
let indent_info.cline = getline(indent_info.clnum)
|
||||
|
||||
" Set up variables for restoring position in file. Could use clnum here.
|
||||
let indent_info.col = col('.')
|
||||
|
||||
" 2.2. Work on the current line {{{2
|
||||
" -----------------------------
|
||||
let indent_callback_names = [
|
||||
\ 's:AccessModifier',
|
||||
\ 's:ClosingBracketOnEmptyLine',
|
||||
\ 's:BlockComment',
|
||||
\ 's:DeindentingKeyword',
|
||||
\ 's:MultilineStringOrLineComment',
|
||||
\ 's:ClosingHeredocDelimiter',
|
||||
\ 's:LeadingOperator',
|
||||
\ ]
|
||||
|
||||
for callback_name in indent_callback_names
|
||||
" Decho "Running: ".callback_name
|
||||
let indent = call(function(callback_name), [indent_info])
|
||||
|
||||
if indent >= 0
|
||||
" Decho "Match: ".callback_name." indent=".indent." info=".string(indent_info)
|
||||
return indent
|
||||
endif
|
||||
endfor
|
||||
|
||||
" 2.3. Work on the previous line. {{{2
|
||||
" -------------------------------
|
||||
|
||||
" Special case: we don't need the real s:PrevNonBlankNonString for an empty
|
||||
" line inside a string. And that call can be quite expensive in that
|
||||
" particular situation.
|
||||
let indent_callback_names = [
|
||||
\ 's:EmptyInsideString',
|
||||
\ ]
|
||||
|
||||
for callback_name in indent_callback_names
|
||||
" Decho "Running: ".callback_name
|
||||
let indent = call(function(callback_name), [indent_info])
|
||||
|
||||
if indent >= 0
|
||||
" Decho "Match: ".callback_name." indent=".indent." info=".string(indent_info)
|
||||
return indent
|
||||
endif
|
||||
endfor
|
||||
|
||||
" Previous line number
|
||||
let indent_info.plnum = s:PrevNonBlankNonString(indent_info.clnum - 1)
|
||||
let indent_info.pline = getline(indent_info.plnum)
|
||||
|
||||
let indent_callback_names = [
|
||||
\ 's:StartOfFile',
|
||||
\ 's:AfterAccessModifier',
|
||||
\ 's:ContinuedLine',
|
||||
\ 's:AfterBlockOpening',
|
||||
\ 's:AfterHangingSplat',
|
||||
\ 's:AfterUnbalancedBracket',
|
||||
\ 's:AfterLeadingOperator',
|
||||
\ 's:AfterEndKeyword',
|
||||
\ 's:AfterIndentKeyword',
|
||||
\ ]
|
||||
|
||||
for callback_name in indent_callback_names
|
||||
" Decho "Running: ".callback_name
|
||||
let indent = call(function(callback_name), [indent_info])
|
||||
|
||||
if indent >= 0
|
||||
" Decho "Match: ".callback_name." indent=".indent." info=".string(indent_info)
|
||||
return indent
|
||||
endif
|
||||
endfor
|
||||
|
||||
" 2.4. Work on the MSL line. {{{2
|
||||
" --------------------------
|
||||
let indent_callback_names = [
|
||||
\ 's:PreviousNotMSL',
|
||||
\ 's:IndentingKeywordInMSL',
|
||||
\ 's:ContinuedHangingOperator',
|
||||
\ ]
|
||||
|
||||
" Most Significant line based on the previous one -- in case it's a
|
||||
" continuation of something above
|
||||
let indent_info.plnum_msl = s:GetMSL(indent_info.plnum)
|
||||
|
||||
for callback_name in indent_callback_names
|
||||
" Decho "Running: ".callback_name
|
||||
let indent = call(function(callback_name), [indent_info])
|
||||
|
||||
if indent >= 0
|
||||
" Decho "Match: ".callback_name." indent=".indent." info=".string(indent_info)
|
||||
return indent
|
||||
endif
|
||||
endfor
|
||||
|
||||
" }}}2
|
||||
|
||||
" By default, just return the previous line's indent
|
||||
" Decho "Default case matched"
|
||||
return indent(indent_info.plnum)
|
||||
endfunction
|
||||
|
||||
" 3. Indenting Logic Callbacks {{{1
|
||||
" ============================
|
||||
|
||||
function! s:AccessModifier(cline_info) abort
|
||||
let info = a:cline_info
|
||||
|
||||
" If this line is an access modifier keyword, align according to the closest
|
||||
" class declaration.
|
||||
if g:ruby_indent_access_modifier_style == 'indent'
|
||||
if s:Match(info.clnum, s:access_modifier_regex)
|
||||
let class_lnum = s:FindContainingClass()
|
||||
if class_lnum > 0
|
||||
return indent(class_lnum) + info.sw
|
||||
endif
|
||||
endif
|
||||
elseif g:ruby_indent_access_modifier_style == 'outdent'
|
||||
if s:Match(info.clnum, s:access_modifier_regex)
|
||||
let class_lnum = s:FindContainingClass()
|
||||
if class_lnum > 0
|
||||
return indent(class_lnum)
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
|
||||
return -1
|
||||
endfunction
|
||||
|
||||
function! s:ClosingBracketOnEmptyLine(cline_info) abort
|
||||
let info = a:cline_info
|
||||
|
||||
" If we got a closing bracket on an empty line, find its match and indent
|
||||
" according to it. For parentheses we indent to its column - 1, for the
|
||||
" others we indent to the containing line's MSL's level. Return -1 if fail.
|
||||
let col = matchend(info.cline, '^\s*[]})]')
|
||||
|
||||
if col > 0 && !s:IsInStringOrComment(info.clnum, col)
|
||||
call cursor(info.clnum, col)
|
||||
let closing_bracket = info.cline[col - 1]
|
||||
let bracket_pair = strpart('(){}[]', stridx(')}]', closing_bracket) * 2, 2)
|
||||
|
||||
if searchpair(escape(bracket_pair[0], '\['), '', bracket_pair[1], 'bW', s:skip_expr) > 0
|
||||
if closing_bracket == ')' && col('.') != col('$') - 1
|
||||
if g:ruby_indent_hanging_elements
|
||||
let ind = virtcol('.') - 1
|
||||
else
|
||||
let ind = indent(line('.'))
|
||||
end
|
||||
elseif g:ruby_indent_block_style == 'do'
|
||||
let ind = indent(line('.'))
|
||||
else " g:ruby_indent_block_style == 'expression'
|
||||
let ind = indent(s:GetMSL(line('.')))
|
||||
endif
|
||||
endif
|
||||
|
||||
return ind
|
||||
endif
|
||||
|
||||
return -1
|
||||
endfunction
|
||||
|
||||
function! s:BlockComment(cline_info) abort
|
||||
" If we have a =begin or =end set indent to first column.
|
||||
if match(a:cline_info.cline, '^\s*\%(=begin\|=end\)$') != -1
|
||||
return 0
|
||||
endif
|
||||
return -1
|
||||
endfunction
|
||||
|
||||
function! s:DeindentingKeyword(cline_info) abort
|
||||
let info = a:cline_info
|
||||
|
||||
" If we have a deindenting keyword, find its match and indent to its level.
|
||||
" TODO: this is messy
|
||||
if s:Match(info.clnum, s:ruby_deindent_keywords)
|
||||
call cursor(info.clnum, 1)
|
||||
|
||||
if searchpair(s:end_start_regex, s:end_middle_regex, s:end_end_regex, 'bW',
|
||||
\ s:end_skip_expr) > 0
|
||||
let msl = s:GetMSL(line('.'))
|
||||
let line = getline(line('.'))
|
||||
|
||||
if s:IsAssignment(line, col('.')) &&
|
||||
\ strpart(line, col('.') - 1, 2) !~ 'do'
|
||||
" assignment to case/begin/etc, on the same line
|
||||
if g:ruby_indent_assignment_style == 'hanging'
|
||||
" hanging indent
|
||||
let ind = virtcol('.') - 1
|
||||
else
|
||||
" align with variable
|
||||
let ind = indent(line('.'))
|
||||
endif
|
||||
elseif g:ruby_indent_block_style == 'do'
|
||||
" align to line of the "do", not to the MSL
|
||||
let ind = indent(line('.'))
|
||||
elseif getline(msl) =~ '=\s*\(#.*\)\=$'
|
||||
" in the case of assignment to the MSL, align to the starting line,
|
||||
" not to the MSL
|
||||
let ind = indent(line('.'))
|
||||
else
|
||||
" align to the MSL
|
||||
let ind = indent(msl)
|
||||
endif
|
||||
endif
|
||||
return ind
|
||||
endif
|
||||
|
||||
return -1
|
||||
endfunction
|
||||
|
||||
function! s:MultilineStringOrLineComment(cline_info) abort
|
||||
let info = a:cline_info
|
||||
|
||||
" If we are in a multi-line string or line-comment, don't do anything to it.
|
||||
if s:IsInStringOrDocumentation(info.clnum, matchend(info.cline, '^\s*') + 1)
|
||||
return indent(info.clnum)
|
||||
endif
|
||||
return -1
|
||||
endfunction
|
||||
|
||||
function! s:ClosingHeredocDelimiter(cline_info) abort
|
||||
let info = a:cline_info
|
||||
|
||||
" If we are at the closing delimiter of a "<<" heredoc-style string, set the
|
||||
" indent to 0.
|
||||
if info.cline =~ '^\k\+\s*$'
|
||||
\ && s:IsInStringDelimiter(info.clnum, 1)
|
||||
\ && search('\V<<'.info.cline, 'nbW') > 0
|
||||
return 0
|
||||
endif
|
||||
|
||||
return -1
|
||||
endfunction
|
||||
|
||||
function! s:LeadingOperator(cline_info) abort
|
||||
" If the current line starts with a leading operator, add a level of indent.
|
||||
if s:Match(a:cline_info.clnum, s:leading_operator_regex)
|
||||
return indent(s:GetMSL(a:cline_info.clnum)) + a:cline_info.sw
|
||||
endif
|
||||
return -1
|
||||
endfunction
|
||||
|
||||
function! s:EmptyInsideString(pline_info) abort
|
||||
" If the line is empty and inside a string (the previous line is a string,
|
||||
" too), use the previous line's indent
|
||||
let info = a:pline_info
|
||||
|
||||
let plnum = prevnonblank(info.clnum - 1)
|
||||
let pline = getline(plnum)
|
||||
|
||||
if info.cline =~ '^\s*$'
|
||||
\ && s:IsInStringOrComment(plnum, 1)
|
||||
\ && s:IsInStringOrComment(plnum, strlen(pline))
|
||||
return indent(plnum)
|
||||
endif
|
||||
return -1
|
||||
endfunction
|
||||
|
||||
function! s:StartOfFile(pline_info) abort
|
||||
" At the start of the file use zero indent.
|
||||
if a:pline_info.plnum == 0
|
||||
return 0
|
||||
endif
|
||||
return -1
|
||||
endfunction
|
||||
|
||||
function! s:AfterAccessModifier(pline_info) abort
|
||||
let info = a:pline_info
|
||||
|
||||
if g:ruby_indent_access_modifier_style == 'indent'
|
||||
" If the previous line was a private/protected keyword, add a
|
||||
" level of indent.
|
||||
if s:Match(info.plnum, s:indent_access_modifier_regex)
|
||||
return indent(info.plnum) + info.sw
|
||||
endif
|
||||
elseif g:ruby_indent_access_modifier_style == 'outdent'
|
||||
" If the previous line was a private/protected/public keyword, add
|
||||
" a level of indent, since the keyword has been out-dented.
|
||||
if s:Match(info.plnum, s:access_modifier_regex)
|
||||
return indent(info.plnum) + info.sw
|
||||
endif
|
||||
endif
|
||||
return -1
|
||||
endfunction
|
||||
|
||||
" Example:
|
||||
"
|
||||
" if foo || bar ||
|
||||
" baz || bing
|
||||
" puts "foo"
|
||||
" end
|
||||
"
|
||||
function! s:ContinuedLine(pline_info) abort
|
||||
let info = a:pline_info
|
||||
|
||||
let col = s:Match(info.plnum, s:ruby_indent_keywords)
|
||||
if s:Match(info.plnum, s:continuable_regex) &&
|
||||
\ s:Match(info.plnum, s:continuation_regex)
|
||||
if col > 0 && s:IsAssignment(info.pline, col)
|
||||
if g:ruby_indent_assignment_style == 'hanging'
|
||||
" hanging indent
|
||||
let ind = col - 1
|
||||
else
|
||||
" align with variable
|
||||
let ind = indent(info.plnum)
|
||||
endif
|
||||
else
|
||||
let ind = indent(s:GetMSL(info.plnum))
|
||||
endif
|
||||
return ind + info.sw + info.sw
|
||||
endif
|
||||
return -1
|
||||
endfunction
|
||||
|
||||
function! s:AfterBlockOpening(pline_info) abort
|
||||
let info = a:pline_info
|
||||
|
||||
" If the previous line ended with a block opening, add a level of indent.
|
||||
if s:Match(info.plnum, s:block_regex)
|
||||
if g:ruby_indent_block_style == 'do'
|
||||
" don't align to the msl, align to the "do"
|
||||
let ind = indent(info.plnum) + info.sw
|
||||
else
|
||||
let plnum_msl = s:GetMSL(info.plnum)
|
||||
|
||||
if getline(plnum_msl) =~ '=\s*\(#.*\)\=$'
|
||||
" in the case of assignment to the msl, align to the starting line,
|
||||
" not to the msl
|
||||
let ind = indent(info.plnum) + info.sw
|
||||
else
|
||||
let ind = indent(plnum_msl) + info.sw
|
||||
endif
|
||||
endif
|
||||
|
||||
return ind
|
||||
endif
|
||||
|
||||
return -1
|
||||
endfunction
|
||||
|
||||
function! s:AfterLeadingOperator(pline_info) abort
|
||||
" If the previous line started with a leading operator, use its MSL's level
|
||||
" of indent
|
||||
if s:Match(a:pline_info.plnum, s:leading_operator_regex)
|
||||
return indent(s:GetMSL(a:pline_info.plnum))
|
||||
endif
|
||||
return -1
|
||||
endfunction
|
||||
|
||||
function! s:AfterHangingSplat(pline_info) abort
|
||||
let info = a:pline_info
|
||||
|
||||
" If the previous line ended with the "*" of a splat, add a level of indent
|
||||
if info.pline =~ s:splat_regex
|
||||
return indent(info.plnum) + info.sw
|
||||
endif
|
||||
return -1
|
||||
endfunction
|
||||
|
||||
function! s:AfterUnbalancedBracket(pline_info) abort
|
||||
let info = a:pline_info
|
||||
|
||||
" If the previous line contained unclosed opening brackets and we are still
|
||||
" in them, find the rightmost one and add indent depending on the bracket
|
||||
" type.
|
||||
"
|
||||
" If it contained hanging closing brackets, find the rightmost one, find its
|
||||
" match and indent according to that.
|
||||
if info.pline =~ '[[({]' || info.pline =~ '[])}]\s*\%(#.*\)\=$'
|
||||
let [opening, closing] = s:ExtraBrackets(info.plnum)
|
||||
|
||||
if opening.pos != -1
|
||||
if !g:ruby_indent_hanging_elements
|
||||
return indent(info.plnum) + info.sw
|
||||
elseif opening.type == '(' && searchpair('(', '', ')', 'bW', s:skip_expr) > 0
|
||||
if col('.') + 1 == col('$')
|
||||
return indent(info.plnum) + info.sw
|
||||
else
|
||||
return virtcol('.')
|
||||
endif
|
||||
else
|
||||
let nonspace = matchend(info.pline, '\S', opening.pos + 1) - 1
|
||||
return nonspace > 0 ? nonspace : indent(info.plnum) + info.sw
|
||||
endif
|
||||
elseif closing.pos != -1
|
||||
call cursor(info.plnum, closing.pos + 1)
|
||||
normal! %
|
||||
|
||||
if strpart(info.pline, closing.pos) =~ '^)\s*='
|
||||
" special case: the closing `) =` of an endless def
|
||||
return indent(s:GetMSL(line('.')))
|
||||
endif
|
||||
|
||||
if s:Match(line('.'), s:ruby_indent_keywords)
|
||||
return indent('.') + info.sw
|
||||
else
|
||||
return indent(s:GetMSL(line('.')))
|
||||
endif
|
||||
else
|
||||
call cursor(info.clnum, info.col)
|
||||
end
|
||||
endif
|
||||
|
||||
return -1
|
||||
endfunction
|
||||
|
||||
function! s:AfterEndKeyword(pline_info) abort
|
||||
let info = a:pline_info
|
||||
" If the previous line ended with an "end", match that "end"s beginning's
|
||||
" indent.
|
||||
let col = s:Match(info.plnum, '\%(^\|[^.:@$]\)\<end\>\s*\%(#.*\)\=$')
|
||||
if col > 0
|
||||
call cursor(info.plnum, col)
|
||||
if searchpair(s:end_start_regex, '', s:end_end_regex, 'bW',
|
||||
\ s:end_skip_expr) > 0
|
||||
let n = line('.')
|
||||
let ind = indent('.')
|
||||
let msl = s:GetMSL(n)
|
||||
if msl != n
|
||||
let ind = indent(msl)
|
||||
end
|
||||
return ind
|
||||
endif
|
||||
end
|
||||
return -1
|
||||
endfunction
|
||||
|
||||
function! s:AfterIndentKeyword(pline_info) abort
|
||||
let info = a:pline_info
|
||||
let col = s:Match(info.plnum, s:ruby_indent_keywords)
|
||||
|
||||
if col > 0 && s:Match(info.plnum, s:ruby_endless_def) <= 0
|
||||
call cursor(info.plnum, col)
|
||||
let ind = virtcol('.') - 1 + info.sw
|
||||
" TODO: make this better (we need to count them) (or, if a searchpair
|
||||
" fails, we know that something is lacking an end and thus we indent a
|
||||
" level
|
||||
if s:Match(info.plnum, s:end_end_regex)
|
||||
let ind = indent('.')
|
||||
elseif s:IsAssignment(info.pline, col)
|
||||
if g:ruby_indent_assignment_style == 'hanging'
|
||||
" hanging indent
|
||||
let ind = col + info.sw - 1
|
||||
else
|
||||
" align with variable
|
||||
let ind = indent(info.plnum) + info.sw
|
||||
endif
|
||||
endif
|
||||
return ind
|
||||
endif
|
||||
|
||||
return -1
|
||||
endfunction
|
||||
|
||||
function! s:PreviousNotMSL(msl_info) abort
|
||||
let info = a:msl_info
|
||||
|
||||
" If the previous line wasn't a MSL
|
||||
if info.plnum != info.plnum_msl
|
||||
" If previous line ends bracket and begins non-bracket continuation decrease indent by 1.
|
||||
if s:Match(info.plnum, s:bracket_switch_continuation_regex)
|
||||
" TODO (2016-10-07) Wrong/unused? How could it be "1"?
|
||||
return indent(info.plnum) - 1
|
||||
" If previous line is a continuation return its indent.
|
||||
elseif s:Match(info.plnum, s:non_bracket_continuation_regex)
|
||||
return indent(info.plnum)
|
||||
endif
|
||||
endif
|
||||
|
||||
return -1
|
||||
endfunction
|
||||
|
||||
function! s:IndentingKeywordInMSL(msl_info) abort
|
||||
let info = a:msl_info
|
||||
" If the MSL line had an indenting keyword in it, add a level of indent.
|
||||
" TODO: this does not take into account contrived things such as
|
||||
" module Foo; class Bar; end
|
||||
let col = s:Match(info.plnum_msl, s:ruby_indent_keywords)
|
||||
if col > 0 && s:Match(info.plnum_msl, s:ruby_endless_def) <= 0
|
||||
let ind = indent(info.plnum_msl) + info.sw
|
||||
if s:Match(info.plnum_msl, s:end_end_regex)
|
||||
let ind = ind - info.sw
|
||||
elseif s:IsAssignment(getline(info.plnum_msl), col)
|
||||
if g:ruby_indent_assignment_style == 'hanging'
|
||||
" hanging indent
|
||||
let ind = col + info.sw - 1
|
||||
else
|
||||
" align with variable
|
||||
let ind = indent(info.plnum_msl) + info.sw
|
||||
endif
|
||||
endif
|
||||
return ind
|
||||
endif
|
||||
return -1
|
||||
endfunction
|
||||
|
||||
function! s:ContinuedHangingOperator(msl_info) abort
|
||||
let info = a:msl_info
|
||||
|
||||
" If the previous line ended with [*+/.,-=], but wasn't a block ending or a
|
||||
" closing bracket, indent one extra level.
|
||||
if s:Match(info.plnum_msl, s:non_bracket_continuation_regex) && !s:Match(info.plnum_msl, '^\s*\([\])}]\|end\)')
|
||||
if info.plnum_msl == info.plnum
|
||||
let ind = indent(info.plnum_msl) + info.sw
|
||||
else
|
||||
let ind = indent(info.plnum_msl)
|
||||
endif
|
||||
return ind
|
||||
endif
|
||||
|
||||
return -1
|
||||
endfunction
|
||||
|
||||
" 4. Auxiliary Functions {{{1
|
||||
" ======================
|
||||
|
||||
function! s:IsInRubyGroup(groups, lnum, col) abort
|
||||
let ids = map(copy(a:groups), 'hlID("ruby".v:val)')
|
||||
return index(ids, synID(a:lnum, a:col, 1)) >= 0
|
||||
endfunction
|
||||
|
||||
" Check if the character at lnum:col is inside a string, comment, or is ascii.
|
||||
function! s:IsInStringOrComment(lnum, col) abort
|
||||
return s:IsInRubyGroup(s:syng_strcom, a:lnum, a:col)
|
||||
endfunction
|
||||
|
||||
" Check if the character at lnum:col is inside a string.
|
||||
function! s:IsInString(lnum, col) abort
|
||||
return s:IsInRubyGroup(s:syng_string, a:lnum, a:col)
|
||||
endfunction
|
||||
|
||||
" Check if the character at lnum:col is inside a string or documentation.
|
||||
function! s:IsInStringOrDocumentation(lnum, col) abort
|
||||
return s:IsInRubyGroup(s:syng_stringdoc, a:lnum, a:col)
|
||||
endfunction
|
||||
|
||||
" Check if the character at lnum:col is inside a string delimiter
|
||||
function! s:IsInStringDelimiter(lnum, col) abort
|
||||
return s:IsInRubyGroup(
|
||||
\ ['HeredocDelimiter', 'PercentStringDelimiter', 'StringDelimiter'],
|
||||
\ a:lnum, a:col
|
||||
\ )
|
||||
endfunction
|
||||
|
||||
function! s:IsAssignment(str, pos) abort
|
||||
return strpart(a:str, 0, a:pos - 1) =~ '=\s*$'
|
||||
endfunction
|
||||
|
||||
" Find line above 'lnum' that isn't empty, in a comment, or in a string.
|
||||
function! s:PrevNonBlankNonString(lnum) abort
|
||||
let in_block = 0
|
||||
let lnum = prevnonblank(a:lnum)
|
||||
while lnum > 0
|
||||
" 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 =~ '^=begin'
|
||||
if in_block
|
||||
let in_block = 0
|
||||
else
|
||||
break
|
||||
endif
|
||||
elseif !in_block && line =~ '^=end'
|
||||
let in_block = 1
|
||||
elseif !in_block && line !~ '^\s*#.*$' && !(s:IsInStringOrComment(lnum, 1)
|
||||
\ && s:IsInStringOrComment(lnum, strlen(line)))
|
||||
break
|
||||
endif
|
||||
let lnum = prevnonblank(lnum - 1)
|
||||
endwhile
|
||||
return lnum
|
||||
endfunction
|
||||
|
||||
" Find line above 'lnum' that started the continuation 'lnum' may be part of.
|
||||
function! s:GetMSL(lnum) abort
|
||||
" Start on the line we're at and use its indent.
|
||||
let msl = a:lnum
|
||||
let lnum = s:PrevNonBlankNonString(a:lnum - 1)
|
||||
while lnum > 0
|
||||
" If we have a continuation line, or we're in a string, use line as MSL.
|
||||
" Otherwise, terminate search as we have found our MSL already.
|
||||
let line = getline(lnum)
|
||||
|
||||
if !s:Match(msl, s:backslash_continuation_regex) &&
|
||||
\ s:Match(lnum, s:backslash_continuation_regex)
|
||||
" If the current line doesn't end in a backslash, but the previous one
|
||||
" does, look for that line's msl
|
||||
"
|
||||
" Example:
|
||||
" foo = "bar" \
|
||||
" "baz"
|
||||
"
|
||||
let msl = lnum
|
||||
elseif s:Match(msl, s:leading_operator_regex)
|
||||
" If the current line starts with a leading operator, keep its indent
|
||||
" and keep looking for an MSL.
|
||||
let msl = lnum
|
||||
elseif s:Match(lnum, s:splat_regex)
|
||||
" If the above line looks like the "*" of a splat, use the current one's
|
||||
" indentation.
|
||||
"
|
||||
" Example:
|
||||
" Hash[*
|
||||
" method_call do
|
||||
" something
|
||||
"
|
||||
return msl
|
||||
elseif s:Match(lnum, s:non_bracket_continuation_regex) &&
|
||||
\ s:Match(msl, s:non_bracket_continuation_regex)
|
||||
" If the current line is a non-bracket continuation and so is the
|
||||
" previous one, keep its indent and continue looking for an MSL.
|
||||
"
|
||||
" Example:
|
||||
" method_call one,
|
||||
" two,
|
||||
" three
|
||||
"
|
||||
let msl = lnum
|
||||
elseif s:Match(lnum, s:dot_continuation_regex) &&
|
||||
\ (s:Match(msl, s:bracket_continuation_regex) || s:Match(msl, s:block_continuation_regex))
|
||||
" If the current line is a bracket continuation or a block-starter, but
|
||||
" the previous is a dot, keep going to see if the previous line is the
|
||||
" start of another continuation.
|
||||
"
|
||||
" Example:
|
||||
" parent.
|
||||
" method_call {
|
||||
" three
|
||||
"
|
||||
let msl = lnum
|
||||
elseif s:Match(lnum, s:non_bracket_continuation_regex) &&
|
||||
\ (s:Match(msl, s:bracket_continuation_regex) || s:Match(msl, s:block_continuation_regex))
|
||||
" If the current line is a bracket continuation or a block-starter, but
|
||||
" the previous is a non-bracket one, respect the previous' indentation,
|
||||
" and stop here.
|
||||
"
|
||||
" Example:
|
||||
" method_call one,
|
||||
" two {
|
||||
" three
|
||||
"
|
||||
return lnum
|
||||
elseif s:Match(lnum, s:bracket_continuation_regex) &&
|
||||
\ (s:Match(msl, s:bracket_continuation_regex) || s:Match(msl, s:block_continuation_regex))
|
||||
" If both lines are bracket continuations (the current may also be a
|
||||
" block-starter), use the current one's and stop here
|
||||
"
|
||||
" Example:
|
||||
" method_call(
|
||||
" other_method_call(
|
||||
" foo
|
||||
return msl
|
||||
elseif s:Match(lnum, s:block_regex) &&
|
||||
\ !s:Match(msl, s:continuation_regex) &&
|
||||
\ !s:Match(msl, s:block_continuation_regex)
|
||||
" If the previous line is a block-starter and the current one is
|
||||
" mostly ordinary, use the current one as the MSL.
|
||||
"
|
||||
" Example:
|
||||
" method_call do
|
||||
" something
|
||||
" something_else
|
||||
return msl
|
||||
else
|
||||
let col = match(line, s:continuation_regex) + 1
|
||||
if (col > 0 && !s:IsInStringOrComment(lnum, col))
|
||||
\ || s:IsInString(lnum, strlen(line))
|
||||
let msl = lnum
|
||||
else
|
||||
break
|
||||
endif
|
||||
endif
|
||||
|
||||
let lnum = s:PrevNonBlankNonString(lnum - 1)
|
||||
endwhile
|
||||
return msl
|
||||
endfunction
|
||||
|
||||
" Check if line 'lnum' has more opening brackets than closing ones.
|
||||
function! s:ExtraBrackets(lnum) abort
|
||||
let opening = {'parentheses': [], 'braces': [], 'brackets': []}
|
||||
let closing = {'parentheses': [], 'braces': [], 'brackets': []}
|
||||
|
||||
let line = getline(a:lnum)
|
||||
let pos = match(line, '[][(){}]', 0)
|
||||
|
||||
" Save any encountered opening brackets, and remove them once a matching
|
||||
" closing one has been found. If a closing bracket shows up that doesn't
|
||||
" close anything, save it for later.
|
||||
while pos != -1
|
||||
if !s:IsInStringOrComment(a:lnum, pos + 1)
|
||||
if line[pos] == '('
|
||||
call add(opening.parentheses, {'type': '(', 'pos': pos})
|
||||
elseif line[pos] == ')'
|
||||
if empty(opening.parentheses)
|
||||
call add(closing.parentheses, {'type': ')', 'pos': pos})
|
||||
else
|
||||
let opening.parentheses = opening.parentheses[0:-2]
|
||||
endif
|
||||
elseif line[pos] == '{'
|
||||
call add(opening.braces, {'type': '{', 'pos': pos})
|
||||
elseif line[pos] == '}'
|
||||
if empty(opening.braces)
|
||||
call add(closing.braces, {'type': '}', 'pos': pos})
|
||||
else
|
||||
let opening.braces = opening.braces[0:-2]
|
||||
endif
|
||||
elseif line[pos] == '['
|
||||
call add(opening.brackets, {'type': '[', 'pos': pos})
|
||||
elseif line[pos] == ']'
|
||||
if empty(opening.brackets)
|
||||
call add(closing.brackets, {'type': ']', 'pos': pos})
|
||||
else
|
||||
let opening.brackets = opening.brackets[0:-2]
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
|
||||
let pos = match(line, '[][(){}]', pos + 1)
|
||||
endwhile
|
||||
|
||||
" Find the rightmost brackets, since they're the ones that are important in
|
||||
" both opening and closing cases
|
||||
let rightmost_opening = {'type': '(', 'pos': -1}
|
||||
let rightmost_closing = {'type': ')', 'pos': -1}
|
||||
|
||||
for opening in opening.parentheses + opening.braces + opening.brackets
|
||||
if opening.pos > rightmost_opening.pos
|
||||
let rightmost_opening = opening
|
||||
endif
|
||||
endfor
|
||||
|
||||
for closing in closing.parentheses + closing.braces + closing.brackets
|
||||
if closing.pos > rightmost_closing.pos
|
||||
let rightmost_closing = closing
|
||||
endif
|
||||
endfor
|
||||
|
||||
return [rightmost_opening, rightmost_closing]
|
||||
endfunction
|
||||
|
||||
function! s:Match(lnum, regex) abort
|
||||
let line = getline(a:lnum)
|
||||
let offset = match(line, '\C'.a:regex)
|
||||
let col = offset + 1
|
||||
|
||||
while offset > -1 && s:IsInStringOrComment(a:lnum, col)
|
||||
let offset = match(line, '\C'.a:regex, offset + 1)
|
||||
let col = offset + 1
|
||||
endwhile
|
||||
|
||||
if offset > -1
|
||||
return col
|
||||
else
|
||||
return 0
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" Locates the containing class/module's definition line, ignoring nested classes
|
||||
" along the way.
|
||||
"
|
||||
function! s:FindContainingClass() abort
|
||||
let saved_position = getpos('.')
|
||||
|
||||
while searchpair(s:end_start_regex, s:end_middle_regex, s:end_end_regex, 'bW',
|
||||
\ s:end_skip_expr) > 0
|
||||
if expand('<cword>') =~# '\<class\|module\>'
|
||||
let found_lnum = line('.')
|
||||
call setpos('.', saved_position)
|
||||
return found_lnum
|
||||
endif
|
||||
endwhile
|
||||
|
||||
call setpos('.', saved_position)
|
||||
return 0
|
||||
endfunction
|
||||
|
||||
" }}}1
|
||||
|
||||
let &cpo = s:cpo_save
|
||||
unlet s:cpo_save
|
||||
|
||||
" vim:set sw=2 sts=2 ts=8 et:
|
@ -1,24 +0,0 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe "Indenting" do
|
||||
specify "multi-line arguments" do
|
||||
assert_correct_indenting <<~EOF
|
||||
User.new(
|
||||
:first_name => 'Some',
|
||||
:second_name => 'Guy'
|
||||
)
|
||||
EOF
|
||||
|
||||
assert_correct_indenting <<~EOF
|
||||
User.new(:first_name => 'Some',
|
||||
:second_name => 'Guy')
|
||||
EOF
|
||||
|
||||
assert_correct_indenting <<~EOF
|
||||
User.new(
|
||||
:first_name => 'Some',
|
||||
:second_name => 'Guy'
|
||||
)
|
||||
EOF
|
||||
end
|
||||
end
|
@ -1,73 +0,0 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe "Indenting" do
|
||||
specify "if-clauses" do
|
||||
assert_correct_indenting <<~EOF
|
||||
if foo
|
||||
bar
|
||||
end
|
||||
EOF
|
||||
|
||||
assert_correct_indenting <<~EOF
|
||||
if foo
|
||||
bar
|
||||
else
|
||||
baz
|
||||
end
|
||||
EOF
|
||||
|
||||
assert_correct_indenting <<~EOF
|
||||
bar if foo
|
||||
something_else
|
||||
EOF
|
||||
end
|
||||
|
||||
specify "heredocs" do
|
||||
assert_correct_indenting <<~EOF
|
||||
def one
|
||||
two = <<-THREE
|
||||
four
|
||||
THREE
|
||||
end
|
||||
EOF
|
||||
|
||||
assert_correct_indenting <<~EOF
|
||||
def one
|
||||
two = <<THREE
|
||||
four
|
||||
THREE
|
||||
end
|
||||
EOF
|
||||
|
||||
assert_correct_indenting <<~EOF
|
||||
def one
|
||||
two = <<~THREE
|
||||
four
|
||||
THREE
|
||||
end
|
||||
EOF
|
||||
|
||||
# See https://github.com/vim-ruby/vim-ruby/issues/318 for details
|
||||
assert_correct_indenting <<~EOF
|
||||
def foo
|
||||
<<-EOS
|
||||
one
|
||||
\#{two} three
|
||||
four
|
||||
EOS
|
||||
end
|
||||
EOF
|
||||
end
|
||||
|
||||
specify "comments" do
|
||||
assert_correct_indenting <<~EOF
|
||||
def one
|
||||
example do |something|
|
||||
=begin
|
||||
something that is ignored
|
||||
=end
|
||||
end
|
||||
end
|
||||
EOF
|
||||
end
|
||||
end
|
@ -1,164 +0,0 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe "Indenting" do
|
||||
specify "indented blocks with expression style" do
|
||||
vim.command 'let g:ruby_indent_block_style = "expression"'
|
||||
|
||||
assert_correct_indenting <<~EOF
|
||||
a.
|
||||
b.
|
||||
c do |x|
|
||||
something
|
||||
end
|
||||
|
||||
next_line
|
||||
EOF
|
||||
|
||||
assert_correct_indenting <<~EOF
|
||||
a.
|
||||
b.
|
||||
c { |x|
|
||||
something
|
||||
}
|
||||
|
||||
next_line
|
||||
EOF
|
||||
end
|
||||
|
||||
specify "indented blocks with do style" do
|
||||
vim.command 'let g:ruby_indent_block_style = "do"'
|
||||
|
||||
assert_correct_indenting <<~EOF
|
||||
a.
|
||||
b.
|
||||
c do |x|
|
||||
something
|
||||
end
|
||||
|
||||
next_line
|
||||
EOF
|
||||
|
||||
# Check that "do" style indentation does not mess up indentation
|
||||
# following the bock.
|
||||
assert_correct_indenting <<~EOF
|
||||
a.
|
||||
b.
|
||||
c do |x|
|
||||
something
|
||||
end
|
||||
|
||||
next_line
|
||||
EOF
|
||||
|
||||
# Check that "do" style indenting works properly for brace blocks.
|
||||
assert_correct_indenting <<~EOF
|
||||
a.
|
||||
b.
|
||||
c { |x|
|
||||
something
|
||||
}
|
||||
|
||||
next_line
|
||||
EOF
|
||||
end
|
||||
|
||||
specify "'do' indenting" do
|
||||
assert_correct_indenting <<~EOF
|
||||
do
|
||||
something
|
||||
end
|
||||
EOF
|
||||
|
||||
assert_correct_indenting <<~EOF
|
||||
def foo
|
||||
a_hash = {:do => 'bar'}
|
||||
end
|
||||
EOF
|
||||
|
||||
assert_correct_indenting <<~EOF
|
||||
def foo(job)
|
||||
job.do!
|
||||
end
|
||||
EOF
|
||||
end
|
||||
|
||||
specify "blocks with assignment on the previous line" do
|
||||
assert_correct_indenting <<~EOF
|
||||
foo =
|
||||
something do
|
||||
"other"
|
||||
end
|
||||
EOF
|
||||
|
||||
assert_correct_indenting <<~EOF
|
||||
@foo ||=
|
||||
something do
|
||||
"other"
|
||||
end
|
||||
EOF
|
||||
end
|
||||
|
||||
specify "blocks with multiline parameters" do
|
||||
vim.command 'let g:ruby_indent_block_style = "expression"'
|
||||
assert_correct_indenting <<~EOF
|
||||
def foo
|
||||
opts.on('--coordinator host=HOST[,port=PORT]',
|
||||
'Specify the HOST and the PORT of the coordinator') do |str|
|
||||
h = sub_opts_to_hash(str)
|
||||
puts h
|
||||
end
|
||||
end
|
||||
EOF
|
||||
end
|
||||
|
||||
specify "case-insensitive matching" do
|
||||
vim.set 'ignorecase'
|
||||
assert_correct_indenting <<~EOF
|
||||
module X
|
||||
Class.new do
|
||||
end
|
||||
end
|
||||
EOF
|
||||
vim.set 'ignorecase&'
|
||||
end
|
||||
|
||||
specify "blocks with tuple arguments" do
|
||||
assert_correct_indenting <<~EOF
|
||||
proc do |(a, b)|
|
||||
puts a
|
||||
puts b
|
||||
end
|
||||
EOF
|
||||
|
||||
assert_correct_indenting <<~EOF
|
||||
proc do |foo, (a, b), bar|
|
||||
puts a
|
||||
puts b
|
||||
end
|
||||
EOF
|
||||
|
||||
assert_correct_indenting <<~EOF
|
||||
proc do |(a, (b, c)), d|
|
||||
puts a, b
|
||||
puts c, d
|
||||
end
|
||||
EOF
|
||||
end
|
||||
|
||||
specify "blocks with default arguments" do
|
||||
assert_correct_indenting <<~EOF
|
||||
proc do |a = 1|
|
||||
puts a
|
||||
end
|
||||
EOF
|
||||
|
||||
# See https://github.com/vim-ruby/vim-ruby/issues/304
|
||||
assert_correct_indenting <<~EOF
|
||||
proc do |a: "asdf", b:|
|
||||
proc do
|
||||
puts a, b
|
||||
end
|
||||
end
|
||||
EOF
|
||||
end
|
||||
end
|
@ -1,323 +0,0 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe "Indenting" do
|
||||
specify "method chaining" do
|
||||
assert_correct_indenting <<~EOF
|
||||
some_object.
|
||||
method_one.
|
||||
method_two.
|
||||
method_three
|
||||
EOF
|
||||
|
||||
assert_correct_indenting <<~EOF
|
||||
some_object
|
||||
.method_one
|
||||
.method_two
|
||||
.method_three
|
||||
EOF
|
||||
|
||||
assert_correct_indenting <<~EOF
|
||||
some_object&.
|
||||
method_one&.
|
||||
method_two&.
|
||||
method_three
|
||||
EOF
|
||||
|
||||
assert_correct_indenting <<~EOF
|
||||
some_object
|
||||
&.method_one
|
||||
&.method_two
|
||||
&.method_three
|
||||
EOF
|
||||
end
|
||||
|
||||
specify "arrays" do
|
||||
assert_correct_indenting <<~EOF
|
||||
foo = [one,
|
||||
two,
|
||||
three]
|
||||
EOF
|
||||
end
|
||||
|
||||
specify "tricky string interpolation" do
|
||||
# See https://github.com/vim-ruby/vim-ruby/issues/75 for details
|
||||
assert_correct_indenting <<~EOF
|
||||
puts %{\#{}}
|
||||
puts "OK"
|
||||
EOF
|
||||
|
||||
assert_correct_indenting <<~EOF
|
||||
while true
|
||||
begin
|
||||
puts %{\#{x}}
|
||||
rescue ArgumentError
|
||||
end
|
||||
end
|
||||
EOF
|
||||
end
|
||||
|
||||
specify "continuations after round braces" do
|
||||
vim.command 'let g:ruby_indent_block_style = "expression"'
|
||||
assert_correct_indenting <<~EOF
|
||||
opts.on('--coordinator host=HOST[,port=PORT]',
|
||||
'Specify the HOST and the PORT of the coordinator') do |str|
|
||||
h = sub_opts_to_hash(str)
|
||||
puts h
|
||||
end
|
||||
EOF
|
||||
end
|
||||
|
||||
describe "assignments" do
|
||||
specify "continuations after assignment" do
|
||||
assert_correct_indenting <<~EOF
|
||||
variable =
|
||||
if condition?
|
||||
1
|
||||
else
|
||||
2
|
||||
end
|
||||
EOF
|
||||
|
||||
assert_correct_indenting <<~EOF
|
||||
variable = # evil comment
|
||||
case something
|
||||
when 'something'
|
||||
something_else
|
||||
else
|
||||
other
|
||||
end
|
||||
EOF
|
||||
|
||||
assert_correct_indenting <<~EOF
|
||||
variable = case something
|
||||
when 'something'
|
||||
something_else
|
||||
else
|
||||
other
|
||||
end
|
||||
EOF
|
||||
|
||||
assert_correct_indenting <<~EOF
|
||||
variable = if something == something_else
|
||||
something_else
|
||||
elsif other == none
|
||||
none
|
||||
else
|
||||
other
|
||||
end
|
||||
EOF
|
||||
|
||||
assert_correct_indenting <<~EOF
|
||||
variable = while
|
||||
break something
|
||||
end
|
||||
EOF
|
||||
|
||||
assert_correct_indenting <<~EOF
|
||||
variable = if [].
|
||||
map { |x| x * 2 }.
|
||||
filter { |x| x % 3 == 0 }.
|
||||
empty?
|
||||
something
|
||||
end
|
||||
EOF
|
||||
|
||||
vim.command 'let g:ruby_indent_assignment_style = "variable"'
|
||||
|
||||
assert_correct_indenting <<~EOF
|
||||
variable = case something # evil comment
|
||||
when 'something'
|
||||
something_else
|
||||
else
|
||||
other
|
||||
end
|
||||
EOF
|
||||
|
||||
assert_correct_indenting <<~EOF
|
||||
variable = if something == something_else
|
||||
something_else
|
||||
elsif other == none
|
||||
none
|
||||
else
|
||||
other
|
||||
end
|
||||
EOF
|
||||
|
||||
assert_correct_indenting <<~EOF
|
||||
variable = while
|
||||
break something
|
||||
end
|
||||
EOF
|
||||
|
||||
assert_correct_indenting <<~EOF
|
||||
variable = if [].
|
||||
map { |x| x * 2 }.
|
||||
filter { |x| x % 3 == 0 }.
|
||||
empty?
|
||||
something
|
||||
end
|
||||
EOF
|
||||
end
|
||||
end
|
||||
|
||||
specify "continuations after hanging comma" do
|
||||
assert_correct_indenting <<~EOF
|
||||
array = [
|
||||
:one,
|
||||
].each do |x|
|
||||
puts x.to_s
|
||||
end
|
||||
EOF
|
||||
end
|
||||
|
||||
specify "string interpolation" do
|
||||
# For details, see:
|
||||
#
|
||||
# https://github.com/vim-ruby/vim-ruby/issues/93
|
||||
# https://github.com/vim-ruby/vim-ruby/issues/160
|
||||
#
|
||||
assert_correct_indenting <<~EOF
|
||||
command = %|\#{file}|
|
||||
settings.log.info("Returning: \#{command}")
|
||||
EOF
|
||||
|
||||
assert_correct_indenting <<~EOF
|
||||
{
|
||||
thing: "[\#{}]",
|
||||
thong: "b"
|
||||
}
|
||||
EOF
|
||||
|
||||
assert_correct_indenting <<~EOF
|
||||
{
|
||||
a: "(\#{a})",
|
||||
b: "(\#{b})",
|
||||
c: "(c)",
|
||||
d: "(d)",
|
||||
e: "(e)",
|
||||
}
|
||||
EOF
|
||||
end
|
||||
|
||||
specify "closing bracket not on its own line" do
|
||||
# See https://github.com/vim-ruby/vim-ruby/issues/81 for details
|
||||
assert_correct_indenting <<~EOF
|
||||
one { two >>
|
||||
three }
|
||||
four
|
||||
EOF
|
||||
end
|
||||
|
||||
specify "lonesome single parenthesis in a method definition" do
|
||||
# See https://github.com/vim-ruby/vim-ruby/issues/130 for details
|
||||
assert_correct_indenting <<~EOF
|
||||
def bar(
|
||||
baz
|
||||
)
|
||||
return baz+1
|
||||
end
|
||||
EOF
|
||||
end
|
||||
|
||||
specify "brackets on their own line, followed by a comma" do
|
||||
# See https://github.com/vim-ruby/vim-ruby/issues/124 for details
|
||||
assert_correct_indenting <<~EOF
|
||||
bla = {
|
||||
:one => [
|
||||
{:bla => :blub}
|
||||
],
|
||||
:two => (
|
||||
{:blub => :abc}
|
||||
),
|
||||
:three => {
|
||||
:blub => :abc
|
||||
},
|
||||
:four => 'five'
|
||||
}
|
||||
EOF
|
||||
end
|
||||
|
||||
specify "string with an and#" do
|
||||
# See https://github.com/vim-ruby/vim-ruby/issues/108 for details
|
||||
assert_correct_indenting <<~EOF
|
||||
outside_block "and#" do
|
||||
inside_block do
|
||||
end
|
||||
end
|
||||
EOF
|
||||
end
|
||||
|
||||
specify "continuation with a symbol at the end" do
|
||||
# See https://github.com/vim-ruby/vim-ruby/issues/132 for details
|
||||
assert_correct_indenting <<~EOF
|
||||
foo = :+
|
||||
# Next indents correctly
|
||||
EOF
|
||||
end
|
||||
|
||||
specify "continuation with a hanging comma" do
|
||||
# See https://github.com/vim-ruby/vim-ruby/issues/139 for details
|
||||
assert_correct_indenting <<~EOF
|
||||
thing :foo
|
||||
thing 'a',
|
||||
'b'
|
||||
EOF
|
||||
end
|
||||
|
||||
specify "continuations in an if-clause condition" do
|
||||
# See https://github.com/vim-ruby/vim-ruby/issues/215 for details
|
||||
assert_correct_indenting <<~EOF
|
||||
if foo || bar ||
|
||||
bong &&
|
||||
baz || bing
|
||||
puts "foo"
|
||||
end
|
||||
EOF
|
||||
end
|
||||
|
||||
specify "continuations with round brackets" do
|
||||
# See https://github.com/vim-ruby/vim-ruby/issues/17 for details
|
||||
assert_correct_indenting <<~EOF
|
||||
foo and
|
||||
(bar and
|
||||
baz) and
|
||||
bing
|
||||
EOF
|
||||
end
|
||||
|
||||
specify "block within an argument list" do
|
||||
# See https://github.com/vim-ruby/vim-ruby/issues/312 for details
|
||||
assert_correct_indenting <<~EOF
|
||||
foo(
|
||||
x: 1,
|
||||
y: [1, 2, 3].map { |i|
|
||||
i + 1
|
||||
}
|
||||
)
|
||||
EOF
|
||||
end
|
||||
|
||||
specify "backslashes" do
|
||||
# See https://github.com/vim-ruby/vim-ruby/issues/311 for details
|
||||
assert_correct_indenting <<~EOF
|
||||
def foo
|
||||
x = 1
|
||||
|
||||
string = ". \#{x}" \\
|
||||
"xyz"
|
||||
|
||||
puts string
|
||||
puts string
|
||||
end
|
||||
EOF
|
||||
end
|
||||
|
||||
specify "wrong continuation within regex character class" do
|
||||
# See https://github.com/vim-ruby/vim-ruby/issues/405 for details
|
||||
|
||||
assert_correct_indenting <<~EOF
|
||||
extname = file.extname(url).split(/[?#]/).first
|
||||
target_file = tempfile.new()
|
||||
EOF
|
||||
end
|
||||
end
|
@ -1,46 +0,0 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe "Indenting" do
|
||||
specify "end constructs" do
|
||||
assert_correct_indenting <<~EOF
|
||||
f do
|
||||
g { def h; end }
|
||||
end
|
||||
EOF
|
||||
|
||||
assert_correct_indenting <<~EOF
|
||||
if foo
|
||||
bar ; end
|
||||
something_else
|
||||
EOF
|
||||
|
||||
assert_correct_indenting <<~EOF
|
||||
if bar ; end
|
||||
something_else
|
||||
EOF
|
||||
|
||||
assert_correct_indenting <<~EOF
|
||||
foo do
|
||||
foo = 3 . class
|
||||
foo = lambda { class One; end }
|
||||
foo = lambda { |args| class One; end }
|
||||
foo = bar; class One; end
|
||||
end
|
||||
EOF
|
||||
|
||||
assert_correct_indenting <<~EOF
|
||||
nested do
|
||||
while true do
|
||||
def foo
|
||||
if bar
|
||||
for i in collection
|
||||
def baz
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
EOF
|
||||
end
|
||||
end
|
@ -1,18 +0,0 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe "Indenting" do
|
||||
specify "closing html tag after multiline eruby tag" do
|
||||
assert_correct_indenting 'erb', <<~EOF
|
||||
<form>
|
||||
<div>
|
||||
<%= text_field_tag :email, nil,
|
||||
placeholder: "email" %>
|
||||
text
|
||||
<%= text_field_tag :password, nil,
|
||||
placeholder: "password" %>
|
||||
</div>
|
||||
</form>
|
||||
EOF
|
||||
end
|
||||
end
|
||||
|
@ -1,78 +0,0 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe 'Indenting' do
|
||||
|
||||
specify 'method args' do
|
||||
assert_correct_indenting <<~EOF
|
||||
render('product/show',
|
||||
product: product,
|
||||
on_sale: true,
|
||||
)
|
||||
EOF
|
||||
|
||||
vim.command 'let g:ruby_indent_hanging_elements = 0'
|
||||
|
||||
assert_correct_indenting <<~EOF
|
||||
render('product/show',
|
||||
product: product,
|
||||
on_sale: true,
|
||||
)
|
||||
EOF
|
||||
end
|
||||
|
||||
specify 'method args with block' do
|
||||
assert_correct_indenting <<~EOF
|
||||
opts.on('--coordinator host=HOST[,port=PORT]',
|
||||
'Specify the HOST and the PORT of the coordinator') do |str|
|
||||
h = sub_opts_to_hash(str)
|
||||
puts h
|
||||
end
|
||||
EOF
|
||||
|
||||
vim.command 'let g:ruby_indent_hanging_elements = 0'
|
||||
|
||||
assert_correct_indenting <<~EOF
|
||||
opts.on('--coordinator host=HOST[,port=PORT]',
|
||||
'Specify the HOST and the PORT of the coordinator') do |str|
|
||||
h = sub_opts_to_hash(str)
|
||||
puts h
|
||||
end
|
||||
EOF
|
||||
end
|
||||
|
||||
specify 'arrays' do
|
||||
assert_correct_indenting <<~EOF
|
||||
x = [1,
|
||||
2,
|
||||
3,
|
||||
]
|
||||
EOF
|
||||
|
||||
vim.command 'let g:ruby_indent_hanging_elements = 0'
|
||||
|
||||
assert_correct_indenting <<~EOF
|
||||
x = [1,
|
||||
2,
|
||||
3,
|
||||
]
|
||||
EOF
|
||||
end
|
||||
|
||||
specify 'hashes' do
|
||||
assert_correct_indenting <<~EOF
|
||||
x = { a: 1,
|
||||
b: 2,
|
||||
c: 3,
|
||||
}
|
||||
EOF
|
||||
|
||||
vim.command 'let g:ruby_indent_hanging_elements = 0'
|
||||
|
||||
assert_correct_indenting <<~EOF
|
||||
x = { a: 1,
|
||||
b: 2,
|
||||
c: 3,
|
||||
}
|
||||
EOF
|
||||
end
|
||||
end
|
@ -1,10 +0,0 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe "Indenting" do
|
||||
specify "identifiers containing keyword substrings" do
|
||||
assert_correct_indenting <<~EOF
|
||||
foo_def
|
||||
42
|
||||
EOF
|
||||
end
|
||||
end
|
@ -1,133 +0,0 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe "Indenting" do
|
||||
specify "default indented access modifiers" do
|
||||
assert_correct_indenting <<~EOF
|
||||
class OuterClass
|
||||
|
||||
private :method
|
||||
protected :method
|
||||
def method; end
|
||||
protected
|
||||
def method; end
|
||||
private
|
||||
def method; end
|
||||
public
|
||||
def method; end
|
||||
|
||||
class InnerClass
|
||||
|
||||
private :method
|
||||
protected :method
|
||||
def method; end
|
||||
protected
|
||||
def method; end
|
||||
private
|
||||
def method; end
|
||||
public
|
||||
def method; end
|
||||
|
||||
end
|
||||
|
||||
private :method
|
||||
protected :method
|
||||
def method; end
|
||||
protected
|
||||
def method; end
|
||||
private
|
||||
def method; end
|
||||
public
|
||||
def method; end
|
||||
|
||||
end
|
||||
EOF
|
||||
end
|
||||
|
||||
specify "indented access modifiers" do
|
||||
vim.command 'let g:ruby_indent_access_modifier_style = "indent"'
|
||||
|
||||
assert_correct_indenting <<~EOF
|
||||
class OuterClass
|
||||
|
||||
private :method
|
||||
protected :method
|
||||
def method; end
|
||||
protected
|
||||
def method; end
|
||||
private
|
||||
def method; end
|
||||
public
|
||||
def method; end
|
||||
|
||||
class InnerClass
|
||||
|
||||
private :method
|
||||
protected :method
|
||||
def method; end
|
||||
protected
|
||||
def method; end
|
||||
private
|
||||
def method; end
|
||||
public
|
||||
def method; end
|
||||
|
||||
end
|
||||
|
||||
private :method
|
||||
protected :method
|
||||
def method; end
|
||||
protected
|
||||
def method; end
|
||||
private
|
||||
def method; end
|
||||
public
|
||||
def method; end
|
||||
|
||||
end
|
||||
EOF
|
||||
end
|
||||
|
||||
specify "outdented access modifiers" do
|
||||
vim.command 'let g:ruby_indent_access_modifier_style = "outdent"'
|
||||
|
||||
assert_correct_indenting <<~EOF
|
||||
class OuterClass
|
||||
|
||||
private :method
|
||||
protected :method
|
||||
def method; end
|
||||
protected
|
||||
def method; end
|
||||
private
|
||||
def method; end
|
||||
public
|
||||
def method; end
|
||||
|
||||
class InnerClass
|
||||
|
||||
private :method
|
||||
protected :method
|
||||
def method; end
|
||||
protected
|
||||
def method; end
|
||||
private
|
||||
def method; end
|
||||
public
|
||||
def method; end
|
||||
|
||||
end
|
||||
|
||||
private :method
|
||||
protected :method
|
||||
def method; end
|
||||
protected
|
||||
def method; end
|
||||
private
|
||||
def method; end
|
||||
public
|
||||
def method; end
|
||||
|
||||
end
|
||||
EOF
|
||||
end
|
||||
end
|
@ -1,76 +0,0 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe "Indenting" do
|
||||
specify "method definitions prefixed with access modifiers" do
|
||||
assert_correct_indenting <<~EOF
|
||||
class Foo
|
||||
public def one(x)
|
||||
end
|
||||
|
||||
private def two(y)
|
||||
code
|
||||
end
|
||||
end
|
||||
EOF
|
||||
end
|
||||
|
||||
specify "method definitions prefixed with any method call" do
|
||||
assert_correct_indenting <<~EOF
|
||||
class Foo
|
||||
foobar def one(x)
|
||||
end
|
||||
foobar? def one(x)
|
||||
end
|
||||
foobar! def one(x)
|
||||
end
|
||||
|
||||
фубар def one(x)
|
||||
end
|
||||
|
||||
foobar
|
||||
def one(x)
|
||||
end
|
||||
|
||||
FooBar1 def two(y)
|
||||
code
|
||||
end
|
||||
end
|
||||
EOF
|
||||
end
|
||||
|
||||
specify "endless methods" do
|
||||
# Note: A case that doesn't work at this time:
|
||||
#
|
||||
# def foo()
|
||||
# = 42
|
||||
#
|
||||
assert_correct_indenting <<~EOF
|
||||
indented_block do
|
||||
def foo(bar) = puts(bar)
|
||||
def foo!(bar) = puts(bar)
|
||||
def foo?(bar) = puts(bar)
|
||||
|
||||
def foo(bar)=puts(bar)
|
||||
|
||||
def foo(bar) = bar + 1
|
||||
|
||||
def foo() = 1 + 1
|
||||
def foo = 1 + 1
|
||||
|
||||
private def foo(bar) = bar + 1
|
||||
|
||||
def foo(bar) =
|
||||
bar + 1
|
||||
|
||||
def foo(bar = default_function()) = puts(bar)
|
||||
|
||||
def foo(bar = default_function()) =
|
||||
puts(bar)
|
||||
|
||||
def foo(
|
||||
bar
|
||||
) = puts(bar)
|
||||
end
|
||||
EOF
|
||||
end
|
||||
end
|
@ -1,69 +0,0 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe "Indenting" do
|
||||
specify "nested blocks" do
|
||||
assert_correct_indenting <<~EOF
|
||||
var.func1(:param => 'value') do
|
||||
var.func2(:param => 'value') do
|
||||
puts "test"
|
||||
end
|
||||
end
|
||||
EOF
|
||||
|
||||
assert_correct_indenting <<~EOF
|
||||
var.func1(:param => 'value') {
|
||||
var.func2(:param => 'value') {
|
||||
foo({ bar => baz })
|
||||
puts "test one"
|
||||
puts "test two"
|
||||
}
|
||||
}
|
||||
EOF
|
||||
|
||||
vim.command 'let g:ruby_indent_block_style = "expression"'
|
||||
assert_correct_indenting <<~EOF
|
||||
var.
|
||||
func1(:param => 'value') {
|
||||
var.func2(:param => 'value') {
|
||||
puts "test"
|
||||
}
|
||||
}
|
||||
EOF
|
||||
end
|
||||
|
||||
specify "nested hashes" do
|
||||
assert_correct_indenting <<~EOF
|
||||
foo, bar = {
|
||||
:bar => {
|
||||
:one => 'two',
|
||||
:five => 'six'
|
||||
}
|
||||
}
|
||||
EOF
|
||||
|
||||
vim.command 'let g:ruby_indent_block_style = "expression"'
|
||||
assert_correct_indenting <<~EOF
|
||||
foo,
|
||||
bar = {
|
||||
:bar => {
|
||||
:foo => { 'bar' => 'baz' },
|
||||
:one => 'two',
|
||||
:three => 'four'
|
||||
}
|
||||
}
|
||||
EOF
|
||||
end
|
||||
|
||||
specify "nested blocks with a continuation and function call inbetween" do
|
||||
vim.command 'let g:ruby_indent_block_style = "expression"'
|
||||
assert_correct_indenting <<~EOF
|
||||
var.
|
||||
func1(:param => 'value') {
|
||||
func1_5(:param => 'value')
|
||||
var.func2(:param => 'value') {
|
||||
puts "test"
|
||||
}
|
||||
}
|
||||
EOF
|
||||
end
|
||||
end
|
@ -1,47 +0,0 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe "Indenting" do
|
||||
specify "splats with blocks in square brackets" do
|
||||
assert_correct_indenting <<~EOF
|
||||
x = Foo[*
|
||||
y do
|
||||
z
|
||||
end
|
||||
]
|
||||
EOF
|
||||
|
||||
assert_correct_indenting <<~EOF
|
||||
x = Foo[* # with a comment
|
||||
y do
|
||||
z
|
||||
end
|
||||
]
|
||||
EOF
|
||||
end
|
||||
|
||||
specify "splats with blocks in assignment" do
|
||||
vim.command 'let g:ruby_indent_block_style = "expression"'
|
||||
assert_correct_indenting <<~EOF
|
||||
x = *
|
||||
array.map do
|
||||
3
|
||||
end
|
||||
EOF
|
||||
end
|
||||
|
||||
specify "splats with blocks in round brackets" do
|
||||
assert_correct_indenting <<~EOF
|
||||
x = Foo(*y do
|
||||
z
|
||||
end)
|
||||
EOF
|
||||
|
||||
assert_correct_indenting <<~EOF
|
||||
x = Foo(
|
||||
*y do
|
||||
z
|
||||
end
|
||||
)
|
||||
EOF
|
||||
end
|
||||
end
|
@ -1,50 +0,0 @@
|
||||
require 'vimrunner'
|
||||
require 'vimrunner/rspec'
|
||||
|
||||
RSpec.configure do |config|
|
||||
# reset globals to default values before each test
|
||||
config.before(:each) do
|
||||
vim.command 'let g:ruby_indent_access_modifier_style = "normal"'
|
||||
vim.command 'let g:ruby_indent_block_style = "do"'
|
||||
vim.command 'let g:ruby_indent_assignment_style = "hanging"'
|
||||
vim.command 'let g:ruby_indent_hanging_elements = 1'
|
||||
end
|
||||
end
|
||||
|
||||
Vimrunner::RSpec.configure do |config|
|
||||
config.reuse_server = true
|
||||
|
||||
config.start_vim do
|
||||
vim = Vimrunner.start_gvim
|
||||
vim.prepend_runtimepath(File.expand_path('../..', __FILE__))
|
||||
vim.add_plugin(File.expand_path('../vim', __FILE__), 'plugin/syntax_test.vim')
|
||||
vim.set 'expandtab'
|
||||
vim.set 'shiftwidth', 2
|
||||
vim
|
||||
end
|
||||
|
||||
def assert_correct_indenting(extension='rb', string)
|
||||
filename = "test.#{extension}"
|
||||
|
||||
IO.write filename, string
|
||||
|
||||
vim.edit filename
|
||||
vim.normal 'gg=G'
|
||||
vim.write
|
||||
|
||||
expect(IO.read(filename)).to eq string
|
||||
end
|
||||
|
||||
def assert_correct_highlighting(extension='rb', string, patterns, group)
|
||||
filename = "test.#{extension}"
|
||||
|
||||
IO.write filename, string
|
||||
|
||||
vim.edit filename
|
||||
|
||||
Array(patterns).each do |pattern|
|
||||
# TODO: add a custom matcher
|
||||
expect(vim.echo("TestSyntax('#{pattern}', '#{group}')")).to eq '1'
|
||||
end
|
||||
end
|
||||
end
|
@ -1,17 +0,0 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe "Syntax highlighting" do
|
||||
specify "block parameters" do
|
||||
assert_correct_highlighting <<~'EOF', 'bar', 'rubySymbol'
|
||||
foo { |bar:| 42 }
|
||||
EOF
|
||||
assert_correct_highlighting <<~'EOF', %w[bar\ze: baz\ze:], 'rubySymbol'
|
||||
foo { |bar: 'bar', baz: 'baz'| 42 }
|
||||
EOF
|
||||
end
|
||||
specify "block parameters with default values including '|'" do
|
||||
assert_correct_highlighting <<~'EOF', %w[|\zebar qux)\zs|], 'rubyBlockParameterList'
|
||||
foo { |bar=(baz|qux)| 42 }
|
||||
EOF
|
||||
end
|
||||
end
|
Binary file not shown.
@ -1,60 +0,0 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe "Syntax highlighting" do
|
||||
specify "single line comments" do
|
||||
assert_correct_highlighting <<~'EOF', '#.*', 'rubyComment'
|
||||
# comment line
|
||||
EOF
|
||||
end
|
||||
|
||||
specify "end of line comments" do
|
||||
assert_correct_highlighting <<~'EOF', '#.*', 'rubyComment'
|
||||
foo = 42 # comment
|
||||
EOF
|
||||
end
|
||||
|
||||
specify "multiline comments" do
|
||||
assert_correct_highlighting <<~'EOF', ['#.*line 1', '#.*line 2'], 'rubyComment'
|
||||
# comment line 1
|
||||
# comment line 2
|
||||
EOF
|
||||
end
|
||||
|
||||
specify "embedded documentation" do
|
||||
assert_correct_highlighting <<~'EOF', 'documentation.*', 'rubyDocumentation'
|
||||
=begin
|
||||
documentation line
|
||||
=end
|
||||
EOF
|
||||
# See issue #3
|
||||
assert_correct_highlighting <<~'EOF', 'documentation.*', 'rubyDocumentation'
|
||||
=begin rdoc
|
||||
documentation line
|
||||
=end rdoc
|
||||
EOF
|
||||
end
|
||||
|
||||
specify "magic comments" do
|
||||
assert_correct_highlighting <<~'EOF', 'frozen_string_literal', 'rubyMagicComment'
|
||||
# frozen_string_literal: true
|
||||
EOF
|
||||
end
|
||||
|
||||
specify "magic comments - shareable_constant_value" do
|
||||
assert_correct_highlighting <<~'EOF', 'shareable_constant_value', 'rubyMagicComment'
|
||||
# shareable_constant_value: literal
|
||||
EOF
|
||||
end
|
||||
|
||||
specify "TODO comments" do
|
||||
assert_correct_highlighting <<~'EOF', 'TODO', 'rubyTodo'
|
||||
# TODO: turn off the oven
|
||||
EOF
|
||||
end
|
||||
|
||||
specify "shebang comments" do
|
||||
assert_correct_highlighting <<~'EOF', '#.*', 'rubySharpBang'
|
||||
#!/bin/ruby
|
||||
EOF
|
||||
end
|
||||
end
|
@ -1,23 +0,0 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe "Syntax highlighting" do
|
||||
specify "useless line continuations" do
|
||||
str = <<~'EOF'
|
||||
foo = \
|
||||
if true
|
||||
42
|
||||
end
|
||||
EOF
|
||||
assert_correct_highlighting str, '\\', 'rubyUselessLineContinuation'
|
||||
assert_correct_highlighting str, 'if', 'rubyConditional'
|
||||
end
|
||||
|
||||
specify "line continuations" do
|
||||
str = <<~'EOF'
|
||||
foo = 42 \
|
||||
if true
|
||||
EOF
|
||||
assert_correct_highlighting str, '\\', 'rubyLineContinuation'
|
||||
assert_correct_highlighting str, 'if', 'rubyConditionalModifier'
|
||||
end
|
||||
end
|
@ -1,12 +0,0 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe "Maxmempattern limit" do
|
||||
specify "maxmempattern=1000 is enough even for long strings" do
|
||||
str = <<~'EOF'
|
||||
hash = {
|
||||
"A-NOT-Managed-Strings" => "ABCDEfghe910dmckamks019292djdjOOOjjjd/cr3wdCA+1n/xHfHMgG+cC0EoUNngcBjgWvBMEF1CurBwTtDswJjQYa5wYRAQEBAQECCwGwAQEvI50CnwMNAwRrAQYBr9PPAoK7sQMBAQMCBAkICAQIAwEBAwYBAQQFFQEBAhQDAwMDCwEBAQUBAQHGAQEWBAEBDecBfS8CHQEKkAEMMxcMCQoUDwYHIjd3DQ4MFk0JWGYALSKLAQOLAYEBFBAjCBGDAQICAgMANjsZAg9fCxkCgLZKAwSEAQIBiwEZGAsrBCgFMmUEJShyFSfRBQEOSQY62AG0AVlCrQ",
|
||||
}
|
||||
EOF
|
||||
assert_correct_highlighting str, %w[ABCDE], 'rubyString'
|
||||
end
|
||||
end
|
@ -1,36 +0,0 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe "Syntax highlighting" do
|
||||
specify "method definitions" do
|
||||
str = <<~'EOF'
|
||||
def foo bar
|
||||
end
|
||||
EOF
|
||||
assert_correct_highlighting str, %w[def end], 'rubyDefine'
|
||||
assert_correct_highlighting str, 'foo', 'rubyMethodName'
|
||||
end
|
||||
|
||||
specify "method definitions named 'end'" do
|
||||
assert_correct_highlighting <<~'EOF', 'end', 'rubyMethodName'
|
||||
def end end
|
||||
EOF
|
||||
assert_correct_highlighting <<~'EOF', 'end', 'rubyMethodName'
|
||||
def
|
||||
end
|
||||
end
|
||||
EOF
|
||||
end
|
||||
|
||||
specify "method parameters with symbol default values" do
|
||||
assert_correct_highlighting <<~'EOF', ':baz', 'rubySymbol'
|
||||
def foo bar=:baz
|
||||
end
|
||||
EOF
|
||||
end
|
||||
|
||||
specify "unparenthesised method parameters with a required trailing keyword then semicolon" do
|
||||
assert_correct_highlighting <<~'EOF', 'bar', 'rubySymbol'
|
||||
def foo bar:; end
|
||||
EOF
|
||||
end
|
||||
end
|
@ -1,204 +0,0 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe "Syntax highlighting" do
|
||||
before :each do
|
||||
vim.command 'let g:ruby_operators = 1'
|
||||
end
|
||||
after :each do
|
||||
vim.command 'unlet g:ruby_operators'
|
||||
end
|
||||
|
||||
specify "defined? operator" do
|
||||
assert_correct_highlighting 'defined? foo', 'defined?', 'rubyDefinedOperator'
|
||||
end
|
||||
|
||||
specify "English boolean operators" do
|
||||
assert_correct_highlighting <<~'EOF', %w[not and or], 'rubyEnglishBooleanOperator'
|
||||
not true
|
||||
true and false
|
||||
true or false
|
||||
EOF
|
||||
end
|
||||
|
||||
specify "modulo-assignment operators" do
|
||||
assert_correct_highlighting <<~'EOF', '%=', 'rubyAssignmentOperator'
|
||||
foo %= bar
|
||||
EOF
|
||||
end
|
||||
|
||||
specify "ternary operators" do
|
||||
assert_correct_highlighting <<~'EOF', %w[? :], 'rubyTernaryOperator'
|
||||
foo = bar ? 4 : 2
|
||||
EOF
|
||||
end
|
||||
|
||||
context "bracket operators" do
|
||||
specify "after a plain identifier" do
|
||||
assert_correct_highlighting <<~'EOF', '\\[..]', 'rubyOperator'
|
||||
foo[42]
|
||||
EOF
|
||||
end
|
||||
specify "after a ?!-named bare method call" do
|
||||
assert_correct_highlighting <<~'EOF', '\\[..]', 'rubyOperator'
|
||||
foo?[42]
|
||||
EOF
|
||||
end
|
||||
specify "after a closing parenthesis" do
|
||||
assert_correct_highlighting <<~'EOF', '\\[..]', 'rubyOperator'
|
||||
(foo)[42]
|
||||
EOF
|
||||
end
|
||||
specify "after a literal hash" do
|
||||
assert_correct_highlighting <<~'EOF', '\\[...]', 'rubyOperator'
|
||||
{ foo: bar }[foo]
|
||||
EOF
|
||||
end
|
||||
specify "after a block arg method call" do
|
||||
assert_correct_highlighting <<~'EOF', '\\[..]', 'rubyOperator'
|
||||
foo { bar }[42]
|
||||
EOF
|
||||
end
|
||||
end
|
||||
|
||||
specify "exponentiation operators" do
|
||||
[
|
||||
'foo**bar',
|
||||
'foo ** bar',
|
||||
'foo** bar',
|
||||
].each do |str|
|
||||
assert_correct_highlighting str, '\*\*', 'rubyArithmeticOperator'
|
||||
end
|
||||
end
|
||||
|
||||
context "double splat operators" do
|
||||
specify "in method definitions" do
|
||||
assert_correct_highlighting <<~'EOF', '\*\*', 'rubyDoubleSplatOperator'
|
||||
def foo(**bar)
|
||||
end
|
||||
EOF
|
||||
end
|
||||
specify "in multiline parameter list method definitions" do
|
||||
assert_correct_highlighting <<~'EOF', '\*\*', 'rubyDoubleSplatOperator'
|
||||
def foo(bar,
|
||||
**baz)
|
||||
end
|
||||
EOF
|
||||
end
|
||||
specify "as an anonymous parameter in method definitions" do
|
||||
assert_correct_highlighting <<~'EOF', '\*\*', 'rubyDoubleSplatOperator'
|
||||
def foo(**)
|
||||
end
|
||||
EOF
|
||||
end
|
||||
specify "in unparenthesised method definitions" do
|
||||
assert_correct_highlighting <<~'EOF', '\*\*', 'rubyDoubleSplatOperator'
|
||||
def foo **bar
|
||||
end
|
||||
EOF
|
||||
end
|
||||
specify "in unparenthesised method calls" do
|
||||
assert_correct_highlighting <<~'EOF', '\*\*', 'rubyDoubleSplatOperator'
|
||||
foo **bar
|
||||
EOF
|
||||
end
|
||||
specify "in block parameter lists" do
|
||||
assert_correct_highlighting <<~'EOF', '\*\*', 'rubyDoubleSplatOperator'
|
||||
foo { |**bar| 42 }
|
||||
EOF
|
||||
end
|
||||
end
|
||||
|
||||
specify "multiplication operators" do
|
||||
[
|
||||
'foo*bar',
|
||||
'foo * bar',
|
||||
'foo* bar',
|
||||
].each do |str|
|
||||
assert_correct_highlighting str, '\*', 'rubyArithmeticOperator'
|
||||
end
|
||||
end
|
||||
|
||||
context "splat operators" do
|
||||
specify "in method definitions" do
|
||||
assert_correct_highlighting <<~'EOF', '\*', 'rubySplatOperator'
|
||||
def foo(*bar)
|
||||
end
|
||||
EOF
|
||||
end
|
||||
specify "in multiline parameter list method definitions" do
|
||||
assert_correct_highlighting <<~'EOF', '\*', 'rubySplatOperator'
|
||||
def foo(bar,
|
||||
*baz)
|
||||
end
|
||||
EOF
|
||||
end
|
||||
specify "as an anonymous parameter in method definitions" do
|
||||
assert_correct_highlighting <<~'EOF', '\*', 'rubySplatOperator'
|
||||
def foo(*)
|
||||
end
|
||||
EOF
|
||||
end
|
||||
specify "in unparenthesised method definitions" do
|
||||
assert_correct_highlighting <<~'EOF', '\*', 'rubySplatOperator'
|
||||
def foo *bar
|
||||
end
|
||||
EOF
|
||||
end
|
||||
specify "in unparenthesised method calls" do
|
||||
assert_correct_highlighting <<~'EOF', '\*', 'rubySplatOperator'
|
||||
foo *bar
|
||||
EOF
|
||||
end
|
||||
specify "in block parameter lists" do
|
||||
assert_correct_highlighting <<~'EOF', '\*', 'rubySplatOperator'
|
||||
foo { |*bar| 42 }
|
||||
EOF
|
||||
end
|
||||
end
|
||||
|
||||
context "proc operators" do
|
||||
specify "in method definitions" do
|
||||
assert_correct_highlighting <<~'EOF', '&', 'rubyProcOperator'
|
||||
def foo(&bar)
|
||||
end
|
||||
EOF
|
||||
end
|
||||
specify "in multiline parameter list method definitions" do
|
||||
assert_correct_highlighting <<~'EOF', '&', 'rubyProcOperator'
|
||||
def foo(bar,
|
||||
&baz)
|
||||
end
|
||||
EOF
|
||||
end
|
||||
specify "in unparenthesised method definitions" do
|
||||
assert_correct_highlighting <<~'EOF', '&', 'rubyProcOperator'
|
||||
def foo &bar
|
||||
end
|
||||
EOF
|
||||
end
|
||||
specify "in unparenthesised method calls" do
|
||||
assert_correct_highlighting <<~'EOF', '&', 'rubyProcOperator'
|
||||
foo &bar
|
||||
EOF
|
||||
end
|
||||
specify "before literal lambdas" do
|
||||
assert_correct_highlighting <<~'EOF', '&', 'rubyProcOperator'
|
||||
foo &->{}
|
||||
EOF
|
||||
end
|
||||
end
|
||||
|
||||
specify "eigenclass operators" do
|
||||
assert_correct_highlighting <<~'EOF', '<<', 'rubyEigenClassOperator'
|
||||
class << self
|
||||
end
|
||||
EOF
|
||||
end
|
||||
|
||||
specify "superclass operators" do
|
||||
assert_correct_highlighting <<~'EOF', '<', 'rubySuperClassOperator'
|
||||
class Foo < Bar
|
||||
end
|
||||
EOF
|
||||
end
|
||||
end
|
@ -1,21 +0,0 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe "Syntax highlighting" do
|
||||
# See issue #171
|
||||
specify "ambiguous / at end of line is not a regexp" do
|
||||
vim.command 'let g:ruby_operators = 1'
|
||||
assert_correct_highlighting <<~'EOF', '/', 'rubyArithmeticOperator'
|
||||
a = calculate(90).and_some_long_expression /
|
||||
and_long_expression_here
|
||||
puts a
|
||||
EOF
|
||||
vim.command 'unlet g:ruby_operators'
|
||||
end
|
||||
|
||||
# See issue #63
|
||||
specify "interpolated regexp in a host regexp" do
|
||||
assert_correct_highlighting <<~'EOF', '/$', 'rubyRegexpDelimiter'
|
||||
/#{foo.sub(/bar/, 'baz')}/
|
||||
EOF
|
||||
end
|
||||
end
|
@ -1,31 +0,0 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe "Syntax highlighting" do
|
||||
specify "only modifiers can appear after regexp literals" do
|
||||
# See issue #254
|
||||
assert_correct_highlighting <<~'EOF', 'if', 'rubyConditionalModifier'
|
||||
def get_regex
|
||||
/some regex/ if false
|
||||
end
|
||||
EOF
|
||||
end
|
||||
|
||||
specify "only modifiers can appear after unparenthesised no-arg method calls" do
|
||||
[
|
||||
"foo if true",
|
||||
"foo? if true",
|
||||
"foo! if true",
|
||||
"foo_ if true",
|
||||
"foo_? if true",
|
||||
"foo_! if true",
|
||||
"foo42 if true",
|
||||
"foo42? if true",
|
||||
"foo42! if true",
|
||||
"Foo if true",
|
||||
"Foo? if true",
|
||||
"Foo! if true"
|
||||
].each do |str|
|
||||
assert_correct_highlighting str, 'if', 'rubyConditionalModifier'
|
||||
end
|
||||
end
|
||||
end
|
@ -1,26 +0,0 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe "Syntax highlighting" do
|
||||
specify "heredocs starting after parenthesised method definitions" do
|
||||
# See issue #356
|
||||
assert_correct_highlighting <<~'EOF', 'HTML', 'rubyHeredocDelimiter'
|
||||
def youtube_video(token, width = 360, height = 215)
|
||||
<<-HTML if token
|
||||
<iframe width="#{width}" height="#{height}" src="http://www.youtube.com/embed/#{token}" frameborder="0" allowfullscreen></iframe>
|
||||
HTML
|
||||
end
|
||||
EOF
|
||||
end
|
||||
|
||||
specify "heredocs do not start after string literals" do
|
||||
assert_correct_highlighting <<~'EOF', 'FOO', 'rubyConstant'
|
||||
"abc" <<FOO
|
||||
EOF
|
||||
assert_correct_highlighting <<~'EOF', 'FOO', 'rubyConstant'
|
||||
'abc' <<FOO
|
||||
EOF
|
||||
assert_correct_highlighting <<~'EOF', 'FOO', 'rubyConstant'
|
||||
`abc` <<FOO
|
||||
EOF
|
||||
end
|
||||
end
|
@ -1,9 +0,0 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe "Syntax highlighting" do
|
||||
specify "invalid interpolated predefined global variables are literal text" do
|
||||
assert_correct_highlighting <<~'EOF', '#\$', 'rubyString'
|
||||
"abc(#$)def"
|
||||
EOF
|
||||
end
|
||||
end
|
@ -1,9 +0,0 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe "Syntax highlighting" do
|
||||
specify "percent strings with a modulo-assignment operator look-alike delimiter" do
|
||||
assert_correct_highlighting <<~'EOF', '%=', 'rubyPercentStringDelimiter'
|
||||
foo = %= bar =
|
||||
EOF
|
||||
end
|
||||
end
|
@ -1,53 +0,0 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe "Syntax highlighting" do
|
||||
# See issue #356
|
||||
specify "hashes with symbol keys and values on different lines" do
|
||||
assert_correct_highlighting <<~'EOF', 'x', 'rubySymbol'
|
||||
h = {
|
||||
x:
|
||||
really_long_method_name,
|
||||
y: 5,
|
||||
}
|
||||
EOF
|
||||
end
|
||||
|
||||
# See issue #44
|
||||
specify "1.9 style hash keys with keyword names" do
|
||||
assert_correct_highlighting <<~EOF, %w[class if def include case end], 'rubySymbol'
|
||||
{ class: "hello", if: "world", def: "i am", include: "foo", case: "bar", end: "baz" }
|
||||
EOF
|
||||
|
||||
assert_correct_highlighting <<~'EOF', 'end', 'rubyDefine'
|
||||
def hello
|
||||
{ if: "world" }
|
||||
end
|
||||
EOF
|
||||
end
|
||||
|
||||
# See issue #144
|
||||
specify "1.9 style hash keys with keyword names in parameter lists" do
|
||||
assert_correct_highlighting <<~'EOF', 'prepend', 'rubySymbol'
|
||||
{prepend: true}
|
||||
EOF
|
||||
assert_correct_highlighting <<~'EOF', 'for', 'rubySymbol'
|
||||
Subscription.generate(for: topic,
|
||||
to: subscriber)
|
||||
EOF
|
||||
end
|
||||
|
||||
# See issue #12
|
||||
specify "1.9 style hash keys with keyword names in argument lists" do
|
||||
assert_correct_highlighting <<~EOF, %w[:\zsgender in\ze: if\ze: :\zsgender_required?], 'rubySymbol'
|
||||
validates_inclusion_of :gender, in: %w(male female), if: :gender_required?
|
||||
EOF
|
||||
end
|
||||
|
||||
specify "nested parentheses inside symbols" do
|
||||
assert_correct_highlighting <<~EOF, 'bar\zs)', 'rubySymbol'
|
||||
h = %i(
|
||||
foo(bar)baz
|
||||
)
|
||||
EOF
|
||||
end
|
||||
end
|
@ -1,21 +0,0 @@
|
||||
|
||||
let s:debug = 0
|
||||
|
||||
function! s:CursorHasGroup(group) abort
|
||||
return synIDattr(synID(line('.'), col('.'), 1), 'name') =~ a:group
|
||||
endfunction
|
||||
|
||||
function! TestSyntax(pattern, group) abort
|
||||
let pattern = '\C' . a:pattern
|
||||
call cursor(1, 1)
|
||||
redraw
|
||||
let start_match = search(pattern, 'c') && s:CursorHasGroup(a:group)
|
||||
if s:debug
|
||||
redraw | sleep 500m
|
||||
endif
|
||||
let end_match = search(pattern, 'e') && s:CursorHasGroup(a:group)
|
||||
if s:debug
|
||||
redraw | sleep 500m
|
||||
endif
|
||||
return start_match && end_match
|
||||
endfunction
|
@ -1,80 +0,0 @@
|
||||
" Vim syntax file
|
||||
" Language: eRuby
|
||||
" Maintainer: Tim Pope <vimNOSPAM@tpope.org>
|
||||
" URL: https://github.com/vim-ruby/vim-ruby
|
||||
" Release Coordinator: Doug Kearns <dougkearns@gmail.com>
|
||||
|
||||
if &syntax !~# '\<eruby\>' || get(b:, 'current_syntax') =~# '\<eruby\>'
|
||||
finish
|
||||
endif
|
||||
|
||||
if !exists("main_syntax")
|
||||
let main_syntax = 'eruby'
|
||||
endif
|
||||
|
||||
if !exists("g:eruby_default_subtype")
|
||||
let g:eruby_default_subtype = "html"
|
||||
endif
|
||||
|
||||
if &filetype =~ '^eruby\.'
|
||||
let b:eruby_subtype = matchstr(&filetype,'^eruby\.\zs\w\+')
|
||||
elseif &filetype =~ '^.*\.eruby\>'
|
||||
let b:eruby_subtype = matchstr(&filetype,'^.\{-\}\ze\.eruby\>')
|
||||
elseif !exists("b:eruby_subtype") && main_syntax == 'eruby'
|
||||
let s:lines = getline(1)."\n".getline(2)."\n".getline(3)."\n".getline(4)."\n".getline(5)."\n".getline("$")
|
||||
let b:eruby_subtype = matchstr(s:lines,'eruby_subtype=\zs\w\+')
|
||||
if b:eruby_subtype == ''
|
||||
let b:eruby_subtype = matchstr(substitute(expand("%:t"),'\c\%(\.erb\|\.eruby\|\.erubis\|\.example\)\+$','',''),'\.\zs\w\+\%(\ze+\w\+\)\=$')
|
||||
endif
|
||||
if b:eruby_subtype == 'rhtml'
|
||||
let b:eruby_subtype = 'html'
|
||||
elseif b:eruby_subtype == 'rb'
|
||||
let b:eruby_subtype = 'ruby'
|
||||
elseif b:eruby_subtype == 'yml'
|
||||
let b:eruby_subtype = 'yaml'
|
||||
elseif b:eruby_subtype == 'js'
|
||||
let b:eruby_subtype = 'javascript'
|
||||
elseif b:eruby_subtype == 'txt'
|
||||
" Conventional; not a real file type
|
||||
let b:eruby_subtype = 'text'
|
||||
elseif b:eruby_subtype == ''
|
||||
let b:eruby_subtype = g:eruby_default_subtype
|
||||
endif
|
||||
endif
|
||||
|
||||
if !exists("b:eruby_nest_level")
|
||||
if &syntax =~# '\<eruby\.eruby\>'
|
||||
let b:eruby_nest_level = strlen(substitute(substitute(&filetype,'\C\<eruby\>','@','g'),'[^@]','','g'))
|
||||
else
|
||||
let b:eruby_nest_level = strlen(substitute(substitute(substitute(expand("%:t"),'@','','g'),'\c\.\%(erb\|rhtml\)\>','@','g'),'[^@]','','g'))
|
||||
endif
|
||||
endif
|
||||
if !b:eruby_nest_level
|
||||
let b:eruby_nest_level = 1
|
||||
endif
|
||||
|
||||
if get(b:, 'eruby_subtype', '') !~# '^\%(eruby\)\=$' && &syntax =~# '^eruby\>'
|
||||
exe "runtime! syntax/".b:eruby_subtype.".vim"
|
||||
endif
|
||||
unlet! b:current_syntax
|
||||
syn include @rubyTop syntax/ruby.vim
|
||||
|
||||
syn cluster erubyRegions contains=erubyOneLiner,erubyBlock,erubyExpression,erubyComment
|
||||
|
||||
exe 'syn region erubyOneLiner matchgroup=erubyDelimiter start="^%\{1,'.b:eruby_nest_level.'\}%\@!" end="$" contains=@rubyTop containedin=ALLBUT,@erubyRegions keepend oneline'
|
||||
exe 'syn region erubyBlock matchgroup=erubyDelimiter start="<%\{1,'.b:eruby_nest_level.'\}%\@!-\=" end="[=-]\=%\@<!%\{1,'.b:eruby_nest_level.'\}>" contains=@rubyTop containedin=ALLBUT,@erubyRegions keepend'
|
||||
exe 'syn region erubyExpression matchgroup=erubyDelimiter start="<%\{1,'.b:eruby_nest_level.'\}=\{1,4}" end="[=-]\=%\@<!%\{1,'.b:eruby_nest_level.'\}>" contains=@rubyTop containedin=ALLBUT,@erubyRegions keepend'
|
||||
exe 'syn region erubyComment matchgroup=erubyDelimiter start="<%\{1,'.b:eruby_nest_level.'\}-\=#" end="[=-]\=%\@<!%\{1,'.b:eruby_nest_level.'\}>" contains=rubyTodo,@Spell containedin=ALLBUT,@erubyRegions keepend'
|
||||
|
||||
" Define the default highlighting.
|
||||
|
||||
hi def link erubyDelimiter PreProc
|
||||
hi def link erubyComment Comment
|
||||
|
||||
let b:current_syntax = matchstr(&syntax, '^.*\<eruby\>')
|
||||
|
||||
if main_syntax == 'eruby'
|
||||
unlet main_syntax
|
||||
endif
|
||||
|
||||
" vim: nowrap sw=2 sts=2 ts=8:
|
@ -1,602 +0,0 @@
|
||||
" Vim syntax file
|
||||
" Language: Ruby
|
||||
" Maintainer: Doug Kearns <dougkearns@gmail.com>
|
||||
" URL: https://github.com/vim-ruby/vim-ruby
|
||||
" Release Coordinator: Doug Kearns <dougkearns@gmail.com>
|
||||
" ----------------------------------------------------------------------------
|
||||
"
|
||||
" Previous Maintainer: Mirko Nasato
|
||||
" Thanks to perl.vim authors, and to Reimer Behrends. :-) (MN)
|
||||
" ----------------------------------------------------------------------------
|
||||
|
||||
" Prelude {{{1
|
||||
if exists("b:current_syntax")
|
||||
finish
|
||||
endif
|
||||
|
||||
" this file uses line continuations
|
||||
let s:cpo_sav = &cpo
|
||||
set cpo&vim
|
||||
|
||||
" eRuby Config {{{1
|
||||
if exists('main_syntax') && main_syntax == 'eruby'
|
||||
let b:ruby_no_expensive = 1
|
||||
endif
|
||||
|
||||
" Folding Config {{{1
|
||||
if has("folding") && exists("ruby_fold")
|
||||
setlocal foldmethod=syntax
|
||||
endif
|
||||
|
||||
let s:foldable_groups = split(
|
||||
\ get(
|
||||
\ b:,
|
||||
\ 'ruby_foldable_groups',
|
||||
\ get(g:, 'ruby_foldable_groups', 'ALL')
|
||||
\ )
|
||||
\ )
|
||||
|
||||
function! s:foldable(...) abort
|
||||
if index(s:foldable_groups, 'NONE') > -1
|
||||
return 0
|
||||
endif
|
||||
|
||||
if index(s:foldable_groups, 'ALL') > -1
|
||||
return 1
|
||||
endif
|
||||
|
||||
for l:i in a:000
|
||||
if index(s:foldable_groups, l:i) > -1
|
||||
return 1
|
||||
endif
|
||||
endfor
|
||||
|
||||
return 0
|
||||
endfunction
|
||||
|
||||
function! s:run_syntax_fold(args) abort
|
||||
let [_0, _1, groups, cmd; _] = matchlist(a:args, '\(["'']\)\(.\{-}\)\1\s\+\(.*\)')
|
||||
if call('s:foldable', split(groups))
|
||||
let cmd .= ' fold'
|
||||
endif
|
||||
exe cmd
|
||||
endfunction
|
||||
|
||||
com! -nargs=* SynFold call s:run_syntax_fold(<q-args>)
|
||||
|
||||
" Not-Top Cluster {{{1
|
||||
syn cluster rubyNotTop contains=@rubyCommentNotTop,@rubyStringNotTop,@rubyRegexpSpecial,@rubyDeclaration,@rubyExceptionHandler,@rubyClassOperator,rubyConditional,rubyModuleName,rubyClassName,rubySymbolDelimiter,rubyDoubleQuoteSymbolDelimiter,rubySingleQuoteSymbolDelimiter,rubyParentheses,@Spell
|
||||
|
||||
" Whitespace Errors {{{1
|
||||
if exists("ruby_space_errors")
|
||||
if !exists("ruby_no_trail_space_error")
|
||||
syn match rubySpaceError display excludenl "\s\+$"
|
||||
endif
|
||||
if !exists("ruby_no_tab_space_error")
|
||||
syn match rubySpaceError display " \+\t"me=e-1
|
||||
endif
|
||||
endif
|
||||
|
||||
" Operators {{{1
|
||||
|
||||
syn match rubyEnglishBooleanOperator "\<\%(and\|or\|not\)\>"
|
||||
|
||||
if exists("ruby_operators") || exists("ruby_pseudo_operators")
|
||||
syn match rubyDotOperator "\.\|&\."
|
||||
|
||||
syn match rubyTernaryOperator "\%(\w\|[^\x00-\x7F]\)\@1<!?\|:"
|
||||
syn match rubyArithmeticOperator "\*\*\|[*/%+]\|->\@!"
|
||||
syn match rubyComparisonOperator "<=>\|<=\|<\|>=\|[-=]\@1<!>"
|
||||
syn match rubyBitwiseOperator "[~^|]\|&\.\@!\|<<\|>>"
|
||||
syn match rubyBooleanOperator "\%(\w\|[^\x00-\x7F]\)\@1<!!\|&&\|||"
|
||||
syn match rubyRangeOperator "\.\.\.\="
|
||||
syn match rubyAssignmentOperator "=>\@!\|-=\|/=\|\*\*=\|\*=\|&&=\|&=\|||=\||=\|%=\|+=\|>>=\|<<=\|\^="
|
||||
syn match rubyAssignmentOperator "=>\@!" contained containedin=rubyBlockParameterList " TODO: this is inelegant
|
||||
syn match rubyEqualityOperator "===\|==\|!=\|!\~\|=\~"
|
||||
|
||||
syn region rubyBracketOperator matchgroup=rubyOperator start="\%(\%(\w\|[^\x00-\x7F]\)[?!]\=\|[]})]\)\@2<=\[" end="]" contains=ALLBUT,@rubyNotTop
|
||||
|
||||
syn match rubyScopeOperator "::"
|
||||
syn match rubySuperClassOperator "<" contained
|
||||
syn match rubyEigenClassOperator "<<" contained
|
||||
syn match rubyLambdaOperator "->"
|
||||
syn match rubySplatOperator "\%([[{(|,=]\_s*\)\@<=\*"
|
||||
syn match rubySplatOperator "\%(^\|\s\)\@1<=\*\%(\h\|[^\x00-\x7F]\|[:$@[]\)\@="
|
||||
syn match rubyDoubleSplatOperator "\%([{(|,]\_s*\)\@<=\*\*"
|
||||
syn match rubyDoubleSplatOperator "\s\@1<=\*\*\%(\h\|[^\x00-\x7F]\|[:$@{]\)\@="
|
||||
syn match rubyProcOperator "\%([[(|,]\_s*\)\@<=&"
|
||||
syn match rubyProcOperator "\s\@1<=&\%(\h\|[^\x00-\x7F]\|[:$@]\|->\)\@="
|
||||
|
||||
syn cluster rubyProperOperator contains=rubyTernaryOperator,rubyArithmeticOperator,rubyComparisonOperator,rubyBitwiseOperator,rubyBooleanOperator,rubyRangeOperator,rubyAssignmentOperator,rubyEqualityOperator,rubyDefinedOperator,rubyEnglishBooleanOperator
|
||||
syn cluster rubyClassOperator contains=rubyEigenClassOperator,rubySuperClassOperator
|
||||
syn cluster rubyPseudoOperator contains=rubyDotOperator,rubyScopeOperator,rubyEigenClassOperator,rubySuperClassOperator,rubyLambdaOperator,rubySplatOperator,rubyDoubleSplatOperator,rubyProcOperator
|
||||
syn cluster rubyOperator contains=ruby.*Operator
|
||||
endif
|
||||
|
||||
" String Interpolation and Backslash Notation {{{1
|
||||
syn region rubyInterpolation matchgroup=rubyInterpolationDelimiter start="#{" end="}" contained contains=ALLBUT,@rubyNotTop
|
||||
syn match rubyInterpolation "#\$\%(-\w\|[!$&"'*+,./0:;<>?@\`~_]\|\w\+\)" display contained contains=rubyInterpolationDelimiter,@rubyGlobalVariable
|
||||
syn match rubyInterpolation "#@@\=\w\+" display contained contains=rubyInterpolationDelimiter,rubyInstanceVariable,rubyClassVariable
|
||||
syn match rubyInterpolationDelimiter "#\ze[$@]" display contained
|
||||
|
||||
syn match rubyStringEscape "\\\_." contained display
|
||||
syn match rubyStringEscape "\\\o\{1,3}\|\\x\x\{1,2}" contained display
|
||||
syn match rubyStringEscape "\\u\%(\x\{4}\|{\x\{1,6}\%(\s\+\x\{1,6}\)*}\)" contained display
|
||||
syn match rubyStringEscape "\%(\\M-\\C-\|\\C-\\M-\|\\M-\\c\|\\c\\M-\|\\c\|\\C-\|\\M-\)\%(\\\o\{1,3}\|\\x\x\{1,2}\|\\\=.\)" contained display
|
||||
|
||||
syn match rubyBackslashEscape "\\\\" contained display
|
||||
syn match rubyQuoteEscape "\\'" contained display
|
||||
syn match rubySpaceEscape "\\ " contained display
|
||||
|
||||
syn match rubyParenthesisEscape "\\[()]" contained display
|
||||
syn match rubyCurlyBraceEscape "\\[{}]" contained display
|
||||
syn match rubyAngleBracketEscape "\\[<>]" contained display
|
||||
syn match rubySquareBracketEscape "\\[[\]]" contained display
|
||||
|
||||
syn region rubyNestedParentheses start="(" skip="\\\\\|\\)" end=")" transparent contained
|
||||
syn region rubyNestedCurlyBraces start="{" skip="\\\\\|\\}" end="}" transparent contained
|
||||
syn region rubyNestedAngleBrackets start="<" skip="\\\\\|\\>" end=">" transparent contained
|
||||
syn region rubyNestedSquareBrackets start="\[" skip="\\\\\|\\\]" end="\]" transparent contained
|
||||
|
||||
syn cluster rubySingleCharEscape contains=rubyBackslashEscape,rubyQuoteEscape,rubySpaceEscape,rubyParenthesisEscape,rubyCurlyBraceEscape,rubyAngleBracketEscape,rubySquareBracketEscape
|
||||
syn cluster rubyNestedBrackets contains=rubyNested.\+
|
||||
syn cluster rubyStringSpecial contains=rubyInterpolation,rubyStringEscape
|
||||
syn cluster rubyStringNotTop contains=@rubyStringSpecial,@rubyNestedBrackets,@rubySingleCharEscape
|
||||
|
||||
" Regular Expression Metacharacters {{{1
|
||||
syn region rubyRegexpComment matchgroup=rubyRegexpSpecial start="(?#" skip="\\\\\|\\)" end=")" contained
|
||||
syn region rubyRegexpParens matchgroup=rubyRegexpSpecial start="(\(?:\|?<\=[=!]\|?>\|?<[a-z_]\w*>\|?[imx]*-[imx]*:\=\|\%(?#\)\@!\)" skip="\\\\\|\\)" end=")" contained transparent contains=@rubyRegexpSpecial
|
||||
syn region rubyRegexpBrackets matchgroup=rubyRegexpCharClass start="\[\^\=" skip="\\\\\|\\\]" end="\]" contained transparent contains=rubyRegexpBrackets,rubyStringEscape,rubyRegexpEscape,rubyRegexpCharClass,rubyRegexpIntersection oneline
|
||||
syn match rubyRegexpCharClass "\\[DdHhRSsWw]" contained display
|
||||
syn match rubyRegexpCharClass "\[:\^\=\%(alnum\|alpha\|ascii\|blank\|cntrl\|digit\|graph\|lower\|print\|punct\|space\|upper\|word\|xdigit\):\]" contained
|
||||
syn match rubyRegexpCharClass "\\[pP]{^\=.\{-}}" contained display
|
||||
syn match rubyRegexpEscape "\\[].*?+^$|\\/(){}[]" contained " see commit e477f10
|
||||
syn match rubyRegexpQuantifier "[*?+][?+]\=" contained display
|
||||
syn match rubyRegexpQuantifier "{\d\+\%(,\d*\)\=}?\=" contained display
|
||||
syn match rubyRegexpAnchor "[$^]\|\\[ABbGZz]" contained display
|
||||
syn match rubyRegexpDot "\.\|\\X" contained display
|
||||
syn match rubyRegexpIntersection "&&" contained display
|
||||
syn match rubyRegexpSpecial "\\K" contained display
|
||||
syn match rubyRegexpSpecial "|" contained display
|
||||
syn match rubyRegexpSpecial "\\[1-9]\d\=\d\@!" contained display
|
||||
syn match rubyRegexpSpecial "\\k<\%([a-z_]\w*\|-\=\d\+\)\%([+-]\d\+\)\=>" contained display
|
||||
syn match rubyRegexpSpecial "\\k'\%([a-z_]\w*\|-\=\d\+\)\%([+-]\d\+\)\='" contained display
|
||||
syn match rubyRegexpSpecial "\\g<\%([a-z_]\w*\|-\=\d\+\)>" contained display
|
||||
syn match rubyRegexpSpecial "\\g'\%([a-z_]\w*\|-\=\d\+\)'" contained display
|
||||
|
||||
syn cluster rubyRegexpSpecial contains=@rubyStringSpecial,rubyRegexpSpecial,rubyRegexpEscape,rubyRegexpBrackets,rubyRegexpCharClass,rubyRegexpDot,rubyRegexpQuantifier,rubyRegexpAnchor,rubyRegexpParens,rubyRegexpComment,rubyRegexpIntersection
|
||||
|
||||
" Numbers {{{1
|
||||
syn match rubyInteger "\%(\%(\w\|[^\x00-\x7F]\|[]})\"']\s*\)\@<!-\)\=\<0[xX]\x\+\%(_\x\+\)*r\=i\=\>" display
|
||||
syn match rubyInteger "\%(\%(\w\|[^\x00-\x7F]\|[]})\"']\s*\)\@<!-\)\=\<\%(0[dD]\)\=\%(0\|[1-9]\d*\%(_\d\+\)*\)r\=i\=\>" display
|
||||
syn match rubyInteger "\%(\%(\w\|[^\x00-\x7F]\|[]})\"']\s*\)\@<!-\)\=\<0[oO]\=\o\+\%(_\o\+\)*r\=i\=\>" display
|
||||
syn match rubyInteger "\%(\%(\w\|[^\x00-\x7F]\|[]})\"']\s*\)\@<!-\)\=\<0[bB][01]\+\%(_[01]\+\)*r\=i\=\>" display
|
||||
syn match rubyFloat "\%(\%(\w\|[^\x00-\x7F]\|[]})\"']\s*\)\@<!-\)\=\<\%(0\|[1-9]\d*\%(_\d\+\)*\)\.\d\+\%(_\d\+\)*r\=i\=\>" display
|
||||
syn match rubyFloat "\%(\%(\w\|[^\x00-\x7F]\|[]})\"']\s*\)\@<!-\)\=\<\%(0\|[1-9]\d*\%(_\d\+\)*\)\%(\.\d\+\%(_\d\+\)*\)\=\%([eE][-+]\=\d\+\%(_\d\+\)*\)i\=\>" display
|
||||
|
||||
" Identifiers {{{1
|
||||
syn match rubyClassName "\%(\%(^\|[^.]\)\.\s*\)\@<!\<[[:upper:]]\%(\w\|[^\x00-\x7F]\)*\>\%(\s*(\)\@!" contained
|
||||
syn match rubyModuleName "\%(\%(^\|[^.]\)\.\s*\)\@<!\<[[:upper:]]\%(\w\|[^\x00-\x7F]\)*\>\%(\s*(\)\@!" contained
|
||||
syn match rubyConstant "\%(\%(^\|[^.]\)\.\s*\)\@<!\<[[:upper:]]\%(\w\|[^\x00-\x7F]\)*\>\%(\s*(\)\@!"
|
||||
syn match rubyClassVariable "@@\%(\h\|[^\x00-\x7F]\)\%(\w\|[^\x00-\x7F]\)*" display
|
||||
syn match rubyInstanceVariable "@\%(\h\|[^\x00-\x7F]\)\%(\w\|[^\x00-\x7F]\)*" display
|
||||
syn match rubyGlobalVariable "$\%(\%(\h\|[^\x00-\x7F]\)\%(\w\|[^\x00-\x7F]\)*\|-.\)"
|
||||
syn match rubySymbolDelimiter ":" contained
|
||||
syn match rubySymbol "[]})\"':]\@1<!:\%(\^\|\~@\|\~\|<<\|<=>\|<=\|<\|===\|[=!]=\|[=!]\~\|!@\|!\|>>\|>=\|>\||\|-@\|-\|/\|\[]=\|\[]\|\*\*\|\*\|&\|%\|+@\|+\|`\)" contains=rubySymbolDelimiter
|
||||
syn match rubySymbol "[]})\"':]\@1<!:\$\%(-.\|[`~<=>_,;:!?/.'"@$*\&+0]\)" contains=rubySymbolDelimiter
|
||||
syn match rubySymbol "[]})\"':]\@1<!:\%(\$\|@@\=\)\=\%(\h\|[^\x00-\x7F]\)\%(\w\|[^\x00-\x7F]\)*" contains=rubySymbolDelimiter
|
||||
syn match rubySymbol "[]})\"':]\@1<!:\%(\h\|[^\x00-\x7F]\)\%(\w\|[^\x00-\x7F]\)*\%([?!=]>\@!\)\=" contains=rubySymbolDelimiter
|
||||
|
||||
SynFold ':' syn region rubySymbol matchgroup=rubySymbolDelimiter start="[]})\"':]\@1<!:'" end="'" skip="\\\\\|\\'" contains=rubyQuoteEscape,rubyBackslashEscape
|
||||
SynFold ':' syn region rubySymbol matchgroup=rubySymbolDelimiter start="[]})\"':]\@1<!:\"" end="\"" skip="\\\\\|\\\"" contains=@rubyStringSpecial
|
||||
|
||||
syn match rubyCapitalizedMethod "\%(\%(^\|[^.]\)\.\s*\)\@<!\<\u\%(\w\|[^\x00-\x7F]\)*\>\%(\s*(\)\@="
|
||||
|
||||
syn region rubyParentheses start="(" end=")" contains=ALLBUT,@rubyNotTop contained containedin=rubyBlockParameterList
|
||||
syn region rubyBlockParameterList start="\%(\%(\<do\>\|{\)\_s*\)\@32<=|" end="|" contains=ALLBUT,@rubyNotTop,@rubyProperOperator
|
||||
|
||||
if exists('ruby_global_variable_error')
|
||||
syn match rubyGlobalVariableError "$[^A-Za-z_]" display
|
||||
syn match rubyGlobalVariableError "$-[^0FIKWadilpvw]" display
|
||||
endif
|
||||
|
||||
syn match rubyPredefinedVariable #$[!$&"'*+,./0:;<>?@\`~]#
|
||||
syn match rubyPredefinedVariable "$\d\+" display
|
||||
syn match rubyPredefinedVariable "$_\>" display
|
||||
syn match rubyPredefinedVariable "$-[0FIWadilpvw]\>" display
|
||||
syn match rubyPredefinedVariable "$\%(stderr\|stdin\|stdout\)\>" display
|
||||
syn match rubyPredefinedVariable "$\%(DEBUG\|FILENAME\|LOADED_FEATURES\|LOAD_PATH\|PROGRAM_NAME\|SAFE\|VERBOSE\)\>" display
|
||||
syn match rubyPredefinedConstant "\%(\%(^\|[^.]\)\.\s*\)\@<!\<\%(ARGF\|ARGV\|ENV\|DATA\|STDERR\|STDIN\|STDOUT\|TOPLEVEL_BINDING\)\>\%(\s*(\)\@!"
|
||||
syn match rubyPredefinedConstant "\%(\%(^\|[^.]\)\.\s*\)\@<!\<\%(RUBY_\%(VERSION\|RELEASE_DATE\|PLATFORM\|PATCHLEVEL\|REVISION\|DESCRIPTION\|COPYRIGHT\|ENGINE\)\)\>\%(\s*(\)\@!"
|
||||
|
||||
" Deprecated/removed in 1.9
|
||||
syn match rubyPredefinedVariable "$="
|
||||
syn match rubyPredefinedVariable "$-K\>" display
|
||||
syn match rubyPredefinedVariable "$\%(deferr\|defout\)\>" display
|
||||
syn match rubyPredefinedVariable "$KCODE\>" display
|
||||
" Deprecated/removed in 2.4
|
||||
syn match rubyPredefinedConstant "\%(\%(^\|[^.]\)\.\s*\)\@<!\<\%(FALSE\|NIL\|TRUE\)\>\%(\s*(\)\@!"
|
||||
|
||||
syn cluster rubyGlobalVariable contains=rubyGlobalVariable,rubyPredefinedVariable,rubyGlobalVariableError
|
||||
|
||||
" Normal Regular Expressions {{{1
|
||||
SynFold '/' syn region rubyRegexp matchgroup=rubyRegexpDelimiter start="\%(\%(^\|\<\%(and\|or\|while\|until\|unless\|if\|elsif\|when\|not\|then\|else\)\|[;\~=!|&(,{[<>?:*+-]\)\s*\)\@<=/" end="/[iomxneus]*" skip="\\\\\|\\/" contains=@rubyRegexpSpecial nextgroup=@rubyModifier skipwhite
|
||||
SynFold '/' syn region rubyRegexp matchgroup=rubyRegexpDelimiter start="\%(\%(\%(\h\|[^\x00-\x7F]\)\%(\w\|[^\x00-\x7F]\)*\)\s\+\)\@<=/\%(=\|\_s\)\@!" end="/[iomxneus]*" skip="\\\\\|\\/" contains=@rubyRegexpSpecial nextgroup=@rubyModifier skipwhite
|
||||
|
||||
" Generalized Regular Expressions {{{1
|
||||
SynFold '%' syn region rubyRegexp matchgroup=rubyPercentRegexpDelimiter start="%r\z([~`!@#$%^&*_\-+=|\:;"',.?/]\)" end="\z1[iomxneus]*" skip="\\\\\|\\\z1" contains=@rubyRegexpSpecial nextgroup=@rubyModifier skipwhite
|
||||
SynFold '%' syn region rubyRegexp matchgroup=rubyPercentRegexpDelimiter start="%r{" end="}[iomxneus]*" skip="\\\\\|\\}" contains=@rubyRegexpSpecial
|
||||
SynFold '%' syn region rubyRegexp matchgroup=rubyPercentRegexpDelimiter start="%r<" end=">[iomxneus]*" skip="\\\\\|\\>" contains=@rubyRegexpSpecial,rubyNestedAngleBrackets
|
||||
SynFold '%' syn region rubyRegexp matchgroup=rubyPercentRegexpDelimiter start="%r\[" end="\][iomxneus]*" skip="\\\\\|\\\]" contains=@rubyRegexpSpecial
|
||||
SynFold '%' syn region rubyRegexp matchgroup=rubyPercentRegexpDelimiter start="%r(" end=")[iomxneus]*" skip="\\\\\|\\)" contains=@rubyRegexpSpecial
|
||||
SynFold '%' syn region rubyRegexp matchgroup=rubyPercentRegexpDelimiter start="%r\z(\s\)" end="\z1[iomxneus]*" skip="\\\\\|\\\z1" contains=@rubyRegexpSpecial
|
||||
|
||||
" Characters {{{1
|
||||
syn match rubyCharacter "\%(\w\|[^\x00-\x7F]\|[]})\"'/]\)\@1<!\%(?\%(\\M-\\C-\|\\C-\\M-\|\\M-\\c\|\\c\\M-\|\\c\|\\C-\|\\M-\)\=\%(\\\o\{1,3}\|\\x\x\{1,2}\|\\[[:space:]]\|\\\=[^[:space:]]\)\)"
|
||||
syn match rubyCharacter "\%(\w\|[^\x00-\x7F]\|[]})\"'/]\)\@1<!?\\u\%(\x\{4}\|{\x\{1,6}}\)"
|
||||
|
||||
" Normal Strings {{{1
|
||||
let s:spell_cluster = exists('ruby_spellcheck_strings') ? ',@Spell' : ''
|
||||
let s:fold_arg = s:foldable('string') ? ' fold' : ''
|
||||
exe 'syn region rubyString matchgroup=rubyStringDelimiter start="\"" end="\"" skip="\\\\\|\\\"" contains=@rubyStringSpecial' . s:spell_cluster . s:fold_arg
|
||||
exe 'syn region rubyString matchgroup=rubyStringDelimiter start="''" end="''" skip="\\\\\|\\''" contains=rubyQuoteEscape,rubyBackslashEscape' . s:spell_cluster . s:fold_arg
|
||||
unlet s:spell_cluster s:fold_arg
|
||||
|
||||
" Shell Command Output {{{1
|
||||
SynFold 'string' syn region rubyString matchgroup=rubyStringDelimiter start="`" end="`" skip="\\\\\|\\`" contains=@rubyStringSpecial
|
||||
|
||||
" Generalized Single Quoted Strings, Symbols, Array of Strings and Array of Symbols {{{1
|
||||
|
||||
" Non-bracket punctuation delimiters {{{2
|
||||
let s:names = { '~': 'Tilde', '`': 'BackQuote', '!': 'Bang', '@': 'At', '#': 'Hash', '$': 'Dollar', '%': 'Percent', '^': 'Caret',
|
||||
\ '&': 'Ampersand', '*': 'Asterix', '_': 'Underscore', '-': 'Dash', '+': 'Plus', '=': 'Equals', '|': 'Bar',
|
||||
\ '\': 'Backslash', ':': 'Colon', ';': 'Semicolon', '"': 'DoubleQuote', "'": 'Quote', ',': 'Comma', '.': 'Period',
|
||||
\ '?': 'QuestionMark', '/': 'ForwardSlash' }
|
||||
|
||||
for s:delimiter in keys(s:names)
|
||||
let s:group = 'ruby' . s:names[s:delimiter] . 'Escape'
|
||||
|
||||
if s:delimiter =~ '[\"]'
|
||||
let s:delimiter = '\' . s:delimiter
|
||||
endif
|
||||
|
||||
exe 'syn match ' . s:group . ' "\V\\' . s:delimiter . '" contained display'
|
||||
exe 'syn cluster rubySingleCharEscape add=' . s:group
|
||||
exe 'SynFold ''%'' syn region rubyString matchgroup=rubyPercentStringDelimiter start="\V%q' . s:delimiter . '" end="\V' . s:delimiter . '" skip="\V\\\\\|\\' . s:delimiter . '" contains=rubyBackslashEscape,' . s:group . ' nextgroup=@rubyModifier skipwhite'
|
||||
exe 'SynFold ''%'' syn region rubyString matchgroup=rubyPercentStringDelimiter start="\V%w' . s:delimiter . '" end="\V' . s:delimiter . '" skip="\V\\\\\|\\' . s:delimiter . '" contains=rubyBackslashEscape,rubySpaceEscape,' . s:group . ' nextgroup=@rubyModifier skipwhite'
|
||||
exe 'SynFold ''%'' syn region rubySymbol matchgroup=rubyPercentSymbolDelimiter start="\V%s' . s:delimiter . '" end="\V' . s:delimiter . '" skip="\V\\\\\|\\' . s:delimiter . '" contains=rubyBackslashEscape,' . s:group . ' nextgroup=@rubyModifier skipwhite'
|
||||
exe 'SynFold ''%'' syn region rubySymbol matchgroup=rubyPercentSymbolDelimiter start="\V%i' . s:delimiter . '" end="\V' . s:delimiter . '" skip="\V\\\\\|\\' . s:delimiter . '" contains=rubyBackslashEscape,rubySpaceEscape,' . s:group . ' nextgroup=@rubyModifier skipwhite'
|
||||
exe 'hi def link ' . s:group . ' rubyStringEscape'
|
||||
endfor
|
||||
|
||||
unlet s:delimiter s:group s:names
|
||||
" }}}2
|
||||
|
||||
SynFold '%' syn region rubyString matchgroup=rubyPercentStringDelimiter start="%q{" end="}" skip="\\\\\|\\}" contains=rubyBackslashEscape,rubyCurlyBraceEscape,rubyNestedCurlyBraces
|
||||
SynFold '%' syn region rubyString matchgroup=rubyPercentStringDelimiter start="%q<" end=">" skip="\\\\\|\\>" contains=rubyBackslashEscape,rubyAngleBracketEscape,rubyNestedAngleBrackets
|
||||
SynFold '%' syn region rubyString matchgroup=rubyPercentStringDelimiter start="%q\[" end="\]" skip="\\\\\|\\\]" contains=rubyBackslashEscape,rubySquareBracketEscape,rubyNestedSquareBrackets
|
||||
SynFold '%' syn region rubyString matchgroup=rubyPercentStringDelimiter start="%q(" end=")" skip="\\\\\|\\)" contains=rubyBackslashEscape,rubyParenthesisEscape,rubyNestedParentheses
|
||||
SynFold '%' syn region rubyString matchgroup=rubyPercentStringDelimiter start="%q\z(\s\)" end="\z1" skip="\\\\\|\\\z1" contains=rubyBackslashEscape,rubySpaceEscape
|
||||
|
||||
SynFold '%' syn region rubyString matchgroup=rubyPercentStringDelimiter start="%w{" end="}" skip="\\\\\|\\}" contains=rubyBackslashEscape,rubySpaceEscape,rubyCurlyBraceEscape,rubyNestedCurlyBraces
|
||||
SynFold '%' syn region rubyString matchgroup=rubyPercentStringDelimiter start="%w<" end=">" skip="\\\\\|\\>" contains=rubyBackslashEscape,rubySpaceEscape,rubyAngleBracketEscape,rubyNestedAngleBrackets
|
||||
SynFold '%' syn region rubyString matchgroup=rubyPercentStringDelimiter start="%w\[" end="\]" skip="\\\\\|\\\]" contains=rubyBackslashEscape,rubySpaceEscape,rubySquareBracketEscape,rubyNestedSquareBrackets
|
||||
SynFold '%' syn region rubyString matchgroup=rubyPercentStringDelimiter start="%w(" end=")" skip="\\\\\|\\)" contains=rubyBackslashEscape,rubySpaceEscape,rubyParenthesisEscape,rubyNestedParentheses
|
||||
|
||||
SynFold '%' syn region rubySymbol matchgroup=rubyPercentSymbolDelimiter start="%s{" end="}" skip="\\\\\|\\}" contains=rubyBackslashEscape,rubyCurlyBraceEscape,rubyNestedCurlyBraces
|
||||
SynFold '%' syn region rubySymbol matchgroup=rubyPercentSymbolDelimiter start="%s<" end=">" skip="\\\\\|\\>" contains=rubyBackslashEscape,rubyAngleBracketEscape,rubyNestedAngleBrackets
|
||||
SynFold '%' syn region rubySymbol matchgroup=rubyPercentSymbolDelimiter start="%s\[" end="\]" skip="\\\\\|\\\]" contains=rubyBackslashEscape,rubySquareBracketEscape,rubyNestedSquareBrackets
|
||||
SynFold '%' syn region rubySymbol matchgroup=rubyPercentSymbolDelimiter start="%s(" end=")" skip="\\\\\|\\)" contains=rubyBackslashEscape,rubyParenthesisEscape,rubyNestedParentheses
|
||||
SynFold '%' syn region rubyString matchgroup=rubyPercentSymbolDelimiter start="%s\z(\s\)" end="\z1" skip="\\\\\|\\\z1" contains=rubyBackslashEscape,rubySpaceEscape
|
||||
|
||||
SynFold '%' syn region rubySymbol matchgroup=rubyPercentSymbolDelimiter start="%i{" end="}" skip="\\\\\|\\}" contains=rubyBackslashEscape,rubySpaceEscape,rubyCurlyBraceEscape,rubyNestedCurlyBraces
|
||||
SynFold '%' syn region rubySymbol matchgroup=rubyPercentSymbolDelimiter start="%i<" end=">" skip="\\\\\|\\>" contains=rubyBackslashEscape,rubySpaceEscape,rubyAngleBracketEscape,rubyNestedAngleBrackets
|
||||
SynFold '%' syn region rubySymbol matchgroup=rubyPercentSymbolDelimiter start="%i\[" end="\]" skip="\\\\\|\\\]" contains=rubyBackslashEscape,rubySpaceEscape,rubySquareBracketEscape,rubyNestedSquareBrackets
|
||||
SynFold '%' syn region rubySymbol matchgroup=rubyPercentSymbolDelimiter start="%i(" end=")" skip="\\\\\|\\)" contains=rubyBackslashEscape,rubySpaceEscape,rubyParenthesisEscape,rubyNestedParentheses
|
||||
|
||||
" Generalized Double Quoted Strings, Array of Strings, Array of Symbols and Shell Command Output {{{1
|
||||
SynFold '%' syn region rubyString matchgroup=rubyPercentStringDelimiter start="\%(\%(\w\|[^\x00-\x7F]\|]\)\s*\)\@<!%=" end="=" skip="\\\\\|\\=" contains=@rubyStringSpecial nextgroup=@rubyModifier skipwhite
|
||||
SynFold '%' syn region rubyString matchgroup=rubyPercentStringDelimiter start="%\z([~`!@#$%^&*_\-+|\:;"',.?/]\)" end="\z1" skip="\\\\\|\\\z1" contains=@rubyStringSpecial nextgroup=@rubyModifier skipwhite
|
||||
SynFold '%' syn region rubyString matchgroup=rubyPercentStringDelimiter start="%[QWx]\z([~`!@#$%^&*_\-+=|\:;"',.?/]\)" end="\z1" skip="\\\\\|\\\z1" contains=@rubyStringSpecial nextgroup=@rubyModifier skipwhite
|
||||
SynFold '%' syn region rubyString matchgroup=rubyPercentStringDelimiter start="%[QWx]\={" end="}" skip="\\\\\|\\}" contains=@rubyStringSpecial,rubyNestedCurlyBraces
|
||||
SynFold '%' syn region rubyString matchgroup=rubyPercentStringDelimiter start="%[QWx]\=<" end=">" skip="\\\\\|\\>" contains=@rubyStringSpecial,rubyNestedAngleBrackets
|
||||
SynFold '%' syn region rubyString matchgroup=rubyPercentStringDelimiter start="%[QWx]\=\[" end="\]" skip="\\\\\|\\\]" contains=@rubyStringSpecial,rubyNestedSquareBrackets
|
||||
SynFold '%' syn region rubyString matchgroup=rubyPercentStringDelimiter start="%[QWx]\=(" end=")" skip="\\\\\|\\)" contains=@rubyStringSpecial,rubyNestedParentheses
|
||||
SynFold '%' syn region rubyString matchgroup=rubyPercentStringDelimiter start="%[Qx]\z(\s\)" end="\z1" skip="\\\\\|\\\z1" contains=@rubyStringSpecial
|
||||
|
||||
SynFold '%' syn region rubySymbol matchgroup=rubyPercentSymbolDelimiter start="%I\z([~`!@#$%^&*_\-+=|\:;"',.?/]\)" end="\z1" skip="\\\\\|\\\z1" contains=@rubyStringSpecial nextgroup=@rubyModifier skipwhite
|
||||
SynFold '%' syn region rubySymbol matchgroup=rubyPercentSymbolDelimiter start="%I{" end="}" skip="\\\\\|\\}" contains=@rubyStringSpecial,rubyNestedCurlyBraces
|
||||
SynFold '%' syn region rubySymbol matchgroup=rubyPercentSymbolDelimiter start="%I<" end=">" skip="\\\\\|\\>" contains=@rubyStringSpecial,rubyNestedAngleBrackets
|
||||
SynFold '%' syn region rubySymbol matchgroup=rubyPercentSymbolDelimiter start="%I\[" end="\]" skip="\\\\\|\\\]" contains=@rubyStringSpecial,rubyNestedSquareBrackets
|
||||
SynFold '%' syn region rubySymbol matchgroup=rubyPercentSymbolDelimiter start="%I(" end=")" skip="\\\\\|\\)" contains=@rubyStringSpecial,rubyNestedParentheses
|
||||
|
||||
" Here Documents {{{1
|
||||
syn region rubyHeredocStart matchgroup=rubyHeredocDelimiter start=+\%(\%(class\|::\|\.\@1<!\.\)\_s*\|\%([]})"'`]\)\s\|\w\)\@<!<<[-~]\=\zs\%(\%(\h\|[^\x00-\x7F]\)\%(\w\|[^\x00-\x7F]\)*\)+ end=+$+ oneline contains=ALLBUT,@rubyNotTop
|
||||
|
||||
syn region rubyHeredocStart matchgroup=rubyHeredocDelimiter start=+\%(\%(class\|::\|\.\@1<!\.\)\_s*\|\%([]})"'`]\)\s\|\w\)\@<!<<[-~]\=\zs"\%([^"]*\)"+ end=+$+ oneline contains=ALLBUT,@rubyNotTop
|
||||
syn region rubyHeredocStart matchgroup=rubyHeredocDelimiter start=+\%(\%(class\|::\|\.\@1<!\.\)\_s*\|\%([]})"'`]\)\s\|\w\)\@<!<<[-~]\=\zs'\%([^']*\)'+ end=+$+ oneline contains=ALLBUT,@rubyNotTop
|
||||
syn region rubyHeredocStart matchgroup=rubyHeredocDelimiter start=+\%(\%(class\|::\|\.\@1<!\.\)\_s*\|\%([]})"'`]\)\s\|\w\)\@<!<<[-~]\=\zs`\%([^`]*\)`+ end=+$+ oneline contains=ALLBUT,@rubyNotTop
|
||||
|
||||
SynFold '<<' syn region rubyString start=+\%(\%(class\|::\|\.\@1<!\.\)\_s*\|\%([]})"'`]\)\s\|\w\)\@<!<<\z(\%(\h\|[^\x00-\x7F]\)\%(\w\|[^\x00-\x7F]\)*\)\ze\%(.*<<[-~]\=['`"]\=\h\)\@!+hs=s+2 matchgroup=rubyHeredocDelimiter end=+^\z1$+ contains=rubyHeredocStart,@rubyStringSpecial keepend
|
||||
SynFold '<<' syn region rubyString start=+\%(\%(class\|::\|\.\@1<!\.\)\_s*\|\%([]})"'`]\)\s\|\w\)\@<!<<"\z([^"]*\)"\ze\%(.*<<[-~]\=['`"]\=\h\)\@!+hs=s+2 matchgroup=rubyHeredocDelimiter end=+^\z1$+ contains=rubyHeredocStart,@rubyStringSpecial keepend
|
||||
SynFold '<<' syn region rubyString start=+\%(\%(class\|::\|\.\@1<!\.\)\_s*\|\%([]})"'`]\)\s\|\w\)\@<!<<'\z([^']*\)'\ze\%(.*<<[-~]\=['`"]\=\h\)\@!+hs=s+2 matchgroup=rubyHeredocDelimiter end=+^\z1$+ contains=rubyHeredocStart keepend
|
||||
SynFold '<<' syn region rubyString start=+\%(\%(class\|::\|\.\@1<!\.\)\_s*\|\%([]})"'`]\)\s\|\w\)\@<!<<`\z([^`]*\)`\ze\%(.*<<[-~]\=['`"]\=\h\)\@!+hs=s+2 matchgroup=rubyHeredocDelimiter end=+^\z1$+ contains=rubyHeredocStart,@rubyStringSpecial keepend
|
||||
|
||||
SynFold '<<' syn region rubyString start=+\%(\%(class\|::\|\.\@1<!\.\)\_s*\|\%([]})]\)\s\|\w\)\@<!<<[-~]\z(\%(\h\|[^\x00-\x7F]\)\%(\w\|[^\x00-\x7F]\)*\)\ze\%(.*<<[-~]\=['`"]\=\h\)\@!+hs=s+3 matchgroup=rubyHeredocDelimiter end=+^\s*\zs\z1$+ contains=rubyHeredocStart,@rubyStringSpecial keepend
|
||||
SynFold '<<' syn region rubyString start=+\%(\%(class\|::\|\.\@1<!\.\)\_s*\|\%([]})]\)\s\|\w\)\@<!<<[-~]"\z([^"]*\)"\ze\%(.*<<[-~]\=['`"]\=\h\)\@!+hs=s+3 matchgroup=rubyHeredocDelimiter end=+^\s*\zs\z1$+ contains=rubyHeredocStart,@rubyStringSpecial keepend
|
||||
SynFold '<<' syn region rubyString start=+\%(\%(class\|::\|\.\@1<!\.\)\_s*\|\%([]})]\)\s\|\w\)\@<!<<[-~]'\z([^']*\)'\ze\%(.*<<[-~]\=['`"]\=\h\)\@!+hs=s+3 matchgroup=rubyHeredocDelimiter end=+^\s*\zs\z1$+ contains=rubyHeredocStart keepend
|
||||
SynFold '<<' syn region rubyString start=+\%(\%(class\|::\|\.\@1<!\.\)\_s*\|\%([]})]\)\s\|\w\)\@<!<<[-~]`\z([^`]*\)`\ze\%(.*<<[-~]\=['`"]\=\h\)\@!+hs=s+3 matchgroup=rubyHeredocDelimiter end=+^\s*\zs\z1$+ contains=rubyHeredocStart,@rubyStringSpecial keepend
|
||||
|
||||
" Module, Class, Method and Alias Declarations {{{1
|
||||
syn match rubyAliasDeclaration "[^[:space:];#.()]\+" contained contains=rubySymbol,@rubyGlobalVariable nextgroup=rubyAliasDeclaration2 skipwhite
|
||||
syn match rubyAliasDeclaration2 "[^[:space:];#.()]\+" contained contains=rubySymbol,@rubyGlobalVariable
|
||||
syn match rubyMethodDeclaration "[^[:space:];#(]\+" contained contains=rubyConstant,rubyBoolean,rubyPseudoVariable,rubyInstanceVariable,rubyClassVariable,rubyGlobalVariable
|
||||
syn match rubyClassDeclaration "[^[:space:];#<]\+" contained contains=rubyClassName,rubyScopeOperator nextgroup=rubySuperClassOperator skipwhite
|
||||
syn match rubyModuleDeclaration "[^[:space:];#<]\+" contained contains=rubyModuleName,rubyScopeOperator
|
||||
|
||||
syn match rubyMethodName "\<\%([_[:alpha:]]\|[^\x00-\x7F]\)\%([_[:alnum:]]\|[^\x00-\x7F]\)*[?!=]\=\%([[:alnum:]_.:?!=]\|[^\x00-\x7F]\)\@!" contained containedin=rubyMethodDeclaration
|
||||
syn match rubyMethodName "\%(\s\|^\)\@1<=\%([_[:alpha:]]\|[^\x00-\x7F]\)\%([_[:alnum:]]\|[^\x00-\x7F]\)*[?!=]\=\%(\s\|$\)\@=" contained containedin=rubyAliasDeclaration,rubyAliasDeclaration2
|
||||
syn match rubyMethodName "\%([[:space:].]\|^\)\@1<=\%(\[\]=\=\|\*\*\|[-+!~]@\=\|[*/%|&^~]\|<<\|>>\|[<>]=\=\|<=>\|===\|[=!]=\|[=!]\~\|!\|`\)\%([[:space:];#(]\|$\)\@=" contained containedin=rubyAliasDeclaration,rubyAliasDeclaration2,rubyMethodDeclaration
|
||||
|
||||
syn cluster rubyDeclaration contains=rubyAliasDeclaration,rubyAliasDeclaration2,rubyMethodDeclaration,rubyModuleDeclaration,rubyClassDeclaration,rubyMethodName
|
||||
|
||||
" Keywords {{{1
|
||||
" TODO: reorganise
|
||||
syn match rubyControl "\%#=1\<\%(break\|in\|next\|redo\|retry\|return\)\>"
|
||||
syn match rubyKeyword "\%#=1\<\%(super\|yield\)\>"
|
||||
syn match rubyBoolean "\%#=1\<\%(true\|false\)\>[?!]\@!"
|
||||
syn match rubyPseudoVariable "\%#=1\<\(self\|nil\)\>[?!]\@!"
|
||||
syn match rubyPseudoVariable "\%#=1\<__\%(ENCODING\|dir\|FILE\|LINE\|callee\|method\)__\>"
|
||||
syn match rubyBeginEnd "\%#=1\<\%(BEGIN\|END\)\>"
|
||||
|
||||
" Expensive Mode {{{1
|
||||
" Match 'end' with the appropriate opening keyword for syntax based folding
|
||||
" and special highlighting of module/class/method definitions
|
||||
if !exists("b:ruby_no_expensive") && !exists("ruby_no_expensive")
|
||||
syn match rubyDefine "\<alias\>" nextgroup=rubyAliasDeclaration skipwhite skipnl
|
||||
syn match rubyDefine "\<def\>" nextgroup=rubyMethodDeclaration skipwhite skipnl
|
||||
syn match rubyDefine "\<undef\>" nextgroup=rubyMethodName skipwhite skipnl
|
||||
syn match rubyClass "\<class\>" nextgroup=rubyClassDeclaration,rubyEigenClassOperator skipwhite skipnl
|
||||
syn match rubyModule "\<module\>" nextgroup=rubyModuleDeclaration skipwhite skipnl
|
||||
|
||||
SynFold 'def' syn region rubyMethodBlock start="\<def\>" matchgroup=rubyDefine skip="\<end:\|\%(\<def\_s\+\)\@<=end\>" end="\<end\>" contains=ALLBUT,@rubyNotTop
|
||||
SynFold 'class' syn region rubyClassBlock start="\<class\>" matchgroup=rubyClass skip="\<end:" end="\<end\>" contains=ALLBUT,@rubyNotTop
|
||||
SynFold 'module' syn region rubyModuleBlock start="\<module\>" matchgroup=rubyModule skip="\<end:" end="\<end\>" contains=ALLBUT,@rubyNotTop
|
||||
|
||||
" modifiers
|
||||
syn match rubyLineContinuation "\\$" nextgroup=@rubyModifier skipwhite skipnl
|
||||
syn match rubyConditionalModifier "\<\%(if\|unless\)\>"
|
||||
syn match rubyRepeatModifier "\<\%(while\|until\)\>"
|
||||
syn match rubyRescueModifier "\<rescue\>"
|
||||
|
||||
syn cluster rubyModifier contains=rubyConditionalModifier,rubyRepeatModifier,rubyRescueModifier
|
||||
|
||||
SynFold 'do' syn region rubyDoBlock matchgroup=rubyControl start="\<do\>" skip="\<end:" end="\<end\>" contains=ALLBUT,@rubyNotTop
|
||||
|
||||
" curly bracket block or hash literal
|
||||
SynFold '{' syn region rubyCurlyBlock matchgroup=rubyCurlyBlockDelimiter start="{" end="}" contains=ALLBUT,@rubyNotTop
|
||||
SynFold '[' syn region rubyArrayLiteral matchgroup=rubyArrayDelimiter start="\%(\%(\w\|[^\x00-\x7F]\)[?!]\=\|[]})]\)\@2<!\[" end="]" contains=ALLBUT,@rubyNotTop
|
||||
|
||||
" statements without 'do'
|
||||
SynFold 'begin' syn region rubyBlockExpression matchgroup=rubyControl start="\<begin\>" skip="\<end:" end="\<end\>" contains=ALLBUT,@rubyNotTop
|
||||
SynFold 'case' syn region rubyCaseExpression matchgroup=rubyConditional start="\<case\>" skip="\<end:" end="\<end\>" contains=ALLBUT,@rubyNotTop
|
||||
|
||||
SynFold 'if' syn region rubyConditionalExpression matchgroup=rubyConditional start="\%(\%(^\|\.\.\.\=\|[{:,;([<>~\*/%&^|+=-]\|\<then\s\|\%(\<\%(\h\|[^\x00-\x7F]\)\%(\w\|[^\x00-\x7F]\)*\)\@<![?!]\)\s*\)\@<=\%(if\|unless\)\>" skip="\<end:" end="\<end\>" contains=ALLBUT,@rubyNotTop
|
||||
|
||||
syn match rubyConditional "\<\%(then\|else\|when\)\>" contained containedin=rubyCaseExpression
|
||||
syn match rubyConditional "\<\%(then\|else\|elsif\)\>" contained containedin=rubyConditionalExpression
|
||||
|
||||
syn match rubyExceptionHandler "\<\%(\%(\%(;\|^\)\s*\)\@<=rescue\|else\|ensure\)\>" contained containedin=rubyBlockExpression,rubyDoBlock
|
||||
syn match rubyExceptionHandler2 "\<\%(\%(\%(;\|^\)\s*\)\@<=rescue\|else\|ensure\)\>" contained containedin=rubyModuleBlock,rubyClassBlock,rubyMethodBlock
|
||||
syn cluster rubyExceptionHandler contains=rubyExceptionHandler,rubyExceptionHandler2
|
||||
|
||||
" statements with optional 'do'
|
||||
syn region rubyOptionalDoLine matchgroup=rubyRepeat start="\<for\>" start="\%(\%(^\|\.\.\.\=\|[{:,;([<>~\*/%&^|+=-]\|\%(\<\%(\h\|[^\x00-\x7F]\)\%(\w\|[^\x00-\x7F]\)*\)\@<![!?]\)\s*\)\@<=\<\%(until\|while\)\>" matchgroup=rubyOptionalDo end="\<do\>" end="\ze\%(;\|$\)" oneline contains=ALLBUT,@rubyNotTop
|
||||
|
||||
SynFold 'for' syn region rubyRepeatExpression start="\<for\>" start="\%(\%(^\|\.\.\.\=\|[{:,;([<>~\*/%&^|+=-]\|\%(\<\%(\h\|[^\x00-\x7F]\)\%(\w\|[^\x00-\x7F]\)*\)\@<![!?]\)\s*\)\@<=\<\%(until\|while\)\>" matchgroup=rubyRepeat skip="\<end:" end="\<end\>" contains=ALLBUT,@rubyNotTop nextgroup=rubyOptionalDoLine
|
||||
|
||||
if !exists("ruby_minlines")
|
||||
let ruby_minlines = 500
|
||||
endif
|
||||
exe "syn sync minlines=" . ruby_minlines
|
||||
|
||||
else
|
||||
syn match rubyControl "\<def\>" nextgroup=rubyMethodDeclaration skipwhite skipnl
|
||||
syn match rubyControl "\<class\>" nextgroup=rubyClassDeclaration skipwhite skipnl
|
||||
syn match rubyControl "\<module\>" nextgroup=rubyModuleDeclaration skipwhite skipnl
|
||||
syn match rubyControl "\<\%(case\|begin\|do\|for\|if\|unless\|while\|until\|else\|elsif\|rescue\|ensure\|then\|when\|end\)\>"
|
||||
syn match rubyKeyword "\<\%(alias\|undef\)\>"
|
||||
endif
|
||||
|
||||
" Special Methods {{{1
|
||||
if !exists("ruby_no_special_methods")
|
||||
syn match rubyAccess "\<\%(public\|protected\|private\)\>" " use re=2
|
||||
syn match rubyAccess "\%#=1\<\%(public\|private\)_class_method\>"
|
||||
syn match rubyAccess "\%#=1\<\%(public\|private\)_constant\>"
|
||||
syn match rubyAccess "\%#=1\<module_function\>"
|
||||
syn match rubyAttribute "\%#=1\%(\%(^\|;\)\s*\)\@<=attr\>\(\s*[.=]\)\@!" " attr is a common variable name
|
||||
syn match rubyAttribute "\%#=1\<attr_\%(accessor\|reader\|writer\)\>"
|
||||
syn match rubyControl "\%#=1\<\%(abort\|at_exit\|exit\|fork\|loop\|trap\)\>"
|
||||
syn match rubyEval "\%#=1\<eval\>"
|
||||
syn match rubyEval "\%#=1\<\%(class\|instance\|module\)_eval\>"
|
||||
syn match rubyException "\%#=1\<\%(raise\|fail\|catch\|throw\)\>"
|
||||
syn match rubyInclude "\%#=1\<\%(autoload\|gem\|load\|require\%(_relative\)\=\)\>"
|
||||
syn match rubyKeyword "\%#=1\<\%(callcc\|caller\|lambda\|proc\)\>"
|
||||
syn match rubyMacro "\%#=1\<\%(extend\|include\|prepend\|refine\|using\)\>"
|
||||
syn match rubyMacro "\%#=1\<\%(alias\|define\|define_singleton\|remove\|undef\)_method\>"
|
||||
endif
|
||||
|
||||
" Comments and Documentation {{{1
|
||||
syn match rubySharpBang "\%^#!.*" display
|
||||
syn keyword rubyTodo FIXME NOTE TODO OPTIMIZE HACK REVIEW XXX todo contained
|
||||
syn match rubyEncoding "[[:alnum:]-_]\+" contained display
|
||||
syn match rubyMagicComment "\c\%<3l#\s*\zs\%(coding\|encoding\):" contained nextgroup=rubyEncoding skipwhite
|
||||
syn match rubyMagicComment "\c\%<10l#\s*\zs\%(frozen_string_literal\|warn_indent\|warn_past_scope\):" contained nextgroup=rubyBoolean skipwhite
|
||||
syn match rubyMagicComment "\c\%<10l#\s*\zs\%(shareable_constant_value\):" contained nextgroup=rubyEncoding skipwhite
|
||||
syn match rubyComment "#.*" contains=@rubyCommentSpecial,rubySpaceError,@Spell
|
||||
|
||||
syn cluster rubyCommentSpecial contains=rubySharpBang,rubyTodo,rubyMagicComment
|
||||
syn cluster rubyCommentNotTop contains=@rubyCommentSpecial,rubyEncoding
|
||||
|
||||
if !exists("ruby_no_comment_fold") && s:foldable('#')
|
||||
syn region rubyMultilineComment start="^\s*#.*\n\%(^\s*#\)\@=" end="^\s*#.*\n\%(^\s*#\)\@!" contains=rubyComment transparent fold keepend
|
||||
syn region rubyDocumentation start="^=begin\ze\%(\s.*\)\=$" end="^=end\%(\s.*\)\=$" contains=rubySpaceError,rubyTodo,@Spell fold
|
||||
else
|
||||
syn region rubyDocumentation start="^=begin\s*$" end="^=end\s*$" contains=rubySpaceError,rubyTodo,@Spell
|
||||
endif
|
||||
|
||||
" {{{1 Useless Line Continuations
|
||||
syn match rubyUselessLineContinuation "\%([.:,;{([<>~\*%&^|+=-]\|%(\%(\w\|[^\x00-\x7F]\)\@1<![?!]\)\s*\zs\\$" nextgroup=rubyUselessLineContinuation skipwhite skipempty
|
||||
syn match rubyUselessLineContinuation "\\$" nextgroup=rubyUselessLineContinuation skipwhite skipempty contained
|
||||
|
||||
" Keyword Nobbling {{{1
|
||||
" prevent methods with keyword names being highlighted as keywords when called
|
||||
syn match rubyKeywordAsMethod "\%(\%(\.\@1<!\.\)\|&\.\|::\)\_s*\%([_[:lower:]][_[:alnum:]]*\|\%(BEGIN\|END\)\>\)" transparent contains=rubyDotOperator,rubyScopeOperator
|
||||
|
||||
" Bang and Predicate Methods and Operators {{{1
|
||||
syn match rubyBangPredicateMethod "\%(\h\|[^\x00-\x7F]\)\%(\w\|[^\x00-\x7F]\)*[?!]"
|
||||
|
||||
if !exists("ruby_no_special_methods")
|
||||
syn match rubyControl "\%#=1\<exit!" display
|
||||
endif
|
||||
syn match rubyDefinedOperator "\%#=1\<defined?" display
|
||||
|
||||
" 1.9-style Hash Keys and Keyword Parameters {{{1
|
||||
syn match rubySymbol "\%(\w\|[^\x00-\x7F]\)\%(\w\|[^\x00-\x7F]\)*[?!]\=::\@!"he=e-1 contained containedin=rubyBlockParameterList,rubyCurlyBlock
|
||||
syn match rubySymbol "[]})\"':]\@1<!\<\%(\h\|[^\x00-\x7F]\)\%(\w\|[^\x00-\x7F]\)*[!?]\=:[[:space:],;]\@="he=e-1
|
||||
syn match rubySymbol "[[:space:],{(]\%(\h\|[^\x00-\x7F]\)\%(\w\|[^\x00-\x7F]\)*[!?]\=:[[:space:],;]\@="hs=s+1,he=e-1
|
||||
syn match rubySingleQuoteSymbolDelimiter "'" contained
|
||||
syn match rubySymbol "'\%(\\.\|[^']\)*'::\@!"he=e-1 contains=rubyQuoteEscape,rubyBackslashEscape,rubySingleQuoteSymbolDelimiter
|
||||
syn match rubyDoubleQuoteSymbolDelimiter "\"" contained
|
||||
syn match rubySymbol "\"\%(\\.\|[^\"]\)*\"::\@!"he=e-1 contains=@rubyStringSpecial,rubyDoubleQuoteSymbolDelimiter
|
||||
|
||||
" __END__ Directive {{{1
|
||||
SynFold '__END__' syn region rubyData matchgroup=rubyDataDirective start="^__END__$" end="\%$"
|
||||
|
||||
" Default Highlighting {{{1
|
||||
hi def link rubyClass rubyDefine
|
||||
hi def link rubyModule rubyDefine
|
||||
hi def link rubyExceptionHandler2 rubyDefine
|
||||
hi def link rubyDefine Define
|
||||
hi def link rubyAccess rubyMacro
|
||||
hi def link rubyAttribute rubyMacro
|
||||
hi def link rubyMacro Macro
|
||||
hi def link rubyMethodName rubyFunction
|
||||
hi def link rubyFunction Function
|
||||
hi def link rubyConditional Conditional
|
||||
hi def link rubyConditionalModifier rubyConditional
|
||||
hi def link rubyExceptionHandler rubyConditional
|
||||
hi def link rubyRescueModifier rubyExceptionHandler
|
||||
hi def link rubyRepeat Repeat
|
||||
hi def link rubyRepeatModifier rubyRepeat
|
||||
hi def link rubyOptionalDo rubyRepeat
|
||||
hi def link rubyControl Statement
|
||||
hi def link rubyInclude Include
|
||||
hi def link rubyInteger Number
|
||||
hi def link rubyCharacter Character
|
||||
hi def link rubyFloat Float
|
||||
hi def link rubyBoolean Boolean
|
||||
hi def link rubyException Exception
|
||||
if !exists("ruby_no_identifiers")
|
||||
hi def link rubyIdentifier Identifier
|
||||
else
|
||||
hi def link rubyIdentifier NONE
|
||||
endif
|
||||
hi def link rubyClassVariable rubyIdentifier
|
||||
hi def link rubyConstant Type
|
||||
hi def link rubyClassName rubyConstant
|
||||
hi def link rubyModuleName rubyConstant
|
||||
hi def link rubyGlobalVariable rubyIdentifier
|
||||
hi def link rubyInstanceVariable rubyIdentifier
|
||||
hi def link rubyPredefinedIdentifier rubyIdentifier
|
||||
hi def link rubyPredefinedConstant rubyPredefinedIdentifier
|
||||
hi def link rubyPredefinedVariable rubyPredefinedIdentifier
|
||||
hi def link rubySymbol Constant
|
||||
hi def link rubyKeyword Keyword
|
||||
|
||||
hi def link rubyOperator Operator
|
||||
hi def link rubyDefinedOperator rubyOperator
|
||||
hi def link rubyEnglishBooleanOperator rubyOperator
|
||||
if exists("ruby_operators")
|
||||
hi def link rubyTernaryOperator rubyOperator
|
||||
hi def link rubyArithmeticOperator rubyOperator
|
||||
hi def link rubyComparisonOperator rubyOperator
|
||||
hi def link rubyBitwiseOperator rubyOperator
|
||||
hi def link rubyBooleanOperator rubyOperator
|
||||
hi def link rubyRangeOperator rubyOperator
|
||||
hi def link rubyAssignmentOperator rubyOperator
|
||||
hi def link rubyEqualityOperator rubyOperator
|
||||
endif
|
||||
|
||||
if exists("ruby_pseudo_operators")
|
||||
hi def link rubyPseudoOperator Special
|
||||
hi def link rubyDotOperator rubyPseudoOperator
|
||||
hi def link rubyScopeOperator rubyPseudoOperator
|
||||
hi def link rubySuperClassOperator rubyPseudoOperator
|
||||
hi def link rubyEigenClassOperator rubyPseudoOperator
|
||||
hi def link rubyLambdaOperator rubyPseudoOperator
|
||||
hi def link rubyDoubleSplatOperator rubyPseudoOperator
|
||||
hi def link rubySplatOperator rubyPseudoOperator
|
||||
hi def link rubyProcOperator rubyPseudoOperator
|
||||
endif
|
||||
|
||||
hi def link rubyBeginEnd Statement
|
||||
hi def link rubyEval Statement
|
||||
hi def link rubyPseudoVariable Constant
|
||||
hi def link rubyCapitalizedMethod NONE
|
||||
|
||||
hi def link rubyComment Comment
|
||||
hi def link rubyEncoding Constant
|
||||
hi def link rubyMagicComment SpecialComment
|
||||
hi def link rubyData Comment
|
||||
hi def link rubyDataDirective Delimiter
|
||||
hi def link rubyDocumentation Comment
|
||||
hi def link rubyTodo Todo
|
||||
|
||||
hi def link rubyBackslashEscape rubyStringEscape
|
||||
hi def link rubyQuoteEscape rubyStringEscape
|
||||
hi def link rubySpaceEscape rubyStringEscape
|
||||
hi def link rubyParenthesisEscape rubyStringEscape
|
||||
hi def link rubyCurlyBraceEscape rubyStringEscape
|
||||
hi def link rubyAngleBracketEscape rubyStringEscape
|
||||
hi def link rubySquareBracketEscape rubyStringEscape
|
||||
hi def link rubyStringEscape Special
|
||||
|
||||
hi def link rubyInterpolationDelimiter Delimiter
|
||||
hi def link rubySharpBang PreProc
|
||||
hi def link rubyStringDelimiter Delimiter
|
||||
hi def link rubyHeredocDelimiter rubyStringDelimiter
|
||||
hi def link rubyPercentRegexpDelimiter rubyRegexpDelimiter
|
||||
hi def link rubyPercentStringDelimiter rubyStringDelimiter
|
||||
hi def link rubyPercentSymbolDelimiter rubySymbolDelimiter
|
||||
hi def link rubyDoubleQuoteSymbolDelimiter rubySymbolDelimiter
|
||||
hi def link rubySingleQuoteSymbolDelimiter rubySymbolDelimiter
|
||||
hi def link rubyRegexpDelimiter rubyStringDelimiter
|
||||
hi def link rubySymbolDelimiter rubySymbol
|
||||
hi def link rubyString String
|
||||
hi def link rubyRegexpEscape rubyRegexpSpecial
|
||||
hi def link rubyRegexpQuantifier rubyRegexpSpecial
|
||||
hi def link rubyRegexpAnchor rubyRegexpSpecial
|
||||
hi def link rubyRegexpDot rubyRegexpCharClass
|
||||
hi def link rubyRegexpCharClass rubyRegexpSpecial
|
||||
hi def link rubyRegexpIntersection rubyRegexpSpecial
|
||||
hi def link rubyRegexpSpecial Special
|
||||
hi def link rubyRegexpComment Comment
|
||||
hi def link rubyRegexp rubyString
|
||||
|
||||
hi def link rubyError Error
|
||||
if exists("ruby_line_continuation_error")
|
||||
hi def link rubyUselessLineContinuation rubyError
|
||||
endif
|
||||
hi def link rubyGlobalVariableError rubyError
|
||||
hi def link rubySpaceError rubyError
|
||||
|
||||
" Postscript {{{1
|
||||
let b:current_syntax = "ruby"
|
||||
|
||||
let &cpo = s:cpo_sav
|
||||
unlet! s:cpo_sav
|
||||
|
||||
delc SynFold
|
||||
|
||||
" vim: nowrap sw=2 sts=2 ts=8 noet fdm=marker:
|
Reference in New Issue
Block a user