nvim 1.0.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/INFO.yaml +2 -2
- data/README.md +32 -1
- data/bin/neovim-ruby-host +24 -21
- data/lib/neovim/connection.rb +2 -2
- data/lib/neovim/foreign/supplement.rb +9 -0
- data/lib/neovim/foreign/xxd.rb +195 -0
- data/lib/neovim/handler.rb +33 -20
- data/lib/neovim/host.rb +27 -47
- data/lib/neovim/info.rb +3 -3
- data/lib/neovim/logging.rb +16 -7
- data/lib/neovim/output.rb +142 -0
- data/lib/neovim/remote.rb +241 -18
- data/lib/neovim/remote_object.rb +7 -7
- data/lib/neovim/ruby_provider.rb +35 -160
- data/lib/neovim/tools/calculator.rb +112 -0
- data/lib/neovim/tools/copy.rb +78 -0
- data/lib/neovim/vimscript_provider.rb +1 -1
- data/lib/neovim.rb +14 -4
- metadata +8 -6
- data/lib/neovim/messager.rb +0 -185
- data/lib/neovim/session.rb +0 -60
@@ -0,0 +1,112 @@
|
|
1
|
+
#
|
2
|
+
# neovim/tools/calculator.rb -- Simple calculator
|
3
|
+
#
|
4
|
+
|
5
|
+
require "supplement"
|
6
|
+
require "bigdecimal"
|
7
|
+
|
8
|
+
|
9
|
+
module Neovim
|
10
|
+
|
11
|
+
class Calculator
|
12
|
+
|
13
|
+
def result
|
14
|
+
r = @result.round @decs
|
15
|
+
case r
|
16
|
+
when BigDecimal then
|
17
|
+
r = r.to_s "F"
|
18
|
+
r.sub! /(?:(\.)([0-9]+))?\z/ do
|
19
|
+
(@sep||$1) + ($2.to_s.ljust @decs, "0")
|
20
|
+
end
|
21
|
+
when Integer then
|
22
|
+
r = r.to_s
|
23
|
+
end
|
24
|
+
r
|
25
|
+
end
|
26
|
+
|
27
|
+
def reset!
|
28
|
+
@result = nil
|
29
|
+
end
|
30
|
+
|
31
|
+
def decs= d ; @decs = Integer d ; end
|
32
|
+
|
33
|
+
def dot! ; @sep, @grp = ".", "," ; end
|
34
|
+
def comma! ; @sep, @grp = ",", "." ; end
|
35
|
+
def dot? ; @sep == "." ; end
|
36
|
+
def comma? ; @sep == "," ; end
|
37
|
+
|
38
|
+
def add line
|
39
|
+
line = line.chomp
|
40
|
+
line.slice! /#.*/
|
41
|
+
if $& =~ /!(\w+)/ then
|
42
|
+
case $1
|
43
|
+
when "c", "comma", "k", "komma" then comma!
|
44
|
+
when "d", "dot", "p", "point" then dot!
|
45
|
+
when /\A\d+\z/ then @decs = $1.to_i
|
46
|
+
end
|
47
|
+
end
|
48
|
+
line.slice! /^.*:/
|
49
|
+
line.strip!
|
50
|
+
line.notempty? or return
|
51
|
+
|
52
|
+
products = []
|
53
|
+
line.split /(?<![,.])[+-]/ do |p|
|
54
|
+
products.push [ (split_products p), $& == "-"]
|
55
|
+
end
|
56
|
+
|
57
|
+
minus = false
|
58
|
+
products.each { |p,nm|
|
59
|
+
if not @result then @result = p
|
60
|
+
elsif minus then @result -= p
|
61
|
+
else @result += p
|
62
|
+
end
|
63
|
+
minus = nm
|
64
|
+
}
|
65
|
+
@result
|
66
|
+
end
|
67
|
+
|
68
|
+
private
|
69
|
+
|
70
|
+
def split_products p
|
71
|
+
nums = []
|
72
|
+
p.split /[*\/]/ do |n|
|
73
|
+
nums.push [ (parse_number n), $& == "/"]
|
74
|
+
end
|
75
|
+
|
76
|
+
inv = false
|
77
|
+
prod = nil
|
78
|
+
nums.each { |n,ni|
|
79
|
+
if not prod then prod = n
|
80
|
+
elsif inv then prod /= n
|
81
|
+
else prod *= n
|
82
|
+
end
|
83
|
+
inv = ni
|
84
|
+
}
|
85
|
+
@prev = prod
|
86
|
+
end
|
87
|
+
|
88
|
+
def parse_number n
|
89
|
+
n.strip!
|
90
|
+
if n =~ %r/ *%\z/ then
|
91
|
+
@prev * (BigDecimal $`) / 100
|
92
|
+
else
|
93
|
+
comma! if not @sep and n =~ /\d,\d/
|
94
|
+
case @sep
|
95
|
+
when "," then n.gsub! @grp, "_" ; n.sub! @sep, "."
|
96
|
+
when "." then n.gsub! @grp, "_"
|
97
|
+
end
|
98
|
+
if n =~ /\.-/ then
|
99
|
+
n = $`
|
100
|
+
@decs ||= 2
|
101
|
+
elsif n =~ /\.(\d*)/ then
|
102
|
+
d = $1.length
|
103
|
+
@decs = d if not @decs or @decs < d
|
104
|
+
end
|
105
|
+
@decs.nonzero? ? (BigDecimal n) : (Integer n)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
end
|
110
|
+
|
111
|
+
end
|
112
|
+
|
@@ -0,0 +1,78 @@
|
|
1
|
+
#
|
2
|
+
# neovim/tools/copy.rb -- Set X11 selection and Tmux buffer
|
3
|
+
#
|
4
|
+
|
5
|
+
|
6
|
+
module Kernel
|
7
|
+
|
8
|
+
private
|
9
|
+
|
10
|
+
def xsel data = nil, sel: :primary
|
11
|
+
if ($xsel ||= command? "xsel" ) then
|
12
|
+
cmd = [ $xsel]
|
13
|
+
case sel
|
14
|
+
when :primary then cmd.push "-p"
|
15
|
+
when :secondary then cmd.push "-s"
|
16
|
+
when :clipboard then cmd.push "-b"
|
17
|
+
end
|
18
|
+
ci, co = "-i", "-o"
|
19
|
+
elsif ($xclip ||= command? "xclip") then
|
20
|
+
cmd = [ $xclip, "-selection", sel.to_s]
|
21
|
+
ci, co = "-i", "-o"
|
22
|
+
end
|
23
|
+
cmd or raise ScriptError, "Sorry, Neither xsel nor xclip seem to be installed."
|
24
|
+
if data then
|
25
|
+
cmd.push ci
|
26
|
+
cmd_write cmd, data
|
27
|
+
else
|
28
|
+
cmd.push co
|
29
|
+
cmd_read cmd
|
30
|
+
end
|
31
|
+
end
|
32
|
+
def xsel! data, sel: :clipboard
|
33
|
+
xsel data, sel: sel
|
34
|
+
end
|
35
|
+
|
36
|
+
def tmuxbuf data = nil, name: nil
|
37
|
+
$tmux ||= command? "tmux"
|
38
|
+
$tmux or raise ScriptError, "Sorry, TMux doesn't seem to be installed."
|
39
|
+
args = []
|
40
|
+
if name then
|
41
|
+
args.push "-b", name
|
42
|
+
end
|
43
|
+
args.push "-"
|
44
|
+
if data then
|
45
|
+
cmd_write [ $tmux, "load-buffer", *args], data
|
46
|
+
else
|
47
|
+
cmd_read [ $tmux, "save-buffer", *args]
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
|
52
|
+
def command? cmd
|
53
|
+
if cmd[ File::SEPARATOR] then
|
54
|
+
cmd if File.executable? cmd
|
55
|
+
else
|
56
|
+
(ENV[ "PATH"].split File::PATH_SEPARATOR).each { |p|
|
57
|
+
c = File.join p, cmd
|
58
|
+
return c if File.executable? c
|
59
|
+
}
|
60
|
+
nil
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def cmd_write cmd, data
|
65
|
+
case data
|
66
|
+
when Array then data = data.join $/
|
67
|
+
when String then nil
|
68
|
+
else data = data.to_s
|
69
|
+
end
|
70
|
+
IO.popen cmd, "w" do |t| t.write data end
|
71
|
+
end
|
72
|
+
|
73
|
+
def cmd_read cmd
|
74
|
+
IO.popen cmd, "r" do |t| t.read end
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
|
data/lib/neovim.rb
CHANGED
@@ -7,13 +7,23 @@ require "neovim/host"
|
|
7
7
|
|
8
8
|
module Neovim
|
9
9
|
|
10
|
+
class Job < Provider
|
11
|
+
|
12
|
+
def initialize plugins, conn
|
13
|
+
super plugins, conn
|
14
|
+
start
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
10
19
|
class <<self
|
11
20
|
|
12
21
|
def start_remote &block
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
22
|
+
Job.run mk_plugins &block
|
23
|
+
end
|
24
|
+
|
25
|
+
def mk_plugins &block
|
26
|
+
{ remote: (DslRemote.open &block) }
|
17
27
|
end
|
18
28
|
|
19
29
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nvim
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bertram Scharpf
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-09-11 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email: software@bertram-scharpf.de
|
@@ -29,18 +29,20 @@ files:
|
|
29
29
|
- lib/neovim/foreign/mplight/bufferio.rb
|
30
30
|
- lib/neovim/foreign/supplement.rb
|
31
31
|
- lib/neovim/foreign/supplement/socket.rb
|
32
|
+
- lib/neovim/foreign/xxd.rb
|
32
33
|
- lib/neovim/handler.rb
|
33
34
|
- lib/neovim/host.rb
|
34
35
|
- lib/neovim/info.rb
|
35
36
|
- lib/neovim/logging.rb
|
36
|
-
- lib/neovim/messager.rb
|
37
37
|
- lib/neovim/meta.rb
|
38
|
+
- lib/neovim/output.rb
|
38
39
|
- lib/neovim/remote.rb
|
39
40
|
- lib/neovim/remote_object.rb
|
40
41
|
- lib/neovim/ruby_provider.rb
|
41
|
-
- lib/neovim/
|
42
|
+
- lib/neovim/tools/calculator.rb
|
43
|
+
- lib/neovim/tools/copy.rb
|
42
44
|
- lib/neovim/vimscript_provider.rb
|
43
|
-
homepage:
|
45
|
+
homepage: https://github.com/BertramScharpf/ruby-nvim
|
44
46
|
licenses:
|
45
47
|
- BSD-2-Clause+
|
46
48
|
metadata: {}
|
@@ -59,7 +61,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
59
61
|
- !ruby/object:Gem::Version
|
60
62
|
version: '0'
|
61
63
|
requirements: []
|
62
|
-
rubygems_version: 3.5.
|
64
|
+
rubygems_version: 3.5.18
|
63
65
|
signing_key:
|
64
66
|
specification_version: 4
|
65
67
|
summary: Yet another Ruby client for Neovim
|
data/lib/neovim/messager.rb
DELETED
@@ -1,185 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# neovim/messager.rb -- Send and Receive Messages
|
3
|
-
#
|
4
|
-
|
5
|
-
require "neovim/foreign/supplement"
|
6
|
-
|
7
|
-
require "neovim/logging"
|
8
|
-
|
9
|
-
|
10
|
-
module Neovim
|
11
|
-
|
12
|
-
class Messager
|
13
|
-
|
14
|
-
class Message
|
15
|
-
|
16
|
-
@subs, @subh = [], {}
|
17
|
-
|
18
|
-
class <<self
|
19
|
-
|
20
|
-
def from_array ary
|
21
|
-
kind, *payload = *ary
|
22
|
-
klass = find kind
|
23
|
-
klass[ *payload]
|
24
|
-
end
|
25
|
-
|
26
|
-
def inherited cls ; @subs.push cls ; end
|
27
|
-
def find id
|
28
|
-
@subh[ id] ||= @subs.find { |c| c::ID == id }
|
29
|
-
end
|
30
|
-
|
31
|
-
alias [] new
|
32
|
-
|
33
|
-
end
|
34
|
-
|
35
|
-
def initialize *args
|
36
|
-
z = self.class::KEYS.zip args
|
37
|
-
@cont = z.inject Hash.new do |c,(h,k)| c[h] = k ; c end
|
38
|
-
end
|
39
|
-
|
40
|
-
def inspect
|
41
|
-
c = self.class.name.sub /.*::/, ""
|
42
|
-
"#<#{c} #@cont>"
|
43
|
-
end
|
44
|
-
|
45
|
-
def to_s
|
46
|
-
c = self.class.name.sub /.*::/, ""
|
47
|
-
j = @cont.map { |k,v| "#{k}:#{v}" if v }.compact.join ","
|
48
|
-
"#{c}(#{j})"
|
49
|
-
end
|
50
|
-
|
51
|
-
def method_missing sym, *args
|
52
|
-
if @cont.key? sym then @cont[ sym] else super end
|
53
|
-
end
|
54
|
-
|
55
|
-
def respond_to_missing? sym, priv = nil
|
56
|
-
@cont.key? sym.to_sym
|
57
|
-
end
|
58
|
-
|
59
|
-
def methods *args
|
60
|
-
super.concat @cont.keys
|
61
|
-
end
|
62
|
-
|
63
|
-
def to_h ; @cont ; end
|
64
|
-
|
65
|
-
def fields ; @cont.fetch_values *self.class::KEYS ; end
|
66
|
-
|
67
|
-
def to_a
|
68
|
-
[self.class::ID, *fields]
|
69
|
-
end
|
70
|
-
|
71
|
-
class Request < Message
|
72
|
-
ID = 0
|
73
|
-
KEYS = %i(request_id method_name arguments)
|
74
|
-
end
|
75
|
-
|
76
|
-
class Response < Message
|
77
|
-
ID = 1
|
78
|
-
KEYS = %i(request_id error value)
|
79
|
-
def initialize *args
|
80
|
-
super
|
81
|
-
e = @cont[ :error]
|
82
|
-
if e and not Array === e then
|
83
|
-
@cont[ :error] = [0, e]
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
end
|
88
|
-
|
89
|
-
class Notification < Message
|
90
|
-
ID = 2
|
91
|
-
KEYS = %i(method_name arguments)
|
92
|
-
end
|
93
|
-
|
94
|
-
end
|
95
|
-
|
96
|
-
class ResponseError < StandardError ; end
|
97
|
-
|
98
|
-
class Disconnected < RuntimeError
|
99
|
-
def initialize
|
100
|
-
super "Lost connection to nvim process"
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
|
105
|
-
include Logging
|
106
|
-
|
107
|
-
def initialize conn, session
|
108
|
-
@conn, @session = conn, session
|
109
|
-
@request_id = 0
|
110
|
-
@responses = {}
|
111
|
-
end
|
112
|
-
|
113
|
-
def run until_id = nil
|
114
|
-
loop do
|
115
|
-
message = get
|
116
|
-
case message
|
117
|
-
when Message::Response then
|
118
|
-
if @responses.key? message.request_id then
|
119
|
-
@responses[ message.request_id] = message
|
120
|
-
else
|
121
|
-
log :warning, "Dropped response", message.request_id
|
122
|
-
end
|
123
|
-
when Message::Request then
|
124
|
-
begin
|
125
|
-
r = @session.execute_handler message.method_name, message.arguments
|
126
|
-
log :debug1, "Request result", result: r
|
127
|
-
rescue
|
128
|
-
e = [ 0, $!.to_s]
|
129
|
-
log_exception :error
|
130
|
-
end
|
131
|
-
rsp = Message::Response.new message.request_id, e, r
|
132
|
-
put rsp
|
133
|
-
when Message::Notification then
|
134
|
-
begin
|
135
|
-
@session.execute_handler message.method_name, message.arguments
|
136
|
-
rescue
|
137
|
-
log_exception :error
|
138
|
-
end
|
139
|
-
end
|
140
|
-
break if until_id and @responses[ until_id]
|
141
|
-
end
|
142
|
-
end
|
143
|
-
|
144
|
-
def request method, *args
|
145
|
-
@request_id += 1
|
146
|
-
put Message::Request[ @request_id, method, args]
|
147
|
-
@responses[ @request_id] = nil
|
148
|
-
run @request_id
|
149
|
-
r = @responses.delete @request_id
|
150
|
-
if r.error then
|
151
|
-
t, e = *r.error
|
152
|
-
t = @conn.error t
|
153
|
-
raise ResponseError, "#{t}: #{e}"
|
154
|
-
end
|
155
|
-
r.value
|
156
|
-
end
|
157
|
-
|
158
|
-
def notify method, *args
|
159
|
-
put Message::Notification[ method, args]
|
160
|
-
end
|
161
|
-
|
162
|
-
private
|
163
|
-
|
164
|
-
def put msg
|
165
|
-
log :debug1, "Sending Message", data: msg
|
166
|
-
@conn.put msg.to_a
|
167
|
-
self
|
168
|
-
rescue Errno::EPIPE
|
169
|
-
raise Disconnected
|
170
|
-
end
|
171
|
-
|
172
|
-
def get
|
173
|
-
IO.select [@conn.input], nil, nil
|
174
|
-
raise Disconnected if @conn.eof?
|
175
|
-
msg = Message.from_array @conn.get
|
176
|
-
log :debug1, "Received Message", data: msg
|
177
|
-
msg
|
178
|
-
rescue EOFError
|
179
|
-
raise Disconnected
|
180
|
-
end
|
181
|
-
|
182
|
-
end
|
183
|
-
|
184
|
-
end
|
185
|
-
|
data/lib/neovim/session.rb
DELETED
@@ -1,60 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# neovim/session.rb -- Sessions
|
3
|
-
#
|
4
|
-
|
5
|
-
require "neovim/foreign/supplement"
|
6
|
-
|
7
|
-
require "neovim/logging"
|
8
|
-
require "neovim/connection"
|
9
|
-
require "neovim/messager"
|
10
|
-
|
11
|
-
|
12
|
-
module Neovim
|
13
|
-
|
14
|
-
class Session
|
15
|
-
|
16
|
-
include Logging
|
17
|
-
|
18
|
-
class <<self
|
19
|
-
|
20
|
-
private :new
|
21
|
-
|
22
|
-
def open conntype, *args, **kwargs
|
23
|
-
conntype.open_files *args, **kwargs do |conn|
|
24
|
-
yield (new conn)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
include Logging
|
29
|
-
|
30
|
-
def start *args
|
31
|
-
open_logfile do
|
32
|
-
log :info, "Starting", args: $*
|
33
|
-
open *args do |i|
|
34
|
-
yield i
|
35
|
-
end
|
36
|
-
ensure
|
37
|
-
log :info, "Leaving"
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
end
|
42
|
-
|
43
|
-
def initialize conn
|
44
|
-
@conn = conn
|
45
|
-
@comm = Messager.new @conn, self
|
46
|
-
end
|
47
|
-
|
48
|
-
def execute_handler name, args
|
49
|
-
raise "No handler found for #{name.inspect}."
|
50
|
-
end
|
51
|
-
|
52
|
-
|
53
|
-
def run ; @comm.run ; end
|
54
|
-
def request method, *args ; @comm.request method, *args ; end
|
55
|
-
def notify method, *args ; @comm.notify method, *args ; end
|
56
|
-
|
57
|
-
end
|
58
|
-
|
59
|
-
end
|
60
|
-
|