PATCH: default installation directories

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

PATCH: default installation directories

Doug Kearns
This is just a quick patch to use $VIM/vimfiles and
$HOME/{.vim,vimfiles} rather than $VIMRUNTIME as the two default
installation directories offered by vim-ruby-install.rb.

$VIM is determined by:
1. checking for an env variable VIM or if this is not found - as in the default case
2. by parsing vim --version on UNIX or reading the 'path' key under
   HKEY_LOCAL_MACHINE\Software\Vim\Gvim on Windows

Perhaps $VIMRUNTIME should be a fall-back but I think there are some
pretty significant problems if we can't find $VIM.

It could undoubtedly be improved...

Regards,
Doug

PS. Apologies for the incorrect threading of the two previous messages.
I stuck them in my drafts folder late one night and forgot to edit the
In-Reply-To header...*sigh* I know how this stuff really annoys some
people. ;-)


Index: README
===================================================================
RCS file: /var/cvs/vim-ruby/vim-ruby/README,v
retrieving revision 1.5
diff -u -r1.5 README
--- README 6 Nov 2003 10:17:33 -0000 1.5
+++ README 15 Aug 2005 14:39:33 -0000
@@ -26,10 +26,10 @@
   - Thank you very much for taking an interest.
 
 Contents of the project:
-  - The compiler, ftplugin, indent and syntax directories contain the ruby.vim
-    files that are to be copied somewhere Vim can see them.
-  - install.rb performs this copying.
-  - build.rb creates a tarball for easy distribution.
+  - The 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 anonymous CVS, you can keep
@@ -37,8 +37,9 @@
     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 install.rb, just Vim files.  You would typically install these
-    wherever Vim is installed, in the (for example) "vim62" directory.
+    README, no vim-ruby-install.rb, just Vim files.  You would typically
+    install these into either $VIM/vimfiles, for system-wide use, or $HOME/.vim
+    ($HOME/vimfiles on Windows) for personal use.
   - Remember that when you install Vim in the first place, all of these files
     are present.  The purpose of downloading and installing them from
     RubyForge is to get the latest version of them.
@@ -70,7 +71,8 @@
     (gsinclair at soyabean.com.au).
   - To ask about the contents of the configuration files, ask on the mailing
     list, as different people maintain the different files.  Gavin knows
-    nothing about the syntax file, for instance.
+    nothing about the syntax file, for instance. (Come to think of it, nor does
+    Doug - djk)
 
 Project gossip:
   - Two of the configuration file maintainers, Doug Kearns and Gavin Sinclair,
Index: bin/vim-ruby-install.rb
===================================================================
RCS file: /var/cvs/vim-ruby/vim-ruby/bin/vim-ruby-install.rb,v
retrieving revision 1.4
diff -u -r1.4 vim-ruby-install.rb
--- bin/vim-ruby-install.rb 11 Aug 2005 13:51:28 -0000 1.4
+++ bin/vim-ruby-install.rb 15 Aug 2005 14:39:33 -0000
@@ -2,10 +2,10 @@
 
 # vim-ruby-install: install the Vim config files for Ruby editing
 #
-#  * scope out the target directry and get user to confirm
+#  * 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 current directory
+#  * 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)
@@ -26,11 +26,11 @@
   syntax/eruby.vim
   syntax/ruby.vim
 }
-# XXX: what do we do with 'filetype/filetype.vim' ???
-                  
+#FIXME: ftdetect/ruby.vim - vim 6.3+ only? This won't cause problems for
+#       earlier versions; it just won't work!
 
   #
-  # Miscelleneous functions in the user's environment.
+  # Miscellaneous functions in the user's environment.
   #
 class Env
     #
@@ -47,18 +47,15 @@
 
     #
     # Returns the path to the directory where the vim configuration files will be copied from.
-    # The first preference is the current directory.  If that fails, we look for the RubyGems
-    # package 'vim-ruby'.  Failing that, we return +nil+.
+    # 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 current directory.
-    if SOURCE_FILES.all? { |path| FileTest.file?(path) }
-      return '.'
-      # 2. Try the directory above this installation script.
-    elsif SOURCE_FILES.map { |f| File.join(File.dirname($0), '..', f) }.all? { |path| FileTest.file?(path) }
-      return File.join(File.dirname($0), '..')
+      # 1. Try the directory above this installation script.
+    if SOURCE_FILES.map { |f| File.join(File.dirname($0), '..', f) }.all? { |path| FileTest.file?(path) }
+      return File.expand_path(File.join(File.dirname($0), '..'))
     end
-      # 3. Try the gem 'vim-ruby'.
+      # 2. Try the gem 'vim-ruby'.
     begin
       require 'rubygems'
       raise "Need RubyGems 0.8+" if Gem::RubyGemsPackageVersion < '0.8'
@@ -77,6 +74,29 @@
     return nil
   end
 
+    # Returns the Vim installation directory ($VIM).
+    # FIXME: 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
+      require 'win32/registry'
+      path = ''
+      Win32::Registry::HKEY_LOCAL_MACHINE.open('SOFTWARE\Vim\Gvim') do |reg|
+ path = reg['path', Win32::Registry::REG_SZ]
+      end
+      # FIXME: Does Registry#[] ever return nil? Exceptions?
+      unless path.empty? or path.nil?
+ dir = path.sub(/\\vim\d\d\\gvim.exe/i, '')
+      end
+    end
+    return installation_dir
+  end
+
   def Env.ask_user(message)
     print message
     gets.strip
@@ -158,21 +178,14 @@
   # user options; but is ultimately created with one in mind.
   #
 class TargetDirectory::Finder
-  POTENTIAL_DIRECTORIES = {
-    :UNIX => [
-      "/usr/local/share/vim",
-      "/usr/local/vim",
-      "/usr/share/vim",
-      "/usr/vim",
-      "/opt/share/vim",
-      "/opt/vim"
-    ],
-    :WINDOWS => [ File.join(ENV['PROGRAMFILES'], 'vim') ]
-  }
 
     # Guides the user through a selection process, ending in a chosen directory.
   def find_target_directory
-      # 1. Try the potentials (if there are any).
+      # 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:"
@@ -186,23 +199,15 @@
         return chosen_directory
       end
     end
-      # 2. We didn't find any, or the user wants to enter another.
+      # 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
-    loop do
-      dir = Env.ask_user "Please enter the full path to your Vim installation directory: "
-      dir = File.expand_path(dir)
-      if FileTest.directory?(dir)
-        entered_directory = dir
-        puts
-        return entered_directory
-      else
-        puts " *** That directory doesn't exist!"
-      end
-    end
-      # 3. We don't get here; every path contains a return statement.
+    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
+      # 4. We don't get here; every path contains a return statement.
   end
   
  private
@@ -210,17 +215,26 @@
     # Return an array of _potential_ directories (i.e. they exist).  Take the options into
     # account.
   def _potential_directories
-    dirs = POTENTIAL_DIRECTORIES[Env.determine_target_os].select { |d| FileTest.directory?(d) }
-    dirs.map { |d| _vim_runtime_directory(d) }
-  end
-
-    # Given a directory like '/usr/share/vim', returns a directory like '/usr/share/vim/vim63'.
-  def _vim_runtime_directory(dir)
-    if File.basename(dir) =~ /vim\d+/
-      dir
-    else
-      Dir.glob("#{dir}/vim*").select { |d| d =~ /vim\d+/ }.sort.last
-    end
+    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
+    dir = ENV['VIM'] || Env.determine_vim_dir
+    system_dir = dir + "/vimfiles" if dir
+    return system_dir
+  end
+
+    # Return the Vim user preferences directory
+  def _vim_user_dir
+    extension = { :UNIX => "/.vim", :WINDOWS => "/vimfiles" }
+    platform = Env.determine_target_os
+    dir = ENV['HOME']
+    user_dir = dir + extension[platform] if dir
+    return user_dir
   end
 
 end  # class TargetDirectory::Finder
@@ -331,7 +345,7 @@
      vim-ruby-install.rb: Install the vim-ruby configuration files
 
       About:
-        * Detects the Vim runtime directory
+        * 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
@@ -368,15 +382,30 @@
           Cygwin or MinGW.
     
         * This installer is quite new (2004-09-20).  Please report bugs to
-          [hidden email].
+          [hidden email].
   }.gsub(/^    /, '')
 end
 op.parse!(ARGV)
 
 source_dir = Env.determine_source_directory
-if source_dir.nil? then raise "Can't find source directory"; end
-target_dir = $options[:target_dir] || TargetDirectory.finder.find_target_directory
-VimRubyInstaller.new(source_dir, target_dir).install
+if source_dir.nil?
+  raise "Can't find source directory"
+end
 
-# vim: ft=ruby
+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] "
+  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
 
+# vim: ft=ruby sw=2 sts=2 ts=8:
_______________________________________________
vim-ruby-devel mailing list
[hidden email]
http://rubyforge.org/mailman/listinfo/vim-ruby-devel
Reply | Threaded
Open this post in threaded view
|

Re: PATCH: default installation directories

Hugh Sasse
On Tue, 16 Aug 2005, Doug Kearns wrote:

> This is just a quick patch to use $VIM/vimfiles and
> $HOME/{.vim,vimfiles} rather than $VIMRUNTIME as the two default
> installation directories offered by vim-ruby-install.rb.

Looks like what I'd wish for.  I'll `cvs update -d` and try this.

> -      end
> -    end
> -      # 3. We don't get here; every path contains a return statement.
> +    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
> +      # 4. We don't get here; every path contains a return statement.
>   end

Isn't the statement # 4 redundant now that it is *straight after* a
return statement?  (I suppose it should have been a raise or assert
before, but still....)

         Hugh
_______________________________________________
vim-ruby-devel mailing list
[hidden email]
http://rubyforge.org/mailman/listinfo/vim-ruby-devel
Reply | Threaded
Open this post in threaded view
|

Re: PATCH: default installation directories

Doug Kearns
On Mon, Aug 15, 2005 at 04:29:36PM +0100, Hugh Sasse wrote:
> On Tue, 16 Aug 2005, Doug Kearns wrote:
>
> >This is just a quick patch to use $VIM/vimfiles and
> >$HOME/{.vim,vimfiles} rather than $VIMRUNTIME as the two default
> >installation directories offered by vim-ruby-install.rb.
>
> Looks like what I'd wish for.  I'll `cvs update -d` and try this.

I thought you'd be glued to the cricket Hugh? ;-)
 

> >-      end
> >-    end
> >-      # 3. We don't get here; every path contains a return statement.
> >+    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
> >+      # 4. We don't get here; every path contains a return statement.
> >  end
>
> Isn't the statement # 4 redundant now that it is *straight after* a
> return statement?

Yes.

> (I suppose it should have been a raise or assert before, but
> still....)

Regards,
Doug
_______________________________________________
vim-ruby-devel mailing list
[hidden email]
http://rubyforge.org/mailman/listinfo/vim-ruby-devel
Reply | Threaded
Open this post in threaded view
|

Re: PATCH: default installation directories

Hugh Sasse
On Tue, 16 Aug 2005, Doug Kearns wrote:

> On Mon, Aug 15, 2005 at 04:29:36PM +0100, Hugh Sasse wrote:
>> On Tue, 16 Aug 2005, Doug Kearns wrote:
>>
>>> This is just a quick patch to use $VIM/vimfiles and
>>> $HOME/{.vim,vimfiles} rather than $VIMRUNTIME as the two default
>>> installation directories offered by vim-ruby-install.rb.
>>
>> Looks like what I'd wish for.  I'll `cvs update -d` and try this.
>
> I thought you'd be glued to the cricket Hugh? ;-)

Many are, but not me.

>
>>> -      end
>>> -    end
>>> -      # 3. We don't get here; every path contains a return statement.
>>> +    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
>>> +      # 4. We don't get here; every path contains a return statement.
>>>  end
>>
>> Isn't the statement # 4 redundant now that it is *straight after* a
>> return statement?
>
> Yes.

OK.  It occurs to me that the user could supply something
unreachable, so I'll have a look at that as I get chance.
>
>> (I suppose it should have been a raise or assert before, but
>> still....)
>
> Regards,
> Doug

         Hugh
_______________________________________________
vim-ruby-devel mailing list
[hidden email]
http://rubyforge.org/mailman/listinfo/vim-ruby-devel
Reply | Threaded
Open this post in threaded view
|

Re: PATCH: default installation directories

Hugh Sasse
Oh, I see those patches aren't in the CVS yet.  OK.  Reading through
I noticed a couple of things that may cause problems, so I've added
comments and express them in the form of a patch for convenience.

I think my mods to _same_contents *may* cover macs as well now,
which I think used \r as a line ending.  Probably not MacOSX.

         HTH
         Hugh

--- vim-ruby/bin/vim-ruby-install.rb.orig 2005-08-16 11:39:51.236954000 +0100
+++ vim-ruby/bin/vim-ruby-install.rb 2005-08-16 12:09:37.698997000 +0100
@@ -119,6 +119,8 @@
    def _ensure_directory_exists(path)
      dir = path.dirname
      unless dir.directory?
+      # <XXX> FileUtils.mkdir_p already checks if it exists and is a
+      # directory.  What if it exists as a file? (HGS)</XXX>
        mkpath(dir)
      end
    end
@@ -220,6 +222,9 @@
        dir
      else
        Dir.glob("#{dir}/vim*").select { |d| d =~ /vim\d+/ }.sort.last
+      # <XXX> I think this may fail at vim version 10 or if vim
+      # 6.22 were replaced by Vim 7.  Not sure of a good fix at this
+      # time (HGS)</XXX>
      end
    end

@@ -279,8 +284,9 @@

      # 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 }
+    ending = /[\r\n]+/
+    contents1 = p1.read.split(ending).map { |line| line.chomp }
+    contents2 = p2.read.split(ending).map { |line| line.chomp }
      contents1 == contents2
    end

_______________________________________________
vim-ruby-devel mailing list
[hidden email]
http://rubyforge.org/mailman/listinfo/vim-ruby-devel
Reply | Threaded
Open this post in threaded view
|

Re: PATCH: default installation directories

Doug Kearns
On Tue, Aug 16, 2005 at 12:25:42PM +0100, Hugh Sasse wrote:
> Oh, I see those patches aren't in the CVS yet.  OK.

Well it's Gavin's installer so I was going to wait for his comments
since this changes it's behaviour. However, it seems he might be away or
similar so I'll commit it.

> Reading through
> I noticed a couple of things that may cause problems, so I've added
> comments and express them in the form of a patch for convenience.
>
> I think my mods to _same_contents *may* cover macs as well now,
> which I think used \r as a line ending.  Probably not MacOSX.

Does Ruby run on 'Macs'?
 

>         HTH
>         Hugh
>
> --- vim-ruby/bin/vim-ruby-install.rb.orig 2005-08-16
> 11:39:51.236954000 +0100
> +++ vim-ruby/bin/vim-ruby-install.rb 2005-08-16 12:09:37.698997000 +0100
> @@ -119,6 +119,8 @@
>    def _ensure_directory_exists(path)
>      dir = path.dirname
>      unless dir.directory?
> +      # <XXX> FileUtils.mkdir_p already checks if it exists and is a
> +      # directory.  What if it exists as a file? (HGS)</XXX>

Yes, I'm not sure what this indirection is about either so I'll just add
your comment until Gavin can elucidate further.

<snip>

>        Dir.glob("#{dir}/vim*").select { |d| d =~ /vim\d+/ }.sort.last
> +      # <XXX> I think this may fail at vim version 10 or if vim
> +      # 6.22 were replaced by Vim 7.  Not sure of a good fix at this
> +      # time (HGS)</XXX>

This code was removed by the patch.

<snip>
 
>      # 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 }
> +    ending = /[\r\n]+/
> +    contents1 = p1.read.split(ending).map { |line| line.chomp }
> +    contents2 = p2.read.split(ending).map { |line| line.chomp }
>      contents1 == contents2
>    end

Doesn't this make the 'map' call redundant too?

FWIW, I'm not sure that silently replacing a file with one which differs
only in it's line endings is a good idea anyway.

Regards,
Doug
_______________________________________________
vim-ruby-devel mailing list
[hidden email]
http://rubyforge.org/mailman/listinfo/vim-ruby-devel
Reply | Threaded
Open this post in threaded view
|

Re: PATCH: default installation directories

Hugh Sasse
On Wed, 17 Aug 2005, Doug Kearns wrote:

> On Tue, Aug 16, 2005 at 12:25:42PM +0100, Hugh Sasse wrote:
>> Oh, I see those patches aren't in the CVS yet.  OK.
>
> Well it's Gavin's installer so I was going to wait for his comments
> since this changes it's behaviour. However, it seems he might be away or
> similar so I'll commit it.

OK, I can't remember how one might reverse a single change like this
later but I think it can be done....
>
>> Reading through
>> I noticed a couple of things that may cause problems, so I've added
>> comments and express them in the form of a patch for convenience.
>>
>> I think my mods to _same_contents *may* cover macs as well now,
>> which I think used \r as a line ending.  Probably not MacOSX.
>
> Does Ruby run on 'Macs'?

I think so, but I've never used one.  Just trying to keep things
open.
>
>>         HTH
>>         Hugh
>>
         [...]
>>    def _ensure_directory_exists(path)
>>      dir = path.dirname
>>      unless dir.directory?
>> +      # <XXX> FileUtils.mkdir_p already checks if it exists and is a
>> +      # directory.  What if it exists as a file? (HGS)</XXX>
>
> Yes, I'm not sure what this indirection is about either so I'll just add
> your comment until Gavin can elucidate further.

OK.
>
> <snip>
>
>>        Dir.glob("#{dir}/vim*").select { |d| d =~ /vim\d+/ }.sort.last
>> +      # <XXX> I think this may fail at vim version 10 or if vim
>> +      # 6.22 were replaced by Vim 7.  Not sure of a good fix at this
>> +      # time (HGS)</XXX>
>
> This code was removed by the patch.

Oh, sorry.

>
> <snip>
>
>>      # 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 }
>> +    ending = /[\r\n]+/
>> +    contents1 = p1.read.split(ending).map { |line| line.chomp }
>> +    contents2 = p2.read.split(ending).map { |line| line.chomp }
>>      contents1 == contents2
>>    end
>
> Doesn't this make the 'map' call redundant too?

Yes, I think so.   I was reluctant to change too much at once
without testing it to death.
>
> FWIW, I'm not sure that silently replacing a file with one which differs
> only in it's line endings is a good idea anyway.

Possibly this is to work around past problems where Unix distros
ended up with DOS-ish files, which choked the interpreter.
>
> Regards,
> Doug

         Thank you,
         Hugh
_______________________________________________
vim-ruby-devel mailing list
[hidden email]
http://rubyforge.org/mailman/listinfo/vim-ruby-devel