diff --git a/Gemfile.lock b/Gemfile.lock index a2d6c65a..8e061195 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,28 +1,29 @@ 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.5.1) + rspec (3.13.0) + rspec-core (~> 3.13.0) + rspec-expectations (~> 3.13.0) + rspec-mocks (~> 3.13.0) + rspec-core (3.13.2) + rspec-support (~> 3.13.0) + rspec-expectations (3.13.3) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.5.0) - rspec-mocks (3.5.0) + rspec-support (~> 3.13.0) + rspec-mocks (3.13.2) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.5.0) - rspec-support (3.5.0) - vimrunner (0.3.0) + rspec-support (~> 3.13.0) + rspec-support (3.13.2) + vimrunner (0.3.5) PLATFORMS ruby + x86_64-linux DEPENDENCIES rspec vimrunner BUNDLED WITH - 1.13.7 + 2.5.17 diff --git a/INSTALL.markdown b/INSTALL.markdown index b767bb58..f41556c5 100644 --- a/INSTALL.markdown +++ b/INSTALL.markdown @@ -9,7 +9,7 @@ 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 + git clone https://github.com/vim-ruby/vim-ruby.git ~/.vim/bundle/vim-ruby With Vundle ----------- @@ -28,6 +28,9 @@ 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 -------- diff --git a/README b/README deleted file mode 100644 index 39d9d91f..00000000 --- a/README +++ /dev/null @@ -1,73 +0,0 @@ - +---------------------------------+ - | vim-ruby github project README | - +---------------------------------+ - -Summary: - This project contains Vim configuration files for editing and compiling Ruby - within Vim. See the project homepage for more details. - -Web links: - Homepage: https://github.com/vim-ruby - Explanation: https://github.com/vim-ruby/vim-ruby/wiki - -For regular users: - - The project page should have two tarballs for download: - - vim-ruby-YYYY.MM.DD.tar.gz (the current stable release) - - vim-ruby-devel-YYYY.MM.DD.tar.gz (cutting-edge features we'd like you - to test) - - Please give feedback through the bug tracking and feature request features - of GitHub. - - Feel free to join discussions on the vim-ruby-devel mailing list: - http://rubyforge.org/mail/?group_id=16 - -For would-be contributors: - - Please get the latest from Git. - - Please join the mailing list and discuss changes, submit patches, etc. - - Thank you very much for taking an interest. - -Contents of the project: - - The autoload, compiler, ftdetect, ftplugin, indent and syntax directories - contain the ruby*.vim files that are to be copied to a location somewhere - in the Vim 'runtimepath'. - -How you get these files into Vim: - - By downloading the project via a snapshot or Git, you can keep up with - the latest, make changes, and install the files to a Vim directory. - - By downloading one of the tarballs, you can easily install the latest - stable or development version wherever you like on your machine. No - README etc. just Vim files. You would typically install these into either - $VIM/vimfiles, for system-wide use, or $HOME/.vim ($HOME/vimfiles on - Windows) for personal use. - - Remember that when you install Vim in the first place, all of these files - are present. The purpose of downloading and installing them from - GitHub is to get the latest version of them. - -Git topics: - - Project was migrated from CVS in August, 2008. - - Files are tagged according to which version of Vim they are released in. - - The project was initiated in July 2003, when the current version of Vim - was 6.2. Thus every file began its life tagged as vim6.2. - - Modifications to the files are made in the expectation that they need to - be tested by interested users. They therefore (probably) don't have a - tag, and are available via "git pull --rebase", or a development snapshot. - - When a modification is considered stable, it is given a tag. - Everything that is stable gets released in vim-ruby-YYY.MM.DD.tar.gz files. - - When a new version of Vim is about to be released, the stable tarball is - contributed to it. After it has been released, the files are tagged - accordingly. - - MORAL OF THE STORY: modifications are committed to the head of the tree; - when they are ready for release into userland, they are tagged "stable". - -Any questions or suggestions? - - If there's something about the project or its concepts that you don't - understand, send an email to the release coordinator, Doug Kearns - (dougkearns at gmail.com). - - To ask about the contents of the configuration files, open a GitHub issue - or ask on the mailing list, as different people maintain the different - files. - -Project gossip: - - While the individual effort to maintain these files has a long history, - this actual project began in late July 2003. - - --= End of Document =-- diff --git a/README.markdown b/README.markdown new file mode 100644 index 00000000..3a402271 --- /dev/null +++ b/README.markdown @@ -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. diff --git a/autoload/rubycomplete.vim b/autoload/rubycomplete.vim index a8c451e1..d62aa08b 100644 --- a/autoload/rubycomplete.vim +++ b/autoload/rubycomplete.vim @@ -1,9 +1,7 @@ " Vim completion script -" Language: Ruby -" Maintainer: Mark Guzman -" URL: https://github.com/vim-ruby/vim-ruby -" Release Coordinator: Doug Kearns -" Maintainer Version: 0.8.1 +" Language: Ruby +" Maintainer: Mark Guzman +" URL: https://github.com/vim-ruby/vim-ruby " ---------------------------------------------------------------------------- " " Ruby IRB/Complete author: Keiju ISHITSUKA(keiju@ishitsuka.com) @@ -53,6 +51,23 @@ if !exists("g:rubycomplete_include_objectspace") 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\):\@!\>' . + \ '\|\%(^\|[^.:@$]\)\@<=\' + +" Regex that defines the middle-match for the 'end' keyword. +let s:end_middle_regex = '\<\%(ensure\|else\|\%(\%(^\|;\)\s*\)\@<=\\|when\|elsif\):\@!\>' + +" Regex that defines the end-match for the 'end' keyword. +let s:end_end_regex = '\%(^\|[^.:@$]\)\@<=\' + +" }}} regex patterns + " {{{ vim-side support functions let s:rubycomplete_debug = 0 @@ -103,7 +118,7 @@ function! s:GetBufferRubyEntity( name, type, ... ) endif let curpos = getpos(".") - let [enum,ecol] = searchpairpos( crex, '', '\(end\|}\)', 'wr' ) + 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 @@ -128,19 +143,28 @@ function! s:IsPosInClassDef(pos) 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 pos = getpos('.') + 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('.',pos) + call setpos('.',curpos) let str = getline(lnum) let vtp = substitute(str,sstr,'\1','') return vtp endif - call setpos('.',pos) + 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' @@ -150,9 +174,13 @@ function! s:GetRubyVarType(v) let fstr = '=\s*\([^ \t]\+.' . ctors .'\>\|[\[{"''/]\|%[xwQqr][(\[{@]\|[A-Za-z0-9@:\-()\.]\+...\?\|lambda\|&\)' let sstr = ''.escape(a:v, '*').'\>\s*[+\-*/]*'.fstr - let [lnum,lcol] = searchpos(sstr,'nb',stopline) - if lnum != 0 && lcol != 0 - let str = matchstr(getline(lnum),fstr,lcol) + 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) @@ -174,7 +202,7 @@ function! s:GetRubyVarType(v) end return '' endif - call setpos('.',pos) + call setpos('.',curpos) return '' endfunction @@ -253,15 +281,27 @@ class VimRubyCompletion # {{{ 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 - eval( "require %s" % $1 ) if /.*require\s*(.*)$/.match( ln ) - rescue Exception - #ignore? + 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 @@ -344,8 +384,13 @@ class VimRubyCompletion if x != cur_line next if x == 0 ln = buf[x] - if /^\s*(module|class|def|include)\s+/.match(ln) - clscnt += 1 if $1 == "class" + 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) @@ -423,7 +468,6 @@ class VimRubyCompletion 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? @@ -444,7 +488,7 @@ class VimRubyCompletion trail = "%s%s" % [ dir, sub ] tcfg = "%sconfig" % trail - if File.exists?( tcfg ) + if File.exist?( tcfg ) rails_base = trail break end @@ -455,14 +499,9 @@ class VimRubyCompletion return if rails_base == nil $:.push rails_base unless $:.index( rails_base ) - rails_config = rails_base + "config/" - rails_lib = rails_base + "lib/" - $:.push rails_config unless $:.index( rails_config ) - $:.push rails_lib unless $:.index( rails_lib ) - - bootfile = rails_config + "boot.rb" - envfile = rails_config + "environment.rb" - if File.exists?( bootfile ) && File.exists?( envfile ) + bootfile = rails_base + "config/boot.rb" + envfile = rails_base + "config/environment.rb" + if File.exist?( bootfile ) && File.exist?( envfile ) begin require bootfile require envfile @@ -529,7 +568,6 @@ class VimRubyCompletion ret += ActiveRecord::ConnectionAdapters::SchemaStatements.methods end - return ret end @@ -614,7 +652,6 @@ class VimRubyCompletion 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 @@ -657,25 +694,25 @@ class VimRubyCompletion methods.delete_if { |c| c.match( /'/ ) } end - when /^::([A-Z][^:\.\(]*)$/ # Absolute Constant or class methods + when /^::([A-Z][^:\.\(]*)?$/ # Absolute Constant or class methods dprint "const or cls" receiver = $1 - methods = Object.constants - methods.grep(/^#{receiver}/).collect{|e| "::" + e} + 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 - classes = eval("#{receiver}.constants") - #methods = eval("#{receiver}.methods") + 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 - methods.grep(/^#{message}/).collect{|e| receiver + "::" + e} when /^(:[^:.]+)\.([^.]*)$/ # Symbol dprint "symbol" @@ -788,7 +825,6 @@ class VimRubyCompletion 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" @@ -831,5 +867,4 @@ 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: diff --git a/compiler/eruby.vim b/compiler/eruby.vim index 45ad5eea..64fa2c1d 100644 --- a/compiler/eruby.vim +++ b/compiler/eruby.vim @@ -2,7 +2,6 @@ " Language: eRuby " Maintainer: Doug Kearns " URL: https://github.com/vim-ruby/vim-ruby -" Release Coordinator: Doug Kearns if exists("current_compiler") finish @@ -28,8 +27,8 @@ CompilerSet errorformat= \%W%f:%l:\ warning:\ %m, \%E%f:%l:in\ %*[^:]:\ %m, \%E%f:%l:\ %m, - \%-C%\tfrom\ %f:%l:in\ %.%#, - \%-Z%\tfrom\ %f:%l, + \%-C%\t%\\d%#:%#\ %#from\ %f:%l:in\ %.%#, + \%-Z%\t%\\d%#:%#\ %#from\ %f:%l, \%-Z%p^, \%-G%.%# diff --git a/compiler/rake.vim b/compiler/rake.vim index c876e17b..8dc468aa 100644 --- a/compiler/rake.vim +++ b/compiler/rake.vim @@ -2,7 +2,6 @@ " Language: Rake " Maintainer: Tim Pope " URL: https://github.com/vim-ruby/vim-ruby -" Release Coordinator: Doug Kearns if exists("current_compiler") finish @@ -20,12 +19,12 @@ CompilerSet makeprg=rake CompilerSet errorformat= \%D(in\ %f), - \%\\s%#from\ %f:%l:%m, - \%\\s%#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%#%\\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!, diff --git a/compiler/rspec.vim b/compiler/rspec.vim index c77bd70d..a9b25c83 100644 --- a/compiler/rspec.vim +++ b/compiler/rspec.vim @@ -2,7 +2,6 @@ " Language: RSpec " Maintainer: Tim Pope " URL: https://github.com/vim-ruby/vim-ruby -" Release Coordinator: Doug Kearns if exists("current_compiler") finish @@ -23,7 +22,8 @@ CompilerSet errorformat= \%E%.%#:in\ `load':\ %f:%l:%m, \%E%f:%l:in\ `%*[^']':\ %m, \%-Z\ \ \ \ \ %\\+\#\ %f:%l:%.%#, - \%E\ \ %\\d%\\+)%.%#, + \%E\ \ \ \ \ Failure/Error:\ %m, + \%E\ \ \ \ \ Failure/Error:, \%C\ \ \ \ \ %m, \%C%\\s%#, \%-G%.%# diff --git a/compiler/ruby.vim b/compiler/ruby.vim index dcf7a401..55c53640 100644 --- a/compiler/ruby.vim +++ b/compiler/ruby.vim @@ -3,8 +3,6 @@ " Function: Syntax check and/or error reporting " Maintainer: Tim Pope " URL: https://github.com/vim-ruby/vim-ruby -" Release Coordinator: Doug Kearns -" ---------------------------------------------------------------------------- if exists("current_compiler") finish @@ -21,21 +19,21 @@ set cpo-=C " default settings runs script normally " add '-c' switch to run syntax check only: " -" CompilerSet makeprg=ruby\ -wc\ $* +" CompilerSet makeprg=ruby\ -c " " or add '-c' at :make command line: " " :make -c % " -CompilerSet makeprg=ruby\ -w\ $* +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%\tfrom\ %f:%l:in\ %.%#, - \%-Z%\tfrom\ %f:%l, + \%-C%\t%\\d%#:%#\ %#from\ %f:%l:in\ %.%#, + \%-Z%\t%\\d%#:%#\ %#from\ %f:%l, \%-Z%p^, \%-G%.%# diff --git a/compiler/rubyunit.vim b/compiler/rubyunit.vim index ed0639b5..6d785056 100644 --- a/compiler/rubyunit.vim +++ b/compiler/rubyunit.vim @@ -2,7 +2,6 @@ " Language: Test::Unit - Ruby Unit Testing Framework " Maintainer: Doug Kearns " URL: https://github.com/vim-ruby/vim-ruby -" Release Coordinator: Doug Kearns if exists("current_compiler") finish diff --git a/doc/ft-ruby-indent.txt b/doc/ft-ruby-indent.txt new file mode 100644 index 00000000..f59d7b32 --- /dev/null +++ b/doc/ft-ruby-indent.txt @@ -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: diff --git a/doc/ft-ruby-omni.txt b/doc/ft-ruby-omni.txt index 5f8fc4df..2abe97fd 100644 --- a/doc/ft-ruby-omni.txt +++ b/doc/ft-ruby-omni.txt @@ -1,4 +1,5 @@ -RUBY *ft-ruby-omni* +RUBY *ft-ruby-omni* + *vim-ruby-omni* Completion of Ruby code requires that Vim be built with |+ruby|. @@ -21,28 +22,31 @@ The completions provided by CTRL-X CTRL-O are sensitive to the context: 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 + 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, +< - 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 +< 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 > + 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 +< 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: > +< To specify an alternative path, use: > let g:rubycomplete_gemfile_path = 'Gemfile.aux' -< To use Bundler.require instead of parsing the Gemfile, set: > +< 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: diff --git a/doc/ft-ruby-plugin.txt b/doc/ft-ruby-plugin.txt new file mode 100644 index 00000000..80b451d8 --- /dev/null +++ b/doc/ft-ruby-plugin.txt @@ -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: diff --git a/doc/ft-ruby-syntax.txt b/doc/ft-ruby-syntax.txt index 8e296dba..2979f20c 100644 --- a/doc/ft-ruby-syntax.txt +++ b/doc/ft-ruby-syntax.txt @@ -1,7 +1,9 @@ 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| @@ -9,10 +11,13 @@ RUBY *ruby.vim* *ft-ruby-syntax* *ruby_operators* Ruby: Operator highlighting ~ -Operators can be highlighted by defining "ruby_operators": > +Operators, and pseudo operators, can be highlighted by defining: > - :let ruby_operators = 1 + :let ruby_operators = 1 + :let ruby_pseudo_operators = 1 < +The supported pseudo operators are ., &., ::, *, **, &, <, << and ->. + *ruby_space_errors* Ruby: Whitespace errors ~ @@ -25,7 +30,16 @@ 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_fold* + *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": > @@ -68,6 +82,8 @@ The value is a space-separated list of keywords: << 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 ~ diff --git a/doc/vim-ruby.txt b/doc/vim-ruby.txt deleted file mode 100644 index 4fe3dd0f..00000000 --- a/doc/vim-ruby.txt +++ /dev/null @@ -1,166 +0,0 @@ -*vim-ruby.txt* - -1. Ruby motions |ruby-motion| -2. Ruby text objects |ruby-text-objects| -3. Access modifier indentation |ruby-access-modifier-indentation| -4. Block style indentation |ruby-block-style-indentation| -5. Assignment style indentation |ruby-assignment-style-indentation| - -============================================================================== -1. Ruby motions *ruby-motion* - -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. - -============================================================================== -2. 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. - -============================================================================== -3. Access modifier indentation *ruby-access-modifier-indentation* - *g:ruby_indent_access_modifier_style* - -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 -< - -============================================================================== -4. Block style indentation *ruby-block-style-indentation* - *g:ruby_indent_block_style* - -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 "expression" 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 -< - -============================================================================== -5. Assignment style indentation *ruby-assignment-style-indentation* - *g:ruby_indent_assignment_style* - -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 -< - - vim:tw=78:sw=4:ts=8:ft=help:norl: diff --git a/ftdetect/ruby_extra.vim b/ftdetect/ruby_extra.vim index 8bae53c1..b1a9b883 100644 --- a/ftdetect/ruby_extra.vim +++ b/ftdetect/ruby_extra.vim @@ -14,6 +14,9 @@ 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') @@ -30,6 +33,9 @@ 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') @@ -54,6 +60,9 @@ 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') diff --git a/ftplugin/eruby.vim b/ftplugin/eruby.vim index 519106b3..3581eb8e 100644 --- a/ftplugin/eruby.vim +++ b/ftplugin/eruby.vim @@ -2,7 +2,6 @@ " Language: eRuby " Maintainer: Tim Pope " URL: https://github.com/vim-ruby/vim-ruby -" Release Coordinator: Doug Kearns " Only do this when not done yet for this buffer if exists("b:did_ftplugin") @@ -66,12 +65,31 @@ if exists("b:match_words") unlet b:match_words endif +let s:cfilemap = v:version >= 704 ? maparg('', '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 =~# '\\' && len(expand('')) ? eval(substitute(&l:inex, '\\', '\\=string(expand(\"\"))', 'g')) : '', '^$', \"\\022\\006\",'')" +endif +let s:ctagmap = v:version >= 704 ? maparg('', 'c', 0, 1) : {} +if !get(s:ctagmap, 'buffer') || !s:ctagmap.expr || s:ctagmap.rhs =~# 'ErubyAtCursor()' + let s:ctagmap = {} +endif +let s:include = &l:include +let s:path = &l:path +let s:suffixesadd = &l:suffixesadd + runtime! ftplugin/ruby.vim ftplugin/ruby_*.vim ftplugin/ruby/*.vim let b:did_ftplugin = 1 " Combine the new set of values with those previously included. -if exists("b:undo_ftplugin") - let s:undo_ftplugin = b:undo_ftplugin . " | " . s:undo_ftplugin +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 @@ -80,6 +98,15 @@ 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