PATCH: use exists() when testing config variables

Doug Kearns dougkearns at gmail.com
Wed May 10 03:03:13 EDT 2006


Mark,

I noticed that unsetting a config variable with 'unlet' broke the
completion script.

In general, when testing boolean config variables in the Vim runtime
files, it's just a test to see whether they're defined or not with
exists().

Regards,
Doug


Index: autoload/rubycomplete.vim
===================================================================
RCS file: /var/cvs/vim-ruby/vim-ruby/autoload/rubycomplete.vim,v
retrieving revision 1.28
diff -u -r1.28 rubycomplete.vim
--- autoload/rubycomplete.vim	7 May 2006 21:04:09 -0000	1.28
+++ autoload/rubycomplete.vim	10 May 2006 06:54:20 -0000
@@ -26,14 +26,6 @@
 endif
 " }}} requirement checks
 
-if !exists("g:rubycomplete_rails")
-    let g:rubycomplete_rails = 0
-endif
-
-if !exists("g:rubycomplete_classes_in_global")
-    let g:rubycomplete_classes_in_global = 0
-endif
-
 " {{{ vim-side support functions
 function! s:GetBufferRubyModule(name)
     let [snum,enum] = s:GetBufferRubyEntity(a:name, "module")
@@ -90,7 +82,7 @@
         return vtp
     endif
     call setpos('.',pos)
-    if g:rubycomplete_rails == 1 && s:rubycomplete_rails_loaded == 1
+    if exists("g:rubycomplete_rails") && s:rubycomplete_rails_loaded == 1
         let ctors = '\(now\|new\|open\|get_instance\|find\|create\)'
     else
         let ctors = '\(now\|new\|open\|get_instance\)'
@@ -255,7 +247,7 @@
 
 def get_buffer_classes()
   # this will be a little expensive.
-  allow_aggressive_load = VIM::evaluate('g:rubycomplete_classes_in_global')
+  allow_aggressive_load = VIM::evaluate('exists("g:rubycomplete_classes_in_global")')
   return [] if allow_aggressive_load != '1'
 
   buf = VIM::Buffer.current
@@ -273,7 +265,7 @@
 end
 
 def load_rails()
-  allow_rails = VIM::evaluate('g:rubycomplete_rails')
+  allow_rails = VIM::evaluate('exists("g:rubycomplete_rails")')
   return if allow_rails != '1'
 
   buf_path = VIM::evaluate('expand("%:p")')
@@ -309,7 +301,7 @@
 end
 
 def get_rails_helpers
-  allow_rails = VIM::evaluate('g:rubycomplete_rails')
+  allow_rails = VIM::evaluate('exists("g:rubycomplete_rails")')
   rails_loaded = VIM::evaluate('s:rubycomplete_rails_loaded')
   return [] if allow_rails != '1' || rails_loaded != '1'
   return RailsWords


More information about the vim-ruby-devel mailing list