From 735b9181d878f0944eeaef20613570023fe7ec20 Mon Sep 17 00:00:00 2001 From: Andrew Radev Date: Sat, 26 May 2012 16:43:21 +0300 Subject: [PATCH 001/451] Remove unneeded unmaps from b:undo_ftplugin The "im" and "am" mappings are present a bit later in the file and the "ic" and "ac" mappings are not relevant anymore. --- ftplugin/ruby.vim | 1 - 1 file changed, 1 deletion(-) diff --git a/ftplugin/ruby.vim b/ftplugin/ruby.vim index bc8370a2..a8233dd5 100644 --- a/ftplugin/ruby.vim +++ b/ftplugin/ruby.vim @@ -130,7 +130,6 @@ if !exists("g:no_plugin_maps") && !exists("g:no_ruby_maps") let b:undo_ftplugin = b:undo_ftplugin \."| sil! exe 'unmap [[' | sil! exe 'unmap ]]' | sil! exe 'unmap []' | sil! exe 'unmap ]['" \."| sil! exe 'unmap [m' | sil! exe 'unmap ]m' | sil! exe 'unmap [M' | sil! exe 'unmap ]M'" - \."| sil! exe 'ounmap im'| sil! exe 'ounmap am'| sil! exe 'ounmap ic'| sil! exe 'ounmap ac'" if maparg('im','n') == '' onoremap im :call wrap_i('[m',']M') From a1c024edf290d3e5af36f7c776df57d78fa39ff6 Mon Sep 17 00:00:00 2001 From: Andrew Radev Date: Tue, 29 May 2012 19:48:10 +0300 Subject: [PATCH 002/451] Initial handling for closing brackets on the same line as code --- etc/examples/indent/closing_brackets.rb | 17 +++++++++++++++++ etc/examples/indent/continuations.rb | 4 ++++ indent/ruby.vim | 9 +++++++++ 3 files changed, 30 insertions(+) create mode 100644 etc/examples/indent/closing_brackets.rb diff --git a/etc/examples/indent/closing_brackets.rb b/etc/examples/indent/closing_brackets.rb new file mode 100644 index 00000000..08d141a1 --- /dev/null +++ b/etc/examples/indent/closing_brackets.rb @@ -0,0 +1,17 @@ +[1, [2, + [3], + 3], +4] + +[1, [2, + 3], +4] + +[1, {2 => + 3}, +4] + + +[1, f(2, + 3), +4] diff --git a/etc/examples/indent/continuations.rb b/etc/examples/indent/continuations.rb index 91eb414b..31076872 100644 --- a/etc/examples/indent/continuations.rb +++ b/etc/examples/indent/continuations.rb @@ -23,3 +23,7 @@ else other end + +x { y >> + z } +w diff --git a/indent/ruby.vim b/indent/ruby.vim index ddc114dc..b22ef882 100644 --- a/indent/ruby.vim +++ b/indent/ruby.vim @@ -401,6 +401,15 @@ function GetRubyIndent(...) return ind endif + " Look for an unbalanced closing bracket on the same line as code: + let col = s:Match(lnum, '\S\s*\zs[\]})]') + if col > 0 + " find the matching opening bracket + call cursor(lnum, col) + normal! % + return indent('.') + endif + " 3.4. Work on the MSL line. {{{2 " -------------------------- From f94575d0cd4fe09e61664ea30b47352b585f07af Mon Sep 17 00:00:00 2001 From: Drew Neil Date: Sat, 2 Jun 2012 14:20:04 +0200 Subject: [PATCH 003/451] Add documentation for ruby motions/text objects. --- doc/vim-ruby.txt | 61 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 doc/vim-ruby.txt diff --git a/doc/vim-ruby.txt b/doc/vim-ruby.txt new file mode 100644 index 00000000..dba015e1 --- /dev/null +++ b/doc/vim-ruby.txt @@ -0,0 +1,61 @@ +*vim-ruby.txt* + +1. Ruby motions |ruby-motion| +2. Ruby text objects |ruby-text-objects| + +============================================================================== +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. + + vim:tw=78:sw=4:ts=8:ft=help:norl: From 80025647c36f6d7d7d0e8281cc362aa8d2d318f2 Mon Sep 17 00:00:00 2001 From: Drew Neil Date: Sat, 2 Jun 2012 14:28:24 +0200 Subject: [PATCH 004/451] Enable im, am, iM, and aM in visual mode. --- ftplugin/ruby.vim | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ftplugin/ruby.vim b/ftplugin/ruby.vim index a8233dd5..735025b0 100644 --- a/ftplugin/ruby.vim +++ b/ftplugin/ruby.vim @@ -134,15 +134,21 @@ if !exists("g:no_plugin_maps") && !exists("g:no_ruby_maps") if maparg('im','n') == '' onoremap im :call wrap_i('[m',']M') onoremap am :call wrap_a('[m',']M') + xnoremap im :call wrap_i('[m',']M') + xnoremap am :call wrap_a('[m',']M') let b:undo_ftplugin = b:undo_ftplugin \."| sil! exe 'ounmap im' | sil! exe 'ounmap am'" + \."| sil! exe 'xunmap im' | sil! exe 'xunmap am'" endif if maparg('iM','n') == '' onoremap iM :call wrap_i('[[','][') onoremap aM :call wrap_a('[[','][') + xnoremap iM :call wrap_i('[[','][') + xnoremap aM :call wrap_a('[[','][') let b:undo_ftplugin = b:undo_ftplugin \."| sil! exe 'ounmap iM' | sil! exe 'ounmap aM'" + \."| sil! exe 'xunmap iM' | sil! exe 'xunmap aM'" endif if maparg("\",'n') == '' From e7e6b4e8d92938b461f20cb94bdca7f79aed2447 Mon Sep 17 00:00:00 2001 From: Andrew Radev Date: Sat, 2 Jun 2012 18:55:10 +0300 Subject: [PATCH 005/451] Indent functions with 2 spaces To maintain consistency with the rest of the project. --- ftplugin/ruby.vim | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/ftplugin/ruby.vim b/ftplugin/ruby.vim index 735025b0..6678731d 100644 --- a/ftplugin/ruby.vim +++ b/ftplugin/ruby.vim @@ -238,29 +238,29 @@ function! RubyBalloonexpr() endfunction function! s:searchsyn(pattern,syn,flags,mode) - norm! m' - if a:mode ==# 'v' - norm! gv - endif - let i = 0 - let cnt = v:count ? v:count : 1 - while i < cnt - let i = i + 1 - let line = line('.') - let col = col('.') - let pos = search(a:pattern,'W'.a:flags) - while pos != 0 && s:synname() !~# a:syn - let pos = search(a:pattern,'W'.a:flags) - endwhile - if pos == 0 - call cursor(line,col) - return - endif + norm! m' + if a:mode ==# 'v' + norm! gv + endif + let i = 0 + let cnt = v:count ? v:count : 1 + while i < cnt + let i = i + 1 + let line = line('.') + let col = col('.') + let pos = search(a:pattern,'W'.a:flags) + while pos != 0 && s:synname() !~# a:syn + let pos = search(a:pattern,'W'.a:flags) endwhile + if pos == 0 + call cursor(line,col) + return + endif + endwhile endfunction function! s:synname() - return synIDattr(synID(line('.'),col('.'),0),'name') + return synIDattr(synID(line('.'),col('.'),0),'name') endfunction function! s:wrap_i(back,forward) From 34a086257a2430a14526daf25b50cc7a2b6894e9 Mon Sep 17 00:00:00 2001 From: Doug Kearns Date: Thu, 14 Jun 2012 20:55:01 +1000 Subject: [PATCH 006/451] Fix omnifunc's requirement test error messages. Quick fix that could probably be better organised. --- autoload/rubycomplete.vim | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/autoload/rubycomplete.vim b/autoload/rubycomplete.vim index 1ecaea92..eb0ca8d2 100644 --- a/autoload/rubycomplete.vim +++ b/autoload/rubycomplete.vim @@ -11,16 +11,23 @@ " ---------------------------------------------------------------------------- " {{{ 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 @@ -50,12 +57,6 @@ endif " {{{ 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 From a9073e55084c391f6322b3bcde9d1a5bd561627e Mon Sep 17 00:00:00 2001 From: Andrew Radev Date: Wed, 18 Jul 2012 21:05:32 +0300 Subject: [PATCH 007/451] Restrict "do" blocks a bit This solves the problem of a "do" being detected where it's part of a method call or a symbol. See: https://github.com/vim-ruby/vim-ruby/issues/92 --- etc/examples/indent/blocks.rb | 12 ++++++++++++ indent/ruby.vim | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/etc/examples/indent/blocks.rb b/etc/examples/indent/blocks.rb index 34408f92..35562b93 100644 --- a/etc/examples/indent/blocks.rb +++ b/etc/examples/indent/blocks.rb @@ -1,3 +1,15 @@ +do + something +end + +def foo + a_hash = {:do => 'bar'} +end + +def foo(job) + job.do! +end + proc do |(a, b)| puts a puts b diff --git a/indent/ruby.vim b/indent/ruby.vim index ddc114dc..67b44a81 100644 --- a/indent/ruby.vim +++ b/indent/ruby.vim @@ -66,7 +66,7 @@ let s:ruby_deindent_keywords = let s:end_start_regex = \ '\C\%(^\s*\|[=,*/%+\-|;{]\|<<\|>>\|:\s\)\s*\zs' . \ '\<\%(module\|class\|def\|if\|for\|while\|until\|case\|unless\|begin\):\@!\>' . - \ '\|\' + \ '\|\%(^\|[^.:@$]\)\@<=\' " Regex that defines the middle-match for the 'end' keyword. let s:end_middle_regex = '\<\%(ensure\|else\|\%(\%(^\|;\)\s*\)\@<=\\|when\|elsif\):\@!\>' From 5990bf15628bcb6ef54a53f370dc68093876be8d Mon Sep 17 00:00:00 2001 From: Andrew Radev Date: Wed, 8 Aug 2012 13:31:30 +0300 Subject: [PATCH 008/451] Minor whitespace tweak --- indent/ruby.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indent/ruby.vim b/indent/ruby.vim index 67b44a81..387899c2 100644 --- a/indent/ruby.vim +++ b/indent/ruby.vim @@ -411,7 +411,7 @@ function GetRubyIndent(...) " If the previous line wasn't a MSL and is continuation return its indent. " TODO: the || s:IsInString() thing worries me a bit. if p_lnum != lnum - if s:Match(p_lnum,s:non_bracket_continuation_regex)||s:IsInString(p_lnum,strlen(line)) + if s:Match(p_lnum, s:non_bracket_continuation_regex) || s:IsInString(p_lnum,strlen(line)) return ind endif endif From 15ae2d70f30196d08c33eb40639ff52ccc469406 Mon Sep 17 00:00:00 2001 From: Andrew Radev Date: Wed, 8 Aug 2012 13:31:44 +0300 Subject: [PATCH 009/451] Handling for multiline splats --- etc/examples/indent/splat.rb | 30 ++++++++++++++++++++++++++++++ indent/ruby.vim | 20 +++++++++++++++++++- 2 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 etc/examples/indent/splat.rb diff --git a/etc/examples/indent/splat.rb b/etc/examples/indent/splat.rb new file mode 100644 index 00000000..8fdb3371 --- /dev/null +++ b/etc/examples/indent/splat.rb @@ -0,0 +1,30 @@ +x = Foo[* + y do + z + end +] + +x = Foo[* # with a comment + y do + z + end +] + +x = * + array.map do + 3 +end + +x = Foo[* + y { + z + } +] + +x = Foo(*y do + z +end) + +foo(1, + 2, + *) diff --git a/indent/ruby.vim b/indent/ruby.vim index 387899c2..f8549da7 100644 --- a/indent/ruby.vim +++ b/indent/ruby.vim @@ -90,6 +90,9 @@ let s:continuation_regex = " Regex that defines bracket continuations let s:bracket_continuation_regex = '%\@ Date: Thu, 9 Aug 2012 00:26:27 +1000 Subject: [PATCH 010/451] Fix some text erroneously marked up as option names in Omni docs. --- doc/ft-ruby-omni.txt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/doc/ft-ruby-omni.txt b/doc/ft-ruby-omni.txt index 36db8313..79fa3da1 100644 --- a/doc/ft-ruby-omni.txt +++ b/doc/ft-ruby-omni.txt @@ -1,9 +1,9 @@ RUBY *ft-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,14 +17,14 @@ 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 +<- 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 From a373648416c0615da366cae37f575aedf8a3e674 Mon Sep 17 00:00:00 2001 From: todesking Date: Fri, 10 Aug 2012 22:02:54 +0900 Subject: [PATCH 011/451] Fix completion error to reproduce: x.f{$ # Invoke omni completion here --- autoload/rubycomplete.vim | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/autoload/rubycomplete.vim b/autoload/rubycomplete.vim index eb0ca8d2..e5c94704 100644 --- a/autoload/rubycomplete.vim +++ b/autoload/rubycomplete.vim @@ -364,6 +364,10 @@ class VimRubyCompletion print txt if @@debug end + def escape_vim_singlequote_string(str) + str.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") @@ -526,9 +530,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 @@ -779,7 +783,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) From 65d246eb604408f7b0a7193600783a0e1b041446 Mon Sep 17 00:00:00 2001 From: joker1007 Date: Tue, 14 Aug 2012 23:06:49 +0900 Subject: [PATCH 012/451] Fix escape_vim_singlequote_string str argument is Symbol Object from Object.instance_methods etc, and Symbol is undefined `#gsub`. --- autoload/rubycomplete.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/autoload/rubycomplete.vim b/autoload/rubycomplete.vim index e5c94704..0294e691 100644 --- a/autoload/rubycomplete.vim +++ b/autoload/rubycomplete.vim @@ -365,7 +365,7 @@ class VimRubyCompletion end def escape_vim_singlequote_string(str) - str.gsub(/'/,"\\'") + str.to_s.gsub(/'/,"\\'") end def get_buffer_entity_list( type ) From b10adca138b41a6ab51c4347fdf20acb88e2423e Mon Sep 17 00:00:00 2001 From: Tim Pope Date: Fri, 17 Aug 2012 21:39:58 -0400 Subject: [PATCH 013/451] Highlight <%-# comments -%> Closes #102. --- syntax/eruby.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/syntax/eruby.vim b/syntax/eruby.vim index 71930ab4..a3dd2729 100644 --- a/syntax/eruby.vim +++ b/syntax/eruby.vim @@ -59,7 +59,7 @@ syn cluster erubyRegions contains=erubyOneLiner,erubyBlock,erubyExpression,eruby exe 'syn region erubyOneLiner matchgroup=erubyDelimiter start="^%\{1,'.b:eruby_nest_level.'\}%\@!" end="$" contains=@rubyTop containedin=ALLBUT,@erubyRegions keepend oneline' exe 'syn region erubyBlock matchgroup=erubyDelimiter start="<%\{1,'.b:eruby_nest_level.'\}%\@!-\=" end="[=-]\=%\@" contains=@rubyTop containedin=ALLBUT,@erubyRegions keepend' exe 'syn region erubyExpression matchgroup=erubyDelimiter start="<%\{1,'.b:eruby_nest_level.'\}=\{1,4}" end="[=-]\=%\@" contains=@rubyTop containedin=ALLBUT,@erubyRegions keepend' -exe 'syn region erubyComment matchgroup=erubyDelimiter start="<%\{1,'.b:eruby_nest_level.'\}#" end="%\@" contains=rubyTodo,@Spell containedin=ALLBUT,@erubyRegions keepend' +exe 'syn region erubyComment matchgroup=erubyDelimiter start="<%\{1,'.b:eruby_nest_level.'\}-\=#" end="[=-]\=%\@" contains=rubyTodo,@Spell containedin=ALLBUT,@erubyRegions keepend' " Define the default highlighting. From 4a90d71c6611e46d05eb110bea8edde983331929 Mon Sep 17 00:00:00 2001 From: Andrew Radev Date: Wed, 26 Sep 2012 20:31:23 +0300 Subject: [PATCH 014/451] Fix an issue with block continuations In the new example, the "].each" registers as a block, so the continuation logic goes upwards and takes the ":one," line into account. As a solution, a (hopefully) better block_continuation_regex is created specifically for continuations -- a block opener starting with "]", "}", or ")" can't be a continuation. --- etc/examples/indent/continuations.rb | 6 ++++++ indent/ruby.vim | 15 +++++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/etc/examples/indent/continuations.rb b/etc/examples/indent/continuations.rb index 91eb414b..fff822d6 100644 --- a/etc/examples/indent/continuations.rb +++ b/etc/examples/indent/continuations.rb @@ -23,3 +23,9 @@ else other end + +array = [ + :one, +].each do |x| + puts x.to_s +end diff --git a/indent/ruby.vim b/indent/ruby.vim index f8549da7..525128f1 100644 --- a/indent/ruby.vim +++ b/indent/ruby.vim @@ -105,6 +105,8 @@ let s:splat_regex = '[[,(]\s*\*\s*\%(#.*\)\=$' let s:block_regex = \ '\%(\\|%\@ Date: Thu, 27 Sep 2012 20:35:01 +0300 Subject: [PATCH 015/451] Oops. Fix s:block_continuation_regex Forgot the leading whitespace there. --- indent/ruby.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indent/ruby.vim b/indent/ruby.vim index 525128f1..05c1e852 100644 --- a/indent/ruby.vim +++ b/indent/ruby.vim @@ -105,7 +105,7 @@ let s:splat_regex = '[[,(]\s*\*\s*\%(#.*\)\=$' let s:block_regex = \ '\%(\\|%\@ Date: Sun, 14 Oct 2012 18:45:49 +0300 Subject: [PATCH 016/451] Fixes to closing bracket handler Only match closing brackets that are at the end of a line, and get the right bracket position. This still doesn't handle the actual line where the brackets are closed, just the following one. --- etc/examples/indent/closing_brackets.rb | 8 ++++---- indent/ruby.vim | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/etc/examples/indent/closing_brackets.rb b/etc/examples/indent/closing_brackets.rb index 0397c914..46c4afd6 100644 --- a/etc/examples/indent/closing_brackets.rb +++ b/etc/examples/indent/closing_brackets.rb @@ -1,16 +1,16 @@ [1, [2, [3], 3], -4] + 4] [1, [2, 3], -4] + 4] [1, {2 => 3}, -4] + 4] [1, f(2, 3), -4] + 4] diff --git a/indent/ruby.vim b/indent/ruby.vim index 28f0f192..e9953252 100644 --- a/indent/ruby.vim +++ b/indent/ruby.vim @@ -413,7 +413,7 @@ function GetRubyIndent(...) " " If it contained hanging closing brackets, find the rightmost one, find its " match and indent according to that. - if line =~ '[][(){}]' + if line =~ '[[({]' || line =~ '[])}]\s*\%(#.*\)\=$' let [opening, closing] = s:ExtraBrackets(lnum) if opening.pos != -1 @@ -428,7 +428,7 @@ function GetRubyIndent(...) return nonspace > 0 ? nonspace : ind + &sw endif elseif closing.pos != -1 - call cursor(lnum, closing.pos) + call cursor(lnum, closing.pos + 1) normal! % return indent('.') else From 0c4190c1c88e25fcd2994709da8c27f22dd697ec Mon Sep 17 00:00:00 2001 From: Andrew Radev Date: Tue, 13 Nov 2012 11:45:07 +0100 Subject: [PATCH 017/451] Fix bug with interpolation in %|| strings --- etc/examples/indent/strings.rb | 2 ++ indent/ruby.vim | 7 +++++-- 2 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 etc/examples/indent/strings.rb diff --git a/etc/examples/indent/strings.rb b/etc/examples/indent/strings.rb new file mode 100644 index 00000000..d69f806a --- /dev/null +++ b/etc/examples/indent/strings.rb @@ -0,0 +1,2 @@ +command = %|#{file}| +settings.log.info("Returning: #{command}") diff --git a/indent/ruby.vim b/indent/ruby.vim index e9953252..8bbbbbb0 100644 --- a/indent/ruby.vim +++ b/indent/ruby.vim @@ -34,7 +34,7 @@ set cpo&vim " Regex of syntax group names that are or delimit string or are comments. let s:syng_strcom = '\' " Regex of syntax group names that are strings. @@ -498,12 +498,15 @@ function GetRubyIndent(...) " If the previous line ended with [*+/.,-=], but wasn't a block ending, " indent one extra level. - if s:Match(lnum, s:non_bracket_continuation_regex) && !s:Match(lnum, '^\s*\(}\|end\)') + if s:Match(lnum, s:non_bracket_continuation_regex) + \ && !s:Match(lnum, '^\s*\(}\|end\)') + \ && !s:IsInStringOrComment(lnum, len(line)) if lnum == p_lnum let ind = msl_ind + &sw else let ind = msl_ind endif + return ind endif " }}}2 From 0eec443be24b543007b1d3055d4252565b2b6b7a Mon Sep 17 00:00:00 2001 From: Andrew Radev Date: Tue, 13 Nov 2012 19:35:38 +0100 Subject: [PATCH 018/451] Fix omnicompletion issue with sorting symbols --- autoload/rubycomplete.vim | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/autoload/rubycomplete.vim b/autoload/rubycomplete.vim index 0294e691..66e88450 100644 --- a/autoload/rubycomplete.vim +++ b/autoload/rubycomplete.vim @@ -771,10 +771,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 = "" From d2982c7ca196b8e33d989e8dfbcea575e843ecb4 Mon Sep 17 00:00:00 2001 From: Andrew Radev Date: Tue, 13 Nov 2012 21:46:51 +0100 Subject: [PATCH 019/451] Remove "keepend" from regex syntax highlighting This fixes an issue with highlighting a regex with interpolation in it with a regex within. /#{foo.sub(/bar/, 'baz')}/ See https://github.com/vim-ruby/vim-ruby/issues/63 for details --- syntax/ruby.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/syntax/ruby.vim b/syntax/ruby.vim index a049901d..87e0aca3 100644 --- a/syntax/ruby.vim +++ b/syntax/ruby.vim @@ -124,7 +124,7 @@ syn match rubyPredefinedConstant "\%(\%(\.\@\%(\s*(\)\@!" " Normal Regular Expression -syn region rubyRegexp matchgroup=rubyRegexpDelimiter start="\%(\%(^\|\<\%(and\|or\|while\|until\|unless\|if\|elsif\|when\|not\|then\|else\)\|[;\~=!|&(,[>?:]\)\s*\)\@<=/" end="/[iomxneus]*" skip="\\\\\|\\/" contains=@rubyRegexpSpecial keepend fold +syn region rubyRegexp matchgroup=rubyRegexpDelimiter start="\%(\%(^\|\<\%(and\|or\|while\|until\|unless\|if\|elsif\|when\|not\|then\|else\)\|[;\~=!|&(,[>?:]\)\s*\)\@<=/" end="/[iomxneus]*" skip="\\\\\|\\/" contains=@rubyRegexpSpecial fold syn region rubyRegexp matchgroup=rubyRegexpDelimiter start="\%(\h\k*\s\+\)\@<=/[ \t=]\@!" end="/[iomxneus]*" skip="\\\\\|\\/" contains=@rubyRegexpSpecial fold " Generalized Regular Expression From 79dd611eac34267b6aca669f62d6e4e7f9d74fb3 Mon Sep 17 00:00:00 2001 From: Doug Ireton Date: Mon, 19 Nov 2012 21:51:02 -0800 Subject: [PATCH 020/451] Add Cheffile and Berksfile to ftdetect Berkshelf (Berksfile), and Librarian-Chef (Cheffile) are Opscode Chef cookbook dependency resolvers written in Ruby. --- ftdetect/ruby.vim | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ftdetect/ruby.vim b/ftdetect/ruby.vim index d2c39cf3..44326a76 100644 --- a/ftdetect/ruby.vim +++ b/ftdetect/ruby.vim @@ -28,6 +28,10 @@ au BufNewFile,BufRead Gemfile set filetype=ruby " Guard au BufNewFile,BufRead Guardfile,.Guardfile set filetype=ruby +" Chef +au BufNewFile,BufRead Cheffile set filetype=ruby +au BufNewFile,BufRead Berksfile set filetype=ruby + " Vagrant au BufNewFile,BufRead [vV]agrantfile set filetype=ruby From c61accbf503fc3735ad4a8ab8d8121b109c08ac6 Mon Sep 17 00:00:00 2001 From: Andrew Radev Date: Sun, 25 Nov 2012 10:18:16 +0100 Subject: [PATCH 021/451] Matchgroup for curly braces --- syntax/ruby.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/syntax/ruby.vim b/syntax/ruby.vim index 87e0aca3..420f992d 100644 --- a/syntax/ruby.vim +++ b/syntax/ruby.vim @@ -222,8 +222,8 @@ if !exists("b:ruby_no_expensive") && !exists("ruby_no_expensive") syn region rubyDoBlock matchgroup=rubyControl start="\" end="\" contains=ALLBUT,@rubyNotTop fold " curly bracket block or hash literal - syn region rubyCurlyBlock start="{" end="}" contains=ALLBUT,@rubyNotTop fold - syn region rubyArrayLiteral matchgroup=rubyArrayDelimiter start="\%(\w\|[\]})]\)\@" end="\" contains=ALLBUT,@rubyNotTop fold From bda28584f7a483f41f81a8ac94fbafdce30cee88 Mon Sep 17 00:00:00 2001 From: Fabio Pelosin Date: Wed, 28 Nov 2012 19:24:00 +0100 Subject: [PATCH 022/451] Added support for YARD todos. --- syntax/ruby.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/syntax/ruby.vim b/syntax/ruby.vim index 420f992d..8450438b 100644 --- a/syntax/ruby.vim +++ b/syntax/ruby.vim @@ -270,7 +270,7 @@ endif " Comments and Documentation syn match rubySharpBang "\%^#!.*" display -syn keyword rubyTodo FIXME NOTE TODO OPTIMIZE XXX contained +syn keyword rubyTodo FIXME NOTE TODO OPTIMIZE XXX todo contained syn match rubyComment "#.*" contains=rubySharpBang,rubySpaceError,rubyTodo,@Spell if !exists("ruby_no_comment_fold") syn region rubyMultilineComment start="\%(\%(^\s*#.*\n\)\@ Date: Fri, 30 Nov 2012 14:14:16 +0100 Subject: [PATCH 023/451] Add documentation for ruby_fold Added documentation for how to use the ruby_fold variable to enable folding if foldmethod is set to anything other than "syntax". --- doc/ft-ruby-syntax.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/doc/ft-ruby-syntax.txt b/doc/ft-ruby-syntax.txt index ba21ac35..6aafc996 100644 --- a/doc/ft-ruby-syntax.txt +++ b/doc/ft-ruby-syntax.txt @@ -34,5 +34,9 @@ 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. + :let ruby_fold = 1 +< +This will set the value |foldmethod| to "syntax" locally to the current buffer +or window, which will enable syntax-based folding when editing Ruby filetypes. vim:tw=78:sw=4:ts=8:ft=help:norl: From 8637525b6117270dd8d55b9e4e9ca97ea8ac3c7e Mon Sep 17 00:00:00 2001 From: Rolf Bjaanes Date: Fri, 30 Nov 2012 19:34:43 +0100 Subject: [PATCH 024/451] Add missing ">" --- doc/ft-ruby-syntax.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/ft-ruby-syntax.txt b/doc/ft-ruby-syntax.txt index 6aafc996..7bc2c064 100644 --- a/doc/ft-ruby-syntax.txt +++ b/doc/ft-ruby-syntax.txt @@ -38,5 +38,6 @@ spaces respectively. < This will set the value |foldmethod| to "syntax" locally to the current buffer or window, which will enable syntax-based folding when editing Ruby filetypes. +> vim:tw=78:sw=4:ts=8:ft=help:norl: From f5c3ad2ee81edff3c96d3cf042bec7c39d76a6d3 Mon Sep 17 00:00:00 2001 From: Rolf Bjaanes Date: Fri, 30 Nov 2012 21:14:11 +0100 Subject: [PATCH 025/451] hefty reformatting of the syntax docs --- doc/ft-ruby-syntax.txt | 60 +++++++++++++++++++++++++++++------------- 1 file changed, 42 insertions(+), 18 deletions(-) diff --git a/doc/ft-ruby-syntax.txt b/doc/ft-ruby-syntax.txt index 7bc2c064..fb815308 100644 --- a/doc/ft-ruby-syntax.txt +++ b/doc/ft-ruby-syntax.txt @@ -1,43 +1,67 @@ -RUBY *ruby.vim* *ft-ruby-syntax* +RUBY *ruby.vim* *ft-ruby-syntax* There are a number of options to the Ruby syntax highlighting. -By default, the "end" keyword is colorized according to the opening statement -of the block it closes. While useful, this feature can be expensive; if you -experience slow redrawing (or you are on a terminal with poor color support) -you may want to turn it off by defining the "ruby_no_expensive" variable: > +1. Ruby operators |ruby_operators| +2. Whitespace errors |ruby_space_errors| +3. Folds |ruby_fold| +4. Reducing expensive operations |ruby_no_expensive| |ruby_minlines| - :let ruby_no_expensive = 1 -< -In this case the same color will be used for all control keywords. -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: > +============================================================================== +1. Ruby operators *ruby_operators* - :let ruby_minlines = 100 -< -Ideally, this value should be a number of lines large enough to embrace your -largest class or module. +Ruby operators can be highlighted. -Ruby operators can be highlighted. This is enabled by defining -"ruby_operators": > +This is enabled by defining "ruby_operators": > :let ruby_operators = 1 < + +============================================================================== +2. Whitespace errors *ruby_space_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. +============================================================================== +3. Folds *ruby_fold* + +Folds can be enabled by defining "ruby_fold": > + :let ruby_fold = 1 < + This will set the value |foldmethod| to "syntax" locally to the current buffer or window, which will enable syntax-based folding when editing Ruby filetypes. -> + +============================================================================== +4. Reducing expensive operations *ruby_no_expensive* + +By default, the "end" keyword is colorized according to the opening statement +of the block it closes. While useful, this feature can be expensive; if you +experience slow redrawing (or you are on a terminal with poor color support) +you may want to turn it off by defining the "ruby_no_expensive" variable: > + + :let ruby_no_expensive = 1 +< +In this case the same color will be used for all control keywords. + + *ruby-minlines* +If you do want this feature enabled, but notice highlighting errors while +scrolling backwards, which are fixed when redrawing with CTRL-L, try setting +the "ruby_minlines" variable to a value larger than 50: > + + :let ruby_minlines = 100 +< +Ideally, this value should be a number of lines large enough to embrace your +largest class or module. vim:tw=78:sw=4:ts=8:ft=help:norl: From 4f20d561914927b2e5095adb5f06f369e6fc2386 Mon Sep 17 00:00:00 2001 From: Rolf Bjaanes Date: Fri, 30 Nov 2012 22:53:59 +0100 Subject: [PATCH 026/451] Typo fix: s/ruby-minlines/ruby_minlines/ --- doc/ft-ruby-syntax.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/ft-ruby-syntax.txt b/doc/ft-ruby-syntax.txt index fb815308..a5760e5d 100644 --- a/doc/ft-ruby-syntax.txt +++ b/doc/ft-ruby-syntax.txt @@ -54,7 +54,7 @@ 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* + *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: > From 42454576554310aae282a0becb0c0b3d69371148 Mon Sep 17 00:00:00 2001 From: Andrew Radev Date: Sat, 1 Dec 2012 13:55:10 +0100 Subject: [PATCH 027/451] Some more help file reformatting Should fit the ":help syntax" section better. --- doc/ft-ruby-syntax.txt | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/doc/ft-ruby-syntax.txt b/doc/ft-ruby-syntax.txt index a5760e5d..482ebefc 100644 --- a/doc/ft-ruby-syntax.txt +++ b/doc/ft-ruby-syntax.txt @@ -1,4 +1,4 @@ -RUBY *ruby.vim* *ft-ruby-syntax* +RUBY *ruby.vim* *ft-ruby-syntax* There are a number of options to the Ruby syntax highlighting. @@ -8,8 +8,7 @@ There are a number of options to the Ruby syntax highlighting. 4. Reducing expensive operations |ruby_no_expensive| |ruby_minlines| -============================================================================== -1. Ruby operators *ruby_operators* +1. Ruby operators *ruby_operators* Ruby operators can be highlighted. @@ -18,8 +17,7 @@ This is enabled by defining "ruby_operators": > :let ruby_operators = 1 < -============================================================================== -2. Whitespace errors *ruby_space_errors* +2. Whitespace errors *ruby_space_errors* Whitespace errors can be highlighted by defining "ruby_space_errors": > @@ -31,8 +29,7 @@ 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. -============================================================================== -3. Folds *ruby_fold* +3. Folds *ruby_fold* Folds can be enabled by defining "ruby_fold": > @@ -42,8 +39,7 @@ Folds can be enabled by defining "ruby_fold": > This will set the value |foldmethod| to "syntax" locally to the current buffer or window, which will enable syntax-based folding when editing Ruby filetypes. -============================================================================== -4. Reducing expensive operations *ruby_no_expensive* +4. Reducing expensive operations *ruby_no_expensive* 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 @@ -54,7 +50,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* + *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: > From 91382a1bb5034318c60519e47e8ba11cea9174cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohnic=CC=81?= Date: Fri, 7 Dec 2012 00:42:30 +0100 Subject: [PATCH 028/451] disable ansi color for keyword lookup with `ri` in GUI --- ftplugin/ruby.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ftplugin/ruby.vim b/ftplugin/ruby.vim index 6678731d..d8fcdbc7 100644 --- a/ftplugin/ruby.vim +++ b/ftplugin/ruby.vim @@ -15,7 +15,7 @@ let s:cpo_save = &cpo set cpo&vim if has("gui_running") && !has("gui_win32") - setlocal keywordprg=ri\ -T + setlocal keywordprg=ri\ -T\ -f\ bs else setlocal keywordprg=ri endif From 680d1eaafc693017318267b6eb08eb889252c0aa Mon Sep 17 00:00:00 2001 From: Tim Pope Date: Sat, 8 Dec 2012 17:25:18 -0500 Subject: [PATCH 029/451] Colon replacement for surround.vim I know supporting plugins is a slippery, slippery slope, but if we can do matchit, why not surround? This lets you do cs": to change a string to a symbol. --- ftplugin/ruby.vim | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ftplugin/ruby.vim b/ftplugin/ruby.vim index d8fcdbc7..4dc83eb5 100644 --- a/ftplugin/ruby.vim +++ b/ftplugin/ruby.vim @@ -41,6 +41,10 @@ if exists("loaded_matchit") && !exists("b:match_words") \ "InstanceVariable\\|GlobalVariable\\|Symbol\\)\\>'" endif +if exists('g:loaded_surround') && !exists('b:surround_'.char2nr(':')) + let b:surround_{char2nr(':')} = ":\r" +endif + setlocal formatoptions-=t formatoptions+=croql setlocal include=^\\s*\\<\\(load\\>\\\|require\\>\\\|autoload\\s*:\\=[\"']\\=\\h\\w*[\"']\\=,\\) From f53e7f127133db9574c6a576898fd683040c134e Mon Sep 17 00:00:00 2001 From: Sencer Selcuk Date: Mon, 10 Dec 2012 23:29:45 -0500 Subject: [PATCH 030/451] a:v -> escape(a:v) in GetRubyVarType for *args --- autoload/rubycomplete.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/autoload/rubycomplete.vim b/autoload/rubycomplete.vim index 66e88450..ca9f7a7f 100644 --- a/autoload/rubycomplete.vim +++ b/autoload/rubycomplete.vim @@ -133,7 +133,7 @@ function! s:GetRubyVarType(v) let stopline = 1 let vtp = '' let pos = getpos('.') - let sstr = '^\s*#\s*@var\s*'.a:v.'\>\s\+[^ \t]\+\s*$' + 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) From 005af7a53d46c353bc5c72b579c7961756aaea51 Mon Sep 17 00:00:00 2001 From: narkisr Date: Tue, 1 Jan 2013 15:49:00 +0200 Subject: [PATCH 031/451] adding puppet librarian file detection --- ftdetect/ruby.vim | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ftdetect/ruby.vim b/ftdetect/ruby.vim index 44326a76..526f49f0 100644 --- a/ftdetect/ruby.vim +++ b/ftdetect/ruby.vim @@ -50,4 +50,7 @@ au BufNewFile,BufRead *.rabl set filetype=ruby " Jbuilder au BufNewFile,BufRead *.jbuilder set filetype=ruby +" Puppet librarian +au BufNewFile,BufRead Puppetfile set filetype=ruby + " vim: nowrap sw=2 sts=2 ts=8 noet: From 01fdf572617c60ec4c6298f9b10e1a536a3279ff Mon Sep 17 00:00:00 2001 From: Tim Pope Date: Fri, 4 Jan 2013 12:33:43 -0500 Subject: [PATCH 032/451] Revert "Colon replacement for surround.vim" This reverts commit 680d1eaafc693017318267b6eb08eb889252c0aa. I'll pick this battle over something more substantive. --- ftplugin/ruby.vim | 4 ---- 1 file changed, 4 deletions(-) diff --git a/ftplugin/ruby.vim b/ftplugin/ruby.vim index 4dc83eb5..d8fcdbc7 100644 --- a/ftplugin/ruby.vim +++ b/ftplugin/ruby.vim @@ -41,10 +41,6 @@ if exists("loaded_matchit") && !exists("b:match_words") \ "InstanceVariable\\|GlobalVariable\\|Symbol\\)\\>'" endif -if exists('g:loaded_surround') && !exists('b:surround_'.char2nr(':')) - let b:surround_{char2nr(':')} = ":\r" -endif - setlocal formatoptions-=t formatoptions+=croql setlocal include=^\\s*\\<\\(load\\>\\\|require\\>\\\|autoload\\s*:\\=[\"']\\=\\h\\w*[\"']\\=,\\) From e272e240b24473194ca487bb1feb146edcb07d1b Mon Sep 17 00:00:00 2001 From: Tim Pope Date: Thu, 10 Jan 2013 20:31:01 -0500 Subject: [PATCH 033/451] Bump ruby_minlines This default was chosen a decade ago. I think computers are faster now. --- syntax/ruby.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/syntax/ruby.vim b/syntax/ruby.vim index 8450438b..de785ff7 100644 --- a/syntax/ruby.vim +++ b/syntax/ruby.vim @@ -241,7 +241,7 @@ if !exists("b:ruby_no_expensive") && !exists("ruby_no_expensive") syn region rubyRepeatExpression start="\[?!]\@!" start="\%(\%(^\|\.\.\.\=\|[{:,;([<>~\*/%&^|+-]\|\%(\<[_[:lower:]][_[:alnum:]]*\)\@" matchgroup=rubyRepeat end="\" contains=ALLBUT,@rubyNotTop nextgroup=rubyOptionalDoLine fold if !exists("ruby_minlines") - let ruby_minlines = 50 + let ruby_minlines = 500 endif exec "syn sync minlines=" . ruby_minlines From ce815669e1fa18669e82a030ff20c811fb5ca4ee Mon Sep 17 00:00:00 2001 From: Wirianto Djunaidi Date: Mon, 14 Jan 2013 10:28:53 +1300 Subject: [PATCH 034/451] add Buildr buildfile ftdetect --- ftdetect/ruby.vim | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ftdetect/ruby.vim b/ftdetect/ruby.vim index 526f49f0..4a32596a 100644 --- a/ftdetect/ruby.vim +++ b/ftdetect/ruby.vim @@ -52,5 +52,8 @@ au BufNewFile,BufRead *.jbuilder set filetype=ruby " Puppet librarian au BufNewFile,BufRead Puppetfile set filetype=ruby +" +" Buildr Buildfile +au BufNewFile,BufRead [Bb]uildfile set filetype=ruby " vim: nowrap sw=2 sts=2 ts=8 noet: From 86bade25a96df1d7f3d2570131838205ca1a40be Mon Sep 17 00:00:00 2001 From: Doug Kearns Date: Sat, 8 Sep 2012 02:05:25 +1000 Subject: [PATCH 035/451] Remove no longer relevant FIXME comment --- bin/vim-ruby-install.rb | 4 ---- 1 file changed, 4 deletions(-) diff --git a/bin/vim-ruby-install.rb b/bin/vim-ruby-install.rb index 81d81a7f..5586df65 100755 --- a/bin/vim-ruby-install.rb +++ b/bin/vim-ruby-install.rb @@ -31,10 +31,6 @@ 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. From c7cb532467f07a650ffe881ae18ce66f210dc52a Mon Sep 17 00:00:00 2001 From: Mike Morearty Date: Wed, 23 Jan 2013 11:03:51 -0800 Subject: [PATCH 036/451] Make matchit's "%" ignore Range.end method With the following code, matchit's "%" key will now jump between line 1 and line 3, as it should: if x (1..5).end end --- syntax/ruby.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/syntax/ruby.vim b/syntax/ruby.vim index de785ff7..3ced9bfc 100644 --- a/syntax/ruby.vim +++ b/syntax/ruby.vim @@ -228,7 +228,7 @@ if !exists("b:ruby_no_expensive") && !exists("ruby_no_expensive") " statements without 'do' syn region rubyBlockExpression matchgroup=rubyControl start="\" end="\" contains=ALLBUT,@rubyNotTop fold syn region rubyCaseExpression matchgroup=rubyConditional start="\" end="\" contains=ALLBUT,@rubyNotTop fold - syn region rubyConditionalExpression matchgroup=rubyConditional start="\%(\%(^\|\.\.\.\=\|[{:,;([<>~\*/%&^|+=-]\|\%(\<[_[:lower:]][_[:alnum:]]*\)\@" end="\" contains=ALLBUT,@rubyNotTop fold + syn region rubyConditionalExpression matchgroup=rubyConditional start="\%(\%(^\|\.\.\.\=\|[{:,;([<>~\*/%&^|+=-]\|\%(\<[_[:lower:]][_[:alnum:]]*\)\@" end="\%(\%(\%(\.\@" contains=ALLBUT,@rubyNotTop fold syn match rubyConditional "\<\%(then\|else\|when\)\>[?!]\@!" contained containedin=rubyCaseExpression syn match rubyConditional "\<\%(then\|else\|elsif\)\>[?!]\@!" contained containedin=rubyConditionalExpression From 96b308b9a2cd99d198e26b51b79d9c3930d9b789 Mon Sep 17 00:00:00 2001 From: Andrew Radev Date: Sun, 10 Feb 2013 10:51:42 +0100 Subject: [PATCH 037/451] Remove unnecessary check This fixes a regression with case statements from commit 0c4190c1c88e25fcd2994709da8c27f22dd697ec. Turns out, `s:Match` already handles the string-or-comment check, and in a much smarter way, so the abovementioned commit only needed to update the syntax groups checked for being a "string". --- indent/ruby.vim | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/indent/ruby.vim b/indent/ruby.vim index 8bbbbbb0..841b48e4 100644 --- a/indent/ruby.vim +++ b/indent/ruby.vim @@ -498,9 +498,7 @@ function GetRubyIndent(...) " If the previous line ended with [*+/.,-=], but wasn't a block ending, " indent one extra level. - if s:Match(lnum, s:non_bracket_continuation_regex) - \ && !s:Match(lnum, '^\s*\(}\|end\)') - \ && !s:IsInStringOrComment(lnum, len(line)) + if s:Match(lnum, s:non_bracket_continuation_regex) && !s:Match(lnum, '^\s*\(}\|end\)') if lnum == p_lnum let ind = msl_ind + &sw else From 17b4d249448feaf54af5bb34aa521b96fe0fbb8c Mon Sep 17 00:00:00 2001 From: Andrew Radev Date: Sun, 10 Feb 2013 11:14:47 +0100 Subject: [PATCH 038/451] Adjust indenting after lines like "]," This is already taken care of for block endings, but needs to be done for arrays and round-brace groupings. --- indent/ruby.vim | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/indent/ruby.vim b/indent/ruby.vim index 841b48e4..dc8d2c34 100644 --- a/indent/ruby.vim +++ b/indent/ruby.vim @@ -496,9 +496,9 @@ function GetRubyIndent(...) return ind endif - " If the previous line ended with [*+/.,-=], but wasn't a block ending, - " indent one extra level. - if s:Match(lnum, s:non_bracket_continuation_regex) && !s:Match(lnum, '^\s*\(}\|end\)') + " If the previous line ended with [*+/.,-=], but wasn't a block ending or a + " closing bracket, indent one extra level. + if s:Match(lnum, s:non_bracket_continuation_regex) && !s:Match(lnum, '^\s*\([\])}]\|end\)') if lnum == p_lnum let ind = msl_ind + &sw else From 1a2075d90992901436bb88391ed52dfbebc5088a Mon Sep 17 00:00:00 2001 From: Andrew Radev Date: Mon, 18 Feb 2013 21:59:52 +0100 Subject: [PATCH 039/451] Watch out for indent keywords with hanging brackets This way, a def or class ending in a multi-line bracket group would indent its body correctly. --- indent/ruby.vim | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/indent/ruby.vim b/indent/ruby.vim index dc8d2c34..4305bb96 100644 --- a/indent/ruby.vim +++ b/indent/ruby.vim @@ -430,7 +430,12 @@ function GetRubyIndent(...) elseif closing.pos != -1 call cursor(lnum, closing.pos + 1) normal! % - return indent('.') + + if s:Match(line('.'), s:ruby_indent_keywords) + return indent('.') + &sw + else + return indent('.') + endif else call cursor(clnum, vcol) end From 3a4093afb890e0d3b5bc39da65ea409095dae0c1 Mon Sep 17 00:00:00 2001 From: Tim Pope Date: Fri, 22 Feb 2013 18:06:25 -0500 Subject: [PATCH 040/451] Remove debugging variable --- ftplugin/ruby.vim | 1 - 1 file changed, 1 deletion(-) diff --git a/ftplugin/ruby.vim b/ftplugin/ruby.vim index d8fcdbc7..5f3e4e40 100644 --- a/ftplugin/ruby.vim +++ b/ftplugin/ruby.vim @@ -317,7 +317,6 @@ function! s:gf(count,map,edit) abort else let target = expand('') endif - let g:target = target let found = findfile(target, &path, a:count) if found ==# '' return 'norm! '.a:count.a:map From b84bf7292a989fe71db089c8444c8932ce274686 Mon Sep 17 00:00:00 2001 From: Tim Pope Date: Fri, 22 Feb 2013 18:19:30 -0500 Subject: [PATCH 041/451] Experimental support for .ruby-version I do not want to head down the road of supporting every Ruby version manager under the sun, but I think .ruby-version can be considered a standard, at this point. --- ftplugin/ruby.vim | 75 ++++++++++++++++++++++++++++++++++------------- 1 file changed, 55 insertions(+), 20 deletions(-) diff --git a/ftplugin/ruby.vim b/ftplugin/ruby.vim index 5f3e4e40..d3d3382c 100644 --- a/ftplugin/ruby.vim +++ b/ftplugin/ruby.vim @@ -63,32 +63,67 @@ endif setlocal comments=:# setlocal commentstring=#\ %s -if !exists("s:ruby_path") - if exists("g:ruby_path") - let s:ruby_path = type(g:ruby_path) == type([]) ? join(g:ruby_path,',') : g:ruby_path +if !exists('g:ruby_version_paths') + let g:ruby_version_paths = {} +endif + +function! s:query_path(root) + let code = "print $:.join(%q{,})" + if &shell =~# 'sh' && $PATH !~# '\s' + let prefix = 'env PATH='.$PATH.' ' + else + let prefix = '' + endif + if &shellxquote == "'" + let path_check = prefix.'ruby -e "' . code . '"' else + let path_check = prefix."ruby -e '" . code . "'" + endif + + let cd = haslocaldir() ? 'lcd' : 'cd' + let cwd = getcwd() + try + exe cd fnameescape(a:root) + return split(system(path_check),',') + finally + exe cd fnameescape(cwd) + endtry +endfunction + +function! s:build_path(path) + let path = join(map(copy(a:path), 'v:val ==# "." ? "" : v:val'), ',') + if &g:path !~# '\v^\.%(,/%(usr|emx)/include)=,,$' + let path = substitute(&g:path,',,$',',','') . ',' . path + endif + return path +endfunction + +if !exists('b:ruby_version') && !exists('g:ruby_path') + let s:version_file = findfile('.ruby-version', '.;') + if !empty(s:version_file) + let b:ruby_version = get(readfile(s:version_file, '', 1), '') + if !has_key(g:ruby_version_paths, b:ruby_version) + let g:ruby_version_paths[b:ruby_version] = s:query_path(fnamemodify(s:version_file, ':p:h')) + endif + endif +endif + +if exists("g:ruby_path") + let s:ruby_path = type(g:ruby_path) == type([]) ? join(g:ruby_path, ',') : g:ruby_path +elseif has_key(g:ruby_version_paths, get(b:, 'ruby_version', '')) + let s:ruby_paths = g:ruby_version_paths[b:ruby_version] + let s:ruby_path = s:build_path(s:ruby_paths) +else + if !exists('g:ruby_default_path') if has("ruby") && has("win32") - ruby ::VIM::command( 'let s:ruby_paths = split("%s",",")' % $:.join(%q{,}) ) + ruby ::VIM::command( 'let g:ruby_default_path = split("%s",",")' % $:.join(%q{,}) ) elseif executable('ruby') - let s:code = "print $:.join(%q{,})" - if executable('env') && $PATH !~# '\s' - let prefix = 'env PATH='.$PATH.' ' - else - let prefix = '' - endif - if &shellxquote == "'" - let s:ruby_paths = split(system(prefix.'ruby -e "' . s:code . '"'),',') - else - let s:ruby_paths = split(system(prefix."ruby -e '" . s:code . "'"),',') - endif + let g:ruby_default_path = s:query_path($HOME) else - let s:ruby_paths = split($RUBYLIB,':') - endif - let s:ruby_path = substitute(join(s:ruby_paths,","), '\%(^\|,\)\.\%(,\|$\)', ',,', '') - if &g:path !~# '\v^\.%(,/%(usr|emx)/include)=,,$' - let s:ruby_path = substitute(&g:path,',,$',',','') . ',' . s:ruby_path + let g:ruby_default_path = map(split($RUBYLIB,':'), 'v:val ==# "." ? "" : v:val') endif endif + let s:ruby_path = s:build_path(g:ruby_default_path) endif if stridx(&l:path, s:ruby_path) == -1 From c6451c855c8d7c293de3f0c77df29f49667a04b6 Mon Sep 17 00:00:00 2001 From: Tim Pope Date: Fri, 22 Feb 2013 19:06:50 -0500 Subject: [PATCH 042/451] Fix 'tags' in the default Ruby case --- ftplugin/ruby.vim | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ftplugin/ruby.vim b/ftplugin/ruby.vim index d3d3382c..3ad2022a 100644 --- a/ftplugin/ruby.vim +++ b/ftplugin/ruby.vim @@ -123,7 +123,8 @@ else let g:ruby_default_path = map(split($RUBYLIB,':'), 'v:val ==# "." ? "" : v:val') endif endif - let s:ruby_path = s:build_path(g:ruby_default_path) + let s:ruby_paths = g:ruby_default_path + let s:ruby_path = s:build_path(s:ruby_paths) endif if stridx(&l:path, s:ruby_path) == -1 From 83653b4d7a2118967d2506ef4ecdd1348228d892 Mon Sep 17 00:00:00 2001 From: Tim Pope Date: Mon, 25 Feb 2013 14:51:07 -0500 Subject: [PATCH 043/451] Highlight Ruby 1.9 overloadable operators --- syntax/ruby.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/syntax/ruby.vim b/syntax/ruby.vim index 3ced9bfc..8987edd6 100644 --- a/syntax/ruby.vim +++ b/syntax/ruby.vim @@ -97,7 +97,7 @@ syn match rubyConstant "\%(\%([.@$]\@\|::\) syn match rubyClassVariable "@@\h\w*" display syn match rubyInstanceVariable "@\h\w*" display syn match rubyGlobalVariable "$\%(\h\w*\|-.\)" -syn match rubySymbol "[]})\"':]\@\|<=\|<\|===\|==\|=\~\|>>\|>=\|>\||\|-@\|-\|/\|\[]=\|\[]\|\*\*\|\*\|&\|%\|+@\|+\|`\)" +syn match rubySymbol "[]})\"':]\@\|<=\|<\|===\|[=!]=\|[=!]\~\|!\|>>\|>=\|>\||\|-@\|-\|/\|\[]=\|\[]\|\*\*\|\*\|&\|%\|+@\|+\|`\)" syn match rubySymbol "[]})\"':]\@_,;:!?/.'"@$*\&+0]\)" syn match rubySymbol "[]})\"':]\@\@!\)\=" @@ -189,7 +189,7 @@ syn match rubyClassDeclaration "[^[:space:];#<]\+" contained contains=rubyC syn match rubyModuleDeclaration "[^[:space:];#<]\+" contained contains=rubyConstant,rubyOperator syn match rubyFunction "\<[_[:alpha:]][_[:alnum:]]*[?!=]\=[[:alnum:]_.:?!=]\@!" contained containedin=rubyMethodDeclaration syn match rubyFunction "\%(\s\|^\)\@<=[_[:alpha:]][_[:alnum:]]*[?!=]\=\%(\s\|$\)\@=" contained containedin=rubyAliasDeclaration,rubyAliasDeclaration2 -syn match rubyFunction "\%([[:space:].]\|^\)\@<=\%(\[\]=\=\|\*\*\|[+-]@\=\|[*/%|&^~]\|<<\|>>\|[<>]=\=\|<=>\|===\|==\|=\~\|`\)\%([[:space:];#(]\|$\)\@=" contained containedin=rubyAliasDeclaration,rubyAliasDeclaration2,rubyMethodDeclaration +syn match rubyFunction "\%([[:space:].]\|^\)\@<=\%(\[\]=\=\|\*\*\|[+-]@\=\|[*/%|&^~]\|<<\|>>\|[<>]=\=\|<=>\|===\|[=!]=\|[=!]\~\|!\|`\)\%([[:space:];#(]\|$\)\@=" contained containedin=rubyAliasDeclaration,rubyAliasDeclaration2,rubyMethodDeclaration syn cluster rubyDeclaration contains=rubyAliasDeclaration,rubyAliasDeclaration2,rubyMethodDeclaration,rubyModuleDeclaration,rubyClassDeclaration,rubyFunction,rubyBlockParameter From 423286ecb27f8e15fd2bd64c3bc26ccaf571e735 Mon Sep 17 00:00:00 2001 From: Tim Pope Date: Mon, 25 Feb 2013 14:51:43 -0500 Subject: [PATCH 044/451] Fix error when editing virtual files Closes #131. --- ftplugin/ruby.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ftplugin/ruby.vim b/ftplugin/ruby.vim index 3ad2022a..9309f3a1 100644 --- a/ftplugin/ruby.vim +++ b/ftplugin/ruby.vim @@ -98,7 +98,7 @@ function! s:build_path(path) return path endfunction -if !exists('b:ruby_version') && !exists('g:ruby_path') +if !exists('b:ruby_version') && !exists('g:ruby_path') && isdirectory(expand('%:p:h')) let s:version_file = findfile('.ruby-version', '.;') if !empty(s:version_file) let b:ruby_version = get(readfile(s:version_file, '', 1), '') From 85c3185d8f5da9fa6f3fd860011fe3217b5409ee Mon Sep 17 00:00:00 2001 From: Tim Pope Date: Sat, 9 Mar 2013 20:33:31 -0500 Subject: [PATCH 045/451] Highlight regexps after <<, +, -, and * Closes #136. --- syntax/ruby.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/syntax/ruby.vim b/syntax/ruby.vim index 8987edd6..ebf75d7b 100644 --- a/syntax/ruby.vim +++ b/syntax/ruby.vim @@ -124,7 +124,7 @@ syn match rubyPredefinedConstant "\%(\%(\.\@\%(\s*(\)\@!" " Normal Regular Expression -syn region rubyRegexp matchgroup=rubyRegexpDelimiter start="\%(\%(^\|\<\%(and\|or\|while\|until\|unless\|if\|elsif\|when\|not\|then\|else\)\|[;\~=!|&(,[>?:]\)\s*\)\@<=/" end="/[iomxneus]*" skip="\\\\\|\\/" contains=@rubyRegexpSpecial fold +syn region rubyRegexp matchgroup=rubyRegexpDelimiter start="\%(\%(^\|\<\%(and\|or\|while\|until\|unless\|if\|elsif\|when\|not\|then\|else\)\|[;\~=!|&(,[<>?:*+-]\)\s*\)\@<=/" end="/[iomxneus]*" skip="\\\\\|\\/" contains=@rubyRegexpSpecial fold syn region rubyRegexp matchgroup=rubyRegexpDelimiter start="\%(\h\k*\s\+\)\@<=/[ \t=]\@!" end="/[iomxneus]*" skip="\\\\\|\\/" contains=@rubyRegexpSpecial fold " Generalized Regular Expression From 6c8f3d848bbad02dedd1cc3b8be2b57b6da3fb82 Mon Sep 17 00:00:00 2001 From: Andrew Radev Date: Mon, 18 Feb 2013 21:38:34 +0100 Subject: [PATCH 046/451] Use s:Match instead of =~ to avoid matching strings or comments --- indent/ruby.vim | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/indent/ruby.vim b/indent/ruby.vim index 4305bb96..82fc6480 100644 --- a/indent/ruby.vim +++ b/indent/ruby.vim @@ -161,7 +161,7 @@ function s:GetMSL(lnum) " Otherwise, terminate search as we have found our MSL already. let line = getline(lnum) - if line =~ s:splat_regex + if s:Match(lnum, s:splat_regex) " If the above line looks like the "*" of a splat, use the current one's " indentation. " @@ -171,8 +171,8 @@ function s:GetMSL(lnum) " something " return msl - elseif line =~ s:non_bracket_continuation_regex && - \ msl_body =~ s:non_bracket_continuation_regex + elseif s:Match(line, s:non_bracket_continuation_regex) && + \ s:Match(msl, s:non_bracket_continuation_regex) " If the current line is a non-bracket continuation and so is the " previous one, keep its indent and continue looking for an MSL. " @@ -182,8 +182,8 @@ function s:GetMSL(lnum) " three " let msl = lnum - elseif line =~ s:non_bracket_continuation_regex && - \ (msl_body =~ s:bracket_continuation_regex || msl_body =~ s:block_continuation_regex) + elseif s:Match(lnum, s:non_bracket_continuation_regex) && + \ (s:Match(msl, s:bracket_continuation_regex) || s:Match(msl, s:block_continuation_regex)) " If the current line is a bracket continuation or a block-starter, but " the previous is a non-bracket one, respect the previous' indentation, " and stop here. @@ -194,8 +194,8 @@ function s:GetMSL(lnum) " three " return lnum - elseif line =~ s:bracket_continuation_regex && - \ (msl_body =~ s:bracket_continuation_regex || msl_body =~ s:block_continuation_regex) + elseif s:Match(lnum, s:bracket_continuation_regex) && + \ (s:Match(msl, s:bracket_continuation_regex) || s:Match(msl, s:block_continuation_regex)) " If both lines are bracket continuations (the current may also be a " block-starter), use the current one's and stop here " @@ -204,9 +204,9 @@ function s:GetMSL(lnum) " other_method_call( " foo return msl - elseif line =~ s:block_regex && - \ msl_body !~ s:continuation_regex && - \ msl_body !~ s:block_continuation_regex + elseif s:Match(lnum, s:block_regex) && + \ !s:Match(msl, s:continuation_regex) && + \ !s:Match(msl, s:block_continuation_regex) " If the previous line is a block-starter and the current one is " mostly ordinary, use the current one as the MSL. " From 9d16028720743e61a8078553d7d60b6d619d2ceb Mon Sep 17 00:00:00 2001 From: Andrew Radev Date: Sun, 10 Mar 2013 17:54:53 +0100 Subject: [PATCH 047/451] Add symbols to string-like patterns --- indent/ruby.vim | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/indent/ruby.vim b/indent/ruby.vim index 82fc6480..5a423464 100644 --- a/indent/ruby.vim +++ b/indent/ruby.vim @@ -32,14 +32,14 @@ set cpo&vim " 1. Variables {{{1 " ============ -" Regex of syntax group names that are or delimit string or are comments. +" Regex of syntax group names that are or delimit strings/symbols or are comments. let s:syng_strcom = '\' -" Regex of syntax group names that are strings. +" Regex of syntax group names that are strings or symbols. let s:syng_string = - \ '\' + \ '\' " Regex of syntax group names that are strings or documentation. let s:syng_stringdoc = From bc0bd7a5b5666ac2111bd6e2a24dfde4f3c5191a Mon Sep 17 00:00:00 2001 From: Andrew Marshall Date: Sun, 10 Mar 2013 14:00:26 -0400 Subject: [PATCH 048/451] Fix incorrect match group reference There can never be a second group here, as the regex only has one. --- autoload/rubycomplete.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/autoload/rubycomplete.vim b/autoload/rubycomplete.vim index ca9f7a7f..6527fb9f 100644 --- a/autoload/rubycomplete.vim +++ b/autoload/rubycomplete.vim @@ -276,7 +276,7 @@ class VimRubyCompletion load_buffer_class( $2 ) if pare != nil && $2 != name # load parent class if needed mixre = /.*\n\s*include\s*(.*)\s*\n/.match( classdef ) - load_buffer_module( $2 ) if mixre != nil && $2 != name # load mixins if needed + load_buffer_module( $1 ) if mixre != nil && $1 != name # load mixins if needed begin eval classdef From e5957da31e9c225cd068524be0c5e2c2c95f57dd Mon Sep 17 00:00:00 2001 From: Andrew Marshall Date: Sun, 10 Mar 2013 14:01:19 -0400 Subject: [PATCH 049/451] Support Ruby 2.0's prepend keyword Which, for the most part, is just like include. --- autoload/rubycomplete.vim | 4 ++-- syntax/ruby.vim | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/autoload/rubycomplete.vim b/autoload/rubycomplete.vim index 6527fb9f..a5479e64 100644 --- a/autoload/rubycomplete.vim +++ b/autoload/rubycomplete.vim @@ -275,8 +275,8 @@ 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 ) - load_buffer_module( $1 ) if mixre != nil && $1 != name # load mixins if needed + mixre = /.*\n\s*(include|prepend)\s*(.*)\s*\n/.match( classdef ) + load_buffer_module( $2 ) if mixre != nil && $2 != name # load mixins if needed begin eval classdef diff --git a/syntax/ruby.vim b/syntax/ruby.vim index ebf75d7b..da0a1d0c 100644 --- a/syntax/ruby.vim +++ b/syntax/ruby.vim @@ -264,7 +264,7 @@ if !exists("ruby_no_special_methods") syn keyword rubyException raise fail catch throw " false positive with 'include?' syn match rubyInclude "\[?!]\@!" - syn keyword rubyInclude autoload extend load require require_relative + syn keyword rubyInclude autoload extend load prepend require require_relative syn keyword rubyKeyword callcc caller lambda proc endif @@ -292,7 +292,7 @@ syn match rubyKeywordAsMethod "\%(\%(\.\@" transparent contains=NONE syn match rubyKeywordAsMethod "\%(\%(\.\@" transparent contains=NONE syn match rubyKeywordAsMethod "\%(\%(\.\@" transparent contains=NONE -syn match rubyKeywordAsMethod "\%(\%(\.\@" transparent contains=NONE +syn match rubyKeywordAsMethod "\%(\%(\.\@" transparent contains=NONE syn match rubyKeywordAsMethod "\%(\%(\.\@" transparent contains=NONE " __END__ Directive From 449e445408e9f419d13691fff43720a96f3cfa06 Mon Sep 17 00:00:00 2001 From: Andrew Marshall Date: Mon, 11 Mar 2013 00:07:58 -0400 Subject: [PATCH 050/451] Correctly highlight identifiers with unicode characters Ruby 2.0's default encoding is UTF-8, so these are now allowed by default. --- syntax/ruby.vim | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/syntax/ruby.vim b/syntax/ruby.vim index ebf75d7b..464d8116 100644 --- a/syntax/ruby.vim +++ b/syntax/ruby.vim @@ -94,21 +94,21 @@ syn match rubyLocalVariableOrMethod "\<[_[:lower:]][_[:alnum:]]*[?!=]\=" contain syn match rubyBlockArgument "&[_[:lower:]][_[:alnum:]]" contains=NONE display transparent syn match rubyConstant "\%(\%([.@$]\@\|::\)\@=\%(\s*(\)\@!" -syn match rubyClassVariable "@@\h\w*" display -syn match rubyInstanceVariable "@\h\w*" display -syn match rubyGlobalVariable "$\%(\h\w*\|-.\)" +syn match rubyClassVariable "@@\%(\h\|[^\x00-\x7F]\)\%(\w\|[^\x00-\x7F]\)*" display +syn match rubyInstanceVariable "@\%(\h\|[^\x00-\x7F]\)\%(\w\|[^\x00-\x7F]\)*" display +syn match rubyGlobalVariable "$\%(\%(\h\|[^\x00-\x7F]\)\%(\w\|[^\x00-\x7F]\)*\|-.\)" syn match rubySymbol "[]})\"':]\@\|<=\|<\|===\|[=!]=\|[=!]\~\|!\|>>\|>=\|>\||\|-@\|-\|/\|\[]=\|\[]\|\*\*\|\*\|&\|%\|+@\|+\|`\)" syn match rubySymbol "[]})\"':]\@_,;:!?/.'"@$*\&+0]\)" -syn match rubySymbol "[]})\"':]\@\@!\)\=" +syn match rubySymbol "[]})\"':]\@\@!\)\=" syn match rubySymbol "\%([{(,]\_s*\)\@<=\l\w*[!?]\=::\@!"he=e-1 -syn match rubySymbol "[]})\"':]\@\|{\)\s*\)\@<=|" end="|" oneline display contains=rubyBlockParameter syn match rubyInvalidVariable "$[^ A-Za-z_-]" @@ -163,17 +163,17 @@ syn region rubyString matchgroup=rubyStringDelimiter start="%[QWx]\=(" en syn region rubyString matchgroup=rubyStringDelimiter start="%[Qx] " end=" " skip="\\\\\|\\)" contains=@rubyStringSpecial fold " Here Document -syn region rubyHeredocStart matchgroup=rubyStringDelimiter start=+\%(\%(class\s*\|\%([]})"'.]\|::\)\)\_s*\|\w\)\@ Date: Tue, 12 Mar 2013 11:35:52 +0100 Subject: [PATCH 051/451] Revert "Add symbols to string-like patterns" This reverts commit 9d16028720743e61a8078553d7d60b6d619d2ceb. --- indent/ruby.vim | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/indent/ruby.vim b/indent/ruby.vim index 5a423464..82fc6480 100644 --- a/indent/ruby.vim +++ b/indent/ruby.vim @@ -32,14 +32,14 @@ set cpo&vim " 1. Variables {{{1 " ============ -" Regex of syntax group names that are or delimit strings/symbols or are comments. +" Regex of syntax group names that are or delimit string or are comments. let s:syng_strcom = '\' -" Regex of syntax group names that are strings or symbols. +" Regex of syntax group names that are strings. let s:syng_string = - \ '\' + \ '\' " Regex of syntax group names that are strings or documentation. let s:syng_stringdoc = From 9fc524627c31410a2a7db8ad9322c56f82da945e Mon Sep 17 00:00:00 2001 From: Andrew Marshall Date: Tue, 12 Mar 2013 19:40:27 -0400 Subject: [PATCH 052/451] Add support for public_constant & private_constant (added in Ruby 1.9.3) --- syntax/ruby.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/syntax/ruby.vim b/syntax/ruby.vim index 464d8116..95c6e2dc 100644 --- a/syntax/ruby.vim +++ b/syntax/ruby.vim @@ -255,7 +255,7 @@ endif " Special Methods if !exists("ruby_no_special_methods") - syn keyword rubyAccess public protected private public_class_method private_class_method module_function + syn keyword rubyAccess public protected private public_class_method private_class_method public_constant private_constant module_function " attr is a common variable name syn match rubyAttribute "\%(\%(^\|;\)\s*\)\@<=attr\>\(\s*[.=]\)\@!" syn keyword rubyAttribute attr_accessor attr_reader attr_writer From dc656257fbc8f5054448bb6b52e375d5a3fdd6b6 Mon Sep 17 00:00:00 2001 From: Nicos Gollan Date: Wed, 13 Mar 2013 10:37:07 +0100 Subject: [PATCH 053/451] Highlight Ruby 2.0 symbol array syntax (%i) --- syntax/ruby.vim | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/syntax/ruby.vim b/syntax/ruby.vim index 464d8116..968f9ddb 100644 --- a/syntax/ruby.vim +++ b/syntax/ruby.vim @@ -140,11 +140,11 @@ syn region rubyString matchgroup=rubyStringDelimiter start="'" end="'" skip="\\ syn region rubyString matchgroup=rubyStringDelimiter start="`" end="`" skip="\\\\\|\\`" contains=@rubyStringSpecial fold " Generalized Single Quoted String, Symbol and Array of Strings -syn region rubyString matchgroup=rubyStringDelimiter start="%[qw]\z([~`!@#$%^&*_\-+=|\:;"',.?/]\)" end="\z1" skip="\\\\\|\\\z1" fold -syn region rubyString matchgroup=rubyStringDelimiter start="%[qw]{" end="}" skip="\\\\\|\\}" fold contains=rubyNestedCurlyBraces,rubyDelimEscape -syn region rubyString matchgroup=rubyStringDelimiter start="%[qw]<" end=">" skip="\\\\\|\\>" fold contains=rubyNestedAngleBrackets,rubyDelimEscape -syn region rubyString matchgroup=rubyStringDelimiter start="%[qw]\[" end="\]" skip="\\\\\|\\\]" fold contains=rubyNestedSquareBrackets,rubyDelimEscape -syn region rubyString matchgroup=rubyStringDelimiter start="%[qw](" end=")" skip="\\\\\|\\)" fold contains=rubyNestedParentheses,rubyDelimEscape +syn region rubyString matchgroup=rubyStringDelimiter start="%[qwi]\z([~`!@#$%^&*_\-+=|\:;"',.?/]\)" end="\z1" skip="\\\\\|\\\z1" fold +syn region rubyString matchgroup=rubyStringDelimiter start="%[qwi]{" end="}" skip="\\\\\|\\}" fold contains=rubyNestedCurlyBraces,rubyDelimEscape +syn region rubyString matchgroup=rubyStringDelimiter start="%[qwi]<" end=">" skip="\\\\\|\\>" fold contains=rubyNestedAngleBrackets,rubyDelimEscape +syn region rubyString matchgroup=rubyStringDelimiter start="%[qwi]\[" end="\]" skip="\\\\\|\\\]" fold contains=rubyNestedSquareBrackets,rubyDelimEscape +syn region rubyString matchgroup=rubyStringDelimiter start="%[qwi](" end=")" skip="\\\\\|\\)" fold contains=rubyNestedParentheses,rubyDelimEscape syn region rubyString matchgroup=rubyStringDelimiter start="%q " end=" " skip="\\\\\|\\)" fold syn region rubySymbol matchgroup=rubySymbolDelimiter start="%s\z([~`!@#$%^&*_\-+=|\:;"',.? /]\)" end="\z1" skip="\\\\\|\\\z1" fold syn region rubySymbol matchgroup=rubySymbolDelimiter start="%s{" end="}" skip="\\\\\|\\}" fold contains=rubyNestedCurlyBraces,rubyDelimEscape @@ -155,11 +155,11 @@ syn region rubySymbol matchgroup=rubySymbolDelimiter start="%s(" end=")" " Generalized Double Quoted String and Array of Strings and Shell Command Output " Note: %= is not matched here as the beginning of a double quoted string syn region rubyString matchgroup=rubyStringDelimiter start="%\z([~`!@#$%^&*_\-+|\:;"',.?/]\)" end="\z1" skip="\\\\\|\\\z1" contains=@rubyStringSpecial fold -syn region rubyString matchgroup=rubyStringDelimiter start="%[QWx]\z([~`!@#$%^&*_\-+=|\:;"',.?/]\)" end="\z1" skip="\\\\\|\\\z1" contains=@rubyStringSpecial fold -syn region rubyString matchgroup=rubyStringDelimiter start="%[QWx]\={" end="}" skip="\\\\\|\\}" contains=@rubyStringSpecial,rubyNestedCurlyBraces,rubyDelimEscape fold -syn region rubyString matchgroup=rubyStringDelimiter start="%[QWx]\=<" end=">" skip="\\\\\|\\>" contains=@rubyStringSpecial,rubyNestedAngleBrackets,rubyDelimEscape fold -syn region rubyString matchgroup=rubyStringDelimiter start="%[QWx]\=\[" end="\]" skip="\\\\\|\\\]" contains=@rubyStringSpecial,rubyNestedSquareBrackets,rubyDelimEscape fold -syn region rubyString matchgroup=rubyStringDelimiter start="%[QWx]\=(" end=")" skip="\\\\\|\\)" contains=@rubyStringSpecial,rubyNestedParentheses,rubyDelimEscape fold +syn region rubyString matchgroup=rubyStringDelimiter start="%[QWIx]\z([~`!@#$%^&*_\-+=|\:;"',.?/]\)" end="\z1" skip="\\\\\|\\\z1" contains=@rubyStringSpecial fold +syn region rubyString matchgroup=rubyStringDelimiter start="%[QWIx]\={" end="}" skip="\\\\\|\\}" contains=@rubyStringSpecial,rubyNestedCurlyBraces,rubyDelimEscape fold +syn region rubyString matchgroup=rubyStringDelimiter start="%[QWIx]\=<" end=">" skip="\\\\\|\\>" contains=@rubyStringSpecial,rubyNestedAngleBrackets,rubyDelimEscape fold +syn region rubyString matchgroup=rubyStringDelimiter start="%[QWIx]\=\[" end="\]" skip="\\\\\|\\\]" contains=@rubyStringSpecial,rubyNestedSquareBrackets,rubyDelimEscape fold +syn region rubyString matchgroup=rubyStringDelimiter start="%[QWIx]\=(" end=")" skip="\\\\\|\\)" contains=@rubyStringSpecial,rubyNestedParentheses,rubyDelimEscape fold syn region rubyString matchgroup=rubyStringDelimiter start="%[Qx] " end=" " skip="\\\\\|\\)" contains=@rubyStringSpecial fold " Here Document From 4937eef614ad45767b1e899b216e9e2029b4b2a8 Mon Sep 17 00:00:00 2001 From: Tim Pope Date: Thu, 14 Mar 2013 13:18:54 -0400 Subject: [PATCH 054/451] Remove "Anon CVS" headers --- autoload/rubycomplete.vim | 1 - compiler/eruby.vim | 1 - compiler/rspec.vim | 1 - compiler/ruby.vim | 1 - compiler/rubyunit.vim | 1 - ftplugin/eruby.vim | 1 - ftplugin/ruby.vim | 1 - indent/eruby.vim | 1 - indent/ruby.vim | 1 - syntax/eruby.vim | 1 - syntax/ruby.vim | 1 - 11 files changed, 11 deletions(-) diff --git a/autoload/rubycomplete.vim b/autoload/rubycomplete.vim index a5479e64..e1064c8a 100644 --- a/autoload/rubycomplete.vim +++ b/autoload/rubycomplete.vim @@ -2,7 +2,6 @@ " 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 " ---------------------------------------------------------------------------- diff --git a/compiler/eruby.vim b/compiler/eruby.vim index e54802ca..45ad5eea 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 -" Anon CVS: See above site " Release Coordinator: Doug Kearns if exists("current_compiler") diff --git a/compiler/rspec.vim b/compiler/rspec.vim index 8e5c7a89..7c340bab 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 -" Anon CVS: See above site " Release Coordinator: Doug Kearns if exists("current_compiler") diff --git a/compiler/ruby.vim b/compiler/ruby.vim index e84088d2..dcf7a401 100644 --- a/compiler/ruby.vim +++ b/compiler/ruby.vim @@ -3,7 +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 " ---------------------------------------------------------------------------- diff --git a/compiler/rubyunit.vim b/compiler/rubyunit.vim index 17b77dc7..93a0c8e6 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 -" Anon CVS: See above site " Release Coordinator: Doug Kearns if exists("current_compiler") diff --git a/ftplugin/eruby.vim b/ftplugin/eruby.vim index 2d124f5d..a097fe0e 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 -" Anon CVS: See above site " Release Coordinator: Doug Kearns " Only do this when not done yet for this buffer diff --git a/ftplugin/ruby.vim b/ftplugin/ruby.vim index 9309f3a1..2d97c5be 100644 --- a/ftplugin/ruby.vim +++ b/ftplugin/ruby.vim @@ -2,7 +2,6 @@ " Language: Ruby " Maintainer: Tim Pope " URL: https://github.com/vim-ruby/vim-ruby -" Anon CVS: See above site " Release Coordinator: Doug Kearns " ---------------------------------------------------------------------------- diff --git a/indent/eruby.vim b/indent/eruby.vim index 30b099d7..80cab700 100644 --- a/indent/eruby.vim +++ b/indent/eruby.vim @@ -2,7 +2,6 @@ " Language: eRuby " Maintainer: Tim Pope " URL: https://github.com/vim-ruby/vim-ruby -" Anon CVS: See above site " Release Coordinator: Doug Kearns if exists("b:did_indent") diff --git a/indent/ruby.vim b/indent/ruby.vim index 82fc6480..6b08f9cb 100644 --- a/indent/ruby.vim +++ b/indent/ruby.vim @@ -2,7 +2,6 @@ " Language: Ruby " Maintainer: Nikolai Weibull " URL: https://github.com/vim-ruby/vim-ruby -" Anon CVS: See above site " Release Coordinator: Doug Kearns " 0. Initialization {{{1 diff --git a/syntax/eruby.vim b/syntax/eruby.vim index a3dd2729..c20b086b 100644 --- a/syntax/eruby.vim +++ b/syntax/eruby.vim @@ -2,7 +2,6 @@ " Language: eRuby " Maintainer: Tim Pope " URL: https://github.com/vim-ruby/vim-ruby -" Anon CVS: See above site " Release Coordinator: Doug Kearns if exists("b:current_syntax") diff --git a/syntax/ruby.vim b/syntax/ruby.vim index 594455c6..28f553de 100644 --- a/syntax/ruby.vim +++ b/syntax/ruby.vim @@ -2,7 +2,6 @@ " Language: Ruby " Maintainer: Doug Kearns " URL: https://github.com/vim-ruby/vim-ruby -" Anon CVS: See above site " Release Coordinator: Doug Kearns " ---------------------------------------------------------------------------- " From e95b8c8555de376e523e3e6a10d1f0b8afd2178b Mon Sep 17 00:00:00 2001 From: Tim Pope Date: Thu, 14 Mar 2013 13:56:58 -0400 Subject: [PATCH 055/451] Add a rake compiler plugin It always bugged me how the first match is almost always some irrelevant stack trace line, or I would have added this years ago. --- compiler/rake.vim | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 compiler/rake.vim diff --git a/compiler/rake.vim b/compiler/rake.vim new file mode 100644 index 00000000..3bd9da0d --- /dev/null +++ b/compiler/rake.vim @@ -0,0 +1,35 @@ +" Vim compiler file +" Language: Rake +" Maintainer: Tim Pope +" URL: https://github.com/vim-ruby/vim-ruby +" Release Coordinator: Doug Kearns + +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%#from\ %f:%l:%m, + \%\\s%#from\ %f:%l:, + \%\\s%##\ %f:%l:%m, + \%\\s%##\ %f:%l, + \%\\s%#[%f:%l:\ %#%m, + \%\\s%#%f:%l:\ %#%m, + \%\\s%#%f:%l:, + \%m\ [%f:%l]: + +let &cpo = s:cpo_save +unlet s:cpo_save + +" vim: nowrap sw=2 sts=2 ts=8: From ef12106da91fd9d71d5737a48c141c3f125e77f9 Mon Sep 17 00:00:00 2001 From: Andrew Radev Date: Fri, 18 May 2012 11:53:50 +0300 Subject: [PATCH 056/451] Introduce tests --- .rspec | 1 + Gemfile | 4 ++ Gemfile.lock | 20 ++++++++ etc/examples/indent/blocks.rb | 47 ------------------ etc/examples/indent/continuations.rb | 39 --------------- etc/examples/indent/end_constructs.rb | 19 -------- etc/examples/indent/nested_hashes.rb | 53 -------------------- etc/examples/indent/splat.rb | 30 ------------ spec/indent/arguments_spec.rb | 24 ++++++++++ spec/indent/basic_spec.rb | 24 ++++++++++ spec/indent/blocks_spec.rb | 69 +++++++++++++++++++++++++++ spec/indent/continuations_spec.rb | 69 +++++++++++++++++++++++++++ spec/indent/end_constructs_spec.rb | 31 ++++++++++++ spec/indent/nesting_spec.rb | 66 +++++++++++++++++++++++++ spec/indent/splat_spec.rb | 46 ++++++++++++++++++ spec/spec_helper.rb | 44 +++++++++++++++++ 16 files changed, 398 insertions(+), 188 deletions(-) create mode 100644 .rspec create mode 100644 Gemfile create mode 100644 Gemfile.lock delete mode 100644 etc/examples/indent/blocks.rb delete mode 100644 etc/examples/indent/continuations.rb delete mode 100644 etc/examples/indent/end_constructs.rb delete mode 100644 etc/examples/indent/nested_hashes.rb delete mode 100644 etc/examples/indent/splat.rb create mode 100644 spec/indent/arguments_spec.rb create mode 100644 spec/indent/basic_spec.rb create mode 100644 spec/indent/blocks_spec.rb create mode 100644 spec/indent/continuations_spec.rb create mode 100644 spec/indent/end_constructs_spec.rb create mode 100644 spec/indent/nesting_spec.rb create mode 100644 spec/indent/splat_spec.rb create mode 100644 spec/spec_helper.rb diff --git a/.rspec b/.rspec new file mode 100644 index 00000000..4e1e0d2f --- /dev/null +++ b/.rspec @@ -0,0 +1 @@ +--color 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..66a9ec64 --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,20 @@ +GEM + remote: http://rubygems.org/ + specs: + diff-lcs (1.1.3) + rspec (2.11.0) + rspec-core (~> 2.11.0) + rspec-expectations (~> 2.11.0) + rspec-mocks (~> 2.11.0) + rspec-core (2.11.1) + rspec-expectations (2.11.2) + diff-lcs (~> 1.1.3) + rspec-mocks (2.11.2) + vimrunner (0.1.1) + +PLATFORMS + ruby + +DEPENDENCIES + rspec + vimrunner diff --git a/etc/examples/indent/blocks.rb b/etc/examples/indent/blocks.rb deleted file mode 100644 index 35562b93..00000000 --- a/etc/examples/indent/blocks.rb +++ /dev/null @@ -1,47 +0,0 @@ -do - something -end - -def foo - a_hash = {:do => 'bar'} -end - -def foo(job) - job.do! -end - -proc do |(a, b)| - puts a - puts b -end - -proc do |foo, (a, b), bar| - puts a - puts b -end - -proc do |(a, (b, c)), d| - puts a, b - puts c, d -end - -define_method "something" do |param| - if param == 42 - do_something - else - do_something_else - end -end - -def foo - opts.on('--coordinator host=HOST[,port=PORT]', - 'Specify the HOST and the PORT of the coordinator') do |str| - h = sub_opts_to_hash(str) - puts h - end -end - -module X - Class.new do - end -end diff --git a/etc/examples/indent/continuations.rb b/etc/examples/indent/continuations.rb deleted file mode 100644 index aeb8d3eb..00000000 --- a/etc/examples/indent/continuations.rb +++ /dev/null @@ -1,39 +0,0 @@ -# See https://github.com/vim-ruby/vim-ruby/issues/75 for details -puts %{#{}} -puts "OK" - -while true - begin - puts %{#{x}} - rescue ArgumentError - end -end - -variable = - if condition? - 1 - else - 2 - end - -variable = # evil comment - case something - when 'something' - something_else - else - other - end - -array = [ - :one, -].each do |x| - puts x.to_s -end - -x { y >> - z } -w - -x { y >> - [z] } -w diff --git a/etc/examples/indent/end_constructs.rb b/etc/examples/indent/end_constructs.rb deleted file mode 100644 index ddb0ed6e..00000000 --- a/etc/examples/indent/end_constructs.rb +++ /dev/null @@ -1,19 +0,0 @@ -module Foo - class Bar - f do - g { def h; end } - end - - if foo - bar ; end - - if bar ; end - - foo do - foo = 3 . class - foo = lambda { class One; end } - foo = lambda { |args| class One; end } - foo = bar; class One; end - end - end -end diff --git a/etc/examples/indent/nested_hashes.rb b/etc/examples/indent/nested_hashes.rb deleted file mode 100644 index 48b00195..00000000 --- a/etc/examples/indent/nested_hashes.rb +++ /dev/null @@ -1,53 +0,0 @@ -class Foo - # nested do ... end blocks: - var.func1(:param => 'value') do - var.func2(:param => 'value') do - puts "test" - end - end - - # nested { ... } blocks - var.func1(:param => 'value') { - var.func2(:param => 'value') { - foo({ bar => baz }) - puts "test one" - puts "test two" - } - } - - # nested hash - foo, bar = { - :bar => { - :one => 'two', - :five => 'six' - } - } - - # nested { ... } blocks with a continued first line - var. - func1(:param => 'value') { - var.func2(:param => 'value') { - puts "test" - } - } - - # nested hashes with a continued first line - foo, - bar = { - :bar => { - :foo => { 'bar' => 'baz' }, - :one => 'two', - :three => 'four' - } - } - - # TODO nested { ... } blocks with a continued first line and a function call - # inbetween - var. - func1(:param => 'value') { - func1_5(:param => 'value') - var.func2(:param => 'value') { - puts "test" - } - } -end diff --git a/etc/examples/indent/splat.rb b/etc/examples/indent/splat.rb deleted file mode 100644 index 8fdb3371..00000000 --- a/etc/examples/indent/splat.rb +++ /dev/null @@ -1,30 +0,0 @@ -x = Foo[* - y do - z - end -] - -x = Foo[* # with a comment - y do - z - end -] - -x = * - array.map do - 3 -end - -x = Foo[* - y { - z - } -] - -x = Foo(*y do - z -end) - -foo(1, - 2, - *) diff --git a/spec/indent/arguments_spec.rb b/spec/indent/arguments_spec.rb new file mode 100644 index 00000000..39837409 --- /dev/null +++ b/spec/indent/arguments_spec.rb @@ -0,0 +1,24 @@ +require 'spec_helper' + +describe "Indenting" do + specify "multi-line arguments" do + assert_correct_indenting <<-EOF + User.new( + :first_name => 'Some', + :second_name => 'Guy' + ) + EOF + + assert_correct_indenting <<-EOF + User.new(:first_name => 'Some', + :second_name => 'Guy') + EOF + + assert_correct_indenting <<-EOF + User.new( + :first_name => 'Some', + :second_name => 'Guy' + ) + EOF + end +end diff --git a/spec/indent/basic_spec.rb b/spec/indent/basic_spec.rb new file mode 100644 index 00000000..a3934404 --- /dev/null +++ b/spec/indent/basic_spec.rb @@ -0,0 +1,24 @@ +require 'spec_helper' + +describe "Indenting" do + specify "if-clauses" do + assert_correct_indenting <<-EOF + if foo + bar + end + EOF + + assert_correct_indenting <<-EOF + if foo + bar + else + baz + end + EOF + + assert_correct_indenting <<-EOF + bar if foo + something_else + EOF + end +end diff --git a/spec/indent/blocks_spec.rb b/spec/indent/blocks_spec.rb new file mode 100644 index 00000000..4903c733 --- /dev/null +++ b/spec/indent/blocks_spec.rb @@ -0,0 +1,69 @@ +require 'spec_helper' + +describe "Indenting" do + specify "'do' indenting" do + assert_correct_indenting <<-EOF + do + something + end + EOF + + assert_correct_indenting <<-EOF + def foo + a_hash = {:do => 'bar'} + end + EOF + + assert_correct_indenting <<-EOF + def foo(job) + job.do! + end + EOF + end + + specify "blocks with multiline parameters" do + assert_correct_indenting <<-EOF + def foo + opts.on('--coordinator host=HOST[,port=PORT]', + 'Specify the HOST and the PORT of the coordinator') do |str| + h = sub_opts_to_hash(str) + puts h + end + end + EOF + end + + specify "case-insensitive matching" do + @vim.set 'ignorecase' + assert_correct_indenting <<-EOF + module X + Class.new do + end + end + EOF + @vim.set 'ignorecase&' + end + + specify "blocks with tuple arguments" do + assert_correct_indenting <<-EOF + proc do |(a, b)| + puts a + puts b + end + EOF + + assert_correct_indenting <<-EOF + proc do |foo, (a, b), bar| + puts a + puts b + end + EOF + + assert_correct_indenting <<-EOF + proc do |(a, (b, c)), d| + puts a, b + puts c, d + end + EOF + end +end diff --git a/spec/indent/continuations_spec.rb b/spec/indent/continuations_spec.rb new file mode 100644 index 00000000..3334c61a --- /dev/null +++ b/spec/indent/continuations_spec.rb @@ -0,0 +1,69 @@ +require 'spec_helper' + +describe "Indenting" do + specify "arrays" do + assert_correct_indenting <<-EOF + foo = [one, + two, + three] + EOF + end + + specify "tricky string interpolation" do + # See https://github.com/vim-ruby/vim-ruby/issues/75 for details + assert_correct_indenting <<-EOF + puts %{\#{}} + puts "OK" + EOF + + assert_correct_indenting <<-EOF + while true + begin + puts %{\#{x}} + rescue ArgumentError + end + end + EOF + end + + specify "continuations after round braces" do + assert_correct_indenting <<-EOF + opts.on('--coordinator host=HOST[,port=PORT]', + 'Specify the HOST and the PORT of the coordinator') do |str| + h = sub_opts_to_hash(str) + puts h + end + EOF + end + + specify "continuations after assignment" do + assert_correct_indenting <<-EOF + variable = + if condition? + 1 + else + 2 + end + EOF + + assert_correct_indenting <<-EOF + variable = # evil comment + case something + when 'something' + something_else + else + other + end + EOF + end + + specify "continuations after hanging comma" do + assert_correct_indenting <<-EOF + array = [ + :one, + ].each do |x| + puts x.to_s + end + EOF + end +end diff --git a/spec/indent/end_constructs_spec.rb b/spec/indent/end_constructs_spec.rb new file mode 100644 index 00000000..e9ae7dad --- /dev/null +++ b/spec/indent/end_constructs_spec.rb @@ -0,0 +1,31 @@ +require 'spec_helper' + +describe "Indenting" do + specify "end constructs" do + assert_correct_indenting <<-EOF + f do + g { def h; end } + end + EOF + + assert_correct_indenting <<-EOF + if foo + bar ; end + something_else + EOF + + assert_correct_indenting <<-EOF + if bar ; end + something_else + EOF + + assert_correct_indenting <<-EOF + foo do + foo = 3 . class + foo = lambda { class One; end } + foo = lambda { |args| class One; end } + foo = bar; class One; end + end + EOF + end +end diff --git a/spec/indent/nesting_spec.rb b/spec/indent/nesting_spec.rb new file mode 100644 index 00000000..7a09d855 --- /dev/null +++ b/spec/indent/nesting_spec.rb @@ -0,0 +1,66 @@ +require 'spec_helper' + +describe "Indenting" do + specify "nested blocks" do + assert_correct_indenting <<-EOF + var.func1(:param => 'value') do + var.func2(:param => 'value') do + puts "test" + end + end + EOF + + assert_correct_indenting <<-EOF + var.func1(:param => 'value') { + var.func2(:param => 'value') { + foo({ bar => baz }) + puts "test one" + puts "test two" + } + } + EOF + + assert_correct_indenting <<-EOF + var. + func1(:param => 'value') { + var.func2(:param => 'value') { + puts "test" + } + } + EOF + end + + specify "nested hashes" do + assert_correct_indenting <<-EOF + foo, bar = { + :bar => { + :one => 'two', + :five => 'six' + } + } + EOF + + assert_correct_indenting <<-EOF + foo, + bar = { + :bar => { + :foo => { 'bar' => 'baz' }, + :one => 'two', + :three => 'four' + } + } + EOF + end + + specify "nested blocks with a continuation and function call inbetween" do + assert_correct_indenting <<-EOF + var. + func1(:param => 'value') { + func1_5(:param => 'value') + var.func2(:param => 'value') { + puts "test" + } + } + EOF + end +end diff --git a/spec/indent/splat_spec.rb b/spec/indent/splat_spec.rb new file mode 100644 index 00000000..235f2528 --- /dev/null +++ b/spec/indent/splat_spec.rb @@ -0,0 +1,46 @@ +require 'spec_helper' + +describe "Indenting" do + specify "splats with blocks in square brackets" do + assert_correct_indenting <<-EOF + x = Foo[* + y do + z + end + ] + EOF + + assert_correct_indenting <<-EOF + x = Foo[* # with a comment + y do + z + end + ] + EOF + end + + specify "splats with blocks in assignment" do + assert_correct_indenting <<-EOF + x = * + array.map do + 3 + end + EOF + end + + specify "splats with blocks in round brackets" do + assert_correct_indenting <<-EOF + x = Foo(*y do + z + end) + EOF + + assert_correct_indenting <<-EOF + x = Foo( + *y do + z + end + ) + EOF + end +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 00000000..a11bb6f1 --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,44 @@ +require 'tmpdir' +require 'vimrunner' + +module Support + def assert_correct_indenting(string) + whitespace = string.scan(/^\s*/).first + string = string.split("\n").map { |line| line.gsub /^#{whitespace}/, '' }.join("\n").strip + + File.open 'test.rb', 'w' do |f| + f.write string + end + + @vim.edit 'test.rb' + @vim.normal 'gg=G' + @vim.write + + IO.read('test.rb').strip.should eq string + end +end + +RSpec.configure do |config| + include Support + + config.before(:suite) do + VIM = Vimrunner.start_gvim + VIM.prepend_runtimepath(File.expand_path('../..', __FILE__)) + end + + config.after(:suite) do + VIM.kill + end + + config.around(:each) do |example| + @vim = VIM + + # cd into a temporary directory for every example. + Dir.mktmpdir do |dir| + Dir.chdir(dir) do + @vim.command("cd #{dir}") + example.call + end + end + end +end From 5d893e6bdc5e5de43eb6c6ec82cc6ef7fd2284d0 Mon Sep 17 00:00:00 2001 From: Andrew Radev Date: Sun, 10 Feb 2013 10:44:48 +0100 Subject: [PATCH 057/451] Migrate an example to a spec --- etc/examples/indent/strings.rb | 2 -- spec/indent/continuations_spec.rb | 8 ++++++++ 2 files changed, 8 insertions(+), 2 deletions(-) delete mode 100644 etc/examples/indent/strings.rb diff --git a/etc/examples/indent/strings.rb b/etc/examples/indent/strings.rb deleted file mode 100644 index d69f806a..00000000 --- a/etc/examples/indent/strings.rb +++ /dev/null @@ -1,2 +0,0 @@ -command = %|#{file}| -settings.log.info("Returning: #{command}") diff --git a/spec/indent/continuations_spec.rb b/spec/indent/continuations_spec.rb index 3334c61a..22bc33fc 100644 --- a/spec/indent/continuations_spec.rb +++ b/spec/indent/continuations_spec.rb @@ -66,4 +66,12 @@ end EOF end + + specify "string interpolation" do + # See https://github.com/vim-ruby/vim-ruby/issues/93 for details + assert_correct_indenting <<-EOF + command = %|\#{file}| + settings.log.info("Returning: \#{command}") + EOF + end end From 43ce47963646e1ea9de16294a6e9c4dbbc60e628 Mon Sep 17 00:00:00 2001 From: Andrew Radev Date: Sun, 10 Feb 2013 11:03:06 +0100 Subject: [PATCH 058/451] One more spec for issue #81 --- spec/indent/continuations_spec.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/spec/indent/continuations_spec.rb b/spec/indent/continuations_spec.rb index 22bc33fc..622306cd 100644 --- a/spec/indent/continuations_spec.rb +++ b/spec/indent/continuations_spec.rb @@ -74,4 +74,13 @@ settings.log.info("Returning: \#{command}") EOF end + + specify "closing bracket not on its own line" do + # See https://github.com/vim-ruby/vim-ruby/issues/81 for details + assert_correct_indenting <<-EOF + one { two >> + three } + four + EOF + end end From 8f1f76ef90a0005fc2dbc889240ecb9ee9203f1f Mon Sep 17 00:00:00 2001 From: Andrew Radev Date: Sun, 10 Feb 2013 11:20:34 +0100 Subject: [PATCH 059/451] Spec --- spec/indent/continuations_spec.rb | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/spec/indent/continuations_spec.rb b/spec/indent/continuations_spec.rb index 622306cd..e4844f7c 100644 --- a/spec/indent/continuations_spec.rb +++ b/spec/indent/continuations_spec.rb @@ -83,4 +83,22 @@ four EOF end + + specify "brackets on their own line, followed by a comma" do + # See https://github.com/vim-ruby/vim-ruby/issues/124 for details + assert_correct_indenting <<-EOF + bla = { + :one => [ + {:bla => :blub} + ], + :two => ( + {:blub => :abc} + ), + :three => { + :blub => :abc + }, + :four => 'five' + } + EOF + end end From 42a35de87090e4f1de595c6d4fc92fb551ce5695 Mon Sep 17 00:00:00 2001 From: Andrew Radev Date: Mon, 18 Feb 2013 22:03:03 +0100 Subject: [PATCH 060/451] Tests for issue 130 --- spec/indent/continuations_spec.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/spec/indent/continuations_spec.rb b/spec/indent/continuations_spec.rb index e4844f7c..bc2f3de8 100644 --- a/spec/indent/continuations_spec.rb +++ b/spec/indent/continuations_spec.rb @@ -84,6 +84,17 @@ EOF end + specify "lonesome single parenthesis in a method definition" do + # See https://github.com/vim-ruby/vim-ruby/issues/130 for details + assert_correct_indenting <<-EOF + def bar( + baz + ) + return baz+1 + end + EOF + end + specify "brackets on their own line, followed by a comma" do # See https://github.com/vim-ruby/vim-ruby/issues/124 for details assert_correct_indenting <<-EOF From e6fbe5499e6f88e21012e59608a58c8744317e63 Mon Sep 17 00:00:00 2001 From: Andrew Radev Date: Sun, 10 Mar 2013 11:01:14 +0100 Subject: [PATCH 061/451] Spec for issue 108 --- spec/indent/continuations_spec.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/spec/indent/continuations_spec.rb b/spec/indent/continuations_spec.rb index bc2f3de8..2a327891 100644 --- a/spec/indent/continuations_spec.rb +++ b/spec/indent/continuations_spec.rb @@ -112,4 +112,14 @@ def bar( } EOF end + + specify "string with an and#" do + # See https://github.com/vim-ruby/vim-ruby/issues/108 for details + assert_correct_indenting <<-EOF + outside_block "and#" do + inside_block do + end + end + EOF + end end From 2d42507d38df6de04c297ed074abeb7c861ec651 Mon Sep 17 00:00:00 2001 From: Andrew Radev Date: Sun, 10 Mar 2013 17:59:06 +0100 Subject: [PATCH 062/451] Spec for issue 132 --- spec/indent/continuations_spec.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/spec/indent/continuations_spec.rb b/spec/indent/continuations_spec.rb index 2a327891..08b192c2 100644 --- a/spec/indent/continuations_spec.rb +++ b/spec/indent/continuations_spec.rb @@ -122,4 +122,12 @@ def bar( end EOF end + + specify "continuation with a symbol at the end" do + # See https://github.com/vim-ruby/vim-ruby/issues/132 for details + assert_correct_indenting <<-EOF + foo = :+ + # Next indents correctly + EOF + end end From 260897af917d479670e2bede89f275c06cf3b1ef Mon Sep 17 00:00:00 2001 From: Andrew Radev Date: Sun, 17 Mar 2013 11:52:53 +0100 Subject: [PATCH 063/451] Fix continuation issue again A spec was implemented for https://github.com/vim-ruby/vim-ruby/issues/139. The issue this commit fixes is: https://github.com/vim-ruby/vim-ruby/issues/132. By adding the `Symbol` group to the "string or syntax" pattern, some continuations are fixed. It should not be added to the "string" pattern, however. --- indent/ruby.vim | 4 ++-- spec/indent/continuations_spec.rb | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/indent/ruby.vim b/indent/ruby.vim index 6b08f9cb..d01a4d10 100644 --- a/indent/ruby.vim +++ b/indent/ruby.vim @@ -31,9 +31,9 @@ set cpo&vim " 1. Variables {{{1 " ============ -" Regex of syntax group names that are or delimit string or are comments. +" Regex of syntax group names that are or delimit strings/symbols or are comments. let s:syng_strcom = '\' " Regex of syntax group names that are strings. diff --git a/spec/indent/continuations_spec.rb b/spec/indent/continuations_spec.rb index 08b192c2..b24d0f89 100644 --- a/spec/indent/continuations_spec.rb +++ b/spec/indent/continuations_spec.rb @@ -130,4 +130,13 @@ def bar( # Next indents correctly EOF end + + specify "continuation with a hanging comma" do + # See https://github.com/vim-ruby/vim-ruby/issues/139 for details + assert_correct_indenting <<-EOF + thing :foo + thing 'a', + 'b' + EOF + end end From 3ead93fbbc10f9ea3ec951fdef69f709d7ca717c Mon Sep 17 00:00:00 2001 From: Tim Pope Date: Mon, 18 Mar 2013 21:32:49 -0400 Subject: [PATCH 064/451] Fix Windows shell escaping issue Closes #143. --- ftplugin/ruby.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ftplugin/ruby.vim b/ftplugin/ruby.vim index 2d97c5be..21af383f 100644 --- a/ftplugin/ruby.vim +++ b/ftplugin/ruby.vim @@ -67,7 +67,7 @@ if !exists('g:ruby_version_paths') endif function! s:query_path(root) - let code = "print $:.join(%q{,})" + let code = "print $:.join %q{,}" if &shell =~# 'sh' && $PATH !~# '\s' let prefix = 'env PATH='.$PATH.' ' else From b5942e740ea95c08b7ddcc1a2bda05bf2c8ea548 Mon Sep 17 00:00:00 2001 From: Derek Prior Date: Fri, 22 Mar 2013 11:21:50 -0400 Subject: [PATCH 065/451] Add appraisals to filetype detection. See: http://github.com/thoughtbot/appraisal --- ftdetect/ruby.vim | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ftdetect/ruby.vim b/ftdetect/ruby.vim index 4a32596a..a4e9a6d9 100644 --- a/ftdetect/ruby.vim +++ b/ftdetect/ruby.vim @@ -56,4 +56,7 @@ au BufNewFile,BufRead Puppetfile set filetype=ruby " Buildr Buildfile au BufNewFile,BufRead [Bb]uildfile set filetype=ruby +" Appraisal +au BufNewFile,BufRead Appraisals set filetype=ruby + " vim: nowrap sw=2 sts=2 ts=8 noet: From 5c3213ab4ba5f446aa98887794ab2cbd909e50c0 Mon Sep 17 00:00:00 2001 From: Tim Pope Date: Wed, 1 May 2013 20:07:57 -0400 Subject: [PATCH 066/451] Work around weird --remote skip of finally Closes #152. --- ftplugin/ruby.vim | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ftplugin/ruby.vim b/ftplugin/ruby.vim index 21af383f..9630a940 100644 --- a/ftplugin/ruby.vim +++ b/ftplugin/ruby.vim @@ -83,7 +83,9 @@ function! s:query_path(root) let cwd = getcwd() try exe cd fnameescape(a:root) - return split(system(path_check),',') + let path = split(system(path_check),',') + exe cd fnameescape(cwd) + return path finally exe cd fnameescape(cwd) endtry From bea6026e78ac2e4ee598430ff2dd8b707f95bc2e Mon Sep 17 00:00:00 2001 From: Jeremy Audet Date: Thu, 9 May 2013 10:13:10 -0400 Subject: [PATCH 067/451] Fix deprecation error. Without fix, this error message appears: bin/vim-ruby-install.rb:15:in `
': Use RbConfig instead of obsolete and deprecated Config. uninitialized constant Env::CONFIG Try 'ruby bin/vim-ruby-install.rb --help' for detailed usage. --- bin/vim-ruby-install.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/vim-ruby-install.rb b/bin/vim-ruby-install.rb index 5586df65..3f738f94 100755 --- a/bin/vim-ruby-install.rb +++ b/bin/vim-ruby-install.rb @@ -12,7 +12,7 @@ # require 'rbconfig' -include Config +include RbConfig require 'fileutils' require 'optparse' require 'pathname' From f90d7b6789d54ad0c68f43288ef5b2b7cd216982 Mon Sep 17 00:00:00 2001 From: Jeremy Audet Date: Thu, 9 May 2013 10:17:44 -0400 Subject: [PATCH 068/451] Reformat installer. Replace tabs with spaces. Ensure comments are properly lined up with code. --- bin/vim-ruby-install.rb | 237 ++++++++++++++++++++-------------------- 1 file changed, 120 insertions(+), 117 deletions(-) diff --git a/bin/vim-ruby-install.rb b/bin/vim-ruby-install.rb index 3f738f94..10a15dd5 100755 --- a/bin/vim-ruby-install.rb +++ b/bin/vim-ruby-install.rb @@ -32,13 +32,13 @@ syntax/ruby.vim } +# +# Miscellaneous functions in the user's environment. +# +class Env # - # Miscellaneous functions in the user's environment. + # Returns :UNIX or :WINDOWS, according to CONFIG['host_os'] and $options[:windows]. # -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] @@ -48,16 +48,16 @@ def Env.determine_target_os 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+. - # + # + # 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. + # 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'. + # 2. Try the gem 'vim-ruby'. begin require 'rubygems' raise "Need RubyGems 0.8+" if Gem::RubyGemsPackageVersion < '0.8' @@ -72,25 +72,25 @@ def Env.determine_source_directory return nil end - # Returns the Vim installation directory ($VIM). - # TODO: print warning if vim command not in PATH or appropriate key not in registry? + # 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 + 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 + 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 @@ -99,7 +99,7 @@ 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'] + ENV['HOMEDRIVE'] + ENV['HOMEPATH'] if ENV['HOMEDRIVE'] and ENV['HOMEPATH'] end return home_dir end @@ -120,12 +120,12 @@ def Env._valid_vim_ruby_dir(dir) end # class Env - # - # A FileWriter writes files with pre-selected line endings and permissions. - # - # writer = FileWriter.new(:UNIX, 0664) - # writer.copy(source, target) - # +# +# 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" } @@ -136,22 +136,25 @@ def initialize(ending, file_permissions=0644, directory_permissions=0755) :dir => directory_permissions } end - # Source and target paths assumed to be Pathname objects. Copy the source to the target, - # ensuring the right line endings. + + # 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) + 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. + + # 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? @@ -162,41 +165,42 @@ def _ensure_directory_exists(path) end end # class FileWriter - - # - # Represents the target base directory for installs. Handles writing the files through a - # given 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. - # +# +# 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. + # 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] @@ -207,13 +211,13 @@ def find_target_directory puts puts "Possible Vim installation directories:" dirs.each_with_index do |dir, idx| - puts " #{idx+1}) #{dir}" + 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 + 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. @@ -228,8 +232,8 @@ def find_target_directory private - # Return an array of _potential_ directories (i.e. they exist). Take the options into - # account. + # Return an array of _potential_ directories (i.e. they exist). Take the options into + # account. def _potential_directories dirs = [] dirs << _vim_user_dir @@ -237,32 +241,29 @@ def _potential_directories return dirs.compact.map { |dir| File.expand_path(dir) } end - # Return the Vim system preferences directory + # 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 + # 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. - # +# +# 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. + # +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" @@ -275,26 +276,26 @@ def initialize(source, target) @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. + # 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) + 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 @@ -302,7 +303,7 @@ def install puts puts "The following backups were made:" backups.each do |path| - puts " * #{path}" + puts " * #{path}" end puts puts "These backups are located in this directory: #{backupdir.path}" @@ -311,19 +312,20 @@ def install private - # Test two files for equality of contents, ignoring line endings. + # 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. + # 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. + + # Copy basedir/path to @path/path. def backup(basedir, path) @base.mkpath unless @base.directory? source = basedir.path + path @@ -331,55 +333,56 @@ def backup(basedir, 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 + 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 * * * - # +# +# * * * M A I N * * * +# begin - $options = { :backup => false, :target_dir => nil, - :windows => false + :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 + 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] + Usage: + direct: ruby bin/vim-ruby-install.rb [options] + gem: vim-ruby-install.rb [options] - Options: - }.gsub(/^ /, '') + Options: + }.gsub(/^ /, '') p.on('-b', '--backup', 'Backup existing runtime files') do |value| $options[:backup] = value end @@ -394,22 +397,22 @@ def path exit end p.on_tail %{ - Notes: + Notes: - * "Direct" usage means unpacking a vim-ruby tarball and running this - program from the vim-ruby directory. + * "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 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. + * 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(/^ /, '') + * This installer is quite new (2004-09-20). Please report bugs to + gsinclair@soyabean.com.au. + }.gsub(/^ /, '') end op.parse!(ARGV) From beb12893e3909462a3cb098b4c778626e61ba025 Mon Sep 17 00:00:00 2001 From: Andrew Radev Date: Sun, 12 May 2013 22:19:36 +0200 Subject: [PATCH 069/451] Basic "<<"-style heredoc indenting If the closing delimiter is at column 0, keep it that way. --- indent/ruby.vim | 13 +++++++++++++ spec/indent/basic_spec.rb | 18 ++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/indent/ruby.vim b/indent/ruby.vim index d01a4d10..095b3a43 100644 --- a/indent/ruby.vim +++ b/indent/ruby.vim @@ -124,6 +124,11 @@ function s:IsInStringOrDocumentation(lnum, col) return synIDattr(synID(a:lnum, a:col, 1), 'name') =~ s:syng_stringdoc endfunction +" Check if the character at lnum:col is inside a string delimiter +function s:IsInStringDelimiter(lnum, col) + return synIDattr(synID(a:lnum, a:col, 1), 'name') == 'rubyStringDelimiter' +endfunction + " Find line above 'lnum' that isn't empty, in a comment, or in a string. function s:PrevNonBlankNonString(lnum) let in_block = 0 @@ -376,6 +381,14 @@ function GetRubyIndent(...) return indent('.') endif + " If we are at the closing delimiter of a "<<" heredoc-style string, set the + " indent to 0. + if line =~ '^\k\+\s*$' + \ && s:IsInStringDelimiter(clnum, 1) + \ && search('\V<<'.line, 'nbW') > 0 + return 0 + endif + " 3.3. Work on the previous line. {{{2 " ------------------------------- diff --git a/spec/indent/basic_spec.rb b/spec/indent/basic_spec.rb index a3934404..8ef872ff 100644 --- a/spec/indent/basic_spec.rb +++ b/spec/indent/basic_spec.rb @@ -21,4 +21,22 @@ something_else EOF end + + specify "heredocs" do + assert_correct_indenting <<-EOF + def one + two = <<-THREE + four + THREE + end + EOF + + assert_correct_indenting <<-EOF + def one + two = < Date: Thu, 6 Jun 2013 21:15:46 -0400 Subject: [PATCH 070/451] Fix keyword symbols after parentheses In response to the comment in #144. --- syntax/ruby.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/syntax/ruby.vim b/syntax/ruby.vim index 28f553de..e4bc98f6 100644 --- a/syntax/ruby.vim +++ b/syntax/ruby.vim @@ -103,7 +103,7 @@ syn match rubySymbol "[]})\"':]\@ Date: Thu, 13 Jun 2013 00:11:26 +1000 Subject: [PATCH 071/451] Remove s:save_cpo when we're done with it --- ftplugin/eruby.vim | 1 + 1 file changed, 1 insertion(+) diff --git a/ftplugin/eruby.vim b/ftplugin/eruby.vim index a097fe0e..9bb8e86f 100644 --- a/ftplugin/eruby.vim +++ b/ftplugin/eruby.vim @@ -97,5 +97,6 @@ let b:undo_ftplugin = "setl cms< " \ " | unlet! b:browsefilter b:match_words | " . s:undo_ftplugin let &cpo = s:save_cpo +unlet s:save_cpo " vim: nowrap sw=2 sts=2 ts=8: From b60da6c63bba329aa0327a2859639f9a02afc3ed Mon Sep 17 00:00:00 2001 From: Doug Kearns Date: Sat, 15 Jun 2013 01:31:11 +1000 Subject: [PATCH 072/451] Simplify ruby*Constant syntax group matching --- syntax/ruby.vim | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/syntax/ruby.vim b/syntax/ruby.vim index e4bc98f6..3b262677 100644 --- a/syntax/ruby.vim +++ b/syntax/ruby.vim @@ -92,7 +92,7 @@ syn match rubyFloat "\%(\%(\w\|[]})\"']\s*\)\@\|::\)\@=\%(\s*(\)\@!" +syn match rubyConstant "\%(\%(^\|[^.]\)\.\_s*\)\@\%(\s*(\)\@!" syn match rubyClassVariable "@@\%(\h\|[^\x00-\x7F]\)\%(\w\|[^\x00-\x7F]\)*" display syn match rubyInstanceVariable "@\%(\h\|[^\x00-\x7F]\)\%(\w\|[^\x00-\x7F]\)*" display syn match rubyGlobalVariable "$\%(\%(\h\|[^\x00-\x7F]\)\%(\w\|[^\x00-\x7F]\)*\|-.\)" @@ -117,10 +117,8 @@ syn match rubyPredefinedVariable "$_\>" display syn match rubyPredefinedVariable "$-[0FIKadilpvw]\>" display syn match rubyPredefinedVariable "$\%(deferr\|defout\|stderr\|stdin\|stdout\)\>" display syn match rubyPredefinedVariable "$\%(DEBUG\|FILENAME\|KCODE\|LOADED_FEATURES\|LOAD_PATH\|PROGRAM_NAME\|SAFE\|VERBOSE\)\>" display -syn match rubyPredefinedConstant "\%(\%(\.\@\%(\s*(\)\@!" -syn match rubyPredefinedConstant "\%(\%(\.\@\%(\s*(\)\@!" -syn match rubyPredefinedConstant "\%(\%(\.\@\%(\s*(\)\@!" -syn match rubyPredefinedConstant "\%(\%(\.\@\%(\s*(\)\@!" +syn match rubyPredefinedConstant "\%(\%(^\|[^.]\)\.\_s*\)\@\%(\s*(\)\@!" +syn match rubyPredefinedConstant "\%(\%(^\|[^.]\)\.\_s*\)\@\%(\s*(\)\@!" " Normal Regular Expression syn region rubyRegexp matchgroup=rubyRegexpDelimiter start="\%(\%(^\|\<\%(and\|or\|while\|until\|unless\|if\|elsif\|when\|not\|then\|else\)\|[;\~=!|&(,[<>?:*+-]\)\s*\)\@<=/" end="/[iomxneus]*" skip="\\\\\|\\/" contains=@rubyRegexpSpecial fold From ab7c7e4cc3c4ac235cebcb4b2495ebdd0d67fdc0 Mon Sep 17 00:00:00 2001 From: Andrew Marshall Date: Sun, 14 Jul 2013 12:31:09 -0400 Subject: [PATCH 073/451] Highlight unicode characters in constants MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Except those which are the first letter (e.g. `Ír`), as Ruby does not recognize them as valid constants. (See also #138) --- syntax/ruby.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/syntax/ruby.vim b/syntax/ruby.vim index 3b262677..bf598389 100644 --- a/syntax/ruby.vim +++ b/syntax/ruby.vim @@ -92,7 +92,7 @@ syn match rubyFloat "\%(\%(\w\|[]})\"']\s*\)\@\%(\s*(\)\@!" +syn match rubyConstant "\%(\%(^\|[^.]\)\.\_s*\)\@\%(\s*(\)\@!" syn match rubyClassVariable "@@\%(\h\|[^\x00-\x7F]\)\%(\w\|[^\x00-\x7F]\)*" display syn match rubyInstanceVariable "@\%(\h\|[^\x00-\x7F]\)\%(\w\|[^\x00-\x7F]\)*" display syn match rubyGlobalVariable "$\%(\%(\h\|[^\x00-\x7F]\)\%(\w\|[^\x00-\x7F]\)*\|-.\)" From 082e9299d4b251046e0d5c5bd9ad3c6650252f88 Mon Sep 17 00:00:00 2001 From: Doug Kearns Date: Sun, 21 Jul 2013 16:53:55 +1000 Subject: [PATCH 074/451] Fix constant definitions after comments. These multi-line edge cases are almost impossible to find in the wild so I won't bother supporting most of them for now. Closes #164. --- syntax/ruby.vim | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/syntax/ruby.vim b/syntax/ruby.vim index 3b262677..aec98781 100644 --- a/syntax/ruby.vim +++ b/syntax/ruby.vim @@ -92,7 +92,7 @@ syn match rubyFloat "\%(\%(\w\|[]})\"']\s*\)\@\%(\s*(\)\@!" +syn match rubyConstant "\%(\%(^\|[^.]\)\.\s*\)\@\%(\s*(\)\@!" syn match rubyClassVariable "@@\%(\h\|[^\x00-\x7F]\)\%(\w\|[^\x00-\x7F]\)*" display syn match rubyInstanceVariable "@\%(\h\|[^\x00-\x7F]\)\%(\w\|[^\x00-\x7F]\)*" display syn match rubyGlobalVariable "$\%(\%(\h\|[^\x00-\x7F]\)\%(\w\|[^\x00-\x7F]\)*\|-.\)" @@ -117,8 +117,8 @@ syn match rubyPredefinedVariable "$_\>" display syn match rubyPredefinedVariable "$-[0FIKadilpvw]\>" display syn match rubyPredefinedVariable "$\%(deferr\|defout\|stderr\|stdin\|stdout\)\>" display syn match rubyPredefinedVariable "$\%(DEBUG\|FILENAME\|KCODE\|LOADED_FEATURES\|LOAD_PATH\|PROGRAM_NAME\|SAFE\|VERBOSE\)\>" display -syn match rubyPredefinedConstant "\%(\%(^\|[^.]\)\.\_s*\)\@\%(\s*(\)\@!" -syn match rubyPredefinedConstant "\%(\%(^\|[^.]\)\.\_s*\)\@\%(\s*(\)\@!" +syn match rubyPredefinedConstant "\%(\%(^\|[^.]\)\.\s*\)\@\%(\s*(\)\@!" +syn match rubyPredefinedConstant "\%(\%(^\|[^.]\)\.\s*\)\@\%(\s*(\)\@!" " Normal Regular Expression syn region rubyRegexp matchgroup=rubyRegexpDelimiter start="\%(\%(^\|\<\%(and\|or\|while\|until\|unless\|if\|elsif\|when\|not\|then\|else\)\|[;\~=!|&(,[<>?:*+-]\)\s*\)\@<=/" end="/[iomxneus]*" skip="\\\\\|\\/" contains=@rubyRegexpSpecial fold From 8d7c6c081be8289630873144826eaed0770b90a5 Mon Sep 17 00:00:00 2001 From: tek Date: Tue, 6 Aug 2013 02:47:52 +0200 Subject: [PATCH 075/451] allow Gemfile gems to be parsed and required --- autoload/rubycomplete.vim | 26 ++++++++++++++++++++++++++ doc/ft-ruby-omni.txt | 8 ++++++++ 2 files changed, 34 insertions(+) diff --git a/autoload/rubycomplete.vim b/autoload/rubycomplete.vim index e1064c8a..aff41b15 100644 --- a/autoload/rubycomplete.vim +++ b/autoload/rubycomplete.vim @@ -266,6 +266,28 @@ class VimRubyCompletion end end + def load_gems + fpath = VIM::evaluate("get(g:, 'rubycomplete_gemfile_path', 'Gemfile')") + return unless File.file?(fpath) && File.readable?(fpath) + want_bundler = VIM::evaluate("get(g:, 'rubycomplete_use_bundler')") + parse_file = !want_bundler + begin + require 'bundler' + Bundler.setup + Bundler.require + rescue Exception + parse_file = true + end + if parse_file + File.new(fpath).each_line do |line| + begin + require $1 if /\s*gem\s*['"]([^'"]+)/.match(line) + rescue Exception + end + end + end + end + def load_buffer_class(name) dprint "load_buffer_class(%s) START" % name classdef = get_buffer_entity(name, 's:GetBufferRubyClass("%s")') @@ -588,6 +610,10 @@ 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] diff --git a/doc/ft-ruby-omni.txt b/doc/ft-ruby-omni.txt index 79fa3da1..5f8fc4df 100644 --- a/doc/ft-ruby-omni.txt +++ b/doc/ft-ruby-omni.txt @@ -36,5 +36,13 @@ Notes: project. The feature is disabled by default, to enable it add > let g:rubycomplete_rails = 1 < to your vimrc + - Vim can parse a Gemfile, in case gems are being implicitly required. To + activate the feature: > + let g:rubycomplete_load_gemfile = 1 +< To specify an alternative path, use: > + let g:rubycomplete_gemfile_path = 'Gemfile.aux' +< To use Bundler.require instead of parsing the Gemfile, set: > + let g:rubycomplete_use_bundler = 1 +< vim:tw=78:sw=4:ts=8:ft=help:norl: From f11ca11cd6caff828c890e6fe058cb0dc9f84c61 Mon Sep 17 00:00:00 2001 From: Andrew Radev Date: Wed, 4 Sep 2013 22:02:01 +0200 Subject: [PATCH 076/451] Missing escape() for '*' It's escaped the first time it's used, but not the second time, causing a regex error for the string '**'. --- autoload/rubycomplete.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/autoload/rubycomplete.vim b/autoload/rubycomplete.vim index e1064c8a..5a0dd9af 100644 --- a/autoload/rubycomplete.vim +++ b/autoload/rubycomplete.vim @@ -149,7 +149,7 @@ 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 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) From 85624725cba5866bb6a49a58aad4b2231fb9b950 Mon Sep 17 00:00:00 2001 From: Andrew Radev Date: Fri, 6 Sep 2013 20:50:25 +0200 Subject: [PATCH 077/451] Another missing "*" escape --- autoload/rubycomplete.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/autoload/rubycomplete.vim b/autoload/rubycomplete.vim index 5a0dd9af..00f26167 100644 --- a/autoload/rubycomplete.vim +++ b/autoload/rubycomplete.vim @@ -93,7 +93,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' ) From 2470dc83f649949480557bc700e9f9c063a76e7b Mon Sep 17 00:00:00 2001 From: Andrew Radev Date: Fri, 6 Sep 2013 21:09:34 +0200 Subject: [PATCH 078/451] Workaround for Vim 7.4's HTML indent --- indent/eruby.vim | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/indent/eruby.vim b/indent/eruby.vim index 80cab700..19109ceb 100644 --- a/indent/eruby.vim +++ b/indent/eruby.vim @@ -52,6 +52,15 @@ function! GetErubyIndent(...) let ind = GetRubyIndent(v:lnum) else exe "let ind = ".b:eruby_subtype_indentexpr + + " Workaround for Andy Wokula's HTML indent + if b:eruby_subtype_indentexpr =~# '^HtmlIndent(' + \ && exists('b:indent') + \ && type(b:indent) == type({}) + \ && has_key(b:indent, 'lnum') + " Force HTML indent to not keep state + let b:indent.lnum = -1 + endif endif let lnum = prevnonblank(v:lnum-1) let line = getline(lnum) From 2c8fa01a6e8bc6ae035523138438997e8fd50af3 Mon Sep 17 00:00:00 2001 From: Andrew Radev Date: Wed, 11 Sep 2013 21:48:27 +0200 Subject: [PATCH 079/451] Add InterpolationDelimiter to the list of "string or delimiter" Unsure if this won't break anything else :/. --- indent/ruby.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indent/ruby.vim b/indent/ruby.vim index 095b3a43..8189a725 100644 --- a/indent/ruby.vim +++ b/indent/ruby.vim @@ -34,7 +34,7 @@ set cpo&vim " Regex of syntax group names that are or delimit strings/symbols or are comments. let s:syng_strcom = '\' + \ '\|Interpolation\|InterpolationDelimiter\|NoInterpolation\|Comment\|Documentation\)\>' " Regex of syntax group names that are strings. let s:syng_string = From f3b1fc6e561901d2c2feb1f7fccb7a3d4142d43d Mon Sep 17 00:00:00 2001 From: Andrew Radev Date: Wed, 11 Sep 2013 21:43:52 +0200 Subject: [PATCH 080/451] WIP Retrying s:Match function The s:Match function tries to find a pattern, but if the found one is in a string or comment, it fails. However, it's possible that beyond the string, there's a comma or something else that *also* fits the pattern and will not be found. There seems to have been an attempt to fix this issue by matching in reverse with the unused `s:MatchLast` function, but it's not really used anywhere, so it was removed. The current implementation tries to match the same pattern on the rest of the string after failing once. Tests and documentation are needed. There may also be issues with multibyte, not sure. --- indent/ruby.vim | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/indent/ruby.vim b/indent/ruby.vim index 8189a725..ea2b862b 100644 --- a/indent/ruby.vim +++ b/indent/ruby.vim @@ -299,18 +299,20 @@ function s:ExtraBrackets(lnum) endfunction function s:Match(lnum, regex) - let col = match(getline(a:lnum), '\C'.a:regex) + 1 - return col > 0 && !s:IsInStringOrComment(a:lnum, col) ? col : 0 -endfunction + let line = getline(a:lnum) + let offset = match(line, '\C'.a:regex) + let col = offset + 1 -function s:MatchLast(lnum, regex) - let line = getline(a:lnum) - let col = match(line, '.*\zs' . a:regex) - while col != -1 && s:IsInStringOrComment(a:lnum, col) - let line = strpart(line, 0, col) - let col = match(line, '.*' . a:regex) + while offset > -1 && s:IsInStringOrComment(a:lnum, col) + let offset = match(line, '\C'.a:regex, offset + 1) + let col = offset + 1 endwhile - return col + 1 + + if offset > -1 + return col + else + return 0 + endif endfunction " 3. GetRubyIndent Function {{{1 From b76efd175af2a220beffceaf45a66bcc92869064 Mon Sep 17 00:00:00 2001 From: Andrew Radev Date: Wed, 11 Sep 2013 21:51:44 +0200 Subject: [PATCH 081/451] Don't match "line", match "lnum" How did this ever work? --- indent/ruby.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indent/ruby.vim b/indent/ruby.vim index ea2b862b..c669a1d5 100644 --- a/indent/ruby.vim +++ b/indent/ruby.vim @@ -175,7 +175,7 @@ function s:GetMSL(lnum) " something " return msl - elseif s:Match(line, s:non_bracket_continuation_regex) && + elseif s:Match(lnum, s:non_bracket_continuation_regex) && \ s:Match(msl, s:non_bracket_continuation_regex) " If the current line is a non-bracket continuation and so is the " previous one, keep its indent and continue looking for an MSL. From 76384e121dde94369e4357ab58d897f1b7c23cec Mon Sep 17 00:00:00 2001 From: Andrew Radev Date: Thu, 3 Oct 2013 09:27:19 +0200 Subject: [PATCH 082/451] Tests for string interpolation problem --- spec/indent/continuations_spec.rb | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/spec/indent/continuations_spec.rb b/spec/indent/continuations_spec.rb index b24d0f89..49b0afcf 100644 --- a/spec/indent/continuations_spec.rb +++ b/spec/indent/continuations_spec.rb @@ -68,11 +68,32 @@ end specify "string interpolation" do - # See https://github.com/vim-ruby/vim-ruby/issues/93 for details + # For details, see: + # + # https://github.com/vim-ruby/vim-ruby/issues/93 + # https://github.com/vim-ruby/vim-ruby/issues/160 + # assert_correct_indenting <<-EOF command = %|\#{file}| settings.log.info("Returning: \#{command}") EOF + + assert_correct_indenting <<-EOF + { + thing: "[\#{}]", + thong: "b" + } + EOF + + assert_correct_indenting <<-EOF + { + a: "(\#{a})", + b: "(\#{b})", + c: "(c)", + d: "(d)", + e: "(e)", + } + EOF end specify "closing bracket not on its own line" do From 934f15781095e367137794ddcadc79d7ae5ff3b3 Mon Sep 17 00:00:00 2001 From: Andrew Radev Date: Sun, 13 Oct 2013 16:47:40 +0200 Subject: [PATCH 083/451] Update vimrunner and ensure consistent buffer defaults --- Gemfile.lock | 2 +- spec/indent/blocks_spec.rb | 4 ++-- spec/spec_helper.rb | 45 +++++++++++++------------------------- 3 files changed, 18 insertions(+), 33 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 66a9ec64..b8deb34f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -10,7 +10,7 @@ GEM rspec-expectations (2.11.2) diff-lcs (~> 1.1.3) rspec-mocks (2.11.2) - vimrunner (0.1.1) + vimrunner (0.3.0) PLATFORMS ruby diff --git a/spec/indent/blocks_spec.rb b/spec/indent/blocks_spec.rb index 4903c733..881d6e2d 100644 --- a/spec/indent/blocks_spec.rb +++ b/spec/indent/blocks_spec.rb @@ -34,14 +34,14 @@ def foo end specify "case-insensitive matching" do - @vim.set 'ignorecase' + vim.set 'ignorecase' assert_correct_indenting <<-EOF module X Class.new do end end EOF - @vim.set 'ignorecase&' + vim.set 'ignorecase&' end specify "blocks with tuple arguments" do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index a11bb6f1..da7841f8 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,7 +1,17 @@ -require 'tmpdir' require 'vimrunner' +require 'vimrunner/rspec' + +Vimrunner::RSpec.configure do |config| + config.reuse_server = true + + config.start_vim do + vim = Vimrunner.start_gvim + vim.prepend_runtimepath(File.expand_path('../..', __FILE__)) + vim.set 'expandtab' + vim.set 'shiftwidth', 2 + vim + end -module Support def assert_correct_indenting(string) whitespace = string.scan(/^\s*/).first string = string.split("\n").map { |line| line.gsub /^#{whitespace}/, '' }.join("\n").strip @@ -10,35 +20,10 @@ def assert_correct_indenting(string) f.write string end - @vim.edit 'test.rb' - @vim.normal 'gg=G' - @vim.write + vim.edit 'test.rb' + vim.normal 'gg=G' + vim.write IO.read('test.rb').strip.should eq string end end - -RSpec.configure do |config| - include Support - - config.before(:suite) do - VIM = Vimrunner.start_gvim - VIM.prepend_runtimepath(File.expand_path('../..', __FILE__)) - end - - config.after(:suite) do - VIM.kill - end - - config.around(:each) do |example| - @vim = VIM - - # cd into a temporary directory for every example. - Dir.mktmpdir do |dir| - Dir.chdir(dir) do - @vim.command("cd #{dir}") - example.call - end - end - end -end From 244ab1989fe27da7a87cc3daf2baa96b87fe3d17 Mon Sep 17 00:00:00 2001 From: Andrew Radev Date: Sat, 19 Oct 2013 12:35:29 +0200 Subject: [PATCH 084/451] Optionally indent private/protected methods --- indent/ruby.vim | 50 ++++++++++++++++++++++++ spec/indent/private_protected_spec.rb | 56 +++++++++++++++++++++++++++ 2 files changed, 106 insertions(+) create mode 100644 spec/indent/private_protected_spec.rb diff --git a/indent/ruby.vim b/indent/ruby.vim index c669a1d5..868b8fb6 100644 --- a/indent/ruby.vim +++ b/indent/ruby.vim @@ -13,6 +13,11 @@ if exists("b:did_indent") endif let b:did_indent = 1 +if !exists('g:ruby_indent_private_protected_style') + " Possible values: "normal", "indent" + let g:ruby_indent_private_protected_style = 'normal' +endif + setlocal nosmartindent " Now, set up our indentation expression and keys that trigger it. @@ -89,9 +94,17 @@ let s:continuation_regex = " Regex that defines bracket continuations let s:bracket_continuation_regex = '%\@>\|:\s\)\s*\zs' . + \ '\<\%(module\|class\):\@!\>' + " Regex that defines the first part of a splat pattern let s:splat_regex = '[[,(]\s*\*\s*\%(#.*\)\=$' +" Regex that describes a private/protected access modifier +let s:private_protected_regex = '\C^\s*\%(private\|protected\)\s*\%(#.*\)\=$' + " Regex that defines blocks. " " Note that there's a slight problem with this regex and s:continuation_regex. @@ -315,6 +328,25 @@ function s:Match(lnum, regex) endif endfunction +" Search for a pattern match with search(), ignoring strings or comments. +" +" Note that you should NOT use the "n" or "c" flags here, since it may loop +" indefinitely. You should use the "W" flag for the same reason. +" +function s:SearchCode(pattern, flags) + let saved_position = getpos('.') + + let [lnum, col] = searchpos(a:pattern, a:flags) + + while lnum > 0 && s:IsInStringOrComment(lnum, col) + let [lnum, col] = searchpos(a:pattern, a:flags) + endwhile + + call setpos('.', saved_position) + + return lnum +endfunction + " 3. GetRubyIndent Function {{{1 " ========================= @@ -335,6 +367,17 @@ function GetRubyIndent(...) let line = getline(clnum) let ind = -1 + if g:ruby_indent_private_protected_style == 'indent' + " If this line is a private/protected keyword, align according to the + " closest class declaration. + if s:Match(clnum, s:private_protected_regex) + let class_line = s:SearchCode(s:class_regex, 'Wb') + if class_line > 0 + return indent(class_line) + &sw + endif + endif + endif + " If we got a closing bracket on an empty line, find its match and indent " according to it. For parentheses we indent to its column - 1, for the " others we indent to the containing line's MSL's level. Return -1 if fail. @@ -411,6 +454,13 @@ function GetRubyIndent(...) let line = getline(lnum) let ind = indent(lnum) + if g:ruby_indent_private_protected_style == 'indent' + " If the previous line was a private/protected keyword, add a level of indent + if s:Match(lnum, s:private_protected_regex) + return indent(s:GetMSL(lnum)) + &sw + endif + endif + " If the previous line ended with a block opening, add a level of indent. if s:Match(lnum, s:block_regex) return indent(s:GetMSL(lnum)) + &sw diff --git a/spec/indent/private_protected_spec.rb b/spec/indent/private_protected_spec.rb new file mode 100644 index 00000000..91740569 --- /dev/null +++ b/spec/indent/private_protected_spec.rb @@ -0,0 +1,56 @@ +require 'spec_helper' + +describe "Indenting" do + specify "default public/private indenting" do + assert_correct_indenting <<-EOF + class One + def two + end + + protected + + def three + end + + private + + def four + end + end + EOF + end + + specify "indented public/private" do + vim.command 'let g:ruby_indent_private_protected_style = "indent"' + + assert_correct_indenting <<-EOF + class One + def two + end + + protected + + def three + end + + private + + def four + end + end + EOF + + assert_correct_indenting <<-EOF + class One + def two + end + + private :two + protected :two + + def three + end + end + EOF + end +end From b5ead62081d67c0ff4121679e3cd23f12bd7a074 Mon Sep 17 00:00:00 2001 From: Andrew Radev Date: Sat, 19 Oct 2013 12:52:40 +0200 Subject: [PATCH 085/451] Also add an "outdent" option Not requested at this time, but easy enough to implement. --- indent/ruby.vim | 15 ++++++++--- spec/indent/private_protected_spec.rb | 38 +++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 4 deletions(-) diff --git a/indent/ruby.vim b/indent/ruby.vim index 868b8fb6..c8c08115 100644 --- a/indent/ruby.vim +++ b/indent/ruby.vim @@ -14,7 +14,7 @@ endif let b:did_indent = 1 if !exists('g:ruby_indent_private_protected_style') - " Possible values: "normal", "indent" + " Possible values: "normal", "indent", "outdent" let g:ruby_indent_private_protected_style = 'normal' endif @@ -367,15 +367,22 @@ function GetRubyIndent(...) let line = getline(clnum) let ind = -1 + " If this line is a private/protected keyword, align according to the + " closest class declaration. if g:ruby_indent_private_protected_style == 'indent' - " If this line is a private/protected keyword, align according to the - " closest class declaration. if s:Match(clnum, s:private_protected_regex) let class_line = s:SearchCode(s:class_regex, 'Wb') if class_line > 0 return indent(class_line) + &sw endif endif + elseif g:ruby_indent_private_protected_style == 'outdent' + if s:Match(clnum, s:private_protected_regex) + let class_line = s:SearchCode(s:class_regex, 'Wb') + if class_line > 0 + return indent(class_line) + endif + endif endif " If we got a closing bracket on an empty line, find its match and indent @@ -454,7 +461,7 @@ function GetRubyIndent(...) let line = getline(lnum) let ind = indent(lnum) - if g:ruby_indent_private_protected_style == 'indent' + if g:ruby_indent_private_protected_style == 'indent' || g:ruby_indent_private_protected_style == 'outdent' " If the previous line was a private/protected keyword, add a level of indent if s:Match(lnum, s:private_protected_regex) return indent(s:GetMSL(lnum)) + &sw diff --git a/spec/indent/private_protected_spec.rb b/spec/indent/private_protected_spec.rb index 91740569..e70d9610 100644 --- a/spec/indent/private_protected_spec.rb +++ b/spec/indent/private_protected_spec.rb @@ -1,6 +1,10 @@ require 'spec_helper' describe "Indenting" do + after :each do + vim.command 'let g:ruby_indent_private_protected_style = "normal"' + end + specify "default public/private indenting" do assert_correct_indenting <<-EOF class One @@ -53,4 +57,38 @@ def three end EOF end + + specify "outdented public/private" do + vim.command 'let g:ruby_indent_private_protected_style = "outdent"' + + assert_correct_indenting <<-EOF + class One + def two + end + + protected + + def three + end + + private + + def four + end + end + EOF + + assert_correct_indenting <<-EOF + class One + def two + end + + private :two + protected :two + + def three + end + end + EOF + end end From aaf5b97d96103cb1b53ab8cecd85f8e0d6a24eec Mon Sep 17 00:00:00 2001 From: Andrew Radev Date: Tue, 22 Oct 2013 12:28:20 +0200 Subject: [PATCH 086/451] Indent private/protected while typing --- indent/ruby.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indent/ruby.vim b/indent/ruby.vim index c8c08115..2f1379c8 100644 --- a/indent/ruby.vim +++ b/indent/ruby.vim @@ -23,7 +23,7 @@ setlocal nosmartindent " Now, set up our indentation expression and keys that trigger it. setlocal indentexpr=GetRubyIndent(v:lnum) setlocal indentkeys=0{,0},0),0],!^F,o,O,e -setlocal indentkeys+==end,=else,=elsif,=when,=ensure,=rescue,==begin,==end +setlocal indentkeys+==end,=else,=elsif,=when,=ensure,=rescue,==begin,==end,=private,=protected " Only define the function once. if exists("*GetRubyIndent") From a7940705de35db73122288ad2e324ea7d421e4ac Mon Sep 17 00:00:00 2001 From: darrenli Date: Thu, 24 Oct 2013 00:00:42 -0700 Subject: [PATCH 087/451] Update indentkeys to support non-outdented 'private' or 'protected'. --- indent/ruby.vim | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/indent/ruby.vim b/indent/ruby.vim index 2f1379c8..3375fd82 100644 --- a/indent/ruby.vim +++ b/indent/ruby.vim @@ -23,7 +23,8 @@ setlocal nosmartindent " Now, set up our indentation expression and keys that trigger it. setlocal indentexpr=GetRubyIndent(v:lnum) setlocal indentkeys=0{,0},0),0],!^F,o,O,e -setlocal indentkeys+==end,=else,=elsif,=when,=ensure,=rescue,==begin,==end,=private,=protected +setlocal indentkeys+==end,=else,=elsif,=when,=ensure,=rescue,==begin,==end +setlocal indentkeys+==private,=protected,:=private,:=protected " Only define the function once. if exists("*GetRubyIndent") From addba7e0a3eb568aa2e89590c1bd2d54b00cc22a Mon Sep 17 00:00:00 2001 From: Andrew Radev Date: Sun, 27 Oct 2013 10:14:02 +0100 Subject: [PATCH 088/451] Locate class definition more reliably In theory, anyway. --- indent/ruby.vim | 33 ++++++++++++--------------- spec/indent/private_protected_spec.rb | 30 ++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 19 deletions(-) diff --git a/indent/ruby.vim b/indent/ruby.vim index 3375fd82..97fcb883 100644 --- a/indent/ruby.vim +++ b/indent/ruby.vim @@ -95,11 +95,6 @@ let s:continuation_regex = " Regex that defines bracket continuations let s:bracket_continuation_regex = '%\@>\|:\s\)\s*\zs' . - \ '\<\%(module\|class\):\@!\>' - " Regex that defines the first part of a splat pattern let s:splat_regex = '[[,(]\s*\*\s*\%(#.*\)\=$' @@ -329,23 +324,23 @@ function s:Match(lnum, regex) endif endfunction -" Search for a pattern match with search(), ignoring strings or comments. -" -" Note that you should NOT use the "n" or "c" flags here, since it may loop -" indefinitely. You should use the "W" flag for the same reason. +" Locates the containing class/module's definition line, ignoring nested classes +" along the way. " -function s:SearchCode(pattern, flags) +function! s:FindContainingClass() let saved_position = getpos('.') - let [lnum, col] = searchpos(a:pattern, a:flags) - - while lnum > 0 && s:IsInStringOrComment(lnum, col) - let [lnum, col] = searchpos(a:pattern, a:flags) - endwhile + while searchpair(s:end_start_regex, s:end_middle_regex, s:end_end_regex, 'bW', + \ s:end_skip_expr) > 0 + if expand('') =~# '\' + let found_lnum = line('.') + call setpos('.', saved_position) + return found_lnum + endif + endif call setpos('.', saved_position) - - return lnum + return 0 endfunction " 3. GetRubyIndent Function {{{1 @@ -372,14 +367,14 @@ function GetRubyIndent(...) " closest class declaration. if g:ruby_indent_private_protected_style == 'indent' if s:Match(clnum, s:private_protected_regex) - let class_line = s:SearchCode(s:class_regex, 'Wb') + let class_line = s:FindContainingClass() if class_line > 0 return indent(class_line) + &sw endif endif elseif g:ruby_indent_private_protected_style == 'outdent' if s:Match(clnum, s:private_protected_regex) - let class_line = s:SearchCode(s:class_regex, 'Wb') + let class_line = s:FindContainingClass() if class_line > 0 return indent(class_line) endif diff --git a/spec/indent/private_protected_spec.rb b/spec/indent/private_protected_spec.rb index e70d9610..d716425c 100644 --- a/spec/indent/private_protected_spec.rb +++ b/spec/indent/private_protected_spec.rb @@ -44,6 +44,21 @@ def four end EOF + assert_correct_indenting <<-EOF + class One + def two + end + + class Two + end + + private + + def four + end + end + EOF + assert_correct_indenting <<-EOF class One def two @@ -78,6 +93,21 @@ def four end EOF + assert_correct_indenting <<-EOF + class One + def two + end + + class Two + end + + private + + def four + end + end + EOF + assert_correct_indenting <<-EOF class One def two From 859183e7943104086d670f9f286dfaa70f6333b7 Mon Sep 17 00:00:00 2001 From: darrenli Date: Thu, 31 Oct 2013 23:36:14 -0700 Subject: [PATCH 089/451] Add support for the public access modifier keyword. --- doc/ft-ruby-syntax.txt | 44 +++++++ indent/ruby.vim | 40 +++--- spec/indent/indent_access_modifier_spec.rb | 137 +++++++++++++++++++++ spec/indent/private_protected_spec.rb | 124 ------------------- 4 files changed, 206 insertions(+), 139 deletions(-) create mode 100644 spec/indent/indent_access_modifier_spec.rb delete mode 100644 spec/indent/private_protected_spec.rb diff --git a/doc/ft-ruby-syntax.txt b/doc/ft-ruby-syntax.txt index 482ebefc..9c8f84a2 100644 --- a/doc/ft-ruby-syntax.txt +++ b/doc/ft-ruby-syntax.txt @@ -6,6 +6,7 @@ There are a number of options to the Ruby syntax highlighting. 2. Whitespace errors |ruby_space_errors| 3. Folds |ruby_fold| 4. Reducing expensive operations |ruby_no_expensive| |ruby_minlines| +5. Reducing expensive operations |ruby_indent_access_modifier_style| 1. Ruby operators *ruby_operators* @@ -61,4 +62,47 @@ 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. +5. Access modifier indentation *ruby_indent_access_modifier_style* + +Different access modifier indentation styles can be used by setting: > + + :let g:ruby_indent_access_modifier_style + :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 + vim:tw=78:sw=4:ts=8:ft=help:norl: diff --git a/indent/ruby.vim b/indent/ruby.vim index 97fcb883..a0483d68 100644 --- a/indent/ruby.vim +++ b/indent/ruby.vim @@ -13,18 +13,18 @@ if exists("b:did_indent") endif let b:did_indent = 1 -if !exists('g:ruby_indent_private_protected_style') +if !exists('g:ruby_indent_access_modifier_style') " Possible values: "normal", "indent", "outdent" - let g:ruby_indent_private_protected_style = 'normal' + let g:ruby_indent_access_modifier_style = 'normal' endif setlocal nosmartindent " Now, set up our indentation expression and keys that trigger it. setlocal indentexpr=GetRubyIndent(v:lnum) -setlocal indentkeys=0{,0},0),0],!^F,o,O,e +setlocal indentkeys=0{,0},0),0],!^F,o,O,e,: setlocal indentkeys+==end,=else,=elsif,=when,=ensure,=rescue,==begin,==end -setlocal indentkeys+==private,=protected,:=private,:=protected +setlocal indentkeys+==private,=protected,=public " Only define the function once. if exists("*GetRubyIndent") @@ -98,8 +98,11 @@ let s:bracket_continuation_regex = '%\@ 0 return indent(class_line) + &sw endif endif - elseif g:ruby_indent_private_protected_style == 'outdent' - if s:Match(clnum, s:private_protected_regex) + elseif g:ruby_indent_access_modifier_style == 'outdent' + if s:Match(clnum, s:access_modifier_regex) let class_line = s:FindContainingClass() if class_line > 0 return indent(class_line) @@ -457,9 +460,16 @@ function GetRubyIndent(...) let line = getline(lnum) let ind = indent(lnum) - if g:ruby_indent_private_protected_style == 'indent' || g:ruby_indent_private_protected_style == 'outdent' - " If the previous line was a private/protected keyword, add a level of indent - if s:Match(lnum, s:private_protected_regex) + if g:ruby_indent_access_modifier_style == 'indent' + " If the previous line was a private/protected keyword, add a + " level of indent + if s:Match(lnum, s:indent_access_modifier_regex) + return indent(s:GetMSL(lnum)) + &sw + endif + elseif g:ruby_indent_access_modifier_style == 'outdent' + " If the previous line was a private/protected/public keyword, remove + " a level of indent + if s:Match(lnum, s:access_modifier_regex) return indent(s:GetMSL(lnum)) + &sw endif endif diff --git a/spec/indent/indent_access_modifier_spec.rb b/spec/indent/indent_access_modifier_spec.rb new file mode 100644 index 00000000..56412035 --- /dev/null +++ b/spec/indent/indent_access_modifier_spec.rb @@ -0,0 +1,137 @@ +require 'spec_helper' + +describe "Indenting" do + after :each do + vim.command 'let g:ruby_indent_access_modifier_style = "normal"' + end + + specify "default indented access modifiers" do + assert_correct_indenting <<-EOF + class OuterClass + + private :method + protected :method + def method; end + protected + def method; end + private + def method; end + public + def method; end + + class InnerClass + + private :method + protected :method + def method; end + protected + def method; end + private + def method; end + public + def method; end + + end + + private :method + protected :method + def method; end + protected + def method; end + private + def method; end + public + def method; end + + end + EOF + end + + specify "indented access modifiers" do + vim.command 'let g:ruby_indent_access_modifier_style = "indent"' + + assert_correct_indenting <<-EOF + class OuterClass + + private :method + protected :method + def method; end + protected + def method; end + private + def method; end + public + def method; end + + class InnerClass + + private :method + protected :method + def method; end + protected + def method; end + private + def method; end + public + def method; end + + end + + private :method + protected :method + def method; end + protected + def method; end + private + def method; end + public + def method; end + + end + EOF + end + + specify "outdented access modifiers" do + vim.command 'let g:ruby_indent_access_modifier_style = "outdent"' + + assert_correct_indenting <<-EOF + class OuterClass + + private :method + protected :method + def method; end + protected + def method; end + private + def method; end + public + def method; end + + class InnerClass + + private :method + protected :method + def method; end + protected + def method; end + private + def method; end + public + def method; end + + end + + private :method + protected :method + def method; end + protected + def method; end + private + def method; end + public + def method; end + + end + EOF + end +end diff --git a/spec/indent/private_protected_spec.rb b/spec/indent/private_protected_spec.rb deleted file mode 100644 index d716425c..00000000 --- a/spec/indent/private_protected_spec.rb +++ /dev/null @@ -1,124 +0,0 @@ -require 'spec_helper' - -describe "Indenting" do - after :each do - vim.command 'let g:ruby_indent_private_protected_style = "normal"' - end - - specify "default public/private indenting" do - assert_correct_indenting <<-EOF - class One - def two - end - - protected - - def three - end - - private - - def four - end - end - EOF - end - - specify "indented public/private" do - vim.command 'let g:ruby_indent_private_protected_style = "indent"' - - assert_correct_indenting <<-EOF - class One - def two - end - - protected - - def three - end - - private - - def four - end - end - EOF - - assert_correct_indenting <<-EOF - class One - def two - end - - class Two - end - - private - - def four - end - end - EOF - - assert_correct_indenting <<-EOF - class One - def two - end - - private :two - protected :two - - def three - end - end - EOF - end - - specify "outdented public/private" do - vim.command 'let g:ruby_indent_private_protected_style = "outdent"' - - assert_correct_indenting <<-EOF - class One - def two - end - - protected - - def three - end - - private - - def four - end - end - EOF - - assert_correct_indenting <<-EOF - class One - def two - end - - class Two - end - - private - - def four - end - end - EOF - - assert_correct_indenting <<-EOF - class One - def two - end - - private :two - protected :two - - def three - end - end - EOF - end -end From c277b5bd6532718f80cd8ab8c1072f6bb84f8e69 Mon Sep 17 00:00:00 2001 From: darrenli Date: Sat, 2 Nov 2013 20:20:22 -0700 Subject: [PATCH 090/451] Update documentation --- doc/ft-ruby-syntax.txt | 44 ------------------------------------- doc/vim-ruby.txt | 50 ++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 48 insertions(+), 46 deletions(-) diff --git a/doc/ft-ruby-syntax.txt b/doc/ft-ruby-syntax.txt index 9c8f84a2..482ebefc 100644 --- a/doc/ft-ruby-syntax.txt +++ b/doc/ft-ruby-syntax.txt @@ -6,7 +6,6 @@ There are a number of options to the Ruby syntax highlighting. 2. Whitespace errors |ruby_space_errors| 3. Folds |ruby_fold| 4. Reducing expensive operations |ruby_no_expensive| |ruby_minlines| -5. Reducing expensive operations |ruby_indent_access_modifier_style| 1. Ruby operators *ruby_operators* @@ -62,47 +61,4 @@ 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. -5. Access modifier indentation *ruby_indent_access_modifier_style* - -Different access modifier indentation styles can be used by setting: > - - :let g:ruby_indent_access_modifier_style - :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 - vim:tw=78:sw=4:ts=8:ft=help:norl: diff --git a/doc/vim-ruby.txt b/doc/vim-ruby.txt index dba015e1..48964cfb 100644 --- a/doc/vim-ruby.txt +++ b/doc/vim-ruby.txt @@ -1,7 +1,9 @@ *vim-ruby.txt* -1. Ruby motions |ruby-motion| -2. Ruby text objects |ruby-text-objects| +1. Ruby motions |ruby-motion| +2. Ruby text objects |ruby-text-objects| +3. Access modifier indentation |ruby-text-objects| + ============================================================================== 1. Ruby motions *ruby-motion* @@ -58,4 +60,48 @@ aM "a class", select from "class" until matching "end" iM "inner class", select contents of "class"/"end" block, excluding the "class" and "end" themselves. +============================================================================== +3. Access modifier indentation *ruby-motion* + +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 + vim:tw=78:sw=4:ts=8:ft=help:norl: From d4132ef56a34217fbb6968952d2717d7011dab1f Mon Sep 17 00:00:00 2001 From: Andrew Radev Date: Sun, 3 Nov 2013 12:10:02 +0100 Subject: [PATCH 091/451] Minor documentation fixes and adjustments --- doc/vim-ruby.txt | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/doc/vim-ruby.txt b/doc/vim-ruby.txt index 48964cfb..8509d9aa 100644 --- a/doc/vim-ruby.txt +++ b/doc/vim-ruby.txt @@ -2,7 +2,7 @@ 1. Ruby motions |ruby-motion| 2. Ruby text objects |ruby-text-objects| -3. Access modifier indentation |ruby-text-objects| +3. Access modifier indentation |ruby-access-modifier-indentation| ============================================================================== @@ -61,7 +61,8 @@ iM "inner class", select contents of "class"/"end" block, excluding the "class" and "end" themselves. ============================================================================== -3. Access modifier indentation *ruby-motion* +3. Access modifier indentation *ruby-access-modifier-indentation* + *g:ruby_indent_access_modifier_style* Different access modifier indentation styles can be used by setting: > @@ -69,8 +70,10 @@ Different access modifier indentation styles can be used by setting: > :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': +By default, the "normal" access modifier style is used. + +Access modifier style "normal": +> class Indent private :method protected :method @@ -81,7 +84,9 @@ Access modifier style 'normal': public def method; end end -Access modifier style 'indent': +< +Access modifier style "indent": +> class Indent private :method protected :method @@ -92,7 +97,9 @@ Access modifier style 'indent': public def method; end end -Access modifier style 'outdent': +< +Access modifier style "outdent": +> class Indent private :method protected :method @@ -103,5 +110,6 @@ Access modifier style 'outdent': public def method; end end +< vim:tw=78:sw=4:ts=8:ft=help:norl: From abe527c3b583d4b11f1a87d29eb9752e062d7459 Mon Sep 17 00:00:00 2001 From: Andrew Radev Date: Sun, 3 Nov 2013 12:14:46 +0100 Subject: [PATCH 092/451] Remove redundant s:GetMSL() In the case of an access modifier, there shouldn't be the need to find an MSL, since the line itself couldn't be a part of a continuation. --- indent/ruby.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/indent/ruby.vim b/indent/ruby.vim index a0483d68..a53c92d4 100644 --- a/indent/ruby.vim +++ b/indent/ruby.vim @@ -464,13 +464,13 @@ function GetRubyIndent(...) " If the previous line was a private/protected keyword, add a " level of indent if s:Match(lnum, s:indent_access_modifier_regex) - return indent(s:GetMSL(lnum)) + &sw + return indent(lnum) + &sw endif elseif g:ruby_indent_access_modifier_style == 'outdent' " If the previous line was a private/protected/public keyword, remove " a level of indent if s:Match(lnum, s:access_modifier_regex) - return indent(s:GetMSL(lnum)) + &sw + return indent(lnum) + &sw endif endif From b9fc8a2f2e768701c52d77ef1e6f351184a7985a Mon Sep 17 00:00:00 2001 From: Andrew Radev Date: Sun, 3 Nov 2013 12:18:00 +0100 Subject: [PATCH 093/451] Minor doc tweaks --- indent/ruby.vim | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/indent/ruby.vim b/indent/ruby.vim index a53c92d4..89a430c4 100644 --- a/indent/ruby.vim +++ b/indent/ruby.vim @@ -462,13 +462,13 @@ function GetRubyIndent(...) if g:ruby_indent_access_modifier_style == 'indent' " If the previous line was a private/protected keyword, add a - " level of indent + " level of indent. if s:Match(lnum, s:indent_access_modifier_regex) return indent(lnum) + &sw endif elseif g:ruby_indent_access_modifier_style == 'outdent' - " If the previous line was a private/protected/public keyword, remove - " a level of indent + " If the previous line was a private/protected/public keyword, add + " a level of indent, since the keyword has been out-dented. if s:Match(lnum, s:access_modifier_regex) return indent(lnum) + &sw endif From 89e46f380177c7e6bf53e84f1e4c56d8e8a2d431 Mon Sep 17 00:00:00 2001 From: Andrew Radev Date: Mon, 6 Jan 2014 21:29:44 +0100 Subject: [PATCH 094/451] Special rules for `def` as an indent keyword See https://github.com/vim-ruby/vim-ruby/issues/190 Ruby 2.1 makes method definitions return the method name as a symbol. This means that you could prefix the `def` line with a `private` and it would make the method private upon definition. Technically, any method call could be placed before the `def`, but that's no different than before. The private/protected use case seems like the most likely one, so this is what we'll handle for now. If it gets popular to use different class-level methods for method definitions, we could put a \k\+ instead. --- indent/ruby.vim | 14 ++++++++------ spec/indent/method_definitions_spec.rb | 16 ++++++++++++++++ 2 files changed, 24 insertions(+), 6 deletions(-) create mode 100644 spec/indent/method_definitions_spec.rb diff --git a/indent/ruby.vim b/indent/ruby.vim index 89a430c4..cc5e5ba7 100644 --- a/indent/ruby.vim +++ b/indent/ruby.vim @@ -55,9 +55,10 @@ let s:skip_expr = \ "synIDattr(synID(line('.'),col('.'),1),'name') =~ '".s:syng_strcom."'" " Regex used for words that, at the start of a line, add a level of indent. -let s:ruby_indent_keywords = '^\s*\zs\<\%(module\|class\|def\|if\|for' . - \ '\|while\|until\|else\|elsif\|case\|when\|unless\|begin\|ensure' . - \ '\|rescue\):\@!\>' . +let s:ruby_indent_keywords = + \ '^\s*\zs\<\%(module\|class\|if\|for' . + \ '\|while\|until\|else\|elsif\|case\|when\|unless\|begin\|ensure\|rescue' . + \ '\|\%(public\|protected\|private\)\=\s*def\):\@!\>' . \ '\|\%([=,*/%+-]\|<<\|>>\|:\s\)\s*\zs' . \ '\<\%(if\|for\|while\|until\|case\|unless\|begin\):\@!\>' @@ -70,7 +71,8 @@ let s:ruby_deindent_keywords = " TODO: the do here should be restricted somewhat (only at end of line)? let s:end_start_regex = \ '\C\%(^\s*\|[=,*/%+\-|;{]\|<<\|>>\|:\s\)\s*\zs' . - \ '\<\%(module\|class\|def\|if\|for\|while\|until\|case\|unless\|begin\):\@!\>' . + \ '\<\%(module\|class\|if\|for\|while\|until\|case\|unless\|begin' . + \ '\|\%(public\|protected\|private\)\=\s*def\):\@!\>' . \ '\|\%(^\|[^.:@$]\)\@<=\' " Regex that defines the middle-match for the 'end' keyword. @@ -99,10 +101,10 @@ let s:bracket_continuation_regex = '%\@ Date: Mon, 6 Jan 2014 21:50:51 +0100 Subject: [PATCH 095/451] Leading dots for method calls See https://github.com/vim-ruby/vim-ruby/issues/189 --- indent/ruby.vim | 22 ++++++++++++++++++++-- spec/indent/continuations_spec.rb | 16 ++++++++++++++++ 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/indent/ruby.vim b/indent/ruby.vim index cc5e5ba7..2a571bd2 100644 --- a/indent/ruby.vim +++ b/indent/ruby.vim @@ -22,7 +22,7 @@ setlocal nosmartindent " Now, set up our indentation expression and keys that trigger it. setlocal indentexpr=GetRubyIndent(v:lnum) -setlocal indentkeys=0{,0},0),0],!^F,o,O,e,: +setlocal indentkeys=0{,0},0),0],!^F,o,O,e,:,. setlocal indentkeys+==end,=else,=elsif,=when,=ensure,=rescue,==begin,==end setlocal indentkeys+==private,=protected,=public @@ -120,6 +120,9 @@ let s:block_regex = let s:block_continuation_regex = '^\s*[^])}\t ].*'.s:block_regex +" Regex that describes a leading operator (only a method call's dot for now) +let s:leading_operator_regex = '^\s*[.]' + " 2. Auxiliary Functions {{{1 " ====================== @@ -179,7 +182,11 @@ function s:GetMSL(lnum) " Otherwise, terminate search as we have found our MSL already. let line = getline(lnum) - if s:Match(lnum, s:splat_regex) + if s:Match(msl, s:leading_operator_regex) + " If the current line starts with a leading operator, keep its indent + " and keep looking for an MSL. + let msl = lnum + elseif s:Match(lnum, s:splat_regex) " If the above line looks like the "*" of a splat, use the current one's " indentation. " @@ -442,6 +449,11 @@ function GetRubyIndent(...) return 0 endif + " If the current line starts with a leading operator, add a level of indent. + if s:Match(clnum, s:leading_operator_regex) + return indent(s:GetMSL(clnum)) + &sw + endif + " 3.3. Work on the previous line. {{{2 " ------------------------------- @@ -481,6 +493,12 @@ function GetRubyIndent(...) return indent(s:GetMSL(lnum)) + &sw endif + " If the previous line started with a leading operator, use its MSL's level + " of indent + if s:Match(lnum, s:leading_operator_regex) + return indent(s:GetMSL(lnum)) + endif + " If the previous line ended with the "*" of a splat, add a level of indent if line =~ s:splat_regex return indent(lnum) + &sw diff --git a/spec/indent/continuations_spec.rb b/spec/indent/continuations_spec.rb index 49b0afcf..4151ce7e 100644 --- a/spec/indent/continuations_spec.rb +++ b/spec/indent/continuations_spec.rb @@ -1,6 +1,22 @@ require 'spec_helper' describe "Indenting" do + specify "method chaining" do + assert_correct_indenting <<-EOF + some_object. + method_one. + method_two. + method_three + EOF + + assert_correct_indenting <<-EOF + some_object + .method_one + .method_two + .method_three + EOF + end + specify "arrays" do assert_correct_indenting <<-EOF foo = [one, From 4c6c740563811fe275b8de38c3b722bd8dc50400 Mon Sep 17 00:00:00 2001 From: Jussi Virtanen Date: Fri, 10 Jan 2014 22:05:32 +0200 Subject: [PATCH 096/451] Add CocoaPods file type detection CocoaPods is to Objective-C what RubyGems and Bundler are to Ruby. It, too, uses Ruby as the language for its dependency declaration (Podfile) and package specification (*.podspec) files. Treat these as Ruby files. --- ftdetect/ruby.vim | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ftdetect/ruby.vim b/ftdetect/ruby.vim index a4e9a6d9..a20c83f7 100644 --- a/ftdetect/ruby.vim +++ b/ftdetect/ruby.vim @@ -59,4 +59,7 @@ au BufNewFile,BufRead [Bb]uildfile set filetype=ruby " Appraisal au BufNewFile,BufRead Appraisals set filetype=ruby +" CocoaPods +au BufNewFile,BufRead Podfile,*.podspec set filetype=ruby + " vim: nowrap sw=2 sts=2 ts=8 noet: From 8775819e3ace1f592156cd0973097b9f3b3d6d85 Mon Sep 17 00:00:00 2001 From: "brian m. carlson" Date: Sat, 18 Jan 2014 20:21:32 +0000 Subject: [PATCH 097/451] Fix highlighting of regexps as hash keys. --- syntax/ruby.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/syntax/ruby.vim b/syntax/ruby.vim index 08f71554..d880051a 100644 --- a/syntax/ruby.vim +++ b/syntax/ruby.vim @@ -121,7 +121,7 @@ syn match rubyPredefinedConstant "\%(\%(^\|[^.]\)\.\s*\)\@\%(\s*(\)\@!" " Normal Regular Expression -syn region rubyRegexp matchgroup=rubyRegexpDelimiter start="\%(\%(^\|\<\%(and\|or\|while\|until\|unless\|if\|elsif\|when\|not\|then\|else\)\|[;\~=!|&(,[<>?:*+-]\)\s*\)\@<=/" end="/[iomxneus]*" skip="\\\\\|\\/" contains=@rubyRegexpSpecial fold +syn region rubyRegexp matchgroup=rubyRegexpDelimiter start="\%(\%(^\|\<\%(and\|or\|while\|until\|unless\|if\|elsif\|when\|not\|then\|else\)\|[;\~=!|&(,{[<>?:*+-]\)\s*\)\@<=/" end="/[iomxneus]*" skip="\\\\\|\\/" contains=@rubyRegexpSpecial fold syn region rubyRegexp matchgroup=rubyRegexpDelimiter start="\%(\h\k*\s\+\)\@<=/[ \t=]\@!" end="/[iomxneus]*" skip="\\\\\|\\/" contains=@rubyRegexpSpecial fold " Generalized Regular Expression From 97f9f972cb7792f26856d9e0dd5425a4249c628d Mon Sep 17 00:00:00 2001 From: Ryan Bright Date: Fri, 24 Jan 2014 23:05:13 -0500 Subject: [PATCH 098/451] Add syntax highlighting for Module#refine and Module#using --- syntax/ruby.vim | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/syntax/ruby.vim b/syntax/ruby.vim index d880051a..75da6085 100644 --- a/syntax/ruby.vim +++ b/syntax/ruby.vim @@ -261,7 +261,7 @@ if !exists("ruby_no_special_methods") syn keyword rubyException raise fail catch throw " false positive with 'include?' syn match rubyInclude "\[?!]\@!" - syn keyword rubyInclude autoload extend load prepend require require_relative + syn keyword rubyInclude autoload extend load prepend refine require require_relative using syn keyword rubyKeyword callcc caller lambda proc endif @@ -279,18 +279,18 @@ endif " Note: this is a hack to prevent 'keywords' being highlighted as such when called as methods with an explicit receiver syn match rubyKeywordAsMethod "\%(\%(\.\@" transparent contains=NONE syn match rubyKeywordAsMethod "\%(\%(\.\@" transparent contains=NONE -syn match rubyKeywordAsMethod "\%(\%(\.\@" transparent contains=NONE +syn match rubyKeywordAsMethod "\%(\%(\.\@" transparent contains=NONE syn match rubyKeywordAsMethod "\%(\%(\.\@" transparent contains=NONE syn match rubyKeywordAsMethod "\<\%(alias\|begin\|case\|class\|def\|do\|end\)[?!]" transparent contains=NONE -syn match rubyKeywordAsMethod "\<\%(if\|module\|undef\|unless\|until\|while\)[?!]" transparent contains=NONE +syn match rubyKeywordAsMethod "\<\%(if\|module\|refine\|undef\|unless\|until\|while\)[?!]" transparent contains=NONE syn match rubyKeywordAsMethod "\%(\%(\.\@" transparent contains=NONE syn match rubyKeywordAsMethod "\%(\%(\.\@" transparent contains=NONE syn match rubyKeywordAsMethod "\%(\%(\.\@" transparent contains=NONE syn match rubyKeywordAsMethod "\%(\%(\.\@" transparent contains=NONE syn match rubyKeywordAsMethod "\%(\%(\.\@" transparent contains=NONE -syn match rubyKeywordAsMethod "\%(\%(\.\@" transparent contains=NONE +syn match rubyKeywordAsMethod "\%(\%(\.\@" transparent contains=NONE " __END__ Directive syn region rubyData matchgroup=rubyDataDirective start="^__END__$" end="\%$" fold From d1f747115acba340de6671a4e9fd626555cedfb3 Mon Sep 17 00:00:00 2001 From: Andrew Radev Date: Tue, 28 Jan 2014 20:57:54 +0100 Subject: [PATCH 099/451] Apply real fix for Andy Wokula's HTML indent --- indent/eruby.vim | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/indent/eruby.vim b/indent/eruby.vim index 19109ceb..5f323857 100644 --- a/indent/eruby.vim +++ b/indent/eruby.vim @@ -19,6 +19,9 @@ else endif unlet! b:did_indent +" Force HTML indent to not keep state. +let b:html_indent_usestate = 0 + if &l:indentexpr == '' if &l:cindent let &l:indentexpr = 'cindent(v:lnum)' @@ -53,7 +56,8 @@ function! GetErubyIndent(...) else exe "let ind = ".b:eruby_subtype_indentexpr - " Workaround for Andy Wokula's HTML indent + " Workaround for Andy Wokula's HTML indent. This should be removed after + " some time, since the newest version is fixed in a different way. if b:eruby_subtype_indentexpr =~# '^HtmlIndent(' \ && exists('b:indent') \ && type(b:indent) == type({}) From 686546d623c93b76a22da1cad3a97ea1a813e53a Mon Sep 17 00:00:00 2001 From: Doug Kearns Date: Thu, 13 Feb 2014 00:48:26 +1100 Subject: [PATCH 100/451] Remove Gem installation infrastructure This project hasn't been distributed as a gem in the better part of a decade and the resulting user complaints have registered as little more than a murmur. Relevant FAQ content will be moved to the wiki. Fixes #198. --- FAQ | 251 ---------------------- INSTALL.markdown | 3 +- README | 11 +- Rakefile | 42 ---- bin/vim-ruby-install.rb | 455 ---------------------------------------- 5 files changed, 6 insertions(+), 756 deletions(-) delete mode 100644 FAQ delete mode 100644 Rakefile delete mode 100755 bin/vim-ruby-install.rb 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/INSTALL.markdown b/INSTALL.markdown index 29ba3fb1..b767bb58 100644 --- a/INSTALL.markdown +++ b/INSTALL.markdown @@ -32,5 +32,4 @@ 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 index 6f1bb2e1..39d9d91f 100644 --- a/README +++ b/README @@ -16,7 +16,7 @@ For regular users: - 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. + of GitHub. - Feel free to join discussions on the vim-ruby-devel mailing list: http://rubyforge.org/mail/?group_id=16 @@ -29,19 +29,18 @@ 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. + 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. + GitHub is to get the latest version of them. Git topics: - Project was migrated from CVS in August, 2008. 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/bin/vim-ruby-install.rb b/bin/vim-ruby-install.rb deleted file mode 100755 index 10a15dd5..00000000 --- a/bin/vim-ruby-install.rb +++ /dev/null @@ -1,455 +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 RbConfig -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 -} - -# -# 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: From 1fb89e65d8328fb8b5a185fa82c8c77a30de98d5 Mon Sep 17 00:00:00 2001 From: robertomiranda Date: Thu, 30 Jan 2014 12:17:27 -0500 Subject: [PATCH 101/451] Add syntax detection for .ruby ref https://github.com/rails/rails/commit/de1060f4e02925c12004f2 --- ftdetect/ruby.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ftdetect/ruby.vim b/ftdetect/ruby.vim index a4e9a6d9..15bae061 100644 --- a/ftdetect/ruby.vim +++ b/ftdetect/ruby.vim @@ -2,7 +2,7 @@ au BufNewFile,BufRead *.rb,*.rbw,*.gemspec set filetype=ruby " Ruby on Rails -au BufNewFile,BufRead *.builder,*.rxml,*.rjs set filetype=ruby +au BufNewFile,BufRead *.builder,*.rxml,*.rjs,*.ruby set filetype=ruby " Rakefile au BufNewFile,BufRead [rR]akefile,*.rake set filetype=ruby From 2e5ed9a88a85174de18fb8015f39f7d4e2dc63ef Mon Sep 17 00:00:00 2001 From: Gino Lucero Date: Wed, 19 Feb 2014 08:52:17 -0800 Subject: [PATCH 102/451] added __dir__ to rubyPseudoVariable list --- syntax/ruby.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/syntax/ruby.vim b/syntax/ruby.vim index 75da6085..9bef5f15 100644 --- a/syntax/ruby.vim +++ b/syntax/ruby.vim @@ -197,7 +197,7 @@ syn match rubyControl "\<\%(and\|break\|in\|next\|not\|or\|redo\|rescue syn match rubyOperator "\[?!]\@!" syn match rubyBoolean "\<\%(true\|false\)\>[?!]\@!" -syn match rubyPseudoVariable "\<\%(nil\|self\|__ENCODING__\|__FILE__\|__LINE__\|__callee__\|__method__\)\>[?!]\@!" " TODO: reorganise +syn match rubyPseudoVariable "\<\%(nil\|self\|__ENCODING__\|__dir__\|__FILE__\|__LINE__\|__callee__\|__method__\)\>[?!]\@!" " TODO: reorganise syn match rubyBeginEnd "\<\%(BEGIN\|END\)\>[?!]\@!" " Expensive Mode - match 'end' with the appropriate opening keyword for syntax From c0392f3caa85e1e47bd664cf92128e255348e190 Mon Sep 17 00:00:00 2001 From: Andrew Radev Date: Sun, 23 Feb 2014 21:58:40 +0100 Subject: [PATCH 103/451] Also skip matchit matches that are regexes --- ftplugin/ruby.vim | 1 + 1 file changed, 1 insertion(+) diff --git a/ftplugin/ruby.vim b/ftplugin/ruby.vim index 9630a940..a8ef8866 100644 --- a/ftplugin/ruby.vim +++ b/ftplugin/ruby.vim @@ -34,6 +34,7 @@ if exists("loaded_matchit") && !exists("b:match_words") let b:match_skip = \ "synIDattr(synID(line('.'),col('.'),0),'name') =~ '" . \ "\\ Date: Sun, 23 Feb 2014 22:17:03 +0100 Subject: [PATCH 104/451] Fix issue with required keyword args These are highlighted as symbols, but only if they're followed by a space. If they're followed with a comma, like in: def one(two:, three:) end Then the "two:" would not be highlighted. See https://github.com/vim-ruby/vim-ruby/issues/193. --- syntax/ruby.vim | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/syntax/ruby.vim b/syntax/ruby.vim index 9bef5f15..e683490e 100644 --- a/syntax/ruby.vim +++ b/syntax/ruby.vim @@ -101,7 +101,7 @@ syn match rubySymbol "[]})\"':]\@_,;:!?/.'"@$*\&+0]\)" syn match rubySymbol "[]})\"':]\@\@!\)\=" syn match rubySymbol "\%([{(,]\_s*\)\@<=\l\w*[!?]\=::\@!"he=e-1 -syn match rubySymbol "[]})\"':]\@" skip="\\\\\|\\>" fold contains=rubyNestedAngleBrackets,rubyDelimEscape From 3ffc0aaf966647090b03ebe9804986760c176655 Mon Sep 17 00:00:00 2001 From: Andrew Radev Date: Sun, 23 Feb 2014 22:45:39 +0100 Subject: [PATCH 105/451] Make two related patterns consistent This pattern is very similar to the one that's a line above. This change keeps them in sync. --- syntax/ruby.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/syntax/ruby.vim b/syntax/ruby.vim index e683490e..052d602e 100644 --- a/syntax/ruby.vim +++ b/syntax/ruby.vim @@ -103,7 +103,7 @@ syn match rubySymbol "[]})\"':]\@ Date: Sun, 23 Mar 2014 15:47:06 -0400 Subject: [PATCH 106/451] Example compilers for avoiding testrb The minitest crew is adamantly opposed to providing testrb, so provide a few alternative examples. In the future, it might make sense to change the default. Ulterior motive for including these examples is to allow dispatch.vim to pick up on them. --- compiler/rubyunit.vim | 2 ++ 1 file changed, 2 insertions(+) diff --git a/compiler/rubyunit.vim b/compiler/rubyunit.vim index 93a0c8e6..ed0639b5 100644 --- a/compiler/rubyunit.vim +++ b/compiler/rubyunit.vim @@ -17,6 +17,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]:, From c38bc43a9fd35be9e07ab1c5a6a38ae912f6d051 Mon Sep 17 00:00:00 2001 From: Tim Pope Date: Tue, 25 Mar 2014 17:52:53 -0400 Subject: [PATCH 107/451] Don't set filetype twice Finding a measurable performance improvement from avoiding this. --- ftdetect/ruby.vim | 50 ++++++++++++++++++++++++++--------------------- 1 file changed, 28 insertions(+), 22 deletions(-) diff --git a/ftdetect/ruby.vim b/ftdetect/ruby.vim index 78cbbde6..43f2b8e3 100644 --- a/ftdetect/ruby.vim +++ b/ftdetect/ruby.vim @@ -1,65 +1,71 @@ +function! s:setf(filetype) abort + if &filetype !=# a:filetype + let &filetype = a:filetype + endif +endfunction + " Ruby -au BufNewFile,BufRead *.rb,*.rbw,*.gemspec set filetype=ruby +au BufNewFile,BufRead *.rb,*.rbw,*.gemspec call s:setf('ruby') " Ruby on Rails -au BufNewFile,BufRead *.builder,*.rxml,*.rjs,*.ruby set filetype=ruby +au BufNewFile,BufRead *.builder,*.rxml,*.rjs,*.ruby call s:setf('ruby') " Rakefile -au BufNewFile,BufRead [rR]akefile,*.rake set filetype=ruby +au BufNewFile,BufRead [rR]akefile,*.rake call s:setf('ruby') " Rantfile -au BufNewFile,BufRead [rR]antfile,*.rant set filetype=ruby +au BufNewFile,BufRead [rR]antfile,*.rant call s:setf('ruby') " IRB config -au BufNewFile,BufRead .irbrc,irbrc set filetype=ruby +au BufNewFile,BufRead .irbrc,irbrc call s:setf('ruby') " Pry config -au BufNewFile,BufRead .pryrc set filetype=ruby +au BufNewFile,BufRead .pryrc call s:setf('ruby') " Rackup -au BufNewFile,BufRead *.ru set filetype=ruby +au BufNewFile,BufRead *.ru call s:setf('ruby') " Capistrano -au BufNewFile,BufRead Capfile set filetype=ruby +au BufNewFile,BufRead Capfile call s:setf('ruby') " Bundler -au BufNewFile,BufRead Gemfile set filetype=ruby +au BufNewFile,BufRead Gemfile call s:setf('ruby') " Guard -au BufNewFile,BufRead Guardfile,.Guardfile set filetype=ruby +au BufNewFile,BufRead Guardfile,.Guardfile call s:setf('ruby') " Chef -au BufNewFile,BufRead Cheffile set filetype=ruby -au BufNewFile,BufRead Berksfile set filetype=ruby +au BufNewFile,BufRead Cheffile call s:setf('ruby') +au BufNewFile,BufRead Berksfile call s:setf('ruby') " Vagrant -au BufNewFile,BufRead [vV]agrantfile set filetype=ruby +au BufNewFile,BufRead [vV]agrantfile call s:setf('ruby') " Autotest -au BufNewFile,BufRead .autotest set filetype=ruby +au BufNewFile,BufRead .autotest call s:setf('ruby') " eRuby -au BufNewFile,BufRead *.erb,*.rhtml set filetype=eruby +au BufNewFile,BufRead *.erb,*.rhtml call s:setf('eruby') " Thor -au BufNewFile,BufRead [tT]horfile,*.thor set filetype=ruby +au BufNewFile,BufRead [tT]horfile,*.thor call s:setf('ruby') " Rabl -au BufNewFile,BufRead *.rabl set filetype=ruby +au BufNewFile,BufRead *.rabl call s:setf('ruby') " Jbuilder -au BufNewFile,BufRead *.jbuilder set filetype=ruby +au BufNewFile,BufRead *.jbuilder call s:setf('ruby') " Puppet librarian -au BufNewFile,BufRead Puppetfile set filetype=ruby +au BufNewFile,BufRead Puppetfile call s:setf('ruby') " " Buildr Buildfile -au BufNewFile,BufRead [Bb]uildfile set filetype=ruby +au BufNewFile,BufRead [Bb]uildfile call s:setf('ruby') " Appraisal -au BufNewFile,BufRead Appraisals set filetype=ruby +au BufNewFile,BufRead Appraisals call s:setf('ruby') " CocoaPods -au BufNewFile,BufRead Podfile,*.podspec set filetype=ruby +au BufNewFile,BufRead Podfile,*.podspec call s:setf('ruby') " vim: nowrap sw=2 sts=2 ts=8 noet: From e9a7554bca4a3b6676b1277fe69ba37d9fbe8e74 Mon Sep 17 00:00:00 2001 From: Tim Pope Date: Thu, 3 Apr 2014 09:56:32 -0400 Subject: [PATCH 108/451] Give symbol key highlighting highest precedence Closes #144. --- syntax/ruby.vim | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/syntax/ruby.vim b/syntax/ruby.vim index 052d602e..3ad8dca3 100644 --- a/syntax/ruby.vim +++ b/syntax/ruby.vim @@ -100,10 +100,6 @@ syn match rubySymbol "[]})\"':]\@\|<=\|<\|===\|[=!]=\|[=! syn match rubySymbol "[]})\"':]\@_,;:!?/.'"@$*\&+0]\)" syn match rubySymbol "[]})\"':]\@\@!\)\=" -syn match rubySymbol "\%([{(,]\_s*\)\@<=\l\w*[!?]\=::\@!"he=e-1 -syn match rubySymbol "[]})\"':]\@" transparent contains=NONE syn match rubyKeywordAsMethod "\%(\%(\.\@" transparent contains=NONE +syn match rubySymbol "\%([{(,]\_s*\)\@<=\l\w*[!?]\=::\@!"he=e-1 +syn match rubySymbol "[]})\"':]\@ Date: Tue, 10 Jun 2014 01:43:46 -0400 Subject: [PATCH 109/451] Shell escape PATH References #202. --- ftplugin/ruby.vim | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/ftplugin/ruby.vim b/ftplugin/ruby.vim index a8ef8866..8d77da96 100644 --- a/ftplugin/ruby.vim +++ b/ftplugin/ruby.vim @@ -69,8 +69,8 @@ endif function! s:query_path(root) let code = "print $:.join %q{,}" - if &shell =~# 'sh' && $PATH !~# '\s' - let prefix = 'env PATH='.$PATH.' ' + if &shell =~# 'sh' + let prefix = 'env PATH='.shellescape($PATH).' ' else let prefix = '' endif @@ -190,15 +190,16 @@ if !exists("g:no_plugin_maps") && !exists("g:no_ruby_maps") endif if maparg("\",'n') == '' - nnoremap :exe v:count1."tag =RubyCursorIdentifier()" - nnoremap g :exe "tjump =RubyCursorIdentifier()" - nnoremap g] :exe "tselect =RubyCursorIdentifier()" - nnoremap ] :exe v:count1."stag =RubyCursorIdentifier()" - nnoremap :exe v:count1."stag =RubyCursorIdentifier()" - nnoremap g :exe "stjump =RubyCursorIdentifier()" - nnoremap g] :exe "stselect =RubyCursorIdentifier()" - nnoremap } :exe "ptag =RubyCursorIdentifier()" - nnoremap g} :exe "ptjump =RubyCursorIdentifier()" + cnoremap foldopen if &foldopen =~# 'tag'foldopenendif + nnoremap