diff --git a/.rspec b/.rspec new file mode 100644 index 00000000..4e1e0d2f --- /dev/null +++ b/.rspec @@ -0,0 +1 @@ +--color diff --git a/CONTRIBUTORS b/CONTRIBUTORS index 20888fc1..732f0cf2 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -2,7 +2,7 @@ Maintainers: Mark Guzman Doug Kearns Tim Pope - Andrew Radev + Andrew Radev Nikolai Weibull Other contributors: @@ -16,3 +16,4 @@ Other contributors: Gavin Sinclair Aaron Son Ned Konz + Pan Thomakos diff --git a/FAQ b/FAQ deleted file mode 100644 index 2776d614..00000000 --- a/FAQ +++ /dev/null @@ -1,251 +0,0 @@ -*vim-ruby.txt* *vim-ruby* *vim-ruby-faq* - - VIM/RUBY CONFIGURATION FILES - - The vim-ruby Project FAQ - - https://github.com/vim-ruby/vim-ruby - -The vim-ruby project maintains Ruby-related configuration files for Vim. This -FAQ contains all you need to know about it. - -*** TOC *** - -============================================================================== - -*vim-ruby-faq-X* What is the vim-ruby project? - -It maintains all the configuration files that help Vim edit Ruby code. By -installing these files, Vim will properly highlight and indent Ruby files, and -will be able to run them and go directly to the location of any errors. -Rakefiles, ERB files, and unit tests are also identified and supported. - -If you make use of this project, make sure you read the installation and -configuration instructions in this FAQ. - - -*vim-ruby-faq-X* Doesn't Vim include these files? - -Yes it does. You should only want to download and install this project if it -has changed since you last installed your version of Vim. Read the "News" -section of the |vim-ruby-homepage| to see when the most recent release was -made. - - -*vim-ruby-faq-X* How do you get it? - -The easiest way is to run: > - - gem install vim-ruby - -(This really only downloads it. See installation instructions -|vim-ruby-install| below.) - -If you don't have RubyGems, download a tarball from: > - - https://github.com/vim-ruby/vim-ruby/downloads - -Again, see installation instructions below. - - -*vim-ruby-faq-X* How do you install it? *vim-ruby-install* - -If you obtained the vim-ruby files via RubyGems, run: > - - vim-ruby-install.rb - -If you downloaded a tarball, unpack it, change to the created directory, and -run: > - - ruby bin/vim-ruby-install.rb - -Whichever way you run it, the effect is the same. The installer will: - - Search for a Vim config directory to put its files and ask you to confirm. - - Copy the configuration files to the appropriate places underneath the - directory you selected. - -Here is an example installation transcript: - - Possible Vim installation directories: ~ - 1) D:/Gavin/vimfiles ~ - 2) E:/Vim/vimfiles ~ - ~ - Please select one (or anything else to specify another directory): 2 ~ - autoload/rubycomplete.vim -> E:/Vim/vimfiles/autoload/rubycomplete.vim ~ - compiler/eruby.vim -> E:/Vim/vimfiles/compiler/eruby.vim ~ - compiler/ruby.vim -> E:/Vim/vimfiles/compiler/ruby.vim ~ - compiler/rubyunit.vim -> E:/Vim/vimfiles/compiler/rubyunit.vim ~ - ftdetect/ruby.vim -> E:/Vim/vimfiles/ftdetect/ruby.vim ~ - ftplugin/eruby.vim -> E:/Vim/vimfiles/ftplugin/eruby.vim ~ - ftplugin/ruby.vim -> E:/Vim/vimfiles/ftplugin/ruby.vim ~ - indent/eruby.vim -> E:/Vim/vimfiles/indent/eruby.vim ~ - indent/ruby.vim -> E:/Vim/vimfiles/indent/ruby.vim ~ - syntax/eruby.vim -> E:/Vim/vimfiles/syntax/eruby.vim ~ - syntax/ruby.vim -> E:/Vim/vimfiles/syntax/ruby.vim ~ - -Existing files are overwritten. This is safe, because it's a slow-maturing -project, so new files are better than old ones. However, if you had edited the -files, you will have lost your changes. Better make your changes in, for -instance: - - ~/.vim/after/ftplugin/ruby.vim ~ - -This file will be loaded _after_ the regular config files are loaded, so your -customisations will definitely take effect. - - -*vim-ruby-faq-X* What Vim config do I need? *vim-ruby-config* - -Without the following lines in your .vimrc, _vimrc, or other startup file, the -files in the vim-ruby project will be largely useless. > - - set nocompatible " We're running Vim, not Vi! - syntax on " Enable syntax highlighting - filetype on " Enable filetype detection - filetype indent on " Enable filetype-specific indenting - filetype plugin on " Enable filetype-specific plugins - compiler ruby " Enable compiler support for ruby - -See |.vimrc| for more information about this important Vim configuration file. - -See |matchit-install| for instructions on installing "matchit", which will -allow you to use |%| to bounce between Ruby keywords (class, def, while, ...) -and their respective "end" keywords. - - -*vim-ruby-faq-X* How do I know that everything's working? - -If you've run the installer and added the configuration |vim-ruby-config| -above, everything should be fine when you restart Vim. To test this: - - Edit a Ruby file with Vim (make sure it has a .rb extension). - - The code should be syntax highlighted. - - Type in some code. When you start a new line, it should be automatically - indented to the correct spot. - - Add or remove some space from the beginning of a line of code and hit ==. - That line should be reindented. - - Put the cursor on a "class" or "def" keyword and hit %. The cursor should - now be on the matching "end" keyword. - - TODO: what else? - - -*vim-ruby-faq-X* How do I use it? - -TODO: write. - - -*vim-ruby-faq-X* How do I customise it? *vim-ruby-customize* - -The most important customisation for editing Ruby code is the amount of space to -indent. The following is a typical setup. Look up the various options to read -about them. > - - set expandtab - set tabstop=2 shiftwidth=2 softtabstop=2 - set autoindent - -TODO: is autoindent necessary? What other options should go here? What about -Ruby comments? -FIXME: Autoindent is good. maybe mention |i_CTRL_D| and |i_CTRL_T| for -moving lines about in this context? -COMMENT: I never use ^D and ^T in insert mode, though I always knew what they -do. Might try them! - - -*vim-ruby-faq-X* I want feature X. Will you include it? - -The idea of the vim-ruby project is to maintain configuration files that are -actually distributed with Vim. Therefore all functionality should be helpful to -all Vim/Ruby users. So the project does not deal with people's individual -tastes. - -That said, we are considering creating a separate configuration file for less -universal features, whose features users can pick and choose. So don't hesitate -to send us your suggestions. - - -*vim-ruby-faq-X* What are some other cool Ruby-related Vim tricks I can use? - -An example is the following (put it in ~/.vimrc/ftplugin/ruby_extra.vim or -similar): [similar? |$VIMRUNTIME| or what?] > - - if !exists( "*EndToken" ) - function EndToken() - let current_line = getline( '.' ) - let braces_at_end = '{\s*\(|\(,\|\s\|\w\)*|\s*\)\?$' - if match( current_line, braces_at_end ) >= 0 - return '}' - else - return 'end' - endif - endfunction - endif - - imap :execute 'normal o' . EndToken()O - -This will help you create ruby blocks of code, by inserting "}" or "end" as -appropriate. Try creating these lines of code and hitting SHIFT-ENTER: - - array.map { |elem| ~ - - def fibonacci(n) ~ - -For other suggestions, search the web or look at: > - - https://github.com/vim-ruby/vim-ruby/wiki/VimRubySupport - - -*vim-ruby-faq-X* How can I report a bug? *vim-ruby-bug-reporting* - -Bug reports are most welcome. In order of preference: - - submit a bug at https://github.com/vim-ruby/vim-ruby/issues - - send an email to the mailing list (see below) - - email the maintainer (email address appears in each configuration file) - - - *vim-ruby-list* -*vim-ruby-faq-X* Does the project have a mailing list? - -Yes: vim-ruby-devel@rubyforge.org. Only subscribers can post. To join, visit: -> - http://rubyforge.org/mailman/listinfo/vim-ruby-devel - -The list is mirrored at: > - - http://news.gmane.org/gmane.comp.editors.vim.vim%2druby.devel - - -*vim-ruby-faq-X* Why is this project separate from Vim? - -We can't use Vim's CVS to keep track of these files, so we organise it ourselves -and give Bram the latest files in time for each release of Vim. By keeping the -Ruby stuff together, we can release it all at once and people can update it -independently of Vim. - - -*vim-ruby-faq-X* I have another question... - -The mailing list or the file maintainer is a good place to ask. Or perhaps -comp.lang.ruby, but please make sure you've read the FAQ thoroughly before -asking there. - - -*vim-ruby-faq-X* Can you repeat all the web pages listed in this FAQ? - -Homepage *vim-ruby-homepage* : > - https://github.com/vim-ruby/vim-ruby/ - -Bug tracker: > - https://github.com/vim-ruby/vim-ruby/issues - -Relevant Wiki page: > - https://github.com/vim-ruby/vim-ruby/wiki - -Mailing list archives: > - http://news.gmane.org/gmane.comp.editors.vim.vim%2druby.devel - http://rubyforge.org/pipermail/vim-ruby-devel/ - -Mailing list join: > - http://rubyforge.org/mailman/listinfo/vim-ruby-devel - - -vim: ft=help tw=78 noet : diff --git a/Gemfile b/Gemfile new file mode 100644 index 00000000..c543a5dd --- /dev/null +++ b/Gemfile @@ -0,0 +1,4 @@ +source 'http://rubygems.org' + +gem 'rspec' +gem 'vimrunner' diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 00000000..8e061195 --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,29 @@ +GEM + remote: http://rubygems.org/ + specs: + 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.13.0) + rspec-mocks (3.13.2) + diff-lcs (>= 1.2.0, < 2.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 + 2.5.17 diff --git a/INSTALL.markdown b/INSTALL.markdown index 29ba3fb1..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,9 +28,11 @@ 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 an archive, and run `bin/vim-ruby-install.rb` to copy the -relevant files to `~/.vim`. +extract the relevant files to `~/.vim` (or `$HOME/vimfiles` on Windows). diff --git a/README b/README deleted file mode 100644 index 6f1bb2e1..00000000 --- a/README +++ /dev/null @@ -1,74 +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'. - - vim-ruby-install.rb performs this copying. - -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, no vim-ruby-install.rb, 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/Rakefile b/Rakefile deleted file mode 100644 index 37c6d573..00000000 --- a/Rakefile +++ /dev/null @@ -1,42 +0,0 @@ -require 'rubygems' -require 'rake/gempackagetask' - -PACKAGE_NAME = 'vim-ruby' -RELEASE_FILES = FileList[ - 'ChangeLog', 'CONTRIBUTORS', 'FAQ', 'INSTALL', 'NEWS', 'README', 'bin/*.rb', - 'doc/*.txt','{autoload,compiler,ftdetect,ftplugin,indent,syntax}/*.vim' -] -PACKAGE_VERSION = Time.now.gmtime.strftime('%Y.%m.%d') - -desc "Build all the packages" -task :default => :package - - -def gemspec - Gem::Specification.new do |s| - s.name = PACKAGE_NAME - s.version = PACKAGE_VERSION - s.files = RELEASE_FILES.to_a - s.summary = "Ruby configuration files for Vim. Run 'vim-ruby-install.rb' to complete installation." - s.description = s.summary + "\n\nThis package doesn't contain a Ruby library." - s.requirements << 'RubyGems 0.8+' << 'Vim 6.0+' - s.required_ruby_version = '>= 1.8.0' - s.require_path = '.' - s.bindir = 'bin' - s.executables = ['vim-ruby-install.rb'] - s.author = 'Gavin Sinclair et al.' - s.email = 'gsinclair@soyabean.com.au' - s.homepage = 'https://github.com/vim-ruby/vim-ruby' - s.has_rdoc = false - end -end - -Rake::GemPackageTask.new(gemspec) do |t| - t.package_dir = 'etc/package' - t.need_tar = true - t.need_zip = true -end - -# Supporting methods - -# vim: nowrap sw=2 sts=2 ts=8 ff=unix ft=ruby: diff --git a/autoload/rubycomplete.vim b/autoload/rubycomplete.vim index 1ecaea92..d62aa08b 100644 --- a/autoload/rubycomplete.vim +++ b/autoload/rubycomplete.vim @@ -1,26 +1,30 @@ " Vim completion script -" Language: Ruby -" Maintainer: Mark Guzman -" URL: https://github.com/vim-ruby/vim-ruby -" Anon CVS: See above site -" 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) " ---------------------------------------------------------------------------- " {{{ requirement checks + +function! s:ErrMsg(msg) + echohl ErrorMsg + echo a:msg + echohl None +endfunction + if !has('ruby') - s:ErrMsg( "Error: Rubycomplete requires vim compiled with +ruby" ) - s:ErrMsg( "Error: falling back to syntax completion" ) + 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 - s:ErrMsg( "Error: Required vim >= 7.0" ) + call s:ErrMsg( "Error: Required vim >= 7.0" ) finish endif " }}} requirement checks @@ -47,15 +51,26 @@ 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 -function! s:ErrMsg(msg) - echohl ErrorMsg - echo a:msg - echohl None -endfunction - function! s:dprint(msg) if s:rubycomplete_debug == 1 echom a:msg @@ -93,7 +108,7 @@ function! s:GetBufferRubyEntity( name, type, ... ) let stopline = 1 - let crex = '^\s*\<' . a:type . '\>\s*\<' . a:name . '\>\s*\(<\s*.*\s*\)\?' + 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' ) @@ -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 sstr = '^\s*#\s*@var\s*'.a:v.'\>\s\+[^ \t]\+\s*$' + 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' @@ -149,10 +173,14 @@ function! s:GetRubyVarType(v) let ctors = ctors.'\)' let fstr = '=\s*\([^ \t]\+.' . ctors .'\>\|[\[{"''/]\|%[xwQqr][(\[{@]\|[A-Za-z0-9@:\-()\.]\+...\?\|lambda\|&\)' - let sstr = ''.a:v.'\>\s*[+\-*/]*'.fstr - let [lnum,lcol] = searchpos(sstr,'nb',stopline) - if lnum != 0 && lcol != 0 - let str = matchstr(getline(lnum),fstr,lcol) + 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) @@ -174,7 +202,7 @@ function! s:GetRubyVarType(v) end return '' endif - call setpos('.',pos) + call setpos('.',curpos) return '' endfunction @@ -196,7 +224,7 @@ function! rubycomplete#Complete(findstart, base) if c =~ '\w' continue elseif ! c =~ '\.' - idx = -1 + let idx = -1 break else break @@ -253,15 +281,49 @@ 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 + + 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 @@ -274,7 +336,7 @@ class VimRubyCompletion 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\s*(.*)\s*\n/.match( classdef ) + mixre = /.*\n\s*(include|prepend)\s*(.*)\s*\n/.match( classdef ) load_buffer_module( $2 ) if mixre != nil && $2 != name # load mixins if needed begin @@ -322,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) @@ -363,6 +430,10 @@ class VimRubyCompletion 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") @@ -397,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? @@ -418,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 @@ -429,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 @@ -503,7 +568,6 @@ class VimRubyCompletion ret += ActiveRecord::ConnectionAdapters::SchemaStatements.methods end - return ret end @@ -525,9 +589,9 @@ class VimRubyCompletion end def clean_sel(sel, msg) - sel.delete_if { |x| x == nil } - sel.uniq! - sel.grep(/^#{Regexp.quote(msg)}/) if msg != nil + ret = sel.reject{|x|x.nil?}.uniq + ret = ret.grep(/^#{Regexp.quote(msg)}/) if msg != nil + ret end def get_rails_view_methods @@ -561,11 +625,13 @@ class VimRubyCompletion # {{{ main completion code def self.preload_rails a = VimRubyCompletion.new - require 'Thread' - Thread.new(a) do |b| - begin - b.load_rails - rescue + if VIM::evaluate("has('nvim')") == 0 + require 'thread' + Thread.new(a) do |b| + begin + b.load_rails + rescue + end end end a.load_rails @@ -584,6 +650,9 @@ class VimRubyCompletion 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] @@ -625,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" @@ -674,7 +743,9 @@ class VimRubyCompletion cv = eval("self.class.constants") vartype = get_var_type( receiver ) dprint "vartype: %s" % vartype - if vartype != '' + + invalid_vartype = ['', "gets"] + if !invalid_vartype.include?(vartype) load_buffer_class( vartype ) begin @@ -702,7 +773,7 @@ class VimRubyCompletion methods.concat m.instance_methods(false) } end - variables += add_rails_columns( "#{vartype}" ) if vartype && vartype.length > 0 + variables += add_rails_columns( "#{vartype}" ) if vartype && !invalid_vartype.include?(vartype) when /^\(?\s*[A-Za-z0-9:^@.%\/+*\(\)]+\.\.\.?[A-Za-z0-9:^@.%\/+*\(\)]+\s*\)?\.([^.]*)/ message = $1 @@ -754,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" @@ -766,10 +836,10 @@ class VimRubyCompletion constants = clean_sel( constants, message ) valid = [] - valid += methods.collect { |m| { :name => m, :type => 'm' } } - valid += variables.collect { |v| { :name => v, :type => 'v' } } - valid += classes.collect { |c| { :name => c, :type => 't' } } - valid += constants.collect { |d| { :name => d, :type => 'd' } } + 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 = "" @@ -778,7 +848,7 @@ class VimRubyCompletion 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] ] } + 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) @@ -797,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/bin/vim-ruby-install.rb b/bin/vim-ruby-install.rb deleted file mode 100755 index 81d81a7f..00000000 --- a/bin/vim-ruby-install.rb +++ /dev/null @@ -1,456 +0,0 @@ -#!/usr/bin/env ruby - -# vim-ruby-install: install the Vim config files for Ruby editing -# -# * scope out the target directory and get user to confirm -# * if no directory found, ask user -# * allow user to force a search for a Windows gvim installation -# * find source files from gem or from top level directory -# * copy to target directory, taking account of -# * line endings (NL for Unix-ish; CRLF for Windows) -# * permissions (755 for directories; 644 for files) -# - -require 'rbconfig' -include Config -require 'fileutils' -require 'optparse' -require 'pathname' - -SOURCE_FILES = %w{ - autoload/rubycomplete.vim - compiler/eruby.vim - compiler/rspec.vim - compiler/ruby.vim - compiler/rubyunit.vim - ftdetect/ruby.vim - ftplugin/eruby.vim - ftplugin/ruby.vim - indent/eruby.vim - indent/ruby.vim - syntax/eruby.vim - syntax/ruby.vim -} -#FIXME: ftdetect/ruby.vim - vim 6.3+ only. This won't cause problems for -# earlier versions; it just won't work! For versions less than 6.2 we -# need to create a filetype.vim file and add it to the root of the -# runtime directory. - - # - # Miscellaneous functions in the user's environment. - # -class Env - # - # Returns :UNIX or :WINDOWS, according to CONFIG['host_os'] and $options[:windows]. - # - def Env.determine_target_os - os = CONFIG['host_os'] - if os =~ /mswin/ or $options[:windows] - return :WINDOWS - else - return :UNIX - end - end - - # - # Returns the path to the directory where the vim configuration files will be copied from. - # The first preference is the directory above this script. If that fails, we look for the - # RubyGems package 'vim-ruby'. Failing that, we return +nil+. - # - def Env.determine_source_directory - # 1. Try the directory above this installation script. - vim_ruby_source_dir = File.expand_path(File.join(File.dirname($0), '..')) - return vim_ruby_source_dir if _valid_vim_ruby_dir(vim_ruby_source_dir) - # 2. Try the gem 'vim-ruby'. - begin - require 'rubygems' - raise "Need RubyGems 0.8+" if Gem::RubyGemsPackageVersion < '0.8' - rescue LoadError - return nil - end - #vim_ruby_gem_dir = Gem.latest_load_paths.grep(%r{gems/vim-ruby-\d{4}\.\d{2}\.\d{2}}).last - vim_ruby_gem_dir = Gem.all_load_paths.grep(%r{gems/vim-ruby-\d{4}\.\d{2}\.\d{2}}).sort.last - if vim_ruby_gem_dir and _valid_vim_ruby_dir(vim_ruby_gem_dir) - return vim_ruby_gem_dir - end - return nil - end - - # Returns the Vim installation directory ($VIM). - # TODO: print warning if vim command not in PATH or appropriate key not in registry? - def Env.determine_vim_dir - installation_dir = ENV['VIM'] || - case Env.determine_target_os - when :UNIX - IO.popen('vim --version 2>/dev/null') do |version| - dir = version.read[/fall-back for \$VIM: "(.*)"/, 1] - end - when :WINDOWS - begin - require 'win32/registry' - Win32::Registry::HKEY_LOCAL_MACHINE.open('SOFTWARE\Vim\Gvim') do |reg| - path = reg['path', Win32::Registry::REG_SZ] - dir = path.sub(/\\vim\d\d\\gvim.exe/i, '') - end - rescue Win32::Registry::Error - nil - end - end - return installation_dir - end - - def Env.determine_home_dir - home_dir = ENV['HOME'] || - case Env.determine_target_os - when :WINDOWS - ENV['HOMEDRIVE'] + ENV['HOMEPATH'] if ENV['HOMEDRIVE'] and ENV['HOMEPATH'] - end - return home_dir - end - - def Env.ask_user(message) - print message - gets.strip - end - - private_class_method - - def Env._valid_vim_ruby_dir(dir) - Dir.chdir(dir) do - return SOURCE_FILES.all? { |path| FileTest.file?(path) } - end - end - -end # class Env - - - # - # A FileWriter writes files with pre-selected line endings and permissions. - # - # writer = FileWriter.new(:UNIX, 0664) - # writer.copy(source, target) - # -class FileWriter - LINE_ENDINGS = { :UNIX => "\n", :WINDOWS => "\r\n" } - - def initialize(ending, file_permissions=0644, directory_permissions=0755) - @ending = LINE_ENDINGS[ending] or raise "No/invalid line ending given: #{ending}" - @permissions = { - :file => file_permissions, - :dir => directory_permissions - } - end - # Source and target paths assumed to be Pathname objects. Copy the source to the target, - # ensuring the right line endings. - def copy(source_path, target_path) - _ensure_directory_exists(target_path) - target_path.open('wb', @permissions[:file]) do |io| - lines = source_path.read.split("\n") - lines.each do |line| - io.write(line.chomp + @ending) - end - end - puts "#{source_path.to_s.ljust(25)} -> #{target_path}" - end - # Create the given directory with the correct directory permissions. - def mkpath(directory) - FileUtils.mkdir_p(directory.to_s, :mode => @permissions[:dir], :verbose => true) - end - def _ensure_directory_exists(path) - dir = path.dirname - unless dir.directory? - # FileUtils.mkdir_p already checks if it exists and is a - # directory. What if it exists as a file? (HGS) - mkpath(dir) - end - end -end # class FileWriter - - - # - # Represents the target base directory for installs. Handles writing the files through a - # given FileWriter. - # -class TargetDirectory - def self.finder - TargetDirectory::Finder.new - end - def initialize(directory, writer) - @directory = Pathname.new(directory) - @writer = writer # FileWriter - end - # Copies the given relative path from the current directory to the target. - def copy(path) - source_path = Pathname.new(path) - target_path = @directory + path - @writer.copy(source_path, target_path) - end - def [](path) - @directory + path - end - def path - @directory - end -end # class TargetDirectory - - - # - # Represents the target directory. Can find candidates, based on the operating system and - # user options; but is ultimately created with one in mind. - # -class TargetDirectory::Finder - - # Guides the user through a selection process, ending in a chosen directory. - def find_target_directory - # 1. Was a directory specified using the --directory option? - if option_dir = $options[:target_dir] - return option_dir - end - # 2. Try the potentials (if there are any). - if dirs = _potential_directories and not dirs.empty? - puts - puts "Possible Vim installation directories:" - dirs.each_with_index do |dir, idx| - puts " #{idx+1}) #{dir}" - end - puts - r = Env.ask_user "Please select one (or anything else to specify another directory): " - if (1..dirs.size).include? r.to_i - chosen_directory = dirs[r.to_i - 1] - return chosen_directory - end - end - # 3. We didn't find any, or the user wants to enter another. - if dirs.empty? - puts - puts "Couldn't find any Vim installation directories." - end - entered_directory = Env.ask_user "Please enter the full path to your Vim installation directory: " - entered_directory = File.expand_path(entered_directory) - return entered_directory - end - - private - - # Return an array of _potential_ directories (i.e. they exist). Take the options into - # account. - def _potential_directories - dirs = [] - dirs << _vim_user_dir - dirs << _vim_system_dir - return dirs.compact.map { |dir| File.expand_path(dir) } - end - - # Return the Vim system preferences directory - def _vim_system_dir - vim_dir = Env.determine_vim_dir - system_dir = vim_dir + "/vimfiles" if vim_dir - return system_dir - end - - # Return the Vim user preferences directory - def _vim_user_dir - platform_dir = { :UNIX => "/.vim", :WINDOWS => "/vimfiles" } - home_dir = Env.determine_home_dir - user_dir = home_dir + platform_dir[Env.determine_target_os] if home_dir - return user_dir - end - -end # class TargetDirectory::Finder - - - # - # VimRubyInstaller is the class that copies the files from the source directory to the target - # directory, both of which are provided. - # -class VimRubyInstaller - - # +source+ and +target+ are the base directories from and to which the configuration files - # will be copied. Both are strings. - def initialize(source, target) - unless FileTest.directory?(source) - raise "Automatically determined source directory ('#{source}') doesn't exist" - end - unless FileTest.directory?(target) - raise "Chosen target directory ('#{target}') doesn't exist" - end - @source_dir = source - file_writer = FileWriter.new(Env.determine_target_os) - @target_dir = TargetDirectory.new(target, file_writer) - end - - # Since we know the source and target directories, all we have to do is copy the files - # across. If the --backup option was specified or the target file is - # _newer_ than the source file, we make a backup of it and report that to - # the user. - def install - backupdir = BackupDir.new("./vim-ruby-backup.#{Process.pid}") - Dir.chdir(@source_dir) do - SOURCE_FILES.each do |path| - source_path = Pathname.new(path) - target_path = @target_dir[path] - # FIXME: Backup everything for now - if $options[:backup] and target_path.file? - backupdir.backup(@target_dir, path) - elsif target_path.file? and target_path.mtime > source_path.mtime - # We're going to overwrite a newer file; back it up, unless they're the same. - unless _same_contents?(target_path, source_path) - backupdir.backup(@target_dir, path) - end - end - @target_dir.copy(path) - end - end - backups = backupdir.contents - unless backups.empty? - puts - puts "The following backups were made:" - backups.each do |path| - puts " * #{path}" - end - puts - puts "These backups are located in this directory: #{backupdir.path}" - end - end - - private - - # Test two files for equality of contents, ignoring line endings. - def _same_contents?(p1, p2) - contents1 = p1.read.split("\n").map { |line| line.chomp } - contents2 = p2.read.split("\n").map { |line| line.chomp } - contents1 == contents2 - end - - # A directory for holding backups of configuration files. - class BackupDir - def initialize(path) - @base = Pathname.new(path).expand_path - end - # Copy basedir/path to @path/path. - def backup(basedir, path) - @base.mkpath unless @base.directory? - source = basedir.path + path - target = @base + path - target.dirname.mkpath - FileUtils.cp(source.to_s, target.dirname.to_s, :verbose => true) - end - def [](path) - @base + path - end - def contents - return [] unless @base.directory? - results = [] - Dir.chdir(@base) do - Pathname.new('.').find do |path| - results << path if path.file? - end - end - results - end - def path - @base - end - end # class VimRubyInstaller::BackupDir - -end # class VimRubyInstaller - - # - # * * * M A I N * * * - # - -begin - - $options = { - :backup => false, - :target_dir => nil, - :windows => false - } - - op = OptionParser.new do |p| - p.banner = %{ - vim-ruby-install.rb: Install the vim-ruby configuration files - - About: - * Detects the Vim user and system-wide preferences directories - * User to confirm before proceeding - * User may specify other directory - * Takes config files from current directory or from vim-ruby gem - * Writes files with correct permissions and line endings - - Usage: - direct: ruby bin/vim-ruby-install.rb [options] - gem: vim-ruby-install.rb [options] - - Options: - }.gsub(/^ /, '') - p.on('-b', '--backup', 'Backup existing runtime files') do |value| - $options[:backup] = value - end - p.on('-d DIR', '--directory', 'Install into given directory') do |dir| - $options[:target_dir] = dir - end - p.on('-w', '--windows', 'Install into Windows directories') do |value| - $options[:windows] = value - end - p.on('-h', '--help', 'Show this message') do - puts p - exit - end - p.on_tail %{ - Notes: - - * "Direct" usage means unpacking a vim-ruby tarball and running this - program from the vim-ruby directory. - - * The convenient alternative is to use RubyGems: - gem install vim-ruby - vim-ruby-install.rb - - * The --windows option is designed for forcing an install into the - Windows (gvim) configuration directory; useful when running from - Cygwin or MinGW. - - * This installer is quite new (2004-09-20). Please report bugs to - gsinclair@soyabean.com.au. - }.gsub(/^ /, '') - end - op.parse!(ARGV) - - if not ARGV.empty? - raise "invalid argument: #{ARGV[0]}" - end - - source_dir = Env.determine_source_directory - if source_dir.nil? - raise "Can't find source directory." - end - - target_dir = TargetDirectory.finder.find_target_directory - if not File.directory?(target_dir) - puts - puts "Target directory '#{target_dir}' does not exist." - response = Env.ask_user "Do you want to create it? [Yn] " - response = "y" if response.empty? - if response.strip =~ /^y(es)?$/i - FileUtils.mkdir_p(target_dir, :verbose => true) - else - puts - puts "Installation aborted." - exit - end - end - - VimRubyInstaller.new(source_dir, target_dir).install - -rescue - - raise if $DEBUG - $stderr.puts - $stderr.puts $!.message - $stderr.puts "Try 'ruby #{$0} --help' for detailed usage." - exit 1 - -end - -# vim: nowrap sw=2 sts=2 ts=8 ff=unix ft=ruby: diff --git a/compiler/eruby.vim b/compiler/eruby.vim index e54802ca..64fa2c1d 100644 --- a/compiler/eruby.vim +++ b/compiler/eruby.vim @@ -2,8 +2,6 @@ " Language: eRuby " Maintainer: Doug Kearns " URL: https://github.com/vim-ruby/vim-ruby -" Anon CVS: See above site -" Release Coordinator: Doug Kearns if exists("current_compiler") finish @@ -29,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 new file mode 100644 index 00000000..8dc468aa --- /dev/null +++ b/compiler/rake.vim @@ -0,0 +1,38 @@ +" Vim compiler file +" Language: Rake +" Maintainer: Tim Pope +" URL: https://github.com/vim-ruby/vim-ruby + +if exists("current_compiler") + finish +endif +let current_compiler = "rake" + +if exists(":CompilerSet") != 2 " older Vim always used :setlocal + command -nargs=* CompilerSet setlocal +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: diff --git a/compiler/rspec.vim b/compiler/rspec.vim index 8e5c7a89..a9b25c83 100644 --- a/compiler/rspec.vim +++ b/compiler/rspec.vim @@ -2,8 +2,6 @@ " Language: RSpec " Maintainer: Tim Pope " URL: https://github.com/vim-ruby/vim-ruby -" Anon CVS: See above site -" Release Coordinator: Doug Kearns if exists("current_compiler") finish @@ -23,9 +21,11 @@ CompilerSet errorformat= \%f:%l:\ %tarning:\ %m, \%E%.%#:in\ `load':\ %f:%l:%m, \%E%f:%l:in\ `%*[^']':\ %m, - \%-Z\ \ \ \ \ \#\ %f:%l:%.%#, - \%E\ \ %\\d%\\+)%.%#, + \%-Z\ \ \ \ \ %\\+\#\ %f:%l:%.%#, + \%E\ \ \ \ \ Failure/Error:\ %m, + \%E\ \ \ \ \ Failure/Error:, \%C\ \ \ \ \ %m, + \%C%\\s%#, \%-G%.%# let &cpo = s:cpo_save diff --git a/compiler/ruby.vim b/compiler/ruby.vim index e84088d2..55c53640 100644 --- a/compiler/ruby.vim +++ b/compiler/ruby.vim @@ -3,9 +3,6 @@ " Function: Syntax check and/or error reporting " Maintainer: Tim Pope " URL: https://github.com/vim-ruby/vim-ruby -" Anon CVS: See above site -" Release Coordinator: Doug Kearns -" ---------------------------------------------------------------------------- if exists("current_compiler") finish @@ -22,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 17b77dc7..6d785056 100644 --- a/compiler/rubyunit.vim +++ b/compiler/rubyunit.vim @@ -2,8 +2,6 @@ " Language: Test::Unit - Ruby Unit Testing Framework " Maintainer: Doug Kearns " URL: https://github.com/vim-ruby/vim-ruby -" Anon CVS: See above site -" Release Coordinator: Doug Kearns if exists("current_compiler") finish @@ -18,6 +16,8 @@ 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]:, 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 36db8313..2abe97fd 100644 --- a/doc/ft-ruby-omni.txt +++ b/doc/ft-ruby-omni.txt @@ -1,9 +1,10 @@ -RUBY *ft-ruby-omni* +RUBY *ft-ruby-omni* + *vim-ruby-omni* -Completion of Ruby code requires that vim be built with |+ruby|. +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' +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: @@ -17,24 +18,35 @@ The completions provided by CTRL-X CTRL-O are sensitive to the context: 3. After '.', '::' or ':' Methods applicable to the object being dereferenced - 4. After ':' or ':foo' Symbol name (beginning with 'foo') + 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 + 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, + 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 +< 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: 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 ba21ac35..2979f20c 100644 --- a/doc/ft-ruby-syntax.txt +++ b/doc/ft-ruby-syntax.txt @@ -1,6 +1,91 @@ RUBY *ruby.vim* *ft-ruby-syntax* + *vim-ruby-syntax* -There are a number of options to the Ruby syntax highlighting. + 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 @@ -11,6 +96,8 @@ you may want to turn it off by defining the "ruby_no_expensive" variable: > < 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: > @@ -20,19 +107,13 @@ the "ruby_minlines" variable to a value larger than 50: > Ideally, this value should be a number of lines large enough to embrace your largest class or module. -Ruby operators can be highlighted. This is enabled by defining -"ruby_operators": > + *ruby_spellcheck_strings* + Ruby: Spellchecking strings ~ - :let ruby_operators = 1 -< -Whitespace errors can be highlighted by defining "ruby_space_errors": > +Ruby syntax will perform spellchecking of strings if you define +"ruby_spellcheck_strings": > - :let ruby_space_errors = 1 + :let ruby_spellcheck_strings = 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. - vim:tw=78:sw=4:ts=8:ft=help:norl: diff --git a/etc/examples/generators/syntax.rb b/etc/examples/generators/syntax.rb new file mode 100755 index 00000000..06cf1600 --- /dev/null +++ b/etc/examples/generators/syntax.rb @@ -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 <