mirror of
https://github.com/SpaceVim/SpaceVim.git
synced 2025-04-14 15:19:12 +08:00
feat(lang#ruby): use bundle vim-ruby
This commit is contained in:
parent
3983da1c7b
commit
52df4ec9fe
@ -101,7 +101,7 @@ endif
|
||||
|
||||
function! SpaceVim#layers#lang#ruby#plugins() abort
|
||||
return [
|
||||
\ ['vim-ruby/vim-ruby', { 'on_ft' : 'ruby' }]
|
||||
\ [g:_spacevim_root_dir . 'bundle/vim-ruby', {'merged' : 0}]
|
||||
\ ]
|
||||
endfunction
|
||||
|
||||
|
1
bundle/vim-ruby/.gitignore
vendored
Normal file
1
bundle/vim-ruby/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
doc/tags
|
1
bundle/vim-ruby/.rspec
vendored
Normal file
1
bundle/vim-ruby/.rspec
vendored
Normal file
@ -0,0 +1 @@
|
||||
--color
|
19
bundle/vim-ruby/CONTRIBUTORS
vendored
Normal file
19
bundle/vim-ruby/CONTRIBUTORS
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
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>
|
1579
bundle/vim-ruby/ChangeLog
vendored
Normal file
1579
bundle/vim-ruby/ChangeLog
vendored
Normal file
File diff suppressed because it is too large
Load Diff
4
bundle/vim-ruby/Gemfile
vendored
Normal file
4
bundle/vim-ruby/Gemfile
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
source 'http://rubygems.org'
|
||||
|
||||
gem 'rspec'
|
||||
gem 'vimrunner'
|
28
bundle/vim-ruby/Gemfile.lock
vendored
Normal file
28
bundle/vim-ruby/Gemfile.lock
vendored
Normal file
@ -0,0 +1,28 @@
|
||||
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
|
38
bundle/vim-ruby/INSTALL.markdown
vendored
Normal file
38
bundle/vim-ruby/INSTALL.markdown
vendored
Normal file
@ -0,0 +1,38 @@
|
||||
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).
|
243
bundle/vim-ruby/NEWS
vendored
Normal file
243
bundle/vim-ruby/NEWS
vendored
Normal file
@ -0,0 +1,243 @@
|
||||
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.
|
63
bundle/vim-ruby/README.markdown
vendored
Normal file
63
bundle/vim-ruby/README.markdown
vendored
Normal file
@ -0,0 +1,63 @@
|
||||
## 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.
|
871
bundle/vim-ruby/autoload/rubycomplete.vim
vendored
Normal file
871
bundle/vim-ruby/autoload/rubycomplete.vim
vendored
Normal file
@ -0,0 +1,871 @@
|
||||
" 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:
|
39
bundle/vim-ruby/compiler/eruby.vim
vendored
Normal file
39
bundle/vim-ruby/compiler/eruby.vim
vendored
Normal file
@ -0,0 +1,39 @@
|
||||
" 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:
|
39
bundle/vim-ruby/compiler/rake.vim
vendored
Normal file
39
bundle/vim-ruby/compiler/rake.vim
vendored
Normal file
@ -0,0 +1,39 @@
|
||||
" 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:
|
35
bundle/vim-ruby/compiler/rspec.vim
vendored
Normal file
35
bundle/vim-ruby/compiler/rspec.vim
vendored
Normal file
@ -0,0 +1,35 @@
|
||||
" 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:
|
44
bundle/vim-ruby/compiler/ruby.vim
vendored
Normal file
44
bundle/vim-ruby/compiler/ruby.vim
vendored
Normal file
@ -0,0 +1,44 @@
|
||||
" 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:
|
35
bundle/vim-ruby/compiler/rubyunit.vim
vendored
Normal file
35
bundle/vim-ruby/compiler/rubyunit.vim
vendored
Normal file
@ -0,0 +1,35 @@
|
||||
" 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:
|
148
bundle/vim-ruby/doc/ft-ruby-indent.txt
vendored
Normal file
148
bundle/vim-ruby/doc/ft-ruby-indent.txt
vendored
Normal file
@ -0,0 +1,148 @@
|
||||
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:
|
52
bundle/vim-ruby/doc/ft-ruby-omni.txt
vendored
Normal file
52
bundle/vim-ruby/doc/ft-ruby-omni.txt
vendored
Normal file
@ -0,0 +1,52 @@
|
||||
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:
|
81
bundle/vim-ruby/doc/ft-ruby-plugin.txt
vendored
Normal file
81
bundle/vim-ruby/doc/ft-ruby-plugin.txt
vendored
Normal file
@ -0,0 +1,81 @@
|
||||
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:
|
119
bundle/vim-ruby/doc/ft-ruby-syntax.txt
vendored
Normal file
119
bundle/vim-ruby/doc/ft-ruby-syntax.txt
vendored
Normal file
@ -0,0 +1,119 @@
|
||||
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:
|
621
bundle/vim-ruby/etc/examples/generators/syntax.rb
vendored
Normal file
621
bundle/vim-ruby/etc/examples/generators/syntax.rb
vendored
Normal file
@ -0,0 +1,621 @@
|
||||
#!/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
|
16
bundle/vim-ruby/etc/examples/indent/closing_brackets.rb
vendored
Normal file
16
bundle/vim-ruby/etc/examples/indent/closing_brackets.rb
vendored
Normal file
@ -0,0 +1,16 @@
|
||||
[1, [2,
|
||||
[3],
|
||||
3],
|
||||
4]
|
||||
|
||||
[1, [2,
|
||||
3],
|
||||
4]
|
||||
|
||||
[1, {2 =>
|
||||
3},
|
||||
4]
|
||||
|
||||
[1, f(2,
|
||||
3),
|
||||
4]
|
42
bundle/vim-ruby/ftdetect/ruby.vim
vendored
Normal file
42
bundle/vim-ruby/ftdetect/ruby.vim
vendored
Normal file
@ -0,0 +1,42 @@
|
||||
" 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:
|
72
bundle/vim-ruby/ftdetect/ruby_extra.vim
vendored
Normal file
72
bundle/vim-ruby/ftdetect/ruby_extra.vim
vendored
Normal file
@ -0,0 +1,72 @@
|
||||
" 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:
|
135
bundle/vim-ruby/ftplugin/eruby.vim
vendored
Normal file
135
bundle/vim-ruby/ftplugin/eruby.vim
vendored
Normal file
@ -0,0 +1,135 @@
|
||||
" 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')
|
||||
" No-op
|
||||
let b:undo_ftplugin = 'exe'
|
||||
endif
|
||||
if !empty(s:undo_ftplugin)
|
||||
let 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 | " . b: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:
|
444
bundle/vim-ruby/ftplugin/ruby.vim
vendored
Normal file
444
bundle/vim-ruby/ftplugin/ruby.vim
vendored
Normal file
@ -0,0 +1,444 @@
|
||||
" 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=b:#
|
||||
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 = 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{,}) )
|
||||
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>
|
||||
cmap <buffer> <SID><cfile> <Plug><cfile>
|
||||
cmap <buffer> <SID><ctag> <Plug><ctag>
|
||||
|
||||
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', '<script><silent>', '<C-]> <SID>:exe v:count1."tag <SID><ctag>"<SID>tagzv<CR>')
|
||||
call s:map('n', '<script><silent>', 'g<C-]> <SID>:exe "tjump <SID><ctag>"<SID>tagzv<CR>')
|
||||
call s:map('n', '<script><silent>', 'g] <SID>:exe "tselect <SID><ctag>"<SID>tagzv<CR>')
|
||||
call s:map('n', '<script><silent>', '<C-W>] <SID>:exe v:count1."stag <SID><ctag>"<SID>tagzv<CR>')
|
||||
call s:map('n', '<script><silent>', '<C-W><C-]> <SID>:exe v:count1."stag <SID><ctag>"<SID>tagzv<CR>')
|
||||
call s:map('n', '<script><silent>', '<C-W>g<C-]> <SID>:exe "stjump <SID><ctag>"<SID>tagzv<CR>')
|
||||
call s:map('n', '<script><silent>', '<C-W>g] <SID>:exe "stselect <SID><ctag>"<SID>tagzv<CR>')
|
||||
call s:map('n', '<script><silent>', '<C-W>} <SID>:exe v:count1."ptag <SID><ctag>"<CR>')
|
||||
call s:map('n', '<script><silent>', '<C-W>g} <SID>:exe "ptjump <SID><ctag>"<CR>')
|
||||
|
||||
call s:map('n', '<script><silent>', 'gf <SID>c:find <SID><cfile><CR>')
|
||||
call s:map('n', '<script><silent>', '<C-W>f <SID>c:sfind <SID><cfile><CR>')
|
||||
call s:map('n', '<script><silent>', '<C-W><C-F> <SID>c:sfind <SID><cfile><CR>')
|
||||
call s:map('n', '<script><silent>', '<C-W>gf <SID>c:tabfind <SID><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:
|
110
bundle/vim-ruby/indent/eruby.vim
vendored
Normal file
110
bundle/vim-ruby/indent/eruby.vim
vendored
Normal file
@ -0,0 +1,110 @@
|
||||
" 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:
|
989
bundle/vim-ruby/indent/ruby.vim
vendored
Normal file
989
bundle/vim-ruby/indent/ruby.vim
vendored
Normal file
@ -0,0 +1,989 @@
|
||||
" 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,=in\ ,=ensure,=rescue,==begin,==end
|
||||
setlocal indentkeys+==private,=protected,=public
|
||||
|
||||
let b:undo_indent = "setlocal indentexpr< indentkeys< smartindent<"
|
||||
|
||||
" 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\|in\|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\|in\|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\|\%(\%(^\|;\)\s*\)\@<=\<in\|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:
|
24
bundle/vim-ruby/spec/indent/arguments_spec.rb
vendored
Normal file
24
bundle/vim-ruby/spec/indent/arguments_spec.rb
vendored
Normal file
@ -0,0 +1,24 @@
|
||||
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
|
73
bundle/vim-ruby/spec/indent/basic_spec.rb
vendored
Normal file
73
bundle/vim-ruby/spec/indent/basic_spec.rb
vendored
Normal file
@ -0,0 +1,73 @@
|
||||
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
|
164
bundle/vim-ruby/spec/indent/blocks_spec.rb
vendored
Normal file
164
bundle/vim-ruby/spec/indent/blocks_spec.rb
vendored
Normal file
@ -0,0 +1,164 @@
|
||||
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
|
29
bundle/vim-ruby/spec/indent/case_in_spec.rb
vendored
Normal file
29
bundle/vim-ruby/spec/indent/case_in_spec.rb
vendored
Normal file
@ -0,0 +1,29 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe "Indenting" do
|
||||
# Reference: https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html
|
||||
specify "pattern-matching with case-in" do
|
||||
assert_correct_indenting 'rb', <<~EOF
|
||||
case {a: a}
|
||||
in {a:}
|
||||
p a
|
||||
end
|
||||
EOF
|
||||
|
||||
assert_correct_indenting 'rb', <<~EOF
|
||||
users = [{name: "Alice", age: 12}, {name: "Bob", age: 23}]
|
||||
users.any? do |user|
|
||||
user in {name: /B/, in: 20..}
|
||||
end #=> true
|
||||
EOF
|
||||
end
|
||||
|
||||
specify "does not deindent while typing" do
|
||||
assert_correct_indent_in_insert 'rb', <<~EOF, "index = 0", <<~RESULT
|
||||
def foo
|
||||
EOF
|
||||
def foo
|
||||
index = 0
|
||||
RESULT
|
||||
end
|
||||
end
|
323
bundle/vim-ruby/spec/indent/continuations_spec.rb
vendored
Normal file
323
bundle/vim-ruby/spec/indent/continuations_spec.rb
vendored
Normal file
@ -0,0 +1,323 @@
|
||||
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
|
46
bundle/vim-ruby/spec/indent/end_constructs_spec.rb
vendored
Normal file
46
bundle/vim-ruby/spec/indent/end_constructs_spec.rb
vendored
Normal file
@ -0,0 +1,46 @@
|
||||
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
|
18
bundle/vim-ruby/spec/indent/eruby_spec.rb
vendored
Normal file
18
bundle/vim-ruby/spec/indent/eruby_spec.rb
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
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
|
||||
|
78
bundle/vim-ruby/spec/indent/hanging_elements_spec.rb
vendored
Normal file
78
bundle/vim-ruby/spec/indent/hanging_elements_spec.rb
vendored
Normal file
@ -0,0 +1,78 @@
|
||||
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
|
10
bundle/vim-ruby/spec/indent/identifiers_spec.rb
vendored
Normal file
10
bundle/vim-ruby/spec/indent/identifiers_spec.rb
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe "Indenting" do
|
||||
specify "identifiers containing keyword substrings" do
|
||||
assert_correct_indenting <<~EOF
|
||||
foo_def
|
||||
42
|
||||
EOF
|
||||
end
|
||||
end
|
133
bundle/vim-ruby/spec/indent/indent_access_modifier_spec.rb
vendored
Normal file
133
bundle/vim-ruby/spec/indent/indent_access_modifier_spec.rb
vendored
Normal file
@ -0,0 +1,133 @@
|
||||
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
|
76
bundle/vim-ruby/spec/indent/method_definitions_spec.rb
vendored
Normal file
76
bundle/vim-ruby/spec/indent/method_definitions_spec.rb
vendored
Normal file
@ -0,0 +1,76 @@
|
||||
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
|
69
bundle/vim-ruby/spec/indent/nesting_spec.rb
vendored
Normal file
69
bundle/vim-ruby/spec/indent/nesting_spec.rb
vendored
Normal file
@ -0,0 +1,69 @@
|
||||
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
|
47
bundle/vim-ruby/spec/indent/splat_spec.rb
vendored
Normal file
47
bundle/vim-ruby/spec/indent/splat_spec.rb
vendored
Normal file
@ -0,0 +1,47 @@
|
||||
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
|
63
bundle/vim-ruby/spec/spec_helper.rb
vendored
Normal file
63
bundle/vim-ruby/spec/spec_helper.rb
vendored
Normal file
@ -0,0 +1,63 @@
|
||||
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_indent_in_insert(extension='rb', content, input, result)
|
||||
filename = "test.#{extension}"
|
||||
|
||||
IO.write filename, content
|
||||
|
||||
vim.edit filename
|
||||
vim.normal 'Go'
|
||||
vim.feedkeys input
|
||||
vim.write
|
||||
|
||||
expect(IO.read(filename)).to eq result
|
||||
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
|
17
bundle/vim-ruby/spec/syntax/blocks_spec.rb
vendored
Normal file
17
bundle/vim-ruby/spec/syntax/blocks_spec.rb
vendored
Normal file
@ -0,0 +1,17 @@
|
||||
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
|
BIN
bundle/vim-ruby/spec/syntax/characters_spec.rb
vendored
Normal file
BIN
bundle/vim-ruby/spec/syntax/characters_spec.rb
vendored
Normal file
Binary file not shown.
60
bundle/vim-ruby/spec/syntax/comments_spec.rb
vendored
Normal file
60
bundle/vim-ruby/spec/syntax/comments_spec.rb
vendored
Normal file
@ -0,0 +1,60 @@
|
||||
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
|
23
bundle/vim-ruby/spec/syntax/line_continuations_spec.rb
vendored
Normal file
23
bundle/vim-ruby/spec/syntax/line_continuations_spec.rb
vendored
Normal file
@ -0,0 +1,23 @@
|
||||
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
|
12
bundle/vim-ruby/spec/syntax/maxmempattern_limit_spec.rb
vendored
Normal file
12
bundle/vim-ruby/spec/syntax/maxmempattern_limit_spec.rb
vendored
Normal file
@ -0,0 +1,12 @@
|
||||
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
|
47
bundle/vim-ruby/spec/syntax/methods_spec.rb
vendored
Normal file
47
bundle/vim-ruby/spec/syntax/methods_spec.rb
vendored
Normal file
@ -0,0 +1,47 @@
|
||||
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
|
||||
|
||||
specify "endless def does not start a method region" do
|
||||
assert_correct_highlighting <<~'EOF', 'end', ''
|
||||
def foo = bar
|
||||
end
|
||||
EOF
|
||||
assert_correct_highlighting <<~'EOF', 'end', ''
|
||||
def foo (a, b) = bar
|
||||
end
|
||||
EOF
|
||||
end
|
||||
end
|
204
bundle/vim-ruby/spec/syntax/operators_spec.rb
vendored
Normal file
204
bundle/vim-ruby/spec/syntax/operators_spec.rb
vendored
Normal file
@ -0,0 +1,204 @@
|
||||
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
|
21
bundle/vim-ruby/spec/syntax/regular_expressions_spec.rb
vendored
Normal file
21
bundle/vim-ruby/spec/syntax/regular_expressions_spec.rb
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
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
|
31
bundle/vim-ruby/spec/syntax/statement_modifiers_spec.rb
vendored
Normal file
31
bundle/vim-ruby/spec/syntax/statement_modifiers_spec.rb
vendored
Normal file
@ -0,0 +1,31 @@
|
||||
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
|
26
bundle/vim-ruby/spec/syntax/strings/heredoc_spec.rb
vendored
Normal file
26
bundle/vim-ruby/spec/syntax/strings/heredoc_spec.rb
vendored
Normal file
@ -0,0 +1,26 @@
|
||||
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
|
9
bundle/vim-ruby/spec/syntax/strings/interpolation_spec.rb
vendored
Normal file
9
bundle/vim-ruby/spec/syntax/strings/interpolation_spec.rb
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
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
|
9
bundle/vim-ruby/spec/syntax/strings/strings_spec.rb
vendored
Normal file
9
bundle/vim-ruby/spec/syntax/strings/strings_spec.rb
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
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
|
53
bundle/vim-ruby/spec/syntax/symbols_spec.rb
vendored
Normal file
53
bundle/vim-ruby/spec/syntax/symbols_spec.rb
vendored
Normal file
@ -0,0 +1,53 @@
|
||||
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
|
21
bundle/vim-ruby/spec/vim/plugin/syntax_test.vim
vendored
Normal file
21
bundle/vim-ruby/spec/vim/plugin/syntax_test.vim
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
|
||||
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
|
78
bundle/vim-ruby/syntax/eruby.vim
vendored
Normal file
78
bundle/vim-ruby/syntax/eruby.vim
vendored
Normal file
@ -0,0 +1,78 @@
|
||||
" 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 exists("b:current_syntax")
|
||||
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 !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 exists("b:eruby_subtype") && b:eruby_subtype != '' && b:eruby_subtype !=? 'eruby'
|
||||
exe "runtime! syntax/".b:eruby_subtype.".vim"
|
||||
unlet! b:current_syntax
|
||||
endif
|
||||
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 = 'eruby'
|
||||
|
||||
if main_syntax == 'eruby'
|
||||
unlet main_syntax
|
||||
endif
|
||||
|
||||
" vim: nowrap sw=2 sts=2 ts=8:
|
605
bundle/vim-ruby/syntax/ruby.vim
vendored
Normal file
605
bundle/vim-ruby/syntax/ruby.vim
vendored
Normal file
@ -0,0 +1,605 @@
|
||||
" 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
|
||||
|
||||
" endless def
|
||||
syn match rubyDefine "\<def\s\+\ze[^[:space:];#(]\+\%(\s\+\|\s*(.*)\s*\)=" nextgroup=rubyMethodDeclaration skipwhite
|
||||
|
||||
" 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:
|
@ -19,7 +19,12 @@ description: "This layer is for Ruby development, provides autocompletion, synta
|
||||
|
||||
## Description
|
||||
|
||||
This layer is for Ruby development.
|
||||
This layer is for Ruby development. Including following features:
|
||||
|
||||
- code completion for ruby, requires `+ruby`
|
||||
- syntax highlight
|
||||
- syntax linter
|
||||
- language server protocol
|
||||
|
||||
## Install
|
||||
|
||||
@ -40,7 +45,7 @@ gem install ruby-lint
|
||||
|
||||
The default code formatter is [rubocop](https://github.com/bbatsov/rubocop).
|
||||
|
||||
```sh
|
||||
```
|
||||
gem install rubocop
|
||||
```
|
||||
|
||||
@ -63,6 +68,7 @@ gem install rubocop
|
||||
```
|
||||
|
||||
- `repl_command`: Set the REPL command for ruby.
|
||||
|
||||
```toml
|
||||
[[layers]]
|
||||
name = 'lang#ruby'
|
||||
@ -71,6 +77,7 @@ gem install rubocop
|
||||
|
||||
- `format_on_save`: Enable/disable code formatting when saving ruby file. Default is `false`.
|
||||
To enable this feature:
|
||||
|
||||
```toml
|
||||
[[layers]]
|
||||
name = 'lang#ruby'
|
||||
|
Loading…
x
Reference in New Issue
Block a user