vimrunner 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE CHANGED
@@ -1,5 +1,17 @@
1
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
1
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
2
+ this software and associated documentation files (the "Software"), to deal in
3
+ the Software without restriction, including without limitation the rights to
4
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
5
+ of the Software, and to permit persons to whom the Software is furnished to do
6
+ so, subject to the following conditions:
2
7
 
3
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+ The above copyright notice and this permission notice shall be included in all
9
+ copies or substantial portions of the Software.
4
10
 
5
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
11
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
15
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
17
+ SOFTWARE.
data/README.md CHANGED
@@ -34,9 +34,9 @@ vim.kill
34
34
  ```
35
35
 
36
36
  Vimrunner will attempt to start up the most suitable version of Vim available,
37
- meaning:
37
+ meaning one of the following:
38
38
 
39
- * `vim` if it supports headlessly creating servers;
39
+ * `vim` if it supports headlessly creating servers (see [Requirements](#requirements) below for more information);
40
40
  * `mvim` if you are on Mac OS X;
41
41
  * `gvim`.
42
42
 
@@ -63,7 +63,7 @@ examples.)
63
63
 
64
64
  Calling `start` (or `start_gvim`) will return a `Client` instance with which
65
65
  you can control Vim. For a full list of methods you can invoke on the remote
66
- vim instance, check out the [`Client`
66
+ Vim instance, check out the [`Client`
67
67
  documentation](http://rubydoc.info/gems/vimrunner/Vimrunner/Client).
68
68
 
69
69
  ## Requirements
@@ -78,7 +78,7 @@ manual](http://vimdoc.sourceforge.net/htmldoc/remote.html#x11-clientserver).
78
78
  The client/server functionality (regrettably) needs a running X server to
79
79
  function, even without a GUI. This means that if you're using it for
80
80
  automated tests on a remote server, you'll probably need to start it with
81
- xvfb.
81
+ Xvfb.
82
82
 
83
83
  If you are using MacVim, note that you will need the `mvim` binary in your
84
84
  `PATH` in order to start and communicate with Vim servers.
@@ -21,30 +21,53 @@ module Vimrunner
21
21
  #
22
22
  # Returns nothing.
23
23
  def add_plugin(dir, entry_script = nil)
24
- command("set runtimepath+=#{dir}")
24
+ append_runtimepath(dir)
25
25
  command("runtime #{entry_script}") if entry_script
26
26
  end
27
27
 
28
- # Public: Switches Vim to normal mode and types in the given keys.
28
+ # Public: Appends a directory to Vim's runtimepath
29
+ #
30
+ # dir - The directory added to the path
31
+ #
32
+ # Returns nothing.
33
+ def append_runtimepath(dir)
34
+ command("set runtimepath+=#{dir}")
35
+ end
36
+
37
+ # Public: Prepends a directory to Vim's runtimepath. Use this instead of
38
+ # #append_runtimepath to give the directory higher priority when Vim
39
+ # runtime's a file.
40
+ #
41
+ # dir - The directory added to the path
29
42
  #
30
43
  # Returns nothing.
44
+ def prepend_runtimepath(dir)
45
+ runtimepath = echo '&runtimepath'
46
+ command("set runtimepath=#{dir},#{runtimepath}")
47
+ end
48
+
49
+ # Public: Switches Vim to normal mode and types in the given keys.
50
+ #
51
+ # Returns the Client instance.
31
52
  def normal(keys = "")
32
53
  server.remote_send("<C-\\><C-n>#{keys}")
54
+ self
33
55
  end
34
56
 
35
57
  # Public: Invokes one of the basic actions the Vim server supports,
36
58
  # sending a key sequence. The keys are sent as-is, so it'd probably be
37
59
  # better to use the wrapper methods, #normal, #insert and so on.
38
60
  #
39
- # Returns nothing.
61
+ # Returns the Client instance.
40
62
  def type(keys)
41
63
  server.remote_send(keys)
64
+ self
42
65
  end
43
66
 
44
67
  # Public: Starts a search in Vim for the given text. The result is that
45
68
  # the cursor is positioned on its first occurrence.
46
69
  #
47
- # Returns nothing.
70
+ # Returns the Client instance.
48
71
  def search(text)
49
72
  normal
50
73
  type "/#{text}<CR>"
@@ -52,15 +75,18 @@ module Vimrunner
52
75
 
53
76
  # Public: Switches Vim to insert mode and types in the given text.
54
77
  #
55
- # Returns nothing.
78
+ # Returns the Client instance.
56
79
  def insert(text)
57
80
  normal "i#{text}"
58
81
  end
59
82
 
60
83
  # Public: Writes the file being edited to disk. Note that you probably
61
84
  # want to set the file's name first by using Runner#edit.
85
+ #
86
+ # Returns the Client instance.
62
87
  def write
63
88
  command :write
89
+ self
64
90
  end
65
91
 
66
92
  # Public: Echo each expression with a space in between.
@@ -78,12 +104,14 @@ module Vimrunner
78
104
  # vim.set 'expandtab' # invokes ":set expandtab"
79
105
  # vim.set 'tabstop', 3 # invokes ":set tabstop=3"
80
106
  #
107
+ # Returns the Client instance
81
108
  def set(setting, value = nil)
82
109
  if value
83
110
  command "set #{setting}=#{value}"
84
111
  else
85
112
  command "set #{setting}"
86
113
  end
114
+ self
87
115
  end
88
116
 
89
117
  # Public: Edits the file +filename+ with Vim.
@@ -92,21 +120,32 @@ module Vimrunner
92
120
  # the command manually. This is necessary to avoid the Vim instance
93
121
  # getting focus.
94
122
  #
95
- # Returns nothing.
123
+ # Returns the Client instance.
96
124
  def edit(filename)
97
125
  command "edit #{filename}"
126
+ self
127
+ end
128
+
129
+ # Public: Edits the file +filename+ with Vim using edit!.
130
+ #
131
+ # Similar to #edit, only discards any changes to the current buffer.
132
+ #
133
+ # Returns the Client instance.
134
+ def edit!(filename)
135
+ command "edit! #{filename}"
136
+ self
98
137
  end
99
138
 
100
139
  # Public: Executes the given command in the Vim instance and returns its
101
140
  # output, stripping all surrounding whitespace.
102
141
  #
103
- # Returns the string output.
142
+ # Returns the String output.
104
143
  # Raises InvalidCommandError if the command is not recognised by vim.
105
144
  def command(commands)
106
145
  expression = "VimrunnerEvaluateCommandOutput('#{escape(commands)}')"
107
146
 
108
147
  server.remote_expr(expression).tap do |output|
109
- raise InvalidCommandError if output =~ /^Vim:E\d+:/
148
+ raise InvalidCommandError.new(output) if output =~ /^Vim:E\d+:/
110
149
  end
111
150
  end
112
151
 
@@ -46,6 +46,7 @@ module Vimrunner
46
46
  ensure
47
47
  r.close
48
48
  w.close
49
+ Process.kill(9, pid) rescue Errno::ESRCH
49
50
  end
50
51
  end
51
52
 
@@ -64,7 +65,7 @@ module Vimrunner
64
65
  def kill
65
66
  @r.close
66
67
  @w.close
67
- Process.detach(@pid)
68
+ Process.kill(9, @pid) rescue Errno::ESRCH
68
69
 
69
70
  self
70
71
  end
@@ -1,3 +1,3 @@
1
1
  module Vimrunner
2
- VERSION = '0.1.0'
2
+ VERSION = '0.1.1'
3
3
  end
data/vim/vimrc CHANGED
@@ -4,8 +4,11 @@ filetype plugin on
4
4
  filetype indent on
5
5
  syntax on
6
6
 
7
+ set noswapfile nobackup
8
+
7
9
  function! VimrunnerEvaluateCommandOutput(command)
8
10
  let base_command = split(a:command, '\s\+')[0]
11
+ let base_command = substitute(base_command, '!$', '', '')
9
12
 
10
13
  if !exists(':'.base_command)
11
14
  let output = 'Vim:E492: Not an editor command: '.base_command
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vimrunner
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-05-08 00:00:00.000000000 Z
12
+ date: 2012-10-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
16
- requirement: &19072460 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,15 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *19072460
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
25
30
  - !ruby/object:Gem::Dependency
26
31
  name: rdoc
27
- requirement: &19071860 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
28
33
  none: false
29
34
  requirements:
30
35
  - - ! '>='
@@ -32,10 +37,15 @@ dependencies:
32
37
  version: '0'
33
38
  type: :development
34
39
  prerelease: false
35
- version_requirements: *19071860
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
36
46
  - !ruby/object:Gem::Dependency
37
47
  name: simplecov
38
- requirement: &19071280 !ruby/object:Gem::Requirement
48
+ requirement: !ruby/object:Gem::Requirement
39
49
  none: false
40
50
  requirements:
41
51
  - - ! '>='
@@ -43,10 +53,15 @@ dependencies:
43
53
  version: '0'
44
54
  type: :development
45
55
  prerelease: false
46
- version_requirements: *19071280
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
47
62
  - !ruby/object:Gem::Dependency
48
63
  name: rspec
49
- requirement: &19069980 !ruby/object:Gem::Requirement
64
+ requirement: !ruby/object:Gem::Requirement
50
65
  none: false
51
66
  requirements:
52
67
  - - ! '>='
@@ -54,7 +69,12 @@ dependencies:
54
69
  version: 2.0.0
55
70
  type: :development
56
71
  prerelease: false
57
- version_requirements: *19069980
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: 2.0.0
58
78
  description: ! " Using Vim's client/server functionality, this library exposes
59
79
  a way to\n spawn a Vim instance and control it programatically. Apart from being
60
80
  a fun\n party trick, this can be used to integration test Vim script.\n"
@@ -65,12 +85,12 @@ executables:
65
85
  extensions: []
66
86
  extra_rdoc_files: []
67
87
  files:
68
- - lib/vimrunner.rb
69
- - lib/vimrunner/errors.rb
70
88
  - lib/vimrunner/server.rb
71
89
  - lib/vimrunner/platform.rb
72
90
  - lib/vimrunner/version.rb
73
91
  - lib/vimrunner/client.rb
92
+ - lib/vimrunner/errors.rb
93
+ - lib/vimrunner.rb
74
94
  - vim/vimrc
75
95
  - bin/vimrunner
76
96
  - LICENSE
@@ -89,7 +109,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
89
109
  version: '0'
90
110
  segments:
91
111
  - 0
92
- hash: 3979564230760095821
112
+ hash: 1355458872230700164
93
113
  required_rubygems_version: !ruby/object:Gem::Requirement
94
114
  none: false
95
115
  requirements:
@@ -98,7 +118,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
98
118
  version: 1.3.6
99
119
  requirements: []
100
120
  rubyforge_project: vimrunner
101
- rubygems_version: 1.8.15
121
+ rubygems_version: 1.8.24
102
122
  signing_key:
103
123
  specification_version: 3
104
124
  summary: Lets you control a Vim instance through Ruby