if exists('g:polyglot_disabled') && index(g:polyglot_disabled, 'ruby') != -1 finish endif " Vim filetype plugin " Language: Ruby " Maintainer: Tim Pope " URL: https://github.com/vim-ruby/vim-ruby " Release Coordinator: Doug Kearns 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\|=\@=\@!' . \ ':' . \ '\<\%(else\|elsif\|ensure\|when\|rescue\|break\|redo\|next\|retry\)\>' . \ ':' . \ '}\|\%(^\|[^.\:@$=]\)\@<=\' . \ ',^=begin\>:^=end\>,' . \ ',\[:\],(:)' let b:match_skip = \ "synIDattr(synID(line('.'),col('.'),0),'name') =~ '" . \ "\\'" 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') 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' '' a:flags a:map let b:undo_ftplugin .= '|sil! '.a:mode.'unmap '.from endif endfunction cmap