read_source 0.2.3 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +28 -0
- data/lib/read_source/version.rb +1 -1
- data/lib/read_source/vim_source.rb +8 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0e5fae70c3b672c0a57efee7e021fa86c6ef1586
|
4
|
+
data.tar.gz: 302b6c3613a02d57db30d5afdfceda1a92c1e1a1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9dd33d3fabc2fc0500cd5131d8561000318d4475ac8f6d41fee1a283b19a4e434350db09fd38bbc4f7071a4fe62efda389da593dedcf5d4a33d883e851b3bf60
|
7
|
+
data.tar.gz: 6591d7b75244cd9df7761f5e456144d128da03a260ff901ce0c1c7f676e01752a247810fbb4bedba96946c1d020120544471343818bb0ca5438ce3731f6e0b03
|
data/README.md
CHANGED
@@ -89,6 +89,34 @@ NOTES:
|
|
89
89
|
* If the source code is written in C then the `read_source` and `vim` methods only return nil.
|
90
90
|
* If the file is in `GEM_HOME` path then VIM opens it in read only mode.
|
91
91
|
|
92
|
+
## VIM
|
93
|
+
|
94
|
+
We now support VIM servers and can open code directly into your existing VIM session(s). If you've started
|
95
|
+
a VIM server with the name of "VIM" then any time you call the `vim` method it will open in there **unless**
|
96
|
+
you choose to specify another servername as a parameter to `vim`.
|
97
|
+
|
98
|
+
#### Start a VIM server with
|
99
|
+
```ruby
|
100
|
+
# A default server
|
101
|
+
vim --servername VIM
|
102
|
+
|
103
|
+
# An alternate server
|
104
|
+
vim --servername SOMENAME
|
105
|
+
```
|
106
|
+
|
107
|
+
Then to open the code in VIM you would do:
|
108
|
+
|
109
|
+
```ruby
|
110
|
+
# If a server is named VIM (or else it will close current Ruby session and open vim in this terminal).
|
111
|
+
Gem::BasicSpecification.instance_method(:base_dir=).vim
|
112
|
+
|
113
|
+
# Using a named server
|
114
|
+
Gem::BasicSpecification.instance_method(:base_dir=).vim 'SOMENAME'
|
115
|
+
```
|
116
|
+
|
117
|
+
This way you can keep your ruby code running and open the code in an existing VIM instance.
|
118
|
+
|
119
|
+
|
92
120
|
## Development
|
93
121
|
|
94
122
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/lib/read_source/version.rb
CHANGED
@@ -3,10 +3,16 @@
|
|
3
3
|
module ReadSource
|
4
4
|
module VimSource
|
5
5
|
def vim servername=nil
|
6
|
-
file, line_num = send :source_location
|
6
|
+
(file, line_num = send :source_location) || return
|
7
7
|
read_only = !!/#{ENV["GEM_HOME"]}/.match(file) ? "-M" : ""
|
8
8
|
remote = "#{('--servername ' + servername.to_s) if servername} --remote-silent"
|
9
|
-
|
9
|
+
serverlist = `vim --serverlist`.split("\n")
|
10
|
+
if serverlist.include?(servername.to_s) || serverlist.include?("VIM")
|
11
|
+
`#{"vim #{remote} %s +%s %s" % [read_only, line_num, file]}`
|
12
|
+
:success
|
13
|
+
else
|
14
|
+
exec("vim #{remote} %s +%s %s" % [read_only, line_num, file])
|
15
|
+
end
|
10
16
|
end
|
11
17
|
end
|
12
18
|
end
|