interactive_editor 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -3,7 +3,28 @@
3
3
 
4
4
  cf. my blog post: [Integrating vim and irb](http://zegoggl.es/2009/04/integrating-vim-and-irb.html).
5
5
 
6
+ ## Usage
6
7
 
7
- # Credits
8
+ $ gem install interactive_editor
8
9
 
9
- Giles Bowkett, Greg Brown, and several audience members from Giles' Ruby East presentation [Use vi or any text editor from within IRB](http://gilesbowkett.blogspot.com/2007/10/use-vi-or-any-text-editor-from-within.html).
10
+ Put the following in your .irbrc:
11
+
12
+ require 'rubygems'
13
+ require 'interactive_editor'
14
+
15
+ Then, from within irb:
16
+
17
+ $ irb
18
+ > vi
19
+ > vi 'filename.rb'
20
+ > [emacs|vim|nano|mate] ...
21
+
22
+ To try it out without installing the gem:
23
+
24
+ $ git clone git://github.com/jberkel/interactive_editor.git
25
+ $ cd interactive_editor
26
+ $ rake console
27
+
28
+ ## Credits
29
+
30
+ Giles Bowkett, Greg Brown, and several audience members from Giles' Ruby East presentation: [Use vi or any text editor from within IRB](http://gilesbowkett.blogspot.com/2007/10/use-vi-or-any-text-editor-from-within.html).
data/Rakefile CHANGED
@@ -70,6 +70,7 @@ task :release => :build do
70
70
  sh "gem push pkg/#{name}-#{version}.gem"
71
71
  end
72
72
 
73
+ desc "Builds the gem"
73
74
  task :build => :gemspec do
74
75
  sh "mkdir -p pkg"
75
76
  sh "gem build #{gemspec_file}"
@@ -7,7 +7,7 @@ Gem::Specification.new do |s|
7
7
  ## If your rubyforge_project name is different, then edit it and comment out
8
8
  ## the sub! line in the Rakefile
9
9
  s.name = 'interactive_editor'
10
- s.version = '0.0.1'
10
+ s.version = '0.0.2'
11
11
  s.date = '2010-05-16'
12
12
  s.rubyforge_project = 'interactive_editor'
13
13
 
@@ -7,7 +7,7 @@ require 'fileutils'
7
7
  require 'tempfile'
8
8
 
9
9
  class InteractiveEditor
10
- VERSION = '0.0.1'
10
+ VERSION = '0.0.2'
11
11
 
12
12
  attr_accessor :editor
13
13
 
@@ -23,7 +23,12 @@ class InteractiveEditor
23
23
  (@file && File.exist?(@file.path)) ? @file : Tempfile.new(["irb_tempfile", ".rb"])
24
24
  end
25
25
  mtime = File.stat(@file.path).mtime
26
- Exec.system(@editor, @file.path)
26
+
27
+ if (args = @editor.split(/\s+/)).size > 1
28
+ Exec.system(args[0], *(args[1..-1] << @file.path))
29
+ else
30
+ Exec.system(@editor, @file.path)
31
+ end
27
32
 
28
33
  execute if mtime < File.stat(@file.path).mtime
29
34
  end
@@ -33,30 +38,28 @@ class InteractiveEditor
33
38
  end
34
39
 
35
40
  def self.edit(editor, file=nil)
36
- #idea serialise last file to disk, for recovery
37
- unless IRB.conf[:interactive_editors] && IRB.conf[:interactive_editors][editor]
38
- IRB.conf[:interactive_editors] ||= {}
39
- IRB.conf[:interactive_editors][editor] = InteractiveEditor.new(editor)
40
- end
41
- IRB.conf[:interactive_editors][editor].edit(file)
41
+ #maybe serialise last file to disk, for recovery
42
+ (IRB.conf[:interactive_editors] ||=
43
+ Hash.new { |h,k| h[k] = InteractiveEditor.new(k) })[editor].edit(file)
42
44
  end
43
45
 
44
46
  module Exec
45
- extend self
46
-
47
- if RUBY_PLATFORM =~ /java/
48
- #http://github.com/headius/spoon
49
- require 'rubygems'
50
- require 'spoon'
51
-
52
- def system(*args)
53
- Process.waitpid(Spoon.spawnp(*args))
47
+ module Java
48
+ def system(file, *args)
49
+ require 'spoon'
50
+ Process.waitpid(Spoon.spawnp(file, *args))
51
+ rescue Errno::ECHILD => e
52
+ raise "error exec'ing #{file}: #{e}"
54
53
  end
55
- else
54
+ end
55
+
56
+ module MRI
56
57
  def system(file, *args)
57
- Kernel::system(file, *args)
58
+ Kernel::system(file, *args) or raise "error exec'ing #{file}: #{$?}"
58
59
  end
59
60
  end
61
+
62
+ extend RUBY_PLATFORM =~ /java/ ? Java : MRI
60
63
  end
61
64
 
62
65
  module Editors
@@ -74,5 +77,4 @@ class InteractiveEditor
74
77
  end
75
78
  end
76
79
 
77
- Object.send(:include, InteractiveEditor::Editors)
78
-
80
+ include InteractiveEditor::Editors
metadata CHANGED
@@ -1,27 +1,36 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: interactive_editor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 2
9
+ version: 0.0.2
5
10
  platform: ruby
6
11
  authors:
7
- - Jan Berkel
12
+ - Jan Berkel
8
13
  autorequire:
9
14
  bindir: bin
10
15
  cert_chain: []
11
16
 
12
- date: 2010-05-16 00:00:00 +09:00
17
+ date: 2010-05-16 00:00:00 +01:00
13
18
  default_executable:
14
19
  dependencies:
15
- - !ruby/object:Gem::Dependency
16
- name: spoon
17
- type: :runtime
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
20
- requirements:
21
- - - ">="
22
- - !ruby/object:Gem::Version
23
- version: 0.0.1
24
- version:
20
+ - !ruby/object:Gem::Dependency
21
+ name: spoon
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ - 0
30
+ - 1
31
+ version: 0.0.1
32
+ type: :runtime
33
+ version_requirements: *id001
25
34
  description: Use vim (or any other text editor) from inside irb to quickly test & write new code.
26
35
  email: jan.berkel@gmail.com
27
36
  executables: []
@@ -29,39 +38,41 @@ executables: []
29
38
  extensions: []
30
39
 
31
40
  extra_rdoc_files:
32
- - README.md
33
- - LICENSE
41
+ - README.md
42
+ - LICENSE
34
43
  files:
35
- - LICENSE
36
- - README.md
37
- - Rakefile
38
- - interactive_editor.gemspec
39
- - lib/interactive_editor.rb
44
+ - LICENSE
45
+ - README.md
46
+ - Rakefile
47
+ - interactive_editor.gemspec
48
+ - lib/interactive_editor.rb
40
49
  has_rdoc: true
41
50
  homepage: http://github.com/jberkel/interactive_editor
42
51
  licenses: []
43
52
 
44
53
  post_install_message:
45
54
  rdoc_options:
46
- - --charset=UTF-8
55
+ - --charset=UTF-8
47
56
  require_paths:
48
- - lib
57
+ - lib
49
58
  required_ruby_version: !ruby/object:Gem::Requirement
50
59
  requirements:
51
- - - ">="
52
- - !ruby/object:Gem::Version
53
- version: "0"
54
- version:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ segments:
63
+ - 0
64
+ version: "0"
55
65
  required_rubygems_version: !ruby/object:Gem::Requirement
56
66
  requirements:
57
- - - ">="
58
- - !ruby/object:Gem::Version
59
- version: "0"
60
- version:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ segments:
70
+ - 0
71
+ version: "0"
61
72
  requirements: []
62
73
 
63
74
  rubyforge_project: interactive_editor
64
- rubygems_version: 1.3.5
75
+ rubygems_version: 1.3.6
65
76
  signing_key:
66
77
  specification_version: 2
67
78
  summary: Interactive editing in irb.