Browse Source

add more ruby stuff

git-svn-id: file:///home/pjones/src/tmp/b2-svn/vimrc/trunk@224 637e2b85-2e0a-0410-84ac-bd785500051d
master
pjones 13 years ago
parent
commit
9b6093f46e
13 changed files with 1164 additions and 156 deletions
  1. 47
    0
      compiler/eruby.vim
  2. 73
    0
      compiler/ruby.vim
  3. 41
    0
      compiler/rubyunit.vim
  4. 8
    0
      ftdetect/ruby.vim
  5. 79
    0
      ftplugin/eruby.vim
  6. 126
    0
      ftplugin/ruby.vim
  7. 20
    0
      indent/eruby.vim
  8. 377
    0
      indent/ruby.vim
  9. 8
    4
      install.sh
  10. 0
    39
      plugin/eruby.vim
  11. 29
    113
      plugin/matchit.vim
  12. 64
    0
      syntax/eruby.vim
  13. 292
    0
      syntax/ruby.vim

+ 47
- 0
compiler/eruby.vim View File

@@ -0,0 +1,47 @@
" Vim compiler file
" Language: eRuby
" Maintainer: Doug Kearns <djkea2 at gus.gscit.monash.edu.au>
" Info: $Id: eruby.vim,v 1.4 2005/09/21 13:43:54 dkearns Exp $
" URL: http://vim-ruby.sourceforge.net
" Anon CVS: See above site
" Licence: GPL (http://www.gnu.org)
" Disclaimer:
" This program is distributed in the hope that it will be useful,
" but WITHOUT ANY WARRANTY; without even the implied warranty of
" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
" GNU General Public License for more details.
" ----------------------------------------------------------------------------

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%\tfrom\ %f:%l:in\ %.%#,
\%-Z%\tfrom\ %f:%l,
\%-Z%p^,
\%-G%.%#

let &cpo = s:cpo_save
unlet s:cpo_save

" vim: nowrap sw=2 sts=2 ts=8 ff=unix:

+ 73
- 0
compiler/ruby.vim View File

@@ -0,0 +1,73 @@
" Vim compiler file
" Language: Ruby
" Function: Syntax check and/or error reporting
" Maintainer: Tim Hammerquist <timh at rubyforge.org>
" Info: $Id: ruby.vim,v 1.11 2005/10/04 11:11:34 dkearns Exp $
" URL: http://vim-ruby.rubyforge.org
" Anon CVS: See above site
" Licence: GPL (http://www.gnu.org)
" Disclaimer:
" This program is distributed in the hope that it will be useful,
" but WITHOUT ANY WARRANTY; without even the implied warranty of
" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
" GNU General Public License for more details.
" ----------------------------------------------------------------------------
"
" Changelog:
" 0.2: script saves and restores 'cpoptions' value to prevent problems with
" line continuations
" 0.1: initial release
"
" Contributors:
" Hugh Sasse <hgs@dmu.ac.uk>
" Doug Kearns <djkea2@gus.gscit.monash.edu.au>
"
" Todo:
" match error type %m
"
" Comments:
" I know this file isn't perfect. If you have any questions, suggestions,
" patches, etc., please don't hesitate to let me know.
"
" This is my first experience with 'errorformat' and compiler plugins and
" I welcome any input from more experienced (or clearer-thinking)
" individuals.
" ----------------------------------------------------------------------------

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\ -wc\ $*
"
" or add '-c' at :make command line:
"
" :make -c %<CR>
"
CompilerSet makeprg=ruby\ -w\ $*

CompilerSet errorformat=
\%+E%f:%l:\ parse\ error,
\%W%f:%l:\ warning:\ %m,
\%E%f:%l:in\ %*[^:]:\ %m,
\%E%f:%l:\ %m,
\%-C%\tfrom\ %f:%l:in\ %.%#,
\%-Z%\tfrom\ %f:%l,
\%-Z%p^,
\%-G%.%#

let &cpo = s:cpo_save
unlet s:cpo_save

" vim: nowrap sw=2 sts=2 ts=8 ff=unix:

+ 41
- 0
compiler/rubyunit.vim View File

@@ -0,0 +1,41 @@
" Vim compiler file
" Language: Test::Unit - Ruby Unit Testing Framework
" Maintainer: Doug Kearns <djkea2 at gus.gscit.monash.edu.au>
" Info: $Id: rubyunit.vim,v 1.9 2005/10/04 11:11:34 dkearns Exp $
" URL: http://vim-ruby.sourceforge.net
" Anon CVS: See above site
" Licence: GPL (http://www.gnu.org)
" Disclaimer:
" This program is distributed in the hope that it will be useful,
" but WITHOUT ANY WARRANTY; without even the implied warranty of
" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
" GNU General Public License for more details.
" ----------------------------------------------------------------------------

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 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 ff=unix:

+ 8
- 0
ftdetect/ruby.vim View File

@@ -0,0 +1,8 @@
" Ruby
au BufNewFile,BufRead *.rb,*.rbw,*.gem,*.gemspec set filetype=ruby

" Rakefile
au BufNewFile,BufRead [rR]akefile* set filetype=ruby

" eRuby
au BufNewFile,BufRead *.rhtml set filetype=eruby

+ 79
- 0
ftplugin/eruby.vim View File

@@ -0,0 +1,79 @@
" Vim filetype plugin
" Language: eRuby
" Maintainer: Doug Kearns <djkea2 at gus.gscit.monash.edu.au>
" Info: $Id: eruby.vim,v 1.3 2005/10/04 11:11:34 dkearns Exp $
" URL: http://vim-ruby.sourceforge.net
" Anon CVS: See above site
" Licence: GPL (http://www.gnu.org)
" Disclaimer:
" This program is distributed in the hope that it will be useful,
" but WITHOUT ANY WARRANTY; without even the implied warranty of
" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
" GNU General Public License for more details.
" ----------------------------------------------------------------------------

" 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 = "Ruby Files (*.rb)\t*.rb\n" .
\ "HTML Files (*.html, *.htm)\t*.html;*.htm\n" .
\ "All Files (*.*)\t*.*\n"
let s:match_words = ""

runtime! ftplugin/html.vim ftplugin/html_*.vim ftplugin/html/*.vim
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

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 = b:browsefilter . s:browsefilter
endif
if exists("b:match_words")
let s:match_words = b:match_words . ',' . s:match_words
endif

" Change the browse dialog on Win32 to show mainly eRuby-related files
if has("gui_win32")
let b:browsefilter="eRuby Files (*.rhtml)\t*.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

" vim: nowrap sw=2 sts=2 ts=8 ff=unix:

+ 126
- 0
ftplugin/ruby.vim View File

@@ -0,0 +1,126 @@
" Vim filetype plugin
" Language: Ruby
" Maintainer: Gavin Sinclair <gsinclair at soyabean.com.au>
" Info: $Id: ruby.vim,v 1.17 2005/10/06 07:13:52 dkearns Exp $
" URL: http://vim-ruby.sourceforge.net
" Anon CVS: See above site
" Licence: GPL (http://www.gnu.org)
" Disclaimer:
" This program is distributed in the hope that it will be useful,
" but WITHOUT ANY WARRANTY; without even the implied warranty of
" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
" GNU General Public License for more details.
" ----------------------------------------------------------------------------
"
" Original matchit support thanks to Ned Konz. See his ftplugin/ruby.vim at
" http://bike-nomad.com/vim/ruby.vim.
" ----------------------------------------------------------------------------

" Only do this when not done yet for this buffer
if (exists("b:did_ftplugin"))
finish
endif
let b:did_ftplugin = 1

let s:cpo_save = &cpo
set cpo&vim

" Matchit support
if exists("loaded_matchit") && !exists("b:match_words")
let b:match_ignorecase = 0

" TODO: improve optional do loops
let b:match_words =
\ '\%(' .
\ '\%(\%(\.\|\:\:\)\s*\|\:\)\@<!\<\%(class\|module\|begin\|def\|case\|for\|do\)\>' .
\ '\|' .
\ '\%(\%(^\|\.\.\.\=\|[\,;=([<>~\*/%!&^|+-]\)\s*\)\@<=\%(if\|unless\|until\|while\)\>' .
\ '\)' .
\ ':' .
\ '\%(' .
\ '\%(\%(\.\|\:\:\)\s*\|\:\)\@<!\<\%(else\|elsif\|ensure\|when\)\>' .
\ '\|' .
\ '\%(\%(^\|;\)\s*\)\@<=\<rescue\>' .
\ '\)' .
\ ':' .
\ '\%(\%(\.\|\:\:\)\s*\|\:\)\@<!\<end\>'

let b:match_skip =
\ "synIDattr(synID(line('.'),col('.'),0),'name') =~ '" .
\ "\\<ruby\\%(String\\|StringDelimiter\\|ASCIICode\\|Interpolation\\|" .
\ "NoInterpolation\\|Escape\\|Comment\\|Documentation\\)\\>'"

endif

setlocal formatoptions-=t formatoptions+=croql

setlocal include=^\\s*\\<\\(load\\\|\w*require\\)\\>
setlocal includeexpr=substitute(substitute(v:fname,'::','/','g'),'$','.rb','')
setlocal suffixesadd=.rb

" TODO:
"setlocal define=^\\s*def

setlocal comments=:#
setlocal commentstring=#\ %s

if !exists("s:rubypath")
if executable("ruby")
let s:code = "print ($: + begin; require %q{rubygems}; Gem.all_load_paths.sort.uniq; rescue LoadError; []; end).join(%q{,})"
if &shellxquote == "'"
let s:rubypath = system('ruby -e "' . s:code . '"')
else
let s:rubypath = system("ruby -e '" . s:code . "'")
endif
let s:rubypath = '.,' . substitute(s:rubypath, '\%(^\|,\)\.\%(,\|$\)', ',,', '')
else
" If we can't call ruby to get its path, just default to using the
" current directory and the directory of the current file.
let s:rubypath = ".,,"
endif
endif

let &l:path = s:rubypath

if has("gui_win32") && !exists("b:browsefilter")
let b:browsefilter = "Ruby Source Files (*.rb)\t*.rb\n" .
\ "All Files (*.*)\t*.*\n"
endif

let b:undo_ftplugin = "setl fo< inc< inex< sua< def< com< cms< path< "
\ "| unlet! b:browsefilter b:match_ignorecase b:match_words b:match_skip"

let &cpo = s:cpo_save
unlet s:cpo_save

"
" 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 ff=unix:

+ 20
- 0
indent/eruby.vim View File

@@ -0,0 +1,20 @@
" Vim indent file
" Language: Ruby
" Maintainer: Doug Kearns <djkea2 at gus.gscit.monash.edu.au>
" Info: $Id: eruby.vim,v 1.2 2005/10/04 11:11:34 dkearns Exp $
" URL: http://vim-ruby.rubyforge.org/
" Anon CVS: See above site
" Licence: GPL (http://www.gnu.org)
" Disclaimer:
" This program is distributed in the hope that it will be useful,
" but WITHOUT ANY WARRANTY; without even the implied warranty of
" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
" GNU General Public License for more details.
" ----------------------------------------------------------------------------

" Only load this indent file when no other was loaded.
if exists("b:did_indent")
finish
endif

runtime! indent/html.vim

+ 377
- 0
indent/ruby.vim View File

@@ -0,0 +1,377 @@
" Vim indent file
" Language: Ruby
" Maintainer: Gavin Sinclair <gsinclair at soyabean.com.au>
" Developer: Nikolai Weibull <source at pcppopper.org>
" Info: $Id: ruby.vim,v 1.32 2005/10/04 11:11:34 dkearns Exp $
" URL: http://vim-ruby.rubyforge.org/
" Anon CVS: See above site
" Licence: GPL (http://www.gnu.org)
" Disclaimer:
" This program is distributed in the hope that it will be useful,
" but WITHOUT ANY WARRANTY; without even the implied warranty of
" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
" GNU General Public License for more details.
" ----------------------------------------------------------------------------

" 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

" Now, set up our indentation expression and keys that trigger it.
setlocal indentexpr=GetRubyIndent()
setlocal indentkeys=0{,0},0),0],!^F,o,O,e
setlocal indentkeys+==end,=elsif,=when,=ensure,=rescue,==begin,==end

" Only define the function once.
if exists("*GetRubyIndent")
finish
endif

let s:cpo_save = &cpo
set cpo&vim

" 1. Variables {{{1
" ============

" Regex of syntax group names that are or delimit string or are comments.
let s:syng_strcom = '\<ruby\%(String\|StringDelimiter\|ASCIICode' .
\ '\|Interpolation\|NoInterpolation\|Escape\|Comment\|Documentation\)\>'

" Regex of syntax group names that are strings or comments.
let s:syng_strcom2 = '\<ruby\%(String' .
\ '\|Interpolation\|NoInterpolation\|Escape\|Comment\|Documentation\)\>'

" Regex of syntax group names that are strings.
let s:syng_string =
\ '\<ruby\%(String\|Interpolation\|NoInterpolation\|Escape\)\>'

" Regex of syntax group names that are strings or documentation.
let s:syng_stringdoc =
\'\<ruby\%(String\|Interpolation\|NoInterpolation\|Escape\|Documentation\)\>'

" 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."'"

" 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\|def\|if\|for' .
\ '\|while\|until\|else\|elsif\|case\|when\|unless\|begin\|ensure' .
\ '\|rescue\)\>' .
\ '\|\%([*+/,=:-]\|<<\|>>\)\s*\zs' .
\ '\<\%(if\|for\|while\|until\|case\|unless\|begin\)\>'

" 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 = '^\s*\zs\<\%(module\|class\|def\|if\|for' .
\ '\|while\|until\|case\|unless\|begin\)\>' .
\ '\|\%([*+/,=:-]\|<<\|>>\)\s*\zs' .
\ '\<\%(if\|for\|while\|until\|case\|unless\|begin\)\>' .
\ '\|\<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 match for 'end' keyword.
let s:end_skip_expr = s:skip_expr .
\ ' || (expand("<cword>") == "do"' .
\ ' && getline(".") =~ "^\\s*\\<while\\|until\\|for\\>")'

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

" Regex that defines continuation lines.
" TODO: this needs to deal with if ...: and so on
let s:continuation_regex2 =
\ '\%([\\*+/.,=:({[-]\|\W[|&?]\|||\|&&\)\s*\%(#.*\)\=$'

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

" 2. Auxiliary Functions {{{1
" ======================

" Check if the character at lnum:col is inside a string, comment, or is ascii.
function s:IsInStringOrComment(lnum, col)
return synIDattr(synID(a:lnum, a:col, 0), 'name') =~ s:syng_strcom
endfunction

" Check if the character at lnum:col is inside a string or comment.
function s:IsInStringOrComment2(lnum, col)
return synIDattr(synID(a:lnum, a:col, 0), 'name') =~ s:syng_strcom2
endfunction

" Check if the character at lnum:col is inside a string.
function s:IsInString(lnum, col)
return synIDattr(synID(a:lnum, a:col, 0), 'name') =~ s:syng_string
endfunction

" Check if the character at lnum:col is inside a string or documentation.
function s:IsInStringOrDocumentation(lnum, col)
return synIDattr(synID(a:lnum, a:col, 0), 'name') =~ s:syng_stringdoc
endfunction

" Find line above 'lnum' that isn't empty, in a comment, or in a string.
function s:PrevNonBlankNonString(lnum)
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)
" 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)
let col = match(line, s:continuation_regex2) + 1
if (col > 0 && !s:IsInStringOrComment(lnum, col))
\ || s:IsInString(lnum, strlen(line))
let msl = lnum
else
break
endif
let lnum = s:PrevNonBlankNonString(lnum - 1)
endwhile
return msl
endfunction

" Check if line 'lnum' has more opening brackets than closing ones.
function s:LineHasOpeningBrackets(lnum)
let open_0 = 0
let open_2 = 0
let open_4 = 0
let line = getline(a:lnum)
let pos = match(line, '[][(){}]', 0)
while pos != -1
if !s:IsInStringOrComment(a:lnum, pos + 1)
let idx = stridx('(){}[]', line[pos])
if idx % 2 == 0
let open_{idx} = open_{idx} + 1
else
let open_{idx - 1} = open_{idx - 1} - 1
endif
endif
let pos = match(line, '[][(){}]', pos + 1)
endwhile
return (open_0 > 0) . (open_2 > 0) . (open_4 > 0)
endfunction

function s:Match(lnum, regex)
let col = match(getline(a:lnum), a:regex) + 1
return col > 0 && !s:IsInStringOrComment(a:lnum, col) ? col : 0
endfunction

function s:MatchLast(lnum, regex)
let line = getline(a:lnum)
let col = match(line, '.*\zs' . a:regex)
while col != -1 && s:IsInStringOrComment(a:lnum, col)
let line = strpart(line, 0, col)
let col = match(line, '.*' . a:regex)
endwhile
return col + 1
endfunction

" 3. GetRubyIndent Function {{{1
" =========================

function GetRubyIndent()
" 3.1. Setup {{{2
" ----------

" Set up variables for restoring position in file. Could use v:lnum here.
let vcol = col('.')

" 3.2. Work on the current line {{{2
" -----------------------------

" Get the current line.
let line = getline(v:lnum)
let ind = -1

" 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(line, '^\s*[]})]')
if col > 0 && !s:IsInStringOrComment(v:lnum, col)
call cursor(v:lnum, col)
let bs = strpart('(){}[]', stridx(')}]', line[col - 1]) * 2, 2)
if searchpair(escape(bs[0], '\['), '', bs[1], 'bW', s:skip_expr) > 0
let ind = line[col-1]==')' ? virtcol('.')-1 : indent(s:GetMSL(line('.')))
endif
return ind
endif

" If we have a =begin or =end set indent to first column.
if match(line, '^\s*\%(=begin\|=end\)$') != -1
return 0
endif

" If we have a deindenting keyword, find its match and indent to its level.
" TODO: this is messy
if s:Match(v:lnum, s:ruby_deindent_keywords)
call cursor(v:lnum, 1)
if searchpair(s:end_start_regex, s:end_middle_regex, s:end_end_regex, 'bW',
\ s:end_skip_expr) > 0
let line = getline('.')
if strpart(line, 0, col('.') - 1) =~ '=\s*$' &&
\ strpart(line, col('.') - 1, 2) !~ 'do'
let ind = virtcol('.') - 1
else
let ind = indent('.')
endif
endif
return ind
endif

" If we are in a multi-line string or line-comment, don't do anything to it.
if s:IsInStringOrDocumentation(v:lnum, matchend(line, '^\s*') + 1)
return indent('.')
endif

" 3.3. Work on the previous line. {{{2
" -------------------------------

" Find a non-blank, non-multi-line string line above the current line.
let lnum = s:PrevNonBlankNonString(v:lnum - 1)

" At the start of the file use zero indent.
if lnum == 0
return 0
endif

" Set up variables for current line.
let line = getline(lnum)
let ind = indent(lnum)

" If the previous line ended with a block opening, add a level of indent.
if s:Match(lnum, s:block_regex)
return indent(s:GetMSL(lnum)) + &sw
endif

" If the previous line contained an opening bracket, and we are still in it,
" add indent depending on the bracket type.
if line =~ '[[({]'
let counts = s:LineHasOpeningBrackets(lnum)
if counts[0] == '1' && searchpair('(', '', ')', 'bW', s:skip_expr) > 0
return virtcol('.')
elseif counts[1] == '1' || counts[2] == '1'
return ind + &sw
else
call cursor(v:lnum, vcol)
end
endif

" If the previous line ended with an "end", match that "end"s beginning's
" indent.
let col = s:Match(lnum, '\%(^\|[^.]\)\<end\>\s*\%(#.*\)\=$')
if col > 0
call cursor(lnum, 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

let col = s:Match(lnum, s:ruby_indent_keywords)
if col > 0
call cursor(lnum, col)
let ind = virtcol('.') - 1 + &sw
" let ind = indent(lnum) + &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(lnum, s:end_end_regex)
let ind = indent('.')
endif
return ind
endif

" 3.4. Work on the MSL line. {{{2
" --------------------------

" Set up variables to use and search for MSL to the previous line.
let p_lnum = lnum
let lnum = s:GetMSL(lnum)

" If the previous line wasn't a MSL and is continuation return its indent.
" TODO: the || s:IsInString() thing worries me a bit.
if p_lnum != lnum
if s:Match(p_lnum,s:continuation_regex)||s:IsInString(p_lnum,strlen(line))
return ind
endif
endif

" Set up more variables, now that we know we wasn't continuation bound.
let line = getline(lnum)
let msl_ind = indent(lnum)

" 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
if s:Match(lnum, s:ruby_indent_keywords)
let ind = msl_ind + &sw
if s:Match(lnum, s:end_end_regex)
let ind = ind - &sw
endif
return ind
endif

" If the previous line ended with [*+/.-=], indent one extra level.
if s:Match(lnum, s:continuation_regex)
if lnum == p_lnum
let ind = msl_ind + &sw
else
let ind = msl_ind
endif
endif

" }}}2

return ind
endfunction

" }}}1

let &cpo = s:cpo_save
unlet s:cpo_save

+ 8
- 4
install.sh View File

@@ -1,7 +1,11 @@
#!/bin/sh

mkdir -p ~/.vim/plugin
rm -rf ~/.vim/plugin/*

cp main/vimrc ~/.vimrc
cp plugin/*.vim ~/.vim/plugin/

for i in `ls|grep -v main`; do
if [ -d $i ]; then
mkdir -p ~/.vim/$i
rm -rf ~/.vim/$i/*
cp -p $i/* ~/.vim/$i/
fi
done

+ 0
- 39
plugin/eruby.vim View File

@@ -1,39 +0,0 @@
" Vim syntax file
" Language: eruby
" Maintainer: Michael Brailsford <brailsmt@yahoo.com>
" Installation:
" To automatilcally load this file when a .rhtml file is opened, add the
" following lines to ~/.vim/filetype.vim:
"
" augroup filetypedetect
" au! BufRead,BufNewFile *.rhtml setfiletype eruby
" augroup END
"
" You will have to restart vim for this to take effect. In any case it
" is a good idea to read ":he new-filetype" so that you know what is going
" on, and why the above lines work.

if version < 600
syntax clear
elseif exists("b:current_syntax")
finish
endif

"Source the html syntax file
ru! syntax/html.vim
"Set the filetype to html to load the html ftplugins
set ft=html
unlet b:current_syntax

"Put the ruby syntax file in @rubyTop
syn include @rubyTop syntax/ruby.vim

syn region erubyBlock matchgroup=erubyRubyDelim start=#<%=\?# end=#%># keepend containedin=ALL contains=@rubyTop,erubyEnd
syn region erubyComment start=+<%#+ end=#%># keepend
syn match erubyEnd #\<end\>#

hi link erubyRubyDelim todo
hi link erubyComment comment
hi link erubyEnd rubyControl

" vim: set ts=4 sw=4:

+ 29
- 113
plugin/matchit.vim View File

@@ -1,7 +1,8 @@
" matchit.vim: (global plugin) Extended "%" matching
" Last Change: June 12, 2002
" Last Change: Sun Feb 26 10:00 AM 2006 EST
" Maintainer: Benji Fisher PhD <benji@member.AMS.org>
" Version: 1.7, for Vim 6.1
" Version: 1.10, for Vim 6.3
" URL: http://www.vim.org/script.php?script_id=39

" Documentation:
" The documentation is in a separate file, matchit.txt .
@@ -14,7 +15,7 @@
" Support for many languages by Johannes Zellner
" Suggestions for improvement, bug reports, and support for additional
" languages by Jordi-Albert Batalla, Neil Bird, Servatius Brandt, Mark
" Collett, Stephen Wall, and Johannes Zellner.
" Collett, Stephen Wall, Dany St-Amant, and Johannes Zellner.

" Debugging:
" If you'd like to try the built-in debugging commands...
@@ -63,6 +64,9 @@ vmap ]% <Esc>]%m'gv``
onoremap <silent> [% v:<C-U>call <SID>MultiMatch("bW", "o") <CR>
onoremap <silent> ]% v:<C-U>call <SID>MultiMatch("W", "o") <CR>

" text object:
vmap a% <Esc>[%v]%

" Auto-complete mappings: (not yet "ready for prime time")
" TODO Read :help write-plugin for the "right" way to let the user
" specify a key binding.
@@ -216,6 +220,10 @@ function! s:Match_wrapper(word, forward, mode) range
let ini = strpart(group, 0, i-1)
let mid = substitute(strpart(group, i,j-i-1), s:notslash.'\zs:', '\\|', 'g')
let fin = strpart(group, j)
"Un-escape the remaining , and : characters.
let ini = substitute(ini, s:notslash . '\zs\\\(:\|,\)', '\1', 'g')
let mid = substitute(mid, s:notslash . '\zs\\\(:\|,\)', '\1', 'g')
let fin = substitute(fin, s:notslash . '\zs\\\(:\|,\)', '\1', 'g')
" searchpair() requires that these patterns avoid \(\) groups.
let ini = substitute(ini, s:notslash . '\zs\\(', '\\%(', 'g')
let mid = substitute(mid, s:notslash . '\zs\\(', '\\%(', 'g')
@@ -248,7 +256,9 @@ function! s:Match_wrapper(word, forward, mode) range

" Fifth step: actually start moving the cursor and call searchpair().
" Later, :execute restore_cursor to get to the original screen.
let restore_cursor = line(".") . "G" . virtcol(".") . "|"
let restore_cursor = virtcol(".") . "|"
normal! g0
let restore_cursor = line(".") . "G" . virtcol(".") . "|zs" . restore_cursor
normal! H
let restore_cursor = "normal!" . line(".") . "Gzt" . restore_cursor
execute restore_cursor
@@ -262,7 +272,7 @@ function! s:Match_wrapper(word, forward, mode) range
execute "if " . skip . "| let skip = '0' | endif"
endif
let sp_return = searchpair(ini, mid, fin, flag, skip)
let final_position = line(".") . "normal!" . virtcol(".") . "|"
let final_position = "call cursor(" . line(".") . "," . col(".") . ")"
" Restore cursor position and original screen.
execute restore_cursor
normal! m'
@@ -285,7 +295,7 @@ fun! s:CleanUp(options, mode, startline, startcol, ...)
" (for example, d%).
" This is only a problem if we end up moving in the forward direction.
elseif (a:startline < line(".")) ||
\ (a:startline == line(".") && a:startcol < col("."))
\ (a:startline == line(".") && a:startcol < col("."))
if a:0
" Check whether the match is a single character. If not, move to the
" end of the match.
@@ -294,7 +304,7 @@ fun! s:CleanUp(options, mode, startline, startcol, ...)
let regexp = s:Wholematch(matchline, a:1, currcol-1)
let endcol = matchend(matchline, regexp)
if endcol > currcol " This is NOT off by one!
execute "normal!" . (endcol - currcol) . "l"
execute "normal!" . (endcol - currcol) . "l"
endif
endif " a:0
endif " a:mode != "o" && etc.
@@ -559,7 +569,7 @@ fun! s:Choose(patterns, string, comma, branch, prefix, suffix, ...)
if a:branch == ""
let currpat = current
else
let currpat = substitute(current, a:branch, '\\|', 'g')
let currpat = substitute(current, s:notslash . a:branch, '\\|', 'g')
endif
while a:string !~ a:prefix . currpat . a:suffix
let tail = strpart(tail, i)
@@ -571,7 +581,7 @@ fun! s:Choose(patterns, string, comma, branch, prefix, suffix, ...)
if a:branch == ""
let currpat = current
else
let currpat = substitute(current, a:branch, '\\|', 'g')
let currpat = substitute(current, s:notslash . a:branch, '\\|', 'g')
endif
if a:0
let alttail = strpart(alttail, j)
@@ -669,9 +679,10 @@ fun! s:MultiMatch(spflag, mode)
" - TODO: A lot of this is copied from s:Match_wrapper().
" - maybe even more functionality should be split off
" - into separate functions!
let open = substitute(s:pat . default, ':[^,]*,', '\\),\\(', 'g')
let cdefault = (s:pat =~ '[^,]$' ? "," : "") . default
let open = substitute(s:pat . cdefault, ':[^,]*,', '\\),\\(', 'g')
let open = '\(' . substitute(open, ':[^,]*$', '\\)', '')
let close = substitute(s:pat . default, ',[^,]*:', '\\),\\(', 'g')
let close = substitute(s:pat . cdefault, ',[^,]*:', '\\),\\(', 'g')
let close = substitute(close, '[^,]*:', '\\(', '') . '\)'
if exists("b:match_skip")
let skip = b:match_skip
@@ -681,7 +692,12 @@ fun! s:MultiMatch(spflag, mode)
let skip = 's:comment\|string'
endif
let skip = s:ParseSkip(skip)
let restore_cursor = line(".") . "G" . virtcol(".") . "|"
" let restore_cursor = line(".") . "G" . virtcol(".") . "|"
" normal! H
" let restore_cursor = "normal!" . line(".") . "Gzt" . restore_cursor
let restore_cursor = virtcol(".") . "|"
normal! g0
let restore_cursor = line(".") . "G" . virtcol(".") . "|zs" . restore_cursor
normal! H
let restore_cursor = "normal!" . line(".") . "Gzt" . restore_cursor
execute restore_cursor
@@ -789,106 +805,6 @@ fun! s:ParseSkip(str)
return skip
endfun

aug Matchit
let s:notend = '\%(\<end\s\+\)\@<!'
au!
" ASP: Active Server Pages (with Visual Basic Script)
" thanks to Gontran BAERTS
au FileType aspvbs if !exists("b:match_words") |
\ do Matchit FileType html |
\ let b:match_words =
\ s:notend . '\<If\>:^\s\+\<Else\>:\<ElseIf\>:\<end\s\+\<if\>,' .
\ s:notend . '\<Select\s\+\<Case\>:\<Case\>:\<Case\s\+\<Else\>:' .
\ '\<End\s\+\<Select\>,' .
\ '^\s*\<Sub\>:\<End\s\+\<Sub\>,' .
\ '^\s*\<Function\>:\<End\s\+\<Function\>,' .
\ '\<Class\>:\<End\s\+\<Class\>,' .
\ '^\s*\<Do\>:\<Loop\>,' .
\ '^\s*\<For\>:\<Next\>,' .
\ '\<While\>:\<Wend\>,' .
\ b:match_words
\ | endif
" Csh: thanks to Johannes Zellner
" - Both foreach and end must appear alone on separate lines.
" - The words else and endif must appear at the beginning of input lines;
" the if must appear alone on its input line or after an else.
" - Each case label and the default label must appear at the start of a
" line.
" - while and end must appear alone on their input lines.
au FileType csh,tcsh if !exists("b:match_words") |
\ let b:match_words =
\ '^\s*\<if\>.*(.*).*\<then\>:'.
\ '^\s*\<else\>\s\+\<if\>.*(.*).*\<then\>:^\s*\<else\>:'.
\ '^\s*\<endif\>,'.
\ '\%(^\s*\<foreach\>\s\+\S\+\|^s*\<while\>\).*(.*):'.
\ '\<break\>:\<continue\>:^\s*\<end\>,'.
\ '^\s*\<switch\>.*(.*):^\s*\<case\>\s\+:^\s*\<default\>:^\s*\<endsw\>'
\ | endif
" DTD: thanks to Johannes Zellner
" - match <!--, --> style comments.
" - match <! with >
" - TODO: why does '--:--,'. not work ?
au! FileType dtd if !exists("b:match_words") |
\ let b:match_words =
\ '<!--:-->,'.
\ '<!:>'
\ | endif
" Entity: see XML.
" Essbase:
au BufNewFile,BufRead *.csc if !exists("b:match_words") |
\ let b:match_words=
\ '\<fix\>:\<endfix\>,' .
\ '\<if\>:\<else\%(if\)\=\>:\<endif\>,' .
\ '\<!loopondimensions\>\|\<!looponselected\>:\<!endloop\>'
\ | endif
" HTML: thanks to Johannes Zellner.
au FileType html,jsp,php if !exists("b:match_words") |
\ let b:match_ignorecase = 1 |
\ let b:match_skip = 's:Comment' |
\ let b:match_words = '<:>,' .
\ '<\@<=[ou]l[^>]*\%(>\|$\):<\@<=li>:<\@<=/[ou]l>,' .
\ '<\@<=\([^/][^ \t>]*\)[^>]*\%(>\|$\):<\@<=/\1>'
\ | endif
" Pascal:
au FileType pascal if !exists("b:match_words") |
\ let b:match_words='\<begin\>:\<end\>'
\ | endif
" SGML: see XML
" Shell: thanks to Johannes Zellner
let s:sol = '\%(;\s*\|^\s*\)\@<=' " start of line
au FileType sh,config if !exists("b:match_words") |
\ let b:match_words =
\ s:sol.'if\>:' . s:sol.'elif\>:' . s:sol.'else\>:' . s:sol. 'fi\>,' .
\ s:sol.'\%(for\|while\)\>:' . s:sol. 'done\>,' .
\ s:sol.'case\>:' . s:sol. 'esac\>'
\ | endif
" RPM Spec: thanks to Max Ischenko
au FileType spec if !exists("b:match_words") |
\ let b:match_ignorecase = 0 | let b:match_words =
\ '^Name:^%description:^%clean:^%setup:^%build:^%install:^%files:' .
\ '^%package:^%preun:^%postun:^%changelog'
\ | endif
" Tcsh: see Csh
" XML: thanks to Johannes Zellner and Akbar Ibrahim
" - case sensitive
" - don't match empty tags <fred/>
" - match <!--, --> style comments (but not --, --)
" - match <!, > inlined dtd's. This is not perfect, as it
" gets confused for example by
" <!ENTITY gt ">">
au! FileType xml,sgml,entity,xslt,svg,xhtml,xsl,xsd
\ if !exists("b:match_words") |
\ let b:match_ignorecase=0 | let b:match_words =
\ '<:>,' .
\ '<\@<=!\[CDATA\[:]]>,'.
\ '<\@<=!--:-->,'.
\ '<\@<=?\k\+:?>,'.
\ '<\@<=\([^ \t>/]\+\)\%(\s\+[^>]*\%([^/]>\|$\)\|>\|$\):<\@<=/\1>,'.
\ '<\@<=\%([^ \t>/]\+\)\%(\s\+[^/>]*\|$\):/>'
\ | endif

aug END

let &cpo = s:save_cpo

" vim:sts=2:sw=2:ff=unix:
" vim:sts=2:sw=2:

+ 64
- 0
syntax/eruby.vim View File

@@ -0,0 +1,64 @@
" Vim syntax file
" Language: eRuby
" Maintainer: Doug Kearns <djkea2 at gus.gscit.monash.edu.au>
" Info: $Id: eruby.vim,v 1.6 2005/09/13 04:26:56 dkearns Exp $
" URL: http://vim-ruby.sourceforge.net
" Anon CVS: See above site
" Licence: GPL (http://www.gnu.org)
" Disclaimer:
" This program is distributed in the hope that it will be useful,
" but WITHOUT ANY WARRANTY; without even the implied warranty of
" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
" GNU General Public License for more details.

" For version 5.x: Clear all syntax items
" For version 6.x: Quit when a syntax file was already loaded
if version < 600
syntax clear
elseif exists("b:current_syntax")
finish
endif

if !exists("main_syntax")
let main_syntax = 'eruby'
endif

if version < 600
so <sfile>:p:h/html.vim
syn include @rubyTop <sfile>:p:h/ruby.vim
else
runtime! syntax/html.vim
unlet b:current_syntax
syn include @rubyTop syntax/ruby.vim
endif

syn cluster erubyRegions contains=erubyOneLiner,erubyBlock,erubyExpression,erubyComment

syn region erubyOneLiner matchgroup=erubyDelimiter start="^%%\@!" end="$" contains=@rubyTop containedin=ALLBUT,@erubyRegions keepend oneline
syn region erubyBlock matchgroup=erubyDelimiter start="<%%\@!" end="%>" contains=@rubyTop containedin=ALLBUT,@erubyRegions
syn region erubyExpression matchgroup=erubyDelimiter start="<%=" end="%>" contains=@rubyTop containedin=ALLBUT,@erubyRegions
syn region erubyComment matchgroup=erubyDelimiter start="<%#" end="%>" contains=rubyTodo,@Spell containedin=ALLBUT,@erubyRegions keepend

" Define the default highlighting.
" For version 5.7 and earlier: only when not done already
" For version 5.8 and later: only when an item doesn't have highlighting yet
if version >= 508 || !exists("did_eruby_syntax_inits")
if version < 508
let did_ruby_syntax_inits = 1
command -nargs=+ HiLink hi link <args>
else
command -nargs=+ HiLink hi def link <args>
endif

HiLink erubyDelimiter Delimiter
HiLink erubyComment Comment

delcommand HiLink
endif
let b:current_syntax = "eruby"

if main_syntax == 'eruby'
unlet main_syntax
endif

" vim: nowrap sw=2 sts=2 ts=8 ff=unix:

+ 292
- 0
syntax/ruby.vim View File

@@ -0,0 +1,292 @@
" Vim syntax file
" Language: Ruby
" Maintainer: Doug Kearns <djkea2 at gus.gscit.monash.edu.au>
" Info: $Id: ruby.vim,v 1.82 2005/10/04 11:26:30 dkearns Exp $
" URL: http://vim-ruby.sourceforge.net
" Anon CVS: See above site
" Licence: GPL (http://www.gnu.org)
" Disclaimer:
" This program is distributed in the hope that it will be useful,
" but WITHOUT ANY WARRANTY; without even the implied warranty of
" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
" GNU General Public License for more details.
" ----------------------------------------------------------------------------
"
" Previous Maintainer: Mirko Nasato
" Thanks to perl.vim authors, and to Reimer Behrends. :-) (MN)
" ----------------------------------------------------------------------------

" For version 5.x: Clear all syntax items
" For version 6.x: Quit when a syntax file was already loaded
if version < 600
syntax clear
elseif exists("b:current_syntax")
finish
endif

if has("folding") && exists("ruby_fold")
setlocal foldmethod=syntax
endif

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

" Expression Substitution and Backslash Notation
syn match rubyEscape "\\\\\|\\[abefnrstv]\|\\\o\{1,3}\|\\x\x\{1,2}" contained display
syn match rubyEscape "\%(\\M-\\C-\|\\C-\\M-\|\\M-\\c\|\\c\\M-\|\\c\|\\C-\|\\M-\)\%(\\\o\{1,3}\|\\x\x\{1,2}\|\\\=\S\)" contained display
syn match rubyInterpolation "#{[^}]*}" contained
syn match rubyInterpolation "#\%(\$\|@@\=\)\w\+" contained display
syn match rubyNoInterpolation "\\#{[^}]*}" contained
syn match rubyNoInterpolation "\\#\%(\$\|@@\=\)\w\+" contained display

syn match rubyDelimEscape "\\[(<{\[)>}\]]" transparent display contained contains=NONE

syn region rubyNestedParentheses start="(" end=")" skip="\\\\\|\\)" transparent contained contains=@rubyStringSpecial,rubyNestedParentheses,rubyDelimEscape
syn region rubyNestedCurlyBraces start="{" end="}" skip="\\\\\|\\}" transparent contained contains=@rubyStringSpecial,rubyNestedCurlyBraces,rubyDelimEscape
syn region rubyNestedAngleBrackets start="<" end=">" skip="\\\\\|\\>" transparent contained contains=@rubyStringSpecial,rubyNestedAngleBrackets,rubyDelimEscape
syn region rubyNestedSquareBrackets start="\[" end="\]" skip="\\\\\|\\\]" transparent contained contains=@rubyStringSpecial,rubyNestedSquareBrackets,rubyDelimEscape

syn cluster rubyStringSpecial contains=rubyInterpolation,rubyNoInterpolation,rubyEscape
syn cluster rubyExtendedStringSpecial contains=@rubyStringSpecial,rubyNestedParentheses,rubyNestedCurlyBraces,rubyNestedAngleBrackets,rubyNestedSquareBrackets

" Numbers and ASCII Codes
syn match rubyASCIICode "\w\@<!\%(?\%(\\M-\\C-\|\\C-\\M-\|\\M-\\c\|\\c\\M-\|\\c\|\\C-\|\\M-\)\=\%(\\\o\{1,3}\|\\x\x\{1,2}\|\\\=\S\)\)"
syn match rubyInteger "\<0[xX]\x\+\%(_\x\+\)*\>" display
syn match rubyInteger "\<\%(0[dD]\)\=\%(0\|[1-9]\d*\%(_\d\+\)*\)\>" display
syn match rubyInteger "\<0[oO]\=\o\+\%(_\o\+\)*\>" display
syn match rubyInteger "\<0[bB][01]\+\%(_[01]\+\)*\>" display
syn match rubyFloat "\<\%(0\|[1-9]\d*\%(_\d\+\)*\)\.\d\+\%(_\d\+\)*\>" display
syn match rubyFloat "\<\%(0\|[1-9]\d*\%(_\d\+\)*\)\%(\.\d\+\%(_\d\+\)*\)\=\%([eE][-+]\=\d\+\%(_\d\+\)*\)\>" display

" Identifiers
syn match rubyLocalVariableOrMethod "\<[_[:lower:]][_[:alnum:]]*[?!=]\=" contains=NONE display transparent
syn match rubyBlockArgument "&[_[:lower:]][_[:alnum:]]" contains=NONE display transparent

syn match rubyConstant "\%(\%(\.\@<!\.\)\@<!\<\|::\)\_s*\zs\u\w*\>\%(\s*(\)\@!"
syn match rubyClassVariable "@@\h\w*" display
syn match rubyInstanceVariable "@\h\w*" display
syn match rubyGlobalVariable "$\%(\h\w*\|-.\)"
syn match rubySymbol ":\@<!:\%(\^\|\~\|<<\|<=>\|<=\|<\|===\|==\|=\~\|>>\|>=\|>\||\|-@\|-\|/\|\[]=\|\[]\|\*\*\|\*\|&\|%\|+@\|+\|`\)"
syn match rubySymbol ":\@<!:\$\%(-.\|[`~<=>_,;:!?/.'"@$*\&+0]\)"
syn match rubySymbol ":\@<!:\%(\$\|@@\=\)\=\h\w*[?!=]\="
syn region rubySymbol start=":\@<!:\"" end="\"" skip="\\\\\|\\\""
syn match rubyBlockParameter "\%(\%(\<do\>\|{\)\s*\)\@<=|\s*\zs[( ,a-zA-Z0-9_*)]\+\ze\s*|" display

syn match rubyPredefinedVariable #$[!$&"'*+,./0:;<=>?@\`~1-9]#
syn match rubyPredefinedVariable "$_\>" display
syn match rubyPredefinedVariable "$-[0FIKadilpvw]\>" display
syn match rubyPredefinedVariable "$\%(deferr\|defout\|stderr\|stdin\|stdout\)\>" display
syn match rubyPredefinedVariable "$\%(DEBUG\|FILENAME\|KCODE\|LOADED_FEATURES\|LOAD_PATH\|PROGRAM_NAME\|SAFE\|VERBOSE\)\>" display
syn match rubyPredefinedConstant "\%(\%(\.\@<!\.\)\@<!\|::\)\_s*\zs\%(MatchingData\|ARGF\|ARGV\|ENV\)\>\%(\s*(\)\@!"
syn match rubyPredefinedConstant "\%(\%(\.\@<!\.\)\@<!\|::\)\_s*\zs\%(DATA\|FALSE\|NIL\|RUBY_PLATFORM\|RUBY_RELEASE_DATE\)\>\%(\s*(\)\@!"
syn match rubyPredefinedConstant "\%(\%(\.\@<!\.\)\@<!\|::\)\_s*\zs\%(RUBY_VERSION\|STDERR\|STDIN\|STDOUT\|TOPLEVEL_BINDING\|TRUE\)\>\%(\s*(\)\@!"
"Obsolete Global Constants
"syn match rubyPredefinedConstant "\%(::\)\=\zs\%(PLATFORM\|RELEASE_DATE\|VERSION\)\>"
"syn match rubyPredefinedConstant "\%(::\)\=\zs\%(NotImplementError\)\>"

" Normal Regular Expression
syn region rubyString matchgroup=rubyStringDelimiter start="\%(\%(^\|\<\%(and\|or\|while\|until\|unless\|if\|elsif\|when\|not\|then\)\|[;\~=!|&(,[>]\)\s*\)\@<=/" end="/[iomx]*" skip="\\\\\|\\/" contains=@rubyStringSpecial
syn region rubyString matchgroup=rubyStringDelimiter start="\%(\<\%(split\|scan\|gsub\|sub\)\s*\)\@<=/" end="/[iomx]*" skip="\\\\\|\\/" contains=@rubyStringSpecial

" Normal String and Shell Command Output
syn region rubyString matchgroup=rubyStringDelimiter start="\"" end="\"" skip="\\\\\|\\\"" contains=@rubyStringSpecial
syn region rubyString matchgroup=rubyStringDelimiter start="'" end="'" skip="\\\\\|\\'"
syn region rubyString matchgroup=rubyStringDelimiter start="`" end="`" skip="\\\\\|\\`" contains=@rubyStringSpecial

" Generalized Regular Expression
syn region rubyString matchgroup=rubyStringDelimiter start="%r\z([~`!@#$%^&*_\-+=|\:;"',.?/]\)" end="\z1[iomx]*" skip="\\\\\|\\\z1" contains=@rubyStringSpecial fold
syn region rubyString matchgroup=rubyStringDelimiter start="%r{" end="}[iomx]*" skip="\\\\\|\\}" contains=@rubyStringSpecial,rubyNestedCurlyBraces,rubyDelimEscape fold
syn region rubyString matchgroup=rubyStringDelimiter start="%r<" end=">[iomx]*" skip="\\\\\|\\>" contains=@rubyStringSpecial,rubyNestedAngleBrackets,rubyDelimEscape fold
syn region rubyString matchgroup=rubyStringDelimiter start="%r\[" end="\][iomx]*" skip="\\\\\|\\\]" contains=@rubyStringSpecial,rubyNestedSquareBrackets,rubyDelimEscape fold
syn region rubyString matchgroup=rubyStringDelimiter start="%r(" end=")[iomx]*" skip="\\\\\|\\)" contains=@rubyStringSpecial,rubyNestedParentheses,rubyDelimEscape fold

" Generalized Single Quoted String, Symbol and Array of Strings
syn region rubyString matchgroup=rubyStringDelimiter start="%[qsw]\z([~`!@#$%^&*_\-+=|\:;"',.?/]\)" end="\z1" skip="\\\\\|\\\z1" fold
syn region rubyString matchgroup=rubyStringDelimiter start="%[qsw]{" end="}" skip="\\\\\|\\}" fold contains=rubyNestedCurlyBraces,rubyDelimEscape
syn region rubyString matchgroup=rubyStringDelimiter start="%[qsw]<" end=">" skip="\\\\\|\\>" fold contains=rubyNestedAngleBrackets,rubyDelimEscape
syn region rubyString matchgroup=rubyStringDelimiter start="%[qsw]\[" end="\]" skip="\\\\\|\\\]" fold contains=rubyNestedSquareBrackets,rubyDelimEscape
syn region rubyString matchgroup=rubyStringDelimiter start="%[qsw](" end=")" skip="\\\\\|\\)" fold contains=rubyNestedParentheses,rubyDelimEscape

" Generalized Double Quoted String and Array of Strings and Shell Command Output
" Note: %= is not matched here as the beginning of a double quoted string
syn region rubyString matchgroup=rubyStringDelimiter start="%\z([~`!@#$%^&*_\-+|\:;"',.?/]\)" end="\z1" skip="\\\\\|\\\z1" contains=@rubyStringSpecial fold
syn region rubyString matchgroup=rubyStringDelimiter start="%[QWx]\z([~`!@#$%^&*_\-+=|\:;"',.?/]\)" end="\z1" skip="\\\\\|\\\z1" contains=@rubyStringSpecial fold
syn region rubyString matchgroup=rubyStringDelimiter start="%[QWx]\={" end="}" skip="\\\\\|\\}" contains=@rubyStringSpecial,rubyNestedCurlyBraces,rubyDelimEscape fold
syn region rubyString matchgroup=rubyStringDelimiter start="%[QWx]\=<" end=">" skip="\\\\\|\\>" contains=@rubyStringSpecial,rubyNestedAngleBrackets,rubyDelimEscape fold
syn region rubyString matchgroup=rubyStringDelimiter start="%[QWx]\=\[" end="\]" skip="\\\\\|\\\]" contains=@rubyStringSpecial,rubyNestedSquareBrackets,rubyDelimEscape fold
syn region rubyString matchgroup=rubyStringDelimiter start="%[QWx]\=(" end=")" skip="\\\\\|\\)" contains=@rubyStringSpecial,rubyNestedParentheses,rubyDelimEscape fold

" Here Document
syn region rubyHeredocStart matchgroup=rubyStringDelimiter start=+\%(\%(class\s*\|\%(\.\|::\)\)\_s*\)\@<!<<-\=\zs\%(\h\w*\)+ end=+$+ oneline contains=TOP
syn region rubyHeredocStart matchgroup=rubyStringDelimiter start=+\%(\%(class\s*\|\%(\.\|::\)\)\_s*\)\@<!<<-\=\zs"\%([^"]*\)"+ end=+$+ oneline contains=TOP
syn region rubyHeredocStart matchgroup=rubyStringDelimiter start=+\%(\%(class\s*\|\%(\.\|::\)\)\_s*\)\@<!<<-\=\zs'\%([^']*\)'+ end=+$+ oneline contains=TOP
syn region rubyHeredocStart matchgroup=rubyStringDelimiter start=+\%(\%(class\s*\|\%(\.\|::\)\)\_s*\)\@<!<<-\=\zs`\%([^`]*\)`+ end=+$+ oneline contains=TOP

syn region rubyString start=+\%(\%(class\s*\|\%(\.\|::\)\)\_s*\)\@<!<<\z(\h\w*\)\ze+hs=s+2 matchgroup=rubyStringDelimiter end=+^\z1$+ contains=rubyHeredocStart,@rubyStringSpecial nextgroup=rubyFunction fold keepend
syn region rubyString start=+\%(\%(class\s*\|\%(\.\|::\)\)\_s*\)\@<!<<"\z([^"]*\)"\ze+hs=s+2 matchgroup=rubyStringDelimiter end=+^\z1$+ contains=rubyHeredocStart,@rubyStringSpecial nextgroup=rubyFunction fold keepend
syn region rubyString start=+\%(\%(class\s*\|\%(\.\|::\)\)\_s*\)\@<!<<'\z([^']*\)'\ze+hs=s+2 matchgroup=rubyStringDelimiter end=+^\z1$+ contains=rubyHeredocStart nextgroup=rubyFunction fold keepend
syn region rubyString start=+\%(\%(class\s*\|\%(\.\|::\)\)\_s*\)\@<!<<`\z([^`]*\)`\ze+hs=s+2 matchgroup=rubyStringDelimiter end=+^\z1$+ contains=rubyHeredocStart,@rubyStringSpecial nextgroup=rubyFunction fold keepend

syn region rubyString start=+\%(\%(class\s*\|\%(\.\|::\)\)\_s*\)\@<!<<-\z(\h\w*\)\ze+hs=s+3 matchgroup=rubyStringDelimiter end=+^\s*\zs\z1$+ contains=rubyHeredocStart,@rubyStringSpecial nextgroup=rubyFunction fold keepend
syn region rubyString start=+\%(\%(class\s*\|\%(\.\|::\)\)\_s*\)\@<!<<-"\z([^"]*\)"\ze+hs=s+3 matchgroup=rubyStringDelimiter end=+^\s*\zs\z1$+ contains=rubyHeredocStart,@rubyStringSpecial nextgroup=rubyFunction fold keepend
syn region rubyString start=+\%(\%(class\s*\|\%(\.\|::\)\)\_s*\)\@<!<<-'\z([^']*\)'\ze+hs=s+3 matchgroup=rubyStringDelimiter end=+^\s*\zs\z1$+ contains=rubyHeredocStart nextgroup=rubyFunction fold keepend
syn region rubyString start=+\%(\%(class\s*\|\%(\.\|::\)\)\_s*\)\@<!<<-`\z([^`]*\)`\ze+hs=s+3 matchgroup=rubyStringDelimiter end=+^\s*\zs\z1$+ contains=rubyHeredocStart,@rubyStringSpecial nextgroup=rubyFunction fold keepend

if exists('main_syntax') && main_syntax == 'eruby'
let b:ruby_no_expensive = 1
end

" Expensive Mode - colorize *end* according to opening statement
if !exists("b:ruby_no_expensive") && !exists("ruby_no_expensive")
syn region rubyFunction matchgroup=rubyDefine start="\<def\s\+" end="\%(\s*\%(\s\|(\|;\|$\|#\)\)\@=" oneline
syn region rubyClass matchgroup=rubyDefine start="\<class\s\+" end="\%(\s*\%(\s\|<\|;\|$\|#\)\)\@=" oneline
syn match rubyDefine "\<class\ze<<"
syn region rubyModule matchgroup=rubyDefine start="\<module\s\+" end="\%(\s*\%(\s\|;\|$\|#\)\)\@=" oneline

syn region rubyBlock start="\<def\>" matchgroup=rubyDefine end="\<end\>" contains=ALLBUT,@rubyExtendedStringSpecial,rubyTodo nextgroup=rubyFunction fold
syn region rubyBlock start="\<class\>" matchgroup=rubyDefine end="\<end\>" contains=ALLBUT,@rubyExtendedStringSpecial,rubyTodo nextgroup=rubyClass fold
syn region rubyBlock start="\<module\>" matchgroup=rubyDefine end="\<end\>" contains=ALLBUT,@rubyExtendedStringSpecial,rubyTodo nextgroup=rubyModule fold

" modifiers
syn match rubyControl "\<\%(if\|unless\|while\|until\)\>" display

" *do* requiring *end*
syn region rubyDoBlock matchgroup=rubyControl start="\<do\>" end="\<end\>" contains=ALLBUT,@rubyExtendedStringSpecial,rubyTodo fold

" *{* requiring *}*
syn region rubyCurlyBlock start="{" end="}" contains=ALLBUT,@rubyExtendedStringSpecial,rubyTodo fold

" statements without *do*
syn region rubyNoDoBlock matchgroup=rubyControl start="\<\%(case\|begin\)\>" start="\%(^\|\.\.\.\=\|[,;=([<>~\*/%!&^|+-]\)\s*\zs\%(if\|unless\)\>" end="\<end\>" contains=ALLBUT,@rubyExtendedStringSpecial,rubyTodo fold

" statement with optional *do*
syn region rubyOptDoLine matchgroup=rubyControl start="\<for\>" start="\%(\%(^\|\.\.\.\=\|[?:,;=([<>~\*/%!&^|+-]\|\%(\<[_[:lower:]][_[:alnum:]]*\)\@<![!=?]\)\s*\)\@<=\<\%(until\|while\)\>" end="\%(\<do\>\|:\)" end="\ze\%(;\|$\)" oneline contains=ALLBUT,@rubyExtendedStringSpecial,rubyTodo
syn region rubyOptDoBlock start="\<for\>" start="\%(\%(^\|\.\.\.\=\|[:,;([<>~\*/%&^|+-]\|\%(\<[_[:lower:]][_[:alnum:]]*\)\@<![!=?]\)\s*\)\@<=\<\%(until\|while\)\>" matchgroup=rubyControl end="\<end\>" contains=ALLBUT,@rubyExtendedStringSpecial,rubyTodo nextgroup=rubyOptDoLine fold

if !exists("ruby_minlines")
let ruby_minlines = 50
endif
exec "syn sync minlines=" . ruby_minlines

else
syn region rubyFunction matchgroup=rubyControl start="\<def\s\+" end="\ze\%(\s\|(\|;\|$\)" oneline
syn region rubyClass matchgroup=rubyControl start="\<class\s\+" end="\ze\%(\s\|<\|;\|$\)" oneline
syn match rubyControl "\<class\ze<<"
syn region rubyModule matchgroup=rubyControl start="\<module\s\+" end="\ze\%(\s\|;\|$\)" oneline
syn keyword rubyControl case begin do for if unless while until end
endif

" Keywords
" Note: the following keywords have already been defined:
" begin case class def do end for if module unless until while
syn keyword rubyControl and break else elsif ensure in next not or redo rescue retry return then when
syn match rubyOperator "\<defined?" display
syn keyword rubyKeyword alias super undef yield
syn keyword rubyBoolean true false
syn keyword rubyPseudoVariable nil self __FILE__ __LINE__
syn keyword rubyBeginEnd BEGIN END

" Special Methods
if !exists("ruby_no_special_methods")
syn keyword rubyAccess public protected private
syn keyword rubyAttribute attr attr_accessor attr_reader attr_writer
syn match rubyControl "\<\%(exit!\|\%(abort\|at_exit\|exit\|fork\|loop\|trap\)\>\)"
syn keyword rubyEval eval class_eval instance_eval module_eval
syn keyword rubyException raise fail catch throw
syn keyword rubyInclude autoload extend include load require
syn keyword rubyKeyword callcc caller lambda proc
endif

" Comments and Documentation
syn match rubySharpBang "\%^#!.*" display
syn keyword rubyTodo FIXME NOTE TODO XXX contained
syn match rubyComment "#.*" contains=rubySharpBang,rubySpaceError,rubyTodo,@Spell
syn region rubyDocumentation start="^=begin" end="^=end.*$" contains=rubySpaceError,rubyTodo,@Spell fold

" Note: this is a hack to prevent 'keywords' being highlighted as such when called as methods with an explicit receiver
syn match rubyKeywordAsMethod "\%(\%(\.\@<!\.\)\|::\)\_s*\%(alias\|and\|begin\|break\|case\|class\|def\|defined\|do\|else\)\>" transparent contains=NONE
syn match rubyKeywordAsMethod "\%(\%(\.\@<!\.\)\|::\)\_s*\%(elsif\|end\|ensure\|false\|for\|if\|in\|module\|next\|nil\)\>" transparent contains=NONE
syn match rubyKeywordAsMethod "\%(\%(\.\@<!\.\)\|::\)\_s*\%(not\|or\|redo\|rescue\|retry\|return\|self\|super\|then\|true\)\>" transparent contains=NONE
syn match rubyKeywordAsMethod "\%(\%(\.\@<!\.\)\|::\)\_s*\%(undef\|unless\|until\|when\|while\|yield\|BEGIN\|END\|__FILE__\|__LINE__\)\>" transparent contains=NONE

syn match rubyKeywordAsMethod "\%(\%(\.\@<!\.\)\|::\)\_s*\%(abort\|at_exit\|attr\|attr_accessor\|attr_reader\)\>" transparent contains=NONE
syn match rubyKeywordAsMethod "\%(\%(\.\@<!\.\)\|::\)\_s*\%(attr_writer\|autoload\|callcc\|catch\|caller\)\>" transparent contains=NONE
syn match rubyKeywordAsMethod "\%(\%(\.\@<!\.\)\|::\)\_s*\%(eval\|class_eval\|instance_eval\|module_eval\|exit\)\>" transparent contains=NONE
syn match rubyKeywordAsMethod "\%(\%(\.\@<!\.\)\|::\)\_s*\%(extend\|fail\|fork\|include\|lambda\)\>" transparent contains=NONE
syn match rubyKeywordAsMethod "\%(\%(\.\@<!\.\)\|::\)\_s*\%(load\|loop\|private\|proc\|protected\)\>" transparent contains=NONE
syn match rubyKeywordAsMethod "\%(\%(\.\@<!\.\)\|::\)\_s*\%(public\|require\|raise\|throw\|trap\)\>" transparent contains=NONE

" __END__ Directive
syn region rubyData matchgroup=rubyDataDirective start="^__END__$" end="\%$" fold

" Define the default highlighting.
" For version 5.7 and earlier: only when not done already
" For version 5.8 and later: only when an item doesn't have highlighting yet
if version >= 508 || !exists("did_ruby_syntax_inits")
if version < 508
let did_ruby_syntax_inits = 1
command -nargs=+ HiLink hi link <args>
else
command -nargs=+ HiLink hi def link <args>
endif

HiLink rubyDefine Define
HiLink rubyFunction Function
HiLink rubyControl Statement
HiLink rubyInclude Include
HiLink rubyInteger Number
HiLink rubyASCIICode rubyInteger
HiLink rubyFloat Float
HiLink rubyBoolean rubyPseudoVariable
HiLink rubyException Exception
HiLink rubyClass Type
HiLink rubyModule Type
if !exists("ruby_no_identifiers")
HiLink rubyIdentifier Identifier
else
HiLink rubyIdentifier NONE
endif
HiLink rubyClassVariable rubyIdentifier
HiLink rubyConstant rubyIdentifier
HiLink rubyGlobalVariable rubyIdentifier
HiLink rubyBlockParameter rubyIdentifier
HiLink rubyInstanceVariable rubyIdentifier
HiLink rubyPredefinedIdentifier rubyIdentifier
HiLink rubyPredefinedConstant rubyPredefinedIdentifier
HiLink rubyPredefinedVariable rubyPredefinedIdentifier
HiLink rubySymbol rubyIdentifier
HiLink rubyKeyword Keyword
HiLink rubyOperator Operator
HiLink rubyBeginEnd Statement
HiLink rubyAccess Statement
HiLink rubyAttribute Statement
HiLink rubyEval Statement
HiLink rubyPseudoVariable Constant

HiLink rubyComment Comment
HiLink rubyData Comment
HiLink rubyDataDirective Delimiter
HiLink rubyDocumentation Comment
HiLink rubyEscape Special
HiLink rubyInterpolation Special
HiLink rubyNoInterpolation rubyString
HiLink rubySharpBang PreProc
HiLink rubyStringDelimiter Delimiter
HiLink rubyString String
HiLink rubyTodo Todo

HiLink rubyError Error
HiLink rubySpaceError rubyError

delcommand HiLink
endif

let b:current_syntax = "ruby"

" vim: nowrap sw=2 sts=2 ts=8 ff=unix:

Loading…
Cancel
Save