FILE: C:\Program Files\Git\usr\share\vim\vim91\ftplugin\ruby.vim
--
" Vim filetype plugin
" Language: Ruby
" Maintainer: Tim Pope
" URL: https://github.com/vim-ruby/vim-ruby
" Last Change: 2023 Dec 31
" 2024 Jan 14 by Vim Project (browsefilter)
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=b:#
setlocal commentstring=#\ %s
if !exists('g:ruby_version_paths')
let g:ruby_version_paths = {}
endif
let s:path_split = has('win32') ? ';' : ':'
function! s:query_path(root) abort
" Disabled by default for security reasons.
if !get(g:, 'ruby_exec', get(g:, 'plugin_exec', 0)) || empty(a:root)
return map(split($RUBYLIB, s:path_split), 'v:val ==# "." ? "" : v:val')
endif
let code = "print $:.join %q{,}"
if &shellxquote == "'"
let args = ' --disable-gems -e "' . code . '"'
else
let args = " --disable-gems -e '" . code . "'"
endif
let cd = haslocaldir() ? 'lcd' : exists(':tcd') && haslocaldir(-1) ? 'tcd' : 'cd'
let cwd = fnameescape(getcwd())
try
exe cd fnameescape(a:root)
for dir in split($PATH, s:path_split)
if dir !=# '.' && executable(dir . '/ruby') == 1
let exepath = dir . '/ruby'
break
endif
endfor
if exists('l:exepath')
let path = split(system(exepath . args),',')
if v:shell_error
let path = []
endif
else
let path = []
endif
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 = path . ',.,,'
elseif &g:path =~# ',\.,,$'
let path = &g:path[0:-4] . path . ',.,,'
elseif &g:path =~# ',,$'
let path = &g:path[0:-2] . path . ',,'
else
let path = substitute(&g:path, '[^,]\zs$', ',', '') . 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{,}) )
else
let g:ruby_default_path = s:query_path($HOME)
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"
if has("win32")
let b:browsefilter .= "All Files (*.*)\t*\n"
else
let b:browsefilter .= "All Files (*)\t*\n"
endif
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